From e2b8231796e41eecf44c2d1e6ae981bd6225b09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Mon, 24 Jun 2019 14:30:43 +0200 Subject: [PATCH] boards/native: fix crash with all-asan Without this change a RIOT application compiled with all-asan will segfault as RIOT provides its own malloc by default. Add a define for disabling custom malloc, calloc and realloc implementations and use it when compiling with all-asan. --- boards/native/Makefile.include | 2 +- cpu/native/syscalls.c | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/boards/native/Makefile.include b/boards/native/Makefile.include index 732bf29a5b..a9cd53e1e7 100644 --- a/boards/native/Makefile.include +++ b/boards/native/Makefile.include @@ -98,7 +98,7 @@ all-cachegrind: CFLAGS += -g3 all-gprof: CFLAGS += -pg all-gprof: LINKFLAGS += -pg all-asan: CFLAGS += -fsanitize=address -fno-omit-frame-pointer -g3 -all-asan: CFLAGS += -DNATIVE_IN_CALLOC +all-asan: CFLAGS += -DNATIVE_MEMORY all-asan: LINKFLAGS += -fsanitize=address -fno-omit-frame-pointer -g3 INCLUDES += $(NATIVEINCLUDES) diff --git a/cpu/native/syscalls.c b/cpu/native/syscalls.c index d0a3b423b8..821535feda 100644 --- a/cpu/native/syscalls.c +++ b/cpu/native/syscalls.c @@ -142,7 +142,7 @@ void _native_syscall_leave(void) /* make use of TLSF if it is included, except when building with valgrind * support, where one probably wants to make use of valgrind's memory leak * detection abilities*/ -#if !(defined MODULE_TLSF) || (defined(HAVE_VALGRIND_H)) +#if (!(defined MODULE_TLSF) && !(defined NATIVE_MEMORY)) || (defined(HAVE_VALGRIND_H)) int _native_in_malloc = 0; void *malloc(size_t size) { @@ -176,11 +176,7 @@ void free(void *ptr) _native_syscall_leave(); } -#ifdef NATIVE_IN_CALLOC -int _native_in_calloc = 1; -#else int _native_in_calloc = 0; -#endif void *calloc(size_t nmemb, size_t size) { /* dynamically load calloc when it's needed - this is necessary to