aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2025-02-24 13:44:45 +0000
committerNick Clifton <nickc@redhat.com>2025-02-24 13:44:45 +0000
commitc619e92beb0784775552abe64d9a886a8cdc7236 (patch)
treec83cb68e6139bc8a1c9d7d9a807f66c7a6a41995
parent8f52366c839a155d660964908b411c027851eae1 (diff)
downloadbinutils-c619e92beb0784775552abe64d9a886a8cdc7236.zip
binutils-c619e92beb0784775552abe64d9a886a8cdc7236.tar.gz
binutils-c619e92beb0784775552abe64d9a886a8cdc7236.tar.bz2
objdump: Inform users if RELR relocs are present in a file when using the -r or -R options and no regular relocs are present.
PR 32459
-rw-r--r--binutils/doc/binutils.texi3
-rw-r--r--binutils/objdump.c80
2 files changed, 64 insertions, 19 deletions
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index af3ff8a..08a854f 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -2817,6 +2817,9 @@ libraries. As for @option{-r}, if used with @option{-d} or
@option{-D}, the relocations are printed interspersed with the
disassembly.
+Note: @command{objdump} does not support displaying RELR type
+relocations. These can be displayed by the @command{readelf} program.
+
@item -s
@itemx --full-contents
@cindex sections, full contents
diff --git a/binutils/objdump.c b/binutils/objdump.c
index ebe586e..5ab29a7 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -5473,7 +5473,7 @@ dump_reloc_set (bfd *abfd, asection *sec, arelent **relpp, long relcount)
static void
dump_relocs_in_section (bfd *abfd,
asection *section,
- void *dummy ATTRIBUTE_UNUSED)
+ void *counter)
{
arelent **relpp;
long relcount;
@@ -5522,41 +5522,71 @@ dump_relocs_in_section (bfd *abfd,
printf ("\n\n");
}
free (relpp);
+
+ * ((unsigned int *) counter) += 1;
+}
+
+static void
+is_relr_section (bfd *abfd ATTRIBUTE_UNUSED,
+ asection * section, void *data)
+{
+ if (section->flags & SEC_LINKER_CREATED)
+ return;
+
+ struct bfd_elf_section_data * esd = elf_section_data (section);
+ if (esd == NULL)
+ return;
+
+ if (esd->this_hdr.sh_type == SHT_RELR)
+ * ((bool *) data) = true;
+}
+
+static bool
+contains_relr_relocs (bfd *abfd)
+{
+ if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+ return false;
+
+ bool result = false;
+
+ bfd_map_over_sections (abfd, is_relr_section, &result);
+
+ return result;
}
static void
dump_relocs (bfd *abfd)
{
- bfd_map_over_sections (abfd, dump_relocs_in_section, NULL);
+ unsigned int counter = 0;
+
+ bfd_map_over_sections (abfd, dump_relocs_in_section, & counter);
+
+ if (counter == 0 && contains_relr_relocs (abfd))
+ {
+ printf (_("%s: This file does not contain any ordinary relocations.\n"),
+ sanitize_string (bfd_get_filename (abfd)));
+
+ printf (_("%s: It does however contain RELR relocations. These can be displayed by the readelf program\n"),
+ sanitize_string (bfd_get_filename (abfd)));
+ }
}
static void
dump_dynamic_relocs (bfd *abfd)
{
long relsize;
- arelent **relpp;
+ arelent **relpp = NULL;
long relcount;
relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
printf ("DYNAMIC RELOCATION RECORDS");
- if (relsize == 0)
- {
- printf (" (none)\n\n");
- return;
- }
+ if (relsize <= 0)
+ goto none;
- if (relsize < 0)
- {
- relpp = NULL;
- relcount = relsize;
- }
- else
- {
- relpp = (arelent **) xmalloc (relsize);
- relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
- }
+ relpp = (arelent **) xmalloc (relsize);
+ relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
if (relcount < 0)
{
@@ -5566,7 +5596,7 @@ dump_dynamic_relocs (bfd *abfd)
my_bfd_nonfatal (_("error message was"));
}
else if (relcount == 0)
- printf (" (none)\n\n");
+ goto none;
else
{
printf ("\n");
@@ -5574,6 +5604,18 @@ dump_dynamic_relocs (bfd *abfd)
printf ("\n\n");
}
free (relpp);
+ return;
+
+ none:
+ printf (" (none)\n\n");
+
+ if (contains_relr_relocs (abfd))
+ printf (_("%s: contains RELR relocations which are not displayed by %s.\n\
+These can be displayed by the readelf program instead.\n"),
+ sanitize_string (bfd_get_filename (abfd)),
+ program_name);
+
+ free (relpp);
}
/* Creates a table of paths, to search for source files. */