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>
---
Makefile | 6 ++++++
arch/Kconfig | 8 ++++++++
arch/arm64/Kconfig.debug | 10 ++++++++++
include/asm-generic/vmlinux.lds.h | 12 ++++++++++++
4 files changed, 36 insertions(+)
diff --git a/Makefile b/Makefile
index b9464c88ac72..35200c39b98d 100644
--- a/Makefile
+++ b/Makefile
@@ -1064,6 +1064,12 @@ ifdef CONFIG_CC_IS_GCC
KBUILD_CFLAGS += -fconserve-stack
endif
+# build with sframe table
+ifdef CONFIG_SFRAME_UNWIND_TABLE
+KBUILD_CFLAGS += -Wa,--gsframe
+KBUILD_AFLAGS += -Wa,--gsframe
+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 6682b2a53e34..ae70f7dbe326 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -1736,4 +1736,12 @@ config ARCH_WANTS_PRE_LINK_VMLINUX
An architecture can select this if it provides arch/<arch>/tools/Makefile
with .arch.vmlinux.o target to be linked into vmlinux.
+config AS_HAS_SFRAME_SUPPORT
+ # Detect availability of the AS option -Wa,--gsframe for generating
+ # sframe unwind table.
+ def_bool $(cc-option,-Wa$(comma)--gsframe)
+
+config SFRAME_UNWIND_TABLE
+ bool
+
endmenu
diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
index 265c4461031f..ed619fcb18b3 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_HAS_SFRAME_SUPPORT
+ 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 direclty generated
+ by toolchain based on DWARF CFI information
+
source "drivers/hwtracing/coresight/Kconfig"
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 54504013c749..6a437bd084c7 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -469,6 +469,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) \
@@ -886,6 +888,16 @@ 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) { \
+ BOUNDED_SECTION_BY(.sframe, _sframe_header) \
+ }
+#else
+#define SFRAME
+#endif
+
#ifdef CONFIG_PRINTK_INDEX
#define PRINTK_INDEX \
.printk_index : AT(ADDR(.printk_index) - LOAD_OFFSET) { \
--
2.48.1.262.g85cc9f2d1e-goog
On 1/27/25 1:33 PM, Weinan Liu 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>
> ---
> Makefile | 6 ++++++
> arch/Kconfig | 8 ++++++++
> arch/arm64/Kconfig.debug | 10 ++++++++++
> include/asm-generic/vmlinux.lds.h | 12 ++++++++++++
> 4 files changed, 36 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index b9464c88ac72..35200c39b98d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1064,6 +1064,12 @@ ifdef CONFIG_CC_IS_GCC
> KBUILD_CFLAGS += -fconserve-stack
> endif
>
> +# build with sframe table
> +ifdef CONFIG_SFRAME_UNWIND_TABLE
> +KBUILD_CFLAGS += -Wa,--gsframe
> +KBUILD_AFLAGS += -Wa,--gsframe
> +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 6682b2a53e34..ae70f7dbe326 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -1736,4 +1736,12 @@ config ARCH_WANTS_PRE_LINK_VMLINUX
> An architecture can select this if it provides arch/<arch>/tools/Makefile
> with .arch.vmlinux.o target to be linked into vmlinux.
>
> +config AS_HAS_SFRAME_SUPPORT
> + # Detect availability of the AS option -Wa,--gsframe for generating
> + # sframe unwind table.
> + def_bool $(cc-option,-Wa$(comma)--gsframe)
> +
Since the version of an admissible SFrame section needs to be atleast
SFRAME_VERSION_2, it will make sense to include SFrame version check
when detecting compatible toolchain.
> +config SFRAME_UNWIND_TABLE
> + bool
> +
> endmenu
> diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
> index 265c4461031f..ed619fcb18b3 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_HAS_SFRAME_SUPPORT
> + 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 direclty generated
> + by toolchain based on DWARF CFI information
> +
> source "drivers/hwtracing/coresight/Kconfig"
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index 54504013c749..6a437bd084c7 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -469,6 +469,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) \
> @@ -886,6 +888,16 @@ 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) { \
> + BOUNDED_SECTION_BY(.sframe, _sframe_header) \
> + }
> +#else
> +#define SFRAME
> +#endif
> +
> #ifdef CONFIG_PRINTK_INDEX
> #define PRINTK_INDEX \
> .printk_index : AT(ADDR(.printk_index) - LOAD_OFFSET) { \
On Tue, Feb 04, 2025 at 04:22:27PM -0800, Indu Bhagat wrote: > > +++ b/arch/Kconfig > > @@ -1736,4 +1736,12 @@ config ARCH_WANTS_PRE_LINK_VMLINUX > > An architecture can select this if it provides arch/<arch>/tools/Makefile > > with .arch.vmlinux.o target to be linked into vmlinux. > > +config AS_HAS_SFRAME_SUPPORT > > + # Detect availability of the AS option -Wa,--gsframe for generating > > + # sframe unwind table. > > + def_bool $(cc-option,-Wa$(comma)--gsframe) > > + > > Since the version of an admissible SFrame section needs to be atleast > SFRAME_VERSION_2, it will make sense to include SFrame version check when > detecting compatible toolchain. Also, Jens pointed out that checking for '-Wa,--gsframe' isn't sufficient, as it still succeeds for architectures that aren't yet supported: https://lore.kernel.org/b89bcb68-d010-4041-aacf-15b934675705@linux.ibm.com so in my patches I have: config AS_SFRAME def_bool $(as-instr,.cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc) Though I'm not sure how you would add an SFrame version check to that. -- Josh
On 28-01-2025 03:03, Weinan Liu 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>
> ---
> Makefile | 6 ++++++
> arch/Kconfig | 8 ++++++++
> arch/arm64/Kconfig.debug | 10 ++++++++++
> include/asm-generic/vmlinux.lds.h | 12 ++++++++++++
> 4 files changed, 36 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index b9464c88ac72..35200c39b98d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1064,6 +1064,12 @@ ifdef CONFIG_CC_IS_GCC
> KBUILD_CFLAGS += -fconserve-stack
> endif
>
> +# build with sframe table
> +ifdef CONFIG_SFRAME_UNWIND_TABLE
> +KBUILD_CFLAGS += -Wa,--gsframe
> +KBUILD_AFLAGS += -Wa,--gsframe
> +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 6682b2a53e34..ae70f7dbe326 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -1736,4 +1736,12 @@ config ARCH_WANTS_PRE_LINK_VMLINUX
> An architecture can select this if it provides arch/<arch>/tools/Makefile
> with .arch.vmlinux.o target to be linked into vmlinux.
>
> +config AS_HAS_SFRAME_SUPPORT
> + # Detect availability of the AS option -Wa,--gsframe for generating
> + # sframe unwind table.
> + def_bool $(cc-option,-Wa$(comma)--gsframe)
> +
> +config SFRAME_UNWIND_TABLE
> + bool
> +
> endmenu
> diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
> index 265c4461031f..ed619fcb18b3 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_HAS_SFRAME_SUPPORT
> + 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 direclty generated
> + by toolchain based on DWARF CFI information
> +
> source "drivers/hwtracing/coresight/Kconfig"
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index 54504013c749..6a437bd084c7 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -469,6 +469,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) \
> @@ -886,6 +888,16 @@ 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) { \
> + BOUNDED_SECTION_BY(.sframe, _sframe_header) \
> + }
> +#else
> +#define SFRAME
> +#endif
> +
> #ifdef CONFIG_PRINTK_INDEX
> #define PRINTK_INDEX \
> .printk_index : AT(ADDR(.printk_index) - LOAD_OFFSET) { \
Looks good to me.
Reviewed-by: Prasanna Kumar T S M <ptsm@linux.microsoft.com>.
© 2016 - 2025 Red Hat, Inc.