Skip to content

Commit e7ccbfa

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 fc824ad commit e7ccbfa

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
@@ -35,6 +35,7 @@ option(AVM_RELEASE "Build an AtomVM release" OFF)
3535
option(AVM_CREATE_STACKTRACES "Create stacktraces" ON)
3636
option(AVM_BUILD_RUNTIME_ONLY "Only build the AtomVM runtime" OFF)
3737
option(COVERAGE "Build for code coverage" OFF)
38+
option(ENABLE_ASAN "Use Address Sanitizer" ON)
3839

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

src/libAtomVM/CMakeLists.txt

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

126126
if (ENABLE_REALLOC_GC)
@@ -132,6 +132,11 @@ if (ADVANCED_TRACING)
132132
target_compile_definitions(libAtomVM PUBLIC ENABLE_ADVANCED_TRACE)
133133
endif()
134134

135+
if(ENABLE_ASAN)
136+
target_compile_options(libAtomVM PUBLIC -fsanitize=address -fno-omit-frame-pointer)
137+
target_link_options(libAtomVM PUBLIC -fsanitize=address)
138+
endif()
139+
135140
target_link_libraries(libAtomVM PUBLIC m)
136141
include(CheckCSourceCompiles)
137142
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unknown-pragmas")

0 commit comments

Comments
 (0)