diff --git a/sanitizers-19/Dockerfile b/sanitizers-19/Dockerfile new file mode 100644 index 0000000..1c0417d --- /dev/null +++ b/sanitizers-19/Dockerfile @@ -0,0 +1,60 @@ +FROM helics/buildenv:clang19-builder as builder + +WORKDIR /root/develop + +RUN apt update && apt install -y ninja-build + +RUN git clone https://github.com/llvm/llvm-project.git + +# Sets the number of threads for make to use +ARG MAKE_PARALLEL + +# Build the Memory sanitizer libraries +RUN mkdir libcxx_msan_build && mkdir libcxx_msan_install && cd libcxx_msan_build && cmake -GNinja -S runtimes ../llvm-project/runtimes -DCMAKE_INSTALL_PREFIX=/root/develop/libcxx_msan_install -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_USE_SANITIZER=MemoryWithOrigins -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ +RUN cd libcxx_msan_build && cmake --build . -j 3 -- cxx cxxabi +RUN cd libcxx_msan_build && ninja install-cxx install-cxxabi + +RUN mkdir -p /root/develop/libcxx_msan/include && cp -r /root/develop/libcxx_msan_install/include/* /root/develop/libcxx_msan/include/ +RUN mkdir -p /root/develop/libcxx_msan/lib && cp -r /root/develop/libcxx_msan_install/lib/* /root/develop/libcxx_msan/lib/ + +# Build the ASAN libraries +COPY asan_suppression.txt . +ENV ASAN_OPTIONS="detect_odr_violation=0" +RUN mkdir libcxx_asan_build && mkdir libcxx_asan_install && cd libcxx_asan_build && cmake -GNinja -S runtimes ../llvm-project/runtimes -DCMAKE_INSTALL_PREFIX=/root/develop/libcxx_asan_install -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-fsanitize-ignorelist=/root/develop/asan_suppression.txt" -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_USE_SANITIZER=Address -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ +RUN cd libcxx_asan_build && cmake --build . -j 3 -- cxx cxxabi +RUN cd libcxx_asan_build && ninja install-cxx install-cxxabi + +RUN mkdir -p /root/develop/libcxx_asan/include && cp -r /root/develop/libcxx_asan_install/include/* /root/develop/libcxx_asan/include/ +RUN mkdir -p /root/develop/libcxx_asan/lib && cp -r /root/develop/libcxx_asan_install/lib/* /root/develop/libcxx_asan/lib/ + +# Build the tsan libraries +RUN mkdir libcxx_tsan_build && mkdir libcxx_tsan_install&& cd libcxx_tsan_build && cmake -GNinja -S runtimes ../llvm-project/runtimes -DCMAKE_INSTALL_PREFIX=/root/develop/libcxx_tsan_install -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_USE_SANITIZER=Thread -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ +RUN cd libcxx_tsan_build && cmake --build . -j 2 -- cxx cxxabi +RUN cd libcxx_tsan_build && ninja install-cxx install-cxxabi + +RUN mkdir -p /root/develop/libcxx_tsan/include && cp -r /root/develop/libcxx_tsan_install/include/* /root/develop/libcxx_tsan/include/ +RUN mkdir -p /root/develop/libcxx_tsan/lib && cp -r /root/develop/libcxx_tsan_install/lib/* /root/develop/libcxx_tsan/lib/ + +FROM helics/buildenv:clang19-builder + +ENV DEBIAN_FRONTEND=noninteractive + +# last updated 2024-12-04 + +# Copy the built libraries from the builder images +COPY --from=builder /root/develop/libcxx_asan /root/develop/libcxx_asan +COPY --from=builder /root/develop/libcxx_tsan /root/develop/libcxx_tsan +COPY --from=builder /root/develop/libcxx_msan /root/develop/libcxx_msan + +# Copy scripts to build and run HELICS with the sanitizers +COPY helics_build_run_*.sh /root/develop/ + +ENV ASAN_CFLAGS="-fsanitize=undefined,address -nostdinc++ -nostdlib++ -L/root/develop/libcxx_asan/lib -lc++ -lc++abi -I/root/develop/libcxx_asan/include -fsanitize-address-use-after-scope -Wno-unused-command-line-argument -fno-omit-frame-pointer -g -O1 -Wl,-rpath,/root/develop/libcxx_asan/lib" + +ENV ASAN_OPTIONS="detect_odr_violation=0" +ENV MSAN_CFLAGS="-fsanitize=memory -nostdinc++ -nostdlib++ -L/root/develop/libcxx_msan/lib -lc++ -lc++abi -I/root/develop/libcxx_msan/include -I/root/develop/libcxx_msan/include/c++/v1 -Wno-unused-command-line-argument -fno-omit-frame-pointer -g -O1 -Wl,-rpath,/root/develop/libcxx_msan/lib" + +ENV TSAN_CFLAGS="-fsanitize=thread -nostdinc++ -nostdlib++ -L/root/develop/libcxx_tsan/lib -lc++ -lc++abi -I/root/develop/libcxx_tsan/include -I/root/develop/libcxx_tsan/include/c++/v1 -Wno-unused-command-line-argument -fno-omit-frame-pointer -g -O2 -Wl,-rpath,/root/develop/libcxx_tsan/lib" + +LABEL maintainer="helicsdevelopers@helics.org" +LABEL date="2024-12-04" diff --git a/sanitizers-19/asan_suppression.txt b/sanitizers-19/asan_suppression.txt new file mode 100644 index 0000000..ce60bf0 --- /dev/null +++ b/sanitizers-19/asan_suppression.txt @@ -0,0 +1,22 @@ +# Lines starting with # are ignored. +# Turn off checks for the source file (use absolute path or path relative +# to the current working directory): +src:*functional.cpp +# Turn off checks for a particular functions (use mangled names): +#fun:MyFooBar +#fun:_Z8MyFooBarv +# Extended regular expressions are supported: +#fun:bad_(foo|bar) +#src:bad_source[1-9].c +# Shell like usage of * is supported (* is treated as .*): +#src:bad/sources/* +#fun:*BadFunction* +# Specific sanitizer tools may introduce categories. +#src:/special/path/*=special_sources +# Sections can be used to limit ignorelist entries to specific sanitizers +#[address] +#fun:*BadASanFunc* +# Section names are regular expressions +#[cfi-vcall|cfi-icall] +#fun:*BadCfiCall +# Entries without sections are placed into [*] and apply to all sanitizers diff --git a/sanitizers-19/helics_build_run_asan.sh b/sanitizers-19/helics_build_run_asan.sh new file mode 100644 index 0000000..d30b4b2 --- /dev/null +++ b/sanitizers-19/helics_build_run_asan.sh @@ -0,0 +1,10 @@ +#!/usr/bin/bash +git clone https://github.com/GMLC-TDC/HELICS.git +cd HELICS +mkdir build-asan +cd build-asan +cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_FLAGS="${ASAN_CFLAGS}" -DHELICS_BUILD_TESTS=ON -DHELICS_ZMQ_SUBPROJECT=ON -DHELICS_ZMQ_FORCE_SUBPROJECT=ON +cd /root/develop/HELICS/build-asan +make -j2 + +./sanitizer_tests.sh diff --git a/sanitizers-19/helics_build_run_msan.sh b/sanitizers-19/helics_build_run_msan.sh new file mode 100644 index 0000000..482d5ff --- /dev/null +++ b/sanitizers-19/helics_build_run_msan.sh @@ -0,0 +1,10 @@ +#!/usr/bin/bash +git git clone --recurse-submodules --branch develop https://github.com/GMLC-TDC/HELICS.git +cd HELICS +mkdir build-msan +cd build-msan +cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_FLAGS="${MSAN_CFLAGS}" -DHELICS_BUILD_TESTS=ON -DHELICS_ZMQ_SUBPROJECT=ON -DHELICS_ZMQ_FORCE_SUBPROJECT=ON +cd /root/develop/HELICS/build-msan +make -j2 + +./sanitizer_tests.sh diff --git a/sanitizers-19/helics_build_run_tsan.sh b/sanitizers-19/helics_build_run_tsan.sh new file mode 100644 index 0000000..3b64cab --- /dev/null +++ b/sanitizers-19/helics_build_run_tsan.sh @@ -0,0 +1,10 @@ +#!/usr/bin/bash +git clone --recurse-submodules --branch develop https://github.com/GMLC-TDC/HELICS.git +cd HELICS +mkdir build-tsan +cd build-tsan +cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_FLAGS="${TSAN_CFLAGS}" -DHELICS_BUILD_TESTS=ON -DHELICS_ZMQ_SUBPROJECT=ON -DHELICS_ZMQ_FORCE_SUBPROJECT=ON +cd /root/develop/HELICS/build-tsan +make -j2 + +./sanitizer_tests.sh diff --git a/sanitizers-19/sanitizer_tests.sh b/sanitizers-19/sanitizer_tests.sh new file mode 100644 index 0000000..a3a6dc7 --- /dev/null +++ b/sanitizers-19/sanitizer_tests.sh @@ -0,0 +1,19 @@ +#!/bin/bash +tests=( + tests/helics/core/core-tests + tests/helics/common/common-tests + "tests/helics/system_tests/system-tests --gtest_filter=-*realtime*" + build/tests/helics/apps/helics_apps-tests +) + +SUMRESULT=0 +for test in "${tests[@]}"; do + echo "${test}" + eval "${test}" + RESULT=$? + echo "***Latest test result: "${RESULT} + SUMRESULT=$(( SUMRESULT + RESULT )) +done +# Return 0 or a positive integer for failure +exit ${SUMRESULT} +