[PATCH] readelf: Report if no GOT section found
H.J. Lu
hjl.tools@gmail.com
Mon Sep 1 18:00:43 GMT 2025
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 | 13 +++++++++++++
binutils/testsuite/binutils-all/readelf-got.d | 5 +++++
binutils/testsuite/binutils-all/readelf.exp | 1 +
3 files changed, 19 insertions(+)
create mode 100644 binutils/testsuite/binutils-all/readelf-got.d
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 4915db928ba..5838f40e869 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -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;
}
@@ -21040,6 +21042,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)
@@ -21123,6 +21127,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
index 00000000000..c5b29018f97
--- /dev/null
+++ b/binutils/testsuite/binutils-all/readelf-got.d
@@ -0,0 +1,5 @@
+#name: readelf --got-contents
+#source: pr25543.s
+#readelf: --got-contents
+
+There is no GOT section in this file.
diff --git a/binutils/testsuite/binutils-all/readelf.exp b/binutils/testsuite/binutils-all/readelf.exp
index 22f2a355bfd..10de1e5cf40 100644
--- a/binutils/testsuite/binutils-all/readelf.exp
+++ b/binutils/testsuite/binutils-all/readelf.exp
@@ -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 {
--
2.51.0
More information about the Binutils
mailing list