]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: add --enable-default-sframe configure option
authorSam James <sam@gentoo.org>
Thu, 3 Jul 2025 10:08:59 +0000 (11:08 +0100)
committerSam James <sam@gentoo.org>
Sat, 23 Aug 2025 02:04:35 +0000 (03:04 +0100)
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.

gas/as.c
gas/config.in
gas/configure
gas/configure.ac
gas/doc/as.texi
gas/dw2gencfi.c
gas/gen-sframe.h

index 58ed0a59e21c79b7de890be23cf19528cbb7ea9d..efcc80deef17dce1e26de33a6c25009de7f1625b 100644 (file)
--- 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\
index bb896244640414c081f10a9cb959a68c19e3b489..ba042ca44eb4e82f7826d0aa21bee2217e3a1b55 100644 (file)
@@ -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
 
index 97340444b725e31559df62f4bcb9f191252cb659..12d96a5acd2249a92bf255990701c961cebb099d 100755 (executable)
@@ -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
index c65797fdf0afb16b32b46407d2bb54edb2947df5..78fe021bafd9510362d1b106a2fd5b5f875f989c 100644 (file)
@@ -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
index 2db5f4896ee76b3de5df0db2d72f3a2893128a51..28fb6a6a97b2e188f1b8e136cc50386d3cefe094 100644 (file)
@@ -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
 
index c28856cdf2406facc31144acf0deb63d865054f8..186dfa667c8b1a61233f24a0baa32b23653f791b 100644 (file)
@@ -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)
index e4a4c6ea0ceb4104aae280f6f7fd42a60fca688b..8ad521b5cbee2e4d22ec0fffd176dfd51348f6ca 100644 (file)
 #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