From: H.J. Lu Date: Mon, 1 Sep 2025 18:00:43 +0000 (-0700) Subject: readelf: Report if no GOT section found X-Git-Tag: gdb-17-branchpoint~88 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eae0da7eb450546da6551a625aa3a5c6328c1c9f;p=thirdparty%2Fbinutils-gdb.git readelf: Report if no GOT section found 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 --- diff --git a/binutils/readelf.c b/binutils/readelf.c index 2affc713adb..2f8dda88913 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; } @@ -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 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 {