From 4d16f46a88012e4df8f897d782a5e7c03b0248b0 Mon Sep 17 00:00:00 2001 From: Guillaume Souchere Date: Tue, 6 Dec 2022 09:23:52 +0100 Subject: [PATCH] esp_system: fix placement of __stack_chk_fail from flash to RAM When stack check is enabled, certain functions (sometimes placed in RAM) are being decorated with stack guards and a call to __stask_chk_fail() in case ofr stack corruption. For this reason, __stack_chk_fail() must be placed in RAM too. Add stack check config in heap tests on all targets to find eventual flash to RAM calls due to stack checks when running callgraph_check.py --- components/esp_system/stack_check.c | 5 ++--- components/heap/test_apps/sdkconfig.defaults | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/esp_system/stack_check.c b/components/esp_system/stack_check.c index f7ae331393..89de27b3d8 100644 --- a/components/esp_system/stack_check.c +++ b/components/esp_system/stack_check.c @@ -23,10 +23,9 @@ __esp_stack_guard_setup (void) __stack_chk_guard = (void *)esp_random(); } -void __stack_chk_fail (void) +IRAM_ATTR void __stack_chk_fail (void) { - esp_rom_printf("\r\nStack smashing protect failure!\r\n\r\n"); - abort(); + esp_system_abort(DRAM_STR("Stack smashing protect failure!")); } #endif diff --git a/components/heap/test_apps/sdkconfig.defaults b/components/heap/test_apps/sdkconfig.defaults index 2fbcda0f36..bbd0363cd0 100644 --- a/components/heap/test_apps/sdkconfig.defaults +++ b/components/heap/test_apps/sdkconfig.defaults @@ -1,3 +1,6 @@ CONFIG_COMPILER_DUMP_RTL_FILES=y CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=n # memory protection needs to be disabled for certain tests + +CONFIG_COMPILER_STACK_CHECK_MODE_ALL=y +CONFIG_COMPILER_STACK_CHECK=y