From: Nick Alcock Date: Fri, 25 Apr 2025 20:45:45 +0000 (+0100) Subject: binutils: objdump, readelf: BTF dumping support X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=61d4ada564f8b7e10e731f28abda6c4192b63cd2;p=thirdparty%2Fbinutils-gdb.git 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). --- diff --git a/binutils/objdump.c b/binutils/objdump.c index bb791e2a8b3..1cf0b267414 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 062ad3eb790..b0199679f98 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)