]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
RISC-V: Re-define mapping symbol $x to the file elf architecture attribute
authorAndrew Oates <andrew@andrewoates.com>
Mon, 24 Feb 2025 07:36:54 +0000 (15:36 +0800)
committerNelson Chu <nelson@rivosinc.com>
Mon, 3 Mar 2025 03:25:43 +0000 (11:25 +0800)
commitade87b8e6293f146f754629101cf4e367aec5da9
tree68a6dcbf86bc2ac321cb67b73af2efead4f14a1f
parent759b09f492d764edfba15c49d12a6f8adfeda019
RISC-V: Re-define mapping symbol $x to the file elf architecture attribute

The mapping symbol "$x" without an ISA string "means using ISA
configuration from ELF attribute."[1].  Currently the code does not
reset the subset_list.  This means that a previous mapping symbol that
overrides the ISA string will continue to be used, rather than the
default string set in the ELF file's .riscv.attributes section.  This
can cause incorrect or failed instruction decodings.

In practice, this causes problems when disassembling code generated by
LLVM, which (unlike gas) does not emit explicit mapping symbols at the
start of each section.

This change stores the default architecture string seen at the beginning
of disassembly in the global parse data struct, and restores that to
subset_list whenever a bare "$x" symbol is seen.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#mapping-symbol

Before this patch, the mapping-x.s was dumped as,

00000000 <.text>:
   0: 00000013           nop
   4: 0001                 .insn 2, 0x0001
   6: 0001                 .insn 2, 0x0001

Which is caused by the definiation of $x was conflict with the psABI.
gas/testsuite/gas/riscv/mapping-x.d [new file with mode: 0644]
gas/testsuite/gas/riscv/mapping-x.s [new file with mode: 0644]
opcodes/riscv-dis.c