Skip to content

Commit b38f06f

Browse files
committed
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 <jakub.gonet@swmansion.com>
1 parent c54cc84 commit b38f06f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ option(AVM_RELEASE "Build an AtomVM release" OFF)
3636
option(AVM_CREATE_STACKTRACES "Create stacktraces" ON)
3737
option(AVM_BUILD_RUNTIME_ONLY "Only build the AtomVM runtime" OFF)
3838
option(COVERAGE "Build for code coverage" OFF)
39+
option(ENABLE_ASAN "Use Address Sanitizer" ON)
3940

4041
if((${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") OR
4142
(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") OR

src/libAtomVM/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ target_compile_features(libAtomVM PUBLIC c_std_11)
123123
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
124124
target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} ${MAYBE_WERROR_FLAG} -Wextra -ggdb -Werror=incompatible-pointer-types)
125125
elseif (CMAKE_C_COMPILER_ID MATCHES "Clang")
126-
target_compile_options(libAtomVM PUBLIC -Wall --extra-warnings -Werror=incompatible-pointer-types ${MAYBE_WERROR_FLAG})
126+
target_compile_options(libAtomVM PUBLIC -Wall --extra-warnings -Werror=incompatible-pointer-types -g ${MAYBE_WERROR_FLAG})
127127
endif()
128128

129129
if (ENABLE_REALLOC_GC)
@@ -135,6 +135,11 @@ if (ADVANCED_TRACING)
135135
target_compile_definitions(libAtomVM PUBLIC ENABLE_ADVANCED_TRACE)
136136
endif()
137137

138+
if(ENABLE_ASAN)
139+
target_compile_options(libAtomVM PUBLIC -fsanitize=address -fno-omit-frame-pointer)
140+
target_link_options(libAtomVM PUBLIC -fsanitize=address)
141+
endif()
142+
138143
target_link_libraries(libAtomVM PUBLIC m)
139144
include(CheckCSourceCompiles)
140145
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unknown-pragmas")

0 commit comments

Comments
 (0)