[binutils-gdb] readelf: Call qsort only if all_relocations_count > 1

H.J. Lu hjl@sourceware.org
Wed Sep 3 12:39:07 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8a94d92a468eb34f1a6c263d2e950b9036cfcc72

commit 8a94d92a468eb34f1a6c263d2e950b9036cfcc72
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Sep 1 06:55:00 2025 -0700

    readelf: Call qsort only if all_relocations_count > 1
    
    Don't call qsort if all_relocations_count < 1.
    
            PR binutils/33351
            * readelf.c (process_got_section_contents): Call qsort only if
            all_relocations_count > 1.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>

Diff:
---
 binutils/readelf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 2f8dda88913..3205cf2e69e 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -21025,8 +21025,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 > 1)
+    qsort (all_relocations_root, all_relocations_count,
+	   sizeof (elf_relocation), elf_relocation_cmp);
 
   initialise_dumps_byname (filedata);


More information about the Binutils-cvs mailing list