external/swiftshader
Revision | bf8fd5b5fb6892dabcc21b4b86d41cd40cb9b4b5 (tree) |
---|---|
Zeit | 2018-06-22 09:07:48 |
Autor | Nicolas Capens <capn@goog...> |
Commiter | 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/19548
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
@@ -51,6 +51,11 @@ option(USE_GROUP_SOURCES "Group the source files in a folder tree for Visual Stu | ||
51 | 51 | option(BUILD_SAMPLES "Build sample programs" 1) |
52 | 52 | option(BUILD_TESTS "Build test programs" 1) |
53 | 53 | |
54 | +option (MSAN "Build with memory sanitizer" 0) | |
55 | +option (ASAN "Build with address sanitizer" 0) | |
56 | +option (TSAN "Build with thread sanitizer" 0) | |
57 | +option (UBSAN "Build with undefined behavior sanitizer" 0) | |
58 | + | |
54 | 59 | if(ARCH STREQUAL "arm") |
55 | 60 | set(DEFAULT_REACTOR_BACKEND "Subzero") |
56 | 61 | else() |
@@ -110,8 +115,12 @@ macro(set_target_export_map TARGET DIR) | ||
110 | 115 | # hides all the others. Gc sections is used in combination |
111 | 116 | # with each functions being in its section, to reduce the |
112 | 117 | # binary size. |
113 | - set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "${LINKFLAGS} -Wl,--hash-style=both,--version-script=${DIR}/${TARGET}.lds,--gc-sections,--no-undefined") | |
118 | + set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "${LINKFLAGS} -Wl,--hash-style=both,--version-script=${DIR}/${TARGET}.lds,--gc-sections") | |
114 | 119 | set_target_properties(${TARGET} PROPERTIES LINK_DEPENDS "${DIR}/${TARGET}.lds") |
120 | + | |
121 | + if(NOT MSAN AND NOT ASAN AND NOT TSAN AND NOT UBSAN) | |
122 | + set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--no-undefined") | |
123 | + endif() | |
115 | 124 | endif() |
116 | 125 | endmacro() |
117 | 126 |
@@ -197,9 +206,21 @@ else() | ||
197 | 206 | set_cpp_flag("-ffunction-sections" RELEASE) |
198 | 207 | set_cpp_flag("-fdata-sections" RELEASE) |
199 | 208 | set_cpp_flag("-fomit-frame-pointer" RELEASE) |
209 | + | |
210 | + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") | |
211 | + if(MSAN) | |
212 | + set_cpp_flag("-fsanitize=memory") | |
213 | + elseif(ASAN) | |
214 | + set_cpp_flag("-fsanitize=address") | |
215 | + elseif(TSAN) | |
216 | + set_cpp_flag("-fsanitize=thread") | |
217 | + elseif(UBSAN) | |
218 | + set_cpp_flag("-fsanitize=undefined -fsanitize-blacklist=${CMAKE_SOURCE_DIR}/third_party/LLVM/ubsan_blacklist.txt") | |
219 | + endif() | |
220 | + endif() | |
200 | 221 | endif() |
201 | 222 | |
202 | -if( WIN32 ) | |
223 | +if(WIN32) | |
203 | 224 | add_definitions(-DWINVER=0x501 -DNOMINMAX -DSTRICT) |
204 | 225 | set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "" "lib") |
205 | 226 | endif() |
@@ -0,0 +1,3 @@ | ||
1 | +############################################################################# | |
2 | +# LLVM is not UBSan vptr clean. | |
3 | +src:*third_party/LLVM* |