[binutils-gdb] gas: add --enable-default-sframe configure option

Sam James sjames@sourceware.org
Sat Aug 23 02:06:22 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b0653e3db9c6d0d4f1f547e19aaad621aad58920

commit b0653e3db9c6d0d4f1f547e19aaad621aad58920
Author: Sam James <sam@gentoo.org>
Date:   Thu Jul 3 11:08:59 2025 +0100

    gas: add --enable-default-sframe configure option
    
    SFrames make the most sense when userland as a whole is built with them,
    so add a --enable-default-sframe configure flag to facilitate distributors
    and vendors doing that.
    
    The primary motivation for a configure-time flag is that we don't support
    SFrame for 32-bit x86 but some packaging uses the same flags (with some
    added on top) for multilib builds (to support old binaries like games),
    and simply adding `-Wa,--gsframe` to the standard build flags isn't an
    option (*).
    
    That aside, I believe it'll be helpful for testing and eventual adoption
    in any case.
    
    In summary, combined with the recent --gsframe=[yes|no] support (**):
    * Configured with --enable-default-sframe and nothing is passed
      => SFrames (previously no SFrames)
    * Configured with --enable-default-sframe and --gsframe=yes is passed
      => SFrames (no change from before)
    * Configured with --enable-default-sframe and --gsframe=no is passed
      => No SFrames (no change from before)
    * Configured with --enable-default-sframe and --gsframe is passed
      => SFrames (no change from before)
    
    * Configured with --disable-default-sframe and nothing is passed
      => No SFrames (no change from before)
    * Configured with --disable-default-sframe and --gsframe=yes is passed
      => SFrames (no change from before)
    * Configured with --disable-default-sframe and --gsframe=no is passed
      => No SFrames (no change from before)
    * Configured with --disable-default-sframe and --gsframe is passed
      => SFrames (no change from before)
    
    I've introduced a sframe_as_bad macro on Indu's suggestion. A following
    patch uses its sibling sframe_as_warn heavily and having symmetry plus
    the macro as a form of documentation of intent seems useful.
    
    (*) It gets added to multilib builds too and then we hit the
        `.sframe not supported for target` error in gas/dw2gencfi.c.
    
    (**) I've verbosely listed --gsframe=yes but it's the same as --gsframe.
    
    gas/
            PR gas/33126
            * as.c (enum gen_sframe_option): Initialize if DEFAULT_SFRAME.
            * config.in (DEFAULT_SFRAME): New.
            * configure: Regenerate.
            * configure.ac: Add --enable-default-sframe.
            * doc/as.texi: Document --enable-default-sframe.
            * dw2gencfi.c (cfi_finish): Don't warn if SFrames are enabled
            by default but unavailable for this target.
            * gen-sframe.h (sframe_as_bad): New macro.

Diff:
---
 gas/as.c         |  8 +++++++-
 gas/config.in    |  3 +++
 gas/configure    | 24 ++++++++++++++++++++++--
 gas/configure.ac | 16 ++++++++++++++++
 gas/doc/as.texi  |  3 ++-
 gas/dw2gencfi.c  |  6 +++++-
 gas/gen-sframe.h | 10 ++++++++++
 7 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/gas/as.c b/gas/as.c
index 58ed0a59e21..efcc80deef1 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -113,6 +113,12 @@ int flag_use_elf_stt_common = DEFAULT_GENERATE_ELF_STT_COMMON;
 bool flag_generate_build_notes = DEFAULT_GENERATE_BUILD_NOTES;
 #endif
 
+/* If DEFAULT_SFRAME is 0 instead, flag_gen_sframe gets the default
+   enum value GEN_SFRAME_DEFAULT_NONE.  */
+#if DEFAULT_SFRAME
+enum gen_sframe_option flag_gen_sframe = GEN_SFRAME_CONFIG_ENABLED;
+#endif
+
 segT reg_section;
 segT expr_section;
 segT text_section;
@@ -312,7 +318,7 @@ Options:\n\
                           generate GNU Build notes if none are present in the input\n"));
   fprintf (stream, _("\
   --gsframe[={no|yes}]    whether to generate SFrame stack trace information\n\
-                          (default: no)\n"));
+                          (default: %s)\n"), DEFAULT_SFRAME ? "yes" : "no");
 # if defined (TARGET_USE_SCFI) && defined (TARGET_USE_GINSN)
   fprintf (stream, _("\
   --scfi=experimental     Synthesize DWARF CFI for hand-written asm\n\
diff --git a/gas/config.in b/gas/config.in
index bb896244640..ba042ca44eb 100644
--- a/gas/config.in
+++ b/gas/config.in
@@ -60,6 +60,9 @@
 /* Define default value for RISC-V -mpriv-spec */
 #undef DEFAULT_RISCV_PRIV_SPEC
 
+/* Define to 1 if you want to emit SFrames by default. */
+#undef DEFAULT_SFRAME
+
 /* Define to 1 if you want to check x86 TLS relocation by default. */
 #undef DEFAULT_X86_TLS_CHECK
 
diff --git a/gas/configure b/gas/configure
index 97340444b72..12d96a5acd2 100755
--- a/gas/configure
+++ b/gas/configure
@@ -820,6 +820,7 @@ enable_default_compressed_debug_sections_algorithm
 enable_x86_relax_relocations
 enable_x86_tls_check
 enable_elf_stt_common
+enable_default_sframe
 enable_generate_build_notes
 enable_mips_fix_loongson3_llsc
 enable_x86_used_note
@@ -1497,6 +1498,7 @@ Optional Features:
   --enable-x86-tls-check  check x86 TLS relocation by default
   --enable-elf-stt-common generate ELF common symbols with STT_COMMON type by
                           default
+  --enable-default-sframe generate SFrame by default
   --enable-generate-build-notes
                           generate GNU Build notes if none are provided by the
                           input
@@ -10777,7 +10779,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10780 "configure"
+#line 10782 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -10883,7 +10885,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10886 "configure"
+#line 10888 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11599,6 +11601,15 @@ if test "${enable_elf_stt_common+set}" = set; then :
 esac
 fi
 
+ac_default_sframe=unset
+# Provide a configure time option to override our default.
+# Check whether --enable-default-sframe was given.
+if test "${enable_default_sframe+set}" = set; then :
+  enableval=$enable_default_sframe; case "${enableval}" in
+  yes) ac_default_sframe=1 ;;
+  no)  ac_default_sframe=0 ;;
+esac
+fi
 
 # Decide if the ELF assembler should default to generating
 # GNU Build notes if none are provided by the input.
@@ -12723,6 +12734,15 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+if test ${ac_default_sframe} = unset; then
+  ac_default_sframe=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define DEFAULT_SFRAME $ac_default_sframe
+_ACEOF
+
+
 
 cat >>confdefs.h <<_ACEOF
 #define DEFAULT_GENERATE_BUILD_NOTES $ac_default_generate_build_notes
diff --git a/gas/configure.ac b/gas/configure.ac
index c65797fdf0a..78fe021bafd 100644
--- a/gas/configure.ac
+++ b/gas/configure.ac
@@ -117,6 +117,15 @@ AC_ARG_ENABLE(elf_stt_common,
   yes)  ac_default_elf_stt_common=1 ;;
 esac])dnl
 
+ac_default_sframe=unset
+# Provide a configure time option to override our default.
+AC_ARG_ENABLE(default-sframe,
+	      AS_HELP_STRING([--enable-default-sframe],
+	      [generate SFrame by default]),
+[case "${enableval}" in
+  yes) ac_default_sframe=1 ;;
+  no)  ac_default_sframe=0 ;;
+esac])dnl
 
 # Decide if the ELF assembler should default to generating
 # GNU Build notes if none are provided by the input.
@@ -757,6 +766,13 @@ AC_DEFINE_UNQUOTED(DEFAULT_GENERATE_ELF_STT_COMMON,
   [Define to 1 if you want to generate ELF common symbols with the
    STT_COMMON type by default.])
 
+if test ${ac_default_sframe} = unset; then
+  ac_default_sframe=0
+fi
+AC_DEFINE_UNQUOTED(DEFAULT_SFRAME,
+  $ac_default_sframe,
+  [Define to 1 if you want to emit SFrames by default.])
+
 AC_DEFINE_UNQUOTED(DEFAULT_GENERATE_BUILD_NOTES,
   $ac_default_generate_build_notes,
   [Define to 1 if you want to generate GNU Build attribute notes
diff --git a/gas/doc/as.texi b/gas/doc/as.texi
index 2db5f4896ee..28fb6a6a97b 100644
--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -864,7 +864,8 @@ configure option.
 @itemx --gsframe=yes
 Create @var{.sframe} section from CFI directives.  The explicit
 @option{--gsframe=yes} option behaves the same as @option{--gsframe}.
-Generation can be suppressed with @option{--gsframe=no}.
+Generation can be suppressed with @option{--gsframe=no}.  The default can be
+controlled by a configure option @option{--enable-default-sframe}.
 
 @end ifset
 
diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c
index c28856cdf24..186dfa667c8 100644
--- a/gas/dw2gencfi.c
+++ b/gas/dw2gencfi.c
@@ -2598,9 +2598,11 @@ cfi_finish (void)
 
   /* Generate SFrame section if the user:
 	- enables via the command line option, or
+	- default-enabled at configure-time via --enable-default-sframe, or
 	- specifies .sframe in the .cfi_sections directive and does not disable
 	  via the command line.  */
   if (flag_gen_sframe == GEN_SFRAME_ENABLED
+      || flag_gen_sframe == GEN_SFRAME_CONFIG_ENABLED
       || ((all_cfi_sections & CFI_EMIT_sframe) != 0
 	  && flag_gen_sframe != GEN_SFRAME_DISABLED))
     {
@@ -2619,7 +2621,9 @@ cfi_finish (void)
 	}
       else
 #endif
-	as_bad (_(".sframe not supported for target"));
+	/* Avoid erroring with DEFAULT_SFRAME for non-default options, like
+	   -32 on x86_64.  */
+	sframe_as_bad (_(".sframe not supported for target"));
     }
 
   if ((all_cfi_sections & CFI_EMIT_debug_frame) != 0)
diff --git a/gas/gen-sframe.h b/gas/gen-sframe.h
index e4a4c6ea0ce..8ad521b5cbe 100644
--- a/gas/gen-sframe.h
+++ b/gas/gen-sframe.h
@@ -21,6 +21,16 @@
 #ifndef GENSFRAME_H
 #define GENSFRAME_H
 
+/* Errors shouldn't be emitted either if SFrames are default-enabled, as
+   we interpret default-enabled as "opportunistic SFrames".  Users don't
+   want to be bothered by something preventing emission of SFrames in
+   such a case.  */
+#define sframe_as_bad(format, ...) \
+  do {					       \
+    if (flag_gen_sframe == GEN_SFRAME_ENABLED) \
+      as_bad (format, ##__VA_ARGS__);	       \
+  } while (0)
+
 #define SFRAME_FRE_ELEM_LOC_REG		0
 #define SFRAME_FRE_ELEM_LOC_STACK	1


More information about the Binutils-cvs mailing list