PR31872, Segfault in objdump (elf_slurp_reloc_table_from_section)

Message ID ZmeT2ZjvTTF4nHUr@squeak.grove.modra.org
State New
Headers
Series PR31872, Segfault in objdump (elf_slurp_reloc_table_from_section) |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed

Commit Message

Alan Modra June 11, 2024, 12:01 a.m. UTC
  This one was triggered by trying to dump an AMDGPU object.
elf64-amdgcn.c lacks support for objdump relocation handling.

	PR 31872
	* elfcode.h (elf_slurp_reloc_table_from_section): Don't segfault
	on NULL elf_info_to_howto_rel.
  

Patch

diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index 39dfe0ba234..3dcba4c4fd7 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -1614,11 +1614,11 @@  elf_slurp_reloc_table_from_section (bfd *abfd,
 
       relent->addend = rela.r_addend;
 
-      if ((entsize == sizeof (Elf_External_Rela)
-	   && ebd->elf_info_to_howto != NULL)
-	  || ebd->elf_info_to_howto_rel == NULL)
+      res = false;
+      if (entsize == sizeof (Elf_External_Rela)
+	  && ebd->elf_info_to_howto != NULL)
 	res = ebd->elf_info_to_howto (abfd, relent, &rela);
-      else
+      else if (ebd->elf_info_to_howto_rel != NULL)
 	res = ebd->elf_info_to_howto_rel (abfd, relent, &rela);
 
       if (! res || relent->howto == NULL)