Skip to content

Commit d55a11d

Browse files
authored
Merge pull request #1124 from JACoders/use-asan
[Shared] provide option to use AddressSanitizer
2 parents b0eeacd + 5735f8c commit d55a11d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ option(BuildJK2SPGame "Whether to create projects for the jk2 sp gamecode mod (j
5050
option(BuildJK2SPRdVanilla "Whether to create projects for the jk2 sp renderer (rdjosp-vanilla_x86.dll)" OFF)
5151

5252
option(BuildTests "Whether to build automatic unit tests (requires Boost)" OFF)
53+
option(UseAddressSanitizer "Whether to enable runtime address sanitizer" OFF)
54+
option(UseUndefinedSanitizer "Whether to enable runtime Undefined Behavior sanitizer" OFF)
5355

5456
include(CMakeDependentOption)
5557
cmake_dependent_option(BuildSymbolServer "Build WIP Windows Symbol Server (experimental and unused)" OFF "NOT WIN32 OR NOT MSVC" OFF)
@@ -244,6 +246,16 @@ elseif (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" M
244246
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
245247
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
246248

249+
if(UseAddressSanitizer)
250+
# also raise stack size drastically (to 64MiB), since the sanitizer adds overhead to stack frames
251+
add_compile_options(-fsanitize=address)
252+
add_link_options(-fsanitize=address -z stack-size=4000000)
253+
endif()
254+
if(UseUndefinedSanitizer)
255+
add_compile_options(-fsanitize=undefined)
256+
add_link_options(-fsanitize=undefined)
257+
endif()
258+
247259
# additional flags for debug configuration
248260
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb")
249261
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb")

0 commit comments

Comments
 (0)