Skip to content

Commit

Permalink
feat(bb): working msan preset (#4618)
Browse files Browse the repository at this point in the history
This creates a working memory sanitizer preset, but woe be to those who
try and use it outside of this docker script, as it requires very fiddly
building of LLVM.

Shoutout to this json_struct project for the magic incantations:
https://github.com/jorgen/json_struct/blob/89ca33179790d1e82ecb95092cd469f96c3ff06e/docker/ubuntu22.04/Dockerfile#L23
(bullish on searching github for dockerfiles)

To use:

`./scripts/docker_interactive.sh msan.ubuntu`
After initial setup, this will run instantly, and you will be in a setup
with LLVM MSAN set up. Only then will:

`cmake --preset msan && cmake --build --preset msan` will work.
Currently not everything builds, and some stuff uncovers issues, but I
will decouple that.

---------

Co-authored-by: ludamad <[email protected]>
  • Loading branch information
ludamad and ludamad0 authored Feb 15, 2024
1 parent 4d0e8d3 commit 0195ac8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
6 changes: 5 additions & 1 deletion barretenberg/cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,15 @@
"description": "Build with thread sanitizer on clang16 with debugging information",
"inherits": "clang16-dbg",
"binaryDir": "build-msan",
"generator": "Unix Makefiles",
"environment": {
"CFLAGS": "-fsanitize=memory",
"CXXFLAGS": "-fsanitize=memory",
"LDFLAGS": "-fsanitize=memory"
},
"cacheVariables": {
"HAVE_STD_REGEX": "ON",
"CMAKE_CXX_FLAGS": "$env{MSAN_CFLAGS}",
"CMAKE_EXE_LINKER_FLAGS": "$env{MSAN_LFLAGS}"
}
},
{
Expand Down
43 changes: 43 additions & 0 deletions barretenberg/cpp/dockerfiles/interactive/Dockerfile.msan.ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM ubuntu:lunar

RUN apt update && apt install -y \
build-essential \
curl \
git \
cmake \
lsb-release \
wget \
software-properties-common \
gnupg \
ninja-build \
npm \
libssl-dev \
jq \
bash \
libstdc++6

RUN wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh 16

ENV CXX=clang++-16
ENV CC=clang-16

RUN git clone --depth 1 -b release/16.x https://github.com/llvm/llvm-project

RUN cd llvm-project

RUN mkdir llvm-project/build

RUN cmake -G Ninja -S llvm-project/runtimes -B llvm-project/build \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
-DLLVM_USE_SANITIZER=MemoryWithOrigins \
-DCMAKE_INSTALL_PREFIX=/opt

RUN ninja -C llvm-project/build cxx cxxabi
RUN ninja -C llvm-project/build install-cxx install-cxxabi

ENV MSAN_CFLAGS="-std=c++20 -fsanitize=memory -nostdinc++ -I/opt/include -I/opt/include/c++/v1"
ENV MSAN_LFLAGS="-fsanitize=memory -stdlib=libc++ -L/opt/lib -lc++abi -Wl,-rpath,/opt/lib"

WORKDIR /usr/src/barretenberg/cpp

CMD ["/bin/bash"]
4 changes: 2 additions & 2 deletions barretenberg/cpp/scripts/docker_interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# Enter script directory.
set -eu
cd $(dirname $0)
# allows for 'alpine' or 'ubuntu'
# allows for 'alpine', 'ubuntu' or 'msan.ubuntu'
ENVIRONMENT_KIND="${1:-alpine}"
DOCKERFILE="../dockerfiles/interactive/Dockerfile.$ENVIRONMENT_KIND"
docker build -t "env-$ENVIRONMENT_KIND" -f "$DOCKERFILE" .
docker run -it --mount type=bind,source=$(pwd)/..,target=/usr/src/barretenberg/cpp "env-$ENVIRONMENT_KIND"
docker run -it --mount type=bind,source=$(pwd)/..,target=/usr/src/barretenberg/cpp "env-$ENVIRONMENT_KIND"

0 comments on commit 0195ac8

Please sign in to comment.