]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Compile MSAN instrumented C++ libraries for MSAN build with googletest.
authorNathan Moinvaziri <nathan@nathanm.com>
Thu, 3 Feb 2022 22:37:12 +0000 (14:37 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sun, 13 Mar 2022 06:41:12 +0000 (07:41 +0100)
.github/workflows/cmake.yml
test/CMakeLists.txt

index 100165fb9adadb715ab70aea5a9e6b9d9d6d9890..3b6ac222065e6f787f223768be994b0b77c8a45e 100644 (file)
@@ -443,6 +443,20 @@ jobs:
       run: |
         wineboot --init
 
+    - name: Compile LLVM C++ libraries (MSAN)
+      if: contains(matrix.name, 'MSAN')
+      run: |
+        git clone --depth=1 https://github.com/llvm/llvm-project --single-branch --branch llvmorg-11.0.0
+        cd llvm-project
+        mkdir build
+        cd build
+        cmake -G Ninja ../llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" -DLLVM_USE_SANITIZER=MemoryWithOrigins -DLLVM_LIBC_ENABLE_LINTING=OFF
+        cmake --build . -- cxx cxxabi
+        echo "LLVM_BUILD_DIR=`pwd`" >> $GITHUB_ENV
+      env:
+        CC: ${{ matrix.compiler }}
+        CXX: ${{ matrix.cxx-compiler }}
+
     - name: Generate project files
       # Shared libraries turned off for qemu ppc* and sparc & reduce code coverage sources
       run: |
index 973e9f9399524166c62b0a11459f5bd6147fb629..9def5f120a1761db5e559371ab8f32964a51ed4d 100644 (file)
@@ -7,6 +7,17 @@ enable_language(CXX)
 # Google test requires at least C++11
 set(CMAKE_CXX_STANDARD 11)
 
+# Google test requires MSAN instrumented LLVM C++ libraries
+if(WITH_SANITIZER STREQUAL "Memory")
+    if(NOT DEFINED ENV{LLVM_BUILD_DIR})
+        message(FATAL_ERROR "MSAN instrumented C++ libraries required!")
+    endif()
+
+    # Must set include and compile options before fetching googletest
+    include_directories($ENV{LLVM_BUILD_DIR}/include $ENV{LLVM_BUILD_DIR}/include/c++/v1)
+    add_compile_options(-stdlib=libc++ -g)
+endif()
+
 # Prevent overriding the parent project's compiler/linker settings for Windows
 set(gtest_force_shared_crt ON CACHE BOOL
     "Use shared (DLL) run-time lib even when Google Test is built as static lib." FORCE)
@@ -36,6 +47,15 @@ target_include_directories(gtest_zlib PRIVATE
     ${CMAKE_SOURCE_DIR}
     ${CMAKE_BINARY_DIR})
 
+if(WITH_SANITIZER STREQUAL "Memory")
+    target_link_directories(gtest_zlib PRIVATE $ENV{LLVM_BUILD_DIR}/lib)
+    target_link_options(gtest_zlib PRIVATE
+        -stdlib=libc++
+        -lc++abi
+        -fsanitize=memory
+        -fsanitize-memory-track-origins)
+endif()
+
 target_link_libraries(gtest_zlib zlibstatic gtest)
 
 if(ZLIB_ENABLE_TESTS)