[ARM] Avoid dereferencing null pointers

Alan Modra amodra@gmail.com
Wed Oct 24 11:36:00 GMT 2018


On Wed, Oct 24, 2018 at 10:37:59AM +0100, Thomas Preudhomme wrote:
> Hi Christophe,
> 
> I'm a bit surprised cmse_scan is run at all in your case. Where you
> targeting an M profile core?
> 
> Regarding sym_hashes[X] being null, under what conditions can a global
> symbol have a null hash?

I sent a little more info to Christophe privately, after I thought a
little more about the problem.  Guess I should have sent it to the
list.

You can have sym_hashes[n] being 0 when you have an as-needed library
that wasn't needed (it's loaded but then unloaded).

Note this elflink.c code:
  if ((elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0)
    {
      unsigned int i;

      /* Restore the symbol table.  */
      old_ent = (char *) old_tab + tabsize;
      memset (elf_sym_hashes (abfd), 0,
	      extsymcount * sizeof (struct elf_link_hash_entry *));

The memset zaps all the sym_hashes, because after restoring the symbol
table to as it was before loading the as-needed library, the symbol
pointers are no longer valid.

The patch I suggest instead of the one Christophe posted is:

diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 2c321bbcb6..5adec5e473 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -6449,7 +6449,8 @@ elf32_arm_size_stubs (bfd *output_bfd,
 	  asection *section;
 	  Elf_Internal_Sym *local_syms = NULL;
 
-	  if (!is_arm_elf (input_bfd))
+	  if (!is_arm_elf (input_bfd)
+	      || (elf_dyn_lib_class (input_bfd) & DYN_AS_NEEDED) != 0)
 	    continue;
 
 	  num_a8_relocs = 0;

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list