From c87dc641bcdead4711bfb7e860e9accae4d35445 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Mon, 13 May 2024 13:12:12 +0800 Subject: [PATCH] arch: generalize frame pointer via CONFIG_FRAME_POINTER introduction Enabling `CONFIG_FRAME_POINTER` allows the users to build the kernel with frame-pointer. Signed-off-by: Yong Cong Sin --- arch/Kconfig | 7 +++++++ arch/arm64/core/CMakeLists.txt | 2 +- arch/arm64/core/Kconfig | 4 +++- arch/arm64/core/fatal.c | 6 +++--- arch/arm64/core/offsets/offsets.c | 2 +- arch/arm64/core/vector_table.S | 4 ++-- arch/riscv/Kconfig | 9 --------- arch/riscv/core/stacktrace.c | 8 ++++---- doc/releases/migration-guide-3.7.rst | 3 +++ include/zephyr/arch/arm64/exception.h | 2 +- subsys/debug/Kconfig | 1 + tests/arch/common/stack_unwind/enable_fp.conf | 2 -- tests/arch/common/stack_unwind/testcase.yaml | 9 ++++++--- 13 files changed, 32 insertions(+), 27 deletions(-) delete mode 100644 tests/arch/common/stack_unwind/enable_fp.conf diff --git a/arch/Kconfig b/arch/Kconfig index b9e40d8ec20..f3e4f14dfbc 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -398,6 +398,13 @@ config NOCACHE_MEMORY transfers when cache coherence issues are not optimal or can not be solved using cache maintenance operations. +config FRAME_POINTER + bool "Compile the kernel with frame pointers" + select OVERRIDE_FRAME_POINTER_DEFAULT + help + Select Y here to gain precise stack traces at the expense of slightly + increased size and decreased speed. + menu "Interrupt Configuration" config ISR_TABLES_LOCAL_DECLARATION_SUPPORTED diff --git a/arch/arm64/core/CMakeLists.txt b/arch/arm64/core/CMakeLists.txt index 05e4be8c0ea..09822dfae47 100644 --- a/arch/arm64/core/CMakeLists.txt +++ b/arch/arm64/core/CMakeLists.txt @@ -43,7 +43,7 @@ if ((CONFIG_MP_MAX_NUM_CPUS GREATER 1) OR (CONFIG_SMP)) endif () zephyr_cc_option_ifdef(CONFIG_USERSPACE -mno-outline-atomics) -zephyr_cc_option_ifdef(CONFIG_ARM64_ENABLE_FRAME_POINTER -mno-omit-leaf-frame-pointer) +zephyr_cc_option_ifdef(CONFIG_FRAME_POINTER -mno-omit-leaf-frame-pointer) # GCC may generate ldp/stp instructions with the Advanced SIMD Qn registers for # consecutive 32-byte loads and stores. Saving and restoring the Advanced SIMD diff --git a/arch/arm64/core/Kconfig b/arch/arm64/core/Kconfig index 8f09d49a04c..7cca2f7045f 100644 --- a/arch/arm64/core/Kconfig +++ b/arch/arm64/core/Kconfig @@ -145,9 +145,11 @@ config ARM64_SAFE_EXCEPTION_STACK config ARM64_ENABLE_FRAME_POINTER bool - default y depends on OVERRIDE_FRAME_POINTER_DEFAULT && !OMIT_FRAME_POINTER + depends on !FRAME_POINTER + select DEPRECATED help + Deprecated. Use CONFIG_FRAME_POINTER instead. Hidden option to simplify access to OVERRIDE_FRAME_POINTER_DEFAULT and OMIT_FRAME_POINTER. It is automatically enabled when the frame pointer unwinding is enabled. diff --git a/arch/arm64/core/fatal.c b/arch/arm64/core/fatal.c index 92ef0d8a3da..86a07632c5a 100644 --- a/arch/arm64/core/fatal.c +++ b/arch/arm64/core/fatal.c @@ -195,7 +195,7 @@ static void esf_dump(const z_arch_esf_t *esf) LOG_ERR("x18: 0x%016llx lr: 0x%016llx", esf->x18, esf->lr); } -#ifdef CONFIG_ARM64_ENABLE_FRAME_POINTER +#ifdef CONFIG_FRAME_POINTER static void esf_unwind(const z_arch_esf_t *esf) { /* @@ -363,9 +363,9 @@ void z_arm64_fatal_error(unsigned int reason, z_arch_esf_t *esf) esf_dump(esf); } -#ifdef CONFIG_ARM64_ENABLE_FRAME_POINTER +#ifdef CONFIG_FRAME_POINTER esf_unwind(esf); -#endif /* CONFIG_ARM64_ENABLE_FRAME_POINTER */ +#endif /* CONFIG_FRAME_POINTER */ #endif /* CONFIG_EXCEPTION_DEBUG */ z_fatal_error(reason, esf); diff --git a/arch/arm64/core/offsets/offsets.c b/arch/arm64/core/offsets/offsets.c index 4268692c498..772f0df3a8d 100644 --- a/arch/arm64/core/offsets/offsets.c +++ b/arch/arm64/core/offsets/offsets.c @@ -40,7 +40,7 @@ GEN_NAMED_OFFSET_SYM(_callee_saved_t, x27, x27_x28); GEN_NAMED_OFFSET_SYM(_callee_saved_t, x29, x29_sp_el0); GEN_NAMED_OFFSET_SYM(_callee_saved_t, sp_elx, sp_elx_lr); -#ifdef CONFIG_ARM64_ENABLE_FRAME_POINTER +#ifdef CONFIG_FRAME_POINTER GEN_NAMED_OFFSET_SYM(_esf_t, fp, fp); #endif diff --git a/arch/arm64/core/vector_table.S b/arch/arm64/core/vector_table.S index 499dbd292a5..632304b7029 100644 --- a/arch/arm64/core/vector_table.S +++ b/arch/arm64/core/vector_table.S @@ -72,7 +72,7 @@ _ASM_FILE_PROLOGUE .endif #endif -#ifdef CONFIG_ARM64_ENABLE_FRAME_POINTER +#ifdef CONFIG_FRAME_POINTER str x29, [sp, ___esf_t_fp_OFFSET] #endif @@ -339,7 +339,7 @@ SECTION_FUNC(TEXT, z_arm64_exit_exc) ldp x16, x17, [sp, ___esf_t_x16_x17_OFFSET] ldp x18, lr, [sp, ___esf_t_x18_lr_OFFSET] -#ifdef CONFIG_ARM64_ENABLE_FRAME_POINTER +#ifdef CONFIG_FRAME_POINTER ldr x29, [sp, ___esf_t_fp_OFFSET] #endif diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 1c4d547b29c..4d964905e42 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -38,15 +38,6 @@ config RISCV_ALWAYS_SWITCH_THROUGH_ECALL and most people should say n here to minimize context switching overhead. -config RISCV_ENABLE_FRAME_POINTER - bool - default y - depends on OVERRIDE_FRAME_POINTER_DEFAULT && !OMIT_FRAME_POINTER - help - Hidden option to simplify access to OVERRIDE_FRAME_POINTER_DEFAULT - and OMIT_FRAME_POINTER. It is automatically enabled when the frame - pointer unwinding is enabled. - config RISCV_EXCEPTION_STACK_TRACE bool default y diff --git a/arch/riscv/core/stacktrace.c b/arch/riscv/core/stacktrace.c index bc0063b3887..7dbcd8067cc 100644 --- a/arch/riscv/core/stacktrace.c +++ b/arch/riscv/core/stacktrace.c @@ -27,7 +27,7 @@ struct stackframe { uintptr_t ra; }; -#ifdef CONFIG_RISCV_ENABLE_FRAME_POINTER +#ifdef CONFIG_FRAME_POINTER #define SFP_FMT "fp: " #else #define SFP_FMT "sp: " @@ -85,7 +85,7 @@ static inline bool in_text_region(uintptr_t addr) return (addr >= (uintptr_t)&__text_region_start) && (addr < (uintptr_t)&__text_region_end); } -#ifdef CONFIG_RISCV_ENABLE_FRAME_POINTER +#ifdef CONFIG_FRAME_POINTER void z_riscv_unwind_stack(const z_arch_esf_t *esf) { uintptr_t fp = esf->s0; @@ -114,7 +114,7 @@ void z_riscv_unwind_stack(const z_arch_esf_t *esf) LOG_ERR(""); } -#else /* !CONFIG_RISCV_ENABLE_FRAME_POINTER */ +#else /* !CONFIG_FRAME_POINTER */ void z_riscv_unwind_stack(const z_arch_esf_t *esf) { uintptr_t sp = z_riscv_get_sp_before_exc(esf); @@ -143,4 +143,4 @@ void z_riscv_unwind_stack(const z_arch_esf_t *esf) LOG_ERR(""); } -#endif /* CONFIG_RISCV_ENABLE_FRAME_POINTER */ +#endif /* CONFIG_FRAME_POINTER */ diff --git a/doc/releases/migration-guide-3.7.rst b/doc/releases/migration-guide-3.7.rst index 079c3645bf5..2ef092224bf 100644 --- a/doc/releases/migration-guide-3.7.rst +++ b/doc/releases/migration-guide-3.7.rst @@ -598,6 +598,9 @@ Architectures * Function :c:func:`arch_start_cpu` has been renamed to :c:func:`arch_cpu_start`. (:github:`64987`) +* ``CONFIG_ARM64_ENABLE_FRAME_POINTER`` is deprecated. Use :kconfig:option:`CONFIG_FRAME_POINTER` + instead. (:github:`72646`) + * x86 * Kconfigs ``CONFIG_DISABLE_SSBD`` and ``CONFIG_ENABLE_EXTENDED_IBRS`` diff --git a/include/zephyr/arch/arm64/exception.h b/include/zephyr/arch/arm64/exception.h index 4ccdc41f19c..05257c087fe 100644 --- a/include/zephyr/arch/arm64/exception.h +++ b/include/zephyr/arch/arm64/exception.h @@ -47,7 +47,7 @@ struct __esf { uint64_t lr; uint64_t spsr; uint64_t elr; -#ifdef CONFIG_ARM64_ENABLE_FRAME_POINTER +#ifdef CONFIG_FRAME_POINTER uint64_t fp; #endif #ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK diff --git a/subsys/debug/Kconfig b/subsys/debug/Kconfig index 00243f49be9..cd9303262eb 100644 --- a/subsys/debug/Kconfig +++ b/subsys/debug/Kconfig @@ -345,6 +345,7 @@ config OVERRIDE_FRAME_POINTER_DEFAULT config OMIT_FRAME_POINTER bool "Omit frame pointer" + depends on !FRAME_POINTER depends on OVERRIDE_FRAME_POINTER_DEFAULT help Choose Y for best performance. On some architectures (including x86) diff --git a/tests/arch/common/stack_unwind/enable_fp.conf b/tests/arch/common/stack_unwind/enable_fp.conf deleted file mode 100644 index 5348bd11370..00000000000 --- a/tests/arch/common/stack_unwind/enable_fp.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT=y -CONFIG_OMIT_FRAME_POINTER=n diff --git a/tests/arch/common/stack_unwind/testcase.yaml b/tests/arch/common/stack_unwind/testcase.yaml index f57e8b41048..41c7f95ab8f 100644 --- a/tests/arch/common/stack_unwind/testcase.yaml +++ b/tests/arch/common/stack_unwind/testcase.yaml @@ -9,7 +9,8 @@ tests: integration_platforms: - qemu_riscv32 - qemu_riscv64 - extra_args: OVERLAY_CONFIG="enable_fp.conf" + extra_configs: + - CONFIG_FRAME_POINTER=y harness_config: type: multi_line regex: @@ -44,7 +45,8 @@ tests: - arm64 integration_platforms: - qemu_cortex_a53 - extra_args: OVERLAY_CONFIG="enable_fp.conf" + extra_configs: + - CONFIG_FRAME_POINTER=y harness_config: type: multi_line regex: @@ -58,7 +60,8 @@ tests: - qemu_riscv32 - qemu_riscv64 - qemu_cortex_a53 - extra_args: OVERLAY_CONFIG="enable_fp.conf" + extra_configs: + - CONFIG_FRAME_POINTER=y harness_config: type: multi_line regex: