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.
This commit is contained in:
Sam James
2025-07-03 11:08:59 +01:00
parent 850a812601
commit b0653e3db9
7 changed files with 65 additions and 5 deletions

View File

@@ -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\

View 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

24
gas/configure vendored
View File

@@ -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

View 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

View 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

View 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)

View File

@@ -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