[V1 32/36] [SFrame-V3] ld: discard sframe sections when --discard-sframe-sections

Indu Bhagat indu.bhagat@oracle.com
Mon Dec 29 09:29:05 GMT 2025


Mark SFrame sections with SEC_EXCLUDE if --discard-sframe-sections is in
effect.

TBD:
  - This does generate an empty .sframe section though!  A problem ? No
    segment marker PT_GNU_SFRAME is created, which is good
  - Rename option to --discard-sframe [Jan, Indu].

bfd/
	* elf-sframe.c (_bfd_elf_parse_sframe): Mark with SEC_EXCLUDE if
	--discard-sframe-sections is in effect.
ld/testsuite/
	* ld-x86-64/x86-64.exp: New test.
	* ld-x86-64/sframe-command-line-1.d: New test.

---
[Changes from RFC]
  - Rename to --discard-sframe-sections [Jan].
[End of changes from RFC]
---
 bfd/elf-sframe.c                               | 3 +++
 ld/testsuite/ld-x86-64/sframe-command-line-1.d | 8 ++++++++
 ld/testsuite/ld-x86-64/x86-64.exp              | 1 +
 3 files changed, 12 insertions(+)
 create mode 100644 ld/testsuite/ld-x86-64/sframe-command-line-1.d

diff --git a/bfd/elf-sframe.c b/bfd/elf-sframe.c
index a84adc1b19b..daca9922ea3 100644
--- a/bfd/elf-sframe.c
+++ b/bfd/elf-sframe.c
@@ -211,6 +211,9 @@ _bfd_elf_parse_sframe (bfd *abfd,
   bfd_size_type sf_size;
   int decerr = 0;
 
+  if (info->discard_sframe_sections)
+    sec->flags |= SEC_EXCLUDE;
+
   /* Prior versions of assembler and ld were generating SFrame sections with
      section type SHT_PROGBITS.  Issue an error for lack of support for such
      objects now.  Even if section size is zero, a valid section type is
diff --git a/ld/testsuite/ld-x86-64/sframe-command-line-1.d b/ld/testsuite/ld-x86-64/sframe-command-line-1.d
new file mode 100644
index 00000000000..64e0473d170
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/sframe-command-line-1.d
@@ -0,0 +1,8 @@
+#as: --gsframe
+#source: sframe-foo.s
+#source: sframe-bar.s
+#readelf: --sframe
+#ld: -shared --no-rosegment -z separate-code --discard-sframe-sections
+#name: Command line option --discard-sframe-sections
+
+Section '.sframe' has no debugging data.
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index f04ae923ebc..45103ae1e4d 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -587,6 +587,7 @@ run_dump_test "tls-le-pic-3-x32"
 
 if { ![skip_sframe_tests] } {
     run_dump_test "sframe-simple-1"
+    run_dump_test "sframe-command-line-1"
     run_dump_test "sframe-reloc-1"
     run_dump_test "sframe-plt-1"
     run_dump_test "sframe-ibt-plt-1"
-- 
2.43.0



More information about the Binutils mailing list