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