]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
readelf: objdump: sframe: fix dumping with section name
authorIndu Bhagat <indu.bhagat@oracle.com>
Sat, 19 Jul 2025 08:41:27 +0000 (01:41 -0700)
committerIndu Bhagat <indu.bhagat@oracle.com>
Fri, 25 Jul 2025 08:21:29 +0000 (01:21 -0700)
Fix PR binutils/33186 - No SFrame dump if section name is not .sframe

When the section name is not ".sframe", ensure that readelf and objdump
are able to dump a section of type SHT_GNU_SFRAME and not fail if the
user specifies the new section name.

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", and user does not
specify the name of the SFrame section either, the documented behaviour
is that the default section name is assumed to be ".sframe".  So the
following (albeit counter intuitive) is expected at this time:

$ readelf -S sort | grep sframe
  [NN] .sframe2          GNU_SFRAME       0000000000NNNNNN  0000NNNN

(Note section name .sframe2).

$ objdump --sframe sort

sort:     file format elf64-x86-64

No .sframe section present

(Similarly for readelf as well).

For objdump, 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.  For sections generated with Binutils >=
2.45, this can be checked with section type of SHT_GNU_SFRAME.
Previously these sections were SHT_PROGBITS with name ".sframe".

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_diplays[] item for the input arg SFrame section.
Use id instead of i, as it is more readable.

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.

binutils/objdump.c
binutils/readelf.c
binutils/testsuite/binutils-all/x86-64/objdump-sframe-01.d [new file with mode: 0644]
binutils/testsuite/binutils-all/x86-64/readelf-sframe-01.d [new file with mode: 0644]
binutils/testsuite/binutils-all/x86-64/sframe-func.s [new file with mode: 0644]

index 98d30496a6f2532eb8a63db0d1da4352e24a185a..0bea4d0761c5e643c4629c0924f4cef08bad6587 100644 (file)
@@ -4498,6 +4498,9 @@ dump_dwarf_section (bfd *abfd, asection *section,
   else
     match = name;
 
+  if (elf_section_type (section) == SHT_GNU_SFRAME)
+    match = ".sframe";
+
   for (i = 0; i < max; i++)
     if ((strcmp (debug_displays [i].section.uncompressed_name, match) == 0
         || strcmp (debug_displays [i].section.compressed_name, match) == 0
@@ -4999,6 +5002,18 @@ dump_sframe_section (bfd *abfd, const char *sect_name, bool is_mainfile)
          printf (_("No %s section present\n\n"), sanitize_string (sect_name));
          return;
        }
+      /* Starting with Binutils 2.45, SFrame sections have section type
+        SHT_GNU_SFRAME.  For SFrame sections from Binutils 2.44 or earlier,
+        check explcitly for SFrame sections of type SHT_PROGBITS and name
+        ".sframe" to allow them.  */
+      else if (elf_section_type (sec) != SHT_GNU_SFRAME
+              && !(elf_section_type (sec) == SHT_PROGBITS
+                   && strcmp (sect_name, ".sframe") == 0))
+       {
+         printf (_("Section %s does not contain SFrame data\n\n"),
+                 sanitize_string (sect_name));
+         return;
+       }
     }
   dump_dwarf (abfd, is_mainfile);
 }
@@ -6332,8 +6347,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");
index 686a16c60fc8e3afb5ec9fe719341392c27c5a27..bb81c824ac3b5b98217e8ebc20c47bdda1c75561 100644 (file)
@@ -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 (id == 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 (file)
index 0000000..cca83cb
--- /dev/null
@@ -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 (file)
index 0000000..a6973d8
--- /dev/null
@@ -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 (file)
index 0000000..cbd83c3
--- /dev/null
@@ -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