/src/binutils-gdb/bfd/elfxx-riscv.c
Line | Count | Source |
1 | | /* RISC-V-specific support for ELF. |
2 | | Copyright (C) 2011-2026 Free Software Foundation, Inc. |
3 | | |
4 | | Contributed by Andrew Waterman (andrew@sifive.com). |
5 | | Based on TILE-Gx and MIPS targets. |
6 | | |
7 | | This file is part of BFD, the Binary File Descriptor library. |
8 | | |
9 | | This program is free software; you can redistribute it and/or modify |
10 | | it under the terms of the GNU General Public License as published by |
11 | | the Free Software Foundation; either version 3 of the License, or |
12 | | (at your option) any later version. |
13 | | |
14 | | This program is distributed in the hope that it will be useful, |
15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | GNU General Public License for more details. |
18 | | |
19 | | You should have received a copy of the GNU General Public License |
20 | | along with this program; see the file COPYING3. If not, |
21 | | see <http://www.gnu.org/licenses/>. */ |
22 | | |
23 | | #include "sysdep.h" |
24 | | #include "bfd.h" |
25 | | #include "libbfd.h" |
26 | | #include "elf-bfd.h" |
27 | | #include "elf/riscv.h" |
28 | | #include "opcode/riscv.h" |
29 | | #include "libiberty.h" |
30 | | #include "elfxx-riscv.h" |
31 | | #include "safe-ctype.h" |
32 | | |
33 | | #define MINUS_ONE ((bfd_vma)0 - 1) |
34 | | |
35 | | /* Special handler for ADD/SUB relocations that allows them to be filled out |
36 | | both in the pre-linked and post-linked file. This is necessary to make |
37 | | pre-linked debug info work, as due to linker relaxations we need to emit |
38 | | relocations for the debug info. */ |
39 | | static bfd_reloc_status_type riscv_elf_add_sub_reloc |
40 | | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
41 | | static bfd_reloc_status_type riscv_elf_ignore_reloc |
42 | | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
43 | | |
44 | | /* The relocation table used for SHT_RELA sections. */ |
45 | | |
46 | | static const reloc_howto_type howto_table[] = |
47 | | { |
48 | | /* No relocation. */ |
49 | | HOWTO (R_RISCV_NONE, /* type */ |
50 | | 0, /* rightshift */ |
51 | | 0, /* size */ |
52 | | 0, /* bitsize */ |
53 | | false, /* pc_relative */ |
54 | | 0, /* bitpos */ |
55 | | complain_overflow_dont, /* complain_on_overflow */ |
56 | | bfd_elf_generic_reloc, /* special_function */ |
57 | | "R_RISCV_NONE", /* name */ |
58 | | false, /* partial_inplace */ |
59 | | 0, /* src_mask */ |
60 | | 0, /* dst_mask */ |
61 | | false), /* pcrel_offset */ |
62 | | |
63 | | /* 32 bit relocation. */ |
64 | | HOWTO (R_RISCV_32, /* type */ |
65 | | 0, /* rightshift */ |
66 | | 4, /* size */ |
67 | | 32, /* bitsize */ |
68 | | false, /* pc_relative */ |
69 | | 0, /* bitpos */ |
70 | | complain_overflow_dont, /* complain_on_overflow */ |
71 | | bfd_elf_generic_reloc, /* special_function */ |
72 | | "R_RISCV_32", /* name */ |
73 | | false, /* partial_inplace */ |
74 | | 0, /* src_mask */ |
75 | | 0xffffffff, /* dst_mask */ |
76 | | false), /* pcrel_offset */ |
77 | | |
78 | | /* 64 bit relocation. */ |
79 | | HOWTO (R_RISCV_64, /* type */ |
80 | | 0, /* rightshift */ |
81 | | 8, /* size */ |
82 | | 64, /* bitsize */ |
83 | | false, /* pc_relative */ |
84 | | 0, /* bitpos */ |
85 | | complain_overflow_dont, /* complain_on_overflow */ |
86 | | bfd_elf_generic_reloc, /* special_function */ |
87 | | "R_RISCV_64", /* name */ |
88 | | false, /* partial_inplace */ |
89 | | 0, /* src_mask */ |
90 | | MINUS_ONE, /* dst_mask */ |
91 | | false), /* pcrel_offset */ |
92 | | |
93 | | /* Relocation against a local symbol in a shared object. */ |
94 | | HOWTO (R_RISCV_RELATIVE, /* type */ |
95 | | 0, /* rightshift */ |
96 | | 4, /* size */ |
97 | | 32, /* bitsize */ |
98 | | false, /* pc_relative */ |
99 | | 0, /* bitpos */ |
100 | | complain_overflow_dont, /* complain_on_overflow */ |
101 | | bfd_elf_generic_reloc, /* special_function */ |
102 | | "R_RISCV_RELATIVE", /* name */ |
103 | | false, /* partial_inplace */ |
104 | | 0, /* src_mask */ |
105 | | 0xffffffff, /* dst_mask */ |
106 | | false), /* pcrel_offset */ |
107 | | |
108 | | HOWTO (R_RISCV_COPY, /* type */ |
109 | | 0, /* rightshift */ |
110 | | 0, /* this one is variable size */ |
111 | | 0, /* bitsize */ |
112 | | false, /* pc_relative */ |
113 | | 0, /* bitpos */ |
114 | | complain_overflow_bitfield, /* complain_on_overflow */ |
115 | | bfd_elf_generic_reloc, /* special_function */ |
116 | | "R_RISCV_COPY", /* name */ |
117 | | false, /* partial_inplace */ |
118 | | 0, /* src_mask */ |
119 | | 0, /* dst_mask */ |
120 | | false), /* pcrel_offset */ |
121 | | |
122 | | HOWTO (R_RISCV_JUMP_SLOT, /* type */ |
123 | | 0, /* rightshift */ |
124 | | 8, /* size */ |
125 | | 64, /* bitsize */ |
126 | | false, /* pc_relative */ |
127 | | 0, /* bitpos */ |
128 | | complain_overflow_bitfield, /* complain_on_overflow */ |
129 | | bfd_elf_generic_reloc, /* special_function */ |
130 | | "R_RISCV_JUMP_SLOT", /* name */ |
131 | | false, /* partial_inplace */ |
132 | | 0, /* src_mask */ |
133 | | 0, /* dst_mask */ |
134 | | false), /* pcrel_offset */ |
135 | | |
136 | | /* Dynamic TLS relocations. */ |
137 | | HOWTO (R_RISCV_TLS_DTPMOD32, /* type */ |
138 | | 0, /* rightshift */ |
139 | | 4, /* size */ |
140 | | 32, /* bitsize */ |
141 | | false, /* pc_relative */ |
142 | | 0, /* bitpos */ |
143 | | complain_overflow_dont, /* complain_on_overflow */ |
144 | | bfd_elf_generic_reloc, /* special_function */ |
145 | | "R_RISCV_TLS_DTPMOD32", /* name */ |
146 | | false, /* partial_inplace */ |
147 | | 0, /* src_mask */ |
148 | | 0xffffffff, /* dst_mask */ |
149 | | false), /* pcrel_offset */ |
150 | | |
151 | | HOWTO (R_RISCV_TLS_DTPMOD64, /* type */ |
152 | | 0, /* rightshift */ |
153 | | 8, /* size */ |
154 | | 64, /* bitsize */ |
155 | | false, /* pc_relative */ |
156 | | 0, /* bitpos */ |
157 | | complain_overflow_dont, /* complain_on_overflow */ |
158 | | bfd_elf_generic_reloc, /* special_function */ |
159 | | "R_RISCV_TLS_DTPMOD64", /* name */ |
160 | | false, /* partial_inplace */ |
161 | | 0, /* src_mask */ |
162 | | MINUS_ONE, /* dst_mask */ |
163 | | false), /* pcrel_offset */ |
164 | | |
165 | | HOWTO (R_RISCV_TLS_DTPREL32, /* type */ |
166 | | 0, /* rightshift */ |
167 | | 4, /* size */ |
168 | | 32, /* bitsize */ |
169 | | false, /* pc_relative */ |
170 | | 0, /* bitpos */ |
171 | | complain_overflow_dont, /* complain_on_overflow */ |
172 | | bfd_elf_generic_reloc, /* special_function */ |
173 | | "R_RISCV_TLS_DTPREL32", /* name */ |
174 | | true, /* partial_inplace */ |
175 | | 0, /* src_mask */ |
176 | | 0xffffffff, /* dst_mask */ |
177 | | false), /* pcrel_offset */ |
178 | | |
179 | | HOWTO (R_RISCV_TLS_DTPREL64, /* type */ |
180 | | 0, /* rightshift */ |
181 | | 8, /* size */ |
182 | | 64, /* bitsize */ |
183 | | false, /* pc_relative */ |
184 | | 0, /* bitpos */ |
185 | | complain_overflow_dont, /* complain_on_overflow */ |
186 | | bfd_elf_generic_reloc, /* special_function */ |
187 | | "R_RISCV_TLS_DTPREL64", /* name */ |
188 | | true, /* partial_inplace */ |
189 | | 0, /* src_mask */ |
190 | | MINUS_ONE, /* dst_mask */ |
191 | | false), /* pcrel_offset */ |
192 | | |
193 | | HOWTO (R_RISCV_TLS_TPREL32, /* type */ |
194 | | 0, /* rightshift */ |
195 | | 4, /* size */ |
196 | | 32, /* bitsize */ |
197 | | false, /* pc_relative */ |
198 | | 0, /* bitpos */ |
199 | | complain_overflow_dont, /* complain_on_overflow */ |
200 | | bfd_elf_generic_reloc, /* special_function */ |
201 | | "R_RISCV_TLS_TPREL32", /* name */ |
202 | | false, /* partial_inplace */ |
203 | | 0, /* src_mask */ |
204 | | 0xffffffff, /* dst_mask */ |
205 | | false), /* pcrel_offset */ |
206 | | |
207 | | HOWTO (R_RISCV_TLS_TPREL64, /* type */ |
208 | | 0, /* rightshift */ |
209 | | 8, /* size */ |
210 | | 64, /* bitsize */ |
211 | | false, /* pc_relative */ |
212 | | 0, /* bitpos */ |
213 | | complain_overflow_dont, /* complain_on_overflow */ |
214 | | bfd_elf_generic_reloc, /* special_function */ |
215 | | "R_RISCV_TLS_TPREL64", /* name */ |
216 | | false, /* partial_inplace */ |
217 | | 0, /* src_mask */ |
218 | | MINUS_ONE, /* dst_mask */ |
219 | | false), /* pcrel_offset */ |
220 | | |
221 | | HOWTO (R_RISCV_TLSDESC, /* type */ |
222 | | 0, /* rightshift */ |
223 | | 0, /* size is handled by dynamic linker */ |
224 | | 0, /* bitsize */ |
225 | | false, /* pc_relative */ |
226 | | 0, /* bitpos */ |
227 | | complain_overflow_dont, /* complain_on_overflow */ |
228 | | bfd_elf_generic_reloc, /* special_function */ |
229 | | "R_RISCV_TLSDESC", /* name */ |
230 | | false, /* partial_inplace */ |
231 | | 0, /* src_mask */ |
232 | | MINUS_ONE, /* dst_mask */ |
233 | | false), /* pcrel_offset */ |
234 | | |
235 | | EMPTY_HOWTO (13), |
236 | | EMPTY_HOWTO (14), |
237 | | EMPTY_HOWTO (15), |
238 | | |
239 | | /* 12-bit PC-relative branch offset. */ |
240 | | HOWTO (R_RISCV_BRANCH, /* type */ |
241 | | 0, /* rightshift */ |
242 | | 4, /* size */ |
243 | | 32, /* bitsize */ |
244 | | true, /* pc_relative */ |
245 | | 0, /* bitpos */ |
246 | | complain_overflow_signed, /* complain_on_overflow */ |
247 | | bfd_elf_generic_reloc, /* special_function */ |
248 | | "R_RISCV_BRANCH", /* name */ |
249 | | false, /* partial_inplace */ |
250 | | 0, /* src_mask */ |
251 | | ENCODE_BTYPE_IMM (-1U), /* dst_mask */ |
252 | | true), /* pcrel_offset */ |
253 | | |
254 | | /* 20-bit PC-relative jump offset. */ |
255 | | HOWTO (R_RISCV_JAL, /* type */ |
256 | | 0, /* rightshift */ |
257 | | 4, /* size */ |
258 | | 32, /* bitsize */ |
259 | | true, /* pc_relative */ |
260 | | 0, /* bitpos */ |
261 | | complain_overflow_dont, /* complain_on_overflow */ |
262 | | bfd_elf_generic_reloc, /* special_function */ |
263 | | "R_RISCV_JAL", /* name */ |
264 | | false, /* partial_inplace */ |
265 | | 0, /* src_mask */ |
266 | | ENCODE_JTYPE_IMM (-1U), /* dst_mask */ |
267 | | true), /* pcrel_offset */ |
268 | | |
269 | | /* 32-bit PC-relative function call (AUIPC/JALR). */ |
270 | | HOWTO (R_RISCV_CALL, /* type */ |
271 | | 0, /* rightshift */ |
272 | | 8, /* size */ |
273 | | 64, /* bitsize */ |
274 | | true, /* pc_relative */ |
275 | | 0, /* bitpos */ |
276 | | complain_overflow_dont, /* complain_on_overflow */ |
277 | | bfd_elf_generic_reloc, /* special_function */ |
278 | | "R_RISCV_CALL", /* name */ |
279 | | false, /* partial_inplace */ |
280 | | 0, /* src_mask */ |
281 | | ENCODE_UTYPE_IMM (-1U) | ((bfd_vma) ENCODE_ITYPE_IMM (-1U) << 32), |
282 | | /* dst_mask */ |
283 | | true), /* pcrel_offset */ |
284 | | |
285 | | /* Like R_RISCV_CALL, but not locally binding. */ |
286 | | HOWTO (R_RISCV_CALL_PLT, /* type */ |
287 | | 0, /* rightshift */ |
288 | | 8, /* size */ |
289 | | 64, /* bitsize */ |
290 | | true, /* pc_relative */ |
291 | | 0, /* bitpos */ |
292 | | complain_overflow_dont, /* complain_on_overflow */ |
293 | | bfd_elf_generic_reloc, /* special_function */ |
294 | | "R_RISCV_CALL_PLT", /* name */ |
295 | | false, /* partial_inplace */ |
296 | | 0, /* src_mask */ |
297 | | ENCODE_UTYPE_IMM (-1U) | ((bfd_vma) ENCODE_ITYPE_IMM (-1U) << 32), |
298 | | /* dst_mask */ |
299 | | true), /* pcrel_offset */ |
300 | | |
301 | | /* High 20 bits of 32-bit PC-relative GOT access. */ |
302 | | HOWTO (R_RISCV_GOT_HI20, /* type */ |
303 | | 0, /* rightshift */ |
304 | | 4, /* size */ |
305 | | 32, /* bitsize */ |
306 | | true, /* pc_relative */ |
307 | | 0, /* bitpos */ |
308 | | complain_overflow_dont, /* complain_on_overflow */ |
309 | | bfd_elf_generic_reloc, /* special_function */ |
310 | | "R_RISCV_GOT_HI20", /* name */ |
311 | | false, /* partial_inplace */ |
312 | | 0, /* src_mask */ |
313 | | ENCODE_UTYPE_IMM (-1U), /* dst_mask */ |
314 | | false), /* pcrel_offset */ |
315 | | |
316 | | /* High 20 bits of 32-bit PC-relative TLS IE GOT access. */ |
317 | | HOWTO (R_RISCV_TLS_GOT_HI20, /* type */ |
318 | | 0, /* rightshift */ |
319 | | 4, /* size */ |
320 | | 32, /* bitsize */ |
321 | | true, /* pc_relative */ |
322 | | 0, /* bitpos */ |
323 | | complain_overflow_dont, /* complain_on_overflow */ |
324 | | bfd_elf_generic_reloc, /* special_function */ |
325 | | "R_RISCV_TLS_GOT_HI20", /* name */ |
326 | | false, /* partial_inplace */ |
327 | | 0, /* src_mask */ |
328 | | ENCODE_UTYPE_IMM (-1U), /* dst_mask */ |
329 | | false), /* pcrel_offset */ |
330 | | |
331 | | /* High 20 bits of 32-bit PC-relative TLS GD GOT reference. */ |
332 | | HOWTO (R_RISCV_TLS_GD_HI20, /* type */ |
333 | | 0, /* rightshift */ |
334 | | 4, /* size */ |
335 | | 32, /* bitsize */ |
336 | | true, /* pc_relative */ |
337 | | 0, /* bitpos */ |
338 | | complain_overflow_dont, /* complain_on_overflow */ |
339 | | bfd_elf_generic_reloc, /* special_function */ |
340 | | "R_RISCV_TLS_GD_HI20", /* name */ |
341 | | false, /* partial_inplace */ |
342 | | 0, /* src_mask */ |
343 | | ENCODE_UTYPE_IMM (-1U), /* dst_mask */ |
344 | | false), /* pcrel_offset */ |
345 | | |
346 | | /* High 20 bits of 32-bit PC-relative reference. */ |
347 | | HOWTO (R_RISCV_PCREL_HI20, /* type */ |
348 | | 0, /* rightshift */ |
349 | | 4, /* size */ |
350 | | 32, /* bitsize */ |
351 | | true, /* pc_relative */ |
352 | | 0, /* bitpos */ |
353 | | complain_overflow_dont, /* complain_on_overflow */ |
354 | | bfd_elf_generic_reloc, /* special_function */ |
355 | | "R_RISCV_PCREL_HI20", /* name */ |
356 | | false, /* partial_inplace */ |
357 | | 0, /* src_mask */ |
358 | | ENCODE_UTYPE_IMM (-1U), /* dst_mask */ |
359 | | true), /* pcrel_offset */ |
360 | | |
361 | | /* Low 12 bits of a 32-bit PC-relative load or add. */ |
362 | | HOWTO (R_RISCV_PCREL_LO12_I, /* type */ |
363 | | 0, /* rightshift */ |
364 | | 4, /* size */ |
365 | | 32, /* bitsize */ |
366 | | false, /* pc_relative */ |
367 | | 0, /* bitpos */ |
368 | | complain_overflow_dont, /* complain_on_overflow */ |
369 | | bfd_elf_generic_reloc, /* special_function */ |
370 | | "R_RISCV_PCREL_LO12_I", /* name */ |
371 | | false, /* partial_inplace */ |
372 | | 0, /* src_mask */ |
373 | | ENCODE_ITYPE_IMM (-1U), /* dst_mask */ |
374 | | false), /* pcrel_offset */ |
375 | | |
376 | | /* Low 12 bits of a 32-bit PC-relative store. */ |
377 | | HOWTO (R_RISCV_PCREL_LO12_S, /* type */ |
378 | | 0, /* rightshift */ |
379 | | 4, /* size */ |
380 | | 32, /* bitsize */ |
381 | | false, /* pc_relative */ |
382 | | 0, /* bitpos */ |
383 | | complain_overflow_dont, /* complain_on_overflow */ |
384 | | bfd_elf_generic_reloc, /* special_function */ |
385 | | "R_RISCV_PCREL_LO12_S", /* name */ |
386 | | false, /* partial_inplace */ |
387 | | 0, /* src_mask */ |
388 | | ENCODE_STYPE_IMM (-1U), /* dst_mask */ |
389 | | false), /* pcrel_offset */ |
390 | | |
391 | | /* High 20 bits of 32-bit absolute address. */ |
392 | | HOWTO (R_RISCV_HI20, /* type */ |
393 | | 0, /* rightshift */ |
394 | | 4, /* size */ |
395 | | 32, /* bitsize */ |
396 | | false, /* pc_relative */ |
397 | | 0, /* bitpos */ |
398 | | complain_overflow_dont, /* complain_on_overflow */ |
399 | | bfd_elf_generic_reloc, /* special_function */ |
400 | | "R_RISCV_HI20", /* name */ |
401 | | false, /* partial_inplace */ |
402 | | 0, /* src_mask */ |
403 | | ENCODE_UTYPE_IMM (-1U), /* dst_mask */ |
404 | | false), /* pcrel_offset */ |
405 | | |
406 | | /* High 12 bits of 32-bit load or add. */ |
407 | | HOWTO (R_RISCV_LO12_I, /* type */ |
408 | | 0, /* rightshift */ |
409 | | 4, /* size */ |
410 | | 32, /* bitsize */ |
411 | | false, /* pc_relative */ |
412 | | 0, /* bitpos */ |
413 | | complain_overflow_dont, /* complain_on_overflow */ |
414 | | bfd_elf_generic_reloc, /* special_function */ |
415 | | "R_RISCV_LO12_I", /* name */ |
416 | | false, /* partial_inplace */ |
417 | | 0, /* src_mask */ |
418 | | ENCODE_ITYPE_IMM (-1U), /* dst_mask */ |
419 | | false), /* pcrel_offset */ |
420 | | |
421 | | /* High 12 bits of 32-bit store. */ |
422 | | HOWTO (R_RISCV_LO12_S, /* type */ |
423 | | 0, /* rightshift */ |
424 | | 4, /* size */ |
425 | | 32, /* bitsize */ |
426 | | false, /* pc_relative */ |
427 | | 0, /* bitpos */ |
428 | | complain_overflow_dont, /* complain_on_overflow */ |
429 | | bfd_elf_generic_reloc, /* special_function */ |
430 | | "R_RISCV_LO12_S", /* name */ |
431 | | false, /* partial_inplace */ |
432 | | 0, /* src_mask */ |
433 | | ENCODE_STYPE_IMM (-1U), /* dst_mask */ |
434 | | false), /* pcrel_offset */ |
435 | | |
436 | | /* High 20 bits of TLS LE thread pointer offset. */ |
437 | | HOWTO (R_RISCV_TPREL_HI20, /* type */ |
438 | | 0, /* rightshift */ |
439 | | 4, /* size */ |
440 | | 32, /* bitsize */ |
441 | | false, /* pc_relative */ |
442 | | 0, /* bitpos */ |
443 | | complain_overflow_signed, /* complain_on_overflow */ |
444 | | bfd_elf_generic_reloc, /* special_function */ |
445 | | "R_RISCV_TPREL_HI20", /* name */ |
446 | | true, /* partial_inplace */ |
447 | | 0, /* src_mask */ |
448 | | ENCODE_UTYPE_IMM (-1U), /* dst_mask */ |
449 | | false), /* pcrel_offset */ |
450 | | |
451 | | /* Low 12 bits of TLS LE thread pointer offset for loads and adds. */ |
452 | | HOWTO (R_RISCV_TPREL_LO12_I, /* type */ |
453 | | 0, /* rightshift */ |
454 | | 4, /* size */ |
455 | | 32, /* bitsize */ |
456 | | false, /* pc_relative */ |
457 | | 0, /* bitpos */ |
458 | | complain_overflow_signed, /* complain_on_overflow */ |
459 | | bfd_elf_generic_reloc, /* special_function */ |
460 | | "R_RISCV_TPREL_LO12_I", /* name */ |
461 | | false, /* partial_inplace */ |
462 | | 0, /* src_mask */ |
463 | | ENCODE_ITYPE_IMM (-1U), /* dst_mask */ |
464 | | false), /* pcrel_offset */ |
465 | | |
466 | | /* Low 12 bits of TLS LE thread pointer offset for stores. */ |
467 | | HOWTO (R_RISCV_TPREL_LO12_S, /* type */ |
468 | | 0, /* rightshift */ |
469 | | 4, /* size */ |
470 | | 32, /* bitsize */ |
471 | | false, /* pc_relative */ |
472 | | 0, /* bitpos */ |
473 | | complain_overflow_signed, /* complain_on_overflow */ |
474 | | bfd_elf_generic_reloc, /* special_function */ |
475 | | "R_RISCV_TPREL_LO12_S", /* name */ |
476 | | false, /* partial_inplace */ |
477 | | 0, /* src_mask */ |
478 | | ENCODE_STYPE_IMM (-1U), /* dst_mask */ |
479 | | false), /* pcrel_offset */ |
480 | | |
481 | | /* TLS LE thread pointer usage. May be relaxed. */ |
482 | | HOWTO (R_RISCV_TPREL_ADD, /* type */ |
483 | | 0, /* rightshift */ |
484 | | 0, /* size */ |
485 | | 0, /* bitsize */ |
486 | | false, /* pc_relative */ |
487 | | 0, /* bitpos */ |
488 | | complain_overflow_dont, /* complain_on_overflow */ |
489 | | bfd_elf_generic_reloc, /* special_function */ |
490 | | "R_RISCV_TPREL_ADD", /* name */ |
491 | | false, /* partial_inplace */ |
492 | | 0, /* src_mask */ |
493 | | 0, /* dst_mask */ |
494 | | false), /* pcrel_offset */ |
495 | | |
496 | | /* 8-bit in-place addition, for local label subtraction. */ |
497 | | HOWTO (R_RISCV_ADD8, /* type */ |
498 | | 0, /* rightshift */ |
499 | | 1, /* size */ |
500 | | 8, /* bitsize */ |
501 | | false, /* pc_relative */ |
502 | | 0, /* bitpos */ |
503 | | complain_overflow_dont, /* complain_on_overflow */ |
504 | | riscv_elf_add_sub_reloc, /* special_function */ |
505 | | "R_RISCV_ADD8", /* name */ |
506 | | false, /* partial_inplace */ |
507 | | 0, /* src_mask */ |
508 | | 0xff, /* dst_mask */ |
509 | | false), /* pcrel_offset */ |
510 | | |
511 | | /* 16-bit in-place addition, for local label subtraction. */ |
512 | | HOWTO (R_RISCV_ADD16, /* type */ |
513 | | 0, /* rightshift */ |
514 | | 2, /* size */ |
515 | | 16, /* bitsize */ |
516 | | false, /* pc_relative */ |
517 | | 0, /* bitpos */ |
518 | | complain_overflow_dont, /* complain_on_overflow */ |
519 | | riscv_elf_add_sub_reloc, /* special_function */ |
520 | | "R_RISCV_ADD16", /* name */ |
521 | | false, /* partial_inplace */ |
522 | | 0, /* src_mask */ |
523 | | 0xffff, /* dst_mask */ |
524 | | false), /* pcrel_offset */ |
525 | | |
526 | | /* 32-bit in-place addition, for local label subtraction. */ |
527 | | HOWTO (R_RISCV_ADD32, /* type */ |
528 | | 0, /* rightshift */ |
529 | | 4, /* size */ |
530 | | 32, /* bitsize */ |
531 | | false, /* pc_relative */ |
532 | | 0, /* bitpos */ |
533 | | complain_overflow_dont, /* complain_on_overflow */ |
534 | | riscv_elf_add_sub_reloc, /* special_function */ |
535 | | "R_RISCV_ADD32", /* name */ |
536 | | false, /* partial_inplace */ |
537 | | 0, /* src_mask */ |
538 | | 0xffffffff, /* dst_mask */ |
539 | | false), /* pcrel_offset */ |
540 | | |
541 | | /* 64-bit in-place addition, for local label subtraction. */ |
542 | | HOWTO (R_RISCV_ADD64, /* type */ |
543 | | 0, /* rightshift */ |
544 | | 8, /* size */ |
545 | | 64, /* bitsize */ |
546 | | false, /* pc_relative */ |
547 | | 0, /* bitpos */ |
548 | | complain_overflow_dont, /* complain_on_overflow */ |
549 | | riscv_elf_add_sub_reloc, /* special_function */ |
550 | | "R_RISCV_ADD64", /* name */ |
551 | | false, /* partial_inplace */ |
552 | | 0, /* src_mask */ |
553 | | MINUS_ONE, /* dst_mask */ |
554 | | false), /* pcrel_offset */ |
555 | | |
556 | | /* 8-bit in-place addition, for local label subtraction. */ |
557 | | HOWTO (R_RISCV_SUB8, /* type */ |
558 | | 0, /* rightshift */ |
559 | | 1, /* size */ |
560 | | 8, /* bitsize */ |
561 | | false, /* pc_relative */ |
562 | | 0, /* bitpos */ |
563 | | complain_overflow_dont, /* complain_on_overflow */ |
564 | | riscv_elf_add_sub_reloc, /* special_function */ |
565 | | "R_RISCV_SUB8", /* name */ |
566 | | false, /* partial_inplace */ |
567 | | 0, /* src_mask */ |
568 | | 0xff, /* dst_mask */ |
569 | | false), /* pcrel_offset */ |
570 | | |
571 | | /* 16-bit in-place addition, for local label subtraction. */ |
572 | | HOWTO (R_RISCV_SUB16, /* type */ |
573 | | 0, /* rightshift */ |
574 | | 2, /* size */ |
575 | | 16, /* bitsize */ |
576 | | false, /* pc_relative */ |
577 | | 0, /* bitpos */ |
578 | | complain_overflow_dont, /* complain_on_overflow */ |
579 | | riscv_elf_add_sub_reloc, /* special_function */ |
580 | | "R_RISCV_SUB16", /* name */ |
581 | | false, /* partial_inplace */ |
582 | | 0, /* src_mask */ |
583 | | 0xffff, /* dst_mask */ |
584 | | false), /* pcrel_offset */ |
585 | | |
586 | | /* 32-bit in-place addition, for local label subtraction. */ |
587 | | HOWTO (R_RISCV_SUB32, /* type */ |
588 | | 0, /* rightshift */ |
589 | | 4, /* size */ |
590 | | 32, /* bitsize */ |
591 | | false, /* pc_relative */ |
592 | | 0, /* bitpos */ |
593 | | complain_overflow_dont, /* complain_on_overflow */ |
594 | | riscv_elf_add_sub_reloc, /* special_function */ |
595 | | "R_RISCV_SUB32", /* name */ |
596 | | false, /* partial_inplace */ |
597 | | 0, /* src_mask */ |
598 | | 0xffffffff, /* dst_mask */ |
599 | | false), /* pcrel_offset */ |
600 | | |
601 | | /* 64-bit in-place addition, for local label subtraction. */ |
602 | | HOWTO (R_RISCV_SUB64, /* type */ |
603 | | 0, /* rightshift */ |
604 | | 8, /* size */ |
605 | | 64, /* bitsize */ |
606 | | false, /* pc_relative */ |
607 | | 0, /* bitpos */ |
608 | | complain_overflow_dont, /* complain_on_overflow */ |
609 | | riscv_elf_add_sub_reloc, /* special_function */ |
610 | | "R_RISCV_SUB64", /* name */ |
611 | | false, /* partial_inplace */ |
612 | | 0, /* src_mask */ |
613 | | MINUS_ONE, /* dst_mask */ |
614 | | false), /* pcrel_offset */ |
615 | | |
616 | | EMPTY_HOWTO (41), |
617 | | EMPTY_HOWTO (42), |
618 | | |
619 | | /* Indicates an alignment statement. The addend field encodes how many |
620 | | bytes of NOPs follow the statement. The desired alignment is the |
621 | | addend rounded up to the next power of two. */ |
622 | | HOWTO (R_RISCV_ALIGN, /* type */ |
623 | | 0, /* rightshift */ |
624 | | 0, /* size */ |
625 | | 0, /* bitsize */ |
626 | | false, /* pc_relative */ |
627 | | 0, /* bitpos */ |
628 | | complain_overflow_dont, /* complain_on_overflow */ |
629 | | bfd_elf_generic_reloc, /* special_function */ |
630 | | "R_RISCV_ALIGN", /* name */ |
631 | | false, /* partial_inplace */ |
632 | | 0, /* src_mask */ |
633 | | 0, /* dst_mask */ |
634 | | false), /* pcrel_offset */ |
635 | | |
636 | | /* 8-bit PC-relative branch offset. */ |
637 | | HOWTO (R_RISCV_RVC_BRANCH, /* type */ |
638 | | 0, /* rightshift */ |
639 | | 2, /* size */ |
640 | | 16, /* bitsize */ |
641 | | true, /* pc_relative */ |
642 | | 0, /* bitpos */ |
643 | | complain_overflow_signed, /* complain_on_overflow */ |
644 | | bfd_elf_generic_reloc, /* special_function */ |
645 | | "R_RISCV_RVC_BRANCH", /* name */ |
646 | | false, /* partial_inplace */ |
647 | | 0, /* src_mask */ |
648 | | ENCODE_CBTYPE_IMM (-1U), /* dst_mask */ |
649 | | true), /* pcrel_offset */ |
650 | | |
651 | | /* 11-bit PC-relative jump offset. */ |
652 | | HOWTO (R_RISCV_RVC_JUMP, /* type */ |
653 | | 0, /* rightshift */ |
654 | | 2, /* size */ |
655 | | 16, /* bitsize */ |
656 | | true, /* pc_relative */ |
657 | | 0, /* bitpos */ |
658 | | complain_overflow_dont, /* complain_on_overflow */ |
659 | | bfd_elf_generic_reloc, /* special_function */ |
660 | | "R_RISCV_RVC_JUMP", /* name */ |
661 | | false, /* partial_inplace */ |
662 | | 0, /* src_mask */ |
663 | | ENCODE_CJTYPE_IMM (-1U), /* dst_mask */ |
664 | | true), /* pcrel_offset */ |
665 | | |
666 | | EMPTY_HOWTO (46), |
667 | | EMPTY_HOWTO (47), |
668 | | EMPTY_HOWTO (48), |
669 | | EMPTY_HOWTO (49), |
670 | | EMPTY_HOWTO (50), |
671 | | |
672 | | /* The paired relocation may be relaxed. */ |
673 | | HOWTO (R_RISCV_RELAX, /* type */ |
674 | | 0, /* rightshift */ |
675 | | 0, /* size */ |
676 | | 0, /* bitsize */ |
677 | | false, /* pc_relative */ |
678 | | 0, /* bitpos */ |
679 | | complain_overflow_dont, /* complain_on_overflow */ |
680 | | bfd_elf_generic_reloc, /* special_function */ |
681 | | "R_RISCV_RELAX", /* name */ |
682 | | false, /* partial_inplace */ |
683 | | 0, /* src_mask */ |
684 | | 0, /* dst_mask */ |
685 | | false), /* pcrel_offset */ |
686 | | |
687 | | /* 6-bit in-place addition, for local label subtraction. */ |
688 | | HOWTO (R_RISCV_SUB6, /* type */ |
689 | | 0, /* rightshift */ |
690 | | 1, /* size */ |
691 | | 8, /* bitsize */ |
692 | | false, /* pc_relative */ |
693 | | 0, /* bitpos */ |
694 | | complain_overflow_dont, /* complain_on_overflow */ |
695 | | riscv_elf_add_sub_reloc, /* special_function */ |
696 | | "R_RISCV_SUB6", /* name */ |
697 | | false, /* partial_inplace */ |
698 | | 0, /* src_mask */ |
699 | | 0x3f, /* dst_mask */ |
700 | | false), /* pcrel_offset */ |
701 | | |
702 | | /* 6-bit in-place setting, for local label subtraction. */ |
703 | | HOWTO (R_RISCV_SET6, /* type */ |
704 | | 0, /* rightshift */ |
705 | | 1, /* size */ |
706 | | 8, /* bitsize */ |
707 | | false, /* pc_relative */ |
708 | | 0, /* bitpos */ |
709 | | complain_overflow_dont, /* complain_on_overflow */ |
710 | | bfd_elf_generic_reloc, /* special_function */ |
711 | | "R_RISCV_SET6", /* name */ |
712 | | false, /* partial_inplace */ |
713 | | 0, /* src_mask */ |
714 | | 0x3f, /* dst_mask */ |
715 | | false), /* pcrel_offset */ |
716 | | |
717 | | /* 8-bit in-place setting, for local label subtraction. */ |
718 | | HOWTO (R_RISCV_SET8, /* type */ |
719 | | 0, /* rightshift */ |
720 | | 1, /* size */ |
721 | | 8, /* bitsize */ |
722 | | false, /* pc_relative */ |
723 | | 0, /* bitpos */ |
724 | | complain_overflow_dont, /* complain_on_overflow */ |
725 | | bfd_elf_generic_reloc, /* special_function */ |
726 | | "R_RISCV_SET8", /* name */ |
727 | | false, /* partial_inplace */ |
728 | | 0, /* src_mask */ |
729 | | 0xff, /* dst_mask */ |
730 | | false), /* pcrel_offset */ |
731 | | |
732 | | /* 16-bit in-place setting, for local label subtraction. */ |
733 | | HOWTO (R_RISCV_SET16, /* type */ |
734 | | 0, /* rightshift */ |
735 | | 2, /* size */ |
736 | | 16, /* bitsize */ |
737 | | false, /* pc_relative */ |
738 | | 0, /* bitpos */ |
739 | | complain_overflow_dont, /* complain_on_overflow */ |
740 | | bfd_elf_generic_reloc, /* special_function */ |
741 | | "R_RISCV_SET16", /* name */ |
742 | | false, /* partial_inplace */ |
743 | | 0, /* src_mask */ |
744 | | 0xffff, /* dst_mask */ |
745 | | false), /* pcrel_offset */ |
746 | | |
747 | | /* 32-bit in-place setting, for local label subtraction. */ |
748 | | HOWTO (R_RISCV_SET32, /* type */ |
749 | | 0, /* rightshift */ |
750 | | 4, /* size */ |
751 | | 32, /* bitsize */ |
752 | | false, /* pc_relative */ |
753 | | 0, /* bitpos */ |
754 | | complain_overflow_dont, /* complain_on_overflow */ |
755 | | bfd_elf_generic_reloc, /* special_function */ |
756 | | "R_RISCV_SET32", /* name */ |
757 | | false, /* partial_inplace */ |
758 | | 0, /* src_mask */ |
759 | | 0xffffffff, /* dst_mask */ |
760 | | false), /* pcrel_offset */ |
761 | | |
762 | | /* 32-bit PC relative. */ |
763 | | HOWTO (R_RISCV_32_PCREL, /* type */ |
764 | | 0, /* rightshift */ |
765 | | 4, /* size */ |
766 | | 32, /* bitsize */ |
767 | | true, /* pc_relative */ |
768 | | 0, /* bitpos */ |
769 | | complain_overflow_dont, /* complain_on_overflow */ |
770 | | bfd_elf_generic_reloc, /* special_function */ |
771 | | "R_RISCV_32_PCREL", /* name */ |
772 | | false, /* partial_inplace */ |
773 | | 0, /* src_mask */ |
774 | | 0xffffffff, /* dst_mask */ |
775 | | false), /* pcrel_offset */ |
776 | | |
777 | | /* Relocation against a local ifunc symbol in a shared object. */ |
778 | | HOWTO (R_RISCV_IRELATIVE, /* type */ |
779 | | 0, /* rightshift */ |
780 | | 4, /* size */ |
781 | | 32, /* bitsize */ |
782 | | false, /* pc_relative */ |
783 | | 0, /* bitpos */ |
784 | | complain_overflow_dont, /* complain_on_overflow */ |
785 | | bfd_elf_generic_reloc, /* special_function */ |
786 | | "R_RISCV_IRELATIVE", /* name */ |
787 | | false, /* partial_inplace */ |
788 | | 0, /* src_mask */ |
789 | | 0xffffffff, /* dst_mask */ |
790 | | false), /* pcrel_offset */ |
791 | | |
792 | | /* Reserved for R_RISCV_PLT32. */ |
793 | | EMPTY_HOWTO (59), |
794 | | |
795 | | /* N-bit in-place setting, for unsigned-leb128 local label subtraction. */ |
796 | | HOWTO (R_RISCV_SET_ULEB128, /* type */ |
797 | | 0, /* rightshift */ |
798 | | 0, /* size */ |
799 | | 0, /* bitsize */ |
800 | | false, /* pc_relative */ |
801 | | 0, /* bitpos */ |
802 | | complain_overflow_dont, /* complain_on_overflow */ |
803 | | riscv_elf_ignore_reloc, /* special_function */ |
804 | | "R_RISCV_SET_ULEB128", /* name */ |
805 | | false, /* partial_inplace */ |
806 | | 0, /* src_mask */ |
807 | | 0, /* dst_mask */ |
808 | | false), /* pcrel_offset */ |
809 | | |
810 | | /* N-bit in-place addition, for unsigned-leb128 local label subtraction. */ |
811 | | HOWTO (R_RISCV_SUB_ULEB128, /* type */ |
812 | | 0, /* rightshift */ |
813 | | 0, /* size */ |
814 | | 0, /* bitsize */ |
815 | | false, /* pc_relative */ |
816 | | 0, /* bitpos */ |
817 | | complain_overflow_dont, /* complain_on_overflow */ |
818 | | riscv_elf_ignore_reloc, /* special_function */ |
819 | | "R_RISCV_SUB_ULEB128", /* name */ |
820 | | false, /* partial_inplace */ |
821 | | 0, /* src_mask */ |
822 | | 0, /* dst_mask */ |
823 | | false), /* pcrel_offset */ |
824 | | |
825 | | HOWTO (R_RISCV_TLSDESC_HI20, /* type */ |
826 | | 0, /* rightshift */ |
827 | | 4, /* size */ |
828 | | 32, /* bitsize */ |
829 | | true, /* pc_relative */ |
830 | | 0, /* bitpos */ |
831 | | complain_overflow_dont, /* complain_on_overflow */ |
832 | | bfd_elf_generic_reloc, /* special_function */ |
833 | | "R_RISCV_TLSDESC_HI20", /* name */ |
834 | | true, /* partial_inplace */ |
835 | | 0, /* src_mask */ |
836 | | ENCODE_UTYPE_IMM (-1U), /* dst_mask */ |
837 | | false), /* pcrel_offset */ |
838 | | |
839 | | HOWTO (R_RISCV_TLSDESC_LOAD_LO12, /* type */ |
840 | | 0, /* rightshift */ |
841 | | 4, /* size */ |
842 | | 32, /* bitsize */ |
843 | | false, /* pc_relative */ |
844 | | 0, /* bitpos */ |
845 | | complain_overflow_dont, /* complain_on_overflow */ |
846 | | bfd_elf_generic_reloc, /* special_function */ |
847 | | "R_RISCV_TLSDESC_LOAD_LO12", /* name */ |
848 | | false, /* partial_inplace */ |
849 | | 0, /* src_mask */ |
850 | | ENCODE_ITYPE_IMM (-1U), /* dst_mask */ |
851 | | false), /* pcrel_offset */ |
852 | | |
853 | | HOWTO (R_RISCV_TLSDESC_ADD_LO12, /* type */ |
854 | | 0, /* rightshift */ |
855 | | 4, /* size */ |
856 | | 32, /* bitsize */ |
857 | | false, /* pc_relative */ |
858 | | 0, /* bitpos */ |
859 | | complain_overflow_dont, /* complain_on_overflow */ |
860 | | bfd_elf_generic_reloc, /* special_function */ |
861 | | "R_RISCV_TLSDESC_ADD_LO12", /* name */ |
862 | | false, /* partial_inplace */ |
863 | | 0, /* src_mask */ |
864 | | ENCODE_ITYPE_IMM (-1U), /* dst_mask */ |
865 | | false), /* pcrel_offset */ |
866 | | |
867 | | HOWTO (R_RISCV_TLSDESC_CALL, /* type */ |
868 | | 0, /* rightshift */ |
869 | | 0, /* size */ |
870 | | 0, /* bitsize */ |
871 | | false, /* pc_relative */ |
872 | | 0, /* bitpos */ |
873 | | complain_overflow_dont, /* complain_on_overflow */ |
874 | | bfd_elf_generic_reloc, /* special_function */ |
875 | | "R_RISCV_TLSDESC_CALL", /* name */ |
876 | | false, /* partial_inplace */ |
877 | | 0, /* src_mask */ |
878 | | ENCODE_ITYPE_IMM (-1U), /* dst_mask */ |
879 | | false) /* pcrel_offset */ |
880 | | }; |
881 | | |
882 | | static const reloc_howto_type howto_table_internal[] = |
883 | | { |
884 | | /* R_RISCV_DELETE. */ |
885 | | EMPTY_HOWTO (0), |
886 | | |
887 | | /* R_RISCV_DELETE_AND_RELAX. */ |
888 | | EMPTY_HOWTO (0), |
889 | | |
890 | | /* High 6 bits of 18-bit absolute address. */ |
891 | | HOWTO (R_RISCV_RVC_LUI, /* type */ |
892 | | 0, /* rightshift */ |
893 | | 2, /* size */ |
894 | | 16, /* bitsize */ |
895 | | false, /* pc_relative */ |
896 | | 0, /* bitpos */ |
897 | | complain_overflow_dont, /* complain_on_overflow */ |
898 | | bfd_elf_generic_reloc, /* special_function */ |
899 | | "R_RISCV_RVC_LUI", /* name */ |
900 | | false, /* partial_inplace */ |
901 | | 0, /* src_mask */ |
902 | | ENCODE_CITYPE_IMM (-1U), /* dst_mask */ |
903 | | false), /* pcrel_offset */ |
904 | | |
905 | | /* GP-relative load. */ |
906 | | HOWTO (R_RISCV_GPREL_I, /* type */ |
907 | | 0, /* rightshift */ |
908 | | 4, /* size */ |
909 | | 32, /* bitsize */ |
910 | | false, /* pc_relative */ |
911 | | 0, /* bitpos */ |
912 | | complain_overflow_dont, /* complain_on_overflow */ |
913 | | bfd_elf_generic_reloc, /* special_function */ |
914 | | "R_RISCV_GPREL_I", /* name */ |
915 | | false, /* partial_inplace */ |
916 | | 0, /* src_mask */ |
917 | | ENCODE_ITYPE_IMM (-1U), /* dst_mask */ |
918 | | false), /* pcrel_offset */ |
919 | | |
920 | | /* GP-relative store. */ |
921 | | HOWTO (R_RISCV_GPREL_S, /* type */ |
922 | | 0, /* rightshift */ |
923 | | 4, /* size */ |
924 | | 32, /* bitsize */ |
925 | | false, /* pc_relative */ |
926 | | 0, /* bitpos */ |
927 | | complain_overflow_dont, /* complain_on_overflow */ |
928 | | bfd_elf_generic_reloc, /* special_function */ |
929 | | "R_RISCV_GPREL_S", /* name */ |
930 | | false, /* partial_inplace */ |
931 | | 0, /* src_mask */ |
932 | | ENCODE_STYPE_IMM (-1U), /* dst_mask */ |
933 | | false), /* pcrel_offset */ |
934 | | |
935 | | /* TP-relative TLS LE load. */ |
936 | | HOWTO (R_RISCV_TPREL_I, /* type */ |
937 | | 0, /* rightshift */ |
938 | | 4, /* size */ |
939 | | 32, /* bitsize */ |
940 | | false, /* pc_relative */ |
941 | | 0, /* bitpos */ |
942 | | complain_overflow_signed, /* complain_on_overflow */ |
943 | | bfd_elf_generic_reloc, /* special_function */ |
944 | | "R_RISCV_TPREL_I", /* name */ |
945 | | false, /* partial_inplace */ |
946 | | 0, /* src_mask */ |
947 | | ENCODE_ITYPE_IMM (-1U), /* dst_mask */ |
948 | | false), /* pcrel_offset */ |
949 | | |
950 | | /* TP-relative TLS LE store. */ |
951 | | HOWTO (R_RISCV_TPREL_S, /* type */ |
952 | | 0, /* rightshift */ |
953 | | 4, /* size */ |
954 | | 32, /* bitsize */ |
955 | | false, /* pc_relative */ |
956 | | 0, /* bitpos */ |
957 | | complain_overflow_signed, /* complain_on_overflow */ |
958 | | bfd_elf_generic_reloc, /* special_function */ |
959 | | "R_RISCV_TPREL_S", /* name */ |
960 | | false, /* partial_inplace */ |
961 | | 0, /* src_mask */ |
962 | | ENCODE_STYPE_IMM (-1U), /* dst_mask */ |
963 | | false), /* pcrel_offset */ |
964 | | |
965 | | /* R_RISCV_TABLE_JUMP. */ |
966 | | EMPTY_HOWTO (0), |
967 | | |
968 | | /* TLSDESC relaxed to Initial Exec. */ |
969 | | HOWTO (R_RISCV_TLSDESC_IE_HI, /* type */ |
970 | | 0, /* rightshift */ |
971 | | 4, /* size */ |
972 | | 32, /* bitsize */ |
973 | | true, /* pc_relative */ |
974 | | 0, /* bitpos */ |
975 | | complain_overflow_signed, /* complain_on_overflow */ |
976 | | bfd_elf_generic_reloc, /* special_function */ |
977 | | "R_RISCV_TLSDESC_IE_HI", /* name */ |
978 | | false, /* partial_inplace */ |
979 | | 0, /* src_mask */ |
980 | | ENCODE_UTYPE_IMM (-1U), /* dst_mask */ |
981 | | false), /* pcrel_offset */ |
982 | | HOWTO (R_RISCV_TLSDESC_IE_LO, /* type */ |
983 | | 0, /* rightshift */ |
984 | | 4, /* size */ |
985 | | 32, /* bitsize */ |
986 | | false, /* pc_relative */ |
987 | | 0, /* bitpos */ |
988 | | complain_overflow_signed, /* complain_on_overflow */ |
989 | | bfd_elf_generic_reloc, /* special_function */ |
990 | | "R_RISCV_TLSDESC_IE_LO", /* name */ |
991 | | false, /* partial_inplace */ |
992 | | 0, /* src_mask */ |
993 | | ENCODE_ITYPE_IMM (-1U), /* dst_mask */ |
994 | | false), /* pcrel_offset */ |
995 | | /* TLSDESC relaxed to Local Exec. */ |
996 | | HOWTO (R_RISCV_TLSDESC_LE_HI, /* type */ |
997 | | 0, /* rightshift */ |
998 | | 4, /* size */ |
999 | | 32, /* bitsize */ |
1000 | | false, /* pc_relative */ |
1001 | | 0, /* bitpos */ |
1002 | | complain_overflow_signed, /* complain_on_overflow */ |
1003 | | bfd_elf_generic_reloc, /* special_function */ |
1004 | | "R_RISCV_TLSDESC_LE_HI", /* name */ |
1005 | | false, /* partial_inplace */ |
1006 | | 0, /* src_mask */ |
1007 | | ENCODE_UTYPE_IMM (-1U), /* dst_mask */ |
1008 | | false), /* pcrel_offset */ |
1009 | | HOWTO (R_RISCV_TLSDESC_LE_LO, /* type */ |
1010 | | 0, /* rightshift */ |
1011 | | 4, /* size */ |
1012 | | 32, /* bitsize */ |
1013 | | false, /* pc_relative */ |
1014 | | 0, /* bitpos */ |
1015 | | complain_overflow_signed, /* complain_on_overflow */ |
1016 | | bfd_elf_generic_reloc, /* special_function */ |
1017 | | "R_RISCV_TLSDESC_LE_LO", /* name */ |
1018 | | false, /* partial_inplace */ |
1019 | | 0, /* src_mask */ |
1020 | | ENCODE_ITYPE_IMM (-1U), /* dst_mask */ |
1021 | | false), /* pcrel_offset */ |
1022 | | }; |
1023 | | |
1024 | | /* A mapping from BFD reloc types to RISC-V ELF reloc types. */ |
1025 | | struct elf_reloc_map |
1026 | | { |
1027 | | bfd_reloc_code_real_type bfd_val; |
1028 | | enum elf_riscv_reloc_type elf_val; |
1029 | | }; |
1030 | | |
1031 | | static const struct elf_reloc_map riscv_reloc_map[] = |
1032 | | { |
1033 | | { BFD_RELOC_NONE, R_RISCV_NONE }, |
1034 | | { BFD_RELOC_32, R_RISCV_32 }, |
1035 | | { BFD_RELOC_64, R_RISCV_64 }, |
1036 | | { BFD_RELOC_RISCV_ADD8, R_RISCV_ADD8 }, |
1037 | | { BFD_RELOC_RISCV_ADD16, R_RISCV_ADD16 }, |
1038 | | { BFD_RELOC_RISCV_ADD32, R_RISCV_ADD32 }, |
1039 | | { BFD_RELOC_RISCV_ADD64, R_RISCV_ADD64 }, |
1040 | | { BFD_RELOC_RISCV_SUB8, R_RISCV_SUB8 }, |
1041 | | { BFD_RELOC_RISCV_SUB16, R_RISCV_SUB16 }, |
1042 | | { BFD_RELOC_RISCV_SUB32, R_RISCV_SUB32 }, |
1043 | | { BFD_RELOC_RISCV_SUB64, R_RISCV_SUB64 }, |
1044 | | { BFD_RELOC_CTOR, R_RISCV_64 }, |
1045 | | { BFD_RELOC_12_PCREL, R_RISCV_BRANCH }, |
1046 | | { BFD_RELOC_RISCV_HI20, R_RISCV_HI20 }, |
1047 | | { BFD_RELOC_RISCV_LO12_I, R_RISCV_LO12_I }, |
1048 | | { BFD_RELOC_RISCV_LO12_S, R_RISCV_LO12_S }, |
1049 | | { BFD_RELOC_RISCV_PCREL_LO12_I, R_RISCV_PCREL_LO12_I }, |
1050 | | { BFD_RELOC_RISCV_PCREL_LO12_S, R_RISCV_PCREL_LO12_S }, |
1051 | | { BFD_RELOC_RISCV_CALL, R_RISCV_CALL }, |
1052 | | { BFD_RELOC_RISCV_CALL_PLT, R_RISCV_CALL_PLT }, |
1053 | | { BFD_RELOC_RISCV_PCREL_HI20, R_RISCV_PCREL_HI20 }, |
1054 | | { BFD_RELOC_RISCV_JMP, R_RISCV_JAL }, |
1055 | | { BFD_RELOC_RISCV_GOT_HI20, R_RISCV_GOT_HI20 }, |
1056 | | { BFD_RELOC_RISCV_TLS_DTPMOD32, R_RISCV_TLS_DTPMOD32 }, |
1057 | | { BFD_RELOC_RISCV_TLS_DTPREL32, R_RISCV_TLS_DTPREL32 }, |
1058 | | { BFD_RELOC_RISCV_TLS_DTPMOD64, R_RISCV_TLS_DTPMOD64 }, |
1059 | | { BFD_RELOC_RISCV_TLS_DTPREL64, R_RISCV_TLS_DTPREL64 }, |
1060 | | { BFD_RELOC_RISCV_TLS_TPREL32, R_RISCV_TLS_TPREL32 }, |
1061 | | { BFD_RELOC_RISCV_TLS_TPREL64, R_RISCV_TLS_TPREL64 }, |
1062 | | { BFD_RELOC_RISCV_TPREL_HI20, R_RISCV_TPREL_HI20 }, |
1063 | | { BFD_RELOC_RISCV_TPREL_ADD, R_RISCV_TPREL_ADD }, |
1064 | | { BFD_RELOC_RISCV_TPREL_LO12_S, R_RISCV_TPREL_LO12_S }, |
1065 | | { BFD_RELOC_RISCV_TPREL_LO12_I, R_RISCV_TPREL_LO12_I }, |
1066 | | { BFD_RELOC_RISCV_TLS_GOT_HI20, R_RISCV_TLS_GOT_HI20 }, |
1067 | | { BFD_RELOC_RISCV_TLS_GD_HI20, R_RISCV_TLS_GD_HI20 }, |
1068 | | { BFD_RELOC_RISCV_TLSDESC_HI20, R_RISCV_TLSDESC_HI20 }, |
1069 | | { BFD_RELOC_RISCV_TLSDESC_LOAD_LO12, R_RISCV_TLSDESC_LOAD_LO12 }, |
1070 | | { BFD_RELOC_RISCV_TLSDESC_ADD_LO12, R_RISCV_TLSDESC_ADD_LO12 }, |
1071 | | { BFD_RELOC_RISCV_TLSDESC_CALL, R_RISCV_TLSDESC_CALL }, |
1072 | | { BFD_RELOC_RISCV_ALIGN, R_RISCV_ALIGN }, |
1073 | | { BFD_RELOC_RISCV_RVC_BRANCH, R_RISCV_RVC_BRANCH }, |
1074 | | { BFD_RELOC_RISCV_RVC_JUMP, R_RISCV_RVC_JUMP }, |
1075 | | { BFD_RELOC_RISCV_RELAX, R_RISCV_RELAX }, |
1076 | | { BFD_RELOC_RISCV_SUB6, R_RISCV_SUB6 }, |
1077 | | { BFD_RELOC_RISCV_SET6, R_RISCV_SET6 }, |
1078 | | { BFD_RELOC_RISCV_SET8, R_RISCV_SET8 }, |
1079 | | { BFD_RELOC_RISCV_SET16, R_RISCV_SET16 }, |
1080 | | { BFD_RELOC_RISCV_SET32, R_RISCV_SET32 }, |
1081 | | { BFD_RELOC_32_PCREL, R_RISCV_32_PCREL }, |
1082 | | { BFD_RELOC_RISCV_SET_ULEB128, R_RISCV_SET_ULEB128 }, |
1083 | | { BFD_RELOC_RISCV_SUB_ULEB128, R_RISCV_SUB_ULEB128 }, |
1084 | | }; |
1085 | | |
1086 | | struct riscv_profiles |
1087 | | { |
1088 | | const char *profile_name; |
1089 | | const char *profile_string; |
1090 | | }; |
1091 | | |
1092 | | /* Given a BFD reloc type, return a howto structure. */ |
1093 | | |
1094 | | reloc_howto_type * |
1095 | | riscv_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
1096 | | bfd_reloc_code_real_type code) |
1097 | 0 | { |
1098 | 0 | unsigned int i; |
1099 | |
|
1100 | 0 | for (i = 0; i < ARRAY_SIZE (riscv_reloc_map); i++) |
1101 | 0 | if (riscv_reloc_map[i].bfd_val == code) |
1102 | 0 | return &howto_table[(int) riscv_reloc_map[i].elf_val]; |
1103 | | |
1104 | 0 | bfd_set_error (bfd_error_bad_value); |
1105 | 0 | return NULL; |
1106 | 0 | } |
1107 | | |
1108 | | reloc_howto_type * |
1109 | | riscv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) |
1110 | 0 | { |
1111 | 0 | unsigned int i; |
1112 | |
|
1113 | 0 | for (i = 0; i < ARRAY_SIZE (howto_table); i++) |
1114 | 0 | if (howto_table[i].name && strcasecmp (howto_table[i].name, r_name) == 0) |
1115 | 0 | return &howto_table[i]; |
1116 | | |
1117 | 0 | return NULL; |
1118 | 0 | } |
1119 | | |
1120 | | reloc_howto_type * |
1121 | | riscv_elf_rtype_to_howto (bfd *abfd, unsigned int r_type) |
1122 | 3.60k | { |
1123 | 3.60k | if (r_type < ARRAY_SIZE (howto_table)) |
1124 | 3.30k | return &howto_table[r_type]; |
1125 | 308 | else if (r_type < R_RISCV_max + ARRAY_SIZE (howto_table_internal)) |
1126 | 59 | return &howto_table_internal[r_type - R_RISCV_max]; |
1127 | 249 | else |
1128 | 249 | { |
1129 | 249 | (*_bfd_error_handler) (_("%pB: unsupported relocation type %#x"), |
1130 | 249 | abfd, r_type); |
1131 | 249 | bfd_set_error (bfd_error_bad_value); |
1132 | 249 | return NULL; |
1133 | 249 | } |
1134 | 3.60k | } |
1135 | | |
1136 | | /* Special_function of RISCV_ADD and RISCV_SUB relocations. */ |
1137 | | |
1138 | | static bfd_reloc_status_type |
1139 | | riscv_elf_add_sub_reloc (bfd *abfd, |
1140 | | arelent *reloc_entry, |
1141 | | asymbol *symbol, |
1142 | | void *data, |
1143 | | asection *input_section, |
1144 | | bfd *output_bfd, |
1145 | | char **error_message ATTRIBUTE_UNUSED) |
1146 | 9 | { |
1147 | 9 | reloc_howto_type *howto = reloc_entry->howto; |
1148 | 9 | bfd_vma relocation; |
1149 | | |
1150 | 9 | if (output_bfd != NULL |
1151 | 0 | && (symbol->flags & BSF_SECTION_SYM) == 0 |
1152 | 0 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) |
1153 | 0 | { |
1154 | 0 | reloc_entry->address += input_section->output_offset; |
1155 | 0 | return bfd_reloc_ok; |
1156 | 0 | } |
1157 | | |
1158 | 9 | if (output_bfd != NULL) |
1159 | 0 | return bfd_reloc_continue; |
1160 | | |
1161 | 9 | relocation = symbol->value + symbol->section->output_section->vma |
1162 | 9 | + symbol->section->output_offset + reloc_entry->addend; |
1163 | | |
1164 | 9 | bfd_size_type octets = reloc_entry->address |
1165 | 9 | * bfd_octets_per_byte (abfd, input_section); |
1166 | 9 | if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd, |
1167 | 9 | input_section, octets)) |
1168 | 1 | return bfd_reloc_outofrange; |
1169 | | |
1170 | 8 | bfd_vma old_value = bfd_get (howto->bitsize, abfd, |
1171 | 8 | data + reloc_entry->address); |
1172 | | |
1173 | 8 | switch (howto->type) |
1174 | 8 | { |
1175 | 2 | case R_RISCV_ADD8: |
1176 | 2 | case R_RISCV_ADD16: |
1177 | 2 | case R_RISCV_ADD32: |
1178 | 3 | case R_RISCV_ADD64: |
1179 | 3 | relocation = old_value + relocation; |
1180 | 3 | break; |
1181 | 1 | case R_RISCV_SUB6: |
1182 | 1 | relocation = (old_value & ~howto->dst_mask) |
1183 | 1 | | (((old_value & howto->dst_mask) - relocation) |
1184 | 1 | & howto->dst_mask); |
1185 | 1 | break; |
1186 | 0 | case R_RISCV_SUB8: |
1187 | 4 | case R_RISCV_SUB16: |
1188 | 4 | case R_RISCV_SUB32: |
1189 | 4 | case R_RISCV_SUB64: |
1190 | 4 | relocation = old_value - relocation; |
1191 | 4 | break; |
1192 | 8 | } |
1193 | 8 | bfd_put (howto->bitsize, abfd, relocation, data + reloc_entry->address); |
1194 | | |
1195 | 8 | return bfd_reloc_ok; |
1196 | 8 | } |
1197 | | |
1198 | | /* Special handler for relocations which don't have to be relocated. |
1199 | | This function just simply return bfd_reloc_ok. */ |
1200 | | |
1201 | | static bfd_reloc_status_type |
1202 | | riscv_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, |
1203 | | arelent *reloc_entry, |
1204 | | asymbol *symbol ATTRIBUTE_UNUSED, |
1205 | | void *data ATTRIBUTE_UNUSED, |
1206 | | asection *input_section, |
1207 | | bfd *output_bfd, |
1208 | | char **error_message ATTRIBUTE_UNUSED) |
1209 | 1 | { |
1210 | 1 | if (output_bfd != NULL) |
1211 | 0 | reloc_entry->address += input_section->output_offset; |
1212 | 1 | return bfd_reloc_ok; |
1213 | 1 | } |
1214 | | |
1215 | | /* Always add implicit extensions for the SUBSET. */ |
1216 | | |
1217 | | static bool |
1218 | | check_implicit_always (riscv_parse_subset_t *rps ATTRIBUTE_UNUSED, |
1219 | | const riscv_subset_t *subset ATTRIBUTE_UNUSED) |
1220 | 9.69k | { |
1221 | 9.69k | return true; |
1222 | 9.69k | } |
1223 | | |
1224 | | /* Add implicit extensions only when the version of SUBSET less than 2.1. */ |
1225 | | |
1226 | | static bool |
1227 | | check_implicit_for_i (riscv_parse_subset_t *rps ATTRIBUTE_UNUSED, |
1228 | | const riscv_subset_t *subset ATTRIBUTE_UNUSED) |
1229 | 1.61k | { |
1230 | 1.61k | return (subset->major_version < 2 |
1231 | 1.61k | || (subset->major_version == 2 |
1232 | 1.61k | && subset->minor_version < 1)); |
1233 | 1.61k | } |
1234 | | |
1235 | | /* Add the IMPLICIT only when the 'f' extension is also available |
1236 | | and XLEN is 32. */ |
1237 | | |
1238 | | static bool |
1239 | | check_implicit_for_zcf (riscv_parse_subset_t *rps, |
1240 | | const riscv_subset_t *subset ATTRIBUTE_UNUSED) |
1241 | 1.61k | { |
1242 | 1.61k | return (rps != NULL |
1243 | 1.61k | && rps->xlen != NULL |
1244 | 1.61k | && *rps->xlen == 32 |
1245 | 0 | && riscv_subset_supports (rps, "f")); |
1246 | 1.61k | } |
1247 | | |
1248 | | /* Add the implicit only when 'd' extension is also available. */ |
1249 | | |
1250 | | static bool |
1251 | | check_implicit_for_zcd (riscv_parse_subset_t *rps, |
1252 | | const riscv_subset_t *subset ATTRIBUTE_UNUSED) |
1253 | 1.61k | { |
1254 | 1.61k | return (rps != NULL |
1255 | 1.61k | && riscv_subset_supports (rps, "d")); |
1256 | 1.61k | } |
1257 | | |
1258 | | /* Record all implicit information for the subsets. */ |
1259 | | struct riscv_implicit_subset |
1260 | | { |
1261 | | const char *ext; |
1262 | | const char *implicit_exts; |
1263 | | /* A function to determine if we need to add the implicit subsets. */ |
1264 | | bool (*check_func) (riscv_parse_subset_t *, |
1265 | | const riscv_subset_t *); |
1266 | | }; |
1267 | | /* Please added in order since this table is only run once time. */ |
1268 | | static const struct riscv_implicit_subset riscv_implicit_subsets[] = |
1269 | | { |
1270 | | {"g", "+i,+m,+a,+f,+d,+zicsr,+zifencei", check_implicit_always}, |
1271 | | {"e", "+i", check_implicit_always}, |
1272 | | {"i", "+zicsr,+zifencei", check_implicit_for_i}, |
1273 | | {"ziccid", "+ziccif", check_implicit_always}, |
1274 | | {"zicntr", "+zicsr", check_implicit_always}, |
1275 | | {"zihpm", "+zicsr", check_implicit_always}, |
1276 | | |
1277 | | {"m", "+zmmul", check_implicit_always}, |
1278 | | |
1279 | | {"zabha", "+zaamo", check_implicit_always}, |
1280 | | {"zacas", "+zaamo", check_implicit_always}, |
1281 | | {"a", "+zaamo,+zalrsc", check_implicit_always}, |
1282 | | {"zalasr", "+zaamo,+zalrsc,+zabha", check_implicit_always}, |
1283 | | |
1284 | | {"xsfvcp", "+zve32x", check_implicit_always}, |
1285 | | {"xsfvqmaccqoq", "+zve32x,+zvl256b", check_implicit_always}, |
1286 | | {"xsfvqmaccdod", "+zve32x,+zvl128b", check_implicit_always}, |
1287 | | {"xsfvfnrclipxfqf", "+zve32f", check_implicit_always}, |
1288 | | |
1289 | | {"xsmtvdot", "+zve32x", check_implicit_always}, |
1290 | | {"xsmtvdotii", "+xsmtvdot", check_implicit_always}, |
1291 | | |
1292 | | {"xtheadvector", "+zicsr", check_implicit_always}, |
1293 | | {"xtheadzvamo", "+zaamo", check_implicit_always}, |
1294 | | |
1295 | | {"xxtvarith", "+v", check_implicit_always}, |
1296 | | {"xxtvcoder", "+v", check_implicit_always}, |
1297 | | |
1298 | | {"v", "+zve64d,+zvl128b", check_implicit_always}, |
1299 | | {"zvabd", "+zve32x", check_implicit_always}, |
1300 | | {"zvfh", "+zvfhmin,+zfhmin", check_implicit_always}, |
1301 | | {"zvfhmin", "+zve32f", check_implicit_always}, |
1302 | | {"zvfbfwma", "+zfbfmin,+zvfbfmin", check_implicit_always}, |
1303 | | {"zvfbfmin", "+zve32f", check_implicit_always}, |
1304 | | {"zvfbdota32f", "+zve32f", check_implicit_always}, |
1305 | | {"zvfqwbdota8f", "+zve32f", check_implicit_always}, |
1306 | | {"zvfqwdota8f", "+zve32f", check_implicit_always}, |
1307 | | {"zvfwbdota16bf", "+zve32f", check_implicit_always}, |
1308 | | {"zvfwdota16bf", "+zve32f", check_implicit_always}, |
1309 | | |
1310 | | {"zvbb", "+zvkb", check_implicit_always}, |
1311 | | {"zvkng", "+zvkn,+zvkg", check_implicit_always}, |
1312 | | {"zvknc", "+zvkn,+zvbc", check_implicit_always}, |
1313 | | {"zvkn", "+zvkned,+zvknhb,+zvkb,+zvkt", check_implicit_always}, |
1314 | | {"zvksg", "+zvks,+zvkg", check_implicit_always}, |
1315 | | {"zvksc", "+zvks,+zvbc", check_implicit_always}, |
1316 | | {"zvks", "+zvksed,+zvksh,+zvkb,+zvkt", check_implicit_always}, |
1317 | | |
1318 | | {"zvbc", "+zve32x", check_implicit_always}, |
1319 | | {"zvkb", "+zve32x", check_implicit_always}, |
1320 | | {"zvkg", "+zve32x", check_implicit_always}, |
1321 | | {"zvkned", "+zve32x", check_implicit_always}, |
1322 | | {"zvknha", "+zve32x", check_implicit_always}, |
1323 | | {"zvknhb", "+zvknha,+zve32x", check_implicit_always}, |
1324 | | {"zvksed", "+zve32x", check_implicit_always}, |
1325 | | {"zvksh", "+zve32x", check_implicit_always}, |
1326 | | |
1327 | | {"zvqwbdota8i", "+zve32x", check_implicit_always}, |
1328 | | {"zvqwbdota16i", "+zve64x", check_implicit_always}, |
1329 | | {"zvqwdota8i", "+zve32x", check_implicit_always}, |
1330 | | {"zvqwdota16i", "+zve64x", check_implicit_always}, |
1331 | | |
1332 | | {"zve64d", "+d,+zve64f", check_implicit_always}, |
1333 | | {"zve64f", "+zve32f,+zve64x", check_implicit_always}, |
1334 | | {"zve32f", "+f,+zve32x", check_implicit_always}, |
1335 | | {"zve64x", "+zve32x,+zvl64b", check_implicit_always}, |
1336 | | {"zve32x", "+zvl32b,+zicsr", check_implicit_always}, |
1337 | | |
1338 | | {"zvl65536b", "+zvl32768b", check_implicit_always}, |
1339 | | {"zvl32768b", "+zvl16384b", check_implicit_always}, |
1340 | | {"zvl16384b", "+zvl8192b", check_implicit_always}, |
1341 | | {"zvl8192b", "+zvl4096b", check_implicit_always}, |
1342 | | {"zvl4096b", "+zvl2048b", check_implicit_always}, |
1343 | | {"zvl2048b", "+zvl1024b", check_implicit_always}, |
1344 | | {"zvl1024b", "+zvl512b", check_implicit_always}, |
1345 | | {"zvl512b", "+zvl256b", check_implicit_always}, |
1346 | | {"zvl256b", "+zvl128b", check_implicit_always}, |
1347 | | {"zvl128b", "+zvl64b", check_implicit_always}, |
1348 | | {"zvl64b", "+zvl32b", check_implicit_always}, |
1349 | | |
1350 | | {"zicfilp", "+zicsr", check_implicit_always}, |
1351 | | {"zicfiss", "+zimop,+zicsr", check_implicit_always}, |
1352 | | {"zclsd", "+zca,+zilsd", check_implicit_always}, |
1353 | | |
1354 | | {"sha", "+h,+ssstateen,+shcounterenw,+shvstvala,+shtvala,+shvstvecd,+shvsatpa,+shgatpa", check_implicit_always}, |
1355 | | |
1356 | | {"shcounterenw", "+h", check_implicit_always}, |
1357 | | {"shgatpa", "+h", check_implicit_always}, |
1358 | | {"shlcofideleg", "+h", check_implicit_always}, |
1359 | | {"shtvala", "+h", check_implicit_always}, |
1360 | | {"shvsatpa", "+h", check_implicit_always}, |
1361 | | {"shvstvala", "+h", check_implicit_always}, |
1362 | | {"shvstvecd", "+h", check_implicit_always}, |
1363 | | {"h", "+zicsr", check_implicit_always}, |
1364 | | {"zhinx", "+zhinxmin", check_implicit_always}, |
1365 | | {"zhinxmin", "+zfinx", check_implicit_always}, |
1366 | | |
1367 | | {"zcd", "+d,+zca", check_implicit_always}, |
1368 | | {"zcf", "+f,+zca", check_implicit_always}, |
1369 | | |
1370 | | {"q", "+d", check_implicit_always}, |
1371 | | {"zqinx", "+zdinx", check_implicit_always}, |
1372 | | |
1373 | | {"d", "+f", check_implicit_always}, |
1374 | | {"zdinx", "+zfinx", check_implicit_always}, |
1375 | | |
1376 | | {"zfa", "+f", check_implicit_always}, |
1377 | | {"zfbfmin", "+zfhmin", check_implicit_always}, |
1378 | | {"zfh", "+zfhmin", check_implicit_always}, |
1379 | | {"zfhmin", "+f", check_implicit_always}, |
1380 | | {"zfinx", "+zicsr", check_implicit_always}, |
1381 | | {"f", "+zicsr", check_implicit_always}, |
1382 | | |
1383 | | {"zce", "+zcb,+zcmp,+zcmt", check_implicit_always}, |
1384 | | {"zce", "+zcf", check_implicit_for_zcf}, |
1385 | | {"zcb", "+zca", check_implicit_always}, |
1386 | | {"zcmp", "+zca", check_implicit_always}, |
1387 | | {"zcmop", "+zca", check_implicit_always}, |
1388 | | {"zcmt", "+zca,+zicsr", check_implicit_always}, |
1389 | | {"c", "+zcf", check_implicit_for_zcf}, |
1390 | | {"c", "+zcd", check_implicit_for_zcd}, |
1391 | | {"c", "+zca", check_implicit_always}, |
1392 | | |
1393 | | {"b", "+zba,+zbb,+zbs", check_implicit_always}, |
1394 | | |
1395 | | {"zk", "+zkn,+zkr,+zkt", check_implicit_always}, |
1396 | | {"zkn", "+zbkb,+zbkc,+zbkx,+zkne,+zknd,+zknh", check_implicit_always}, |
1397 | | {"zks", "+zbkb,+zbkc,+zbkx,+zksed,+zksh", check_implicit_always}, |
1398 | | {"zbc", "+zbkc", check_implicit_always}, |
1399 | | |
1400 | | {"sdext", "+zicsr", check_implicit_always}, |
1401 | | {"sdtrig", "+zicsr", check_implicit_always}, |
1402 | | |
1403 | | {"smaia", "+ssaia", check_implicit_always}, |
1404 | | {"smcdeleg", "+ssccfg", check_implicit_always}, |
1405 | | {"smpmpdeleg", "+smcsrind,+sspmp", check_implicit_always}, |
1406 | | {"smcsrind", "+sscsrind", check_implicit_always}, |
1407 | | {"smcntrpmf", "+zicsr", check_implicit_always}, |
1408 | | {"smctr", "+zicsr", check_implicit_always}, |
1409 | | {"smrnmi", "+zicsr", check_implicit_always}, |
1410 | | {"smstateen", "+ssstateen", check_implicit_always}, |
1411 | | {"smepmp", "+zicsr", check_implicit_always}, |
1412 | | {"smdbltrp", "+zicsr", check_implicit_always}, |
1413 | | {"smnpm", "+zicsr", check_implicit_always}, |
1414 | | {"smmpm", "+zicsr", check_implicit_always}, |
1415 | | |
1416 | | {"ssaia", "+zicsr", check_implicit_always}, |
1417 | | {"ssccfg", "+sscsrind", check_implicit_always}, |
1418 | | {"sspmpen", "+sspmp", check_implicit_always}, |
1419 | | {"sspmp", "+sscsrind", check_implicit_always}, |
1420 | | {"sscsrind", "+zicsr", check_implicit_always}, |
1421 | | {"sscofpmf", "+zicsr", check_implicit_always}, |
1422 | | {"sscounterenw", "+zicsr", check_implicit_always}, |
1423 | | {"ssctr", "+zicsr", check_implicit_always}, |
1424 | | {"ssstateen", "+zicsr", check_implicit_always}, |
1425 | | {"ssstrict", "+zicsr", check_implicit_always}, |
1426 | | {"sstc", "+zicsr", check_implicit_always}, |
1427 | | {"sstvala", "+zicsr", check_implicit_always}, |
1428 | | {"sstvecd", "+zicsr", check_implicit_always}, |
1429 | | {"ssu64xl", "+zicsr", check_implicit_always}, |
1430 | | {"ssdbltrp", "+zicsr", check_implicit_always}, |
1431 | | {"ssnpm", "+zicsr", check_implicit_always}, |
1432 | | |
1433 | | {"svade", "+zicsr", check_implicit_always}, |
1434 | | {"svadu", "+zicsr", check_implicit_always}, |
1435 | | {"svbare", "+zicsr", check_implicit_always}, |
1436 | | {NULL, NULL, NULL} |
1437 | | }; |
1438 | | |
1439 | | /* This table records the mapping form RISC-V Profiles into march string. */ |
1440 | | static const struct riscv_profiles riscv_profiles_table[] = |
1441 | | { |
1442 | | /* RVI20U only contains the base extension 'i' as mandatory extension. */ |
1443 | | {"rvi20u64", "rv64i"}, |
1444 | | {"rvi20u32", "rv32i"}, |
1445 | | |
1446 | | /* RVA20U contains the 'i,m,a,f,d,c,zicsr,zicntr,ziccif,ziccrse,ziccamoa, |
1447 | | zicclsm,za128rs' as mandatory extensions. */ |
1448 | | {"rva20u64", "rv64imafdc_zicsr_zicntr_ziccif_ziccrse_ziccamoa" |
1449 | | "_zicclsm_za128rs"}, |
1450 | | |
1451 | | /* RVA22U contains the 'i,m,a,f,d,c,zicsr,zihintpause,zba,zbb,zbs,zicntr, |
1452 | | zihpm,ziccif,ziccrse,ziccamoa, zicclsm,zic64b,za64rs,zicbom,zicbop,zicboz, |
1453 | | zfhmin,zkt' as mandatory extensions. */ |
1454 | | {"rva22u64", "rv64imafdc_zicsr_zicntr_ziccif_ziccrse_ziccamoa" |
1455 | | "_zicclsm_zic64b_za64rs_zihintpause_zba_zbb_zbs_zicbom_zicbop" |
1456 | | "_zicboz_zfhmin_zkt"}, |
1457 | | |
1458 | | /* RVA23 contains all mandatory base ISA for RVA22U64 and the new extension |
1459 | | 'v,zihintntl,zvfhmin,zvbb,zvkt,zicond,zimop,zcmop,zfa,zawrs' as mandatory |
1460 | | extensions. */ |
1461 | | {"rva23u64", "rv64imafdcbv_zicsr_zicntr_zihpm_ziccif_ziccrse_ziccamoa" |
1462 | | "_zicclsm_zic64b_za64rs_zihintpause_zba_zbb_zbs_zicbom_zicbop" |
1463 | | "_zicboz_zfhmin_zkt_zvfhmin_zvbb_zvkt_zihintntl_zicond_zimop_zcmop_zcb" |
1464 | | "_zfa_zawrs_supm"}, |
1465 | | |
1466 | | /* RVA23S contains all mandatory base ISA for RVA23U64 and the privileged |
1467 | | extensions as mandatory extensions. */ |
1468 | | {"rva23s64", "rv64imafdcbv_zicsr_zicntr_zihpm_ziccif_ziccrse_ziccamoa" |
1469 | | "_zicclsm_zic64b_za64rs_zihintpause_zba_zbb_zbs_zicbom_zicbop" |
1470 | | "_zicboz_zfhmin_zkt_zvfhmin_zvbb_zvkt_zihintntl_zicond_zimop_zcmop_zcb" |
1471 | | "_zfa_zawrs_supm_svbare_svade_ssccptr_sstvecd_sstvala_sscounterenw_svpbmt" |
1472 | | "_svinval_svnapot_sstc_sscofpmf_ssnpm_ssu64xl_sha"}, |
1473 | | |
1474 | | /* RVB23 contains all mandatory base ISA for RVA22U64 and the new extension |
1475 | | 'zihintntl,zicond,zimop,zcmop,zfa,zawrs' as mandatory |
1476 | | extensions. */ |
1477 | | {"rvb23u64", "rv64imafdcb_zicsr_zicntr_zihpm_ziccif_ziccrse_ziccamoa" |
1478 | | "_zicclsm_zic64b_za64rs_zihintpause_zba_zbb_zbs_zicbom_zicbop" |
1479 | | "_zicboz_zfhmin_zkt_zihintntl_zicond_zimop_zcmop_zcb" |
1480 | | "_zfa_zawrs_supm"}, |
1481 | | |
1482 | | /* RVB23S contains all mandatory base ISA for RVB23U64 and the privileged |
1483 | | extensions as mandatory extensions. */ |
1484 | | {"rvb23s64", "rv64imafdcb_zicsr_zicntr_zihpm_ziccif_ziccrse_ziccamoa" |
1485 | | "_zicclsm_zic64b_za64rs_zihintpause_zba_zbb_zbs_zicbom_zicbop" |
1486 | | "_zicboz_zfhmin_zkt_zvfhmin_zvbb_zvkt_zihintntl_zicond_zimop_zcmop_zcb" |
1487 | | "_zfa_zawrs_supm_svbare_svade_ssccptr_sstvecd_sstvala_sscounterenw_svpbmt" |
1488 | | "_svinval_svnapot_sstc_sscofpmf_ssu64xl"}, |
1489 | | |
1490 | | /* Terminate the list. */ |
1491 | | {NULL, NULL} |
1492 | | }; |
1493 | | |
1494 | | /* For default_enable field, decide if the extension should |
1495 | | be enbaled by default. */ |
1496 | | |
1497 | 0 | #define EXT_DEFAULT 0x1 |
1498 | | |
1499 | | /* List all extensions that binutils should know about. */ |
1500 | | |
1501 | | struct riscv_supported_ext |
1502 | | { |
1503 | | const char *name; |
1504 | | enum riscv_spec_class isa_spec_class; |
1505 | | int major_version; |
1506 | | int minor_version; |
1507 | | unsigned long default_enable; |
1508 | | }; |
1509 | | |
1510 | | /* The standard extensions must be added in canonical order. */ |
1511 | | |
1512 | | static const struct riscv_supported_ext riscv_supported_std_ext[] = |
1513 | | { |
1514 | | {"e", ISA_SPEC_CLASS_20191213, 1, 9, 0 }, |
1515 | | {"e", ISA_SPEC_CLASS_20190608, 1, 9, 0 }, |
1516 | | {"e", ISA_SPEC_CLASS_2P2, 1, 9, 0 }, |
1517 | | {"i", ISA_SPEC_CLASS_20191213, 2, 1, 0 }, |
1518 | | {"i", ISA_SPEC_CLASS_20190608, 2, 1, 0 }, |
1519 | | {"i", ISA_SPEC_CLASS_2P2, 2, 0, 0 }, |
1520 | | /* The g is a special case which we don't want to output it, |
1521 | | but still need it when adding implicit extensions. */ |
1522 | | {"g", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, EXT_DEFAULT }, |
1523 | | {"m", ISA_SPEC_CLASS_20191213, 2, 0, 0 }, |
1524 | | {"m", ISA_SPEC_CLASS_20190608, 2, 0, 0 }, |
1525 | | {"m", ISA_SPEC_CLASS_2P2, 2, 0, 0 }, |
1526 | | {"a", ISA_SPEC_CLASS_20191213, 2, 1, 0 }, |
1527 | | {"a", ISA_SPEC_CLASS_20190608, 2, 0, 0 }, |
1528 | | {"a", ISA_SPEC_CLASS_2P2, 2, 0, 0 }, |
1529 | | {"f", ISA_SPEC_CLASS_20191213, 2, 2, 0 }, |
1530 | | {"f", ISA_SPEC_CLASS_20190608, 2, 2, 0 }, |
1531 | | {"f", ISA_SPEC_CLASS_2P2, 2, 0, 0 }, |
1532 | | {"d", ISA_SPEC_CLASS_20191213, 2, 2, 0 }, |
1533 | | {"d", ISA_SPEC_CLASS_20190608, 2, 2, 0 }, |
1534 | | {"d", ISA_SPEC_CLASS_2P2, 2, 0, 0 }, |
1535 | | {"q", ISA_SPEC_CLASS_20191213, 2, 2, 0 }, |
1536 | | {"q", ISA_SPEC_CLASS_20190608, 2, 2, 0 }, |
1537 | | {"q", ISA_SPEC_CLASS_2P2, 2, 0, 0 }, |
1538 | | {"c", ISA_SPEC_CLASS_20191213, 2, 0, 0 }, |
1539 | | {"c", ISA_SPEC_CLASS_20190608, 2, 0, 0 }, |
1540 | | {"c", ISA_SPEC_CLASS_2P2, 2, 0, 0 }, |
1541 | | {"b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1542 | | {"v", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1543 | | {"h", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1544 | | {NULL, 0, 0, 0, 0} |
1545 | | }; |
1546 | | |
1547 | | static const struct riscv_supported_ext riscv_supported_std_z_ext[] = |
1548 | | { |
1549 | | {"zic64b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1550 | | {"ziccamoa", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1551 | | {"ziccamoc", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1552 | | {"ziccid", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1553 | | {"ziccif", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1554 | | {"zicclsm", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1555 | | {"ziccrse", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1556 | | {"zicbom", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1557 | | {"zicbop", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1558 | | {"zicboz", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1559 | | {"zicond", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1560 | | {"zicntr", ISA_SPEC_CLASS_DRAFT, 2, 0, 0 }, |
1561 | | {"zicsr", ISA_SPEC_CLASS_20191213, 2, 0, 0 }, |
1562 | | {"zicsr", ISA_SPEC_CLASS_20190608, 2, 0, 0 }, |
1563 | | {"zifencei", ISA_SPEC_CLASS_20191213, 2, 0, 0 }, |
1564 | | {"zifencei", ISA_SPEC_CLASS_20190608, 2, 0, 0 }, |
1565 | | {"zihintntl", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1566 | | {"zihintpause", ISA_SPEC_CLASS_DRAFT, 2, 0, 0 }, |
1567 | | {"zihpm", ISA_SPEC_CLASS_DRAFT, 2, 0, 0 }, |
1568 | | {"zimop", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1569 | | {"zicfiss", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1570 | | {"zicfilp", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1571 | | {"zilsd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1572 | | {"zmmul", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1573 | | {"za64rs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1574 | | {"za128rs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1575 | | {"zaamo", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1576 | | {"zabha", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1577 | | {"zacas", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1578 | | {"zalasr", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1579 | | {"zalrsc", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1580 | | {"zama16b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1581 | | {"zawrs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1582 | | {"zfbfmin", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1583 | | {"zfa", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1584 | | {"zfh", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1585 | | {"zfhmin", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1586 | | {"zfinx", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1587 | | {"zdinx", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1588 | | {"zqinx", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1589 | | {"zhinx", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1590 | | {"zhinxmin", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1591 | | {"zbb", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1592 | | {"zba", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1593 | | {"zbc", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1594 | | {"zbs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1595 | | {"zbkb", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1596 | | {"zbkc", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1597 | | {"zbkx", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1598 | | {"zk", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1599 | | {"zkn", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1600 | | {"zknd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1601 | | {"zkne", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1602 | | {"zknh", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1603 | | {"zkr", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1604 | | {"zks", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1605 | | {"zksed", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1606 | | {"zksh", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1607 | | {"zkt", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1608 | | {"zve32x", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1609 | | {"zve32f", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1610 | | {"zve64x", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1611 | | {"zve64f", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1612 | | {"zve64d", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1613 | | {"zvabd", ISA_SPEC_CLASS_DRAFT, 0, 9, 0 }, |
1614 | | {"zvbb", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1615 | | {"zvbc", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1616 | | {"zvfbdota32f", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1617 | | {"zvfbfmin", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1618 | | {"zvfbfwma", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1619 | | {"zvfh", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1620 | | {"zvfhmin", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1621 | | {"zvfqwbdota8f", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1622 | | {"zvfqwdota8f", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1623 | | {"zvfwbdota16bf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1624 | | {"zvfwdota16bf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1625 | | {"zvkb", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1626 | | {"zvkg", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1627 | | {"zvkn", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1628 | | {"zvkng", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1629 | | {"zvknc", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1630 | | {"zvkned", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1631 | | {"zvknha", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1632 | | {"zvknhb", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1633 | | {"zvksed", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1634 | | {"zvksh", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1635 | | {"zvks", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1636 | | {"zvksg", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1637 | | {"zvksc", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1638 | | {"zvkt", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1639 | | {"zvqwbdota8i", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1640 | | {"zvqwbdota16i", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1641 | | {"zvqwdota8i", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1642 | | {"zvqwdota16i", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1643 | | {"zvl32b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1644 | | {"zvl64b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1645 | | {"zvl128b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1646 | | {"zvl256b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1647 | | {"zvl512b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1648 | | {"zvl1024b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1649 | | {"zvl2048b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1650 | | {"zvl4096b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1651 | | {"zvl8192b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1652 | | {"zvl16384b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1653 | | {"zvl32768b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1654 | | {"zvl65536b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1655 | | {"ztso", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1656 | | {"zca", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1657 | | {"zcb", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1658 | | {"zce", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1659 | | {"zcf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1660 | | {"zcd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1661 | | {"zcmop", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1662 | | {"zcmp", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1663 | | {"zcmt", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1664 | | {"zclsd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1665 | | {NULL, 0, 0, 0, 0} |
1666 | | }; |
1667 | | |
1668 | | static const struct riscv_supported_ext riscv_supported_std_s_ext[] = |
1669 | | { |
1670 | | {"sdext", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1671 | | {"sdtrig", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1672 | | {"sha", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1673 | | {"shcounterenw", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1674 | | {"shgatpa", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1675 | | {"shlcofideleg", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1676 | | {"shtvala", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1677 | | {"shvsatpa", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1678 | | {"shvstvala", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1679 | | {"shvstvecd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1680 | | {"smaia", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1681 | | {"smcdeleg", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1682 | | {"smcsrind", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1683 | | {"smcntrpmf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1684 | | {"smctr", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1685 | | {"smepmp", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1686 | | {"smpmpdeleg", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1687 | | {"smpmpmt", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1688 | | {"smrnmi", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1689 | | {"smstateen", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1690 | | {"smdbltrp", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1691 | | {"ss", ISA_SPEC_CLASS_DRAFT, 1, 11, 0 }, |
1692 | | {"ss", ISA_SPEC_CLASS_DRAFT, 1, 12, 0 }, |
1693 | | {"ss", ISA_SPEC_CLASS_DRAFT, 1, 13, 0 }, |
1694 | | {"ssaia", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1695 | | {"ssccfg", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1696 | | {"ssccptr", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1697 | | {"sscsrind", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1698 | | {"sscofpmf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1699 | | {"sscounterenw", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1700 | | {"ssctr", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1701 | | {"ssstateen", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1702 | | {"ssstrict", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1703 | | {"sstc", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1704 | | {"sstvala", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1705 | | {"sstvecd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1706 | | {"ssu64xl", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1707 | | {"ssdbltrp", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1708 | | {"svade", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1709 | | {"svadu", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1710 | | {"svbare", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1711 | | {"svinval", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1712 | | {"svnapot", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1713 | | {"svpbmt", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1714 | | {"svrsw60t59b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1715 | | {"svvptc", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1716 | | {"ssqosid", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1717 | | {"sspmp", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1718 | | {"sspmpen", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1719 | | {"ssnpm", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1720 | | {"smnpm", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1721 | | {"smmpm", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1722 | | {"sspm", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1723 | | {"supm", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1724 | | {NULL, 0, 0, 0, 0} |
1725 | | }; |
1726 | | |
1727 | | static const struct riscv_supported_ext riscv_supported_std_zxm_ext[] = |
1728 | | { |
1729 | | {NULL, 0, 0, 0, 0} |
1730 | | }; |
1731 | | |
1732 | | static const struct riscv_supported_ext riscv_supported_vendor_x_ext[] = |
1733 | | { |
1734 | | {"xandesbfhcvt", ISA_SPEC_CLASS_DRAFT, 5, 0, 0 }, |
1735 | | {"xandesvbfhcvt", ISA_SPEC_CLASS_DRAFT, 5, 0, 0 }, |
1736 | | {"xandesvdot", ISA_SPEC_CLASS_DRAFT, 5, 0, 0 }, |
1737 | | {"xandesvpackfph", ISA_SPEC_CLASS_DRAFT, 5, 0, 0 }, |
1738 | | {"xandesvsinth", ISA_SPEC_CLASS_DRAFT, 5, 0, 0 }, |
1739 | | {"xandesvsintload", ISA_SPEC_CLASS_DRAFT, 5, 0, 0 }, |
1740 | | {"xcvalu", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1741 | | {"xcvbi", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1742 | | {"xcvbitmanip", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1743 | | {"xcvelw", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1744 | | {"xcvmac", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1745 | | {"xcvmem", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1746 | | {"xcvsimd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1747 | | {"xmipscbop", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1748 | | {"xmipscmov", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1749 | | {"xmipsexectl", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1750 | | {"xmipslsp", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1751 | | {"xsfcease", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1752 | | {"xsfvcp", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1753 | | {"xsfvfnrclipxfqf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1754 | | {"xsfvqmaccdod", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1755 | | {"xsfvqmaccqoq", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1756 | | {"xsmtvdot", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1757 | | {"xsmtvdotii", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1758 | | {"xtheadba", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1759 | | {"xtheadbb", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1760 | | {"xtheadbs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1761 | | {"xtheadcmo", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1762 | | {"xtheadcondmov", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1763 | | {"xtheadfmemidx", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1764 | | {"xtheadfmv", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1765 | | {"xtheadint", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1766 | | {"xtheadmac", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1767 | | {"xtheadmemidx", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1768 | | {"xtheadmempair", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1769 | | {"xtheadsync", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1770 | | {"xtheadvdot", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1771 | | {"xtheadvector", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1772 | | {"xtheadzvamo", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1773 | | {"xventanacondops", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1774 | | {"xxtvarith", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1775 | | {"xxtvcoder", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, |
1776 | | {NULL, 0, 0, 0, 0} |
1777 | | }; |
1778 | | |
1779 | | static const struct riscv_supported_ext *riscv_all_supported_ext[] = |
1780 | | { |
1781 | | riscv_supported_std_ext, |
1782 | | riscv_supported_std_z_ext, |
1783 | | riscv_supported_std_s_ext, |
1784 | | riscv_supported_std_zxm_ext, |
1785 | | riscv_supported_vendor_x_ext, |
1786 | | NULL |
1787 | | }; |
1788 | | |
1789 | | /* ISA extension prefixed name class. Must define them in parsing order. */ |
1790 | | enum riscv_prefix_ext_class |
1791 | | { |
1792 | | RV_ISA_CLASS_Z = 1, |
1793 | | RV_ISA_CLASS_S, |
1794 | | RV_ISA_CLASS_ZXM, |
1795 | | RV_ISA_CLASS_X, |
1796 | | RV_ISA_CLASS_SINGLE |
1797 | | }; |
1798 | | |
1799 | | /* Record the strings of the prefixed extensions, and their corresponding |
1800 | | classes. The more letters of the prefix string, the more forward it must |
1801 | | be defined. Otherwise, the riscv_get_prefix_class will map it to the |
1802 | | wrong classes. */ |
1803 | | struct riscv_parse_prefix_config |
1804 | | { |
1805 | | /* Class of the extension. */ |
1806 | | enum riscv_prefix_ext_class class; |
1807 | | |
1808 | | /* Prefix string for error printing and internal parser usage. */ |
1809 | | const char *prefix; |
1810 | | }; |
1811 | | static const struct riscv_parse_prefix_config parse_config[] = |
1812 | | { |
1813 | | {RV_ISA_CLASS_ZXM, "zxm"}, |
1814 | | {RV_ISA_CLASS_Z, "z"}, |
1815 | | {RV_ISA_CLASS_S, "s"}, |
1816 | | {RV_ISA_CLASS_X, "x"}, |
1817 | | {RV_ISA_CLASS_SINGLE, NULL} |
1818 | | }; |
1819 | | |
1820 | | /* Get the prefixed name class for the extensions, the class also |
1821 | | means the order of the prefixed extensions. */ |
1822 | | |
1823 | | static enum riscv_prefix_ext_class |
1824 | | riscv_get_prefix_class (const char *arch) |
1825 | 154M | { |
1826 | 154M | int i = 0; |
1827 | 424M | while (parse_config[i].class != RV_ISA_CLASS_SINGLE) |
1828 | 385M | { |
1829 | 385M | if (strncmp (arch, parse_config[i].prefix, |
1830 | 385M | strlen (parse_config[i].prefix)) == 0) |
1831 | 115M | return parse_config[i].class; |
1832 | 269M | i++; |
1833 | 269M | } |
1834 | 38.4M | return RV_ISA_CLASS_SINGLE; |
1835 | 154M | } |
1836 | | |
1837 | | /* Check KNOWN_EXTS to see if the EXT is supported. */ |
1838 | | |
1839 | | static bool |
1840 | | riscv_known_prefixed_ext (const char *ext, |
1841 | | const struct riscv_supported_ext *known_exts) |
1842 | 0 | { |
1843 | 0 | size_t i; |
1844 | 0 | for (i = 0; known_exts[i].name != NULL; ++i) |
1845 | 0 | if (strcmp (ext, known_exts[i].name) == 0) |
1846 | 0 | return true; |
1847 | 0 | return false; |
1848 | 0 | } |
1849 | | |
1850 | | /* Check whether the prefixed extension is recognized or not. Return |
1851 | | true if recognized, otehrwise return false. */ |
1852 | | |
1853 | | static bool |
1854 | | riscv_recognized_prefixed_ext (const char *ext) |
1855 | 0 | { |
1856 | 0 | enum riscv_prefix_ext_class class = riscv_get_prefix_class (ext); |
1857 | 0 | switch (class) |
1858 | 0 | { |
1859 | 0 | case RV_ISA_CLASS_Z: |
1860 | 0 | return riscv_known_prefixed_ext (ext, riscv_supported_std_z_ext); |
1861 | 0 | case RV_ISA_CLASS_ZXM: |
1862 | 0 | return riscv_known_prefixed_ext (ext, riscv_supported_std_zxm_ext); |
1863 | 0 | case RV_ISA_CLASS_S: |
1864 | 0 | return riscv_known_prefixed_ext (ext, riscv_supported_std_s_ext); |
1865 | 0 | case RV_ISA_CLASS_X: |
1866 | | /* Only the single x is unrecognized. */ |
1867 | 0 | if (strcmp (ext, "x") != 0) |
1868 | 0 | return true; |
1869 | 0 | default: |
1870 | 0 | break; |
1871 | 0 | } |
1872 | 0 | return false; |
1873 | 0 | } |
1874 | | |
1875 | | /* Canonical order for single letter extensions. */ |
1876 | | static const char riscv_ext_canonical_order[] = "eigmafdqlcbkjtvph"; |
1877 | | |
1878 | | /* Array is used to compare the orders of standard extensions quickly. */ |
1879 | | static int riscv_ext_order[26] = {0}; |
1880 | | |
1881 | | /* Init the riscv_ext_order array. */ |
1882 | | |
1883 | | static void |
1884 | | riscv_init_ext_order (void) |
1885 | 1.61k | { |
1886 | 1.61k | static bool inited = false; |
1887 | 1.61k | if (inited) |
1888 | 1.61k | return; |
1889 | | |
1890 | | /* The orders of all standard extensions are positive. */ |
1891 | 2 | int order = 1; |
1892 | | |
1893 | 36 | for (const char *ext = &riscv_ext_canonical_order[0]; *ext; ++ext) |
1894 | 34 | riscv_ext_order[(*ext - 'a')] = order++; |
1895 | | |
1896 | | /* Some of the prefixed keyword are not single letter, so we set |
1897 | | their prefixed orders in the riscv_compare_subsets directly, |
1898 | | not through the riscv_ext_order. */ |
1899 | | |
1900 | 2 | inited = true; |
1901 | 2 | } |
1902 | | |
1903 | | /* Similar to the strcmp. It returns an integer less than, equal to, |
1904 | | or greater than zero if `subset2` is found, respectively, to be less |
1905 | | than, to match, or be greater than `subset1`. |
1906 | | |
1907 | | The order values, |
1908 | | Zero: Preserved keywords. |
1909 | | Positive number: Standard extensions. |
1910 | | Negative number: Prefixed keywords. */ |
1911 | | |
1912 | | int |
1913 | | riscv_compare_subsets (const char *subset1, const char *subset2) |
1914 | 77.7M | { |
1915 | 77.7M | int order1 = riscv_ext_order[(*subset1 - 'a')]; |
1916 | 77.7M | int order2 = riscv_ext_order[(*subset2 - 'a')]; |
1917 | | |
1918 | | /* Compare the standard extension first. */ |
1919 | 77.7M | if (order1 > 0 && order2 > 0) |
1920 | 610k | return order1 - order2; |
1921 | | |
1922 | | /* Set the prefixed orders to negative numbers. */ |
1923 | 77.1M | enum riscv_prefix_ext_class class1 = riscv_get_prefix_class (subset1); |
1924 | 77.1M | enum riscv_prefix_ext_class class2 = riscv_get_prefix_class (subset2); |
1925 | | |
1926 | 77.1M | if (class1 != RV_ISA_CLASS_SINGLE) |
1927 | 38.8M | order1 = - (int) class1; |
1928 | 77.1M | if (class2 != RV_ISA_CLASS_SINGLE) |
1929 | 76.9M | order2 = - (int) class2; |
1930 | | |
1931 | 77.1M | if (order1 == order2) |
1932 | 38.5M | { |
1933 | | /* Compare the standard addition z extensions. */ |
1934 | 38.5M | if (class1 == RV_ISA_CLASS_Z) |
1935 | 38.5M | { |
1936 | 38.5M | order1 = riscv_ext_order[(*++subset1 - 'a')]; |
1937 | 38.5M | order2 = riscv_ext_order[(*++subset2 - 'a')]; |
1938 | 38.5M | if (order1 != order2) |
1939 | 34.9M | return order1 - order2; |
1940 | 38.5M | } |
1941 | 3.56M | return strcasecmp (++subset1, ++subset2); |
1942 | 38.5M | } |
1943 | | |
1944 | 38.5M | return order2 - order1; |
1945 | 77.1M | } |
1946 | | |
1947 | | /* Find subset in the list. Return TRUE and set `current` to the subset |
1948 | | if it is found. Otherwise, return FALSE and set `current` to the place |
1949 | | where we should insert the subset. However, return FALSE with the NULL |
1950 | | `current` means we should insert the subset at the head of subset list, |
1951 | | if needed. */ |
1952 | | |
1953 | | bool |
1954 | | riscv_lookup_subset (const riscv_subset_list_t *subset_list, |
1955 | | const char *subset, |
1956 | | riscv_subset_t **current) |
1957 | 5.97M | { |
1958 | 5.97M | riscv_subset_t *s, *pre_s = NULL; |
1959 | | |
1960 | | /* If the subset is added in order, then just add it at the tail. */ |
1961 | 5.97M | if (subset_list->tail != NULL |
1962 | 5.97M | && riscv_compare_subsets (subset_list->tail->name, subset) < 0) |
1963 | 339k | { |
1964 | 339k | *current = subset_list->tail; |
1965 | 339k | return false; |
1966 | 339k | } |
1967 | | |
1968 | 5.63M | for (s = subset_list->head; |
1969 | 71.7M | s != NULL; |
1970 | 66.1M | pre_s = s, s = s->next) |
1971 | 71.7M | { |
1972 | 71.7M | int cmp = riscv_compare_subsets (s->name, subset); |
1973 | 71.7M | if (cmp == 0) |
1974 | 1.71M | { |
1975 | 1.71M | *current = s; |
1976 | 1.71M | return true; |
1977 | 1.71M | } |
1978 | 70.0M | else if (cmp > 0) |
1979 | 3.92M | break; |
1980 | 71.7M | } |
1981 | 3.92M | *current = pre_s; |
1982 | | |
1983 | 3.92M | return false; |
1984 | 5.63M | } |
1985 | | |
1986 | | /* Add the extension to the subset list. Search the |
1987 | | list first, and then find the right place to add. */ |
1988 | | |
1989 | | void |
1990 | | riscv_add_subset (riscv_subset_list_t *subset_list, |
1991 | | const char *subset, |
1992 | | int major, |
1993 | | int minor) |
1994 | 22.6k | { |
1995 | 22.6k | riscv_subset_t *current, *new; |
1996 | | |
1997 | 22.6k | if (riscv_lookup_subset (subset_list, subset, ¤t)) |
1998 | 0 | return; |
1999 | | |
2000 | 22.6k | new = xmalloc (sizeof *new); |
2001 | 22.6k | new->name = xstrdup (subset); |
2002 | 22.6k | new->major_version = major; |
2003 | 22.6k | new->minor_version = minor; |
2004 | 22.6k | new->next = NULL; |
2005 | | |
2006 | 22.6k | if (current != NULL) |
2007 | 19.3k | { |
2008 | 19.3k | new->next = current->next; |
2009 | 19.3k | current->next = new; |
2010 | 19.3k | } |
2011 | 3.23k | else |
2012 | 3.23k | { |
2013 | 3.23k | new->next = subset_list->head; |
2014 | 3.23k | subset_list->head = new; |
2015 | 3.23k | } |
2016 | | |
2017 | 22.6k | if (new->next == NULL) |
2018 | 12.9k | subset_list->tail = new; |
2019 | 22.6k | } |
2020 | | |
2021 | | /* Get the default versions from the riscv_supported_*ext tables. */ |
2022 | | |
2023 | | static void |
2024 | | riscv_get_default_ext_version (enum riscv_spec_class default_isa_spec, |
2025 | | const char *name, |
2026 | | int *major_version, |
2027 | | int *minor_version) |
2028 | 22.6k | { |
2029 | 22.6k | if (name == NULL |
2030 | 22.6k | || default_isa_spec == ISA_SPEC_CLASS_NONE) |
2031 | 0 | return; |
2032 | | |
2033 | 22.6k | const struct riscv_supported_ext *table = NULL; |
2034 | 22.6k | enum riscv_prefix_ext_class class = riscv_get_prefix_class (name); |
2035 | 22.6k | switch (class) |
2036 | 22.6k | { |
2037 | 0 | case RV_ISA_CLASS_ZXM: table = riscv_supported_std_zxm_ext; break; |
2038 | 11.3k | case RV_ISA_CLASS_Z: table = riscv_supported_std_z_ext; break; |
2039 | 0 | case RV_ISA_CLASS_S: table = riscv_supported_std_s_ext; break; |
2040 | 0 | case RV_ISA_CLASS_X: table = riscv_supported_vendor_x_ext; break; |
2041 | 11.3k | default: |
2042 | 11.3k | table = riscv_supported_std_ext; |
2043 | 22.6k | } |
2044 | | |
2045 | 22.6k | int i = 0; |
2046 | 704k | while (table != NULL && table[i].name != NULL) |
2047 | 702k | { |
2048 | 702k | if (strcmp (table[i].name, name) == 0 |
2049 | 22.6k | && (table[i].isa_spec_class == ISA_SPEC_CLASS_DRAFT |
2050 | 14.5k | || table[i].isa_spec_class == default_isa_spec)) |
2051 | 21.0k | { |
2052 | 21.0k | *major_version = table[i].major_version; |
2053 | 21.0k | *minor_version = table[i].minor_version; |
2054 | 21.0k | return; |
2055 | 21.0k | } |
2056 | 681k | i++; |
2057 | 681k | } |
2058 | 22.6k | } |
2059 | | |
2060 | | /* Find the default versions for the extension before adding them to |
2061 | | the subset list, if their versions are RISCV_UNKNOWN_VERSION. |
2062 | | Afterwards, report errors if we can not find their default versions. */ |
2063 | | |
2064 | | static void |
2065 | | riscv_parse_add_subset (riscv_parse_subset_t *rps, |
2066 | | const char *subset, |
2067 | | int major, |
2068 | | int minor, |
2069 | | bool implicit) |
2070 | 22.6k | { |
2071 | 22.6k | int major_version = major; |
2072 | 22.6k | int minor_version = minor; |
2073 | | |
2074 | 22.6k | if ((major_version == RISCV_UNKNOWN_VERSION |
2075 | 0 | || minor_version == RISCV_UNKNOWN_VERSION) |
2076 | 22.6k | && rps->isa_spec != NULL) |
2077 | 22.6k | riscv_get_default_ext_version (*rps->isa_spec, subset, |
2078 | 22.6k | &major_version, &minor_version); |
2079 | | |
2080 | | /* We don't care the versions of the implicit extensions. */ |
2081 | 22.6k | if (!implicit |
2082 | 1.61k | && (major_version == RISCV_UNKNOWN_VERSION |
2083 | 1.61k | || minor_version == RISCV_UNKNOWN_VERSION)) |
2084 | 0 | { |
2085 | 0 | if (subset[0] == 'x') |
2086 | 0 | rps->error_handler |
2087 | 0 | (_("x ISA extension `%s' must be set with the versions"), |
2088 | 0 | subset); |
2089 | | /* Allow old ISA spec can recognize zicsr and zifencei. */ |
2090 | 0 | else if (strcmp (subset, "zicsr") != 0 |
2091 | 0 | && strcmp (subset, "zifencei") != 0) |
2092 | 0 | rps->error_handler |
2093 | 0 | (_("cannot find default versions of the ISA extension `%s'"), |
2094 | 0 | subset); |
2095 | 0 | return; |
2096 | 0 | } |
2097 | | |
2098 | 22.6k | riscv_add_subset (rps->subset_list, subset, |
2099 | 22.6k | major_version, minor_version); |
2100 | 22.6k | } |
2101 | | |
2102 | | /* Release subset list. */ |
2103 | | |
2104 | | void |
2105 | | riscv_release_subset_list (riscv_subset_list_t *subset_list) |
2106 | 3.23k | { |
2107 | 25.8k | while (subset_list->head != NULL) |
2108 | 22.6k | { |
2109 | 22.6k | riscv_subset_t *next = subset_list->head->next; |
2110 | 22.6k | free ((void *)subset_list->head->name); |
2111 | 22.6k | free (subset_list->head); |
2112 | 22.6k | subset_list->head = next; |
2113 | 22.6k | } |
2114 | | |
2115 | 3.23k | subset_list->tail = NULL; |
2116 | | |
2117 | 3.23k | if (subset_list->arch_str != NULL) |
2118 | 1.61k | { |
2119 | 1.61k | free ((void*) subset_list->arch_str); |
2120 | 1.61k | subset_list->arch_str = NULL; |
2121 | 1.61k | } |
2122 | 3.23k | } |
2123 | | |
2124 | | /* Parsing extension version. |
2125 | | |
2126 | | Return Value: |
2127 | | Points to the end of version |
2128 | | |
2129 | | Arguments: |
2130 | | `p`: Curent parsing position. |
2131 | | `major_version`: Parsed major version. |
2132 | | `minor_version`: Parsed minor version. */ |
2133 | | |
2134 | | static const char * |
2135 | | riscv_parsing_subset_version (const char *p, |
2136 | | int *major_version, |
2137 | | int *minor_version) |
2138 | 25.8k | { |
2139 | 25.8k | bool major_p = true; |
2140 | 25.8k | int version = 0; |
2141 | 25.8k | char np; |
2142 | | |
2143 | 25.8k | *major_version = 0; |
2144 | 25.8k | *minor_version = 0; |
2145 | 25.8k | for (; *p; ++p) |
2146 | 12.9k | { |
2147 | 12.9k | if (*p == 'p') |
2148 | 0 | { |
2149 | 0 | np = *(p + 1); |
2150 | | |
2151 | | /* Might be beginning of `p` extension. */ |
2152 | 0 | if (!ISDIGIT (np)) |
2153 | 0 | break; |
2154 | | |
2155 | 0 | *major_version = version; |
2156 | 0 | major_p = false; |
2157 | 0 | version = 0; |
2158 | 0 | } |
2159 | 12.9k | else if (ISDIGIT (*p)) |
2160 | 0 | version = (version * 10) + (*p - '0'); |
2161 | 12.9k | else |
2162 | 12.9k | break; |
2163 | 12.9k | } |
2164 | | |
2165 | 25.8k | if (major_p) |
2166 | 25.8k | *major_version = version; |
2167 | 0 | else |
2168 | 0 | *minor_version = version; |
2169 | | |
2170 | | /* We can not find any version in string. */ |
2171 | 25.8k | if (*major_version == 0 && *minor_version == 0) |
2172 | 25.8k | { |
2173 | 25.8k | *major_version = RISCV_UNKNOWN_VERSION; |
2174 | 25.8k | *minor_version = RISCV_UNKNOWN_VERSION; |
2175 | 25.8k | } |
2176 | | |
2177 | 25.8k | return p; |
2178 | 25.8k | } |
2179 | | |
2180 | | /* Parsing function for both standard and prefixed extensions. |
2181 | | |
2182 | | Return Value: |
2183 | | Points to the end of extensions. |
2184 | | |
2185 | | Arguments: |
2186 | | `rps`: Hooks and status for parsing extensions. |
2187 | | `arch`: Full ISA string. |
2188 | | `p`: Curent parsing position. */ |
2189 | | |
2190 | | static const char * |
2191 | | riscv_parse_extensions (riscv_parse_subset_t *rps, |
2192 | | const char *arch, |
2193 | | const char *p, |
2194 | | bool profile) |
2195 | 1.61k | { |
2196 | | /* First letter must start with i, e, g or a profile. */ |
2197 | 1.61k | if (*p != 'e' && *p != 'i' && *p != 'g' && !profile) |
2198 | 0 | { |
2199 | 0 | rps->error_handler |
2200 | 0 | (_("%s: first ISA extension must be `e', `i' or `g'"), |
2201 | 0 | arch); |
2202 | 0 | return NULL; |
2203 | 0 | } |
2204 | | |
2205 | 4.84k | while (*p != '\0') |
2206 | 3.23k | { |
2207 | 3.23k | if (*p == '_') |
2208 | 0 | { |
2209 | 0 | p++; |
2210 | 0 | continue; |
2211 | 0 | } |
2212 | | |
2213 | 3.23k | char *subset = xstrdup (p); |
2214 | 3.23k | char *q = subset; /* Start of version. */ |
2215 | 3.23k | const char *end_of_version; |
2216 | 3.23k | bool implicit = false; |
2217 | | |
2218 | 3.23k | enum riscv_prefix_ext_class class = riscv_get_prefix_class (p); |
2219 | 3.23k | if (class == RV_ISA_CLASS_SINGLE) |
2220 | 3.23k | { |
2221 | 3.23k | if (riscv_ext_order[(*subset - 'a')] == 0) |
2222 | 0 | { |
2223 | 0 | rps->error_handler |
2224 | 0 | (_("%s: unknown standard ISA extension or prefix class `%c'"), |
2225 | 0 | arch, *subset); |
2226 | 0 | free (subset); |
2227 | 0 | return NULL; |
2228 | 0 | } |
2229 | 3.23k | q++; |
2230 | 3.23k | } |
2231 | 0 | else |
2232 | 0 | { |
2233 | | /* Extract the whole prefixed extension by '_'. */ |
2234 | 0 | while (*++q != '\0' && *q != '_') |
2235 | 0 | ; |
2236 | | /* Look forward to the first letter which is not <major>p<minor>. */ |
2237 | 0 | bool find_any_version = false; |
2238 | 0 | bool find_minor_version = false; |
2239 | 0 | while (1) |
2240 | 0 | { |
2241 | 0 | q--; |
2242 | 0 | if (ISDIGIT (*q)) |
2243 | 0 | find_any_version = true; |
2244 | 0 | else if (find_any_version |
2245 | 0 | && !find_minor_version |
2246 | 0 | && q > subset |
2247 | 0 | && *q == 'p' |
2248 | 0 | && ISDIGIT (*(q - 1))) |
2249 | 0 | find_minor_version = true; |
2250 | 0 | else |
2251 | 0 | break; |
2252 | 0 | } |
2253 | | |
2254 | | /* Check if the end of extension is 'p' or not. If yes, then |
2255 | | the second letter from the end cannot be number. */ |
2256 | 0 | if (q > subset && *q == 'p' && ISDIGIT (*(q - 1))) |
2257 | 0 | { |
2258 | 0 | q[1] = '\0'; |
2259 | 0 | rps->error_handler |
2260 | 0 | (_("%s: invalid prefixed ISA extension `%s' ends with <number>p"), |
2261 | 0 | arch, subset); |
2262 | 0 | free (subset); |
2263 | 0 | return NULL; |
2264 | 0 | } |
2265 | | |
2266 | 0 | q++; |
2267 | 0 | } |
2268 | | |
2269 | 3.23k | int major_version = RISCV_UNKNOWN_VERSION; |
2270 | 3.23k | int minor_version = RISCV_UNKNOWN_VERSION; |
2271 | 3.23k | end_of_version = |
2272 | 3.23k | riscv_parsing_subset_version (q, &major_version, &minor_version); |
2273 | 3.23k | *q = '\0'; |
2274 | | |
2275 | | /* Check if the prefixed extension name is well-formed. */ |
2276 | 3.23k | if (class != RV_ISA_CLASS_SINGLE |
2277 | 0 | && rps->check_unknown_prefixed_ext |
2278 | 0 | && !riscv_recognized_prefixed_ext (subset)) |
2279 | 0 | { |
2280 | 0 | rps->error_handler |
2281 | 0 | (_("%s: unknown prefixed ISA extension `%s'"), |
2282 | 0 | arch, subset); |
2283 | 0 | free (subset); |
2284 | 0 | return NULL; |
2285 | 0 | } |
2286 | | |
2287 | | /* Added g as an implicit extension. */ |
2288 | 3.23k | if (class == RV_ISA_CLASS_SINGLE |
2289 | 3.23k | && strcmp (subset, "g") == 0) |
2290 | 1.61k | { |
2291 | 1.61k | implicit = true; |
2292 | 1.61k | major_version = RISCV_UNKNOWN_VERSION; |
2293 | 1.61k | minor_version = RISCV_UNKNOWN_VERSION; |
2294 | 1.61k | } |
2295 | 3.23k | riscv_parse_add_subset (rps, subset, |
2296 | 3.23k | major_version, |
2297 | 3.23k | minor_version, implicit); |
2298 | 3.23k | p += end_of_version - subset; |
2299 | 3.23k | free (subset); |
2300 | | |
2301 | 3.23k | if (class != RV_ISA_CLASS_SINGLE |
2302 | 0 | && *p != '\0' && *p != '_') |
2303 | 0 | { |
2304 | 0 | rps->error_handler |
2305 | 0 | (_("%s: prefixed ISA extension must separate with _"), |
2306 | 0 | arch); |
2307 | 0 | return NULL; |
2308 | 0 | } |
2309 | 3.23k | } |
2310 | | |
2311 | 1.61k | return p; |
2312 | 1.61k | } |
2313 | | |
2314 | | static bool |
2315 | | riscv_update_subset1 (riscv_parse_subset_t *, const char *, bool); |
2316 | | |
2317 | | /* Add the implicit extensions. */ |
2318 | | |
2319 | | static void |
2320 | | riscv_parse_add_implicit_subsets (riscv_parse_subset_t *rps) |
2321 | 1.61k | { |
2322 | 1.61k | const struct riscv_implicit_subset *t = riscv_implicit_subsets; |
2323 | 227k | for (; t->ext; t++) |
2324 | 226k | { |
2325 | 226k | riscv_subset_t *subset = NULL; |
2326 | 226k | if (riscv_lookup_subset (rps->subset_list, t->ext, &subset) |
2327 | 14.5k | && t->check_func (rps, subset)) |
2328 | 11.3k | riscv_update_subset1 (rps, t->implicit_exts, true /* implicit */); |
2329 | 226k | } |
2330 | 1.61k | } |
2331 | | |
2332 | | /* Check extensions conflicts. */ |
2333 | | |
2334 | | static bool |
2335 | | riscv_parse_check_conflicts (riscv_parse_subset_t *rps) |
2336 | 1.61k | { |
2337 | 1.61k | riscv_subset_t *subset = NULL; |
2338 | 1.61k | int xlen = *rps->xlen; |
2339 | 1.61k | bool no_conflict = true; |
2340 | | |
2341 | 1.61k | if (riscv_subset_supports (rps, "e") |
2342 | 0 | && riscv_subset_supports (rps, "h")) |
2343 | 0 | { |
2344 | 0 | rps->error_handler |
2345 | 0 | (_("rv%de does not support the `h' extension"), xlen); |
2346 | 0 | no_conflict = false; |
2347 | 0 | } |
2348 | 1.61k | if (riscv_lookup_subset (rps->subset_list, "q", &subset) |
2349 | 0 | && (subset->major_version < 2 || (subset->major_version == 2 |
2350 | 0 | && subset->minor_version < 2)) |
2351 | 0 | && xlen < 64) |
2352 | 0 | { |
2353 | 0 | rps->error_handler (_("rv%d does not support the `q' extension"), xlen); |
2354 | 0 | no_conflict = false; |
2355 | 0 | } |
2356 | 1.61k | if (riscv_subset_supports (rps, "zcmp") |
2357 | 0 | && riscv_subset_supports (rps, "zcd")) |
2358 | 0 | { |
2359 | 0 | rps->error_handler |
2360 | 0 | (_("zcmp' is incompatible with `d' and `c', or `zcd' extension")); |
2361 | 0 | no_conflict = false; |
2362 | 0 | } |
2363 | 1.61k | if (riscv_lookup_subset (rps->subset_list, "zcf", &subset) |
2364 | 0 | && xlen > 32) |
2365 | 0 | { |
2366 | 0 | rps->error_handler |
2367 | 0 | (_("rv%d does not support the `zcf' extension"), xlen); |
2368 | 0 | no_conflict = false; |
2369 | 0 | } |
2370 | 1.61k | if (riscv_lookup_subset (rps->subset_list, "zfinx", &subset) |
2371 | 0 | && riscv_lookup_subset (rps->subset_list, "f", &subset)) |
2372 | 0 | { |
2373 | 0 | rps->error_handler |
2374 | 0 | (_("`zfinx' conflicts with the `f/d/q/zfh/zfhmin' extension")); |
2375 | 0 | no_conflict = false; |
2376 | 0 | } |
2377 | 1.61k | if (riscv_lookup_subset (rps->subset_list, "xtheadvector", &subset) |
2378 | 0 | && riscv_lookup_subset (rps->subset_list, "zve32x", &subset)) |
2379 | 0 | { |
2380 | 0 | rps->error_handler |
2381 | 0 | (_("`xtheadvector' conflicts with the `v/zve32x' extension")); |
2382 | 0 | no_conflict = false; |
2383 | 0 | } |
2384 | 1.61k | if (riscv_lookup_subset (rps->subset_list, "zclsd", &subset) |
2385 | 0 | && ((riscv_lookup_subset (rps->subset_list, "c", &subset) |
2386 | 0 | && riscv_lookup_subset (rps->subset_list, "f", &subset)) |
2387 | 0 | || riscv_lookup_subset (rps->subset_list, "zcf", &subset))) |
2388 | 0 | { |
2389 | 0 | rps->error_handler |
2390 | 0 | (_("`zclsd' conflicts with the `c+f'/`zcf' extension")); |
2391 | 0 | no_conflict = false; |
2392 | 0 | } |
2393 | 1.61k | if (riscv_lookup_subset (rps->subset_list, "ssnpm", &subset) && xlen != 64) |
2394 | 0 | { |
2395 | 0 | rps->error_handler (_ ("rv%d does not support the `ssnpm' extension"), |
2396 | 0 | xlen); |
2397 | 0 | no_conflict = false; |
2398 | 0 | } |
2399 | 1.61k | if (riscv_lookup_subset (rps->subset_list, "smnpm", &subset) && xlen != 64) |
2400 | 0 | { |
2401 | 0 | rps->error_handler (_ ("rv%d does not support the `smnpm' extension"), |
2402 | 0 | xlen); |
2403 | 0 | no_conflict = false; |
2404 | 0 | } |
2405 | 1.61k | if (riscv_lookup_subset (rps->subset_list, "smmpm", &subset) && xlen != 64) |
2406 | 0 | { |
2407 | 0 | rps->error_handler (_ ("rv%d does not support the `smmpm' extension"), |
2408 | 0 | xlen); |
2409 | 0 | no_conflict = false; |
2410 | 0 | } |
2411 | 1.61k | if (riscv_lookup_subset (rps->subset_list, "sspm", &subset) && xlen != 64) |
2412 | 0 | { |
2413 | 0 | rps->error_handler (_ ("rv%d does not support the `sspm' extension"), |
2414 | 0 | xlen); |
2415 | 0 | no_conflict = false; |
2416 | 0 | } |
2417 | 1.61k | if (riscv_lookup_subset (rps->subset_list, "supm", &subset) && xlen != 64) |
2418 | 0 | { |
2419 | 0 | rps->error_handler (_ ("rv%d does not support the `supm' extension"), |
2420 | 0 | xlen); |
2421 | 0 | no_conflict = false; |
2422 | 0 | } |
2423 | | |
2424 | 1.61k | bool support_zve = false; |
2425 | 1.61k | bool support_zvl = false; |
2426 | 1.61k | riscv_subset_t *s = rps->subset_list->head; |
2427 | 24.2k | for (; s != NULL; s = s->next) |
2428 | 22.6k | { |
2429 | 22.6k | if (!support_zve |
2430 | 22.6k | && strncmp (s->name, "zve", 3) == 0) |
2431 | 0 | support_zve = true; |
2432 | 22.6k | if (!support_zvl |
2433 | 22.6k | && strncmp (s->name, "zvl", 3) == 0) |
2434 | 0 | support_zvl = true; |
2435 | 22.6k | if (support_zve && support_zvl) |
2436 | 0 | break; |
2437 | 22.6k | } |
2438 | 1.61k | if (support_zvl && !support_zve) |
2439 | 0 | { |
2440 | 0 | rps->error_handler |
2441 | 0 | (_("zvl*b extensions need to enable either `v' or `zve' extension")); |
2442 | 0 | no_conflict = false; |
2443 | 0 | } |
2444 | | |
2445 | 1.61k | return no_conflict; |
2446 | 1.61k | } |
2447 | | |
2448 | | /* Set the default subset list according to the default_enable field |
2449 | | of riscv_supported_*ext tables. */ |
2450 | | |
2451 | | static void |
2452 | | riscv_set_default_arch (riscv_parse_subset_t *rps) |
2453 | 0 | { |
2454 | 0 | unsigned long enable = EXT_DEFAULT; |
2455 | 0 | int i, j; |
2456 | 0 | for (i = 0; riscv_all_supported_ext[i] != NULL; i++) |
2457 | 0 | { |
2458 | 0 | const struct riscv_supported_ext *table = riscv_all_supported_ext[i]; |
2459 | 0 | for (j = 0; table[j].name != NULL; j++) |
2460 | 0 | { |
2461 | 0 | bool implicit = false; |
2462 | 0 | if (strcmp (table[j].name, "g") == 0) |
2463 | 0 | implicit = true; |
2464 | 0 | if (table[j].default_enable & enable) |
2465 | 0 | riscv_parse_add_subset (rps, table[j].name, |
2466 | 0 | RISCV_UNKNOWN_VERSION, |
2467 | 0 | RISCV_UNKNOWN_VERSION, implicit); |
2468 | 0 | } |
2469 | 0 | } |
2470 | 0 | } |
2471 | | |
2472 | | static bool |
2473 | | riscv_find_profiles (riscv_parse_subset_t *rps, const char **pp) |
2474 | 1.61k | { |
2475 | 1.61k | const char *p = *pp; |
2476 | | |
2477 | | /* Checking if input string contains a Profiles. |
2478 | | There are two cases use Profiles in -march option: |
2479 | | |
2480 | | 1. Only use Profiles in '-march' as input |
2481 | | 2. Mixed Profiles with other extensions |
2482 | | |
2483 | | Use '_' to split Profiles and other extensions. */ |
2484 | | |
2485 | 14.5k | for (int i = 0; riscv_profiles_table[i].profile_name != NULL; ++i) |
2486 | 12.9k | { |
2487 | | /* Find profile at the begin. */ |
2488 | 12.9k | if (startswith (p, riscv_profiles_table[i].profile_name)) |
2489 | 0 | { |
2490 | | /* Handle the profile string. */ |
2491 | 0 | riscv_parse_subset (rps, riscv_profiles_table[i].profile_string); |
2492 | 0 | p += strlen (riscv_profiles_table[i].profile_name); |
2493 | | /* Handle string after profiles if exists. If missing underline |
2494 | | bewteen profile and other extensions, warn the user but not deal |
2495 | | as an error. */ |
2496 | 0 | if (*p != '\0' && *p != '_') |
2497 | 0 | _bfd_error_handler |
2498 | 0 | (_("Warning: should use \"_\" to contact Profiles with other " |
2499 | 0 | "extensions")); |
2500 | 0 | *pp = p; |
2501 | 0 | return true; |
2502 | 0 | } |
2503 | 12.9k | } |
2504 | | /* Not found profile, return directly. */ |
2505 | 1.61k | return false; |
2506 | 1.61k | } |
2507 | | |
2508 | | /* Function for parsing ISA string. |
2509 | | |
2510 | | Return Value: |
2511 | | Return TRUE on success. |
2512 | | |
2513 | | Arguments: |
2514 | | `rps`: Hooks and status for parsing extensions. |
2515 | | `arch`: Full ISA string. */ |
2516 | | |
2517 | | bool |
2518 | | riscv_parse_subset (riscv_parse_subset_t *rps, |
2519 | | const char *arch) |
2520 | 1.61k | { |
2521 | 1.61k | const char *p; |
2522 | | |
2523 | | /* Init the riscv_ext_order array to compare the order of extensions |
2524 | | quickly. */ |
2525 | 1.61k | riscv_init_ext_order (); |
2526 | | |
2527 | 1.61k | if (arch == NULL) |
2528 | 0 | { |
2529 | 0 | riscv_set_default_arch (rps); |
2530 | 0 | riscv_parse_add_implicit_subsets (rps); |
2531 | 0 | return riscv_parse_check_conflicts (rps); |
2532 | 0 | } |
2533 | | |
2534 | 11.3k | for (p = arch; *p != '\0'; p++) |
2535 | 9.69k | { |
2536 | 9.69k | if (ISUPPER (*p)) |
2537 | 0 | { |
2538 | 0 | rps->error_handler |
2539 | 0 | (_("%s: ISA string cannot contain uppercase letters"), |
2540 | 0 | arch); |
2541 | 0 | return false; |
2542 | 0 | } |
2543 | 9.69k | } |
2544 | | |
2545 | 1.61k | bool profile = false; |
2546 | 1.61k | p = arch; |
2547 | 1.61k | if (riscv_find_profiles (rps, &p)) |
2548 | 0 | { |
2549 | | /* Check if using Profiles. */ |
2550 | 0 | profile = true; |
2551 | 0 | } |
2552 | 1.61k | else if (startswith (p, "rv32")) |
2553 | 0 | { |
2554 | 0 | *rps->xlen = 32; |
2555 | 0 | p += 4; |
2556 | 0 | } |
2557 | 1.61k | else if (startswith (p, "rv64")) |
2558 | 1.61k | { |
2559 | 1.61k | *rps->xlen = 64; |
2560 | 1.61k | p += 4; |
2561 | 1.61k | } |
2562 | 0 | else |
2563 | 0 | { |
2564 | | /* ISA string shouldn't be NULL or empty here. For linker, |
2565 | | it might be empty when we failed to merge the ISA string |
2566 | | in the riscv_merge_attributes. For assembler, we might |
2567 | | give an empty string by .attribute arch, "" or -march=. |
2568 | | However, We have already issued the correct error message |
2569 | | in another side, so do not issue this error when the ISA |
2570 | | string is empty. */ |
2571 | 0 | if (strlen (arch)) |
2572 | 0 | rps->error_handler ( |
2573 | 0 | _("%s: ISA string must begin with rv32, rv64 or Profiles"), |
2574 | 0 | arch); |
2575 | 0 | return false; |
2576 | 0 | } |
2577 | | |
2578 | | /* Parse single standard and prefixed extensions. */ |
2579 | 1.61k | if (riscv_parse_extensions (rps, arch, p, profile) == NULL) |
2580 | 0 | return false; |
2581 | | |
2582 | | /* Finally add implicit extensions according to the current |
2583 | | extensions. */ |
2584 | 1.61k | riscv_parse_add_implicit_subsets (rps); |
2585 | | |
2586 | | /* Check the conflicts. */ |
2587 | 1.61k | return riscv_parse_check_conflicts (rps); |
2588 | 1.61k | } |
2589 | | |
2590 | | /* Return the number of digits for the input. */ |
2591 | | |
2592 | | size_t |
2593 | | riscv_estimate_digit (unsigned num) |
2594 | 45.2k | { |
2595 | 45.2k | size_t digit = 0; |
2596 | 45.2k | if (num == 0) |
2597 | 14.5k | return 1; |
2598 | | |
2599 | 90.4k | for (digit = 0; num ; num /= 10) |
2600 | 59.7k | digit++; |
2601 | | |
2602 | 30.7k | return digit; |
2603 | 45.2k | } |
2604 | | |
2605 | | /* Auxiliary function to estimate string length of subset list. */ |
2606 | | |
2607 | | static size_t |
2608 | | riscv_estimate_arch_strlen1 (const riscv_subset_t *subset) |
2609 | 24.2k | { |
2610 | 24.2k | if (subset == NULL) |
2611 | 1.61k | return 6; /* For rv32/rv64/rv128 and string terminator. */ |
2612 | | |
2613 | 22.6k | return riscv_estimate_arch_strlen1 (subset->next) |
2614 | 22.6k | + strlen (subset->name) |
2615 | 22.6k | + riscv_estimate_digit (subset->major_version) |
2616 | 22.6k | + 1 /* For version seperator 'p'. */ |
2617 | 22.6k | + riscv_estimate_digit (subset->minor_version) |
2618 | 22.6k | + 1 /* For underscore. */; |
2619 | 24.2k | } |
2620 | | |
2621 | | /* Estimate the string length of this subset list. */ |
2622 | | |
2623 | | static size_t |
2624 | | riscv_estimate_arch_strlen (const riscv_subset_list_t *subset_list) |
2625 | 1.61k | { |
2626 | 1.61k | return riscv_estimate_arch_strlen1 (subset_list->head); |
2627 | 1.61k | } |
2628 | | |
2629 | | /* Auxiliary function to convert subset info to string. */ |
2630 | | |
2631 | | static void |
2632 | | riscv_arch_str1 (riscv_subset_t *subset, |
2633 | | char *attr_str, char *buf, size_t bufsz) |
2634 | 22.6k | { |
2635 | 22.6k | const char *underline = "_"; |
2636 | 22.6k | riscv_subset_t *subset_t = subset; |
2637 | | |
2638 | 22.6k | if (subset_t == NULL) |
2639 | 1.61k | return; |
2640 | | |
2641 | | /* No underline between rvXX and i/e. */ |
2642 | 21.0k | if ((strcasecmp (subset_t->name, "i") == 0) |
2643 | 19.3k | || (strcasecmp (subset_t->name, "e") == 0)) |
2644 | 1.61k | underline = ""; |
2645 | | |
2646 | 21.0k | snprintf (buf, bufsz, "%s%s%dp%d", |
2647 | 21.0k | underline, |
2648 | 21.0k | subset_t->name, |
2649 | 21.0k | subset_t->major_version, |
2650 | 21.0k | subset_t->minor_version); |
2651 | | |
2652 | 21.0k | strncat (attr_str, buf, bufsz); |
2653 | | |
2654 | | /* Skip 'i' extension after 'e', or skip extensions which |
2655 | | versions are unknown. */ |
2656 | 22.6k | while (subset_t->next |
2657 | 21.0k | && ((strcmp (subset_t->name, "e") == 0 |
2658 | 0 | && strcmp (subset_t->next->name, "i") == 0) |
2659 | 21.0k | || subset_t->next->major_version == RISCV_UNKNOWN_VERSION |
2660 | 19.3k | || subset_t->next->minor_version == RISCV_UNKNOWN_VERSION)) |
2661 | 1.61k | subset_t = subset_t->next; |
2662 | | |
2663 | 21.0k | riscv_arch_str1 (subset_t->next, attr_str, buf, bufsz); |
2664 | 21.0k | } |
2665 | | |
2666 | | /* Convert subset information into string with explicit versions. */ |
2667 | | |
2668 | | char * |
2669 | | riscv_arch_str (unsigned xlen, riscv_subset_list_t *subset, bool update) |
2670 | 1.61k | { |
2671 | 1.61k | size_t arch_str_len = riscv_estimate_arch_strlen (subset); |
2672 | 1.61k | char *attr_str = xmalloc (arch_str_len); |
2673 | 1.61k | char *buf = xmalloc (arch_str_len); |
2674 | | |
2675 | 1.61k | snprintf (attr_str, arch_str_len, "rv%u", xlen); |
2676 | | |
2677 | 1.61k | riscv_arch_str1 (subset->head, attr_str, buf, arch_str_len); |
2678 | 1.61k | free (buf); |
2679 | | |
2680 | 1.61k | if (update) |
2681 | 1.61k | { |
2682 | 1.61k | if (subset->arch_str != NULL) |
2683 | 0 | free ((void *) subset->arch_str); |
2684 | 1.61k | subset->arch_str = attr_str; |
2685 | 1.61k | } |
2686 | | |
2687 | 1.61k | return attr_str; |
2688 | 1.61k | } |
2689 | | |
2690 | | /* Copy the subset in the subset list. */ |
2691 | | |
2692 | | static struct riscv_subset_t * |
2693 | | riscv_copy_subset (riscv_subset_list_t *subset_list, |
2694 | | riscv_subset_t *subset) |
2695 | 0 | { |
2696 | 0 | if (subset == NULL) |
2697 | 0 | return NULL; |
2698 | | |
2699 | 0 | riscv_subset_t *new = xmalloc (sizeof *new); |
2700 | 0 | new->name = xstrdup (subset->name); |
2701 | 0 | new->major_version = subset->major_version; |
2702 | 0 | new->minor_version = subset->minor_version; |
2703 | 0 | new->next = riscv_copy_subset (subset_list, subset->next); |
2704 | |
|
2705 | 0 | if (subset->next == NULL) |
2706 | 0 | subset_list->tail = new; |
2707 | |
|
2708 | 0 | return new; |
2709 | 0 | } |
2710 | | |
2711 | | /* Copy the subset list. */ |
2712 | | |
2713 | | riscv_subset_list_t * |
2714 | | riscv_copy_subset_list (riscv_subset_list_t *subset_list) |
2715 | 0 | { |
2716 | 0 | riscv_subset_list_t *new = xmalloc (sizeof *new); |
2717 | 0 | new->head = riscv_copy_subset (new, subset_list->head); |
2718 | 0 | new->arch_str = xstrdup (subset_list->arch_str); |
2719 | 0 | return new; |
2720 | 0 | } |
2721 | | |
2722 | | /* Remove the SUBSET from the subset list. */ |
2723 | | |
2724 | | static void |
2725 | | riscv_remove_subset (riscv_subset_list_t *subset_list, |
2726 | | const char *subset) |
2727 | 0 | { |
2728 | 0 | riscv_subset_t *current = subset_list->head; |
2729 | 0 | riscv_subset_t *pre = NULL; |
2730 | 0 | for (; current != NULL; pre = current, current = current->next) |
2731 | 0 | { |
2732 | 0 | if (strcmp (current->name, subset) == 0) |
2733 | 0 | { |
2734 | 0 | if (pre == NULL) |
2735 | 0 | subset_list->head = current->next; |
2736 | 0 | else |
2737 | 0 | pre->next = current->next; |
2738 | 0 | if (current->next == NULL) |
2739 | 0 | subset_list->tail = pre; |
2740 | 0 | free ((void *) current->name); |
2741 | 0 | free (current); |
2742 | 0 | break; |
2743 | 0 | } |
2744 | 0 | } |
2745 | 0 | } |
2746 | | |
2747 | | /* Auxiliary to add/remove extensions to/from the subset list. |
2748 | | This is called from riscv_update_subset or riscv_parse_add_implicit_subsets. |
2749 | | |
2750 | | The EXTS, +extension[version] [,...,+extension_n[version_n]] |
2751 | | (Deprecated) -extension [,...,-extension_n], |
2752 | | full ISA. |
2753 | | |
2754 | | IMPLICT is false when called from riscv_update_subset(), i.e. when dealing |
2755 | | with the operand of ".option arch". */ |
2756 | | |
2757 | | static bool |
2758 | | riscv_update_subset1 (riscv_parse_subset_t *rps, |
2759 | | const char *exts, |
2760 | | bool implicit) |
2761 | 11.3k | { |
2762 | 11.3k | const char *p = exts; |
2763 | 11.3k | const char *errmsg_internal = !implicit ? "" : _("internal: "); |
2764 | 11.3k | const char *errmsg_caller = !implicit |
2765 | 11.3k | ? ".option arch" : "riscv_implicit_subsets"; |
2766 | | |
2767 | 11.3k | do |
2768 | 22.6k | { |
2769 | 22.6k | int major_version = RISCV_UNKNOWN_VERSION; |
2770 | 22.6k | int minor_version = RISCV_UNKNOWN_VERSION; |
2771 | | |
2772 | 22.6k | bool removed = false; |
2773 | 22.6k | switch (*p) |
2774 | 22.6k | { |
2775 | 22.6k | case '+': removed = false; break; |
2776 | 0 | case '-': removed = true; break; |
2777 | 0 | default: |
2778 | 0 | riscv_release_subset_list (rps->subset_list); |
2779 | 0 | return riscv_parse_subset (rps, p); |
2780 | 22.6k | } |
2781 | 22.6k | ++p; |
2782 | | |
2783 | 22.6k | char *subset = xstrdup (p); |
2784 | 22.6k | char *q = subset; |
2785 | 22.6k | const char *end_of_version; |
2786 | | /* Extract the whole prefixed extension by ','. */ |
2787 | 96.9k | while (*q != '\0' && *q != ',') |
2788 | 74.3k | q++; |
2789 | | |
2790 | | /* Look forward to the first letter which is not <major>p<minor>. */ |
2791 | 22.6k | bool find_any_version = false; |
2792 | 22.6k | bool find_minor_version = false; |
2793 | 22.6k | size_t len = q - subset; |
2794 | 22.6k | size_t i; |
2795 | 22.6k | for (i = len; i > 0; i--) |
2796 | 22.6k | { |
2797 | 22.6k | q--; |
2798 | 22.6k | if (ISDIGIT (*q)) |
2799 | 0 | find_any_version = true; |
2800 | 22.6k | else if (find_any_version |
2801 | 0 | && !find_minor_version |
2802 | 0 | && q > subset |
2803 | 0 | && *q == 'p' |
2804 | 0 | && ISDIGIT (*(q - 1))) |
2805 | 0 | find_minor_version = true; |
2806 | 22.6k | else |
2807 | 22.6k | break; |
2808 | 22.6k | } |
2809 | | |
2810 | | /* Check if the end of extension is 'p' or not. If yes, then |
2811 | | the second letter from the end cannot be number. */ |
2812 | 22.6k | if (q > subset && *q == 'p' && ISDIGIT (*(q - 1))) |
2813 | 0 | { |
2814 | 0 | q[1] = '\0'; |
2815 | 0 | rps->error_handler |
2816 | 0 | (_("%sinvalid ISA extension `%s' ends with <number>p in %s `%s'"), |
2817 | 0 | errmsg_internal, subset, errmsg_caller, exts); |
2818 | 0 | free (subset); |
2819 | 0 | return false; |
2820 | 0 | } |
2821 | | |
2822 | 22.6k | if (len > 0) |
2823 | 22.6k | q++; |
2824 | | |
2825 | 22.6k | end_of_version = |
2826 | 22.6k | riscv_parsing_subset_version (q, &major_version, &minor_version); |
2827 | 22.6k | *q = '\0'; |
2828 | | |
2829 | 22.6k | if (strlen (subset) == 0 |
2830 | 22.6k | || (strlen (subset) == 1 |
2831 | 9.69k | && riscv_ext_order[(*subset - 'a')] == 0) |
2832 | 22.6k | || (strlen (subset) > 1 |
2833 | 12.9k | && rps->check_unknown_prefixed_ext |
2834 | 0 | && !riscv_recognized_prefixed_ext (subset))) |
2835 | 0 | { |
2836 | 0 | rps->error_handler |
2837 | 0 | (_("%sunknown ISA extension `%s' in %s `%s'"), |
2838 | 0 | errmsg_internal, subset, errmsg_caller, exts); |
2839 | 0 | free (subset); |
2840 | 0 | return false; |
2841 | 0 | } |
2842 | | |
2843 | 22.6k | if (!implicit) |
2844 | 0 | { |
2845 | 0 | if (removed) |
2846 | 0 | { |
2847 | 0 | rps->error_handler |
2848 | 0 | (_("deprecated - extension `%s' in %s `%s'"), |
2849 | 0 | subset, errmsg_caller, exts); |
2850 | 0 | free (subset); |
2851 | 0 | return false; |
2852 | 0 | } |
2853 | 0 | else if (strcmp (subset, "i") == 0 |
2854 | 0 | || strcmp (subset, "e") == 0 |
2855 | 0 | || strcmp (subset, "g") == 0) |
2856 | 0 | { |
2857 | 0 | rps->error_handler |
2858 | 0 | (_("cannot + base extension `%s' in %s `%s'"), |
2859 | 0 | subset, errmsg_caller, exts); |
2860 | 0 | free (subset); |
2861 | 0 | return false; |
2862 | 0 | } |
2863 | 0 | } |
2864 | | |
2865 | 22.6k | if (removed) |
2866 | 0 | riscv_remove_subset (rps->subset_list, subset); |
2867 | 22.6k | else |
2868 | 22.6k | { |
2869 | 22.6k | riscv_subset_t *isubset = NULL; |
2870 | 22.6k | if (!riscv_lookup_subset (rps->subset_list, subset, &isubset)) |
2871 | 19.3k | riscv_parse_add_subset (rps, subset, major_version, minor_version, |
2872 | 19.3k | implicit); |
2873 | 22.6k | } |
2874 | 22.6k | p += end_of_version - subset; |
2875 | 22.6k | free (subset); |
2876 | 22.6k | } |
2877 | 22.6k | while (*p++ == ','); |
2878 | | |
2879 | 11.3k | bool no_conflict = true; |
2880 | 11.3k | if (!implicit) |
2881 | 0 | { |
2882 | 0 | riscv_parse_add_implicit_subsets (rps); |
2883 | 0 | no_conflict = riscv_parse_check_conflicts (rps); |
2884 | 0 | } |
2885 | 11.3k | return no_conflict; |
2886 | 11.3k | } |
2887 | | |
2888 | | /* Add an extension to/from the subset list. This is used for the .option rvc |
2889 | | and .option arch directives. */ |
2890 | | |
2891 | | bool |
2892 | | riscv_update_subset (riscv_parse_subset_t *rps, |
2893 | | const char *str) |
2894 | 0 | { |
2895 | 0 | unsigned int newxlen = *rps->xlen; |
2896 | 0 | riscv_parse_subset_t newrps = { |
2897 | 0 | .subset_list = riscv_copy_subset_list (rps->subset_list), |
2898 | 0 | .error_handler = rps->error_handler, |
2899 | 0 | .xlen = &newxlen, |
2900 | 0 | .isa_spec = rps->isa_spec, |
2901 | 0 | .check_unknown_prefixed_ext = rps->check_unknown_prefixed_ext, |
2902 | 0 | }; |
2903 | |
|
2904 | 0 | if (!riscv_update_subset1 (&newrps, str, false /* implicit */)) |
2905 | 0 | { |
2906 | 0 | riscv_release_subset_list (newrps.subset_list); |
2907 | 0 | free (newrps.subset_list); |
2908 | 0 | return false; |
2909 | 0 | } |
2910 | | |
2911 | 0 | *rps->xlen = newxlen; |
2912 | 0 | riscv_release_subset_list (rps->subset_list); |
2913 | 0 | *rps->subset_list = *newrps.subset_list; |
2914 | 0 | free (newrps.subset_list); |
2915 | |
|
2916 | 0 | return true; |
2917 | 0 | } |
2918 | | |
2919 | | /* Called from .option norvc directives. */ |
2920 | | |
2921 | | bool |
2922 | | riscv_update_subset_norvc (riscv_parse_subset_t *rps) |
2923 | 0 | { |
2924 | 0 | return riscv_update_subset1 (rps, |
2925 | 0 | "-c,-zca,-zcd,-zcf,-zcb,-zce,-zcmp,-zcmt," |
2926 | 0 | "-zcmop,-zclsd", |
2927 | 0 | true /* implicit */); |
2928 | 0 | } |
2929 | | |
2930 | | /* Check if the FEATURE subset is supported or not in the subset list. |
2931 | | Return true if it is supported; Otherwise, return false. */ |
2932 | | |
2933 | | bool |
2934 | | riscv_subset_supports (riscv_parse_subset_t *rps, |
2935 | | const char *feature) |
2936 | 5.69M | { |
2937 | 5.69M | struct riscv_subset_t *subset; |
2938 | 5.69M | return riscv_lookup_subset (rps->subset_list, feature, &subset); |
2939 | 5.69M | } |
2940 | | |
2941 | | /* Each instuction is belonged to an instruction class INSN_CLASS_*. |
2942 | | Call riscv_subset_supports to make sure if the instuction is valid. */ |
2943 | | |
2944 | | bool |
2945 | | riscv_multi_subset_supports (riscv_parse_subset_t *rps, |
2946 | | enum riscv_insn_class insn_class) |
2947 | 1.85M | { |
2948 | 1.85M | switch (insn_class) |
2949 | 1.85M | { |
2950 | 78.5k | case INSN_CLASS_I: |
2951 | 78.5k | return riscv_subset_supports (rps, "i"); |
2952 | 132 | case INSN_CLASS_ZICBOM: |
2953 | 132 | return riscv_subset_supports (rps, "zicbom"); |
2954 | 123 | case INSN_CLASS_ZICBOP: |
2955 | 123 | return riscv_subset_supports (rps, "zicbop"); |
2956 | 73 | case INSN_CLASS_ZICBOZ: |
2957 | 73 | return riscv_subset_supports (rps, "zicboz"); |
2958 | 99 | case INSN_CLASS_ZICOND: |
2959 | 99 | return riscv_subset_supports (rps, "zicond"); |
2960 | 10.3k | case INSN_CLASS_ZICSR: |
2961 | 10.3k | return riscv_subset_supports (rps, "zicsr"); |
2962 | 45 | case INSN_CLASS_ZIFENCEI: |
2963 | 45 | return riscv_subset_supports (rps, "zifencei"); |
2964 | 67 | case INSN_CLASS_ZIHINTNTL: |
2965 | 67 | return riscv_subset_supports (rps, "zihintntl"); |
2966 | 118 | case INSN_CLASS_ZIHINTNTL_AND_ZCA: |
2967 | 118 | return riscv_subset_supports (rps, "zihintntl") |
2968 | 0 | && riscv_subset_supports (rps, "zca"); |
2969 | 102 | case INSN_CLASS_ZIHINTPAUSE: |
2970 | 102 | return riscv_subset_supports (rps, "zihintpause"); |
2971 | 235 | case INSN_CLASS_ZIMOP: |
2972 | 235 | return riscv_subset_supports (rps, "zimop"); |
2973 | 98 | case INSN_CLASS_ZICFISS: |
2974 | 98 | return riscv_subset_supports (rps, "zicfiss"); |
2975 | 286 | case INSN_CLASS_ZICFISS_AND_ZCMOP: |
2976 | 286 | return riscv_subset_supports (rps, "zicfiss") |
2977 | 0 | && riscv_subset_supports (rps, "zcmop"); |
2978 | 1.25k | case INSN_CLASS_ZICFILP: |
2979 | 1.25k | return riscv_subset_supports (rps, "zicfilp"); |
2980 | 323 | case INSN_CLASS_M: |
2981 | 323 | return riscv_subset_supports (rps, "m"); |
2982 | 408 | case INSN_CLASS_ZMMUL: |
2983 | 408 | return riscv_subset_supports (rps, "zmmul"); |
2984 | 1.51k | case INSN_CLASS_ZAAMO: |
2985 | 1.51k | return riscv_subset_supports (rps, "zaamo"); |
2986 | 1.33k | case INSN_CLASS_ZABHA: |
2987 | 1.33k | return riscv_subset_supports (rps, "zabha"); |
2988 | 1.74k | case INSN_CLASS_ZACAS: |
2989 | 1.74k | return riscv_subset_supports (rps, "zacas"); |
2990 | 337 | case INSN_CLASS_ZABHA_AND_ZACAS: |
2991 | 337 | return (riscv_subset_supports (rps, "zabha") |
2992 | 0 | && riscv_subset_supports (rps, "zacas")); |
2993 | 30 | case INSN_CLASS_ZALASR: |
2994 | 30 | return riscv_subset_supports (rps, "zalasr"); |
2995 | 173 | case INSN_CLASS_ZALRSC: |
2996 | 173 | return riscv_subset_supports (rps, "zalrsc"); |
2997 | 228 | case INSN_CLASS_ZAWRS: |
2998 | 228 | return riscv_subset_supports (rps, "zawrs"); |
2999 | 5.00k | case INSN_CLASS_F: |
3000 | 5.00k | return riscv_subset_supports (rps, "f"); |
3001 | 1.23k | case INSN_CLASS_D: |
3002 | 1.23k | return riscv_subset_supports (rps, "d"); |
3003 | 1.67k | case INSN_CLASS_Q: |
3004 | 1.67k | return riscv_subset_supports (rps, "q"); |
3005 | 1.38M | case INSN_CLASS_ZCA: |
3006 | 1.38M | return riscv_subset_supports (rps, "zca"); |
3007 | 0 | case INSN_CLASS_ZCF: |
3008 | 0 | return riscv_subset_supports (rps, "zcf"); |
3009 | 185k | case INSN_CLASS_ZCD: |
3010 | 185k | return riscv_subset_supports (rps, "zcd"); |
3011 | 11.9k | case INSN_CLASS_F_INX: |
3012 | 11.9k | return (riscv_subset_supports (rps, "f") |
3013 | 0 | || riscv_subset_supports (rps, "zfinx")); |
3014 | 8.15k | case INSN_CLASS_D_INX: |
3015 | 8.15k | return (riscv_subset_supports (rps, "d") |
3016 | 0 | || riscv_subset_supports (rps, "zdinx")); |
3017 | 9.06k | case INSN_CLASS_Q_INX: |
3018 | 9.06k | return (riscv_subset_supports (rps, "q") |
3019 | 9.06k | || riscv_subset_supports (rps, "zqinx")); |
3020 | 5.93k | case INSN_CLASS_ZFH_INX: |
3021 | 5.93k | return (riscv_subset_supports (rps, "zfh") |
3022 | 5.93k | || riscv_subset_supports (rps, "zhinx")); |
3023 | 1.16k | case INSN_CLASS_ZFHMIN: |
3024 | 1.16k | return riscv_subset_supports (rps, "zfhmin"); |
3025 | 95 | case INSN_CLASS_ZFHMIN_INX: |
3026 | 95 | return (riscv_subset_supports (rps, "zfhmin") |
3027 | 95 | || riscv_subset_supports (rps, "zhinxmin")); |
3028 | 1 | case INSN_CLASS_ZFHMIN_AND_D_INX: |
3029 | 1 | return ((riscv_subset_supports (rps, "zfhmin") |
3030 | 0 | && riscv_subset_supports (rps, "d")) |
3031 | 1 | || (riscv_subset_supports (rps, "zhinxmin") |
3032 | 0 | && riscv_subset_supports (rps, "zdinx"))); |
3033 | 45 | case INSN_CLASS_ZFHMIN_AND_Q_INX: |
3034 | 45 | return ((riscv_subset_supports (rps, "zfhmin") |
3035 | 0 | && riscv_subset_supports (rps, "q")) |
3036 | 45 | || (riscv_subset_supports (rps, "zhinxmin") |
3037 | 0 | && riscv_subset_supports (rps, "zqinx"))); |
3038 | 10 | case INSN_CLASS_ZFBFMIN: |
3039 | 10 | return riscv_subset_supports (rps, "zfbfmin"); |
3040 | 114 | case INSN_CLASS_ZFA: |
3041 | 114 | return riscv_subset_supports (rps, "zfa"); |
3042 | 150 | case INSN_CLASS_D_AND_ZFA: |
3043 | 150 | return riscv_subset_supports (rps, "d") |
3044 | 150 | && riscv_subset_supports (rps, "zfa"); |
3045 | 108 | case INSN_CLASS_Q_AND_ZFA: |
3046 | 108 | return riscv_subset_supports (rps, "q") |
3047 | 0 | && riscv_subset_supports (rps, "zfa"); |
3048 | 87 | case INSN_CLASS_ZFH_AND_ZFA: |
3049 | 87 | return riscv_subset_supports (rps, "zfh") |
3050 | 0 | && riscv_subset_supports (rps, "zfa"); |
3051 | 0 | case INSN_CLASS_ZFH_OR_ZVFH_AND_ZFA: |
3052 | 0 | return (riscv_subset_supports (rps, "zfh") |
3053 | 0 | || riscv_subset_supports (rps, "zvfh")) |
3054 | 0 | && riscv_subset_supports (rps, "zfa"); |
3055 | 380 | case INSN_CLASS_ZBA: |
3056 | 380 | return riscv_subset_supports (rps, "zba"); |
3057 | 198 | case INSN_CLASS_ZBB: |
3058 | 198 | return riscv_subset_supports (rps, "zbb"); |
3059 | 27 | case INSN_CLASS_ZBC: |
3060 | 27 | return riscv_subset_supports (rps, "zbc"); |
3061 | 385 | case INSN_CLASS_ZBS: |
3062 | 385 | return riscv_subset_supports (rps, "zbs"); |
3063 | 90 | case INSN_CLASS_ZBKB: |
3064 | 90 | return riscv_subset_supports (rps, "zbkb"); |
3065 | 0 | case INSN_CLASS_ZBKC: |
3066 | 0 | return riscv_subset_supports (rps, "zbkc"); |
3067 | 88 | case INSN_CLASS_ZBKX: |
3068 | 88 | return riscv_subset_supports (rps, "zbkx"); |
3069 | 286 | case INSN_CLASS_ZBB_OR_ZBKB: |
3070 | 286 | return (riscv_subset_supports (rps, "zbb") |
3071 | 286 | || riscv_subset_supports (rps, "zbkb")); |
3072 | 66 | case INSN_CLASS_ZBC_OR_ZBKC: |
3073 | 66 | return (riscv_subset_supports (rps, "zbc") |
3074 | 66 | || riscv_subset_supports (rps, "zbkc")); |
3075 | 162 | case INSN_CLASS_ZKND: |
3076 | 162 | return riscv_subset_supports (rps, "zknd"); |
3077 | 177 | case INSN_CLASS_ZKNE: |
3078 | 177 | return riscv_subset_supports (rps, "zkne"); |
3079 | 153 | case INSN_CLASS_ZKNH: |
3080 | 153 | return riscv_subset_supports (rps, "zknh"); |
3081 | 59 | case INSN_CLASS_ZKND_OR_ZKNE: |
3082 | 59 | return (riscv_subset_supports (rps, "zknd") |
3083 | 59 | || riscv_subset_supports (rps, "zkne")); |
3084 | 168 | case INSN_CLASS_ZKSED: |
3085 | 168 | return riscv_subset_supports (rps, "zksed"); |
3086 | 199 | case INSN_CLASS_ZKSH: |
3087 | 199 | return riscv_subset_supports (rps, "zksh"); |
3088 | 10.4k | case INSN_CLASS_V: |
3089 | 10.4k | return (riscv_subset_supports (rps, "v") |
3090 | 10.4k | || riscv_subset_supports (rps, "zve64x") |
3091 | 10.4k | || riscv_subset_supports (rps, "zve32x")); |
3092 | 703 | case INSN_CLASS_ZVE64X: |
3093 | 703 | return (riscv_subset_supports (rps, "v") |
3094 | 703 | || riscv_subset_supports (rps, "zve64x")); |
3095 | 1.36k | case INSN_CLASS_ZVEF: |
3096 | 1.36k | return (riscv_subset_supports (rps, "v") |
3097 | 1.36k | || riscv_subset_supports (rps, "zve64d") |
3098 | 1.36k | || riscv_subset_supports (rps, "zve64f") |
3099 | 1.36k | || riscv_subset_supports (rps, "zve32f")); |
3100 | 167 | case INSN_CLASS_ZVABD: |
3101 | 167 | return riscv_subset_supports (rps, "zvabd"); |
3102 | 543 | case INSN_CLASS_ZVBB: |
3103 | 543 | return riscv_subset_supports (rps, "zvbb"); |
3104 | 188 | case INSN_CLASS_ZVBC: |
3105 | 188 | return riscv_subset_supports (rps, "zvbc"); |
3106 | 48 | case INSN_CLASS_ZVFBFMIN: |
3107 | 48 | return riscv_subset_supports (rps, "zvfbfmin"); |
3108 | 165 | case INSN_CLASS_ZVFBFWMA: |
3109 | 165 | return riscv_subset_supports (rps, "zvfbfwma"); |
3110 | 48 | case INSN_CLASS_ZVFBDOTA32F: |
3111 | 48 | return riscv_subset_supports (rps, "zvfbdota32f"); |
3112 | 95 | case INSN_CLASS_ZVFQWBDOTA8F: |
3113 | 95 | return riscv_subset_supports (rps, "zvfqwbdota8f"); |
3114 | 29 | case INSN_CLASS_ZVFQWDOTA8F: |
3115 | 29 | return riscv_subset_supports (rps, "zvfqwdota8f"); |
3116 | 36 | case INSN_CLASS_ZVFWBDOTA16BF: |
3117 | 36 | return riscv_subset_supports (rps, "zvfwbdota16bf"); |
3118 | 157 | case INSN_CLASS_ZVFWDOTA16BF: |
3119 | 157 | return riscv_subset_supports (rps, "zvfwdota16bf"); |
3120 | 211 | case INSN_CLASS_ZVKB: |
3121 | 211 | return riscv_subset_supports (rps, "zvkb"); |
3122 | 8 | case INSN_CLASS_ZVKG: |
3123 | 8 | return riscv_subset_supports (rps, "zvkg"); |
3124 | 60 | case INSN_CLASS_ZVKNED: |
3125 | 60 | return riscv_subset_supports (rps, "zvkned"); |
3126 | 81 | case INSN_CLASS_ZVKNHA_OR_ZVKNHB: |
3127 | 81 | return (riscv_subset_supports (rps, "zvknha") |
3128 | 81 | || riscv_subset_supports (rps, "zvknhb")); |
3129 | 218 | case INSN_CLASS_ZVKSED: |
3130 | 218 | return riscv_subset_supports (rps, "zvksed"); |
3131 | 23 | case INSN_CLASS_ZVKSH: |
3132 | 23 | return riscv_subset_supports (rps, "zvksh"); |
3133 | 0 | case INSN_CLASS_ZVQWBDOTA8I: |
3134 | 0 | return riscv_subset_supports (rps, "zvqwbdota8i"); |
3135 | 0 | case INSN_CLASS_ZVQWBDOTA16I: |
3136 | 0 | return riscv_subset_supports (rps, "zvqwbdota16i"); |
3137 | 197 | case INSN_CLASS_ZVQWBDOTA8I_OR_ZVQWBDOTA16I: |
3138 | 197 | return (riscv_subset_supports (rps, "zvqwbdota8i") |
3139 | 197 | || riscv_subset_supports (rps, "zvqwbdota16i")); |
3140 | 0 | case INSN_CLASS_ZVQWDOTA8I: |
3141 | 0 | return riscv_subset_supports (rps, "zvqwdota8i"); |
3142 | 0 | case INSN_CLASS_ZVQWDOTA16I: |
3143 | 0 | return riscv_subset_supports (rps, "zvqwdota16i"); |
3144 | 126 | case INSN_CLASS_ZVQWDOTA8I_OR_ZVQWDOTA16I: |
3145 | 126 | return (riscv_subset_supports (rps, "zvqwdota8i") |
3146 | 126 | || riscv_subset_supports (rps, "zvqwdota16i")); |
3147 | 53.4k | case INSN_CLASS_ZCB: |
3148 | 53.4k | return riscv_subset_supports (rps, "zcb"); |
3149 | 798 | case INSN_CLASS_ZCB_AND_ZBB: |
3150 | 798 | return (riscv_subset_supports (rps, "zcb") |
3151 | 0 | && riscv_subset_supports (rps, "zbb")); |
3152 | 740 | case INSN_CLASS_ZCB_AND_ZBA: |
3153 | 740 | return (riscv_subset_supports (rps, "zcb") |
3154 | 0 | && riscv_subset_supports (rps, "zba")); |
3155 | 1.88k | case INSN_CLASS_ZCB_AND_ZMMUL: |
3156 | 1.88k | return (riscv_subset_supports (rps, "zcb") |
3157 | 0 | && riscv_subset_supports (rps, "zmmul")); |
3158 | 770 | case INSN_CLASS_ZCMOP: |
3159 | 770 | return riscv_subset_supports (rps, "zcmop"); |
3160 | 0 | case INSN_CLASS_ZCMP: |
3161 | 0 | return riscv_subset_supports (rps, "zcmp"); |
3162 | 0 | case INSN_CLASS_ZCMT: |
3163 | 0 | return riscv_subset_supports (rps, "zcmt"); |
3164 | 16 | case INSN_CLASS_SMCTR_OR_SSCTR: |
3165 | 16 | return (riscv_subset_supports (rps, "smctr") |
3166 | 16 | || riscv_subset_supports (rps, "ssctr")); |
3167 | 0 | case INSN_CLASS_ZILSD: |
3168 | 0 | return riscv_subset_supports (rps, "zilsd"); |
3169 | 0 | case INSN_CLASS_ZCLSD: |
3170 | 0 | return riscv_subset_supports (rps, "zclsd"); |
3171 | 0 | case INSN_CLASS_SMRNMI: |
3172 | 0 | return riscv_subset_supports (rps, "smrnmi"); |
3173 | 40 | case INSN_CLASS_SVINVAL: |
3174 | 40 | return riscv_subset_supports (rps, "svinval"); |
3175 | 104 | case INSN_CLASS_H: |
3176 | 104 | return riscv_subset_supports (rps, "h"); |
3177 | 79 | case INSN_CLASS_XANDESBFHCVT: |
3178 | 79 | return riscv_subset_supports (rps, "xandesbfhcvt"); |
3179 | 54 | case INSN_CLASS_XANDESVBFHCVT: |
3180 | 54 | return riscv_subset_supports (rps, "xandesvbfhcvt"); |
3181 | 39 | case INSN_CLASS_XANDESVSINTLOAD: |
3182 | 39 | return riscv_subset_supports (rps, "xandesvsintload"); |
3183 | 90 | case INSN_CLASS_XANDESVPACKFPH: |
3184 | 90 | return riscv_subset_supports (rps, "xandesvpackfph"); |
3185 | 48 | case INSN_CLASS_XANDESVDOT: |
3186 | 48 | return riscv_subset_supports (rps, "xandesvdot"); |
3187 | 96 | case INSN_CLASS_XANDESVSINTH: |
3188 | 96 | return riscv_subset_supports (rps, "xandesvsinth"); |
3189 | 1.51k | case INSN_CLASS_XCVALU: |
3190 | 1.51k | return riscv_subset_supports (rps, "xcvalu"); |
3191 | 4.04k | case INSN_CLASS_XCVBI: |
3192 | 4.04k | return riscv_subset_supports (rps, "xcvbi"); |
3193 | 2.05k | case INSN_CLASS_XCVBITMANIP: |
3194 | 2.05k | return riscv_subset_supports (rps, "xcvbitmanip"); |
3195 | 2.16k | case INSN_CLASS_XCVELW: |
3196 | 2.16k | return riscv_subset_supports (rps, "xcvelw"); |
3197 | 6.24k | case INSN_CLASS_XCVMAC: |
3198 | 6.24k | return riscv_subset_supports (rps, "xcvmac"); |
3199 | 17.5k | case INSN_CLASS_XCVMEM: |
3200 | 17.5k | return riscv_subset_supports (rps, "xcvmem"); |
3201 | 2.67k | case INSN_CLASS_XCVSIMD: |
3202 | 2.67k | return riscv_subset_supports (rps, "xcvsimd"); |
3203 | 552 | case INSN_CLASS_XTHEADBA: |
3204 | 552 | return riscv_subset_supports (rps, "xtheadba"); |
3205 | 1.86k | case INSN_CLASS_XTHEADBB: |
3206 | 1.86k | return riscv_subset_supports (rps, "xtheadbb"); |
3207 | 148 | case INSN_CLASS_XTHEADBS: |
3208 | 148 | return riscv_subset_supports (rps, "xtheadbs"); |
3209 | 224 | case INSN_CLASS_XTHEADCMO: |
3210 | 224 | return riscv_subset_supports (rps, "xtheadcmo"); |
3211 | 362 | case INSN_CLASS_XTHEADCONDMOV: |
3212 | 362 | return riscv_subset_supports (rps, "xtheadcondmov"); |
3213 | 837 | case INSN_CLASS_XTHEADFMEMIDX: |
3214 | 837 | return riscv_subset_supports (rps, "xtheadfmemidx"); |
3215 | 0 | case INSN_CLASS_XTHEADFMV: |
3216 | 0 | return riscv_subset_supports (rps, "xtheadfmv"); |
3217 | 45 | case INSN_CLASS_XTHEADINT: |
3218 | 45 | return riscv_subset_supports (rps, "xtheadint"); |
3219 | 95 | case INSN_CLASS_XTHEADMAC: |
3220 | 95 | return riscv_subset_supports (rps, "xtheadmac"); |
3221 | 1.94k | case INSN_CLASS_XTHEADMEMIDX: |
3222 | 1.94k | return riscv_subset_supports (rps, "xtheadmemidx"); |
3223 | 232 | case INSN_CLASS_XTHEADMEMPAIR: |
3224 | 232 | return riscv_subset_supports (rps, "xtheadmempair"); |
3225 | 131 | case INSN_CLASS_XTHEADSYNC: |
3226 | 131 | return riscv_subset_supports (rps, "xtheadsync"); |
3227 | 9.35k | case INSN_CLASS_XTHEADVECTOR: |
3228 | 9.35k | return riscv_subset_supports (rps, "xtheadvector"); |
3229 | 200 | case INSN_CLASS_XTHEADVDOT: |
3230 | 200 | return riscv_subset_supports (rps, "xtheadvdot"); |
3231 | 263 | case INSN_CLASS_XXTVARITH: |
3232 | 263 | return riscv_subset_supports (rps, "xxtvarith"); |
3233 | 862 | case INSN_CLASS_XXTVCODER: |
3234 | 862 | return riscv_subset_supports (rps, "xxtvcoder"); |
3235 | 766 | case INSN_CLASS_XTHEADZVAMO: |
3236 | 766 | return riscv_subset_supports (rps, "xtheadzvamo"); |
3237 | 513 | case INSN_CLASS_XVENTANACONDOPS: |
3238 | 513 | return riscv_subset_supports (rps, "xventanacondops"); |
3239 | 964 | case INSN_CLASS_XSFVCP: |
3240 | 964 | return riscv_subset_supports (rps, "xsfvcp"); |
3241 | 0 | case INSN_CLASS_XSFCEASE: |
3242 | 0 | return riscv_subset_supports (rps, "xsfcease"); |
3243 | 207 | case INSN_CLASS_XSFVQMACCQOQ: |
3244 | 207 | return riscv_subset_supports (rps, "xsfvqmaccqoq"); |
3245 | 128 | case INSN_CLASS_XSFVQMACCDOD: |
3246 | 128 | return riscv_subset_supports (rps, "xsfvqmaccdod"); |
3247 | 131 | case INSN_CLASS_XSFVFNRCLIPXFQF: |
3248 | 131 | return riscv_subset_supports (rps, "xsfvfnrclipxfqf"); |
3249 | 5.33k | case INSN_CLASS_XMIPSCBOP: |
3250 | 5.33k | return riscv_subset_supports (rps, "xmipscbop"); |
3251 | 261 | case INSN_CLASS_XMIPSCMOV: |
3252 | 261 | return riscv_subset_supports (rps, "xmipscmov"); |
3253 | 233 | case INSN_CLASS_XMIPSEXECTL: |
3254 | 233 | return riscv_subset_supports (rps, "xmipsexectl"); |
3255 | 1.52k | case INSN_CLASS_XMIPSLSP: |
3256 | 1.52k | return riscv_subset_supports (rps, "xmipslsp"); |
3257 | 0 | case INSN_CLASS_XSMTVDOT: |
3258 | 0 | return riscv_subset_supports (rps, "xsmtvdot"); |
3259 | 3.04k | case INSN_CLASS_XSMTVDOTII: |
3260 | 3.04k | return riscv_subset_supports (rps, "xsmtvdotii"); |
3261 | 111 | case INSN_CLASS_XSMTVDOT_OR_XSMTVDOTII: |
3262 | 111 | return (riscv_subset_supports (rps, "xsmtvdot") |
3263 | 111 | || riscv_subset_supports (rps, "xsmtvdotii")); |
3264 | 0 | default: |
3265 | 0 | rps->error_handler |
3266 | 0 | (_("internal: unreachable INSN_CLASS_*")); |
3267 | 0 | return false; |
3268 | 1.85M | } |
3269 | 1.85M | } |
3270 | | |
3271 | | /* Each instuction is belonged to an instruction class INSN_CLASS_*. |
3272 | | Call riscv_subset_supports_ext to determine the missing extension. */ |
3273 | | |
3274 | | const char * |
3275 | | riscv_multi_subset_supports_ext (riscv_parse_subset_t *rps, |
3276 | | enum riscv_insn_class insn_class) |
3277 | 0 | { |
3278 | 0 | switch (insn_class) |
3279 | 0 | { |
3280 | 0 | case INSN_CLASS_I: |
3281 | 0 | return "i"; |
3282 | 0 | case INSN_CLASS_ZICBOM: |
3283 | 0 | return "zicbom"; |
3284 | 0 | case INSN_CLASS_ZICBOP: |
3285 | 0 | return "zicbop"; |
3286 | 0 | case INSN_CLASS_ZICBOZ: |
3287 | 0 | return "zicboz"; |
3288 | 0 | case INSN_CLASS_ZICOND: |
3289 | 0 | return "zicond"; |
3290 | 0 | case INSN_CLASS_ZICSR: |
3291 | 0 | return "zicsr"; |
3292 | 0 | case INSN_CLASS_ZIFENCEI: |
3293 | 0 | return "zifencei"; |
3294 | 0 | case INSN_CLASS_ZICFISS: |
3295 | 0 | return "zicfiss"; |
3296 | 0 | case INSN_CLASS_ZICFISS_AND_ZCMOP: |
3297 | 0 | if (!riscv_subset_supports (rps, "zicfiss")) |
3298 | 0 | { |
3299 | 0 | if (!riscv_subset_supports (rps, "zcmop")) |
3300 | 0 | return _("zicfiss' and `zcmop"); |
3301 | 0 | else |
3302 | 0 | return "zicfiss"; |
3303 | 0 | } |
3304 | 0 | return "zcmop"; |
3305 | 0 | case INSN_CLASS_ZICFILP: |
3306 | 0 | return "zicfilp"; |
3307 | 0 | case INSN_CLASS_ZIHINTNTL: |
3308 | 0 | return "zihintntl"; |
3309 | 0 | case INSN_CLASS_ZIHINTNTL_AND_ZCA: |
3310 | 0 | if (!riscv_subset_supports (rps, "zihintntl")) |
3311 | 0 | { |
3312 | 0 | if (!riscv_subset_supports (rps, "zca")) |
3313 | 0 | return _("zihintntl' and `c', or `zihintntl' and `zca"); |
3314 | 0 | else |
3315 | 0 | return "zihintntl"; |
3316 | 0 | } |
3317 | 0 | else |
3318 | 0 | return _("c' or `zca"); |
3319 | 0 | case INSN_CLASS_ZIHINTPAUSE: |
3320 | 0 | return "zihintpause"; |
3321 | 0 | case INSN_CLASS_ZIMOP: |
3322 | 0 | return "zimop"; |
3323 | 0 | case INSN_CLASS_M: |
3324 | 0 | return "m"; |
3325 | 0 | case INSN_CLASS_ZMMUL: |
3326 | 0 | return _ ("m' or `zmmul"); |
3327 | 0 | case INSN_CLASS_ZAAMO: |
3328 | 0 | return "zaamo"; |
3329 | 0 | case INSN_CLASS_ZABHA: |
3330 | 0 | return "zabha"; |
3331 | 0 | case INSN_CLASS_ZACAS: |
3332 | 0 | return "zacas"; |
3333 | 0 | case INSN_CLASS_ZABHA_AND_ZACAS: |
3334 | 0 | if (!riscv_subset_supports (rps, "zabha")) |
3335 | 0 | { |
3336 | 0 | if (!riscv_subset_supports (rps, "zacas")) |
3337 | 0 | return _ ("zabha' and `zacas"); |
3338 | 0 | else |
3339 | 0 | return "zabha"; |
3340 | 0 | } |
3341 | 0 | return "zacas"; |
3342 | 0 | case INSN_CLASS_ZALASR: |
3343 | 0 | return "zalasr"; |
3344 | 0 | case INSN_CLASS_ZALRSC: |
3345 | 0 | return "zalrsc"; |
3346 | 0 | case INSN_CLASS_ZAWRS: |
3347 | 0 | return "zawrs"; |
3348 | 0 | case INSN_CLASS_F: |
3349 | 0 | return "f"; |
3350 | 0 | case INSN_CLASS_D: |
3351 | 0 | return "d"; |
3352 | 0 | case INSN_CLASS_Q: |
3353 | 0 | return "q"; |
3354 | 0 | case INSN_CLASS_ZCA: |
3355 | 0 | return _("c' or `zca"); |
3356 | 0 | case INSN_CLASS_ZCF: |
3357 | 0 | return _("f' and `c', or `zcf"); |
3358 | 0 | case INSN_CLASS_ZCD: |
3359 | 0 | return _("d' and `c', or `zcd"); |
3360 | 0 | case INSN_CLASS_F_INX: |
3361 | 0 | return _("f' or `zfinx"); |
3362 | 0 | case INSN_CLASS_D_INX: |
3363 | 0 | return _("d' or `zdinx"); |
3364 | 0 | case INSN_CLASS_Q_INX: |
3365 | 0 | return _("q' or `zqinx"); |
3366 | 0 | case INSN_CLASS_ZFH_INX: |
3367 | 0 | return _("zfh' or `zhinx"); |
3368 | 0 | case INSN_CLASS_ZFHMIN: |
3369 | 0 | return "zfhmin"; |
3370 | 0 | case INSN_CLASS_ZFHMIN_INX: |
3371 | 0 | return _("zfhmin' or `zhinxmin"); |
3372 | 0 | case INSN_CLASS_ZFHMIN_AND_D_INX: |
3373 | 0 | if (riscv_subset_supports (rps, "zfhmin")) |
3374 | 0 | return "d"; |
3375 | 0 | else if (riscv_subset_supports (rps, "d")) |
3376 | 0 | return "zfhmin"; |
3377 | 0 | else if (riscv_subset_supports (rps, "zhinxmin")) |
3378 | 0 | return "zdinx"; |
3379 | 0 | else if (riscv_subset_supports (rps, "zdinx")) |
3380 | 0 | return "zhinxmin"; |
3381 | 0 | else |
3382 | 0 | return _("zfhmin' and `d', or `zhinxmin' and `zdinx"); |
3383 | 0 | case INSN_CLASS_ZFHMIN_AND_Q_INX: |
3384 | 0 | if (riscv_subset_supports (rps, "zfhmin")) |
3385 | 0 | return "q"; |
3386 | 0 | else if (riscv_subset_supports (rps, "q")) |
3387 | 0 | return "zfhmin"; |
3388 | 0 | else if (riscv_subset_supports (rps, "zhinxmin")) |
3389 | 0 | return "zqinx"; |
3390 | 0 | else if (riscv_subset_supports (rps, "zqinx")) |
3391 | 0 | return "zhinxmin"; |
3392 | 0 | else |
3393 | 0 | return _("zfhmin' and `q', or `zhinxmin' and `zqinx"); |
3394 | 0 | case INSN_CLASS_ZFBFMIN: |
3395 | 0 | return "zfbfmin"; |
3396 | 0 | case INSN_CLASS_ZFA: |
3397 | 0 | return "zfa"; |
3398 | 0 | case INSN_CLASS_D_AND_ZFA: |
3399 | 0 | if (!riscv_subset_supports (rps, "d") |
3400 | 0 | && !riscv_subset_supports (rps, "zfa")) |
3401 | 0 | return _("d' and `zfa"); |
3402 | 0 | else if (!riscv_subset_supports (rps, "d")) |
3403 | 0 | return "d"; |
3404 | 0 | else |
3405 | 0 | return "zfa"; |
3406 | 0 | case INSN_CLASS_Q_AND_ZFA: |
3407 | 0 | if (!riscv_subset_supports (rps, "q") |
3408 | 0 | && !riscv_subset_supports (rps, "zfa")) |
3409 | 0 | return _("q' and `zfa"); |
3410 | 0 | else if (!riscv_subset_supports (rps, "q")) |
3411 | 0 | return "q"; |
3412 | 0 | else |
3413 | 0 | return "zfa"; |
3414 | 0 | case INSN_CLASS_ZFH_AND_ZFA: |
3415 | 0 | if (!riscv_subset_supports (rps, "zfh") |
3416 | 0 | && !riscv_subset_supports (rps, "zfa")) |
3417 | 0 | return _("zfh' and `zfa"); |
3418 | 0 | else if (!riscv_subset_supports (rps, "zfh")) |
3419 | 0 | return "zfh"; |
3420 | 0 | else |
3421 | 0 | return "zfa"; |
3422 | 0 | case INSN_CLASS_ZFH_OR_ZVFH_AND_ZFA: |
3423 | 0 | if (!riscv_subset_supports (rps, "zfa")) |
3424 | 0 | { |
3425 | 0 | if (!riscv_subset_supports (rps, "zfh") |
3426 | 0 | && !riscv_subset_supports (rps, "zvfh")) |
3427 | 0 | return _("zfh' and `zfa', or `zvfh' and `zfa"); |
3428 | 0 | else |
3429 | 0 | return "zfa"; |
3430 | 0 | } |
3431 | 0 | else |
3432 | 0 | return _("zfh' or `zvfh"); |
3433 | 0 | case INSN_CLASS_ZBA: |
3434 | 0 | return "zba"; |
3435 | 0 | case INSN_CLASS_ZBB: |
3436 | 0 | return "zbb"; |
3437 | 0 | case INSN_CLASS_ZBC: |
3438 | 0 | return "zbc"; |
3439 | 0 | case INSN_CLASS_ZBS: |
3440 | 0 | return "zbs"; |
3441 | 0 | case INSN_CLASS_ZBKB: |
3442 | 0 | return "zbkb"; |
3443 | 0 | case INSN_CLASS_ZBKC: |
3444 | 0 | return "zbkc"; |
3445 | 0 | case INSN_CLASS_ZBKX: |
3446 | 0 | return "zbkx"; |
3447 | 0 | case INSN_CLASS_ZBB_OR_ZBKB: |
3448 | 0 | return _("zbb' or `zbkb"); |
3449 | 0 | case INSN_CLASS_ZBC_OR_ZBKC: |
3450 | 0 | return _("zbc' or `zbkc"); |
3451 | 0 | case INSN_CLASS_ZKND: |
3452 | 0 | return "zknd"; |
3453 | 0 | case INSN_CLASS_ZKNE: |
3454 | 0 | return "zkne"; |
3455 | 0 | case INSN_CLASS_ZKNH: |
3456 | 0 | return "zknh"; |
3457 | 0 | case INSN_CLASS_ZKND_OR_ZKNE: |
3458 | 0 | return _("zknd' or `zkne"); |
3459 | 0 | case INSN_CLASS_ZKSED: |
3460 | 0 | return "zksed"; |
3461 | 0 | case INSN_CLASS_ZKSH: |
3462 | 0 | return "zksh"; |
3463 | 0 | case INSN_CLASS_V: |
3464 | 0 | return _("v' or `zve64x' or `zve32x"); |
3465 | 0 | case INSN_CLASS_ZVE64X: |
3466 | 0 | return _("v' or `zve64x"); |
3467 | 0 | case INSN_CLASS_ZVEF: |
3468 | 0 | return _("v' or `zve64d' or `zve64f' or `zve32f"); |
3469 | 0 | case INSN_CLASS_ZVABD: |
3470 | 0 | return _("zvabd"); |
3471 | 0 | case INSN_CLASS_ZVBB: |
3472 | 0 | return _("zvbb"); |
3473 | 0 | case INSN_CLASS_ZVBC: |
3474 | 0 | return _("zvbc"); |
3475 | 0 | case INSN_CLASS_ZVFBFMIN: |
3476 | 0 | return "zvfbfmin"; |
3477 | 0 | case INSN_CLASS_ZVFBFWMA: |
3478 | 0 | return "zvfbfwma"; |
3479 | 0 | case INSN_CLASS_ZVFBDOTA32F: |
3480 | 0 | return "zvfbdota32f"; |
3481 | 0 | case INSN_CLASS_ZVFQWBDOTA8F: |
3482 | 0 | return "zvfqwbdota8f"; |
3483 | 0 | case INSN_CLASS_ZVFQWDOTA8F: |
3484 | 0 | return "zvfqwdota8f"; |
3485 | 0 | case INSN_CLASS_ZVFWBDOTA16BF: |
3486 | 0 | return "zvfwbdota16bf"; |
3487 | 0 | case INSN_CLASS_ZVFWDOTA16BF: |
3488 | 0 | return "zvfwdota16bf"; |
3489 | 0 | case INSN_CLASS_ZVKB: |
3490 | 0 | return _("zvkb"); |
3491 | 0 | case INSN_CLASS_ZVKG: |
3492 | 0 | return _("zvkg"); |
3493 | 0 | case INSN_CLASS_ZVKNED: |
3494 | 0 | return _("zvkned"); |
3495 | 0 | case INSN_CLASS_ZVKNHA_OR_ZVKNHB: |
3496 | 0 | return _("zvknha' or `zvknhb"); |
3497 | 0 | case INSN_CLASS_ZVKSED: |
3498 | 0 | return _("zvksed"); |
3499 | 0 | case INSN_CLASS_ZVKSH: |
3500 | 0 | return _("zvksh"); |
3501 | 0 | case INSN_CLASS_ZVQWBDOTA8I: |
3502 | 0 | return "zvqwbdota8i"; |
3503 | 0 | case INSN_CLASS_ZVQWBDOTA16I: |
3504 | 0 | return "zvqwbdota16i"; |
3505 | 0 | case INSN_CLASS_ZVQWBDOTA8I_OR_ZVQWBDOTA16I: |
3506 | 0 | return _("zvqwbdota8i' or `zvqwbdota16i"); |
3507 | 0 | case INSN_CLASS_ZVQWDOTA8I: |
3508 | 0 | return "zvqwdota8i"; |
3509 | 0 | case INSN_CLASS_ZVQWDOTA16I: |
3510 | 0 | return "zvqwdota16i"; |
3511 | 0 | case INSN_CLASS_ZVQWDOTA8I_OR_ZVQWDOTA16I: |
3512 | 0 | return _("zvqwdota8i' or `zvqwdota16i"); |
3513 | 0 | case INSN_CLASS_ZCB: |
3514 | 0 | return "zcb"; |
3515 | 0 | case INSN_CLASS_ZCB_AND_ZBA: |
3516 | 0 | return _("zcb' and `zba"); |
3517 | 0 | case INSN_CLASS_ZCB_AND_ZBB: |
3518 | 0 | return _("zcb' and `zbb"); |
3519 | 0 | case INSN_CLASS_ZCB_AND_ZMMUL: |
3520 | 0 | return _("zcb' and `zmmul', or `zcb' and `m"); |
3521 | 0 | case INSN_CLASS_ZCMOP: |
3522 | 0 | return "zcmop"; |
3523 | 0 | case INSN_CLASS_ZCMP: |
3524 | 0 | return "zcmp"; |
3525 | 0 | case INSN_CLASS_ZCMT: |
3526 | 0 | return "zcmt"; |
3527 | 0 | case INSN_CLASS_SMCTR_OR_SSCTR: |
3528 | 0 | return _("smctr' or `ssctr"); |
3529 | 0 | case INSN_CLASS_ZILSD: |
3530 | 0 | return "zilsd"; |
3531 | 0 | case INSN_CLASS_ZCLSD: |
3532 | 0 | return "zclsd"; |
3533 | 0 | case INSN_CLASS_SMRNMI: |
3534 | 0 | return "smrnmi"; |
3535 | 0 | case INSN_CLASS_SVINVAL: |
3536 | 0 | return "svinval"; |
3537 | 0 | case INSN_CLASS_H: |
3538 | 0 | return _("h"); |
3539 | 0 | case INSN_CLASS_XANDESBFHCVT: |
3540 | 0 | return "xandesbfhcvt"; |
3541 | 0 | case INSN_CLASS_XANDESVBFHCVT: |
3542 | 0 | return "xandesvbfhcvt"; |
3543 | 0 | case INSN_CLASS_XANDESVDOT: |
3544 | 0 | return "xandesvdot"; |
3545 | 0 | case INSN_CLASS_XANDESVPACKFPH: |
3546 | 0 | return "xandesvpackfph"; |
3547 | 0 | case INSN_CLASS_XANDESVSINTH: |
3548 | 0 | return "xandesvsinth"; |
3549 | 0 | case INSN_CLASS_XANDESVSINTLOAD: |
3550 | 0 | return "xandesvsintload"; |
3551 | 0 | case INSN_CLASS_XCVALU: |
3552 | 0 | return "xcvalu"; |
3553 | 0 | case INSN_CLASS_XCVBI: |
3554 | 0 | return "xcvbi"; |
3555 | 0 | case INSN_CLASS_XCVBITMANIP: |
3556 | 0 | return "xcvbitmanip"; |
3557 | 0 | case INSN_CLASS_XCVELW: |
3558 | 0 | return "xcvelw"; |
3559 | 0 | case INSN_CLASS_XCVMAC: |
3560 | 0 | return "xcvmac"; |
3561 | 0 | case INSN_CLASS_XCVMEM: |
3562 | 0 | return "xcvmem"; |
3563 | 0 | case INSN_CLASS_XCVSIMD: |
3564 | 0 | return "xcvsimd"; |
3565 | 0 | case INSN_CLASS_XMIPSCBOP: |
3566 | 0 | return "xmipscbop"; |
3567 | 0 | case INSN_CLASS_XMIPSCMOV: |
3568 | 0 | return "xmipscmov"; |
3569 | 0 | case INSN_CLASS_XMIPSEXECTL: |
3570 | 0 | return "xmipsexectl"; |
3571 | 0 | case INSN_CLASS_XMIPSLSP: |
3572 | 0 | return "xmipslsp"; |
3573 | 0 | case INSN_CLASS_XSFCEASE: |
3574 | 0 | return "xsfcease"; |
3575 | 0 | case INSN_CLASS_XSFVCP: |
3576 | 0 | return "xsfvcp"; |
3577 | 0 | case INSN_CLASS_XSFVFNRCLIPXFQF: |
3578 | 0 | return "xsfvfnrclipxfqf"; |
3579 | 0 | case INSN_CLASS_XSFVQMACCDOD: |
3580 | 0 | return "xsfvqmaccdod"; |
3581 | 0 | case INSN_CLASS_XSFVQMACCQOQ: |
3582 | 0 | return "xsfvqmaccqoq"; |
3583 | 0 | case INSN_CLASS_XSMTVDOT: |
3584 | 0 | return "xsmtvdot"; |
3585 | 0 | case INSN_CLASS_XSMTVDOTII: |
3586 | 0 | return "xsmtvdotii"; |
3587 | 0 | case INSN_CLASS_XSMTVDOT_OR_XSMTVDOTII: |
3588 | 0 | return _("xsmtvdot' or `xsmtvdotii"); |
3589 | 0 | case INSN_CLASS_XTHEADBA: |
3590 | 0 | return "xtheadba"; |
3591 | 0 | case INSN_CLASS_XTHEADBB: |
3592 | 0 | return "xtheadbb"; |
3593 | 0 | case INSN_CLASS_XTHEADBS: |
3594 | 0 | return "xtheadbs"; |
3595 | 0 | case INSN_CLASS_XTHEADCMO: |
3596 | 0 | return "xtheadcmo"; |
3597 | 0 | case INSN_CLASS_XTHEADCONDMOV: |
3598 | 0 | return "xtheadcondmov"; |
3599 | 0 | case INSN_CLASS_XTHEADFMEMIDX: |
3600 | 0 | return "xtheadfmemidx"; |
3601 | 0 | case INSN_CLASS_XTHEADFMV: |
3602 | 0 | return "xtheadfmv"; |
3603 | 0 | case INSN_CLASS_XTHEADINT: |
3604 | 0 | return "xtheadint"; |
3605 | 0 | case INSN_CLASS_XTHEADMAC: |
3606 | 0 | return "xtheadmac"; |
3607 | 0 | case INSN_CLASS_XTHEADMEMIDX: |
3608 | 0 | return "xtheadmemidx"; |
3609 | 0 | case INSN_CLASS_XTHEADMEMPAIR: |
3610 | 0 | return "xtheadmempair"; |
3611 | 0 | case INSN_CLASS_XTHEADSYNC: |
3612 | 0 | return "xtheadsync"; |
3613 | 0 | case INSN_CLASS_XTHEADVDOT: |
3614 | 0 | return "xtheadvdot"; |
3615 | 0 | case INSN_CLASS_XTHEADVECTOR: |
3616 | 0 | return "xtheadvector"; |
3617 | 0 | case INSN_CLASS_XTHEADZVAMO: |
3618 | 0 | return "xtheadzvamo"; |
3619 | 0 | case INSN_CLASS_XVENTANACONDOPS: |
3620 | 0 | return "xventanacondops"; |
3621 | 0 | case INSN_CLASS_XXTVARITH: |
3622 | 0 | return "xxtvarith"; |
3623 | 0 | case INSN_CLASS_XXTVCODER: |
3624 | 0 | return "xxtvcoder"; |
3625 | 0 | default: |
3626 | 0 | rps->error_handler |
3627 | 0 | (_("internal: unreachable INSN_CLASS_*")); |
3628 | 0 | return NULL; |
3629 | 0 | } |
3630 | 0 | } |
3631 | | |
3632 | | /* Print supported extensions with versions if -march=help. */ |
3633 | | |
3634 | | void |
3635 | | riscv_print_extensions (void) |
3636 | 0 | { |
3637 | | /* Record the previous printed extension. |
3638 | | Print the current one if they are not the same. */ |
3639 | 0 | const struct riscv_supported_ext *cur = NULL, *prev = NULL; |
3640 | 0 | int i, j; |
3641 | |
|
3642 | 0 | printf ("All available -march extensions for RISC-V:"); |
3643 | |
|
3644 | 0 | for (i = 0; riscv_all_supported_ext[i] != NULL; i++) |
3645 | 0 | { |
3646 | 0 | const struct riscv_supported_ext *exts = riscv_all_supported_ext[i]; |
3647 | 0 | prev = NULL; |
3648 | 0 | for (j = 0; exts[j].name != NULL; j++) |
3649 | 0 | { |
3650 | 0 | cur = &exts[j]; |
3651 | | /* Unclear version information, skip. */ |
3652 | 0 | if (cur->isa_spec_class == ISA_SPEC_CLASS_NONE |
3653 | 0 | || cur->major_version == RISCV_UNKNOWN_VERSION |
3654 | 0 | || cur->minor_version == RISCV_UNKNOWN_VERSION) |
3655 | 0 | continue; |
3656 | | |
3657 | | /* Same extension. */ |
3658 | 0 | if (prev && strcmp (prev->name, cur->name) == 0) |
3659 | 0 | { |
3660 | | /* Same version, skip. */ |
3661 | 0 | if (prev->major_version == cur->major_version |
3662 | 0 | && prev->minor_version == cur->minor_version) |
3663 | 0 | continue; |
3664 | | /* Different version, print version with comma. */ |
3665 | 0 | else |
3666 | 0 | printf (", %d.%d", cur->major_version, cur->minor_version); |
3667 | 0 | } |
3668 | | /* Different extension, print extension and version with newline. */ |
3669 | 0 | else |
3670 | 0 | printf ("\n\t%-40s%d.%d", cur->name, cur->major_version, |
3671 | 0 | cur->minor_version); |
3672 | 0 | prev = &exts[j]; |
3673 | 0 | } |
3674 | 0 | } |
3675 | 0 | printf ("\n"); |
3676 | 0 | } |
3677 | | |
3678 | | /* Given the ELF header flags in FLAGS, it returns a string that describes the |
3679 | | float ABI. */ |
3680 | | |
3681 | | static const char * |
3682 | | riscv_float_abi_string (flagword flags) |
3683 | 0 | { |
3684 | 0 | switch (flags & EF_RISCV_FLOAT_ABI) |
3685 | 0 | { |
3686 | 0 | case EF_RISCV_FLOAT_ABI_SOFT: |
3687 | 0 | return "soft-float"; |
3688 | 0 | break; |
3689 | 0 | case EF_RISCV_FLOAT_ABI_SINGLE: |
3690 | 0 | return "single-float"; |
3691 | 0 | break; |
3692 | 0 | case EF_RISCV_FLOAT_ABI_DOUBLE: |
3693 | 0 | return "double-float"; |
3694 | 0 | break; |
3695 | 0 | case EF_RISCV_FLOAT_ABI_QUAD: |
3696 | 0 | return "quad-float"; |
3697 | 0 | break; |
3698 | 0 | default: |
3699 | 0 | abort (); |
3700 | 0 | } |
3701 | 0 | } |
3702 | | |
3703 | | /* The information of architecture elf attributes. */ |
3704 | | static riscv_subset_list_t in_subsets; |
3705 | | static riscv_subset_list_t out_subsets; |
3706 | | static riscv_subset_list_t merged_subsets; |
3707 | | |
3708 | | /* Predicator for standard extension. */ |
3709 | | |
3710 | | static bool |
3711 | | riscv_std_ext_p (const char *name) |
3712 | 0 | { |
3713 | 0 | return (strlen (name) == 1) && (name[0] != 'x') && (name[0] != 's'); |
3714 | 0 | } |
3715 | | |
3716 | | /* Update the output subset's version to match the input when the input |
3717 | | subset's version is newer. */ |
3718 | | |
3719 | | static void |
3720 | | riscv_update_subset_version (struct riscv_subset_t *in, |
3721 | | struct riscv_subset_t *out) |
3722 | 0 | { |
3723 | 0 | if (in == NULL || out == NULL) |
3724 | 0 | return; |
3725 | | |
3726 | | /* Update the output ISA versions to the newest ones, but otherwise don't |
3727 | | provide any errors or warnings about mis-matched ISA versions as it's |
3728 | | generally too tricky to check for these at link time. */ |
3729 | 0 | if ((in->major_version > out->major_version) |
3730 | 0 | || (in->major_version == out->major_version |
3731 | 0 | && in->minor_version > out->minor_version) |
3732 | 0 | || (out->major_version == RISCV_UNKNOWN_VERSION)) |
3733 | 0 | { |
3734 | 0 | out->major_version = in->major_version; |
3735 | 0 | out->minor_version = in->minor_version; |
3736 | 0 | } |
3737 | 0 | } |
3738 | | |
3739 | | /* Return true if subset is 'i' or 'e'. */ |
3740 | | |
3741 | | static bool |
3742 | | riscv_i_or_e_p (bfd *ibfd, |
3743 | | const char *arch, |
3744 | | struct riscv_subset_t *subset) |
3745 | 0 | { |
3746 | 0 | if ((strcasecmp (subset->name, "e") != 0) |
3747 | 0 | && (strcasecmp (subset->name, "i") != 0)) |
3748 | 0 | { |
3749 | 0 | _bfd_error_handler |
3750 | 0 | (_("error: %pB: corrupted ISA string '%s'. " |
3751 | 0 | "First letter should be 'i' or 'e' but got '%s'"), |
3752 | 0 | ibfd, arch, subset->name); |
3753 | 0 | return false; |
3754 | 0 | } |
3755 | 0 | return true; |
3756 | 0 | } |
3757 | | |
3758 | | /* Merge standard extensions. |
3759 | | |
3760 | | Return Value: |
3761 | | Return FALSE if failed to merge. |
3762 | | |
3763 | | Arguments: |
3764 | | `bfd`: bfd handler. |
3765 | | `in_arch`: Raw ISA string for input object. |
3766 | | `out_arch`: Raw ISA string for output object. |
3767 | | `pin`: Subset list for input object. |
3768 | | `pout`: Subset list for output object. */ |
3769 | | |
3770 | | static bool |
3771 | | riscv_merge_std_ext (bfd *ibfd, |
3772 | | const char *in_arch, |
3773 | | const char *out_arch, |
3774 | | struct riscv_subset_t **pin, |
3775 | | struct riscv_subset_t **pout) |
3776 | 0 | { |
3777 | 0 | const char *standard_exts = "mafdqlcbjtpvnh"; |
3778 | 0 | const char *p; |
3779 | 0 | struct riscv_subset_t *in = *pin; |
3780 | 0 | struct riscv_subset_t *out = *pout; |
3781 | | |
3782 | | /* First letter should be 'i' or 'e'. */ |
3783 | 0 | if (!riscv_i_or_e_p (ibfd, in_arch, in)) |
3784 | 0 | return false; |
3785 | | |
3786 | 0 | if (!riscv_i_or_e_p (ibfd, out_arch, out)) |
3787 | 0 | return false; |
3788 | | |
3789 | 0 | if (strcasecmp (in->name, out->name) != 0) |
3790 | 0 | { |
3791 | | /* TODO: We might allow merge 'i' with 'e'. */ |
3792 | 0 | _bfd_error_handler |
3793 | 0 | (_("error: %pB: mis-matched ISA string to merge '%s' and '%s'"), |
3794 | 0 | ibfd, in->name, out->name); |
3795 | 0 | return false; |
3796 | 0 | } |
3797 | | |
3798 | 0 | riscv_update_subset_version(in, out); |
3799 | 0 | riscv_add_subset (&merged_subsets, |
3800 | 0 | out->name, out->major_version, out->minor_version); |
3801 | |
|
3802 | 0 | in = in->next; |
3803 | 0 | out = out->next; |
3804 | | |
3805 | | /* Handle standard extension first. */ |
3806 | 0 | for (p = standard_exts; *p; ++p) |
3807 | 0 | { |
3808 | 0 | struct riscv_subset_t *ext_in, *ext_out, *ext_merged; |
3809 | 0 | char find_ext[2] = {*p, '\0'}; |
3810 | 0 | bool find_in, find_out; |
3811 | |
|
3812 | 0 | find_in = riscv_lookup_subset (&in_subsets, find_ext, &ext_in); |
3813 | 0 | find_out = riscv_lookup_subset (&out_subsets, find_ext, &ext_out); |
3814 | |
|
3815 | 0 | if (!find_in && !find_out) |
3816 | 0 | continue; |
3817 | | |
3818 | 0 | if (find_in && find_out) |
3819 | 0 | riscv_update_subset_version(ext_in, ext_out); |
3820 | |
|
3821 | 0 | ext_merged = find_out ? ext_out : ext_in; |
3822 | 0 | riscv_add_subset (&merged_subsets, ext_merged->name, |
3823 | 0 | ext_merged->major_version, ext_merged->minor_version); |
3824 | 0 | } |
3825 | | |
3826 | | /* Skip all standard extensions. */ |
3827 | 0 | while ((in != NULL) && riscv_std_ext_p (in->name)) in = in->next; |
3828 | 0 | while ((out != NULL) && riscv_std_ext_p (out->name)) out = out->next; |
3829 | |
|
3830 | 0 | *pin = in; |
3831 | 0 | *pout = out; |
3832 | |
|
3833 | 0 | return true; |
3834 | 0 | } |
3835 | | |
3836 | | /* Merge multi letter extensions. PIN is a pointer to the head of the input |
3837 | | object subset list. Likewise for POUT and the output object. Return TRUE |
3838 | | on success and FALSE when a conflict is found. */ |
3839 | | |
3840 | | static bool |
3841 | | riscv_merge_multi_letter_ext (riscv_subset_t **pin, |
3842 | | riscv_subset_t **pout) |
3843 | 0 | { |
3844 | 0 | riscv_subset_t *in = *pin; |
3845 | 0 | riscv_subset_t *out = *pout; |
3846 | 0 | riscv_subset_t *tail; |
3847 | |
|
3848 | 0 | int cmp; |
3849 | |
|
3850 | 0 | while (in && out) |
3851 | 0 | { |
3852 | 0 | cmp = riscv_compare_subsets (in->name, out->name); |
3853 | |
|
3854 | 0 | if (cmp < 0) |
3855 | 0 | { |
3856 | | /* `in' comes before `out', append `in' and increment. */ |
3857 | 0 | riscv_add_subset (&merged_subsets, in->name, in->major_version, |
3858 | 0 | in->minor_version); |
3859 | 0 | in = in->next; |
3860 | 0 | } |
3861 | 0 | else if (cmp > 0) |
3862 | 0 | { |
3863 | | /* `out' comes before `in', append `out' and increment. */ |
3864 | 0 | riscv_add_subset (&merged_subsets, out->name, out->major_version, |
3865 | 0 | out->minor_version); |
3866 | 0 | out = out->next; |
3867 | 0 | } |
3868 | 0 | else |
3869 | 0 | { |
3870 | | /* Both present, check version and increment both. */ |
3871 | 0 | riscv_update_subset_version (in, out); |
3872 | |
|
3873 | 0 | riscv_add_subset (&merged_subsets, out->name, out->major_version, |
3874 | 0 | out->minor_version); |
3875 | 0 | out = out->next; |
3876 | 0 | in = in->next; |
3877 | 0 | } |
3878 | 0 | } |
3879 | |
|
3880 | 0 | if (in || out) |
3881 | 0 | { |
3882 | | /* If we're here, either `in' or `out' is running longer than |
3883 | | the other. So, we need to append the corresponding tail. */ |
3884 | 0 | tail = in ? in : out; |
3885 | 0 | while (tail) |
3886 | 0 | { |
3887 | 0 | riscv_add_subset (&merged_subsets, tail->name, tail->major_version, |
3888 | 0 | tail->minor_version); |
3889 | 0 | tail = tail->next; |
3890 | 0 | } |
3891 | 0 | } |
3892 | |
|
3893 | 0 | return true; |
3894 | 0 | } |
3895 | | |
3896 | | /* Merge Tag_RISCV_arch attribute. */ |
3897 | | |
3898 | | static char * |
3899 | | riscv_merge_arch_attr_info (bfd *ibfd, char *in_arch, char *out_arch, |
3900 | | unsigned int arch_size) |
3901 | 0 | { |
3902 | 0 | riscv_subset_t *in, *out; |
3903 | 0 | static char *merged_arch_str = NULL; |
3904 | 0 | char *result = NULL; |
3905 | |
|
3906 | 0 | unsigned xlen_in, xlen_out; |
3907 | |
|
3908 | 0 | riscv_parse_subset_t riscv_rps_ld_in = |
3909 | 0 | {&in_subsets, _bfd_error_handler, &xlen_in, NULL, false}; |
3910 | 0 | riscv_parse_subset_t riscv_rps_ld_out = |
3911 | 0 | {&out_subsets, _bfd_error_handler, &xlen_out, NULL, false}; |
3912 | |
|
3913 | 0 | if (in_arch == NULL && out_arch == NULL) |
3914 | 0 | return NULL; |
3915 | 0 | if (in_arch == NULL && out_arch != NULL) |
3916 | 0 | return out_arch; |
3917 | 0 | if (in_arch != NULL && out_arch == NULL) |
3918 | 0 | return in_arch; |
3919 | | |
3920 | | /* Parse subset from ISA string. */ |
3921 | 0 | if (!riscv_parse_subset (&riscv_rps_ld_in, in_arch)) |
3922 | 0 | goto cleanup; |
3923 | 0 | if (!riscv_parse_subset (&riscv_rps_ld_out, out_arch)) |
3924 | 0 | goto cleanup; |
3925 | | |
3926 | | /* Checking XLEN. */ |
3927 | 0 | if (xlen_out != xlen_in) |
3928 | 0 | { |
3929 | 0 | _bfd_error_handler |
3930 | 0 | (_("error: %pB: ISA string of input (%s) doesn't match " |
3931 | 0 | "output (%s)"), ibfd, in_arch, out_arch); |
3932 | 0 | goto cleanup; |
3933 | 0 | } |
3934 | | |
3935 | | /* Merge subset list. */ |
3936 | 0 | in = in_subsets.head; |
3937 | 0 | out = out_subsets.head; |
3938 | | |
3939 | | /* Merge standard extension. */ |
3940 | 0 | if (!riscv_merge_std_ext (ibfd, in_arch, out_arch, &in, &out)) |
3941 | 0 | goto cleanup; |
3942 | | |
3943 | | /* Merge all non-single letter extensions with single call. */ |
3944 | 0 | if (!riscv_merge_multi_letter_ext (&in, &out)) |
3945 | 0 | goto cleanup; |
3946 | | |
3947 | 0 | if (xlen_in != xlen_out) |
3948 | 0 | { |
3949 | 0 | _bfd_error_handler |
3950 | 0 | (_("error: %pB: XLEN of input (%u) doesn't match " |
3951 | 0 | "output (%u)"), ibfd, xlen_in, xlen_out); |
3952 | 0 | goto cleanup; |
3953 | 0 | } |
3954 | | |
3955 | 0 | if (xlen_in != arch_size) |
3956 | 0 | { |
3957 | 0 | _bfd_error_handler |
3958 | 0 | (_("error: %pB: unsupported XLEN (%u), you might be " |
3959 | 0 | "using wrong emulation"), ibfd, xlen_in); |
3960 | 0 | goto cleanup; |
3961 | 0 | } |
3962 | | |
3963 | | /* Add the implicit subsets implied by the merged subset list, then |
3964 | | check if the result is conflicting. */ |
3965 | 0 | riscv_parse_subset_t riscv_rps_ld_merged = |
3966 | 0 | {&merged_subsets, _bfd_error_handler, &xlen_in, NULL, false}; |
3967 | 0 | riscv_parse_add_implicit_subsets (&riscv_rps_ld_merged); |
3968 | 0 | if (!riscv_parse_check_conflicts (&riscv_rps_ld_merged)) |
3969 | 0 | goto cleanup; |
3970 | | |
3971 | | /* Free the previous merged_arch_str which called xmalloc. */ |
3972 | 0 | free (merged_arch_str); |
3973 | |
|
3974 | 0 | merged_arch_str = riscv_arch_str (arch_size, &merged_subsets, |
3975 | 0 | false/* update */); |
3976 | 0 | result = merged_arch_str; |
3977 | |
|
3978 | 0 | cleanup: |
3979 | | /* Release the subset lists. */ |
3980 | 0 | riscv_release_subset_list (&in_subsets); |
3981 | 0 | riscv_release_subset_list (&out_subsets); |
3982 | 0 | riscv_release_subset_list (&merged_subsets); |
3983 | |
|
3984 | 0 | return result; |
3985 | 0 | } |
3986 | | |
3987 | | /* Merge object attributes from IBFD into output_bfd of INFO. |
3988 | | Raise an error if there are conflicting attributes. */ |
3989 | | |
3990 | | static bool |
3991 | | riscv_merge_attributes (bfd *ibfd, struct bfd_link_info *info, |
3992 | | unsigned int arch_size) |
3993 | 0 | { |
3994 | 0 | bfd *obfd = info->output_bfd; |
3995 | 0 | obj_attribute *in_attr; |
3996 | 0 | obj_attribute *out_attr; |
3997 | 0 | bool result = true; |
3998 | 0 | const char *sec_name = get_elf_backend_data (ibfd)->obj_attrs_section; |
3999 | 0 | unsigned int i; |
4000 | | |
4001 | | /* Skip linker created files. */ |
4002 | 0 | if (ibfd->flags & BFD_LINKER_CREATED) |
4003 | 0 | return true; |
4004 | | |
4005 | | /* Skip any input that doesn't have an attribute section. |
4006 | | This enables to link object files without attribute section with |
4007 | | any others. */ |
4008 | 0 | if (bfd_get_section_by_name (ibfd, sec_name) == NULL) |
4009 | 0 | return true; |
4010 | | |
4011 | 0 | if (!elf_known_obj_attributes_proc (obfd)[0].i) |
4012 | 0 | { |
4013 | | /* This is the first object. Copy the attributes. */ |
4014 | 0 | _bfd_elf_copy_obj_attributes (ibfd, obfd); |
4015 | |
|
4016 | 0 | out_attr = elf_known_obj_attributes_proc (obfd); |
4017 | | |
4018 | | /* Use the Tag_null value to indicate the attributes have been |
4019 | | initialized. */ |
4020 | 0 | out_attr[0].i = 1; |
4021 | |
|
4022 | 0 | for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++) |
4023 | 0 | { |
4024 | 0 | switch (i) |
4025 | 0 | { |
4026 | | /* The privileged spec tags are deprecated, drop them. */ |
4027 | 0 | case Tag_RISCV_priv_spec: |
4028 | 0 | case Tag_RISCV_priv_spec_minor: |
4029 | 0 | case Tag_RISCV_priv_spec_revision: |
4030 | 0 | out_attr[i].i = 0; |
4031 | 0 | break; |
4032 | | |
4033 | 0 | case Tag_RISCV_unaligned_access: |
4034 | 0 | if (out_attr[i].i <= 1) |
4035 | 0 | break; |
4036 | | |
4037 | 0 | _bfd_error_handler |
4038 | 0 | (_("warning: %pB uses non-boolean `unaligned_access' attribute; " |
4039 | 0 | "converting to boolean"), |
4040 | 0 | ibfd); |
4041 | 0 | out_attr[i].i = 1; |
4042 | 0 | break; |
4043 | | |
4044 | 0 | case Tag_RISCV_stack_align: |
4045 | 0 | if (!(out_attr[i].i & (out_attr[i].i - 1))) |
4046 | 0 | break; |
4047 | | |
4048 | 0 | _bfd_error_handler |
4049 | 0 | (_("warning: %pB uses non-power-of-2 `stack_align' attribute; " |
4050 | 0 | "ignoring"), |
4051 | 0 | ibfd); |
4052 | 0 | out_attr[i].i = 0; |
4053 | 0 | break; |
4054 | 0 | } |
4055 | 0 | } |
4056 | | |
4057 | 0 | return true; |
4058 | 0 | } |
4059 | | |
4060 | 0 | in_attr = elf_known_obj_attributes_proc (ibfd); |
4061 | 0 | out_attr = elf_known_obj_attributes_proc (obfd); |
4062 | |
|
4063 | 0 | for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++) |
4064 | 0 | { |
4065 | 0 | switch (i) |
4066 | 0 | { |
4067 | 0 | case Tag_RISCV_arch: |
4068 | 0 | if (!out_attr[Tag_RISCV_arch].s) |
4069 | 0 | out_attr[Tag_RISCV_arch].s = in_attr[Tag_RISCV_arch].s; |
4070 | 0 | else if (in_attr[Tag_RISCV_arch].s |
4071 | 0 | && out_attr[Tag_RISCV_arch].s) |
4072 | 0 | { |
4073 | | /* Check compatible. */ |
4074 | 0 | char *merged_arch = |
4075 | 0 | riscv_merge_arch_attr_info (ibfd, |
4076 | 0 | in_attr[Tag_RISCV_arch].s, |
4077 | 0 | out_attr[Tag_RISCV_arch].s, |
4078 | 0 | arch_size); |
4079 | 0 | if (merged_arch == NULL) |
4080 | 0 | { |
4081 | 0 | result = false; |
4082 | 0 | out_attr[Tag_RISCV_arch].s = ""; |
4083 | 0 | } |
4084 | 0 | else |
4085 | 0 | out_attr[Tag_RISCV_arch].s = merged_arch; |
4086 | 0 | } |
4087 | 0 | break; |
4088 | | |
4089 | | /* The privileged spec tags are deprecated, ignore them. */ |
4090 | 0 | case Tag_RISCV_priv_spec: |
4091 | 0 | case Tag_RISCV_priv_spec_minor: |
4092 | 0 | case Tag_RISCV_priv_spec_revision: |
4093 | 0 | break; |
4094 | | |
4095 | 0 | case Tag_RISCV_unaligned_access: |
4096 | 0 | if (in_attr[i].i > 1) |
4097 | 0 | _bfd_error_handler |
4098 | 0 | (_("warning: %pB uses non-boolean `unaligned_access' attribute; " |
4099 | 0 | "converting to boolean"), |
4100 | 0 | ibfd); |
4101 | 0 | out_attr[i].i |= !!in_attr[i].i; |
4102 | 0 | break; |
4103 | | |
4104 | 0 | case Tag_RISCV_stack_align: |
4105 | 0 | if ((in_attr[i].i & (in_attr[i].i - 1)) != 0) |
4106 | 0 | _bfd_error_handler |
4107 | 0 | (_("warning: %pB uses non-power-of-2 `stack_align' attribute; " |
4108 | 0 | "ignoring"), |
4109 | 0 | ibfd); |
4110 | 0 | else if (out_attr[i].i == 0) |
4111 | 0 | out_attr[i].i = in_attr[i].i; |
4112 | 0 | else if (in_attr[i].i != 0 |
4113 | 0 | && out_attr[i].i != in_attr[i].i) |
4114 | 0 | { |
4115 | 0 | _bfd_error_handler |
4116 | 0 | (_("error: %pB use %u-byte stack aligned but the output " |
4117 | 0 | "use %u-byte stack aligned"), |
4118 | 0 | ibfd, in_attr[i].i, out_attr[i].i); |
4119 | 0 | result = false; |
4120 | 0 | } |
4121 | 0 | break; |
4122 | | |
4123 | 0 | default: |
4124 | 0 | result &= _bfd_elf_merge_unknown_attribute_low (ibfd, obfd, i); |
4125 | 0 | } |
4126 | | |
4127 | | /* If out_attr was copied from in_attr then it won't have a type yet. */ |
4128 | 0 | if (in_attr[i].type && !out_attr[i].type) |
4129 | 0 | out_attr[i].type = in_attr[i].type; |
4130 | 0 | } |
4131 | | |
4132 | | /* Merge Tag_compatibility attributes and any common GNU ones. */ |
4133 | 0 | if (!_bfd_elf_merge_object_attributes (ibfd, info)) |
4134 | 0 | return false; |
4135 | | |
4136 | | /* Check for any attributes not known on RISC-V. */ |
4137 | 0 | result &= _bfd_elf_merge_unknown_attribute_list (ibfd, obfd); |
4138 | |
|
4139 | 0 | return result; |
4140 | 0 | } |
4141 | | |
4142 | | /* Merge backend specific data from an object file to the output |
4143 | | object file when linking. */ |
4144 | | |
4145 | | bool |
4146 | | _bfd_riscv_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info, |
4147 | | unsigned int arch_size) |
4148 | 0 | { |
4149 | 0 | bfd *obfd = info->output_bfd; |
4150 | 0 | flagword new_flags, old_flags; |
4151 | |
|
4152 | 0 | if (!is_riscv_elf (ibfd)) |
4153 | 0 | return true; |
4154 | | |
4155 | 0 | if (strcmp (bfd_get_target (ibfd), bfd_get_target (obfd)) != 0) |
4156 | 0 | { |
4157 | 0 | (*_bfd_error_handler) |
4158 | 0 | (_("%pB: ABI is incompatible with that of the selected emulation:\n" |
4159 | 0 | " target emulation `%s' does not match `%s'"), |
4160 | 0 | ibfd, bfd_get_target (ibfd), bfd_get_target (obfd)); |
4161 | 0 | return false; |
4162 | 0 | } |
4163 | | |
4164 | 0 | if (!_bfd_elf_merge_object_attributes (ibfd, info)) |
4165 | 0 | return false; |
4166 | | |
4167 | 0 | if (!riscv_merge_attributes (ibfd, info, arch_size)) |
4168 | 0 | return false; |
4169 | | |
4170 | | /* Check to see if the input BFD actually contains any sections. If not, |
4171 | | its flags may not have been initialized either, but it cannot actually |
4172 | | cause any incompatibility. Do not short-circuit dynamic objects; their |
4173 | | section list may be emptied by elf_link_add_object_symbols. |
4174 | | |
4175 | | Also check to see if there are no code sections in the input. In this |
4176 | | case, there is no need to check for code specific flags. */ |
4177 | 0 | if (!(ibfd->flags & DYNAMIC)) |
4178 | 0 | { |
4179 | 0 | bool null_input_bfd = true; |
4180 | 0 | bool only_data_sections = true; |
4181 | 0 | asection *sec; |
4182 | |
|
4183 | 0 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
4184 | 0 | { |
4185 | 0 | null_input_bfd = false; |
4186 | |
|
4187 | 0 | if ((bfd_section_flags (sec) |
4188 | 0 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) |
4189 | 0 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) |
4190 | 0 | { |
4191 | 0 | only_data_sections = false; |
4192 | 0 | break; |
4193 | 0 | } |
4194 | 0 | } |
4195 | |
|
4196 | 0 | if (null_input_bfd || only_data_sections) |
4197 | 0 | return true; |
4198 | 0 | } |
4199 | | |
4200 | 0 | new_flags = elf_elfheader (ibfd)->e_flags; |
4201 | 0 | old_flags = elf_elfheader (obfd)->e_flags; |
4202 | |
|
4203 | 0 | if (!elf_flags_init (obfd)) |
4204 | 0 | { |
4205 | 0 | elf_flags_init (obfd) = true; |
4206 | 0 | elf_elfheader (obfd)->e_flags = new_flags; |
4207 | 0 | return true; |
4208 | 0 | } |
4209 | | |
4210 | | /* Disallow linking different float ABIs. */ |
4211 | 0 | if ((old_flags ^ new_flags) & EF_RISCV_FLOAT_ABI) |
4212 | 0 | { |
4213 | 0 | (*_bfd_error_handler) |
4214 | 0 | (_("%pB: can't link %s modules with %s modules"), ibfd, |
4215 | 0 | riscv_float_abi_string (new_flags), |
4216 | 0 | riscv_float_abi_string (old_flags)); |
4217 | 0 | goto fail; |
4218 | 0 | } |
4219 | | |
4220 | | /* Disallow linking RVE and non-RVE. */ |
4221 | 0 | if ((old_flags ^ new_flags) & EF_RISCV_RVE) |
4222 | 0 | { |
4223 | 0 | (*_bfd_error_handler) |
4224 | 0 | (_("%pB: can't link RVE with other target"), ibfd); |
4225 | 0 | goto fail; |
4226 | 0 | } |
4227 | | |
4228 | | /* Allow linking RVC and non-RVC, and keep the RVC flag. */ |
4229 | 0 | elf_elfheader (obfd)->e_flags |= new_flags & EF_RISCV_RVC; |
4230 | | |
4231 | | /* Allow linking TSO and non-TSO, and keep the TSO flag. */ |
4232 | 0 | elf_elfheader (obfd)->e_flags |= new_flags & EF_RISCV_TSO; |
4233 | |
|
4234 | 0 | return true; |
4235 | | |
4236 | 0 | fail: |
4237 | 0 | bfd_set_error (bfd_error_bad_value); |
4238 | 0 | return false; |
4239 | 0 | } |
4240 | | |
4241 | | /* Find the first input bfd with GNU property and merge it with GPROP. If no |
4242 | | such input is found, add it to a new section at the last input. Update |
4243 | | GPROP accordingly. */ |
4244 | | |
4245 | | bfd * |
4246 | | _bfd_riscv_elf_link_setup_gnu_properties (struct bfd_link_info *info, |
4247 | | uint32_t *and_prop_p) |
4248 | 0 | { |
4249 | 0 | asection *sec; |
4250 | 0 | bfd *pbfd; |
4251 | 0 | bfd *ebfd = NULL; |
4252 | 0 | elf_property *prop; |
4253 | |
|
4254 | 0 | uint32_t and_prop = *and_prop_p; |
4255 | | |
4256 | | /* Find a normal input file with GNU property note. */ |
4257 | 0 | for (pbfd = info->input_bfds; pbfd != NULL; pbfd = pbfd->link.next) |
4258 | 0 | if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour |
4259 | 0 | && bfd_count_sections (pbfd) != 0) |
4260 | 0 | { |
4261 | 0 | ebfd = pbfd; |
4262 | |
|
4263 | 0 | if (elf_properties (pbfd) != NULL) |
4264 | 0 | break; |
4265 | 0 | } |
4266 | | |
4267 | | /* If ebfd != NULL it is either an input with property note or the last |
4268 | | input. Either way if we have and_prop, we should add it (by |
4269 | | creating a section if needed). */ |
4270 | 0 | if (ebfd != NULL && (and_prop)) |
4271 | 0 | { |
4272 | 0 | prop = _bfd_elf_get_property (ebfd, GNU_PROPERTY_RISCV_FEATURE_1_AND, 4); |
4273 | |
|
4274 | 0 | prop->u.number |= and_prop; |
4275 | 0 | prop->pr_kind = property_number; |
4276 | | |
4277 | | /* pbfd being NULL implies ebfd is the last input. Create the GNU |
4278 | | property note section. */ |
4279 | 0 | if (pbfd == NULL) |
4280 | 0 | { |
4281 | 0 | sec |
4282 | 0 | = bfd_make_section_with_flags (ebfd, NOTE_GNU_PROPERTY_SECTION_NAME, |
4283 | 0 | (SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY |
4284 | 0 | | SEC_READONLY | SEC_HAS_CONTENTS |
4285 | 0 | | SEC_DATA)); |
4286 | 0 | if (sec == NULL) |
4287 | 0 | info->callbacks->fatal ( |
4288 | 0 | _("%P: failed to create GNU property section\n")); |
4289 | | |
4290 | 0 | elf_section_type (sec) = SHT_NOTE; |
4291 | 0 | } |
4292 | 0 | } |
4293 | | |
4294 | 0 | pbfd = _bfd_elf_link_setup_gnu_properties (info); |
4295 | |
|
4296 | 0 | if (bfd_link_relocatable (info)) |
4297 | 0 | return pbfd; |
4298 | | |
4299 | | /* If pbfd has any GNU_PROPERTY_RISCV_FEATURE_1_AND properties, update |
4300 | | and_prop accordingly. */ |
4301 | 0 | if (pbfd != NULL) |
4302 | 0 | { |
4303 | 0 | elf_property_list *p; |
4304 | 0 | elf_property_list *plist = elf_properties (pbfd); |
4305 | |
|
4306 | 0 | if ((p = _bfd_elf_find_property (plist, GNU_PROPERTY_RISCV_FEATURE_1_AND, |
4307 | 0 | NULL)) |
4308 | 0 | != NULL) |
4309 | 0 | and_prop = p->property.u.number |
4310 | 0 | & (GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED |
4311 | 0 | | GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS); |
4312 | 0 | } |
4313 | |
|
4314 | 0 | *and_prop_p = and_prop; |
4315 | 0 | return pbfd; |
4316 | 0 | } |
4317 | | |
4318 | | /* Define elf_backend_parse_gnu_properties for RISC-V. */ |
4319 | | |
4320 | | enum elf_property_kind |
4321 | | _bfd_riscv_elf_parse_gnu_properties (bfd *abfd, unsigned int type, |
4322 | | bfd_byte *ptr, unsigned int datasz) |
4323 | 12 | { |
4324 | 12 | elf_property *prop; |
4325 | | |
4326 | 12 | switch (type) |
4327 | 12 | { |
4328 | 1 | case GNU_PROPERTY_RISCV_FEATURE_1_AND: |
4329 | 1 | if (datasz != 4) |
4330 | 1 | { |
4331 | 1 | _bfd_error_handler (_ ( |
4332 | 1 | "error: %pB: <corrupt RISC-V used size: 0x%x>"), |
4333 | 1 | abfd, datasz); |
4334 | 1 | return property_corrupt; |
4335 | 1 | } |
4336 | 0 | prop = _bfd_elf_get_property (abfd, type, datasz); |
4337 | | /* Combine properties of the same type. */ |
4338 | 0 | prop->u.number |= bfd_h_get_32 (abfd, ptr); |
4339 | 0 | prop->pr_kind = property_number; |
4340 | 0 | break; |
4341 | | |
4342 | 11 | default: |
4343 | 11 | return property_ignored; |
4344 | 12 | } |
4345 | | |
4346 | 0 | return property_number; |
4347 | 12 | } |
4348 | | |
4349 | | /* Merge RISC-V GNU property BPROP with APROP also accounting for PROP. |
4350 | | If APROP isn't NULL, merge it with BPROP and/or PROP. Vice-versa if BROP |
4351 | | isn't NULL. Return TRUE if there is any update to APROP or if BPROP should |
4352 | | be merge with ABFD. */ |
4353 | | |
4354 | | bool |
4355 | | _bfd_riscv_elf_merge_gnu_properties |
4356 | | (struct bfd_link_info *info ATTRIBUTE_UNUSED, bfd *abfd ATTRIBUTE_UNUSED, |
4357 | | elf_property *aprop, elf_property *bprop, uint32_t and_prop) |
4358 | 0 | { |
4359 | 0 | unsigned int orig_number; |
4360 | 0 | bool updated = false; |
4361 | 0 | unsigned int pr_type = aprop != NULL ? aprop->pr_type : bprop->pr_type; |
4362 | |
|
4363 | 0 | switch (pr_type) |
4364 | 0 | { |
4365 | 0 | case GNU_PROPERTY_RISCV_FEATURE_1_AND: { |
4366 | 0 | if (aprop != NULL && bprop != NULL) |
4367 | 0 | { |
4368 | 0 | orig_number = aprop->u.number; |
4369 | 0 | aprop->u.number = (orig_number & bprop->u.number) | and_prop; |
4370 | 0 | updated = orig_number != aprop->u.number; |
4371 | | /* Remove the property if all feature bits are cleared. */ |
4372 | 0 | if (aprop->u.number == 0) |
4373 | 0 | aprop->pr_kind = property_remove; |
4374 | 0 | break; |
4375 | 0 | } |
4376 | | /* If either is NULL, the AND would be 0 so, if there is |
4377 | | any PROP, asign it to the input that is not NULL. */ |
4378 | 0 | if (and_prop) |
4379 | 0 | { |
4380 | 0 | if (aprop != NULL) |
4381 | 0 | { |
4382 | 0 | orig_number = aprop->u.number; |
4383 | 0 | aprop->u.number = and_prop; |
4384 | 0 | updated = orig_number != aprop->u.number; |
4385 | 0 | } |
4386 | 0 | else if (bprop != NULL) |
4387 | 0 | { |
4388 | 0 | bprop->u.number = and_prop; |
4389 | 0 | updated = true; |
4390 | 0 | } |
4391 | | /* Shouldn't happen because we checked one of APROP or BPROP != |
4392 | | * NULL. */ |
4393 | 0 | else |
4394 | 0 | abort (); |
4395 | 0 | } |
4396 | | /* No PROP and BPROP is NULL, so remove APROP. */ |
4397 | 0 | else if (!and_prop && bprop == NULL && aprop != NULL) |
4398 | 0 | { |
4399 | 0 | aprop->pr_kind = property_remove; |
4400 | 0 | updated = true; |
4401 | 0 | } |
4402 | 0 | } |
4403 | 0 | break; |
4404 | | |
4405 | 0 | default: |
4406 | 0 | abort (); |
4407 | 0 | } |
4408 | | |
4409 | 0 | return updated; |
4410 | 0 | } |