Commit bf8fd5b5 by Nicolas Capens Committed by Nicolas Capens

Support Sanitizer builds with CMake.

Added MSAN, ASAN, TSAN, and UBSAN build options. Disabled use of --no-undefined if a Santizer is used, since by design they leave some symbols unresolved until run time. UBSAN required blacklisting of our old copy of LLVM. Bug swiftshader:108 Change-Id: Iab94b6815bc188c2a7f07d5b7a461234fb1035f3 Reviewed-on: https://swiftshader-review.googlesource.com/19548Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 050ef946
......@@ -51,6 +51,11 @@ option(USE_GROUP_SOURCES "Group the source files in a folder tree for Visual Stu
option(BUILD_SAMPLES "Build sample programs" 1)
option(BUILD_TESTS "Build test programs" 1)
option (MSAN "Build with memory sanitizer" 0)
option (ASAN "Build with address sanitizer" 0)
option (TSAN "Build with thread sanitizer" 0)
option (UBSAN "Build with undefined behavior sanitizer" 0)
if(ARCH STREQUAL "arm")
set(DEFAULT_REACTOR_BACKEND "Subzero")
else()
......@@ -110,8 +115,12 @@ macro(set_target_export_map TARGET DIR)
# hides all the others. Gc sections is used in combination
# with each functions being in its section, to reduce the
# binary size.
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "${LINKFLAGS} -Wl,--hash-style=both,--version-script=${DIR}/${TARGET}.lds,--gc-sections,--no-undefined")
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "${LINKFLAGS} -Wl,--hash-style=both,--version-script=${DIR}/${TARGET}.lds,--gc-sections")
set_target_properties(${TARGET} PROPERTIES LINK_DEPENDS "${DIR}/${TARGET}.lds")
if(NOT MSAN AND NOT ASAN AND NOT TSAN AND NOT UBSAN)
set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--no-undefined")
endif()
endif()
endmacro()
......@@ -197,9 +206,21 @@ else()
set_cpp_flag("-ffunction-sections" RELEASE)
set_cpp_flag("-fdata-sections" RELEASE)
set_cpp_flag("-fomit-frame-pointer" RELEASE)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(MSAN)
set_cpp_flag("-fsanitize=memory")
elseif(ASAN)
set_cpp_flag("-fsanitize=address")
elseif(TSAN)
set_cpp_flag("-fsanitize=thread")
elseif(UBSAN)
set_cpp_flag("-fsanitize=undefined -fsanitize-blacklist=${CMAKE_SOURCE_DIR}/third_party/LLVM/ubsan_blacklist.txt")
endif()
endif()
endif()
if( WIN32 )
if(WIN32)
add_definitions(-DWINVER=0x501 -DNOMINMAX -DSTRICT)
set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "" "lib")
endif()
......
#############################################################################
# LLVM is not UBSan vptr clean.
src:*third_party/LLVM*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment