aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2025-04-25 21:45:45 +0100
committerNick Alcock <nick.alcock@oracle.com>2025-04-25 21:45:45 +0100
commit61d4ada564f8b7e10e731f28abda6c4192b63cd2 (patch)
treef29feb26cd394b2d52a2be964dabf6620b450799
parent0d6c6345b74557482be29adeb3944cc5822526cd (diff)
downloadbinutils-61d4ada564f8b7e10e731f28abda6c4192b63cd2.zip
binutils-61d4ada564f8b7e10e731f28abda6c4192b63cd2.tar.gz
binutils-61d4ada564f8b7e10e731f28abda6c4192b63cd2.tar.bz2
binutils: objdump, readelf: BTF dumping support
objdump and readelf's --ctf option can now dump BTF as well (in CTF dumping format, which is quite high-level and C-like compared to bpftool btf dump: both have their uses).
-rw-r--r--binutils/objdump.c14
-rw-r--r--binutils/readelf.c10
2 files changed, 17 insertions, 7 deletions
diff --git a/binutils/objdump.c b/binutils/objdump.c
index bb791e2..1cf0b26 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -4875,12 +4875,22 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name,
ctf_next_t *i = NULL;
const char *name;
size_t member = 0;
+ int try_defaults = 0;
int err;
if (sect_name == NULL)
- sect_name = ".ctf";
+ {
+ sect_name = ".ctf";
+ try_defaults = 1;
+ }
sec = read_section (abfd, sect_name, &ctfdata);
+ if (sec == NULL && try_defaults)
+ {
+ sect_name = ".BTF";
+ sec = read_section (abfd, sect_name, &ctfdata);
+ }
+
if (sec == NULL)
{
my_bfd_nonfatal (bfd_get_filename (abfd));
@@ -4936,7 +4946,7 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name,
return;
}
- printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name));
+ printf (_("Contents of type section %s:\n"), sanitize_string (sect_name));
while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL)
{
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 062ad3e..b019967 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -17045,9 +17045,9 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
strsect.cts_data = strdata;
}
- /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
- libctf papers over the difference, so we can pretend it is always an
- archive. */
+ /* Load the section and dump it. It may be a raw CTF or BTF section, or an
+ archive: libctf papers over the difference, so we can pretend it is always
+ an archive. */
if ((ctfa = ctf_arc_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL)
{
@@ -17071,11 +17071,11 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
ret = true;
if (filedata->is_separate)
- printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
+ printf (_("\nDump of type section '%s' in linked file %s:\n"),
printable_section_name (filedata, section),
filedata->file_name);
else
- printf (_("\nDump of CTF section '%s':\n"),
+ printf (_("\nDump of type section '%s':\n"),
printable_section_name (filedata, section));
while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL)