From: Nathan Moinvaziri Date: Thu, 3 Feb 2022 22:37:12 +0000 (-0800) Subject: Compile MSAN instrumented C++ libraries for MSAN build with googletest. X-Git-Tag: 2.1.0-beta1~353 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7e746bcf6585527659179e906b984cd8dd2ae28;p=thirdparty%2Fzlib-ng.git Compile MSAN instrumented C++ libraries for MSAN build with googletest. --- diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 100165fb9..3b6ac2220 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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: | diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 973e9f939..9def5f120 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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)