[PATCH] readelf: objdump: sframe: fix dumping with section name
Indu Bhagat
indu.bhagat@oracle.com
Sun Jul 20 05:34:49 GMT 2025
Fix PR binutils/33186 - No SFrame dump if section name is not .sframe
When no section name is given, ensure that the dumping routines are able
to dump a section of type SHT_GNU_SFRAME and not fail if the SFrame
section name is not ".sframe".
For objdump, in dump_dwarf_section (), use the match string of ".sframe"
to find the corresponding debug_displays[] item for SFrame section.
Doing this ensures that any call to dump_dwarf_section () with the
section pointing to the SFrame section (with name possibly different
from ".sframe") will successfully dump the SFrame section.
If the SFrame section is named anything but ".sframe", the desirable
behaviour is:
$ readelf -S sort | grep sframe
[NN] .sframe2 GNU_SFRAME 0000000000NNNNNN 0000NNNN
$ objdump --sframe sort
sort: file format elf64-x86-64
No .sframe section present
So, set dump_sframe_section_name to ".sframe" if user specifies no
section name. In the error checking done in dump_sframe_section, add
the case when user specifies a valid section name but one that does not
contain SFrame section data.
Similar changes in readelf.
Add a test each for objdump and readelf to dump a renamed section. Use
gas_sframe_check to limit the execution of these tests only when a gas
supporting SFrame format is present.
binutils/
PR binutils/33186
* objdump.c (dump_dwarf_section): Set match to ".sframe" which
corresponds to the name in the debug_displays[] entry for
SFrame section.
(dump_sframe_section): Check if the user specified section name
contains SFrame data.
(main): Set default section name to ".sframe".
* readelf.c (display_debug_section): Adjust checks to find the
debug_diplay[] item for the input SFrame section in the arg.
binutils/testsuite/
PR binutils/33186
* binutils-all/x86-64/objdump-sframe-01.d: New test.
* binutils-all/x86-64/readelf-sframe-01.d: New test.
* binutils-all/x86-64/sframe-func.s: New test.
----
After the patch:
$ objcopy --rename-section .sframe=.sframe2 sort
$ $ readelf -S sort | grep sframe
[NN] .sframe2 GNU_SFRAME 0000000000NNNNNN 0000NNNN
$ readelf --sframe=.sframe sort
readelf: Warning: Section '.sframe' was not dumped because it does not exist
$ readelf --sframe sort
readelf: Warning: Section '.sframe' was not dumped because it does not exist
$ readelf --sframe=.sframe2 sort
Contents of the SFrame section .sframe2:
Header :
Version: SFRAME_VERSION_2
...
$ readelf --sframe=.ctf sort
Unrecognized debug section: .ctf
$ objdump --sframe=.sframe sort
No .sframe section present
$ objdump --sframe sort
No .sframe section present
$ objdump --sframe=.sframe2 sort
Contents of the SFrame section .sframe:
Header :
Version: SFRAME_VERSION_2
...
$ objdump --sframe=.ctf sort
Section .ctf does not contain SFrame data
---
binutils/objdump.c | 12 +++++++++++-
binutils/readelf.c | 3 +++
.../binutils-all/x86-64/objdump-sframe-01.d | 18 ++++++++++++++++++
.../binutils-all/x86-64/readelf-sframe-01.d | 18 ++++++++++++++++++
.../binutils-all/x86-64/sframe-func.s | 11 +++++++++++
5 files changed, 61 insertions(+), 1 deletion(-)
create mode 100644 binutils/testsuite/binutils-all/x86-64/objdump-sframe-01.d
create mode 100644 binutils/testsuite/binutils-all/x86-64/readelf-sframe-01.d
create mode 100644 binutils/testsuite/binutils-all/x86-64/sframe-func.s
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 98d30496a6f..b94eabdb059 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -4495,6 +4495,8 @@ dump_dwarf_section (bfd *abfd, asection *section,
if (startswith (name, ".gnu.linkonce.wi."))
match = ".debug_info";
+ else if (elf_section_type (section) == SHT_GNU_SFRAME)
+ match = ".sframe";
else
match = name;
@@ -4999,6 +5001,12 @@ dump_sframe_section (bfd *abfd, const char *sect_name, bool is_mainfile)
printf (_("No %s section present\n\n"), sanitize_string (sect_name));
return;
}
+ else if (elf_section_type (sec) != SHT_GNU_SFRAME)
+ {
+ printf (_("Section %s does not contain SFrame data\n\n"),
+ sanitize_string (sect_name));
+ return;
+ }
}
dump_dwarf (abfd, is_mainfile);
}
@@ -6332,8 +6340,10 @@ main (int argc, char **argv)
if (optarg)
dump_sframe_section_name = xstrdup (optarg);
+ else
+ dump_sframe_section_name = ".sframe";
- /* Error checking for user-provided section name is done in
+ /* Error checking for dump_sframe_section_name is done in
dump_sframe_section (). Initialize for now with the default
internal name: "sframe-internal-only". */
dwarf_select_sections_by_names ("sframe-internal-only");
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 686a16c60fc..53c18b3d0e1 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -17493,6 +17493,7 @@ display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * fileda
if (streq (sec->uncompressed_name, name)
|| (id == line && startswith (name, ".debug_line."))
+ || (id == sframe && section->sh_type == SHT_GNU_SFRAME)
|| streq (sec->compressed_name, name))
{
bool secondary = (section != find_section (filedata, name));
@@ -17502,6 +17503,8 @@ display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * fileda
if (i == line && startswith (name, ".debug_line."))
sec->name = name;
+ else if (i == sframe && section->sh_type == SHT_GNU_SFRAME)
+ sec->name = name;
else if (streq (sec->uncompressed_name, name))
sec->name = sec->uncompressed_name;
else
diff --git a/binutils/testsuite/binutils-all/x86-64/objdump-sframe-01.d b/binutils/testsuite/binutils-all/x86-64/objdump-sframe-01.d
new file mode 100644
index 00000000000..cca83cbf09b
--- /dev/null
+++ b/binutils/testsuite/binutils-all/x86-64/objdump-sframe-01.d
@@ -0,0 +1,18 @@
+#PROG:objcopy
+#name: objdump dump SFrame section .sframe2
+#source: sframe-func.s
+#as: --gsframe
+#objcopy: --rename-section .sframe=.sframe2
+#objdump: --sframe=.sframe2
+#target: x86_64-*-*
+#xfail: ![gas_sframe_check]
+
+#...
+ Header :
+
+ Version: SFRAME_VERSION_2
+ Flags: SFRAME_F_FDE_FUNC_START_PCREL
+ CFA fixed RA offset: -8
+ Num FDEs: 1
+ Num FREs: 4
+#pass
diff --git a/binutils/testsuite/binutils-all/x86-64/readelf-sframe-01.d b/binutils/testsuite/binutils-all/x86-64/readelf-sframe-01.d
new file mode 100644
index 00000000000..a6973d832a4
--- /dev/null
+++ b/binutils/testsuite/binutils-all/x86-64/readelf-sframe-01.d
@@ -0,0 +1,18 @@
+#PROG:objcopy
+#name: readelf dump SFrame section .sframe2
+#source: sframe-func.s
+#as: --gsframe
+#objcopy: --rename-section .sframe=.sframe2
+#readelf: --sframe=.sframe2
+#target: x86_64-*-*
+#xfail: ![gas_sframe_check]
+
+#...
+ Header :
+
+ Version: SFRAME_VERSION_2
+ Flags: SFRAME_F_FDE_FUNC_START_PCREL
+ CFA fixed RA offset: -8
+ Num FDEs: 1
+ Num FREs: 4
+#pass
diff --git a/binutils/testsuite/binutils-all/x86-64/sframe-func.s b/binutils/testsuite/binutils-all/x86-64/sframe-func.s
new file mode 100644
index 00000000000..cbd83c38d67
--- /dev/null
+++ b/binutils/testsuite/binutils-all/x86-64/sframe-func.s
@@ -0,0 +1,11 @@
+ .cfi_sections .sframe
+ .cfi_startproc
+ .long 8
+ .cfi_def_cfa_offset 16
+ .cfi_offset 6, -16
+ .long 8
+ .cfi_def_cfa_register 6
+ .long 8
+ .cfi_def_cfa 7, 8
+ .long 8
+ .cfi_endproc
--
2.43.0
More information about the Binutils
mailing list