]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
readelf: Report if no GOT section found
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 1 Sep 2025 18:00:43 +0000 (11:00 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 2 Sep 2025 15:29:26 +0000 (08:29 -0700)
Update "readelf --got-contents" to report if no GOT section found.

* readelf.c (process_got_section_contents): Report if no GOT
section found.
* testsuite/binutils-all/readelf-got.d: New file.
* testsuite/binutils-all/readelf.exp: Run readelf-got.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
binutils/readelf.c
binutils/testsuite/binutils-all/readelf-got.d [new file with mode: 0644]
binutils/testsuite/binutils-all/readelf.exp

index 2affc713adb73ac125f94d9a2d51f5995393e21f..2f8dda889134bb6ab273ac4b902afcac10d9cb65 100644 (file)
@@ -21009,6 +21009,7 @@ process_got_section_contents (Filedata * filedata)
   uint64_t entries;
   unsigned char *data;
   bool res = true;
+  bool found = false;
 
   if (!do_got_section_contents)
     return res;
@@ -21020,6 +21021,7 @@ process_got_section_contents (Filedata * filedata)
       /* process_mips_specific also displays GOT related contents.  */
       if (!do_arch)
        res = process_mips_specific (filedata, true);
+      found = true;
       goto out;
     }
 
@@ -21039,6 +21041,8 @@ process_got_section_contents (Filedata * filedata)
        if (!startswith (name, ".got"))
          continue;
 
+       found = true;
+
        data = (unsigned char *) get_section_contents (section,
                                                       filedata);
        if (data == NULL)
@@ -21122,6 +21126,15 @@ process_got_section_contents (Filedata * filedata)
       }
 
  out:
+  if (! found)
+    {
+      if (filedata->is_separate)
+       printf (_("\nThere is no GOT section in linked file '%s'.\n"),
+               filedata->file_name);
+      else
+       printf (_("\nThere is no GOT section in this file.\n"));
+    }
+
   for (size_t j = 0; j < all_relocations_count; j++)
     free (all_relocations_root[j].r_symbol);
   free (all_relocations_root);
diff --git a/binutils/testsuite/binutils-all/readelf-got.d b/binutils/testsuite/binutils-all/readelf-got.d
new file mode 100644 (file)
index 0000000..c5b2901
--- /dev/null
@@ -0,0 +1,5 @@
+#name: readelf --got-contents
+#source: pr25543.s
+#readelf: --got-contents
+
+There is no GOT section in this file.
index 22f2a355bfdf69767390eaeb60710bef4d34cd5a..10de1e5cf4017854821b37aee47c2ad0b246e7f7 100644 (file)
@@ -402,6 +402,7 @@ if {[which $AS] != 0} then {
     run_dump_test "readelf-maskos-1a"
     run_dump_test "readelf-maskos-1b"
     run_dump_test "readelf-debug-str-offsets-dw4"
+    run_dump_test "readelf-got"
     if {![istarget *-*-hpux*]} then {
        run_dump_test pr26548
        if {![binutils_assemble_flags $srcdir/$subdir/pr26548.s tmpdir/pr26548e.o {--defsym ERROR=1}]} then {