From: Job Noorman Date: Tue, 18 May 2021 00:41:11 +0000 (+0800) Subject: RISC-V: PR27814, Objdump crashes when disassembling a non-ELF RISC-V binary. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=113bb7618a4b52c5fc8fdc0e82b2cd9f72471f72;p=binutils-gdb.git RISC-V: PR27814, Objdump crashes when disassembling a non-ELF RISC-V binary. 2021-05-18 Job Noorman opcodes/ PR 27814 * riscv-dis.c (riscv_get_disassembler): Get elf attributes only for the elf objects. --- diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index d506b711559..11896df782a 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,9 @@ +2021-05-18 Job Noorman + + PR 27814 + * riscv-dis.c (riscv_get_disassembler): Get elf attributes only for + the elf objects. + 2021-05-17 Alex Coplan * arm-dis.c (mve_opcodes): Fix disassembly of diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index 025d1348459..fe8dfb88d90 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -597,17 +597,21 @@ riscv_get_disassembler (bfd *abfd) { if (abfd) { - const char *sec_name = get_elf_backend_data (abfd)->obj_attrs_section; - if (bfd_get_section_by_name (abfd, sec_name) != NULL) + const struct elf_backend_data *ebd = get_elf_backend_data (abfd); + if (ebd) { - obj_attribute *attr = elf_known_obj_attributes_proc (abfd); - 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; - riscv_get_priv_spec_class_from_numbers (attr[Tag_a].i, - attr[Tag_b].i, - attr[Tag_c].i, - &default_priv_spec); + const char *sec_name = ebd->obj_attrs_section; + if (bfd_get_section_by_name (abfd, sec_name) != NULL) + { + obj_attribute *attr = elf_known_obj_attributes_proc (abfd); + 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; + riscv_get_priv_spec_class_from_numbers (attr[Tag_a].i, + attr[Tag_b].i, + attr[Tag_c].i, + &default_priv_spec); + } } } return print_insn_riscv;