Skip to content

Commit 3da873a

Browse files
vanwinkeljannashif
authored andcommitted
debug: asan: Added leak suppression for SDL2 & X11
Added leak suppression, by implementing __lsan_default_suppressions function, for SDL2 and X11 library which are used by the SDL display driver. Signed-off-by: Jan Van Winkel <[email protected]>
1 parent a0d6289 commit 3da873a

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@
345345
/subsys/bluetooth/mesh/ @jhedberg @trond-snekvik @joerchan @Vudentz
346346
/subsys/cpp/ @pabigot @vanwinkeljan
347347
/subsys/debug/ @nashif
348-
/subsys/debug/asan.c @vanwinkeljan @aescolar
348+
/subsys/debug/asan_hacks.c @vanwinkeljan @aescolar
349349
/subsys/disk/disk_access_spi_sdhc.c @JunYangNXP
350350
/subsys/disk/disk_access_sdhc.h @JunYangNXP
351351
/subsys/disk/disk_access_usdhc.c @JunYangNXP

subsys/debug/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ zephyr_sources_ifdef(
77

88
zephyr_sources_ifdef(
99
CONFIG_ASAN
10-
asan.c
10+
asan_hacks.c
1111
)
1212

1313
add_subdirectory(tracing)

subsys/debug/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ config ASAN
5757
This behavior can be changes by adding leak_check_at_exit=1 to the
5858
environment variable ASAN_OPTIONS.
5959

60+
if ASAN
61+
config ASAN_NOP_DLCLOSE
62+
bool "Override host OS dlclose() with a NOP"
63+
default y if HAS_SDL
64+
help
65+
Override host OS dlclose() with a NOP.
66+
67+
This NOP implementation is needed as workaround for a known limitation in
68+
LSAN (leak sanitizer) that if dlcose is called before performing the leak
69+
check, "<unknown module>" is reported in the stack traces during the leak
70+
check and these can not be suppressed, see
71+
https://github.com/google/sanitizers/issues/89 for more info.
72+
endif # ASAN
73+
6074
config UBSAN
6175
bool "Build with undefined behavior sanitizer"
6276
depends on ARCH_POSIX

subsys/debug/asan.c

Lines changed: 0 additions & 18 deletions
This file was deleted.

subsys/debug/asan_hacks.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2019 Jan Van Winkel <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#if defined(CONFIG_64BIT) && defined(__GNUC__) && !defined(__clang__)
8+
const char *__asan_default_options(void)
9+
{
10+
/* Running leak detection at exit could lead to a deadlock on
11+
* 64-bit boards if GCC is used.
12+
* https://github.com/zephyrproject-rtos/zephyr/issues/20122
13+
*/
14+
return "leak_check_at_exit=0:";
15+
}
16+
#endif
17+
18+
#ifdef CONFIG_HAS_SDL
19+
const char *__lsan_default_suppressions(void)
20+
{
21+
/* The SDL2 library does not clean-up all it resources on exit,
22+
* as such suppress all memory leaks coming from libSDL2 and the
23+
* underlying X11 library
24+
*/
25+
return "leak:libX11\nleak:libSDL2\n";
26+
}
27+
#endif /* CONFIG_HAS_SDL */
28+
29+
#ifdef CONFIG_ASAN_NOP_DLCLOSE
30+
/* LSAN has a known limitation that if dlcose is called before performing the
31+
* leak check; "<unknown module>" is reported in the stack traces during the
32+
* leak check and these can not be suppressed, see
33+
* https://github.com/google/sanitizers/issues/89 for more info.
34+
*
35+
* A workaround for this is to implement a NOP version of dlclose.
36+
*/
37+
int dlclose(void *handler)
38+
{
39+
return 0;
40+
}
41+
#endif /* CONFIG_ASAN_NOP_DLCLOSE */

0 commit comments

Comments
 (0)