Skip to content

Commit 1be95c3

Browse files
anchaopkarashchenko
authored andcommitted
sim/lsan: disable fast-unwind by default
The fast-unwind implementation of leak-sanitizer will obtain the current stack top/bottom and frame address(Stack Pointer) for backtrace calculation: https://github.com/gcc-mirror/gcc/blob/releases/gcc-13/libsanitizer/lsan/lsan.cpp#L39-L42 Since the scheduling mechanism of NuttX sim is coroutine (setjmp/longjmp), if the Stack Pointer is switched, the fast-unwind will unable to get the available address, so the memory leaks on the system/application side that cannot be caught normally. This PR will disable fast-unwind by default to avoid unwind failure. Signed-off-by: chao an <[email protected]>
1 parent 1e22163 commit 1be95c3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

arch/sim/src/sim/sim_head.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,36 @@ static void allsyms_relocate(void)
9797
* Public Functions
9898
****************************************************************************/
9999

100+
/****************************************************************************
101+
* Name: __lsan_default_options
102+
*
103+
* Description:
104+
* This function may be optionally provided by user and should return
105+
* a string containing leak sanitizer runtime options.
106+
*
107+
****************************************************************************/
108+
109+
#ifdef CONFIG_SIM_ASAN
110+
const char *__lsan_default_options(void)
111+
{
112+
/* The fast-unwind implementation of leak-sanitizer will obtain the
113+
* current stack top/bottom and frame address(Stack Pointer) for
114+
* backtrace calculation:
115+
*
116+
* https://github.com/gcc-mirror/gcc/blob/releases/gcc-13/libsanitizer/
117+
* lsan/lsan.cpp#L39-L42
118+
*
119+
* Since the scheduling mechanism of NuttX sim is coroutine
120+
* (setjmp/longjmp), if the Stack Pointer is switched, the fast-unwind
121+
* will unable to get the available address, so the memory leaks on the
122+
* system/application side that cannot be caught normally. This PR will
123+
* disable fast-unwind by default to avoid unwind failure.
124+
*/
125+
126+
return "fast_unwind_on_malloc=0";
127+
}
128+
#endif
129+
100130
/****************************************************************************
101131
* Name: main
102132
*

0 commit comments

Comments
 (0)