Explorar el Código

Build libcxx and libcxxabi with Memory Sanitizer

tags/v0.0.1
Henry Case hace 3 años
padre
commit
7be2562de5
Se han modificado 4 ficheros con 58 adiciones y 15 borrados
  1. +14
    -0
      .cmake/libstd-memcheck.mk
  2. +7
    -2
      .github/workflows/main.yml
  3. +14
    -13
      CMakeLists.txt
  4. +23
    -0
      test/ct.cpp

+ 14
- 0
.cmake/libstd-memcheck.mk Ver fichero

@@ -0,0 +1,14 @@
include(ExternalProject)
string (REPLACE " " "$<SEMICOLON>" LLVM_PROJECT_TARGETS "libcxx libcxxabi")
set(PREFIX ${CMAKE_CURRENT_BINARY_DIR}/3rd/llvm-project)
ExternalProject_Add(
llvm-project
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
BUILD_COMMAND make cxx cxxabi
INSTALL_COMMAND DESTDIR=${PREFIX} make install-cxx-headers install-cxx install-cxxabi
COMMENT "Building memcheck instrumented libc++ and libc++abi"
PREFIX ${PREFIX}
)

+ 7
- 2
.github/workflows/main.yml Ver fichero

@@ -21,7 +21,8 @@ jobs:
clang-release-build,
gcc-debug-build,
clang-debug-build,
clang-debug-asan-build,
clang-release-asan-build,
clang-release-msan-build,
]

include:
@@ -41,10 +42,14 @@ jobs:
cc: /usr/bin/clang
cxx: /usr/bin/clang++
flags: -DCMAKE_BUILD_TYPE=Debug
- name: clang-debug-asan-build
- name: clang-release-asan-build
cc: clang
cxx: clang++
flags: -DCMAKE_BUILD_TYPE=Release -DADDRSAN=1
- name: clang-release-msan-build
cc: clang
cxx: clang++
flags: -DCMAKE_BUILD_TYPE=Release -DMEMSAN=1
steps:
- uses: actions/checkout@v1
with:


+ 14
- 13
CMakeLists.txt Ver fichero

@@ -24,6 +24,7 @@ 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)

@@ -32,9 +33,22 @@ 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)

if(MEMSAN)
# PQC_MEMSAN enables usage of some internals from clang
if (NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
message(FATAL_ERROR "Must use clang if compiled with memory sanitizer.")
endif()
if(ADDRSAN)
message(FATAL_ERROR "Can't use MSAN and ASAN")
endif()
include(.cmake/libstd-memcheck.mk)
#set(C_CXX_FLAGS "${C_CXX_FLAGS} -DPQC_MEMSAN=1 -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer")
endif()

add_subdirectory(3rd/gtest)
set(BUILD_PIC ON CACHE BOOL "")
add_subdirectory(3rd/cpu_features)
@@ -117,19 +131,6 @@ if(ADDRSAN)
set(LDFLAGS "${LDFLAGS} -fsanitize=undefined,address,leak")
endif()

# Build with memory sanitizer
if(MEMSAN)
# PQC_MEMSAN enables usage of some internals from clang
if (NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
message(FATAL_ERROR "Must use clang if compiled with memory sanitizer.")
endif()
if(ADDRSAN)
message(FATAL_ERROR "Can't use MSAN and ASAN")
endif()

set(C_CXX_FLAGS "${C_CXX_FLAGS} -DPQC_MEMSAN=1 -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer")
endif()

include(.cmake/common.mk)

# Control Debug/Release mode


+ 23
- 0
test/ct.cpp Ver fichero

@@ -0,0 +1,23 @@
#include <algorithm>
#include <vector>
#include <gtest/gtest.h>
#include <pqc/pqc.h>

// #ifdef VALGRIND
// #include <valgrind/valgrind.h>
// #include <valgrind/memcheck.h>
// #define POISON(p,sz) VALGRIND_MAKE_MEM_UNDEFINED(p,sz)
// #endif

#ifdef PQC_MEMSAN
#include <sanitizer/msan_interface.h>
#define POISON(p,sz) __msan_poison(p,sz)
#endif


TEST(ConstantTime, Poisonner_Basic) {
unsigned char x[8] = {0};
//gi POISON(x, 4);
if(x[5]) x[6] = x[5];
//UNPOISON(x, 4);
}

Cargando…
Cancelar
Guardar