]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[SFrame-V3] ld: add --no-sframe-info command line option
authorIndu Bhagat <indu.bhagat@oracle.com>
Wed, 3 Dec 2025 20:50:33 +0000 (12:50 -0800)
committerIndu Bhagat <indu.bhagat@oracle.com>
Tue, 9 Dec 2025 08:26:15 +0000 (00:26 -0800)
Add a new command line option `--no-sframe-info` to the linker. This option
allows users to prevent the linker from generating .sframe sections,
including the linker-generated (internal) SFrame sections for PLT entries.

Previously, the existing `--no-ld-generated-unwind-info` option
controlled whether (not just .eh_frame for PLT entries, but also) SFrame
for PLT entries. This change decouples SFrame from other unwind formats
(like .eh_frame), allowing for more control over the output binary's
SFrame data.

The option is added for architectures that currently support SFrame:
AArch64, s390x, and x86_64.

In a subsequent commit, we will tie this option with discard of all
input .sframe sections.

TBD:
  - For aarch64, is adding to both aarch64elf.sh and aarch64linux.sh
    necessary?  The desired outcome is to allow the new command line for
    aarch64 elf, amd64 elf, s390x elf only.  Confirm.

bfd/
* elf64-s390.c (elf_s390_create_dynamic_sections): Use
no_ld_sframe_info to guard .sframe section creation.
* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Likewise.
include/
* bfdlink.h (struct bfd_link_info): Add no_ld_sframe_info bitfield.
ld/
* ldlex.h (enum option_values): Add OPTION_NO_LD_SFRAME_INFO.
* lexsup.c (elf_sframe_list_options): New function.
(ld_list_options): Add sframe_info argument. Update callers.
* emulparams/sframe_info.sh: New file.
* emulparams/aarch64elf.sh: Source sframe_info.sh.
* emulparams/aarch64linux.sh: Likewise.
* emulparams/elf64_s390.sh: Likewise.
* emulparams/elf_x86_64.sh: Likewise.
* Makefile.am: Update to handle sframe_info.sh and new list options.
* configure.ac: Handle SFRAME_INFO target variable.
* Makefile.in: Regenerate.
* configure: Regenerate.

14 files changed:
bfd/elf64-s390.c
bfd/elfxx-x86.c
include/bfdlink.h
ld/Makefile.am
ld/Makefile.in
ld/configure
ld/configure.ac
ld/emulparams/aarch64elf.sh
ld/emulparams/aarch64linux.sh
ld/emulparams/elf64_s390.sh
ld/emulparams/elf_x86_64.sh
ld/emulparams/sframe_info.sh [new file with mode: 0644]
ld/ldlex.h
ld/lexsup.c

index 7b2b7c218989938862e90da4e3cdc439f0582775..ac1708f6b80a5a5c64a0ed7e1d4dc46ca63420a2 100644 (file)
@@ -4309,7 +4309,7 @@ elf_s390_create_dynamic_sections (bfd *dynobj,
         }
 
       /* Create .sframe section for .plt section.  */
-      if (!info->no_ld_generated_unwind_info)
+      if (!info->no_ld_sframe_info)
        {
          flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
                            | SEC_HAS_CONTENTS | SEC_IN_MEMORY
index 0e1185993cab4d5141deb77750634960593188bf..d7d12c192cbcf1d276fe6bb2082bfdbfe1496319 100644 (file)
@@ -4840,7 +4840,7 @@ _bfd_x86_elf_link_setup_gnu_properties
        }
 
       /* .sframe sections are emitted for AMD64 ABI only.  */
-      if (ABI_64_P (info->output_bfd) && !info->no_ld_generated_unwind_info)
+      if (ABI_64_P (info->output_bfd) && !info->no_ld_sframe_info)
        {
          flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
                            | SEC_HAS_CONTENTS | SEC_IN_MEMORY
index 00fe0f8c7c831c840a9e37c149b0a835e816d957..698db231af5bc525e3fb1cf17d7bec965e6d9e82 100644 (file)
@@ -475,6 +475,10 @@ struct bfd_link_info
      linker created sections, TRUE if it should be omitted.  */
   unsigned int no_ld_generated_unwind_info: 1;
 
+  /* TRUE if no .sframe stack trace info should be generated for the output.
+     This includes linker generated SFrame info as well.  */
+  unsigned int no_ld_sframe_info: 1;
+
   /* TRUE if BFD should generate a "task linked" object file,
      similar to relocatable but also with globals converted to
      statics.  */
index c006448bdcaf29640abcb49f4bd07266af3d7992..b6b1944380ab9a21b975680f7cb1c70ab3ecc7de 100644 (file)
@@ -42,7 +42,8 @@ ZLIBINC = @zlibinc@
 
 ELF_CFLAGS=-DELF_LIST_OPTIONS=@elf_list_options@ \
           -DELF_SHLIB_LIST_OPTIONS=@elf_shlib_list_options@ \
-          -DELF_PLT_UNWIND_LIST_OPTIONS=@elf_plt_unwind_list_options@
+          -DELF_PLT_UNWIND_LIST_OPTIONS=@elf_plt_unwind_list_options@ \
+          -DELF_SFRAME_LIST_OPTIONS=@elf_sframe_list_options@
 WARN_CFLAGS = @WARN_CFLAGS@
 NO_WERROR = @NO_WERROR@
 AM_CFLAGS = $(WARN_CFLAGS) $(ELF_CFLAGS) $(JANSSON_CFLAGS) $(ZSTD_CFLAGS)
index 0acf5f473e22b7a0414022b3e89059b44d6bbafd..060fb5b5152c063b61b6d4ae20ecc7ac31a95350 100644 (file)
@@ -520,6 +520,7 @@ docdir = @docdir@
 dvidir = @dvidir@
 elf_list_options = @elf_list_options@
 elf_plt_unwind_list_options = @elf_plt_unwind_list_options@
+elf_sframe_list_options = @elf_sframe_list_options@
 elf_shlib_list_options = @elf_shlib_list_options@
 enable_initfini_array = @enable_initfini_array@
 enable_libctf = @enable_libctf@
@@ -579,7 +580,8 @@ ZLIB = @zlibdir@ -lz
 ZLIBINC = @zlibinc@
 ELF_CFLAGS = -DELF_LIST_OPTIONS=@elf_list_options@ \
           -DELF_SHLIB_LIST_OPTIONS=@elf_shlib_list_options@ \
-          -DELF_PLT_UNWIND_LIST_OPTIONS=@elf_plt_unwind_list_options@
+          -DELF_PLT_UNWIND_LIST_OPTIONS=@elf_plt_unwind_list_options@ \
+          -DELF_SFRAME_LIST_OPTIONS=@elf_sframe_list_options@
 
 AM_CFLAGS = $(WARN_CFLAGS) $(ELF_CFLAGS) $(JANSSON_CFLAGS) $(ZSTD_CFLAGS)
 
index 9572955642987350473097df61a41d705b743794..a7161189e09342fbb587a5bc0adc96ef9cf8cce9 100755 (executable)
@@ -644,6 +644,7 @@ EMUL_EXTRA_OFILES
 EMULATION_OFILES
 TDIRS
 EMUL
+elf_sframe_list_options
 elf_plt_unwind_list_options
 elf_shlib_list_options
 elf_list_options
@@ -11893,7 +11894,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11896 "configure"
+#line 11897 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11999,7 +12000,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12002 "configure"
+#line 12003 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19201,6 +19202,7 @@ TDIRS=
 elf_list_options=false
 elf_shlib_list_options=false
 elf_plt_unwind_list_options=false
+elf_sframe_list_options=false
 for targ_alias in `echo $target_alias $enable_targets | sed 's/,/ /g'`
 do
   if test "$targ_alias" = "all"; then
@@ -19208,6 +19210,7 @@ do
     elf_list_options=true
     elf_shlib_list_options=true
     elf_plt_unwind_list_options=true
+    elf_sframe_list_options=true
   else
     # Canonicalize the secondary target names.
     result=`$ac_config_sub $targ_alias 2>/dev/null`
@@ -19263,6 +19266,9 @@ tdir_$i=$result"
            if test x${PLT_UNWIND} = xyes; then
              elf_plt_unwind_list_options=true
            fi
+           if test x${SFRAME_INFO} = xyes; then
+             elf_sframe_list_options=true
+           fi
          fi
          ;;
        esac
@@ -19471,6 +19477,7 @@ _ACEOF
 
 
 
+
 if test x${all_targets} = xtrue; then
   if test x${have_64_bit_bfd} = xyes; then
     EMULATION_OFILES='$(ALL_EMULATIONS) $(ALL_64_EMULATIONS)'
index 3e44e3361efb2aeb1f028c3659eafe6217ade559..866d31569f23c5ceff82cce85b3b95d126993477 100644 (file)
@@ -506,6 +506,7 @@ TDIRS=
 elf_list_options=false
 elf_shlib_list_options=false
 elf_plt_unwind_list_options=false
+elf_sframe_list_options=false
 for targ_alias in `echo $target_alias $enable_targets | sed 's/,/ /g'`
 do
   if test "$targ_alias" = "all"; then
@@ -513,6 +514,7 @@ do
     elf_list_options=true
     elf_shlib_list_options=true
     elf_plt_unwind_list_options=true
+    elf_sframe_list_options=true
   else
     # Canonicalize the secondary target names.
     result=`$ac_config_sub $targ_alias 2>/dev/null`
@@ -568,6 +570,9 @@ tdir_$i=$result"
            if test x${PLT_UNWIND} = xyes; then
              elf_plt_unwind_list_options=true
            fi
+           if test x${SFRAME_INFO} = xyes; then
+             elf_sframe_list_options=true
+           fi
          fi
          ;;
        esac
@@ -730,6 +735,7 @@ AC_DEFINE_UNQUOTED([DEFAULT_EMIT_GNU_HASH],
 AC_SUBST(elf_list_options)
 AC_SUBST(elf_shlib_list_options)
 AC_SUBST(elf_plt_unwind_list_options)
+AC_SUBST(elf_sframe_list_options)
 AC_SUBST(EMUL)
 
 AC_SUBST(TDIRS)
index aa051c76a7a1782f81188fe8758ec113424b362a..d4f54de5f51bf3dca1b032b787f03627148e2724 100644 (file)
@@ -1,3 +1,4 @@
+source_sh ${srcdir}/emulparams/sframe_info.sh
 source_sh ${srcdir}/emulparams/dt-relr.sh
 
 ARCH=aarch64
index 6fe82a70659f1a00ef1480098a77a6269f5bd88c..97df7cb2d8c9c2734eaa41542711ebd83532d216 100644 (file)
@@ -1,3 +1,4 @@
+source_sh ${srcdir}/emulparams/sframe_info.sh
 source_sh ${srcdir}/emulparams/dt-relr.sh
 
 ARCH=aarch64
index b58314800d10b44ec01b1e5915a5cacbd2a2f44f..c06299af3cb3b3b6158957594903cf927d5971a2 100644 (file)
@@ -1,4 +1,5 @@
 source_sh ${srcdir}/emulparams/plt_unwind.sh
+source_sh ${srcdir}/emulparams/sframe_info.sh
 SCRIPT_NAME=elf
 ELFSIZE=64
 OUTPUT_FORMAT="elf64-s390"
index 4bab1489b94f5abd2f8ba36174ada4e628a7b3e4..d5f5b372abbb6ee074b629608111b3f2018acc47 100644 (file)
@@ -1,4 +1,5 @@
 source_sh ${srcdir}/emulparams/plt_unwind.sh
+source_sh ${srcdir}/emulparams/sframe_info.sh
 source_sh ${srcdir}/emulparams/extern_protected_data.sh
 source_sh ${srcdir}/emulparams/dynamic_undefined_weak.sh
 source_sh ${srcdir}/emulparams/reloc_overflow.sh
diff --git a/ld/emulparams/sframe_info.sh b/ld/emulparams/sframe_info.sh
new file mode 100644 (file)
index 0000000..b1bc427
--- /dev/null
@@ -0,0 +1,15 @@
+SFRAME_INFO=yes
+
+PARSE_AND_LIST_LONGOPTS_SFRAME='
+  {"no-sframe-info", no_argument, NULL,
+   OPTION_NO_LD_SFRAME_INFO},
+'
+
+PARSE_AND_LIST_ARGS_CASES_SFRAME='
+    case OPTION_NO_LD_SFRAME_INFO:
+      link_info.no_ld_sframe_info = true;
+      break;
+'
+
+PARSE_AND_LIST_LONGOPTS="$PARSE_AND_LIST_LONGOPTS $PARSE_AND_LIST_LONGOPTS_SFRAME"
+PARSE_AND_LIST_ARGS_CASES="$PARSE_AND_LIST_ARGS_CASES $PARSE_AND_LIST_ARGS_CASES_SFRAME"
index 24cac1cdfc0f4f5d19f2dc0f3bcab907537c631e..3ae5323e70d2803cab148021f3219ddc9b2c2a23 100644 (file)
@@ -215,6 +215,8 @@ enum option_values
   /* Used by emulparams/plt_unwind.sh.  */
   OPTION_LD_GENERATED_UNWIND_INFO,
   OPTION_NO_LD_GENERATED_UNWIND_INFO,
+  /* Used by emulparams/sframe_info.sh.  */
+  OPTION_NO_LD_SFRAME_INFO,
   /* Used by emultempl/aarch64elf.em.  */
   OPTION_FIX_ERRATUM_835769,
   OPTION_FIX_ERRATUM_843419,
index 5cb77992733a1a2fd241ae3f52cabda881f220f2..c49bb4c433c7b8f4cf7e37deff72182577ae29c3 100644 (file)
@@ -2364,13 +2364,23 @@ elf_plt_unwind_list_options (FILE *file)
 }
 
 static void
-ld_list_options (FILE *file, bool elf, bool shlib, bool plt_unwind)
+elf_sframe_list_options (FILE *file)
+{
+  fprintf (file, _("\
+  --no-sframe-info            Don't generate SFrame stack trace info in output\n"));
+}
+
+static void
+ld_list_options (FILE *file, bool elf, bool shlib, bool plt_unwind,
+                bool sframe_info)
 {
   if (!elf)
     return;
   printf (_("ELF emulations:\n"));
   if (plt_unwind)
     elf_plt_unwind_list_options (file);
+  if (sframe_info)
+    elf_sframe_list_options (file);
   elf_static_list_options (file);
   if (shlib)
     elf_shlib_list_options (file);
@@ -2495,7 +2505,8 @@ help (void)
   /* xgettext:c-format */
   printf (_("%s: emulation specific options:\n"), program_name);
   ld_list_options (stdout, ELF_LIST_OPTIONS, ELF_SHLIB_LIST_OPTIONS,
-                  ELF_PLT_UNWIND_LIST_OPTIONS);
+                  ELF_PLT_UNWIND_LIST_OPTIONS,
+                  ELF_SFRAME_LIST_OPTIONS);
   ldemul_list_emulation_options (stdout);
   printf ("\n");