[PATCH] gas: fix silent failure of .cfi_sections .sframe on unsupported targets
Indu Bhagat
indu.bhagat@oracle.com
Tue Mar 10 06:07:26 GMT 2026
[Resending as I messed up one of the email in the to list in the
previous attempt].
Starting in Binutils 2.46, the .cfi_sections .sframe directive failed
silently when targeting unsupported architectures (e.g., i386 or even
x32 on x86_64). This happened because the sframe_as_bad macro only
checked for the command-line flag --gsframe (GEN_SFRAME_ENABLED) and
ignored the explicit request via the assembler directive
(CFI_EMIT_sframe).
This patch ensures that an error is emitted (for unsupported targets) if
SFrame is requested via either the command line or the .cfi_sections
directive, while maintaining silence for 'opportunistic' sframe
generation (GEN_SFRAME_CONFIG_ENABLED).
Add two testcases:
- cfi-sframe-x86_64-err-1.d: usage of --32 with .cfi_sections .sframe,
- cfi-sframe-x86_64-err-2.d: usage of --gsframe --32 without
.cfi_sections .sframe
GAS is expected to error out in both the cases.
This fixes PR gas/33962 - .cfi_sections directive with .sframe on
unsupported targets does not error.
gas/
PR gas/33962
* dw2gencfi.c (dot_cfi_sections): Ensure as_bad is called if
SFrame was explicitly requested via directive.
* gen-sframe.h: Remove sframe_as_bad macro.
gas/testsuite/
PR gas/33962
* gas/cfi-sframe/cfi-sframe-x86_64-err-1.s: New test.
* gas/cfi-sframe/cfi-sframe-x86_64-err-1.d: New test.
* gas/cfi-sframe/cfi-sframe-x86_64-err-2.s: New test.
* gas/cfi-sframe/cfi-sframe-x86_64-err-1.d: New test.
* gas/cfi-sframe/cfi-sframe.exp: Run the new tests.
---
gas/dw2gencfi.c | 15 ++++++++++++---
gas/gen-sframe.h | 10 ----------
.../gas/cfi-sframe/cfi-sframe-x86_64-err-1.d | 3 +++
.../gas/cfi-sframe/cfi-sframe-x86_64-err-1.s | 4 ++++
.../gas/cfi-sframe/cfi-sframe-x86_64-err-2.d | 3 +++
.../gas/cfi-sframe/cfi-sframe-x86_64-err-2.s | 3 +++
gas/testsuite/gas/cfi-sframe/cfi-sframe.exp | 2 ++
7 files changed, 27 insertions(+), 13 deletions(-)
create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-1.d
create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-1.s
create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-2.d
create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-2.s
diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c
index ee157636ef1..44ccd354f3d 100644
--- a/gas/dw2gencfi.c
+++ b/gas/dw2gencfi.c
@@ -2620,9 +2620,18 @@ cfi_finish (void)
}
else
#endif
- /* Avoid erroring with DEFAULT_SFRAME for non-default options, like
- -32 on x86_64. */
- sframe_as_bad ("%s", _(".sframe not supported for target"));
+ /* Issue an error for unsupported targets, like --32 on x86_64. Avoid
+ erroring when default-enabled at configure-time though, because we
+ interpret default-enabled as "opportunistic SFrames". Users don't
+ want to be bothered by something preventing emission of SFrames in
+ such a case. */
+ {
+ if (flag_gen_sframe == GEN_SFRAME_ENABLED
+ || ((all_cfi_sections & CFI_EMIT_sframe) != 0
+ && flag_gen_sframe != GEN_SFRAME_DISABLED
+ && flag_gen_sframe != GEN_SFRAME_CONFIG_ENABLED))
+ 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 1a1f887d508..1e4eea02c52 100644
--- a/gas/gen-sframe.h
+++ b/gas/gen-sframe.h
@@ -21,16 +21,6 @@
#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)
-
/* The entity is not tracked. */
#define SFRAME_FRE_ELEM_LOC_NONE 0
/* The location of the tracked entity is based on a register. May or may not
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-1.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-1.d
new file mode 100644
index 00000000000..9cef72fa48a
--- /dev/null
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-1.d
@@ -0,0 +1,3 @@
+#as: --32
+#name: .cfi_sections .sframe error check on i386
+#error: .sframe not supported for target
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-1.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-1.s
new file mode 100644
index 00000000000..f44e448a590
--- /dev/null
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-1.s
@@ -0,0 +1,4 @@
+ .cfi_sections .sframe
+ .cfi_startproc
+ .long 0
+ .cfi_endproc
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-2.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-2.d
new file mode 100644
index 00000000000..c490c3207dd
--- /dev/null
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-2.d
@@ -0,0 +1,3 @@
+#as: --32 --gsframe
+#name: --gsframe error check on i386
+#error: .sframe not supported for target
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-2.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-2.s
new file mode 100644
index 00000000000..3c8ebf77354
--- /dev/null
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-err-2.s
@@ -0,0 +1,3 @@
+ .cfi_startproc
+ .long 0
+ .cfi_endproc
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
index a73e5c84033..bb1358c09d8 100644
--- a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
@@ -61,6 +61,8 @@ if { ([istarget "x86_64-*-*"] || [istarget "aarch64*-*-*"]
if { [istarget "x86_64-*-*"] && [gas_sframe_check] } then {
if { [gas_x86_64_check] } then {
set ASFLAGS "$ASFLAGS --64"
+ run_dump_test "cfi-sframe-x86_64-err-1"
+ run_dump_test "cfi-sframe-x86_64-err-2"
run_dump_test "cfi-sframe-x86_64-1"
run_dump_test "cfi-sframe-x86_64-2"
run_dump_test "cfi-sframe-x86_64-3"
--
2.43.0
More information about the Binutils
mailing list