Android-x86
Fork
Spenden

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-swiftshader: Commit

external/swiftshader


Commit MetaInfo

Revisionbf8fd5b5fb6892dabcc21b4b86d41cd40cb9b4b5 (tree)
Zeit2018-06-22 09:07:48
AutorNicolas Capens <capn@goog...>
CommiterNicolas Capens

Log Message

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>

Ändern Zusammenfassung

Diff

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -51,6 +51,11 @@ option(USE_GROUP_SOURCES "Group the source files in a folder tree for Visual Stu
5151 option(BUILD_SAMPLES "Build sample programs" 1)
5252 option(BUILD_TESTS "Build test programs" 1)
5353
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+
5459 if(ARCH STREQUAL "arm")
5560 set(DEFAULT_REACTOR_BACKEND "Subzero")
5661 else()
@@ -110,8 +115,12 @@ macro(set_target_export_map TARGET DIR)
110115 # hides all the others. Gc sections is used in combination
111116 # with each functions being in its section, to reduce the
112117 # 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")
114119 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()
115124 endif()
116125 endmacro()
117126
@@ -197,9 +206,21 @@ else()
197206 set_cpp_flag("-ffunction-sections" RELEASE)
198207 set_cpp_flag("-fdata-sections" RELEASE)
199208 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()
200221 endif()
201222
202-if( WIN32 )
223+if(WIN32)
203224 add_definitions(-DWINVER=0x501 -DNOMINMAX -DSTRICT)
204225 set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "" "lib")
205226 endif()
--- /dev/null
+++ b/third_party/LLVM/ubsan_blacklist.txt
@@ -0,0 +1,3 @@
1+#############################################################################
2+# LLVM is not UBSan vptr clean.
3+src:*third_party/LLVM*
Show on old repository browser