[PATCH 2/2] RISC-V: Use obfd for disassembly instead of abfd
Marek Pikuła <[email protected]> Fri, 13 Dec 2024 18:25:44 +0100
| Newsgroups | gmane.comp.gnu.binutils,gmane.comp.gdb.patches,gmane.comp.tools.cgen.devel |
|---|---|
| Message-ID | <[email protected]> |
In case the disassembled ELF is built for a different subset of ISA extensions than the target binary (abfd) the disassembly might be different. For example, a binary might be built for a general `rv64gc` target, but a library that the binary loads might be built for `rv64gcv`. In that case, when only abfd provides information to disassembler, the vector instructions don't get disassembled correctly (and are shown as generic `.insn`). With this change, the disassembler checks which object file is in scope. Thus, it adjusts the output to the ISA subset present in `Tag_RISCV_arch` from the object file in the current scope. Signed-off-by: Marek Pikuła <[email protected]> --- opcodes/riscv-dis.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index f9cf9c5eed0..f5c2329cd8b 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -1371,6 +1371,7 @@ print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info) int (*riscv_disassembler) (bfd_vma, insn_t, const bfd_byte *, struct disassemble_info *); const char *default_arch = "rv64gc"; + bfd *obfd = info->get_obfd_for_addr_func(memaddr, info); if (info->disassembler_options != NULL) { @@ -1381,12 +1382,12 @@ print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info) else if (riscv_gpr_names == NULL) set_default_riscv_dis_options (); - if (info->abfd && bfd_get_flavour (info->abfd) == bfd_target_elf_flavour) + if (obfd && bfd_get_flavour (obfd) == bfd_target_elf_flavour) { - const char *sec_name = get_elf_backend_data (info->abfd)->obj_attrs_section; - if (bfd_get_section_by_name (info->abfd, sec_name) != NULL) + const char *sec_name = get_elf_backend_data (obfd)->obj_attrs_section; + if (bfd_get_section_by_name (obfd, sec_name) != NULL) { - obj_attribute *attr = elf_known_obj_attributes_proc (info->abfd); + obj_attribute *attr = elf_known_obj_attributes_proc (obfd); unsigned int Tag_a = Tag_RISCV_priv_spec; unsigned int Tag_b = Tag_RISCV_priv_spec_minor; unsigned int Tag_c = Tag_RISCV_priv_spec_revision; -- 2.47.0