Requirements

Linux (msan doesn’t work on Windows or MacOS), clang 8 (7 should also work)

Build instrumented version of libc++

  • Checkout LLVM, libc++ and libc++abi

$ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm

$ (cd llvm/projects && svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx)

$ (cd llvm/projects && svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi)

  • Build libc++ with MSan:

$ mkdir libcxx_msan && cd libcxx_msan

$ cmake ../llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER=Memory -DCMAKE_C_COMPILER=clang-8 -DCMAKE_CXX_COMPILER=clang++-8

$ make cxx -j$(nproc)

Build instrumented version of boost

$ ./bootstrap.sh --with-libraries=thread,system,filesystem --prefix=/home/luckychess/src/msan_guide/boost/boost_1_70_0_msan --with-toolset=clang

(--prefix is a path where built libraries will be stored, create this directory first)

  • Open file project-config.jam with a text editor. Find “using clang” line and replace it with the next line:

using clang : 8.0 : : <cxxflags>"-fsanitize=memory -fsanitize-memory-track-origins -stdlib=libc++ -L/home/luckychess/src/msan_guide/libcxx_msan/lib -lc++abi -I/home/luckychess/src/msan_guide/libcxx_msan/include -I/home/luckychess/src/msan_guide/libcxx_msan/include/c++/v1" ;

Paths at -L and -I parameters are actually paths to directories from the previous step. Also please note - there is a space after ; (in the line’s very end)

Prepare Iroha to build (check https://github.com/luckychess/iroha-1/tree/msan):

  • Please ensure that no external dependencies are installed (like protobuf, grpc…). Boost can be installed - boost path will be passed to cmake explicitly.
  • In the root CMakeLists.txt find

append_build_flags(-fsanitize=memory -fsanitize-memory-track-origins)

line and replace it with

append_build_flags(-fsanitize=memory -fsanitize-memory-track-origins -stdlib=libc++ -L/home/luckychess/src/msan_guide/libcxx_msan/lib -lc++abi -I/home/luckychess/src/msan_guide/libcxx_msan/include -I/home/luckychess/src/msan_guide/libcxx_msan/include/c++/v1 -Wno-error=unused-command-line-argument)

(change paths to your own)

  • In functions.cmake add libcxx_msan/lib path to LD_LIBRARY_PATH for protoc, e.g.:

set(GEN_COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${protobuf_LIBRARY_DIR}:$ENV{LD_LIBRARY_PATH}:/home/luckychess/src/libcxx_msan/lib "${protoc_EXECUTABLE}")

Note: tbb still remains uncovered which could bring some inaccuracies. It's way too painful to integrate it at the moment.

Build Iroha

$ mkdir build && cd build

$ cmake -DCMAKE_C_COMPILER=clang-8 -DCMAKE_CXX_COMPILER=clang++-8 -DSANITIZE_MEMORY=ON -DBOOST_ROOT=/home/luckychess/src/msan_guide/boost/boost_1_70_0_msan ..

(set -DBOOST_ROOT to your own boost root )

$ LD_LIBRARY_PATH=/home/luckychess/src/msan_guide/libcxx_msan/lib make irohad (or just make) (again use your own path)

  • No labels