From 73daf206496b0df21ba2db4284002e596ea9691b Mon Sep 17 00:00:00 2001 From: Kris Kwiatkowski Date: Tue, 22 Jun 2021 01:10:53 +0100 Subject: [PATCH] Memory Sanitizer build --- .cmake/libstd-memory_sanitizer.mk | 6 ++++-- .github/workflows/main.yml | 32 +++++++++++++++---------------- CMakeLists.txt | 10 ++++++++-- test/bench/CMakeLists.txt | 11 +++++++++-- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/.cmake/libstd-memory_sanitizer.mk b/.cmake/libstd-memory_sanitizer.mk index a6fc3b8c..f610c3e9 100644 --- a/.cmake/libstd-memory_sanitizer.mk +++ b/.cmake/libstd-memory_sanitizer.mk @@ -13,7 +13,7 @@ ExternalProject_Add( GIT_REPOSITORY https://github.com/llvm/llvm-project.git GIT_TAG llvmorg-12.0.0 GIT_SHALLOW TRUE - CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=${LLVM_PROJECT_TARGETS} -DLLVM_USE_SANITIZER=MemoryWithOrigins -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm-project/llvm + CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=${LLVM_PROJECT_TARGETS} -DLLVM_USE_SANITIZER=MemoryWithOrigins -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm-project/llvm -DLLVM_INCLUDE_BENCHMARKS=OFF BUILD_COMMAND ${MAKE_PROGRAM} cxx cxxabi INSTALL_COMMAND DESTDIR=${PREFIX} make install-cxx-headers install-cxx install-cxxabi COMMENT "Building memcheck instrumented libc++ and libc++abi" @@ -37,4 +37,6 @@ set_target_properties( set_target_properties( cxxabi PROPERTIES IMPORTED_LOCATION ${LLVM_LIB_CXXABI}) -set_property(GLOBAL PROPERTY llvmproject_build_install_dir_property ${PREFIX}/usr/local) +set_property( + GLOBAL PROPERTY llvmproject_build_install_dir_property + ${PREFIX}/usr/local) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 415fafff..e5f93df8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -86,19 +86,19 @@ jobs: curl http://amongbytes.com/~flowher/permalinks/kat.zip --output kat.zip unzip kat.zip cargo run --release -- --katdir KAT -# MEMSAN: -# name: Memory Sanitizer build -# runs-on: [ubuntu-20.04] -# steps: -# - uses: actions/checkout@v1 -# with: -# submodules: true -# - name: build -# run: | -# mkdir -p build -# cd build -# CC=clang CXX=clang++ cmake -DCMAKE_BUILD_TYPE=Release -DMEMSAN=1 .. -# make -# - name: run tests -# run: | -# cd build && ./ut --gtest_filter="NONE" + MEMSAN: + name: Memory Sanitizer build + runs-on: [ubuntu-20.04] + steps: + - uses: actions/checkout@v1 + with: + submodules: true + - name: build + run: | + mkdir -p build + cd build + CC=clang CXX=clang++ cmake -DCMAKE_BUILD_TYPE=Release -DMEMSAN=1 .. + make + - name: run tests + run: | + cd build && ./ut --gtest_filter="NONE" diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a27cc46..9e60c4ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,6 @@ FetchContent_Declare( SOURCE_DIR ${PROJECT_SOURCE_DIR}/3rd/gbench GIT_REPOSITORY https://github.com/kriskwiatkowski/benchmark.git GIT_TAG 49862ab56b6b7c3afd87b80bd5d787ed78ce3b96 - GIT_SHALLOW TRUE ) FetchContent_Populate(gbench) @@ -62,7 +61,6 @@ FetchContent_Declare( SOURCE_DIR ${PROJECT_SOURCE_DIR}/3rd/cpu_features GIT_REPOSITORY https://github.com/google/cpu_features.git GIT_TAG bc2846e78faeb26b8a46c17df369d4e5f1f9e2bb - GIT_SHALLOW TRUE ) FetchContent_Populate(cpu_features) @@ -382,8 +380,16 @@ if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug") # set(BENCHMARK_ENABLE_LTO ON CACHE BOOL "Enable link time optim" FORCE) #endif() set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) + set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE) set(CMAKE_C_FLAGS "${C_CXX_FLAGS} ${EXTRA_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${C_CXX_FLAGS} ${EXTRA_CXX_FLAGS}") + if (MEMSAN) + set(BENCHMARK_USE_LIBCXX ON CACHE BOOL "" FORCE) + # Since build requires C++20 it is safe to assume that std::regex is available. + # It seems I need to force it as benchmark build doesn't work very well with libc++ + set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE) + endif() + add_subdirectory(${CMAKE_SOURCE_DIR}/3rd/gbench) add_subdirectory(test/bench) endif() diff --git a/test/bench/CMakeLists.txt b/test/bench/CMakeLists.txt index ad005ee1..3f5135d1 100644 --- a/test/bench/CMakeLists.txt +++ b/test/bench/CMakeLists.txt @@ -1,12 +1,16 @@ cmake_minimum_required(VERSION 3.13) +set(CMAKE_CXX_STANDARD 14) include_directories(${PROJECT_SOURCE_DIR}/3rd/gbench/include) link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../3rd/gbench/lib) +if (MEMSAN) +set(CXXLIBS_FOR_MEMORY_SANITIZER cxx cxxabi) +endif() + add_executable( bench - kyber.cc -) + kyber.cc) target_link_libraries( bench @@ -16,3 +20,6 @@ target_link_libraries( benchmark_main ${CXXLIBS_FOR_MEMORY_SANITIZER}) +if (MEMSAN) +add_dependencies(bench ${CXXLIBS_FOR_MEMORY_SANITIZER}) +endif()