[PATCH] readelf: Call qsort only if all_relocations_count != 0

Alan Modra amodra@gmail.com
Wed Sep 3 05:23:22 GMT 2025


On Mon, Sep 01, 2025 at 06:55:00AM -0700, H.J. Lu wrote:
> Don't call qsort if all_relocations_count == 0.
> 
> 	PR binutils/33351
> 	* readelf.c (process_got_section_contents): Call qsort only if
> 	all_relocations_count != 0.

Better to test for > 1.  OK with that change.

> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>  binutils/readelf.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/binutils/readelf.c b/binutils/readelf.c
> index 2affc713adb..4915db928ba 100644
> --- a/binutils/readelf.c
> +++ b/binutils/readelf.c
> @@ -21023,8 +21023,9 @@ process_got_section_contents (Filedata * filedata)
>        goto out;
>      }
>  
> -  qsort (all_relocations_root, all_relocations_count,
> -	 sizeof (elf_relocation), elf_relocation_cmp);
> +  if (all_relocations_count != 0)
> +    qsort (all_relocations_root, all_relocations_count,
> +	   sizeof (elf_relocation), elf_relocation_cmp);
>  
>    initialise_dumps_byname (filedata);
>  
> -- 
> 2.51.0

-- 
Alan Modra


More information about the Binutils mailing list