Use the -Wa,--gsframe flags to build the code, so GAS will generate
a new .sframe section for the stack trace information.
Currently, the sframe format only supports arm64 and x86_64
architectures. Add this configuration on arm64 to enable sframe
unwinder in the future.
Signed-off-by: Weinan Liu <wnliu@google.com>
Signed-off-by: Dylan Hatch <dylanbhatch@google.com>
Reviewed-by: Prasanna Kumar T S M <ptsm@linux.microsoft.com>
---
Makefile | 8 ++++++++
arch/Kconfig | 6 ++++++
arch/arm64/Kconfig.debug | 10 ++++++++++
arch/arm64/kernel/vdso/Makefile | 2 +-
include/asm-generic/vmlinux.lds.h | 15 +++++++++++++++
5 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index b9c661913250..09972c71a3e8 100644
--- a/Makefile
+++ b/Makefile
@@ -1078,6 +1078,14 @@ endif
# Ensure compilers do not transform certain loops into calls to wcslen()
KBUILD_CFLAGS += -fno-builtin-wcslen
+# build with sframe table
+ifdef CONFIG_SFRAME_UNWIND_TABLE
+CC_FLAGS_SFRAME := -Wa,--gsframe
+KBUILD_CFLAGS += $(CC_FLAGS_SFRAME)
+KBUILD_AFLAGS += $(CC_FLAGS_SFRAME)
+export CC_FLAGS_SFRAME
+endif
+
# change __FILE__ to the relative path to the source directory
ifdef building_out_of_srctree
KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srcroot)/=)
diff --git a/arch/Kconfig b/arch/Kconfig
index d1b4ffd6e085..4362d2f49d91 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -1782,4 +1782,10 @@ config ARCH_WANTS_PRE_LINK_VMLINUX
config ARCH_HAS_CPU_ATTACK_VECTORS
bool
+config AS_SFRAME
+ def_bool $(as-instr,.cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc)
+
+config SFRAME_UNWIND_TABLE
+ bool
+
endmenu
diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
index 265c4461031f..d64bf58457de 100644
--- a/arch/arm64/Kconfig.debug
+++ b/arch/arm64/Kconfig.debug
@@ -20,4 +20,14 @@ config ARM64_RELOC_TEST
depends on m
tristate "Relocation testing module"
+config SFRAME_UNWINDER
+ bool "Sframe unwinder"
+ depends on AS_SFRAME
+ depends on 64BIT
+ select SFRAME_UNWIND_TABLE
+ help
+ This option enables the sframe (Simple Frame) unwinder for unwinding
+ kernel stack traces. It uses unwind table that is directly generated
+ by toolchain based on DWARF CFI information.
+
source "drivers/hwtracing/coresight/Kconfig"
diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile
index 7dec05dd33b7..c60ef921956f 100644
--- a/arch/arm64/kernel/vdso/Makefile
+++ b/arch/arm64/kernel/vdso/Makefile
@@ -38,7 +38,7 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \
$(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) \
$(GCC_PLUGINS_CFLAGS) \
- $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \
+ $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(CC_FLAGS_SFRAME) \
-Wmissing-prototypes -Wmissing-declarations
CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index ae2d2359b79e..4f486080e4fb 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -473,6 +473,8 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
*(.rodata1) \
} \
\
+ SFRAME \
+ \
/* PCI quirks */ \
.pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \
BOUNDED_SECTION_PRE_LABEL(.pci_fixup_early, _pci_fixups_early, __start, __end) \
@@ -891,6 +893,19 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
#define TRACEDATA
#endif
+#ifdef CONFIG_SFRAME_UNWIND_TABLE
+#define SFRAME \
+ /* sframe */ \
+ .sframe : AT(ADDR(.sframe) - LOAD_OFFSET) { \
+ __start_sframe_header = .; \
+ KEEP(*(.sframe)) \
+ KEEP(*(.init.sframe)) \
+ __stop_sframe_header = .; \
+ }
+#else
+#define SFRAME
+#endif
+
#ifdef CONFIG_PRINTK_INDEX
#define PRINTK_INDEX \
.printk_index : AT(ADDR(.printk_index) - LOAD_OFFSET) { \
--
2.51.0.355.g5224444f11-goog
Hello Dylan! On 9/5/2025 12:38 AM, Dylan Hatch wrote: > Use the -Wa,--gsframe flags to build the code, so GAS will generate > a new .sframe section for the stack trace information. > Currently, the sframe format only supports arm64 and x86_64 > architectures. Add this configuration on arm64 to enable sframe > unwinder in the future. > > Signed-off-by: Weinan Liu <wnliu@google.com> > Signed-off-by: Dylan Hatch <dylanbhatch@google.com> > Reviewed-by: Prasanna Kumar T S M <ptsm@linux.microsoft.com> > diff --git a/arch/Kconfig b/arch/Kconfig > @@ -1782,4 +1782,10 @@ config ARCH_WANTS_PRE_LINK_VMLINUX > config ARCH_HAS_CPU_ATTACK_VECTORS > bool > > +config AS_SFRAME > + def_bool $(as-instr,.cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc) As you will soon be requiring SFrame V2 with the new PC-relative FDE function start address encoding you may want to extend this check as follows: config AS_SFRAME def_bool y depends on $(as-instr,.cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc) depends on $(success,printf "%b\n" ".cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc" | $(CC) $(CLANG_FLAGS) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o "$$TMP" - && $(OBJDUMP) --sframe "$$TMP" | grep -q "SFRAME_VERSION_2") depends on $(success,printf "%b\n" ".cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc" | $(CC) $(CLANG_FLAGS) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o "$$TMP" - && $(OBJDUMP) --sframe "$$TMP" | grep -q "SFRAME_F_FDE_FUNC_START_PCREL") Or you could change it into multiple config options, which might be overkill: config AS_SFRAME def_bool $(as-instr,.cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc) config AS_SFRAME_V2 def_bool y depends on AS_SFRAME depends on $(success,printf "%b\n" ".cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc" | $(CC) $(CLANG_FLAGS) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o "$$TMP" - && $(OBJDUMP) --sframe "$$TMP" | grep -q "SFRAME_VERSION_2") config AS_SFRAME_V2_PCREL_FDE def_bool y depends on AS_SFRAME_V2 depends on $(success,printf "%b\n" ".cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc" | $(CC) $(CLANG_FLAGS) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o "$$TMP" - && $(OBJDUMP) --sframe "$$TMP" | grep -q "SFRAME_F_FDE_FUNC_START_PCREL") > + > +config SFRAME_UNWIND_TABLE > + bool > + > endmenu Regards, Jens -- Jens Remus Linux on Z Development (D3303) +49-7031-16-1128 Office jremus@de.ibm.com IBM IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Böblingen; Registergericht: Amtsgericht Stuttgart, HRB 243294 IBM Data Privacy Statement: https://www.ibm.com/privacy/
On Thu, Sep 04, 2025 at 10:38:45PM +0000, Dylan Hatch wrote: > Use the -Wa,--gsframe flags to build the code, so GAS will generate > a new .sframe section for the stack trace information. > Currently, the sframe format only supports arm64 and x86_64 > architectures. Add this configuration on arm64 to enable sframe > unwinder in the future. > > Signed-off-by: Weinan Liu <wnliu@google.com> > Signed-off-by: Dylan Hatch <dylanbhatch@google.com> > Reviewed-by: Prasanna Kumar T S M <ptsm@linux.microsoft.com> > --- > Makefile | 8 ++++++++ > arch/Kconfig | 6 ++++++ > arch/arm64/Kconfig.debug | 10 ++++++++++ > arch/arm64/kernel/vdso/Makefile | 2 +- > include/asm-generic/vmlinux.lds.h | 15 +++++++++++++++ > 5 files changed, 40 insertions(+), 1 deletion(-) > > diff --git a/Makefile b/Makefile > index b9c661913250..09972c71a3e8 100644 > --- a/Makefile > +++ b/Makefile > @@ -1078,6 +1078,14 @@ endif > # Ensure compilers do not transform certain loops into calls to wcslen() > KBUILD_CFLAGS += -fno-builtin-wcslen > > +# build with sframe table > +ifdef CONFIG_SFRAME_UNWIND_TABLE > +CC_FLAGS_SFRAME := -Wa,--gsframe > +KBUILD_CFLAGS += $(CC_FLAGS_SFRAME) > +KBUILD_AFLAGS += $(CC_FLAGS_SFRAME) > +export CC_FLAGS_SFRAME > +endif > + > # change __FILE__ to the relative path to the source directory > ifdef building_out_of_srctree > KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srcroot)/=) > diff --git a/arch/Kconfig b/arch/Kconfig > index d1b4ffd6e085..4362d2f49d91 100644 > --- a/arch/Kconfig > +++ b/arch/Kconfig > @@ -1782,4 +1782,10 @@ config ARCH_WANTS_PRE_LINK_VMLINUX > config ARCH_HAS_CPU_ATTACK_VECTORS > bool > > +config AS_SFRAME > + def_bool $(as-instr,.cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc) Is it possible to extend this check so that we reject assemblers that emit the unsupported "sframe version one" format? > +config SFRAME_UNWIND_TABLE > + bool Is this extra option actually needed for anything? > endmenu > diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug > index 265c4461031f..d64bf58457de 100644 > --- a/arch/arm64/Kconfig.debug > +++ b/arch/arm64/Kconfig.debug > @@ -20,4 +20,14 @@ config ARM64_RELOC_TEST > depends on m > tristate "Relocation testing module" > > +config SFRAME_UNWINDER > + bool "Sframe unwinder" > + depends on AS_SFRAME > + depends on 64BIT Shouldn't there be an arch dependency here as well? Since architectures need to make use of sframe in their unwinders, I was expecting something like 'depends on ARCH_SUPPORTS_SFRAME_UNWINDER' here. Will
© 2016 - 2026 Red Hat, Inc.