Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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/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.
  • Open Findsoci.cmake and change soci commit hash to a47fd6994d5dcab0aadea0348ea380a22248bebf (latest at the moment)
  • In the root CMakeLists.txt find

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

...

(change paths to your own)

  • In mst_state.cpp replace std::min_element to boost::first_min_element and add

#include <boost/algorithm/minmax_element.hpp>

line at the file header

  • 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}")// TODO: tbb (no success)

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

...