[PATCH] elf: Use elf_link_first_hash_entry for first_hash

Alan Modra amodra@gmail.com
Fri Apr 5 23:53:41 GMT 2024


On Fri, Apr 05, 2024 at 04:37:58PM -0700, H.J. Lu wrote:
> @@ -4341,11 +4377,11 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
>  	  && htab->first_hash == NULL)
>  	{
>  	  /* Initialize first_hash for an IR input.  */
> -	  htab->first_hash = (struct bfd_link_hash_table *)
> -	    xmalloc (sizeof (struct bfd_link_hash_table));
> -	  if (!bfd_hash_table_init (&htab->first_hash->table,
> -				    _bfd_link_hash_newfunc,
> -				    sizeof (struct bfd_link_hash_entry)))
> +	  htab->first_hash = (struct bfd_hash_table *)
> +	    xmalloc (sizeof (struct bfd_hash_table));
> +	  if (!bfd_hash_table_init
> +	      (htab->first_hash, elf_link_first_hash_newfunc,
> +	       sizeof (struct elf_link_first_hash_entry)))
>  	    info->callbacks->einfo
>  	      (_("%F%P: first_hash failed to initialize: %E\n"));
>  	}

I didn't notice this before, but you shouldn't really be using xmalloc
in libbfd.  Yes, as a practical matter it isn't so relevant for
linker-only bfd functions, but it's probably worth fixing here.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list