RISC-V: PR27814, Objdump crashes when disassembling a non-ELF RISC-V binary.
authorJob Noorman <mtvec@pm.me>
Tue, 18 May 2021 00:41:11 +0000 (08:41 +0800)
committerNelson Chu <nelson.chu@sifive.com>
Tue, 18 May 2021 01:26:39 +0000 (09:26 +0800)
2021-05-18  Job Noorman  <mtvec@pm.me>

opcodes/
    PR 27814
    * riscv-dis.c (riscv_get_disassembler): Get elf attributes only for
    the elf objects.

opcodes/ChangeLog
opcodes/riscv-dis.c

index d506b71155981a9f230c29de781d8d1533f911be..11896df782ac20447c44703cc83ffad4d692ac5c 100644 (file)
@@ -1,3 +1,9 @@
+2021-05-18  Job Noorman  <mtvec@pm.me>
+
+       PR 27814
+       * riscv-dis.c (riscv_get_disassembler): Get elf attributes only for
+       the elf objects.
+
 2021-05-17  Alex Coplan  <alex.coplan@arm.com>
 
        * arm-dis.c (mve_opcodes): Fix disassembly of
index 025d134845965987cde089ab0d0fe2b8e485afbf..fe8dfb88d903a2aa494763b8ca504344d9818b61 100644 (file)
@@ -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;