Merge branch 'feature/add_kasan_support' into 'master'

feat(kasan): add Kernel Address Sanitizer (KASAN) support for ESP-IDF

Closes IDF-13467

See merge request espressif/esp-idf!48106
This commit is contained in:
Meet Patel
2026-06-25 11:30:48 +05:30
25 changed files with 1856 additions and 49 deletions
+12 -9
View File
@@ -401,6 +401,18 @@ void IRAM_ATTR do_multicore_settings(void)
FORCE_INLINE_ATTR IRAM_ATTR void init_cpu(void)
{
#ifdef __riscv
// Configure the global pointer register.
// This must be the first thing the IDF app does on RISC-V, as any other
// piece of code could be relaxed by the linker to access something relative
// to __global_pointer$. With KASAN enabled, even calls like
// esp_cpu_dbgr_is_attached() are instrumented and may emit gp-relative
// loads, so gp must be set up before any C function call.
__asm__ __volatile__(
".option push\n"
".option norelax\n"
"la gp, __global_pointer$\n"
".option pop"
);
if (esp_cpu_dbgr_is_attached()) {
/* Let debugger some time to detect that target started, halt it, enable ebreaks and resume.
500ms should be enough. */
@@ -408,15 +420,6 @@ FORCE_INLINE_ATTR IRAM_ATTR void init_cpu(void)
esp_rom_delay_us(100000);
}
}
// Configure the global pointer register
// (This should be the first thing IDF app does, as any other piece of code could be
// relaxed by the linker to access something relative to __global_pointer$)
__asm__ __volatile__(
".option push\n"
".option norelax\n"
"la gp, __global_pointer$\n"
".option pop"
);
#endif
/* NOTE: When ESP-TEE is enabled, this sets up the callback function