From 88f3bc77f1f6a3cc2526649f21b836c0a3f6d52e Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Tue, 15 Aug 2023 17:16:01 +0800 Subject: [PATCH] toolchain: detect use of large stack variables partition/fs_gpt.c:384:5: warning: stack usage might be 288 bytes [-Wstack-usage=] 384 | int parse_gpt_partition(FAR struct partition_state_s *state, Signed-off-by: yinshengkai --- Kconfig | 7 +++++++ arch/arm/src/common/Toolchain.defs | 4 ++++ arch/risc-v/src/common/Toolchain.defs | 4 ++++ arch/sim/src/cmake/Toolchain.cmake | 4 ++++ arch/xtensa/src/lx6/Toolchain.defs | 4 ++++ arch/xtensa/src/lx7/Toolchain.defs | 4 ++++ boards/sim/sim/sim/scripts/Make.defs | 4 ++++ 7 files changed, 31 insertions(+) diff --git a/Kconfig b/Kconfig index abd0d4e512..d15089d603 100644 --- a/Kconfig +++ b/Kconfig @@ -2073,6 +2073,13 @@ config STACK_USAGE on a per-function basis. Please use https://github.com/HBehrens/puncover or tools/showstack.sh to generate the more useful report. +config STACK_USAGE_WARNING + int "Detect use of large stack variables" + default 0 + help + Set the stack warning threshold, if the stack usage exceeds the + threshold, a warning will be generated + config ARCH_HAVE_HEAPCHECK bool default n diff --git a/arch/arm/src/common/Toolchain.defs b/arch/arm/src/common/Toolchain.defs index 98868391fd..618ed630ff 100644 --- a/arch/arm/src/common/Toolchain.defs +++ b/arch/arm/src/common/Toolchain.defs @@ -58,6 +58,10 @@ ifeq ($(CONFIG_STACK_USAGE),y) ARCHOPTIMIZATION += -fstack-usage endif +ifneq ($(CONFIG_STACK_USAGE_WARNING),0) + ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING) +endif + ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y) ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage endif diff --git a/arch/risc-v/src/common/Toolchain.defs b/arch/risc-v/src/common/Toolchain.defs index 0bb6e3e055..0f0270b347 100644 --- a/arch/risc-v/src/common/Toolchain.defs +++ b/arch/risc-v/src/common/Toolchain.defs @@ -69,6 +69,10 @@ ifeq ($(CONFIG_STACK_USAGE),y) ARCHOPTIMIZATION += -fstack-usage endif +ifneq ($(CONFIG_STACK_USAGE_WARNING),0) + ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING) +endif + ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y) ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage endif diff --git a/arch/sim/src/cmake/Toolchain.cmake b/arch/sim/src/cmake/Toolchain.cmake index 14cff55a6f..1b91a918be 100644 --- a/arch/sim/src/cmake/Toolchain.cmake +++ b/arch/sim/src/cmake/Toolchain.cmake @@ -65,6 +65,10 @@ if(CONFIG_STACK_USAGE) add_compile_options(-fstack-usage) endif() +if(CONFIG_STACK_USAGE_WARNING) + add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING}) +endif() + if(CONFIG_ARCH_COVERAGE) add_compile_options(-fprofile-generate -ftest-coverage) endif() diff --git a/arch/xtensa/src/lx6/Toolchain.defs b/arch/xtensa/src/lx6/Toolchain.defs index c2ebf14b39..e1258773da 100644 --- a/arch/xtensa/src/lx6/Toolchain.defs +++ b/arch/xtensa/src/lx6/Toolchain.defs @@ -79,6 +79,10 @@ ifeq ($(CONFIG_STACK_USAGE),y) ARCHOPTIMIZATION += -fstack-usage endif +ifneq ($(CONFIG_STACK_USAGE_WARNING),0) + ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING) +endif + ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y) ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage endif diff --git a/arch/xtensa/src/lx7/Toolchain.defs b/arch/xtensa/src/lx7/Toolchain.defs index 7dd3a23630..0f9bef98c5 100644 --- a/arch/xtensa/src/lx7/Toolchain.defs +++ b/arch/xtensa/src/lx7/Toolchain.defs @@ -79,6 +79,10 @@ ifeq ($(CONFIG_STACK_USAGE),y) ARCHOPTIMIZATION += -fstack-usage endif +ifneq ($(CONFIG_STACK_USAGE_WARNING),0) + ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING) +endif + ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y) ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage endif diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs index 8e7149d213..7ade925e10 100644 --- a/boards/sim/sim/sim/scripts/Make.defs +++ b/boards/sim/sim/sim/scripts/Make.defs @@ -68,6 +68,10 @@ ifeq ($(CONFIG_STACK_USAGE),y) ARCHOPTIMIZATION += -fstack-usage endif +ifneq ($(CONFIG_STACK_USAGE_WARNING),0) + ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING) +endif + ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y) ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage endif