1 /* RISC-V-specific support for ELF.
2 Copyright (C) 2011-2022 Free Software Foundation, Inc.
4 Contributed by Andrew Waterman (andrew@sifive.com).
5 Based on TILE-Gx and MIPS targets.
7 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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/>. */
27 #include "elf/riscv.h"
28 #include "opcode/riscv.h"
29 #include "libiberty.h"
30 #include "elfxx-riscv.h"
31 #include "safe-ctype.h"
33 #define MINUS_ONE ((bfd_vma)0 - 1)
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 **);
42 /* The relocation table used for SHT_RELA sections. */
44 static reloc_howto_type howto_table
[] =
47 HOWTO (R_RISCV_NONE
, /* type */
51 false, /* pc_relative */
53 complain_overflow_dont
, /* complain_on_overflow */
54 bfd_elf_generic_reloc
, /* special_function */
55 "R_RISCV_NONE", /* name */
56 false, /* partial_inplace */
59 false), /* pcrel_offset */
61 /* 32 bit relocation. */
62 HOWTO (R_RISCV_32
, /* type */
66 false, /* pc_relative */
68 complain_overflow_dont
, /* complain_on_overflow */
69 bfd_elf_generic_reloc
, /* special_function */
70 "R_RISCV_32", /* name */
71 false, /* partial_inplace */
73 0xffffffff, /* dst_mask */
74 false), /* pcrel_offset */
76 /* 64 bit relocation. */
77 HOWTO (R_RISCV_64
, /* type */
81 false, /* pc_relative */
83 complain_overflow_dont
, /* complain_on_overflow */
84 bfd_elf_generic_reloc
, /* special_function */
85 "R_RISCV_64", /* name */
86 false, /* partial_inplace */
88 MINUS_ONE
, /* dst_mask */
89 false), /* pcrel_offset */
91 /* Relocation against a local symbol in a shared object. */
92 HOWTO (R_RISCV_RELATIVE
, /* type */
96 false, /* pc_relative */
98 complain_overflow_dont
, /* complain_on_overflow */
99 bfd_elf_generic_reloc
, /* special_function */
100 "R_RISCV_RELATIVE", /* name */
101 false, /* partial_inplace */
103 0xffffffff, /* dst_mask */
104 false), /* pcrel_offset */
106 HOWTO (R_RISCV_COPY
, /* type */
108 0, /* this one is variable size */
110 false, /* pc_relative */
112 complain_overflow_bitfield
, /* complain_on_overflow */
113 bfd_elf_generic_reloc
, /* special_function */
114 "R_RISCV_COPY", /* name */
115 false, /* partial_inplace */
118 false), /* pcrel_offset */
120 HOWTO (R_RISCV_JUMP_SLOT
, /* type */
124 false, /* pc_relative */
126 complain_overflow_bitfield
, /* complain_on_overflow */
127 bfd_elf_generic_reloc
, /* special_function */
128 "R_RISCV_JUMP_SLOT", /* name */
129 false, /* partial_inplace */
132 false), /* pcrel_offset */
134 /* Dynamic TLS relocations. */
135 HOWTO (R_RISCV_TLS_DTPMOD32
, /* type */
139 false, /* pc_relative */
141 complain_overflow_dont
, /* complain_on_overflow */
142 bfd_elf_generic_reloc
, /* special_function */
143 "R_RISCV_TLS_DTPMOD32", /* name */
144 false, /* partial_inplace */
146 0xffffffff, /* dst_mask */
147 false), /* pcrel_offset */
149 HOWTO (R_RISCV_TLS_DTPMOD64
, /* type */
153 false, /* pc_relative */
155 complain_overflow_dont
, /* complain_on_overflow */
156 bfd_elf_generic_reloc
, /* special_function */
157 "R_RISCV_TLS_DTPMOD64", /* name */
158 false, /* partial_inplace */
160 MINUS_ONE
, /* dst_mask */
161 false), /* pcrel_offset */
163 HOWTO (R_RISCV_TLS_DTPREL32
, /* type */
167 false, /* pc_relative */
169 complain_overflow_dont
, /* complain_on_overflow */
170 bfd_elf_generic_reloc
, /* special_function */
171 "R_RISCV_TLS_DTPREL32", /* name */
172 true, /* partial_inplace */
174 0xffffffff, /* dst_mask */
175 false), /* pcrel_offset */
177 HOWTO (R_RISCV_TLS_DTPREL64
, /* type */
181 false, /* pc_relative */
183 complain_overflow_dont
, /* complain_on_overflow */
184 bfd_elf_generic_reloc
, /* special_function */
185 "R_RISCV_TLS_DTPREL64", /* name */
186 true, /* partial_inplace */
188 MINUS_ONE
, /* dst_mask */
189 false), /* pcrel_offset */
191 HOWTO (R_RISCV_TLS_TPREL32
, /* type */
195 false, /* pc_relative */
197 complain_overflow_dont
, /* complain_on_overflow */
198 bfd_elf_generic_reloc
, /* special_function */
199 "R_RISCV_TLS_TPREL32", /* name */
200 false, /* partial_inplace */
202 0xffffffff, /* dst_mask */
203 false), /* pcrel_offset */
205 HOWTO (R_RISCV_TLS_TPREL64
, /* type */
209 false, /* pc_relative */
211 complain_overflow_dont
, /* complain_on_overflow */
212 bfd_elf_generic_reloc
, /* special_function */
213 "R_RISCV_TLS_TPREL64", /* name */
214 false, /* partial_inplace */
216 MINUS_ONE
, /* dst_mask */
217 false), /* pcrel_offset */
219 /* Reserved for future relocs that the dynamic linker must understand. */
225 /* 12-bit PC-relative branch offset. */
226 HOWTO (R_RISCV_BRANCH
, /* type */
230 true, /* pc_relative */
232 complain_overflow_signed
, /* complain_on_overflow */
233 bfd_elf_generic_reloc
, /* special_function */
234 "R_RISCV_BRANCH", /* name */
235 false, /* partial_inplace */
237 ENCODE_BTYPE_IMM (-1U), /* dst_mask */
238 true), /* pcrel_offset */
240 /* 20-bit PC-relative jump offset. */
241 HOWTO (R_RISCV_JAL
, /* type */
245 true, /* pc_relative */
247 complain_overflow_dont
, /* complain_on_overflow */
248 bfd_elf_generic_reloc
, /* special_function */
249 "R_RISCV_JAL", /* name */
250 false, /* partial_inplace */
252 ENCODE_JTYPE_IMM (-1U), /* dst_mask */
253 true), /* pcrel_offset */
255 /* 32-bit PC-relative function call (AUIPC/JALR). */
256 HOWTO (R_RISCV_CALL
, /* type */
260 true, /* pc_relative */
262 complain_overflow_dont
, /* complain_on_overflow */
263 bfd_elf_generic_reloc
, /* special_function */
264 "R_RISCV_CALL", /* name */
265 false, /* partial_inplace */
267 ENCODE_UTYPE_IMM (-1U) | ((bfd_vma
) ENCODE_ITYPE_IMM (-1U) << 32),
269 true), /* pcrel_offset */
271 /* Like R_RISCV_CALL, but not locally binding. */
272 HOWTO (R_RISCV_CALL_PLT
, /* type */
276 true, /* pc_relative */
278 complain_overflow_dont
, /* complain_on_overflow */
279 bfd_elf_generic_reloc
, /* special_function */
280 "R_RISCV_CALL_PLT", /* name */
281 false, /* partial_inplace */
283 ENCODE_UTYPE_IMM (-1U) | ((bfd_vma
) ENCODE_ITYPE_IMM (-1U) << 32),
285 true), /* pcrel_offset */
287 /* High 20 bits of 32-bit PC-relative GOT access. */
288 HOWTO (R_RISCV_GOT_HI20
, /* type */
292 true, /* pc_relative */
294 complain_overflow_dont
, /* complain_on_overflow */
295 bfd_elf_generic_reloc
, /* special_function */
296 "R_RISCV_GOT_HI20", /* name */
297 false, /* partial_inplace */
299 ENCODE_UTYPE_IMM (-1U), /* dst_mask */
300 false), /* pcrel_offset */
302 /* High 20 bits of 32-bit PC-relative TLS IE GOT access. */
303 HOWTO (R_RISCV_TLS_GOT_HI20
, /* type */
307 true, /* pc_relative */
309 complain_overflow_dont
, /* complain_on_overflow */
310 bfd_elf_generic_reloc
, /* special_function */
311 "R_RISCV_TLS_GOT_HI20", /* name */
312 false, /* partial_inplace */
314 ENCODE_UTYPE_IMM (-1U), /* dst_mask */
315 false), /* pcrel_offset */
317 /* High 20 bits of 32-bit PC-relative TLS GD GOT reference. */
318 HOWTO (R_RISCV_TLS_GD_HI20
, /* type */
322 true, /* pc_relative */
324 complain_overflow_dont
, /* complain_on_overflow */
325 bfd_elf_generic_reloc
, /* special_function */
326 "R_RISCV_TLS_GD_HI20", /* name */
327 false, /* partial_inplace */
329 ENCODE_UTYPE_IMM (-1U), /* dst_mask */
330 false), /* pcrel_offset */
332 /* High 20 bits of 32-bit PC-relative reference. */
333 HOWTO (R_RISCV_PCREL_HI20
, /* type */
337 true, /* pc_relative */
339 complain_overflow_dont
, /* complain_on_overflow */
340 bfd_elf_generic_reloc
, /* special_function */
341 "R_RISCV_PCREL_HI20", /* name */
342 false, /* partial_inplace */
344 ENCODE_UTYPE_IMM (-1U), /* dst_mask */
345 true), /* pcrel_offset */
347 /* Low 12 bits of a 32-bit PC-relative load or add. */
348 HOWTO (R_RISCV_PCREL_LO12_I
, /* type */
352 false, /* pc_relative */
354 complain_overflow_dont
, /* complain_on_overflow */
355 bfd_elf_generic_reloc
, /* special_function */
356 "R_RISCV_PCREL_LO12_I", /* name */
357 false, /* partial_inplace */
359 ENCODE_ITYPE_IMM (-1U), /* dst_mask */
360 false), /* pcrel_offset */
362 /* Low 12 bits of a 32-bit PC-relative store. */
363 HOWTO (R_RISCV_PCREL_LO12_S
, /* type */
367 false, /* pc_relative */
369 complain_overflow_dont
, /* complain_on_overflow */
370 bfd_elf_generic_reloc
, /* special_function */
371 "R_RISCV_PCREL_LO12_S", /* name */
372 false, /* partial_inplace */
374 ENCODE_STYPE_IMM (-1U), /* dst_mask */
375 false), /* pcrel_offset */
377 /* High 20 bits of 32-bit absolute address. */
378 HOWTO (R_RISCV_HI20
, /* type */
382 false, /* pc_relative */
384 complain_overflow_dont
, /* complain_on_overflow */
385 bfd_elf_generic_reloc
, /* special_function */
386 "R_RISCV_HI20", /* name */
387 false, /* partial_inplace */
389 ENCODE_UTYPE_IMM (-1U), /* dst_mask */
390 false), /* pcrel_offset */
392 /* High 12 bits of 32-bit load or add. */
393 HOWTO (R_RISCV_LO12_I
, /* type */
397 false, /* pc_relative */
399 complain_overflow_dont
, /* complain_on_overflow */
400 bfd_elf_generic_reloc
, /* special_function */
401 "R_RISCV_LO12_I", /* name */
402 false, /* partial_inplace */
404 ENCODE_ITYPE_IMM (-1U), /* dst_mask */
405 false), /* pcrel_offset */
407 /* High 12 bits of 32-bit store. */
408 HOWTO (R_RISCV_LO12_S
, /* type */
412 false, /* pc_relative */
414 complain_overflow_dont
, /* complain_on_overflow */
415 bfd_elf_generic_reloc
, /* special_function */
416 "R_RISCV_LO12_S", /* name */
417 false, /* partial_inplace */
419 ENCODE_STYPE_IMM (-1U), /* dst_mask */
420 false), /* pcrel_offset */
422 /* High 20 bits of TLS LE thread pointer offset. */
423 HOWTO (R_RISCV_TPREL_HI20
, /* type */
427 false, /* pc_relative */
429 complain_overflow_signed
, /* complain_on_overflow */
430 bfd_elf_generic_reloc
, /* special_function */
431 "R_RISCV_TPREL_HI20", /* name */
432 true, /* partial_inplace */
434 ENCODE_UTYPE_IMM (-1U), /* dst_mask */
435 false), /* pcrel_offset */
437 /* Low 12 bits of TLS LE thread pointer offset for loads and adds. */
438 HOWTO (R_RISCV_TPREL_LO12_I
, /* type */
442 false, /* pc_relative */
444 complain_overflow_signed
, /* complain_on_overflow */
445 bfd_elf_generic_reloc
, /* special_function */
446 "R_RISCV_TPREL_LO12_I", /* name */
447 false, /* partial_inplace */
449 ENCODE_ITYPE_IMM (-1U), /* dst_mask */
450 false), /* pcrel_offset */
452 /* Low 12 bits of TLS LE thread pointer offset for stores. */
453 HOWTO (R_RISCV_TPREL_LO12_S
, /* type */
457 false, /* pc_relative */
459 complain_overflow_signed
, /* complain_on_overflow */
460 bfd_elf_generic_reloc
, /* special_function */
461 "R_RISCV_TPREL_LO12_S", /* name */
462 false, /* partial_inplace */
464 ENCODE_STYPE_IMM (-1U), /* dst_mask */
465 false), /* pcrel_offset */
467 /* TLS LE thread pointer usage. May be relaxed. */
468 HOWTO (R_RISCV_TPREL_ADD
, /* type */
472 false, /* pc_relative */
474 complain_overflow_dont
, /* complain_on_overflow */
475 bfd_elf_generic_reloc
, /* special_function */
476 "R_RISCV_TPREL_ADD", /* name */
477 false, /* partial_inplace */
480 false), /* pcrel_offset */
482 /* 8-bit in-place addition, for local label subtraction. */
483 HOWTO (R_RISCV_ADD8
, /* type */
487 false, /* pc_relative */
489 complain_overflow_dont
, /* complain_on_overflow */
490 riscv_elf_add_sub_reloc
, /* special_function */
491 "R_RISCV_ADD8", /* name */
492 false, /* partial_inplace */
495 false), /* pcrel_offset */
497 /* 16-bit in-place addition, for local label subtraction. */
498 HOWTO (R_RISCV_ADD16
, /* type */
502 false, /* pc_relative */
504 complain_overflow_dont
, /* complain_on_overflow */
505 riscv_elf_add_sub_reloc
, /* special_function */
506 "R_RISCV_ADD16", /* name */
507 false, /* partial_inplace */
509 0xffff, /* dst_mask */
510 false), /* pcrel_offset */
512 /* 32-bit in-place addition, for local label subtraction. */
513 HOWTO (R_RISCV_ADD32
, /* type */
517 false, /* pc_relative */
519 complain_overflow_dont
, /* complain_on_overflow */
520 riscv_elf_add_sub_reloc
, /* special_function */
521 "R_RISCV_ADD32", /* name */
522 false, /* partial_inplace */
524 0xffffffff, /* dst_mask */
525 false), /* pcrel_offset */
527 /* 64-bit in-place addition, for local label subtraction. */
528 HOWTO (R_RISCV_ADD64
, /* type */
532 false, /* pc_relative */
534 complain_overflow_dont
, /* complain_on_overflow */
535 riscv_elf_add_sub_reloc
, /* special_function */
536 "R_RISCV_ADD64", /* name */
537 false, /* partial_inplace */
539 MINUS_ONE
, /* dst_mask */
540 false), /* pcrel_offset */
542 /* 8-bit in-place addition, for local label subtraction. */
543 HOWTO (R_RISCV_SUB8
, /* type */
547 false, /* pc_relative */
549 complain_overflow_dont
, /* complain_on_overflow */
550 riscv_elf_add_sub_reloc
, /* special_function */
551 "R_RISCV_SUB8", /* name */
552 false, /* partial_inplace */
555 false), /* pcrel_offset */
557 /* 16-bit in-place addition, for local label subtraction. */
558 HOWTO (R_RISCV_SUB16
, /* type */
562 false, /* pc_relative */
564 complain_overflow_dont
, /* complain_on_overflow */
565 riscv_elf_add_sub_reloc
, /* special_function */
566 "R_RISCV_SUB16", /* name */
567 false, /* partial_inplace */
569 0xffff, /* dst_mask */
570 false), /* pcrel_offset */
572 /* 32-bit in-place addition, for local label subtraction. */
573 HOWTO (R_RISCV_SUB32
, /* type */
577 false, /* pc_relative */
579 complain_overflow_dont
, /* complain_on_overflow */
580 riscv_elf_add_sub_reloc
, /* special_function */
581 "R_RISCV_SUB32", /* name */
582 false, /* partial_inplace */
584 0xffffffff, /* dst_mask */
585 false), /* pcrel_offset */
587 /* 64-bit in-place addition, for local label subtraction. */
588 HOWTO (R_RISCV_SUB64
, /* type */
592 false, /* pc_relative */
594 complain_overflow_dont
, /* complain_on_overflow */
595 riscv_elf_add_sub_reloc
, /* special_function */
596 "R_RISCV_SUB64", /* name */
597 false, /* partial_inplace */
599 MINUS_ONE
, /* dst_mask */
600 false), /* pcrel_offset */
602 /* 41 and 42 are reserved. */
606 /* Indicates an alignment statement. The addend field encodes how many
607 bytes of NOPs follow the statement. The desired alignment is the
608 addend rounded up to the next power of two. */
609 HOWTO (R_RISCV_ALIGN
, /* type */
613 false, /* pc_relative */
615 complain_overflow_dont
, /* complain_on_overflow */
616 bfd_elf_generic_reloc
, /* special_function */
617 "R_RISCV_ALIGN", /* name */
618 false, /* partial_inplace */
621 false), /* pcrel_offset */
623 /* 8-bit PC-relative branch offset. */
624 HOWTO (R_RISCV_RVC_BRANCH
, /* type */
628 true, /* pc_relative */
630 complain_overflow_signed
, /* complain_on_overflow */
631 bfd_elf_generic_reloc
, /* special_function */
632 "R_RISCV_RVC_BRANCH", /* name */
633 false, /* partial_inplace */
635 ENCODE_CBTYPE_IMM (-1U), /* dst_mask */
636 true), /* pcrel_offset */
638 /* 11-bit PC-relative jump offset. */
639 HOWTO (R_RISCV_RVC_JUMP
, /* type */
643 true, /* pc_relative */
645 complain_overflow_dont
, /* complain_on_overflow */
646 bfd_elf_generic_reloc
, /* special_function */
647 "R_RISCV_RVC_JUMP", /* name */
648 false, /* partial_inplace */
650 ENCODE_CJTYPE_IMM (-1U), /* dst_mask */
651 true), /* pcrel_offset */
653 /* High 6 bits of 18-bit absolute address. */
654 HOWTO (R_RISCV_RVC_LUI
, /* type */
658 false, /* pc_relative */
660 complain_overflow_dont
, /* complain_on_overflow */
661 bfd_elf_generic_reloc
, /* special_function */
662 "R_RISCV_RVC_LUI", /* name */
663 false, /* partial_inplace */
665 ENCODE_CITYPE_IMM (-1U), /* dst_mask */
666 false), /* pcrel_offset */
668 /* GP-relative load. */
669 HOWTO (R_RISCV_GPREL_I
, /* type */
673 false, /* pc_relative */
675 complain_overflow_dont
, /* complain_on_overflow */
676 bfd_elf_generic_reloc
, /* special_function */
677 "R_RISCV_GPREL_I", /* name */
678 false, /* partial_inplace */
680 ENCODE_ITYPE_IMM (-1U), /* dst_mask */
681 false), /* pcrel_offset */
683 /* GP-relative store. */
684 HOWTO (R_RISCV_GPREL_S
, /* type */
688 false, /* pc_relative */
690 complain_overflow_dont
, /* complain_on_overflow */
691 bfd_elf_generic_reloc
, /* special_function */
692 "R_RISCV_GPREL_S", /* name */
693 false, /* partial_inplace */
695 ENCODE_STYPE_IMM (-1U), /* dst_mask */
696 false), /* pcrel_offset */
698 /* TP-relative TLS LE load. */
699 HOWTO (R_RISCV_TPREL_I
, /* type */
703 false, /* pc_relative */
705 complain_overflow_signed
, /* complain_on_overflow */
706 bfd_elf_generic_reloc
, /* special_function */
707 "R_RISCV_TPREL_I", /* name */
708 false, /* partial_inplace */
710 ENCODE_ITYPE_IMM (-1U), /* dst_mask */
711 false), /* pcrel_offset */
713 /* TP-relative TLS LE store. */
714 HOWTO (R_RISCV_TPREL_S
, /* type */
718 false, /* pc_relative */
720 complain_overflow_signed
, /* complain_on_overflow */
721 bfd_elf_generic_reloc
, /* special_function */
722 "R_RISCV_TPREL_S", /* name */
723 false, /* partial_inplace */
725 ENCODE_STYPE_IMM (-1U), /* dst_mask */
726 false), /* pcrel_offset */
728 /* The paired relocation may be relaxed. */
729 HOWTO (R_RISCV_RELAX
, /* type */
733 false, /* pc_relative */
735 complain_overflow_dont
, /* complain_on_overflow */
736 bfd_elf_generic_reloc
, /* special_function */
737 "R_RISCV_RELAX", /* name */
738 false, /* partial_inplace */
741 false), /* pcrel_offset */
743 /* 6-bit in-place addition, for local label subtraction. */
744 HOWTO (R_RISCV_SUB6
, /* type */
748 false, /* pc_relative */
750 complain_overflow_dont
, /* complain_on_overflow */
751 riscv_elf_add_sub_reloc
, /* special_function */
752 "R_RISCV_SUB6", /* name */
753 false, /* partial_inplace */
756 false), /* pcrel_offset */
758 /* 6-bit in-place setting, for local label subtraction. */
759 HOWTO (R_RISCV_SET6
, /* type */
763 false, /* pc_relative */
765 complain_overflow_dont
, /* complain_on_overflow */
766 bfd_elf_generic_reloc
, /* special_function */
767 "R_RISCV_SET6", /* name */
768 false, /* partial_inplace */
771 false), /* pcrel_offset */
773 /* 8-bit in-place setting, for local label subtraction. */
774 HOWTO (R_RISCV_SET8
, /* type */
778 false, /* pc_relative */
780 complain_overflow_dont
, /* complain_on_overflow */
781 bfd_elf_generic_reloc
, /* special_function */
782 "R_RISCV_SET8", /* name */
783 false, /* partial_inplace */
786 false), /* pcrel_offset */
788 /* 16-bit in-place setting, for local label subtraction. */
789 HOWTO (R_RISCV_SET16
, /* type */
793 false, /* pc_relative */
795 complain_overflow_dont
, /* complain_on_overflow */
796 bfd_elf_generic_reloc
, /* special_function */
797 "R_RISCV_SET16", /* name */
798 false, /* partial_inplace */
800 0xffff, /* dst_mask */
801 false), /* pcrel_offset */
803 /* 32-bit in-place setting, for local label subtraction. */
804 HOWTO (R_RISCV_SET32
, /* type */
808 false, /* pc_relative */
810 complain_overflow_dont
, /* complain_on_overflow */
811 bfd_elf_generic_reloc
, /* special_function */
812 "R_RISCV_SET32", /* name */
813 false, /* partial_inplace */
815 0xffffffff, /* dst_mask */
816 false), /* pcrel_offset */
818 /* 32-bit PC relative. */
819 HOWTO (R_RISCV_32_PCREL
, /* type */
823 true, /* pc_relative */
825 complain_overflow_dont
, /* complain_on_overflow */
826 bfd_elf_generic_reloc
, /* special_function */
827 "R_RISCV_32_PCREL", /* name */
828 false, /* partial_inplace */
830 0xffffffff, /* dst_mask */
831 false), /* pcrel_offset */
833 /* Relocation against a local ifunc symbol in a shared object. */
834 HOWTO (R_RISCV_IRELATIVE
, /* type */
838 false, /* pc_relative */
840 complain_overflow_dont
, /* complain_on_overflow */
841 bfd_elf_generic_reloc
, /* special_function */
842 "R_RISCV_IRELATIVE", /* name */
843 false, /* partial_inplace */
845 0xffffffff, /* dst_mask */
846 false), /* pcrel_offset */
849 /* A mapping from BFD reloc types to RISC-V ELF reloc types. */
852 bfd_reloc_code_real_type bfd_val
;
853 enum elf_riscv_reloc_type elf_val
;
856 static const struct elf_reloc_map riscv_reloc_map
[] =
858 { BFD_RELOC_NONE
, R_RISCV_NONE
},
859 { BFD_RELOC_32
, R_RISCV_32
},
860 { BFD_RELOC_64
, R_RISCV_64
},
861 { BFD_RELOC_RISCV_ADD8
, R_RISCV_ADD8
},
862 { BFD_RELOC_RISCV_ADD16
, R_RISCV_ADD16
},
863 { BFD_RELOC_RISCV_ADD32
, R_RISCV_ADD32
},
864 { BFD_RELOC_RISCV_ADD64
, R_RISCV_ADD64
},
865 { BFD_RELOC_RISCV_SUB8
, R_RISCV_SUB8
},
866 { BFD_RELOC_RISCV_SUB16
, R_RISCV_SUB16
},
867 { BFD_RELOC_RISCV_SUB32
, R_RISCV_SUB32
},
868 { BFD_RELOC_RISCV_SUB64
, R_RISCV_SUB64
},
869 { BFD_RELOC_CTOR
, R_RISCV_64
},
870 { BFD_RELOC_12_PCREL
, R_RISCV_BRANCH
},
871 { BFD_RELOC_RISCV_HI20
, R_RISCV_HI20
},
872 { BFD_RELOC_RISCV_LO12_I
, R_RISCV_LO12_I
},
873 { BFD_RELOC_RISCV_LO12_S
, R_RISCV_LO12_S
},
874 { BFD_RELOC_RISCV_PCREL_LO12_I
, R_RISCV_PCREL_LO12_I
},
875 { BFD_RELOC_RISCV_PCREL_LO12_S
, R_RISCV_PCREL_LO12_S
},
876 { BFD_RELOC_RISCV_CALL
, R_RISCV_CALL
},
877 { BFD_RELOC_RISCV_CALL_PLT
, R_RISCV_CALL_PLT
},
878 { BFD_RELOC_RISCV_PCREL_HI20
, R_RISCV_PCREL_HI20
},
879 { BFD_RELOC_RISCV_JMP
, R_RISCV_JAL
},
880 { BFD_RELOC_RISCV_GOT_HI20
, R_RISCV_GOT_HI20
},
881 { BFD_RELOC_RISCV_TLS_DTPMOD32
, R_RISCV_TLS_DTPMOD32
},
882 { BFD_RELOC_RISCV_TLS_DTPREL32
, R_RISCV_TLS_DTPREL32
},
883 { BFD_RELOC_RISCV_TLS_DTPMOD64
, R_RISCV_TLS_DTPMOD64
},
884 { BFD_RELOC_RISCV_TLS_DTPREL64
, R_RISCV_TLS_DTPREL64
},
885 { BFD_RELOC_RISCV_TLS_TPREL32
, R_RISCV_TLS_TPREL32
},
886 { BFD_RELOC_RISCV_TLS_TPREL64
, R_RISCV_TLS_TPREL64
},
887 { BFD_RELOC_RISCV_TPREL_HI20
, R_RISCV_TPREL_HI20
},
888 { BFD_RELOC_RISCV_TPREL_ADD
, R_RISCV_TPREL_ADD
},
889 { BFD_RELOC_RISCV_TPREL_LO12_S
, R_RISCV_TPREL_LO12_S
},
890 { BFD_RELOC_RISCV_TPREL_LO12_I
, R_RISCV_TPREL_LO12_I
},
891 { BFD_RELOC_RISCV_TLS_GOT_HI20
, R_RISCV_TLS_GOT_HI20
},
892 { BFD_RELOC_RISCV_TLS_GD_HI20
, R_RISCV_TLS_GD_HI20
},
893 { BFD_RELOC_RISCV_ALIGN
, R_RISCV_ALIGN
},
894 { BFD_RELOC_RISCV_RVC_BRANCH
, R_RISCV_RVC_BRANCH
},
895 { BFD_RELOC_RISCV_RVC_JUMP
, R_RISCV_RVC_JUMP
},
896 { BFD_RELOC_RISCV_RVC_LUI
, R_RISCV_RVC_LUI
},
897 { BFD_RELOC_RISCV_GPREL_I
, R_RISCV_GPREL_I
},
898 { BFD_RELOC_RISCV_GPREL_S
, R_RISCV_GPREL_S
},
899 { BFD_RELOC_RISCV_TPREL_I
, R_RISCV_TPREL_I
},
900 { BFD_RELOC_RISCV_TPREL_S
, R_RISCV_TPREL_S
},
901 { BFD_RELOC_RISCV_RELAX
, R_RISCV_RELAX
},
902 { BFD_RELOC_RISCV_SUB6
, R_RISCV_SUB6
},
903 { BFD_RELOC_RISCV_SET6
, R_RISCV_SET6
},
904 { BFD_RELOC_RISCV_SET8
, R_RISCV_SET8
},
905 { BFD_RELOC_RISCV_SET16
, R_RISCV_SET16
},
906 { BFD_RELOC_RISCV_SET32
, R_RISCV_SET32
},
907 { BFD_RELOC_RISCV_32_PCREL
, R_RISCV_32_PCREL
},
910 /* Given a BFD reloc type, return a howto structure. */
913 riscv_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
914 bfd_reloc_code_real_type code
)
918 for (i
= 0; i
< ARRAY_SIZE (riscv_reloc_map
); i
++)
919 if (riscv_reloc_map
[i
].bfd_val
== code
)
920 return &howto_table
[(int) riscv_reloc_map
[i
].elf_val
];
922 bfd_set_error (bfd_error_bad_value
);
927 riscv_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, const char *r_name
)
931 for (i
= 0; i
< ARRAY_SIZE (howto_table
); i
++)
932 if (howto_table
[i
].name
&& strcasecmp (howto_table
[i
].name
, r_name
) == 0)
933 return &howto_table
[i
];
939 riscv_elf_rtype_to_howto (bfd
*abfd
, unsigned int r_type
)
941 if (r_type
>= ARRAY_SIZE (howto_table
))
943 (*_bfd_error_handler
) (_("%pB: unsupported relocation type %#x"),
945 bfd_set_error (bfd_error_bad_value
);
948 return &howto_table
[r_type
];
951 /* Special_function of RISCV_ADD and RISCV_SUB relocations. */
953 static bfd_reloc_status_type
954 riscv_elf_add_sub_reloc (bfd
*abfd
,
955 arelent
*reloc_entry
,
958 asection
*input_section
,
960 char **error_message ATTRIBUTE_UNUSED
)
962 reloc_howto_type
*howto
= reloc_entry
->howto
;
965 if (output_bfd
!= NULL
966 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
967 && (!reloc_entry
->howto
->partial_inplace
|| reloc_entry
->addend
== 0))
969 reloc_entry
->address
+= input_section
->output_offset
;
973 if (output_bfd
!= NULL
)
974 return bfd_reloc_continue
;
976 relocation
= symbol
->value
+ symbol
->section
->output_section
->vma
977 + symbol
->section
->output_offset
+ reloc_entry
->addend
;
979 bfd_size_type octets
= reloc_entry
->address
980 * bfd_octets_per_byte (abfd
, input_section
);
981 if (!bfd_reloc_offset_in_range (reloc_entry
->howto
, abfd
,
982 input_section
, octets
))
983 return bfd_reloc_outofrange
;
985 bfd_vma old_value
= bfd_get (howto
->bitsize
, abfd
,
986 data
+ reloc_entry
->address
);
994 relocation
= old_value
+ relocation
;
1001 relocation
= old_value
- relocation
;
1004 bfd_put (howto
->bitsize
, abfd
, relocation
, data
+ reloc_entry
->address
);
1006 return bfd_reloc_ok
;
1009 /* Always add the IMPLICIT for the SUBSET. */
1012 check_implicit_always (const char *implicit ATTRIBUTE_UNUSED
,
1013 riscv_subset_t
*subset ATTRIBUTE_UNUSED
)
1018 /* Add the IMPLICIT only when the version of SUBSET less than 2.1. */
1021 check_implicit_for_i (const char *implicit ATTRIBUTE_UNUSED
,
1022 riscv_subset_t
*subset
)
1024 return (subset
->major_version
< 2
1025 || (subset
->major_version
== 2
1026 && subset
->minor_version
< 1));
1029 /* Record all implicit information for the subsets. */
1030 struct riscv_implicit_subset
1032 const char *subset_name
;
1033 const char *implicit_name
;
1034 /* A function to determine if we need to add the implicit subset. */
1035 bool (*check_func
) (const char *, riscv_subset_t
*);
1037 static struct riscv_implicit_subset riscv_implicit_subsets
[] =
1039 {"e", "i", check_implicit_always
},
1040 {"i", "zicsr", check_implicit_for_i
},
1041 {"i", "zifencei", check_implicit_for_i
},
1042 {"g", "i", check_implicit_always
},
1043 {"g", "m", check_implicit_always
},
1044 {"g", "a", check_implicit_always
},
1045 {"g", "f", check_implicit_always
},
1046 {"g", "d", check_implicit_always
},
1047 {"g", "zicsr", check_implicit_always
},
1048 {"g", "zifencei", check_implicit_always
},
1049 {"m", "zmmul", check_implicit_always
},
1050 {"q", "d", check_implicit_always
},
1051 {"v", "d", check_implicit_always
},
1052 {"v", "zve64d", check_implicit_always
},
1053 {"v", "zvl128b", check_implicit_always
},
1054 {"zve64d", "d", check_implicit_always
},
1055 {"zve64d", "zve64f", check_implicit_always
},
1056 {"zve64f", "zve32f", check_implicit_always
},
1057 {"zve64f", "zve64x", check_implicit_always
},
1058 {"zve64f", "zvl64b", check_implicit_always
},
1059 {"zve32f", "f", check_implicit_always
},
1060 {"zve32f", "zvl32b", check_implicit_always
},
1061 {"zve32f", "zve32x", check_implicit_always
},
1062 {"zve64x", "zve32x", check_implicit_always
},
1063 {"zve64x", "zvl64b", check_implicit_always
},
1064 {"zve32x", "zvl32b", check_implicit_always
},
1065 {"zvl65536b", "zvl32768b", check_implicit_always
},
1066 {"zvl32768b", "zvl16384b", check_implicit_always
},
1067 {"zvl16384b", "zvl8192b", check_implicit_always
},
1068 {"zvl8192b", "zvl4096b", check_implicit_always
},
1069 {"zvl4096b", "zvl2048b", check_implicit_always
},
1070 {"zvl2048b", "zvl1024b", check_implicit_always
},
1071 {"zvl1024b", "zvl512b", check_implicit_always
},
1072 {"zvl512b", "zvl256b", check_implicit_always
},
1073 {"zvl256b", "zvl128b", check_implicit_always
},
1074 {"zvl128b", "zvl64b", check_implicit_always
},
1075 {"zvl64b", "zvl32b", check_implicit_always
},
1076 {"d", "f", check_implicit_always
},
1077 {"zfh", "zfhmin", check_implicit_always
},
1078 {"zfhmin", "f", check_implicit_always
},
1079 {"f", "zicsr", check_implicit_always
},
1080 {"zqinx", "zdinx", check_implicit_always
},
1081 {"zdinx", "zfinx", check_implicit_always
},
1082 {"zhinx", "zhinxmin", check_implicit_always
},
1083 {"zhinxmin", "zfinx", check_implicit_always
},
1084 {"zfinx", "zicsr", check_implicit_always
},
1085 {"zk", "zkn", check_implicit_always
},
1086 {"zk", "zkr", check_implicit_always
},
1087 {"zk", "zkt", check_implicit_always
},
1088 {"zkn", "zbkb", check_implicit_always
},
1089 {"zkn", "zbkc", check_implicit_always
},
1090 {"zkn", "zbkx", check_implicit_always
},
1091 {"zkn", "zkne", check_implicit_always
},
1092 {"zkn", "zknd", check_implicit_always
},
1093 {"zkn", "zknh", check_implicit_always
},
1094 {"zks", "zbkb", check_implicit_always
},
1095 {"zks", "zbkc", check_implicit_always
},
1096 {"zks", "zbkx", check_implicit_always
},
1097 {"zks", "zksed", check_implicit_always
},
1098 {"zks", "zksh", check_implicit_always
},
1102 /* For default_enable field, decide if the extension should
1103 be enbaled by default. */
1105 #define EXT_DEFAULT 0x1
1107 /* List all extensions that binutils should know about. */
1109 struct riscv_supported_ext
1112 enum riscv_spec_class isa_spec_class
;
1115 unsigned long default_enable
;
1118 /* The standard extensions must be added in canonical order. */
1120 static struct riscv_supported_ext riscv_supported_std_ext
[] =
1122 {"e", ISA_SPEC_CLASS_20191213
, 1, 9, 0 },
1123 {"e", ISA_SPEC_CLASS_20190608
, 1, 9, 0 },
1124 {"e", ISA_SPEC_CLASS_2P2
, 1, 9, 0 },
1125 {"i", ISA_SPEC_CLASS_20191213
, 2, 1, 0 },
1126 {"i", ISA_SPEC_CLASS_20190608
, 2, 1, 0 },
1127 {"i", ISA_SPEC_CLASS_2P2
, 2, 0, 0 },
1128 /* The g is a special case which we don't want to output it,
1129 but still need it when adding implicit extensions. */
1130 {"g", ISA_SPEC_CLASS_NONE
, RISCV_UNKNOWN_VERSION
, RISCV_UNKNOWN_VERSION
, EXT_DEFAULT
},
1131 {"m", ISA_SPEC_CLASS_20191213
, 2, 0, 0 },
1132 {"m", ISA_SPEC_CLASS_20190608
, 2, 0, 0 },
1133 {"m", ISA_SPEC_CLASS_2P2
, 2, 0, 0 },
1134 {"a", ISA_SPEC_CLASS_20191213
, 2, 1, 0 },
1135 {"a", ISA_SPEC_CLASS_20190608
, 2, 0, 0 },
1136 {"a", ISA_SPEC_CLASS_2P2
, 2, 0, 0 },
1137 {"f", ISA_SPEC_CLASS_20191213
, 2, 2, 0 },
1138 {"f", ISA_SPEC_CLASS_20190608
, 2, 2, 0 },
1139 {"f", ISA_SPEC_CLASS_2P2
, 2, 0, 0 },
1140 {"d", ISA_SPEC_CLASS_20191213
, 2, 2, 0 },
1141 {"d", ISA_SPEC_CLASS_20190608
, 2, 2, 0 },
1142 {"d", ISA_SPEC_CLASS_2P2
, 2, 0, 0 },
1143 {"q", ISA_SPEC_CLASS_20191213
, 2, 2, 0 },
1144 {"q", ISA_SPEC_CLASS_20190608
, 2, 2, 0 },
1145 {"q", ISA_SPEC_CLASS_2P2
, 2, 0, 0 },
1146 {"c", ISA_SPEC_CLASS_20191213
, 2, 0, 0 },
1147 {"c", ISA_SPEC_CLASS_20190608
, 2, 0, 0 },
1148 {"c", ISA_SPEC_CLASS_2P2
, 2, 0, 0 },
1149 {"v", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1150 {"h", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1154 static struct riscv_supported_ext riscv_supported_std_z_ext
[] =
1156 {"zicbom", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1157 {"zicbop", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1158 {"zicboz", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1159 {"zicsr", ISA_SPEC_CLASS_20191213
, 2, 0, 0 },
1160 {"zicsr", ISA_SPEC_CLASS_20190608
, 2, 0, 0 },
1161 {"zifencei", ISA_SPEC_CLASS_20191213
, 2, 0, 0 },
1162 {"zifencei", ISA_SPEC_CLASS_20190608
, 2, 0, 0 },
1163 {"zihintpause", ISA_SPEC_CLASS_DRAFT
, 2, 0, 0 },
1164 {"zmmul", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1165 {"zawrs", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1166 {"zfh", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1167 {"zfhmin", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1168 {"zfinx", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1169 {"zdinx", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1170 {"zqinx", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1171 {"zhinx", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1172 {"zhinxmin", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1173 {"zbb", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1174 {"zba", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1175 {"zbc", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1176 {"zbs", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1177 {"zbkb", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1178 {"zbkc", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1179 {"zbkx", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1180 {"zk", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1181 {"zkn", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1182 {"zknd", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1183 {"zkne", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1184 {"zknh", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1185 {"zkr", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1186 {"zks", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1187 {"zksed", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1188 {"zksh", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1189 {"zkt", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1190 {"zve32x", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1191 {"zve32f", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1192 {"zve32d", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1193 {"zve64x", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1194 {"zve64f", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1195 {"zve64d", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1196 {"zvl32b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1197 {"zvl64b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1198 {"zvl128b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1199 {"zvl256b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1200 {"zvl512b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1201 {"zvl1024b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1202 {"zvl2048b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1203 {"zvl4096b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1204 {"zvl8192b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1205 {"zvl16384b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1206 {"zvl32768b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1207 {"zvl65536b", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1208 {"ztso", ISA_SPEC_CLASS_DRAFT
, 0, 1, 0 },
1212 static struct riscv_supported_ext riscv_supported_std_s_ext
[] =
1214 {"smstateen", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1215 {"sscofpmf", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1216 {"sstc", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1217 {"svinval", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1221 static struct riscv_supported_ext riscv_supported_std_zxm_ext
[] =
1226 static struct riscv_supported_ext riscv_supported_vendor_x_ext
[] =
1228 {"xtheadba", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1229 {"xtheadbb", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1230 {"xtheadbs", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1231 {"xtheadcmo", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1232 {"xtheadcondmov", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1233 {"xtheadfmemidx", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1234 {"xtheadmac", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1235 {"xtheadmemidx", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1236 {"xtheadmempair", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1237 {"xtheadsync", ISA_SPEC_CLASS_DRAFT
, 1, 0, 0 },
1241 const struct riscv_supported_ext
*riscv_all_supported_ext
[] =
1243 riscv_supported_std_ext
,
1244 riscv_supported_std_z_ext
,
1245 riscv_supported_std_s_ext
,
1246 riscv_supported_std_zxm_ext
,
1247 riscv_supported_vendor_x_ext
,
1251 /* ISA extension prefixed name class. Must define them in parsing order. */
1252 enum riscv_prefix_ext_class
1258 RV_ISA_CLASS_UNKNOWN
1261 /* Record the strings of the prefixed extensions, and their corresponding
1262 classes. The more letters of the prefix string, the more forward it must
1263 be defined. Otherwise, the riscv_get_prefix_class will map it to the
1265 struct riscv_parse_prefix_config
1267 /* Class of the extension. */
1268 enum riscv_prefix_ext_class
class;
1270 /* Prefix string for error printing and internal parser usage. */
1273 static const struct riscv_parse_prefix_config parse_config
[] =
1275 {RV_ISA_CLASS_ZXM
, "zxm"},
1276 {RV_ISA_CLASS_Z
, "z"},
1277 {RV_ISA_CLASS_S
, "s"},
1278 {RV_ISA_CLASS_X
, "x"},
1279 {RV_ISA_CLASS_UNKNOWN
, NULL
}
1282 /* Get the prefixed name class for the extensions, the class also
1283 means the order of the prefixed extensions. */
1285 static enum riscv_prefix_ext_class
1286 riscv_get_prefix_class (const char *arch
)
1289 while (parse_config
[i
].class != RV_ISA_CLASS_UNKNOWN
)
1291 if (strncmp (arch
, parse_config
[i
].prefix
,
1292 strlen (parse_config
[i
].prefix
)) == 0)
1293 return parse_config
[i
].class;
1296 return RV_ISA_CLASS_UNKNOWN
;
1299 /* Check KNOWN_EXTS to see if the EXT is supported. */
1302 riscv_known_prefixed_ext (const char *ext
,
1303 struct riscv_supported_ext
*known_exts
)
1306 for (i
= 0; known_exts
[i
].name
!= NULL
; ++i
)
1307 if (strcmp (ext
, known_exts
[i
].name
) == 0)
1312 /* Check whether the prefixed extension is recognized or not. Return
1313 true if recognized, otehrwise return false. */
1316 riscv_recognized_prefixed_ext (const char *ext
)
1318 enum riscv_prefix_ext_class
class = riscv_get_prefix_class (ext
);
1321 case RV_ISA_CLASS_Z
:
1322 return riscv_known_prefixed_ext (ext
, riscv_supported_std_z_ext
);
1323 case RV_ISA_CLASS_ZXM
:
1324 return riscv_known_prefixed_ext (ext
, riscv_supported_std_zxm_ext
);
1325 case RV_ISA_CLASS_S
:
1326 return riscv_known_prefixed_ext (ext
, riscv_supported_std_s_ext
);
1327 case RV_ISA_CLASS_X
:
1328 /* Only the single x is unrecognized. */
1329 if (strcmp (ext
, "x") != 0)
1337 /* Canonical order for single letter extensions. */
1338 static const char riscv_ext_canonical_order
[] = "eigmafdqlcbkjtpvnh";
1340 /* Array is used to compare the orders of standard extensions quickly. */
1341 static int riscv_ext_order
[26] = {0};
1343 /* Init the riscv_ext_order array. */
1346 riscv_init_ext_order (void)
1348 static bool inited
= false;
1352 /* The orders of all standard extensions are positive. */
1355 for (const char *ext
= &riscv_ext_canonical_order
[0]; *ext
; ++ext
)
1356 riscv_ext_order
[(*ext
- 'a')] = order
++;
1358 /* Some of the prefixed keyword are not single letter, so we set
1359 their prefixed orders in the riscv_compare_subsets directly,
1360 not through the riscv_ext_order. */
1365 /* Similar to the strcmp. It returns an integer less than, equal to,
1366 or greater than zero if `subset2` is found, respectively, to be less
1367 than, to match, or be greater than `subset1`.
1370 Zero: Preserved keywords.
1371 Positive number: Standard extensions.
1372 Negative number: Prefixed keywords. */
1375 riscv_compare_subsets (const char *subset1
, const char *subset2
)
1377 int order1
= riscv_ext_order
[(*subset1
- 'a')];
1378 int order2
= riscv_ext_order
[(*subset2
- 'a')];
1380 /* Compare the standard extension first. */
1381 if (order1
> 0 && order2
> 0)
1382 return order1
- order2
;
1384 /* Set the prefixed orders to negative numbers. */
1385 enum riscv_prefix_ext_class class1
= riscv_get_prefix_class (subset1
);
1386 enum riscv_prefix_ext_class class2
= riscv_get_prefix_class (subset2
);
1388 if (class1
!= RV_ISA_CLASS_UNKNOWN
)
1389 order1
= - (int) class1
;
1390 if (class2
!= RV_ISA_CLASS_UNKNOWN
)
1391 order2
= - (int) class2
;
1393 if (order1
== order2
)
1395 /* Compare the standard addition z extensions. */
1396 if (class1
== RV_ISA_CLASS_Z
)
1398 order1
= riscv_ext_order
[(*++subset1
- 'a')];
1399 order2
= riscv_ext_order
[(*++subset2
- 'a')];
1400 if (order1
!= order2
)
1401 return order1
- order2
;
1403 return strcasecmp (++subset1
, ++subset2
);
1406 return order2
- order1
;
1409 /* Find subset in the list. Return TRUE and set `current` to the subset
1410 if it is found. Otherwise, return FALSE and set `current` to the place
1411 where we should insert the subset. However, return FALSE with the NULL
1412 `current` means we should insert the subset at the head of subset list,
1416 riscv_lookup_subset (const riscv_subset_list_t
*subset_list
,
1418 riscv_subset_t
**current
)
1420 riscv_subset_t
*s
, *pre_s
= NULL
;
1422 /* If the subset is added in order, then just add it at the tail. */
1423 if (subset_list
->tail
!= NULL
1424 && riscv_compare_subsets (subset_list
->tail
->name
, subset
) < 0)
1426 *current
= subset_list
->tail
;
1430 for (s
= subset_list
->head
;
1432 pre_s
= s
, s
= s
->next
)
1434 int cmp
= riscv_compare_subsets (s
->name
, subset
);
1448 /* Add the extension to the subset list. Search the
1449 list first, and then find the right place to add. */
1452 riscv_add_subset (riscv_subset_list_t
*subset_list
,
1457 riscv_subset_t
*current
, *new;
1459 if (riscv_lookup_subset (subset_list
, subset
, ¤t
))
1462 new = xmalloc (sizeof *new);
1463 new->name
= xstrdup (subset
);
1464 new->major_version
= major
;
1465 new->minor_version
= minor
;
1468 if (current
!= NULL
)
1470 new->next
= current
->next
;
1471 current
->next
= new;
1475 new->next
= subset_list
->head
;
1476 subset_list
->head
= new;
1479 if (new->next
== NULL
)
1480 subset_list
->tail
= new;
1483 /* Get the default versions from the riscv_supported_*ext tables. */
1486 riscv_get_default_ext_version (enum riscv_spec_class
*default_isa_spec
,
1492 || default_isa_spec
== NULL
1493 || *default_isa_spec
== ISA_SPEC_CLASS_NONE
)
1496 struct riscv_supported_ext
*table
= NULL
;
1497 enum riscv_prefix_ext_class
class = riscv_get_prefix_class (name
);
1500 case RV_ISA_CLASS_ZXM
: table
= riscv_supported_std_zxm_ext
; break;
1501 case RV_ISA_CLASS_Z
: table
= riscv_supported_std_z_ext
; break;
1502 case RV_ISA_CLASS_S
: table
= riscv_supported_std_s_ext
; break;
1503 case RV_ISA_CLASS_X
: table
= riscv_supported_vendor_x_ext
; break;
1505 table
= riscv_supported_std_ext
;
1509 while (table
!= NULL
&& table
[i
].name
!= NULL
)
1511 if (strcmp (table
[i
].name
, name
) == 0
1512 && (table
[i
].isa_spec_class
== ISA_SPEC_CLASS_DRAFT
1513 || table
[i
].isa_spec_class
== *default_isa_spec
))
1515 *major_version
= table
[i
].major_version
;
1516 *minor_version
= table
[i
].minor_version
;
1523 /* Find the default versions for the extension before adding them to
1524 the subset list, if their versions are RISCV_UNKNOWN_VERSION.
1525 Afterwards, report errors if we can not find their default versions. */
1528 riscv_parse_add_subset (riscv_parse_subset_t
*rps
,
1534 int major_version
= major
;
1535 int minor_version
= minor
;
1537 if (major_version
== RISCV_UNKNOWN_VERSION
1538 || minor_version
== RISCV_UNKNOWN_VERSION
)
1539 riscv_get_default_ext_version (rps
->isa_spec
, subset
,
1540 &major_version
, &minor_version
);
1542 /* We don't care the versions of the implicit extensions. */
1544 && (major_version
== RISCV_UNKNOWN_VERSION
1545 || minor_version
== RISCV_UNKNOWN_VERSION
))
1547 if (subset
[0] == 'x')
1549 (_("x ISA extension `%s' must be set with the versions"),
1551 /* Allow old ISA spec can recognize zicsr and zifencei. */
1552 else if (strcmp (subset
, "zicsr") != 0
1553 && strcmp (subset
, "zifencei") != 0)
1555 (_("cannot find default versions of the ISA extension `%s'"),
1560 riscv_add_subset (rps
->subset_list
, subset
,
1561 major_version
, minor_version
);
1564 /* Release subset list. */
1567 riscv_release_subset_list (riscv_subset_list_t
*subset_list
)
1569 while (subset_list
->head
!= NULL
)
1571 riscv_subset_t
*next
= subset_list
->head
->next
;
1572 free ((void *)subset_list
->head
->name
);
1573 free (subset_list
->head
);
1574 subset_list
->head
= next
;
1577 subset_list
->tail
= NULL
;
1580 /* Parsing extension version.
1583 Points to the end of version
1586 `p`: Curent parsing position.
1587 `major_version`: Parsed major version.
1588 `minor_version`: Parsed minor version. */
1591 riscv_parsing_subset_version (const char *p
,
1595 bool major_p
= true;
1607 /* Might be beginning of `p` extension. */
1611 *major_version
= version
;
1615 else if (ISDIGIT (*p
))
1616 version
= (version
* 10) + (*p
- '0');
1622 *major_version
= version
;
1624 *minor_version
= version
;
1626 /* We can not find any version in string. */
1627 if (*major_version
== 0 && *minor_version
== 0)
1629 *major_version
= RISCV_UNKNOWN_VERSION
;
1630 *minor_version
= RISCV_UNKNOWN_VERSION
;
1636 /* Parsing function for standard extensions.
1639 Points to the end of extensions.
1642 `rps`: Hooks and status for parsing extensions.
1643 `arch`: Full ISA string.
1644 `p`: Curent parsing position. */
1647 riscv_parse_std_ext (riscv_parse_subset_t
*rps
,
1651 /* First letter must start with i, e or g. */
1652 if (*p
!= 'e' && *p
!= 'i' && *p
!= 'g')
1655 (_("%s: first ISA extension must be `e', `i' or `g'"),
1660 while (p
!= NULL
&& *p
!= '\0')
1662 /* Stop when we parsed the known prefix class. */
1663 enum riscv_prefix_ext_class
class = riscv_get_prefix_class (p
);
1664 if (class != RV_ISA_CLASS_UNKNOWN
)
1673 bool implicit
= false;
1674 int major
= RISCV_UNKNOWN_VERSION
;
1675 int minor
= RISCV_UNKNOWN_VERSION
;
1676 char subset
[2] = {0, 0};
1680 /* Check if the standard extension is supported. */
1681 if (riscv_ext_order
[(subset
[0] - 'a')] == 0)
1684 (_("%s: unknown standard ISA extension `%c'"),
1689 /* Checking canonical order. */
1690 if (rps
->subset_list
->tail
!= NULL
1691 && riscv_compare_subsets (rps
->subset_list
->tail
->name
, subset
) > 0)
1694 (_("%s: standard ISA extension `%c' is not "
1695 "in canonical order"), arch
, subset
[0]);
1699 p
= riscv_parsing_subset_version (++p
, &major
, &minor
);
1700 /* Added g as an implicit extension. */
1701 if (subset
[0] == 'g')
1704 major
= RISCV_UNKNOWN_VERSION
;
1705 minor
= RISCV_UNKNOWN_VERSION
;
1707 riscv_parse_add_subset (rps
, subset
, major
, minor
, implicit
);
1713 /* Parsing function for prefixed extensions.
1716 Points to the end of extension.
1719 `rps`: Hooks and status for parsing extensions.
1720 `arch`: Full ISA string.
1721 `p`: Curent parsing position. */
1724 riscv_parse_prefixed_ext (riscv_parse_subset_t
*rps
,
1730 enum riscv_prefix_ext_class
class;
1740 class = riscv_get_prefix_class (p
);
1741 if (class == RV_ISA_CLASS_UNKNOWN
)
1744 (_("%s: unknown prefix class for the ISA extension `%s'"),
1749 char *subset
= xstrdup (p
);
1751 const char *end_of_version
;
1753 /* Extract the whole prefixed extension by '_'. */
1754 while (*++q
!= '\0' && *q
!= '_')
1756 /* Look forward to the first letter which is not <major>p<minor>. */
1757 bool find_any_version
= false;
1758 bool find_minor_version
= false;
1763 find_any_version
= true;
1764 else if (find_any_version
1765 && !find_minor_version
1767 && ISDIGIT (*(q
- 1)))
1768 find_minor_version
= true;
1774 /* Check if the end of extension is 'p' or not. If yes, then
1775 the second letter from the end cannot be number. */
1776 if (*(q
- 1) == 'p' && ISDIGIT (*(q
- 2)))
1780 (_("%s: invalid prefixed ISA extension `%s' ends with <number>p"),
1787 riscv_parsing_subset_version (q
, &major_version
, &minor_version
);
1789 if (end_of_version
== NULL
)
1795 /* Check that the extension name is well-formed. */
1796 if (rps
->check_unknown_prefixed_ext
1797 && !riscv_recognized_prefixed_ext (subset
))
1800 (_("%s: unknown prefixed ISA extension `%s'"),
1806 riscv_parse_add_subset (rps
, subset
,
1808 minor_version
, false);
1809 p
+= end_of_version
- subset
;
1812 if (*p
!= '\0' && *p
!= '_')
1815 (_("%s: prefixed ISA extension must separate with _"),
1824 /* Add the implicit extensions. */
1827 riscv_parse_add_implicit_subsets (riscv_parse_subset_t
*rps
)
1829 struct riscv_implicit_subset
*t
= riscv_implicit_subsets
;
1830 for (; t
->subset_name
; t
++)
1832 riscv_subset_t
*subset
= NULL
;
1833 if (riscv_lookup_subset (rps
->subset_list
, t
->subset_name
, &subset
)
1834 && t
->check_func (t
->implicit_name
, subset
))
1835 riscv_parse_add_subset (rps
, t
->implicit_name
,
1836 RISCV_UNKNOWN_VERSION
,
1837 RISCV_UNKNOWN_VERSION
, true);
1841 /* Check extensions conflicts. */
1844 riscv_parse_check_conflicts (riscv_parse_subset_t
*rps
)
1846 riscv_subset_t
*subset
= NULL
;
1847 int xlen
= *rps
->xlen
;
1848 bool no_conflict
= true;
1850 if (riscv_lookup_subset (rps
->subset_list
, "e", &subset
)
1854 (_("rv%d does not support the `e' extension"), xlen
);
1855 no_conflict
= false;
1857 if (riscv_lookup_subset (rps
->subset_list
, "q", &subset
)
1858 && (subset
->major_version
< 2 || (subset
->major_version
== 2
1859 && subset
->minor_version
< 2))
1862 rps
->error_handler (_("rv%d does not support the `q' extension"), xlen
);
1863 no_conflict
= false;
1865 if (riscv_lookup_subset (rps
->subset_list
, "e", &subset
)
1866 && riscv_lookup_subset (rps
->subset_list
, "f", &subset
))
1869 (_("rv32e does not support the `f' extension"));
1870 no_conflict
= false;
1872 if (riscv_lookup_subset (rps
->subset_list
, "zfinx", &subset
)
1873 && riscv_lookup_subset (rps
->subset_list
, "f", &subset
))
1876 (_("`zfinx' is conflict with the `f/d/q/zfh/zfhmin' extension"));
1877 no_conflict
= false;
1880 bool support_zve
= false;
1881 bool support_zvl
= false;
1882 riscv_subset_t
*s
= rps
->subset_list
->head
;
1883 for (; s
!= NULL
; s
= s
->next
)
1886 && strncmp (s
->name
, "zve", 3) == 0)
1889 && strncmp (s
->name
, "zvl", 3) == 0)
1891 if (support_zve
&& support_zvl
)
1894 if (support_zvl
&& !support_zve
)
1897 (_("zvl*b extensions need to enable either `v' or `zve' extension"));
1898 no_conflict
= false;
1904 /* Set the default subset list according to the default_enable field
1905 of riscv_supported_*ext tables. */
1908 riscv_set_default_arch (riscv_parse_subset_t
*rps
)
1910 unsigned long enable
= EXT_DEFAULT
;
1912 for (i
= 0; riscv_all_supported_ext
[i
] != NULL
; i
++)
1914 const struct riscv_supported_ext
*table
= riscv_all_supported_ext
[i
];
1915 for (j
= 0; table
[j
].name
!= NULL
; j
++)
1917 bool implicit
= false;
1918 if (strcmp (table
[j
].name
, "g") == 0)
1920 if (table
[j
].default_enable
& enable
)
1921 riscv_parse_add_subset (rps
, table
[j
].name
,
1922 RISCV_UNKNOWN_VERSION
,
1923 RISCV_UNKNOWN_VERSION
, implicit
);
1928 /* Function for parsing ISA string.
1931 Return TRUE on success.
1934 `rps`: Hooks and status for parsing extensions.
1935 `arch`: Full ISA string. */
1938 riscv_parse_subset (riscv_parse_subset_t
*rps
,
1943 /* Init the riscv_ext_order array to compare the order of extensions
1945 riscv_init_ext_order ();
1949 riscv_set_default_arch (rps
);
1950 riscv_parse_add_implicit_subsets (rps
);
1951 return riscv_parse_check_conflicts (rps
);
1954 for (p
= arch
; *p
!= '\0'; p
++)
1959 (_("%s: ISA string cannot contain uppercase letters"),
1966 if (startswith (p
, "rv32"))
1971 else if (startswith (p
, "rv64"))
1978 /* ISA string shouldn't be NULL or empty here. For linker,
1979 it might be empty when we failed to merge the ISA string
1980 in the riscv_merge_attributes. For assembler, we might
1981 give an empty string by .attribute arch, "" or -march=.
1982 However, We have already issued the correct error message
1983 in another side, so do not issue this error when the ISA
1986 rps
->error_handler (
1987 _("%s: ISA string must begin with rv32 or rv64"),
1992 /* Parsing standard extension. */
1993 p
= riscv_parse_std_ext (rps
, arch
, p
);
1998 /* Parse prefixed extensions. */
1999 p
= riscv_parse_prefixed_ext (rps
, arch
, p
);
2004 /* Finally add implicit extensions according to the current
2006 riscv_parse_add_implicit_subsets (rps
);
2008 /* Check the conflicts. */
2009 return riscv_parse_check_conflicts (rps
);
2012 /* Return the number of digits for the input. */
2015 riscv_estimate_digit (unsigned num
)
2021 for (digit
= 0; num
; num
/= 10)
2027 /* Auxiliary function to estimate string length of subset list. */
2030 riscv_estimate_arch_strlen1 (const riscv_subset_t
*subset
)
2033 return 6; /* For rv32/rv64/rv128 and string terminator. */
2035 return riscv_estimate_arch_strlen1 (subset
->next
)
2036 + strlen (subset
->name
)
2037 + riscv_estimate_digit (subset
->major_version
)
2038 + 1 /* For version seperator 'p'. */
2039 + riscv_estimate_digit (subset
->minor_version
)
2040 + 1 /* For underscore. */;
2043 /* Estimate the string length of this subset list. */
2046 riscv_estimate_arch_strlen (const riscv_subset_list_t
*subset_list
)
2048 return riscv_estimate_arch_strlen1 (subset_list
->head
);
2051 /* Auxiliary function to convert subset info to string. */
2054 riscv_arch_str1 (riscv_subset_t
*subset
,
2055 char *attr_str
, char *buf
, size_t bufsz
)
2057 const char *underline
= "_";
2058 riscv_subset_t
*subset_t
= subset
;
2060 if (subset_t
== NULL
)
2063 /* No underline between rvXX and i/e. */
2064 if ((strcasecmp (subset_t
->name
, "i") == 0)
2065 || (strcasecmp (subset_t
->name
, "e") == 0))
2068 snprintf (buf
, bufsz
, "%s%s%dp%d",
2071 subset_t
->major_version
,
2072 subset_t
->minor_version
);
2074 strncat (attr_str
, buf
, bufsz
);
2076 /* Skip 'i' extension after 'e', or skip extensions which
2077 versions are unknown. */
2078 while (subset_t
->next
2079 && ((strcmp (subset_t
->name
, "e") == 0
2080 && strcmp (subset_t
->next
->name
, "i") == 0)
2081 || subset_t
->next
->major_version
== RISCV_UNKNOWN_VERSION
2082 || subset_t
->next
->minor_version
== RISCV_UNKNOWN_VERSION
))
2083 subset_t
= subset_t
->next
;
2085 riscv_arch_str1 (subset_t
->next
, attr_str
, buf
, bufsz
);
2088 /* Convert subset information into string with explicit versions. */
2091 riscv_arch_str (unsigned xlen
, const riscv_subset_list_t
*subset
)
2093 size_t arch_str_len
= riscv_estimate_arch_strlen (subset
);
2094 char *attr_str
= xmalloc (arch_str_len
);
2095 char *buf
= xmalloc (arch_str_len
);
2097 snprintf (attr_str
, arch_str_len
, "rv%u", xlen
);
2099 riscv_arch_str1 (subset
->head
, attr_str
, buf
, arch_str_len
);
2105 /* Copy the subset in the subset list. */
2107 static struct riscv_subset_t
*
2108 riscv_copy_subset (riscv_subset_list_t
*subset_list
,
2109 riscv_subset_t
*subset
)
2114 riscv_subset_t
*new = xmalloc (sizeof *new);
2115 new->name
= xstrdup (subset
->name
);
2116 new->major_version
= subset
->major_version
;
2117 new->minor_version
= subset
->minor_version
;
2118 new->next
= riscv_copy_subset (subset_list
, subset
->next
);
2120 if (subset
->next
== NULL
)
2121 subset_list
->tail
= new;
2126 /* Copy the subset list. */
2128 riscv_subset_list_t
*
2129 riscv_copy_subset_list (riscv_subset_list_t
*subset_list
)
2131 riscv_subset_list_t
*new = xmalloc (sizeof *new);
2132 new->head
= riscv_copy_subset (new, subset_list
->head
);
2136 /* Remove the SUBSET from the subset list. */
2139 riscv_remove_subset (riscv_subset_list_t
*subset_list
,
2142 riscv_subset_t
*current
= subset_list
->head
;
2143 riscv_subset_t
*pre
= NULL
;
2144 for (; current
!= NULL
; pre
= current
, current
= current
->next
)
2146 if (strcmp (current
->name
, subset
) == 0)
2149 subset_list
->head
= current
->next
;
2151 pre
->next
= current
->next
;
2152 if (current
->next
== NULL
)
2153 subset_list
->tail
= pre
;
2154 free ((void *) current
->name
);
2161 /* Add/Remove an extension to/from the subset list. This is used for
2162 the .option rvc or norvc, and .option arch directives. */
2165 riscv_update_subset (riscv_parse_subset_t
*rps
,
2168 const char *p
= str
;
2172 int major_version
= RISCV_UNKNOWN_VERSION
;
2173 int minor_version
= RISCV_UNKNOWN_VERSION
;
2175 bool removed
= false;
2178 case '+': removed
= false; break;
2179 case '-': removed
= true; break;
2181 riscv_release_subset_list (rps
->subset_list
);
2182 return riscv_parse_subset (rps
, p
);
2186 char *subset
= xstrdup (p
);
2188 const char *end_of_version
;
2189 /* Extract the whole prefixed extension by ','. */
2190 while (*q
!= '\0' && *q
!= ',')
2193 /* Look forward to the first letter which is not <major>p<minor>. */
2194 bool find_any_version
= false;
2195 bool find_minor_version
= false;
2196 size_t len
= q
- subset
;
2198 for (i
= len
; i
> 0; i
--)
2202 find_any_version
= true;
2203 else if (find_any_version
2204 && !find_minor_version
2206 && ISDIGIT (*(q
- 1)))
2207 find_minor_version
= true;
2214 /* Check if the end of extension is 'p' or not. If yes, then
2215 the second letter from the end cannot be number. */
2216 if (len
> 1 && *(q
- 1) == 'p' && ISDIGIT (*(q
- 2)))
2220 (_("invalid ISA extension ends with <number>p "
2221 "in .option arch `%s'"), str
);
2227 riscv_parsing_subset_version (q
, &major_version
, &minor_version
);
2229 if (end_of_version
== NULL
)
2235 if (strlen (subset
) == 0
2236 || (strlen (subset
) == 1
2237 && riscv_ext_order
[(*subset
- 'a')] == 0)
2238 || (strlen (subset
) > 1
2239 && rps
->check_unknown_prefixed_ext
2240 && !riscv_recognized_prefixed_ext (subset
)))
2243 (_("unknown ISA extension `%s' in .option arch `%s'"),
2249 if (strcmp (subset
, "i") == 0
2250 || strcmp (subset
, "e") == 0
2251 || strcmp (subset
, "g") == 0)
2254 (_("cannot + or - base extension `%s' in .option "
2255 "arch `%s'"), subset
, str
);
2261 riscv_remove_subset (rps
->subset_list
, subset
);
2263 riscv_parse_add_subset (rps
, subset
, major_version
, minor_version
, true);
2264 p
+= end_of_version
- subset
;
2267 while (*p
++ == ',');
2269 riscv_parse_add_implicit_subsets (rps
);
2270 return riscv_parse_check_conflicts (rps
);
2273 /* Check if the FEATURE subset is supported or not in the subset list.
2274 Return true if it is supported; Otherwise, return false. */
2277 riscv_subset_supports (riscv_parse_subset_t
*rps
,
2278 const char *feature
)
2280 struct riscv_subset_t
*subset
;
2281 return riscv_lookup_subset (rps
->subset_list
, feature
, &subset
);
2284 /* Each instuction is belonged to an instruction class INSN_CLASS_*.
2285 Call riscv_subset_supports to make sure if the instuction is valid. */
2288 riscv_multi_subset_supports (riscv_parse_subset_t
*rps
,
2289 enum riscv_insn_class insn_class
)
2294 return riscv_subset_supports (rps
, "i");
2295 case INSN_CLASS_ZICBOM
:
2296 return riscv_subset_supports (rps
, "zicbom");
2297 case INSN_CLASS_ZICBOP
:
2298 return riscv_subset_supports (rps
, "zicbop");
2299 case INSN_CLASS_ZICBOZ
:
2300 return riscv_subset_supports (rps
, "zicboz");
2301 case INSN_CLASS_ZICSR
:
2302 return riscv_subset_supports (rps
, "zicsr");
2303 case INSN_CLASS_ZIFENCEI
:
2304 return riscv_subset_supports (rps
, "zifencei");
2305 case INSN_CLASS_ZIHINTPAUSE
:
2306 return riscv_subset_supports (rps
, "zihintpause");
2308 return riscv_subset_supports (rps
, "m");
2309 case INSN_CLASS_ZMMUL
:
2310 return riscv_subset_supports (rps
, "zmmul");
2312 return riscv_subset_supports (rps
, "a");
2313 case INSN_CLASS_ZAWRS
:
2314 return riscv_subset_supports (rps
, "zawrs");
2316 return riscv_subset_supports (rps
, "f");
2318 return riscv_subset_supports (rps
, "d");
2320 return riscv_subset_supports (rps
, "q");
2322 return riscv_subset_supports (rps
, "c");
2323 case INSN_CLASS_F_AND_C
:
2324 return (riscv_subset_supports (rps
, "f")
2325 && riscv_subset_supports (rps
, "c"));
2326 case INSN_CLASS_D_AND_C
:
2327 return (riscv_subset_supports (rps
, "d")
2328 && riscv_subset_supports (rps
, "c"));
2329 case INSN_CLASS_F_OR_ZFINX
:
2330 return (riscv_subset_supports (rps
, "f")
2331 || riscv_subset_supports (rps
, "zfinx"));
2332 case INSN_CLASS_D_OR_ZDINX
:
2333 return (riscv_subset_supports (rps
, "d")
2334 || riscv_subset_supports (rps
, "zdinx"));
2335 case INSN_CLASS_Q_OR_ZQINX
:
2336 return (riscv_subset_supports (rps
, "q")
2337 || riscv_subset_supports (rps
, "zqinx"));
2338 case INSN_CLASS_ZFH_OR_ZHINX
:
2339 return (riscv_subset_supports (rps
, "zfh")
2340 || riscv_subset_supports (rps
, "zhinx"));
2341 case INSN_CLASS_ZFHMIN
:
2342 return riscv_subset_supports (rps
, "zfhmin");
2343 case INSN_CLASS_ZFHMIN_OR_ZHINXMIN
:
2344 return (riscv_subset_supports (rps
, "zfhmin")
2345 || riscv_subset_supports (rps
, "zhinxmin"));
2346 case INSN_CLASS_ZFHMIN_AND_D
:
2347 return ((riscv_subset_supports (rps
, "zfhmin")
2348 && riscv_subset_supports (rps
, "d"))
2349 || (riscv_subset_supports (rps
, "zhinxmin")
2350 && riscv_subset_supports (rps
, "zdinx")));
2351 case INSN_CLASS_ZFHMIN_AND_Q
:
2352 return ((riscv_subset_supports (rps
, "zfhmin")
2353 && riscv_subset_supports (rps
, "q"))
2354 || (riscv_subset_supports (rps
, "zhinxmin")
2355 && riscv_subset_supports (rps
, "zqinx")));
2356 case INSN_CLASS_ZBA
:
2357 return riscv_subset_supports (rps
, "zba");
2358 case INSN_CLASS_ZBB
:
2359 return riscv_subset_supports (rps
, "zbb");
2360 case INSN_CLASS_ZBC
:
2361 return riscv_subset_supports (rps
, "zbc");
2362 case INSN_CLASS_ZBS
:
2363 return riscv_subset_supports (rps
, "zbs");
2364 case INSN_CLASS_ZBKB
:
2365 return riscv_subset_supports (rps
, "zbkb");
2366 case INSN_CLASS_ZBKC
:
2367 return riscv_subset_supports (rps
, "zbkc");
2368 case INSN_CLASS_ZBKX
:
2369 return riscv_subset_supports (rps
, "zbkx");
2370 case INSN_CLASS_ZBB_OR_ZBKB
:
2371 return (riscv_subset_supports (rps
, "zbb")
2372 || riscv_subset_supports (rps
, "zbkb"));
2373 case INSN_CLASS_ZBC_OR_ZBKC
:
2374 return (riscv_subset_supports (rps
, "zbc")
2375 || riscv_subset_supports (rps
, "zbkc"));
2376 case INSN_CLASS_ZKND
:
2377 return riscv_subset_supports (rps
, "zknd");
2378 case INSN_CLASS_ZKNE
:
2379 return riscv_subset_supports (rps
, "zkne");
2380 case INSN_CLASS_ZKNH
:
2381 return riscv_subset_supports (rps
, "zknh");
2382 case INSN_CLASS_ZKND_OR_ZKNE
:
2383 return (riscv_subset_supports (rps
, "zknd")
2384 || riscv_subset_supports (rps
, "zkne"));
2385 case INSN_CLASS_ZKSED
:
2386 return riscv_subset_supports (rps
, "zksed");
2387 case INSN_CLASS_ZKSH
:
2388 return riscv_subset_supports (rps
, "zksh");
2390 return (riscv_subset_supports (rps
, "v")
2391 || riscv_subset_supports (rps
, "zve64x")
2392 || riscv_subset_supports (rps
, "zve32x"));
2393 case INSN_CLASS_ZVEF
:
2394 return (riscv_subset_supports (rps
, "v")
2395 || riscv_subset_supports (rps
, "zve64d")
2396 || riscv_subset_supports (rps
, "zve64f")
2397 || riscv_subset_supports (rps
, "zve32f"));
2398 case INSN_CLASS_SVINVAL
:
2399 return riscv_subset_supports (rps
, "svinval");
2401 return riscv_subset_supports (rps
, "h");
2402 case INSN_CLASS_XTHEADBA
:
2403 return riscv_subset_supports (rps
, "xtheadba");
2404 case INSN_CLASS_XTHEADBB
:
2405 return riscv_subset_supports (rps
, "xtheadbb");
2406 case INSN_CLASS_XTHEADBS
:
2407 return riscv_subset_supports (rps
, "xtheadbs");
2408 case INSN_CLASS_XTHEADCMO
:
2409 return riscv_subset_supports (rps
, "xtheadcmo");
2410 case INSN_CLASS_XTHEADCONDMOV
:
2411 return riscv_subset_supports (rps
, "xtheadcondmov");
2412 case INSN_CLASS_XTHEADFMEMIDX
:
2413 return riscv_subset_supports (rps
, "xtheadfmemidx");
2414 case INSN_CLASS_XTHEADMAC
:
2415 return riscv_subset_supports (rps
, "xtheadmac");
2416 case INSN_CLASS_XTHEADMEMIDX
:
2417 return riscv_subset_supports (rps
, "xtheadmemidx");
2418 case INSN_CLASS_XTHEADMEMPAIR
:
2419 return riscv_subset_supports (rps
, "xtheadmempair");
2420 case INSN_CLASS_XTHEADSYNC
:
2421 return riscv_subset_supports (rps
, "xtheadsync");
2424 (_("internal: unreachable INSN_CLASS_*"));
2429 /* Each instuction is belonged to an instruction class INSN_CLASS_*.
2430 Call riscv_subset_supports_ext to determine the missing extension. */
2433 riscv_multi_subset_supports_ext (riscv_parse_subset_t
*rps
,
2434 enum riscv_insn_class insn_class
)
2440 case INSN_CLASS_ZICSR
:
2442 case INSN_CLASS_ZIFENCEI
:
2444 case INSN_CLASS_ZIHINTPAUSE
:
2445 return "zihintpause";
2448 case INSN_CLASS_ZMMUL
:
2449 return _ ("m' or `zmmul");
2452 case INSN_CLASS_ZAWRS
:
2462 case INSN_CLASS_F_AND_C
:
2463 if (!riscv_subset_supports (rps
, "f")
2464 && !riscv_subset_supports (rps
, "c"))
2465 return _("f' and `c");
2466 else if (!riscv_subset_supports (rps
, "f"))
2470 case INSN_CLASS_D_AND_C
:
2471 if (!riscv_subset_supports (rps
, "d")
2472 && !riscv_subset_supports (rps
, "c"))
2473 return _("d' and `c");
2474 else if (!riscv_subset_supports (rps
, "d"))
2478 case INSN_CLASS_F_OR_ZFINX
:
2479 /* i18n: Formatted like "extension `f' or `zfinx' required". */
2480 return _("f' or `zfinx");
2481 case INSN_CLASS_D_OR_ZDINX
:
2482 return _("d' or `zdinx");
2483 case INSN_CLASS_Q_OR_ZQINX
:
2484 return _("q' or `zqinx");
2485 case INSN_CLASS_ZFH_OR_ZHINX
:
2486 return _("zfh' or `zhinx");
2487 case INSN_CLASS_ZFHMIN
:
2489 case INSN_CLASS_ZFHMIN_OR_ZHINXMIN
:
2490 return _("zfhmin' or `zhinxmin");
2491 case INSN_CLASS_ZFHMIN_AND_D
:
2492 if (riscv_subset_supports (rps
, "zfhmin"))
2494 else if (riscv_subset_supports (rps
, "d"))
2496 else if (riscv_subset_supports (rps
, "zhinxmin"))
2498 else if (riscv_subset_supports (rps
, "zdinx"))
2501 return _("zfhmin' and `d', or `zhinxmin' and `zdinx");
2502 case INSN_CLASS_ZFHMIN_AND_Q
:
2503 if (riscv_subset_supports (rps
, "zfhmin"))
2505 else if (riscv_subset_supports (rps
, "q"))
2507 else if (riscv_subset_supports (rps
, "zhinxmin"))
2509 else if (riscv_subset_supports (rps
, "zqinx"))
2512 return _("zfhmin' and `q', or `zhinxmin' and `zqinx");
2513 case INSN_CLASS_ZBA
:
2515 case INSN_CLASS_ZBB
:
2517 case INSN_CLASS_ZBC
:
2519 case INSN_CLASS_ZBS
:
2521 case INSN_CLASS_ZBKB
:
2523 case INSN_CLASS_ZBKC
:
2525 case INSN_CLASS_ZBKX
:
2527 case INSN_CLASS_ZBB_OR_ZBKB
:
2528 return _("zbb' or `zbkb");
2529 case INSN_CLASS_ZBC_OR_ZBKC
:
2530 return _("zbc' or `zbkc");
2531 case INSN_CLASS_ZKND
:
2533 case INSN_CLASS_ZKNE
:
2535 case INSN_CLASS_ZKNH
:
2537 case INSN_CLASS_ZKND_OR_ZKNE
:
2538 return _("zknd' or `zkne");
2539 case INSN_CLASS_ZKSED
:
2541 case INSN_CLASS_ZKSH
:
2544 return _("v' or `zve64x' or `zve32x");
2545 case INSN_CLASS_ZVEF
:
2546 return _("v' or `zve64d' or `zve64f' or `zve32f");
2547 case INSN_CLASS_SVINVAL
:
2551 case INSN_CLASS_XTHEADBA
:
2553 case INSN_CLASS_XTHEADBB
:
2555 case INSN_CLASS_XTHEADBS
:
2557 case INSN_CLASS_XTHEADCMO
:
2559 case INSN_CLASS_XTHEADCONDMOV
:
2560 return "xtheadcondmov";
2561 case INSN_CLASS_XTHEADFMEMIDX
:
2562 return "xtheadfmemidx";
2563 case INSN_CLASS_XTHEADMAC
:
2565 case INSN_CLASS_XTHEADMEMIDX
:
2566 return "xtheadmemidx";
2567 case INSN_CLASS_XTHEADMEMPAIR
:
2568 return "xtheadmempair";
2569 case INSN_CLASS_XTHEADSYNC
:
2570 return "xtheadsync";
2573 (_("internal: unreachable INSN_CLASS_*"));