From e7ccbfa51d54c705c36147456396571f2b3882bb Mon Sep 17 00:00:00 2001 From: Jakub Gonet Date: Tue, 10 Dec 2024 23:58:06 +0100 Subject: [PATCH] Add ASAN On MacOS running an AVM shows a warning "malloc: nano zone abandoned due to inability to reserve vm space.". To avoid this warning, set MallocNanoZone=0 env variable. Also adds debug symbols when compiling with Clang. Signed-off-by: Jakub Gonet --- CMakeLists.txt | 1 + src/libAtomVM/CMakeLists.txt | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4971a341..fc16bf636 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ option(AVM_RELEASE "Build an AtomVM release" OFF) option(AVM_CREATE_STACKTRACES "Create stacktraces" ON) option(AVM_BUILD_RUNTIME_ONLY "Only build the AtomVM runtime" OFF) option(COVERAGE "Build for code coverage" OFF) +option(ENABLE_ASAN "Use Address Sanitizer" ON) if((${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") OR (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") OR diff --git a/src/libAtomVM/CMakeLists.txt b/src/libAtomVM/CMakeLists.txt index 23739c466..635e1fbf5 100644 --- a/src/libAtomVM/CMakeLists.txt +++ b/src/libAtomVM/CMakeLists.txt @@ -120,7 +120,7 @@ target_compile_features(libAtomVM PUBLIC c_std_11) if (CMAKE_C_COMPILER_ID STREQUAL "GNU") target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} ${MAYBE_WERROR_FLAG} -Wextra -ggdb -Werror=incompatible-pointer-types) elseif (CMAKE_C_COMPILER_ID MATCHES "Clang") - target_compile_options(libAtomVM PUBLIC -Wall --extra-warnings -Werror=incompatible-pointer-types ${MAYBE_WERROR_FLAG}) + target_compile_options(libAtomVM PUBLIC -Wall --extra-warnings -Werror=incompatible-pointer-types -g ${MAYBE_WERROR_FLAG}) endif() if (ENABLE_REALLOC_GC) @@ -132,6 +132,11 @@ if (ADVANCED_TRACING) target_compile_definitions(libAtomVM PUBLIC ENABLE_ADVANCED_TRACE) endif() +if(ENABLE_ASAN) + target_compile_options(libAtomVM PUBLIC -fsanitize=address -fno-omit-frame-pointer) + target_link_options(libAtomVM PUBLIC -fsanitize=address) +endif() + target_link_libraries(libAtomVM PUBLIC m) include(CheckCSourceCompiles) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unknown-pragmas")