Skip to content

Commit

Permalink
Compile MSAN instrumented C++ libraries for MSAN build with googletest.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz authored and Dead2 committed Mar 13, 2022
1 parent 2125162 commit f7e746b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
20 changes: 20 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f7e746b

Please sign in to comment.