From f7e746bcf6585527659179e906b984cd8dd2ae28 Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Thu, 3 Feb 2022 14:37:12 -0800 Subject: [PATCH] Compile MSAN instrumented C++ libraries for MSAN build with googletest. --- .github/workflows/cmake.yml | 14 ++++++++++++++ test/CMakeLists.txt | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 100165fb..3b6ac222 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 973e9f93..9def5f12 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) -- 2.47.3