diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-09-04 22:15:18 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-09-04 22:15:25 +0200 |
| commit | 3697f01a3906815cbbbe8927f50045163976c1db (patch) | |
| tree | 8c380b2d24e707412a9c9eddd2773d327f880d5a | |
| parent | 9bbe812c3ccc5b26100e4fbd30b851c609e8a3a7 (diff) | |
| download | kernel-3697f01a3906815cbbbe8927f50045163976c1db.tar.xz kernel-3697f01a3906815cbbbe8927f50045163976c1db.zip | |
build: enable stack frame size diagnostics
It has been observed that certain call-chains are too large for a 4 KiB
kernel stack. While we have increased the stack on x86-64 to 8 KiB, it
seems desirable to enable diagnostics that warn us of large stack
frames.
This changeset introduces 3 new CMake configuration options, two of
which are considered internal:
TEACHOS_STACK_FRAME_LIMIT:
The size limit of in bytes we are willing to accepts for any given
stack frame. Defaults to "0", meaning the internal defaults are used
per build configuration.
TEACHOS_STACK_FRAME_LIMIT_DEBUG:
TEACHOS_STACK_FRAME_LIMIT_RELEASE:
!!internal!!
The default stack frame size limit in bytes, per configuration, if no
user specified stack frame size limit was defined at configure time.
| -rw-r--r-- | CMakeLists.txt | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 830da817..34738e18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,15 @@ option(TEACHOS_ENABLE_TEST_TSAN "Enable TSan for the test executable" OFF) set(ACPI_ENABLE_TEST_COVERAGE ${TEACHOS_ENABLE_TEST_COVERAGE}) set(KSTD_ENABLE_TEST_COVERAGE ${TEACHOS_ENABLE_TEST_COVERAGE}) +set(CACHE{TEACHOS_STACK_FRAME_LIMIT} + TYPE STRING + HELP "The maximum allowed stack frame size in bytes." + VALUE "0" +) + +set(CACHE{TEACHOS_STACK_FRAME_LIMIT_DEBUG} TYPE INTERNAL VALUE "3072") +set(CACHE{TEACHOS_STACK_FRAME_LIMIT_RELEASE} TYPE INTERNAL VALUE "1280") + #[============================================================================[ # Global Build System Configuration #]============================================================================] @@ -69,6 +78,27 @@ add_compile_options( "$<$<CXX_COMPILER_ID:GNU>:-pedantic-errors>" ) +if(NOT BUILD_TESTING) + if(TEACHOS_STACK_FRAME_LIMIT) + set(STACK_FRAME_LIMIT "${TEACHOS_STACK_FRAME_LIMIT}") + else() + set(STACK_FRAME_LIMIT "$<IF:$<CONFIG:Debug>,${TEACHOS_STACK_FRAME_LIMIT_DEBUG},${TEACHOS_STACK_FRAME_LIMIT_RELEASE}>") + endif() + + add_compile_options( + "$<$<CXX_COMPILER_ID:GNU>:-fstack-usage>" + "$<$<CXX_COMPILER_ID:GNU>:-Wframe-larger-than=${STACK_FRAME_LIMIT}>" + ) + + add_link_options( + "$<$<CXX_COMPILER_ID:GNU>:-fstack-usage>" + "$<$<CXX_COMPILER_ID:GNU>:-Wframe-larger-than=${STACK_FRAME_LIMIT}>" + "$<$<CXX_COMPILER_ID:GNU>:-Werror=frame-larger-than=${STACK_FRAME_LIMIT}>" + ) + + unset(STACK_FRAME_LIMIT) +endif() + #[============================================================================[ # Global Linting Configuration #]============================================================================] |
