[PATCH v2] readelf: Don't change the symbol table

Jan Beulich jbeulich@suse.com
Wed Sep 3 13:19:00 GMT 2025


On 03.09.2025 15:05, H.J. Lu wrote:
> @@ -1880,13 +1879,13 @@ dump_relr_relocations (Filedata *          filedata,
>  		       uint64_t            relr_size,
>  		       int                 relr_entsize,
>  		       uint64_t            relr_offset,
> -		       Elf_Internal_Sym *  symtab,
> +		       uint64_t *          relrs,

With this effectively owned by the caller, if you really want to keep
freeing it at the bottom of this function, I think at the very least
at the call site the variable would want setting to NULL after the
call, even if that's just for documentation (as the compiler may be
able to figure out that it can drop that assignment).

> @@ -2076,12 +2079,14 @@ dump_relr_relocations (Filedata *          filedata,
>  	break;
>        }
>  
> -  if (symtab != NULL)
> +  Elf_Internal_Sym *symtab = NULL;
> +  if (symtab_p != NULL)
>      {
>        /* Symbol tables are not sorted on address, but we want a quick lookup
>  	 for the symbol associated with each address computed below, so sort
> -	 the table then filter out unwanted entries. FIXME: This assumes that
> -	 the symbol table will not be used later on for some other purpose.  */
> +	 the table then filter out unwanted entries.  */
> +      symtab = xmalloc (nsyms * sizeof (*symtab));
> +      memcpy (symtab, symtab_p, nsyms * sizeof (*symtab));

As before - xmemdup()?

Jan


More information about the Binutils mailing list