From 8983e981351980d47ac2f09392408cb72ad1dd75 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Thu, 2 Jul 2020 10:26:43 -0400 Subject: [PATCH 01/26] Merge #18288: build: Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BACKPORT NOTE: File ci/test/00_setup_env_native_msan.sh has NO_BDB instead NO_WALLET because #19077 is already backported to dash core ----- 870f0cd2a0534d54bba18190e9f024f88e832933 build: Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory (practicalswift) Pull request description: Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory. First UBSan, then ASan followed by TSan... and now: yes, the wait is over -- **MSan is finally here!** :) Some historical context: * 2017: Continuous compilation with Clang Thread Safety analysis enabled (#10866, #10923) * 2018: Continuous testing with trapping on signed integer overflows (`-ftrapv`) (#12686) * 2018: Continuous testing of use of locale dependent functions (#13041) * 2018: Continuous testing of format strings (#13705) * 2018: Continuous compilation with MSVC `TreatWarningAsError` (#14151) * 2018: Continuous testing under UndefinedBehaviorSanitizer – UBSan (#14252, #14673, #17006) * 2018: Continuous testing under AddressSanitizer – ASan (#14794, #17205, #17674) * 2018: Continuous testing under ThreadSanitizer – TSan (#14829) * 2019: Continuous testing in an unsigned char environment (`-funsigned-char`) (#15134) * 2019: Continuous compile-time testing of assumptions we're making (#15391) * 2019: Continuous testing of fuzz test cases under Valgrind (#17633, #18159, #18166) * 2020: Finally... MemorySanitizer – MSAN! :) What is the next step? What tools should we add to CI to keep bugs from entering `master`? :) ACKs for top commit: MarcoFalke: Co-authored-by: MarcoFalke --- ci/dash/build_src.sh | 8 ++++++++ ci/dash/matrix.sh | 2 ++ ci/test/00_setup_env_native_msan.sh | 22 ++++++++++++++++++++++ ci/test/04_install.sh | 9 +++++++++ ci/test/05_before_script.sh | 8 ++++++++ 5 files changed, 49 insertions(+) create mode 100644 ci/test/00_setup_env_native_msan.sh diff --git a/ci/dash/build_src.sh b/ci/dash/build_src.sh index 391224587271..d26a31001079 100755 --- a/ci/dash/build_src.sh +++ b/ci/dash/build_src.sh @@ -47,6 +47,14 @@ bash -c "${MAYBE_BEAR} ${MAYBE_TOKEN} make ${MAKEJOBS} ${GOAL}" || ( echo "Build ccache --version | head -n 1 && ccache --show-stats +if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then + # MemorySanitizer (MSAN) does not support tracking memory initialization done by + # using the Linux getrandom syscall. Avoid using getrandom by undefining + # HAVE_SYS_GETRANDOM. See https://github.com/google/sanitizers/issues/852 for + # details. + bash -c 'grep -v HAVE_SYS_GETRANDOM src/config/bitcoin-config.h > src/config/bitcoin-config.h.tmp && mv src/config/bitcoin-config.h.tmp src/config/bitcoin-config.h' +fi + if [ -n "$USE_VALGRIND" ]; then echo "valgrind in USE!" "${BASE_ROOT_DIR}/ci/test/wrap-valgrind.sh" diff --git a/ci/dash/matrix.sh b/ci/dash/matrix.sh index e54e279422c4..26ea6d1fc10f 100755 --- a/ci/dash/matrix.sh +++ b/ci/dash/matrix.sh @@ -22,6 +22,8 @@ elif [ "$BUILD_TARGET" = "linux64" ]; then source ./ci/test/00_setup_env_native_qt5.sh elif [ "$BUILD_TARGET" = "linux64_asan" ]; then source ./ci/test/00_setup_env_native_asan.sh +elif [ "$BUILD_TARGET" = "linux64_msan" ]; then + source ./ci/test/00_setup_env_native_msan.sh elif [ "$BUILD_TARGET" = "linux64_fuzz" ]; then source ./ci/test/00_setup_env_native_fuzz.sh elif [ "$BUILD_TARGET" = "linux64_multiprocess" ]; then diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh new file mode 100644 index 000000000000..e477001a390b --- /dev/null +++ b/ci/test/00_setup_env_native_msan.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2020 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +export LC_ALL=C.UTF-8 + +export DOCKER_NAME_TAG="ubuntu:20.04" +LIBCXX_DIR="${BASE_ROOT_DIR}/ci/scratch/msan/build/" +export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" +LIBCXX_FLAGS="-nostdinc++ -stdlib=libc++ -L${LIBCXX_DIR}lib -lc++abi -I${LIBCXX_DIR}include -I${LIBCXX_DIR}include/c++/v1 -lpthread -Wl,-rpath,${LIBCXX_DIR}lib -Wno-unused-command-line-argument" +export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" +export BDB_PREFIX="${BASE_ROOT_DIR}/db4" + +export CONTAINER_NAME="ci_native_msan" +export PACKAGES="clang-9 llvm-9 cmake" +export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' boost_cxxflags='-std=c++11 -fvisibility=hidden -fPIC ${MSAN_AND_LIBCXX_FLAGS}' zeromq_cxxflags='-std=c++11 ${MSAN_AND_LIBCXX_FLAGS}'" +export GOAL="install" +export BITCOIN_CONFIG="--enable-wallet --with-sanitizers=memory --with-asm=no --prefix=${BASE_ROOT_DIR}/depends/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' BDB_LIBS='-L${BDB_PREFIX}/lib -ldb_cxx-4.8' BDB_CFLAGS='-I${BDB_PREFIX}/include'" +export USE_MEMORY_SANITIZER="true" +export RUN_FUNCTIONAL_TESTS="false" diff --git a/ci/test/04_install.sh b/ci/test/04_install.sh index 992d1ed19b17..f0dbe1619dcd 100755 --- a/ci/test/04_install.sh +++ b/ci/test/04_install.sh @@ -130,6 +130,15 @@ fi CI_EXEC mkdir -p "${BASE_SCRATCH_DIR}/sanitizer-output/" +if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then + DOCKER_EXEC "update-alternatives --install /usr/bin/clang++ clang++ \$(which clang++-9) 100" + DOCKER_EXEC "update-alternatives --install /usr/bin/clang clang \$(which clang-9) 100" + DOCKER_EXEC "mkdir -p ${BASE_SCRATCH_DIR}/msan/build/" + DOCKER_EXEC "git clone --depth=1 https://github.com/llvm/llvm-project -b llvmorg-10.0.0 ${BASE_SCRATCH_DIR}/msan/llvm-project" + DOCKER_EXEC "cd ${BASE_SCRATCH_DIR}/msan/build/ && cmake -DLLVM_ENABLE_PROJECTS='libcxx;libcxxabi' -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER=Memory -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_TARGETS_TO_BUILD=X86 ../llvm-project/llvm/" + DOCKER_EXEC "cd ${BASE_SCRATCH_DIR}/msan/build/ && make $MAKEJOBS cxx" +fi + if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then echo "Create $BASE_ROOT_DIR" CI_EXEC rsync -a /ro_base/ "$BASE_ROOT_DIR" diff --git a/ci/test/05_before_script.sh b/ci/test/05_before_script.sh index e8043f65dfd7..2b34c1f1c475 100755 --- a/ci/test/05_before_script.sh +++ b/ci/test/05_before_script.sh @@ -19,6 +19,14 @@ CI_EXEC mkdir -p "${DEPENDS_DIR}/SDKs" "${DEPENDS_DIR}/sdk-sources" if [ -n "$XCODE_VERSION" ] && [ ! -f "$OSX_SDK_PATH" ]; then CI_EXEC curl --location --fail "${SDK_URL}/${OSX_SDK_BASENAME}" -o "$OSX_SDK_PATH" fi + +if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then + # Use BDB compiled using install_db4.sh script to work around linking issue when using BDB + # from depends. See https://github.com/bitcoin/bitcoin/pull/18288#discussion_r433189350 for + # details. + DOCKER_EXEC "contrib/install_db4.sh \$(pwd) --enable-umrw CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +fi + if [ -n "$XCODE_VERSION" ] && [ -f "$OSX_SDK_PATH" ]; then CI_EXEC tar -C "${DEPENDS_DIR}/SDKs" -xf "$OSX_SDK_PATH" fi From f05d45825e49dba9fb51f2c4e8226c092688eb78 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 4 May 2021 17:04:39 +0200 Subject: [PATCH 02/26] Merge bitcoin/bitcoin#21852: ci: Add msan fuzz config BACKPORT NOTE: missing changes seems irrelevant ---- fa0422c251ac7e23a01f4f504cdfcf7878657c1f ci: Add msan fuzz config (MarcoFalke) fa399a76c6f222200c144041c144da88eebfec38 ci: Use clang-12 in msan task (MarcoFalke) fab30174af7548ead6d858225e74024925d3445f ci: Set BASE_SCRATCH_DIR early, so that it can be used in test configs (MarcoFalke) Pull request description: Similar to the valgrind config, this config is not run by any ci task in this repo, but it can be used by other repos or self-hosted infrastructure. ACKs for top commit: practicalswift: cr ACK fa0422c251ac7e23a01f4f504cdfcf7878657c1f: patch looks correct Tree-SHA512: 2122ac0948978a7b952efc80d4aa3674b27d48c6166e0ce917c61ac4ee6b68d701a83e5f71ee6868c208885ee45aae409ca022ebcb23ccbe37819a8c36e34872 Co-authored-by: MarcoFalke --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 24 +++++++++++++++++++ ci/test/00_setup_env_native_msan.sh | 4 ++-- ci/test/04_install.sh | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 ci/test/00_setup_env_native_fuzz_with_msan.sh diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh new file mode 100644 index 000000000000..48208fe5a1eb --- /dev/null +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2020 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +export LC_ALL=C.UTF-8 + +export DOCKER_NAME_TAG="ubuntu:20.04" +LIBCXX_DIR="${BASE_SCRATCH_DIR}/msan/build/" +export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" +LIBCXX_FLAGS="-nostdinc++ -stdlib=libc++ -L${LIBCXX_DIR}lib -lc++abi -I${LIBCXX_DIR}include -I${LIBCXX_DIR}include/c++/v1 -lpthread -Wl,-rpath,${LIBCXX_DIR}lib -Wno-unused-command-line-argument" +export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" + +export CONTAINER_NAME="ci_native_msan" +export PACKAGES="clang-9 llvm-9 cmake" +export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' boost_cxxflags='-std=c++17 -fvisibility=hidden -fPIC ${MSAN_AND_LIBCXX_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" +export GOAL="install" +export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export USE_MEMORY_SANITIZER="true" +export RUN_UNIT_TESTS="false" +export RUN_FUNCTIONAL_TESTS="false" +export RUN_FUZZ_TESTS=true +export CCACHE_SIZE=250M diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index e477001a390b..bfa1d916a058 100644 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -7,7 +7,7 @@ export LC_ALL=C.UTF-8 export DOCKER_NAME_TAG="ubuntu:20.04" -LIBCXX_DIR="${BASE_ROOT_DIR}/ci/scratch/msan/build/" +LIBCXX_DIR="${BASE_SCRATCH_DIR}/msan/build/" export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" LIBCXX_FLAGS="-nostdinc++ -stdlib=libc++ -L${LIBCXX_DIR}lib -lc++abi -I${LIBCXX_DIR}include -I${LIBCXX_DIR}include/c++/v1 -lpthread -Wl,-rpath,${LIBCXX_DIR}lib -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" @@ -17,6 +17,6 @@ export CONTAINER_NAME="ci_native_msan" export PACKAGES="clang-9 llvm-9 cmake" export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' boost_cxxflags='-std=c++11 -fvisibility=hidden -fPIC ${MSAN_AND_LIBCXX_FLAGS}' zeromq_cxxflags='-std=c++11 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--enable-wallet --with-sanitizers=memory --with-asm=no --prefix=${BASE_ROOT_DIR}/depends/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' BDB_LIBS='-L${BDB_PREFIX}/lib -ldb_cxx-4.8' BDB_CFLAGS='-I${BDB_PREFIX}/include'" +export BITCOIN_CONFIG="--enable-wallet --with-sanitizers=memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' BDB_LIBS='-L${BDB_PREFIX}/lib -ldb_cxx-4.8' BDB_CFLAGS='-I${BDB_PREFIX}/include'" export USE_MEMORY_SANITIZER="true" export RUN_FUNCTIONAL_TESTS="false" diff --git a/ci/test/04_install.sh b/ci/test/04_install.sh index f0dbe1619dcd..742f1e8238a3 100755 --- a/ci/test/04_install.sh +++ b/ci/test/04_install.sh @@ -134,7 +134,7 @@ if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then DOCKER_EXEC "update-alternatives --install /usr/bin/clang++ clang++ \$(which clang++-9) 100" DOCKER_EXEC "update-alternatives --install /usr/bin/clang clang \$(which clang-9) 100" DOCKER_EXEC "mkdir -p ${BASE_SCRATCH_DIR}/msan/build/" - DOCKER_EXEC "git clone --depth=1 https://github.com/llvm/llvm-project -b llvmorg-10.0.0 ${BASE_SCRATCH_DIR}/msan/llvm-project" + DOCKER_EXEC "git clone --depth=1 https://github.com/llvm/llvm-project -b llvmorg-12.0.0 ${BASE_SCRATCH_DIR}/msan/llvm-project" DOCKER_EXEC "cd ${BASE_SCRATCH_DIR}/msan/build/ && cmake -DLLVM_ENABLE_PROJECTS='libcxx;libcxxabi' -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER=Memory -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_TARGETS_TO_BUILD=X86 ../llvm-project/llvm/" DOCKER_EXEC "cd ${BASE_SCRATCH_DIR}/msan/build/ && make $MAKEJOBS cxx" fi From 15e829bd49337935b76ea7b73fa2e0de5dd43d01 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 5 May 2021 21:05:33 +0200 Subject: [PATCH 03/26] Merge bitcoin/bitcoin#21864: fix permissions on 00_setup_env_native_fuzz_with_msan.sh d48565d10968171edeeb75c1a0af8f4119bb99bc fix permissions on 00_setup_env_native_fuzz_with_msan (glozow) Pull request description: I think there was a silent merge conflict between #21852 and #21740? I have a [linter failure](https://cirrus-ci.com/task/5436849834426368): ``` File "ci/test/00_setup_env_native_fuzz_with_msan.sh" contains a shebang line, but has the file permission 644 instead of the expected executable permission 755. Do "chmod 755 ci/test/00_setup_env_native_fuzz_with_msan.sh" (or remove the shebang line). ERROR: There were 1 failed tests in the lint-files.py lint test. Please resolve the above errors. ^---- failure generated from test/lint/lint-files.sh ``` ACKs for top commit: MarcoFalke: ACK d48565d10968171edeeb75c1a0af8f4119bb99bc Tree-SHA512: 445bdd738faf007451f40bbcf360dd1fb4675e17a4c96546e6818c12e33dd336dadd95cf8d4b5f8df1d6ccfbc4bf5496864bb5528e416cea894857b6b732140c Co-authored-by: MarcoFalke --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 ci/test/00_setup_env_native_fuzz_with_msan.sh diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh old mode 100644 new mode 100755 From 7d95295c9777cfef5793308f0f6c23556b6a7832 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Thu, 6 May 2021 14:00:32 +0800 Subject: [PATCH 04/26] Merge bitcoin/bitcoin#21865: ci: Properly pass msan cflags fa3bbcf81e11a1753010421381fc386819e1e88c ci: Properly pass msan cflags (MarcoFalke) Pull request description: Uninstrumented libraries might cause false positives with msan. Fixes #21632 ACKs for top commit: practicalswift: cr ACK fa3bbcf81e11a1753010421381fc386819e1e88c: patch looks correct fanquake: ACK fa3bbcf81e11a1753010421381fc386819e1e88c Tree-SHA512: 55af961f3d422074bed4eec15df6b8d03cf5d7687a2ca5ea04c2591c0292ad3749db821d6160ba0e4458f0dcf448f0b2f05cc496314839264ddc8b89cced9e14 Co-authored-by: fanquake --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 2 +- ci/test/00_setup_env_native_msan.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) mode change 100644 => 100755 ci/test/00_setup_env_native_msan.sh diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index 48208fe5a1eb..d5b28ca5cf02 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -14,7 +14,7 @@ export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_msan" export PACKAGES="clang-9 llvm-9 cmake" -export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' boost_cxxflags='-std=c++17 -fvisibility=hidden -fPIC ${MSAN_AND_LIBCXX_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" +export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' boost_cxxflags='-std=c++17 -fvisibility=hidden -fPIC ${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh old mode 100644 new mode 100755 index bfa1d916a058..7bcf9f23a2b9 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -15,8 +15,9 @@ export BDB_PREFIX="${BASE_ROOT_DIR}/db4" export CONTAINER_NAME="ci_native_msan" export PACKAGES="clang-9 llvm-9 cmake" -export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' boost_cxxflags='-std=c++11 -fvisibility=hidden -fPIC ${MSAN_AND_LIBCXX_FLAGS}' zeromq_cxxflags='-std=c++11 ${MSAN_AND_LIBCXX_FLAGS}'" +export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' boost_cxxflags='-std=c++17 -fvisibility=hidden -fPIC ${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" export BITCOIN_CONFIG="--enable-wallet --with-sanitizers=memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' BDB_LIBS='-L${BDB_PREFIX}/lib -ldb_cxx-4.8' BDB_CFLAGS='-I${BDB_PREFIX}/include'" export USE_MEMORY_SANITIZER="true" export RUN_FUNCTIONAL_TESTS="false" +export CCACHE_SIZE=250M From 573bd4f640f0f7f012ab53b9f47efca86fe49e4c Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 18 Feb 2022 17:47:55 +0100 Subject: [PATCH 05/26] Merge bitcoin/bitcoin#24384: ci: remove `boost_cxxflags` from MSAN CIs 7e02adf78d8a5816ec1490d0528a625d149b7d1e ci: add missing sqlite_cflags to MSAN fuzz job (fanquake) 54d817c5b9f6adbcd19d24ce9bee6751b9cd0fd2 ci: remove boost_cxxflags from MSAN CIs (fanquake) Pull request description: No-longer needed after #24301. Add missing sqlite_cflags. ACKs for top commit: MarcoFalke: cr ACK 7e02adf78d8a5816ec1490d0528a625d149b7d1e Tree-SHA512: df7588e1380661d2777f2d2d0ba25546eb25fb9e398e37d69d888f5e5250abbbeabc5b92df6a7a781743ad0b7ab5acb9b0110de247f8dbb1b1862b424bcbeadd Co-authored-by: MarcoFalke --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 2 +- ci/test/00_setup_env_native_msan.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index d5b28ca5cf02..abbde239cf33 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -14,7 +14,7 @@ export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_msan" export PACKAGES="clang-9 llvm-9 cmake" -export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' boost_cxxflags='-std=c++17 -fvisibility=hidden -fPIC ${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" +export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index 7bcf9f23a2b9..e4fafa64e640 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -15,7 +15,7 @@ export BDB_PREFIX="${BASE_ROOT_DIR}/db4" export CONTAINER_NAME="ci_native_msan" export PACKAGES="clang-9 llvm-9 cmake" -export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' boost_cxxflags='-std=c++17 -fvisibility=hidden -fPIC ${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" +export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" export BITCOIN_CONFIG="--enable-wallet --with-sanitizers=memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' BDB_LIBS='-L${BDB_PREFIX}/lib -ldb_cxx-4.8' BDB_CFLAGS='-I${BDB_PREFIX}/include'" export USE_MEMORY_SANITIZER="true" From 6210fb8911dfe97374c08d9baa3fe919ec34dce6 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Thu, 10 Mar 2022 15:22:03 +0100 Subject: [PATCH 06/26] Merge bitcoin/bitcoin#24522: ci: remove compiled-but-unused BDB from MSAN job 3566353c5e8c699f5da80cb3f8081e407f1b5813 ci: remove compiled-but-unused BDB from MSAN job (fanquake) Pull request description: Self-compiled BDB was added to this job as opposed to using depends BDB [due to linking issues](https://github.com/bitcoin/bitcoin/pull/18288#discussion_r433189350), however the compiled BDB is not actually used. Remove it for now, given we don't actually lose any coverage (note that BDB is also not currently used in the naitve MSAN fuzz job or for [OSS Fuzz](https://github.com/google/oss-fuzz/blob/master/projects/bitcoin-core/build.sh#L32) builds). In future, we can use depends BDB, however introducing it now will cause false positives, which can be fixed by upgrading the versions of Clang / LLVM we use, however upgrading to those newer versions causes other issues, which appear in standard library code, and require more involved suppressing, which can be solved in a follow up or another PR i.e #23008. Top commit has no ACKs. Tree-SHA512: 9e8fdd95246cafa27cda7bcf0641b428d4573f6748ecdf07cc6205a64351db22ba383ec943e88a69df3694ccb9f125d994b64345a4e44fb6fea4a014504760d1 Co-authored-by: MarcoFalke --- ci/test/00_setup_env_native_msan.sh | 3 +-- ci/test/05_before_script.sh | 7 ------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index e4fafa64e640..03b157e8a770 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -11,13 +11,12 @@ LIBCXX_DIR="${BASE_SCRATCH_DIR}/msan/build/" export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" LIBCXX_FLAGS="-nostdinc++ -stdlib=libc++ -L${LIBCXX_DIR}lib -lc++abi -I${LIBCXX_DIR}include -I${LIBCXX_DIR}include/c++/v1 -lpthread -Wl,-rpath,${LIBCXX_DIR}lib -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" -export BDB_PREFIX="${BASE_ROOT_DIR}/db4" export CONTAINER_NAME="ci_native_msan" export PACKAGES="clang-9 llvm-9 cmake" export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--enable-wallet --with-sanitizers=memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' BDB_LIBS='-L${BDB_PREFIX}/lib -ldb_cxx-4.8' BDB_CFLAGS='-I${BDB_PREFIX}/include'" +export BITCOIN_CONFIG="--enable-wallet --with-sanitizers=memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" export RUN_FUNCTIONAL_TESTS="false" export CCACHE_SIZE=250M diff --git a/ci/test/05_before_script.sh b/ci/test/05_before_script.sh index 2b34c1f1c475..fa72e95dead1 100755 --- a/ci/test/05_before_script.sh +++ b/ci/test/05_before_script.sh @@ -20,13 +20,6 @@ if [ -n "$XCODE_VERSION" ] && [ ! -f "$OSX_SDK_PATH" ]; then CI_EXEC curl --location --fail "${SDK_URL}/${OSX_SDK_BASENAME}" -o "$OSX_SDK_PATH" fi -if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then - # Use BDB compiled using install_db4.sh script to work around linking issue when using BDB - # from depends. See https://github.com/bitcoin/bitcoin/pull/18288#discussion_r433189350 for - # details. - DOCKER_EXEC "contrib/install_db4.sh \$(pwd) --enable-umrw CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" -fi - if [ -n "$XCODE_VERSION" ] && [ -f "$OSX_SDK_PATH" ]; then CI_EXEC tar -C "${DEPENDS_DIR}/SDKs" -xf "$OSX_SDK_PATH" fi From b906c20488da36fa81b65f5eaf16fd88eca70eee Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 29 Mar 2022 13:27:37 +0200 Subject: [PATCH 07/26] Merge bitcoin/bitcoin#24705: ci: note why bdb is disabled in msan jobs 527eeaf580b8204aea05e1bcec1a8626e71ab701 ci: note why BDB is disabled for MSAN jobs (fanquake) d6c71b0ccf533bca7af7603f26760612cd9f6e71 ci: remove explicit --enable-wallet from msan job (fanquake) Pull request description: Closes #24703. Top commit has no ACKs. Tree-SHA512: 231a52a0a1f55ecabf5b4f816dbc9ff4bc349bf3a247939fc75fee95454aff9fde04c9723b620a24e5a7993bd9bad7de5de1b0fd3c6cacc6297b7a64606e3a29 Co-authored-by: MarcoFalke --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 1 + ci/test/00_setup_env_native_msan.sh | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index abbde239cf33..72bf6be2bac5 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -14,6 +14,7 @@ export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_msan" export PACKAGES="clang-9 llvm-9 cmake" +# BDB generates false-positives and will be removed in future export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index 03b157e8a770..4ec97355a747 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -14,9 +14,10 @@ export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_msan" export PACKAGES="clang-9 llvm-9 cmake" +# BDB generates false-positives and will be removed in future export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--enable-wallet --with-sanitizers=memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export BITCOIN_CONFIG="--with-sanitizers=memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" export RUN_FUNCTIONAL_TESTS="false" export CCACHE_SIZE=250M From 8be042bf0fb1c965100d6eff42797958a802c80f Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 30 Mar 2022 19:19:24 +0100 Subject: [PATCH 08/26] Merge bitcoin/bitcoin#23008: ci: Use clang-12 and libcxx-12 for msan fa73f8a4695d5bcbd054f4c68ee2a648c808afd2 ci: Use clang-12 and libcxx-12 for msan (MarcoFalke) Pull request description: Run the latest sanitizers to get the most implemented features ACKs for top commit: fanquake: ACK fa73f8a4695d5bcbd054f4c68ee2a648c808afd2 - `--disable-hardening` matches what was just added to oss-fuzz. Tree-SHA512: 2e533bb9273c97600176be2e41069a03f425aa586f9f32b8ed5f0c9844215a3a41e95a8edd58d044386e350807d6a1df09008a7da35428abd185a509ca71bd82 Co-authored-by: fanquake --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 4 ++-- ci/test/00_setup_env_native_msan.sh | 4 ++-- ci/test/04_install.sh | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index 72bf6be2bac5..648393792fbe 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -13,11 +13,11 @@ LIBCXX_FLAGS="-nostdinc++ -stdlib=libc++ -L${LIBCXX_DIR}lib -lc++abi -I${LIBCXX_ export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_msan" -export PACKAGES="clang-9 llvm-9 cmake" +export PACKAGES="clang-12 llvm-12 cmake" # BDB generates false-positives and will be removed in future export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" export RUN_UNIT_TESTS="false" export RUN_FUNCTIONAL_TESTS="false" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index 4ec97355a747..b4f93db3de71 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -13,11 +13,11 @@ LIBCXX_FLAGS="-nostdinc++ -stdlib=libc++ -L${LIBCXX_DIR}lib -lc++abi -I${LIBCXX_ export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_msan" -export PACKAGES="clang-9 llvm-9 cmake" +export PACKAGES="clang-12 llvm-12 cmake" # BDB generates false-positives and will be removed in future export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--with-sanitizers=memory --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" export RUN_FUNCTIONAL_TESTS="false" export CCACHE_SIZE=250M diff --git a/ci/test/04_install.sh b/ci/test/04_install.sh index 742f1e8238a3..8f20cf3f3a8f 100755 --- a/ci/test/04_install.sh +++ b/ci/test/04_install.sh @@ -131,11 +131,11 @@ fi CI_EXEC mkdir -p "${BASE_SCRATCH_DIR}/sanitizer-output/" if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then - DOCKER_EXEC "update-alternatives --install /usr/bin/clang++ clang++ \$(which clang++-9) 100" - DOCKER_EXEC "update-alternatives --install /usr/bin/clang clang \$(which clang-9) 100" + DOCKER_EXEC "update-alternatives --install /usr/bin/clang++ clang++ \$(which clang++-12) 100" + DOCKER_EXEC "update-alternatives --install /usr/bin/clang clang \$(which clang-12) 100" DOCKER_EXEC "mkdir -p ${BASE_SCRATCH_DIR}/msan/build/" DOCKER_EXEC "git clone --depth=1 https://github.com/llvm/llvm-project -b llvmorg-12.0.0 ${BASE_SCRATCH_DIR}/msan/llvm-project" - DOCKER_EXEC "cd ${BASE_SCRATCH_DIR}/msan/build/ && cmake -DLLVM_ENABLE_PROJECTS='libcxx;libcxxabi' -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER=Memory -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_TARGETS_TO_BUILD=X86 ../llvm-project/llvm/" + DOCKER_EXEC "cd ${BASE_SCRATCH_DIR}/msan/build/ && cmake -DLLVM_ENABLE_PROJECTS='libcxx;libcxxabi' -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER=MemoryWithOrigins -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_TARGETS_TO_BUILD=X86 ../llvm-project/llvm/" DOCKER_EXEC "cd ${BASE_SCRATCH_DIR}/msan/build/ && make $MAKEJOBS cxx" fi From f3e8c2644a95dd1b2bd4ebe996c74c6df8b269fd Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 28 Nov 2022 10:20:00 +0100 Subject: [PATCH 09/26] Merge bitcoin/bitcoin#26574: ci: use ci_exec_root for clang install 54dd8f51ce8815a93a6aceb36dd72bd449d6b327 ci: use ci_exec_root for clang install (josibake) Pull request description: fixes a bug introduced in #25900 ; see https://github.com/bitcoin/bitcoin/pull/25900#issuecomment-1327311069 the general idea of #25900 was to use a non-root user as much as possible to avoid modifying the user's local filesystem. however, it appears the root user is needed to correctly install clang. ACKs for top commit: hebasto: ACK 54dd8f51ce8815a93a6aceb36dd72bd449d6b327, tested on Ubuntu 22.04. Tree-SHA512: beb01d4b6127fbba3c8d18e85cf7ec7d1b2ec93ea05c475ab51bcaa04ef1b0591d886f1a7e0732c5ae86806013f022c0b44027380d2b0cfb1bfdc843e40f99b4 Co-authored-by: MarcoFalke --- ci/test/04_install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test/04_install.sh b/ci/test/04_install.sh index 8f20cf3f3a8f..fa0195acc989 100755 --- a/ci/test/04_install.sh +++ b/ci/test/04_install.sh @@ -131,8 +131,8 @@ fi CI_EXEC mkdir -p "${BASE_SCRATCH_DIR}/sanitizer-output/" if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then - DOCKER_EXEC "update-alternatives --install /usr/bin/clang++ clang++ \$(which clang++-12) 100" - DOCKER_EXEC "update-alternatives --install /usr/bin/clang clang \$(which clang-12) 100" + CI_EXEC_ROOT "update-alternatives --install /usr/bin/clang++ clang++ \$(which clang++-12) 100" + CI_EXEC_ROOT "update-alternatives --install /usr/bin/clang clang \$(which clang-12) 100" DOCKER_EXEC "mkdir -p ${BASE_SCRATCH_DIR}/msan/build/" DOCKER_EXEC "git clone --depth=1 https://github.com/llvm/llvm-project -b llvmorg-12.0.0 ${BASE_SCRATCH_DIR}/msan/llvm-project" DOCKER_EXEC "cd ${BASE_SCRATCH_DIR}/msan/build/ && cmake -DLLVM_ENABLE_PROJECTS='libcxx;libcxxabi' -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER=MemoryWithOrigins -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_TARGETS_TO_BUILD=X86 ../llvm-project/llvm/" From cf0e58f0d3b4583a77e4c1a13d6ccd3439949639 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 21 Dec 2022 09:01:48 +0000 Subject: [PATCH 10/26] partial Merge bitcoin/bitcoin#26683: ci: Use `CONFIG_SITE` variable and `--prefix` option properly BACKPORT NOTE: Taking that PR in full broke every target that needs depends. aarch64-linux fails at configure with configure: error: Boost is not available! ci/test/00_setup_env_aarch64.sh passes no --host and no depends paths; it sets HOST and leaves the rest to depends' config.site, which supplies host_alias, cross_compiling and with_boost. Moving --prefix off the depends prefix and dropping --bindir/--libdir removes what the cross builds rely on, so configure looks for a native Boost in a container that has none for arm64. The rewrite was not needed by the msan work either. The compiler reaches configure through the msan target's own BITCOIN_CONFIG. Upstream can use CONFIG_SITE with --prefix=$BASE_OUTDIR because its CI copies the tree into the container and its paths line up. Adopting that here is a prerequisite change in its own right - it is what would let Dash run a NO_DEPENDS=1 build the way upstream's asan job does - and it needs the depends and workflow paths sorted out first, not a drive-by inside an msan series. -------------- d3a84347e812b746a555e895594c595982815081 ci: remove --prefix from msan job (fanquake) 574e50addf8c65a3a9e0f2d8e933c147d1e93932 ci: Use `CONFIG_SITE` variable and `--prefix` option properly (Hennadii Stepanov) Pull request description: When running CI scripts locally, they attempt to use a `$DEPENDS_DIR/$HOST` directory even `NO_DEPENDS=1` is provided. This PR fixes this broken behavior. Top commit has no ACKs. Tree-SHA512: 5e83b921763e6d463e520bbee2ed1599e9f4de36668d19b23dd9d2d7e4441c415e275f588c585b72cadda8bfab5a938979acc1ee4963230aa47081785c741e98 Co-authored-by: fanquake --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 2 +- ci/test/00_setup_env_native_msan.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index 648393792fbe..7f934adb97af 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -17,7 +17,7 @@ export PACKAGES="clang-12 llvm-12 cmake" # BDB generates false-positives and will be removed in future export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" export RUN_UNIT_TESTS="false" export RUN_FUNCTIONAL_TESTS="false" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index b4f93db3de71..5d8379eb057c 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -17,7 +17,7 @@ export PACKAGES="clang-12 llvm-12 cmake" # BDB generates false-positives and will be removed in future export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening --with-asm=no --prefix=${DEPENDS_DIR}/x86_64-pc-linux-gnu/ CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening --with-asm=no CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" export RUN_FUNCTIONAL_TESTS="false" export CCACHE_SIZE=250M From b67d12af8b760aae6693d2e1b9e92f8fabed6a43 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 9 Jan 2023 09:46:14 +0100 Subject: [PATCH 11/26] Merge bitcoin/bitcoin#26843: ci: Fix ci_native_fuzz_msan CONTAINER_NAME fa4e98c77f8c6b693b88c1a6bb811650a6267fdb ci: Fix ci_native_fuzz_msan CONTAINER_NAME (MarcoFalke) Pull request description: This avoids a duplicate name with the other msan task, which will lead to errors when running locally: > Error: creating container storage: the container name "ci_native_msan" is already in use by 77350e26f9c36abbb601140cd0b485ead093ff118803c720ca8b10f6bdfa37d2. You have to remove that container to be able to reuse that name: that name is already in use ACKs for top commit: fanquake: ACK fa4e98c77f8c6b693b88c1a6bb811650a6267fdb hebasto: ACK fa4e98c77f8c6b693b88c1a6bb811650a6267fdb, I've verified that there are no other duplicated `CONTAINER_NAME`'s values. Tree-SHA512: f1b28b21302c0947912d642c12c2ccad236af6824fd27e68341baddedec24087af738f3226028a0eeb6e0fc7e9f90713fc680855eeb07adc113c4f6e8b03a545 Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index 7f934adb97af..7117d049ba9c 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -12,7 +12,7 @@ export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit LIBCXX_FLAGS="-nostdinc++ -stdlib=libc++ -L${LIBCXX_DIR}lib -lc++abi -I${LIBCXX_DIR}include -I${LIBCXX_DIR}include/c++/v1 -lpthread -Wl,-rpath,${LIBCXX_DIR}lib -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" -export CONTAINER_NAME="ci_native_msan" +export CONTAINER_NAME="ci_native_fuzz_msan" export PACKAGES="clang-12 llvm-12 cmake" # BDB generates false-positives and will be removed in future export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" From df22d6a3adf8606d57afe54c4a8805790d82d879 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 30 Jan 2023 14:31:43 +0000 Subject: [PATCH 12/26] Merge bitcoin/bitcoin#23619: build: Propagate user-defined flags to host packages a3a2bd9e8ad360a63cc8bdfc365d8bfd25ecc720 ci: Drop no longer needed package-specific flags (Hennadii Stepanov) 071eef1e974f128131afe6c6b5c68a430c64687a build: Propagate user-defined flags to host packages (Hennadii Stepanov) Pull request description: On master (4f8b1f8759301d2553183e14f72444a0f1d80725) `{CPP,C,CXX,LD}FLAGS` that are specified in the command line are not propagated to packages: ``` $ make --no-print-directory -C depends print-libevent_cxxflags CXXFLAGS=-some-fancy-flag libevent_cxxflags=-pipe -O2 ``` This PR: - propagates `{CPP,C,CXX,LD}FLAGS` to host packages: ``` $ make --no-print-directory -C depends print-libevent_cxxflags CXXFLAGS=-some-fancy-flag libevent_cxxflags= -some-fancy-flag ``` - does not propagate `{CPP,C,CXX,LD}FLAGS` to native packages: ``` $ make --no-print-directory -C depends print-native_b2_cxxflags CXXFLAGS=-some-fancy-flag native_b2_cxxflags= ``` - actually addresses the https://github.com/bitcoin/bitcoin/pull/23551#issuecomment-973896518 ACKs for top commit: TheCharlatan: Code review ACK a3a2bd9e8ad360a63cc8bdfc365d8bfd25ecc720 Tree-SHA512: 243d6b1b0e9c5de46debc36de62a77b6b4d6f638940fd530040c219956ec624e321b0c25290fed164e3a8c88befa7b97b20f765d7b9a428c269b3720f21da099 Co-authored-by: fanquake --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 2 +- ci/test/00_setup_env_native_msan.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index 7117d049ba9c..187e218ba842 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -15,7 +15,7 @@ export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_fuzz_msan" export PACKAGES="clang-12 llvm-12 cmake" # BDB generates false-positives and will be removed in future -export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" +export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index 5d8379eb057c..007d4b3a1495 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -15,7 +15,7 @@ export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_msan" export PACKAGES="clang-12 llvm-12 cmake" # BDB generates false-positives and will be removed in future -export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' libevent_cflags='${MSAN_FLAGS}' sqlite_cflags='${MSAN_FLAGS}' zeromq_cxxflags='-std=c++17 ${MSAN_AND_LIBCXX_FLAGS}'" +export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening --with-asm=no CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" From 591ddaee798e6e0363203514570e54cc0758a2ac Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 11 Apr 2023 10:51:33 +0100 Subject: [PATCH 13/26] Merge bitcoin/bitcoin#27436: test: LLVM/Clang 16 for MSAN jobs 676671527f08ef8113af3661de73db583f6ea9e2 test: LLVM/Clang 16 for MSAN jobs (fanquake) Pull request description: Similar to other CI infra changes we've made recently. Move to LLVM/Clang 16 for the MSAN jobs (which is currently using LLVM 12). See also: https://releases.llvm.org/16.0.0/tools/clang/docs/ReleaseNotes.html#sanitizers: > `-fsanitize-memory-param-retval` is turned on by default. With `-fsanitize=memory`, passing uninitialized variables to functions and returning uninitialized variables from functions is more aggressively reported. `-fno-sanitize-memory-param-retval` restores the previous behavior. ACKs for top commit: dergoegge: utACK 676671527f08ef8113af3661de73db583f6ea9e2 Tree-SHA512: a105bd1bf7f4e3ede50bb119fd8ab7f308919dc46e093eb3e94351484d65a13220e2449c40d80b8103b9ac0f4b1c8ca29576ab83e2083c26b9d8060c5802b64d Co-authored-by: fanquake --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 6 +++--- ci/test/00_setup_env_native_msan.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index 187e218ba842..35a0de8034e6 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -1,19 +1,19 @@ #!/usr/bin/env bash # -# Copyright (c) 2020 The Bitcoin Core developers +# Copyright (c) 2020-2022 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. export LC_ALL=C.UTF-8 -export DOCKER_NAME_TAG="ubuntu:20.04" +export CI_IMAGE_NAME_TAG="ubuntu:23.04" # Version 23.04 will reach EOL in Jan 2024, and can be replaced by "ubuntu:24.04" (or anything else that ships the wanted clang version). LIBCXX_DIR="${BASE_SCRATCH_DIR}/msan/build/" export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" LIBCXX_FLAGS="-nostdinc++ -stdlib=libc++ -L${LIBCXX_DIR}lib -lc++abi -I${LIBCXX_DIR}include -I${LIBCXX_DIR}include/c++/v1 -lpthread -Wl,-rpath,${LIBCXX_DIR}lib -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_fuzz_msan" -export PACKAGES="clang-12 llvm-12 cmake" +export PACKAGES="clang-16 llvm-16 libclang-rt-16-dev cmake" # BDB generates false-positives and will be removed in future export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index 007d4b3a1495..bdb9bd7b5d87 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -1,19 +1,19 @@ #!/usr/bin/env bash # -# Copyright (c) 2020 The Bitcoin Core developers +# Copyright (c) 2020-2022 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. export LC_ALL=C.UTF-8 -export DOCKER_NAME_TAG="ubuntu:20.04" +export CI_IMAGE_NAME_TAG="ubuntu:23.04" # Version 23.04 will reach EOL in Jan 2024, and can be replaced by "ubuntu:24.04" (or anything else that ships the wanted clang version). LIBCXX_DIR="${BASE_SCRATCH_DIR}/msan/build/" export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" LIBCXX_FLAGS="-nostdinc++ -stdlib=libc++ -L${LIBCXX_DIR}lib -lc++abi -I${LIBCXX_DIR}include -I${LIBCXX_DIR}include/c++/v1 -lpthread -Wl,-rpath,${LIBCXX_DIR}lib -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_msan" -export PACKAGES="clang-12 llvm-12 cmake" +export PACKAGES="clang-16 llvm-16 libclang-rt-16-dev cmake" # BDB generates false-positives and will be removed in future export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" From dae4fc2c75afedf0677ab652f05ba21ad1a1735d Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 2 Jun 2023 10:34:40 +0100 Subject: [PATCH 14/26] Merge bitcoin/bitcoin#27737: ci: compile Clang and compiler-rt in msan jobs BACKPORT NOTE: Changes in 01_base_install.sh is emitted; this file doesn't exist in dash core repo more over this code become obsole in the future commits. ---- 5763b232e6e6a0f72d046f8aa322b39328be135b ci: return to using Ubuntu 22.04 in MSAN jobs (fanquake) d3cbcbf62693ad7394b3f8693b1c08d4271903fa ci: compile clang and compiler-rt in MSAN jobs (fanquake) 796bd1d0d147ac90f921ce3831961f97748d4e1a ci: use LLVM 16.0.4 in MSAN jobs (fanquake) 883bc9f5611648c44956a09795afd924842c1d1d ci: remove extra CC & CXX from MSAN jobs (fanquake) 2d4f4b8f29c015c26cb02b26a517450bb6056ed4 ci: standardize custom libc++ usage in MSAN jobs (fanquake) Pull request description: This reworks the MSAN CIs, to first compile Clang and compiler-rt (using GCC 12), and then, compile an MSAN instrumented libc++ using the just-built Clang 16. This fixes the `native_fuzz_with_msan` job, working around https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1005341, by not using the Debian provided Clang/LLVM. Also included are changes to streamline how we use our "custom libc++", according to upstream: https://releases.llvm.org/16.0.0/projects/libcxx/docs/UsingLibcxx.html#using-a-custom-built-libc, as well as other minor cleanups in the CI configs. An example job is currently running in the qa-assets repo: https://github.com/bitcoin-core/qa-assets/pull/129 (https://cirrus-ci.com/task/4632561431871488). ACKs for top commit: dergoegge: utACK 5763b232e6e6a0f72d046f8aa322b39328be135b Tree-SHA512: 4f2a6e0b796bb1830b8346dd1e55eaa86a79037b8b4f16a336c1e29f4fc460acca2ecba076635459370bcbb4009333cb79d27ef1521c1fb5db7599cd5bdf558c Co-authored-by: fanquake --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 12 ++++++------ ci/test/00_setup_env_native_msan.sh | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index 35a0de8034e6..1f9adc0682d5 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -6,18 +6,18 @@ export LC_ALL=C.UTF-8 -export CI_IMAGE_NAME_TAG="ubuntu:23.04" # Version 23.04 will reach EOL in Jan 2024, and can be replaced by "ubuntu:24.04" (or anything else that ships the wanted clang version). -LIBCXX_DIR="${BASE_SCRATCH_DIR}/msan/build/" +export CI_IMAGE_NAME_TAG="ubuntu:22.04" +LIBCXX_DIR="${BASE_SCRATCH_DIR}/msan/cxx_build/" export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" -LIBCXX_FLAGS="-nostdinc++ -stdlib=libc++ -L${LIBCXX_DIR}lib -lc++abi -I${LIBCXX_DIR}include -I${LIBCXX_DIR}include/c++/v1 -lpthread -Wl,-rpath,${LIBCXX_DIR}lib -Wno-unused-command-line-argument" +LIBCXX_FLAGS="-nostdinc++ -nostdlib++ -isystem ${LIBCXX_DIR}include/c++/v1 -L${LIBCXX_DIR}lib -Wl,-rpath,${LIBCXX_DIR}lib -lc++ -lc++abi -lpthread -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_fuzz_msan" -export PACKAGES="clang-16 llvm-16 libclang-rt-16-dev cmake" +export PACKAGES="cmake ninja-build" # BDB generates false-positives and will be removed in future -export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export DEP_OPTS="NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CFLAGS='${MSAN_FLAGS}' CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" export RUN_UNIT_TESTS="false" export RUN_FUNCTIONAL_TESTS="false" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index bdb9bd7b5d87..6ebea46ad0a6 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -6,18 +6,18 @@ export LC_ALL=C.UTF-8 -export CI_IMAGE_NAME_TAG="ubuntu:23.04" # Version 23.04 will reach EOL in Jan 2024, and can be replaced by "ubuntu:24.04" (or anything else that ships the wanted clang version). -LIBCXX_DIR="${BASE_SCRATCH_DIR}/msan/build/" +export CI_IMAGE_NAME_TAG="ubuntu:22.04" +LIBCXX_DIR="${BASE_SCRATCH_DIR}/msan/cxx_build/" export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" -LIBCXX_FLAGS="-nostdinc++ -stdlib=libc++ -L${LIBCXX_DIR}lib -lc++abi -I${LIBCXX_DIR}include -I${LIBCXX_DIR}include/c++/v1 -lpthread -Wl,-rpath,${LIBCXX_DIR}lib -Wno-unused-command-line-argument" +LIBCXX_FLAGS="-nostdinc++ -nostdlib++ -isystem ${LIBCXX_DIR}include/c++/v1 -L${LIBCXX_DIR}lib -Wl,-rpath,${LIBCXX_DIR}lib -lc++ -lc++abi -lpthread -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_msan" -export PACKAGES="clang-16 llvm-16 libclang-rt-16-dev cmake" +export PACKAGES="cmake ninja-build" # BDB generates false-positives and will be removed in future -export DEP_OPTS="NO_BDB=1 NO_QT=1 CC='clang' CXX='clang++' CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export DEP_OPTS="NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening --with-asm=no CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening --with-asm=no CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" export RUN_FUNCTIONAL_TESTS="false" export CCACHE_SIZE=250M From bf2cae3548907686c470122d2dfb5dcd25055b02 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 29 Jan 2024 16:41:31 +0000 Subject: [PATCH 15/26] Merge bitcoin/bitcoin#27495: ci: Use LLVM 17.0.6 & DEBUG=1 in depends for MSAN jobs BACKPORT NOTE: Changes in 01_base_install.sh is emitted; this file doesn't exist in dash core repo. More over this code become obsole in the future commits. ---- 8531e1e7312efe66204dc8ce56f21e44de99e956 ci: Use DEBUG=1 in depends for MSAN jobs (fanquake) 800ddef6b994b8b05a11f2c1c6d265daaec5751a ci: use LLVM 17.0.6 in MSAN jobs (fanquake) Pull request description: Switch to using LLVM 17.0.6 and `DEBUG=1` in MSAN CI jobs. ACKs for top commit: maflcko: lgtm ACK 8531e1e7312efe66204dc8ce56f21e44de99e956 Tree-SHA512: 819889762aeb78f95c4f955978890c6d98884bed0c7ff97ec072f4c7c1119ee3e3268ccab795bb1c801d36a206e16c6c1195e7a2bc7af94b580d17e49c632161 Co-authored-by: fanquake --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 2 +- ci/test/00_setup_env_native_msan.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index 1f9adc0682d5..aca3e4658950 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -15,7 +15,7 @@ export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_fuzz_msan" export PACKAGES="cmake ninja-build" # BDB generates false-positives and will be removed in future -export DEP_OPTS="NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CFLAGS='${MSAN_FLAGS}' CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index 6ebea46ad0a6..04e4f5a4e59e 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -15,7 +15,7 @@ export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_msan" export PACKAGES="cmake ninja-build" # BDB generates false-positives and will be removed in future -export DEP_OPTS="NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening --with-asm=no CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" From c7155fcf6a7cf8ce4317fb0caec6a57d55d18c7d Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 15 Aug 2023 11:15:51 +0100 Subject: [PATCH 16/26] partial Merge bitcoin/bitcoin#28185: ci: Use hard-coded root path for CI containers (bugfix) BACKPORT NOTE: In full it breaks the depends targets: configure: error: Boost is not available! As well it breaks msan job: ./ci/test/00_setup_env.sh: line 42: /ci_container_base/depends/config.guess: No such file or directory Upstream can hard-code BASE_ROOT_DIR=/ci_container_base because its CI starts its own container and rsyncs the read-only source tree into that path first; ci/test/04_install.sh still carries that step here. Dash's GitHub Actions workflows do not use it. They declare the image in the job's container: block and run ci/dash/*.sh directly, with the checkout left where actions/checkout put it, so /ci_container_base never exists and nothing sets DANGER_RUN_CI_ON_HOST to opt out. Everything derived from BASE_ROOT_DIR then points into a directory that is not there. DEPENDS_DIR is the one that shows: configure is given --prefix=$DEPENDS_DIR/$HOST, finds no share/config.site, and so never learns where depends put Boost, or that a cross build is a cross build. ------------- fafa17c00b87c685200198979ed13018e55e474a ci: Use hard-coded root path for CI containers (MarcoFalke) fa084f5ba5dad58a55b5a0a0e9d839c54e9a9238 ci: Only create folders when needed (MarcoFalke) fab27127f4794b57a00328bdf8e779d9db07a2f5 ci: Drop BASE_SCRATCH_DIR from LIBCXX_DIR (MarcoFalke) Pull request description: Currently the CI system will fail if the git folder that holds the Bitcoin Core source is moved from one location to another. Fix this by using a single hard-coded root path *inside* the CI system containers. Steps to test: * Run the CI system: `MAKEJOBS="-j$(nproc)" FILE_ENV="./ci/test/00_setup_env_win64.sh" ./ci/test_run_all.sh` * Move the git folder: `pwd && cd .. && mv bitcoin_core_folder_1 bitcoin_core_folder_2 && cd ./bitcoin_core_folder_2 && pwd` * Run the CI system again: (same cmd as above) On master (error): ``` STRIPPROG="x86_64-w64-mingw32-strip" /bin/bash /bitcoin_core_folder_2/ci/scratch/build/bitcoin-x86_64-w64-mingw32/build-aux/install-sh -c -s ./src/qt/bitcoin-qt.exe ./release /bitcoin_core_folder_2/ci/scratch/build/bitcoin-x86_64-w64-mingw32/build-aux/install-sh: ./src/qt/bitcoin-qt.exe does not exist. make: *** [Makefile:1258: bitcoin-25.99.0-win64-setup.exe] Error 1 ``` On this pull: (pass). ACKs for top commit: fanquake: ACK https://github.com/bitcoin/bitcoin/pull/28185/commits/fafa17c00b87c685200198979ed13018e55e474a - somewhat tested. MSAN changes are the same as what we did for tidy. Tree-SHA512: 2ce693a3773c70fcfca062c2a6f0e5a16b94960b34a6145d10cee1a28f79154829d59d014465ccbb80e1cb9dcd5aa043729cee9afd2c4175b05e9bc945364b79 Co-authored-by: fanquake --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 2 +- ci/test/00_setup_env_native_msan.sh | 2 +- ci/test/04_install.sh | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index aca3e4658950..594680004c48 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -7,7 +7,7 @@ export LC_ALL=C.UTF-8 export CI_IMAGE_NAME_TAG="ubuntu:22.04" -LIBCXX_DIR="${BASE_SCRATCH_DIR}/msan/cxx_build/" +LIBCXX_DIR="/msan/cxx_build/" export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" LIBCXX_FLAGS="-nostdinc++ -nostdlib++ -isystem ${LIBCXX_DIR}include/c++/v1 -L${LIBCXX_DIR}lib -Wl,-rpath,${LIBCXX_DIR}lib -lc++ -lc++abi -lpthread -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index 04e4f5a4e59e..482353409d25 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -7,7 +7,7 @@ export LC_ALL=C.UTF-8 export CI_IMAGE_NAME_TAG="ubuntu:22.04" -LIBCXX_DIR="${BASE_SCRATCH_DIR}/msan/cxx_build/" +LIBCXX_DIR="/msan/cxx_build/" export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" LIBCXX_FLAGS="-nostdinc++ -nostdlib++ -isystem ${LIBCXX_DIR}include/c++/v1 -L${LIBCXX_DIR}lib -Wl,-rpath,${LIBCXX_DIR}lib -lc++ -lc++abi -lpthread -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" diff --git a/ci/test/04_install.sh b/ci/test/04_install.sh index fa0195acc989..5a925a6efe00 100755 --- a/ci/test/04_install.sh +++ b/ci/test/04_install.sh @@ -10,10 +10,6 @@ if [[ $QEMU_USER_CMD == qemu-s390* ]]; then export LC_ALL=C fi -# Create folders that are mounted into the docker -mkdir -p "${CCACHE_DIR}" -mkdir -p "${PREVIOUS_RELEASES_DIR}" - export ASAN_OPTIONS="detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1" export LSAN_OPTIONS="suppressions=${BASE_BUILD_DIR}/test/sanitizer_suppressions/lsan:print_suppressions=0" export TSAN_OPTIONS="suppressions=${BASE_BUILD_DIR}/test/sanitizer_suppressions/tsan:halt_on_error=1" @@ -37,7 +33,7 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then # shellcheck disable=SC2086 DOCKER_ID=$(docker run $DOCKER_ADMIN -idt \ - --mount type=bind,src=$BASE_ROOT_DIR,dst=/ro_base,readonly \ + --mount type=bind,src=$BASE_READ_ONLY_DIR,dst=/ro_base,readonly \ --mount type=bind,src=$CCACHE_DIR,dst=$CCACHE_DIR \ --mount type=bind,src=$DEPENDS_DIR,dst=$DEPENDS_DIR \ --mount type=bind,src=$PREVIOUS_RELEASES_DIR,dst=$PREVIOUS_RELEASES_DIR \ @@ -60,6 +56,9 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then $DOCKER_CI_CMD_PREFIX_ROOT git config --global --add safe.directory "*" else echo "Running on host system without docker wrapper" + echo "Create missing folders" + mkdir -p "${CCACHE_DIR}" + mkdir -p "${PREVIOUS_RELEASES_DIR}" fi CI_EXEC () { From 1c59091b003babf9123960016665a607cd230a37 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 20 Mar 2024 11:56:20 +0000 Subject: [PATCH 17/26] Merge bitcoin/bitcoin#29676: ci: Bump msan to llvm-18 BACKPORT NOTE: missing changes belongs to ci/test/01_base_install.sh which is not presented in Dash Core ---- faecf3a7e6779c2cacadd91a6eba446431778849 ci: Bump msan to llvm-18 (MarcoFalke) Pull request description: Last one: https://github.com/bitcoin/bitcoin/pull/28476 ACKs for top commit: fanquake: ACK faecf3a7e6779c2cacadd91a6eba446431778849 - There is now a 18.1.2, but given it doesn't fix the instrumenting in libunwind, we don't need that here. I've tested that both jobs are now working on both arches. Tree-SHA512: 489c0b343bdc732687131317a570f3efbb18a3f548736d739da90d1a1e784df1dbb208c2da8a2a7740f27f961a841c477487a14c4d59910368f651225f0779b2 Co-authored-by: fanquake --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 8 ++++---- ci/test/00_setup_env_native_msan.sh | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index 594680004c48..0a9dee2ed826 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -1,19 +1,19 @@ #!/usr/bin/env bash # -# Copyright (c) 2020-2022 The Bitcoin Core developers +# Copyright (c) 2020-present The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. export LC_ALL=C.UTF-8 -export CI_IMAGE_NAME_TAG="ubuntu:22.04" +export CI_IMAGE_NAME_TAG="docker.io/ubuntu:24.04" LIBCXX_DIR="/msan/cxx_build/" export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" LIBCXX_FLAGS="-nostdinc++ -nostdlib++ -isystem ${LIBCXX_DIR}include/c++/v1 -L${LIBCXX_DIR}lib -Wl,-rpath,${LIBCXX_DIR}lib -lc++ -lc++abi -lpthread -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_fuzz_msan" -export PACKAGES="cmake ninja-build" +export PACKAGES="ninja-build" # BDB generates false-positives and will be removed in future export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" @@ -22,4 +22,4 @@ export USE_MEMORY_SANITIZER="true" export RUN_UNIT_TESTS="false" export RUN_FUNCTIONAL_TESTS="false" export RUN_FUZZ_TESTS=true -export CCACHE_SIZE=250M +export CCACHE_MAXSIZE=250M diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index 482353409d25..cbcd51e21878 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -1,23 +1,23 @@ #!/usr/bin/env bash # -# Copyright (c) 2020-2022 The Bitcoin Core developers +# Copyright (c) 2020-present The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. export LC_ALL=C.UTF-8 -export CI_IMAGE_NAME_TAG="ubuntu:22.04" +export CI_IMAGE_NAME_TAG="docker.io/ubuntu:24.04" LIBCXX_DIR="/msan/cxx_build/" export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" LIBCXX_FLAGS="-nostdinc++ -nostdlib++ -isystem ${LIBCXX_DIR}include/c++/v1 -L${LIBCXX_DIR}lib -Wl,-rpath,${LIBCXX_DIR}lib -lc++ -lc++abi -lpthread -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" export CONTAINER_NAME="ci_native_msan" -export PACKAGES="cmake ninja-build" +export PACKAGES="ninja-build" # BDB generates false-positives and will be removed in future export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening --with-asm=no CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export USE_MEMORY_SANITIZER="true" export RUN_FUNCTIONAL_TESTS="false" -export CCACHE_SIZE=250M +export CCACHE_MAXSIZE=250M From 5fdd260e1be3418e4186e03c325f18e53bb910b8 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 5 Apr 2024 17:07:50 +0100 Subject: [PATCH 18/26] Merge bitcoin/bitcoin#29800: ci: Drop duplicated compiler flags a3485af67da4949c72c45acc608f8746ed0e0848 ci: Drop duplicated compiler flags (Hennadii Stepanov) Pull request description: On the master branch @ 0d509bab45d292caeaf34600e57b5928757c6005, it is easy to check the _"Options used to compile and link"_ section in the `configure` script output and observe duplicated compiler flags. This PR cleans such cases up. ACKs for top commit: maflcko: re-ACK a3485af67da4949c72c45acc608f8746ed0e0848 fanquake: ACK a3485af67da4949c72c45acc608f8746ed0e0848 - no-longer a change in behaviour. Tree-SHA512: 7e644fcfad7be48af3b18edd2994c0c78a21ac3f9fff497724be80f74c9e859d156de15ca4024c5c50d1080435576ce63402b48aba5c2fd556e2ed7e318e0e34 Co-authored-by: fanquake --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 2 +- ci/test/00_setup_env_native_msan.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index 0a9dee2ed826..e615c63276ec 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -17,7 +17,7 @@ export PACKAGES="ninja-build" # BDB generates false-positives and will be removed in future export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CFLAGS='${MSAN_FLAGS}' CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE'" export USE_MEMORY_SANITIZER="true" export RUN_UNIT_TESTS="false" export RUN_FUNCTIONAL_TESTS="false" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index cbcd51e21878..b26b86cb2ffe 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -17,7 +17,7 @@ export PACKAGES="ninja-build" # BDB generates false-positives and will be removed in future export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening --with-asm=no CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening --with-asm=no" export USE_MEMORY_SANITIZER="true" export RUN_FUNCTIONAL_TESTS="false" export CCACHE_MAXSIZE=250M From 6eace527a246a8dbeaa1a22837d874256b9c92ae Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Sun, 7 Apr 2024 10:42:46 +0100 Subject: [PATCH 19/26] Merge bitcoin/bitcoin#29742: ci: remove --with-asm=no (secp256k1) from MSAN jobs BACKPORT NOTE: changes in 01_base_install.sh is omitted here intentionally ---- 61641e2466768e128fef995e9fcb24cad90e527d ci: remove --with-asm usage (secp256k1) (fanquake) c7efee591a27720757504f3ebf7dbeaef0185931 ci: use LLVM 18.1.3 in MSAN jobs (fanquake) Pull request description: Bumps LLVM to `18.1.3`: * Includes https://github.com/llvm/llvm-project/pull/86201, which is useful as it removes the need to (possibly) apply a work around when running the CI locally. Drops `--with-asm=no` (only being passed to secp256k1) from the MSAN CI. New MSAN annotations were pulled in as part of #29803. ACKs for top commit: maflcko: lgtm ACK 61641e2466768e128fef995e9fcb24cad90e527d hebasto: ACK 61641e2466768e128fef995e9fcb24cad90e527d. Tree-SHA512: da51c9f08a9aacb9dd936c47ef47777a8c84234e4df5b9776647ac94ebe88084b5e7b8182af90cfa01ae183072f6ce5915b73825f66b2567214ab270b2ff7837 Co-authored-by: fanquake --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 2 +- ci/test/00_setup_env_native_msan.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index e615c63276ec..36a172e42c9b 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -17,7 +17,7 @@ export PACKAGES="ninja-build" # BDB generates false-positives and will be removed in future export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening --with-asm=no CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE'" +export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE'" export USE_MEMORY_SANITIZER="true" export RUN_UNIT_TESTS="false" export RUN_FUNCTIONAL_TESTS="false" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index b26b86cb2ffe..431e4aba4915 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -17,7 +17,7 @@ export PACKAGES="ninja-build" # BDB generates false-positives and will be removed in future export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening --with-asm=no" +export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening" export USE_MEMORY_SANITIZER="true" export RUN_FUNCTIONAL_TESTS="false" export CCACHE_MAXSIZE=250M From cb458b00c7a238b68c88e9613636fbca6f41ff4f Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 24 Apr 2024 22:46:25 +0800 Subject: [PATCH 20/26] Merge bitcoin/bitcoin#29837: ci: disable `_FORTIFY_SOURCE` with MSAN 08ff17d1420a3d1c14c6b1a5436678fbb1dd9cbc ci: disable _FORTIFY_SOURCE with MSAN (fanquake) Pull request description: By undefining `_FORTIFY_SOURCE` we can drop`--disable-hardening`. ACKs for top commit: maflcko: lgtm ACK 08ff17d1420a3d1c14c6b1a5436678fbb1dd9cbc hernanmarino: utACK 08ff17d1420a3d1c14c6b1a5436678fbb1dd9cbc . Relevant CI test seems to be working OK. Tree-SHA512: 948fd075aa648a7e34c37376fb913074ebc07d1c3cb0737d5fcbe7eac0b35c4152139773e4515ccb80f2d11b1ced6c6984da1757c2bcf8dd90e8ff6f664dae8e Co-authored-by: merge-script --- ci/test/00_setup_env_native_fuzz_with_msan.sh | 3 ++- ci/test/00_setup_env_native_msan.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ci/test/00_setup_env_native_fuzz_with_msan.sh b/ci/test/00_setup_env_native_fuzz_with_msan.sh index 36a172e42c9b..f1c358082d5c 100755 --- a/ci/test/00_setup_env_native_fuzz_with_msan.sh +++ b/ci/test/00_setup_env_native_fuzz_with_msan.sh @@ -17,7 +17,8 @@ export PACKAGES="ninja-build" # BDB generates false-positives and will be removed in future export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory --disable-hardening CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE'" +# _FORTIFY_SOURCE is not compatible with MSAN. +export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer,memory CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE -U_FORTIFY_SOURCE'" export USE_MEMORY_SANITIZER="true" export RUN_UNIT_TESTS="false" export RUN_FUNCTIONAL_TESTS="false" diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index 431e4aba4915..dd465cac2e29 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -17,7 +17,8 @@ export PACKAGES="ninja-build" # BDB generates false-positives and will be removed in future export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" -export BITCOIN_CONFIG="--with-sanitizers=memory --disable-hardening" +# _FORTIFY_SOURCE is not compatible with MSAN. +export BITCOIN_CONFIG="--with-sanitizers=memory CPPFLAGS='-U_FORTIFY_SOURCE'" export USE_MEMORY_SANITIZER="true" export RUN_FUNCTIONAL_TESTS="false" export CCACHE_MAXSIZE=250M From ae15342e502ba1fdcbbb216e068879f87ee2e115 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 6 Jan 2025 10:22:52 +0000 Subject: [PATCH 21/26] Merge bitcoin/bitcoin#31592: ci: Run functional tests in msan task fa0411ee305fe04800c54d141fbbeac342eaa764 ci: Run functional tests in msan task (MarcoFalke) Pull request description: Now that the CI machines have a bit more CPU, it seems good to run the functional tests as well under msan. (Also, bump the llvm minor version) ACKs for top commit: TheCharlatan: ACK fa0411ee305fe04800c54d141fbbeac342eaa764 Tree-SHA512: 0dbb2b934485ed54b8caafb5bcd96ddef87088b148dab72a584f721c398bb7fda4095fb720b9ad602dc71f8f40a1e0f29e1b08b2879b78b90b29d46604df36c3 Co-authored-by: merge-script --- ci/test/00_setup_env_native_msan.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index dd465cac2e29..c68ee49b6ec1 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -20,5 +20,5 @@ export GOAL="install" # _FORTIFY_SOURCE is not compatible with MSAN. export BITCOIN_CONFIG="--with-sanitizers=memory CPPFLAGS='-U_FORTIFY_SOURCE'" export USE_MEMORY_SANITIZER="true" -export RUN_FUNCTIONAL_TESTS="false" +export RUN_FUNCTIONAL_TESTS="true" export CCACHE_MAXSIZE=250M From f3297afd3662586bac4260eda4ca1e14eedf4b49 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 22 May 2023 11:12:03 +0100 Subject: [PATCH 22/26] Merge bitcoin/bitcoin#27699: random: drop syscall wrapper usage for getrandom() 5228223e1ff2af29e6e77668ce3288005c2adbbc ci: remove MSAN getrandom syscall workaround (fanquake) d5e06919db5e221bfef445c5a40c88de72dc5869 random: switch to using getrandom() directly (fanquake) c2ba3f5b0c7d0eece7d16d1ffc125d8a6a9297af random: add [[maybe_unused]] to GetDevURandom (fanquake) c13c97dbf846cf0e6a5581ac414ef96a215b0dc6 random: getentropy on macOS does not need unistd.h (fanquake) Pull request description: This requires a linux kernel of `3.17`+, which seems entirely reasonable. `3.17` went EOL in 2015, and the last supported `3.x` kernel (`3.16`) went EOL > 4 years ago, in 2020. For reference, the current oldest maintained kernel is `4.14` (released 2017, going EOL Jan 2024). Support for `getrandom()` (and `getentropy()`) was added to glibc `2.25` https://sourceware.org/legacy-ml/libc-alpha/2017-02/msg00079.html: > * The getentropy and getrandom functions, and the header file have been added. and we already require `2.27` or later. All that being said, I don't think you would encounter a current day (+~6 months from now) system, running with kernel headers older than 3.17 (released 2014) but also having a glibc of 2.27+ (released 2018)? Removing this (our only) use of `syscall()` also means we can drop a workaround in our MSAN jobs. If this is merged, I'll drop the [same workaround in oss-fuzz](https://github.com/google/oss-fuzz/blob/25946a544856413d31d9cbb3a366a4aef5a8fd60/projects/bitcoin-core/build.sh#L49-L56). ACKs for top commit: josibake: ACK https://github.com/bitcoin/bitcoin/pull/27699/commits/5228223e1ff2af29e6e77668ce3288005c2adbbc hebasto: ACK 5228223e1ff2af29e6e77668ce3288005c2adbbc, I've tested build system changes on Ubuntu 22.04 and macOS Monterey 12.6.6 (x86_64). Tree-SHA512: cc978e08510c461b875ca8c08ae176b4519fa1108f0efd74dcb7474518945357e0184e54423282c9a496de195e4ddc3e221ee78623bd63e24c50cc86acdf32e2 Co-authored-by: fanquake --- ci/dash/build_src.sh | 8 -------- configure.ac | 15 +++++++-------- doc/dependencies.md | 1 + src/random.cpp | 33 ++++++--------------------------- 4 files changed, 14 insertions(+), 43 deletions(-) diff --git a/ci/dash/build_src.sh b/ci/dash/build_src.sh index d26a31001079..391224587271 100755 --- a/ci/dash/build_src.sh +++ b/ci/dash/build_src.sh @@ -47,14 +47,6 @@ bash -c "${MAYBE_BEAR} ${MAYBE_TOKEN} make ${MAKEJOBS} ${GOAL}" || ( echo "Build ccache --version | head -n 1 && ccache --show-stats -if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then - # MemorySanitizer (MSAN) does not support tracking memory initialization done by - # using the Linux getrandom syscall. Avoid using getrandom by undefining - # HAVE_SYS_GETRANDOM. See https://github.com/google/sanitizers/issues/852 for - # details. - bash -c 'grep -v HAVE_SYS_GETRANDOM src/config/bitcoin-config.h > src/config/bitcoin-config.h.tmp && mv src/config/bitcoin-config.h.tmp src/config/bitcoin-config.h' -fi - if [ -n "$USE_VALGRIND" ]; then echo "valgrind in USE!" "${BASE_ROOT_DIR}/ci/test/wrap-valgrind.sh" diff --git a/configure.ac b/configure.ac index daf733fb2224..097a0b3cd812 100644 --- a/configure.ac +++ b/configure.ac @@ -1276,17 +1276,16 @@ if test "$LINK_WRAP_SUPPORTED" = "yes"; then fi dnl Check for different ways of gathering OS randomness -AC_MSG_CHECKING([for Linux getrandom syscall]) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include - #include - #include ]], - [[ syscall(SYS_getrandom, nullptr, 32, 0); ]])], - [ AC_MSG_RESULT([yes]); AC_DEFINE([HAVE_SYS_GETRANDOM], [1], [Define this symbol if the Linux getrandom system call is available]) ], +AC_MSG_CHECKING([for Linux getrandom function]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + #include ]], + [[ getrandom(nullptr, 32, 0); ]])], + [ AC_MSG_RESULT([yes]); AC_DEFINE([HAVE_GETRANDOM], [1], [Define this symbol if the Linux getrandom function call is available]) ], [ AC_MSG_RESULT([no])] ) -AC_MSG_CHECKING([for getentropy via random.h]) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include +AC_MSG_CHECKING([for getentropy via sys/random.h]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include ]], [[ getentropy(nullptr, 32) ]])], [ AC_MSG_RESULT([yes]); AC_DEFINE([HAVE_GETENTROPY_RAND], [1], [Define this symbol if the BSD getentropy system call is available with sys/random.h]) ], diff --git a/doc/dependencies.md b/doc/dependencies.md index 2a2b7ec28370..a9be6395aaa0 100644 --- a/doc/dependencies.md +++ b/doc/dependencies.md @@ -20,6 +20,7 @@ You can find installation instructions in the `build-*.md` file for your platfor | [Boost](../depends/packages/boost.mk) | [link](https://www.boost.org/users/download/) | 1.81.0 | [1.73.0](https://github.com/bitcoin/bitcoin/pull/29066) | No | | [libevent](../depends/packages/libevent.mk) | [link](https://github.com/libevent/libevent/releases) | [2.1.12-stable](https://github.com/bitcoin/bitcoin/pull/21991) | [2.1.8](https://github.com/bitcoin/bitcoin/pull/24681) | No | | glibc | [link](https://www.gnu.org/software/libc/) | N/A | [2.31](https://github.com/bitcoin/bitcoin/pull/29987) | Yes | +| Linux Kernel | [link](https://www.kernel.org/) | N/A | [3.17.0](https://github.com/bitcoin/bitcoin/pull/27699) | Yes | ## Optional diff --git a/src/random.cpp b/src/random.cpp index 3b5266ffc6ea..b955cbbd55c2 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -28,14 +28,10 @@ #include #endif -#ifdef HAVE_SYS_GETRANDOM -#include -#include -#endif -#if defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) -#include +#if defined(HAVE_GETRANDOM) || (defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)) #include #endif + #ifdef HAVE_SYSCTL_ARND #include #endif @@ -325,7 +321,7 @@ static void Strengthen(const unsigned char (&seed)[32], SteadyClock::duration du /** Fallback: get 32 bytes of system entropy from /dev/urandom. The most * compatible way to get cryptographic randomness on UNIX-ish platforms. */ -static void GetDevURandom(unsigned char *ent32) +[[maybe_unused]] static void GetDevURandom(unsigned char *ent32) { int f = open("/dev/urandom", O_RDONLY); if (f == -1) { @@ -357,23 +353,14 @@ void GetOSRand(unsigned char *ent32) if (status != STATUS_SUCCESS) { RandFailure(); } -#elif defined(HAVE_SYS_GETRANDOM) +#elif defined(HAVE_GETRANDOM) /* Linux. From the getrandom(2) man page: * "If the urandom source has been initialized, reads of up to 256 bytes * will always return as many bytes as requested and will not be * interrupted by signals." */ - int rv = syscall(SYS_getrandom, ent32, NUM_OS_RANDOM_BYTES, 0); - if (rv != NUM_OS_RANDOM_BYTES) { - if (rv < 0 && errno == ENOSYS) { - /* Fallback for kernel <3.17: the return value will be -1 and errno - * ENOSYS if the syscall is not available, in that case fall back - * to /dev/urandom. - */ - GetDevURandom(ent32); - } else { - RandFailure(); - } + if (getrandom(ent32, NUM_OS_RANDOM_BYTES, 0) != NUM_OS_RANDOM_BYTES) { + RandFailure(); } #elif defined(__OpenBSD__) /* OpenBSD. From the arc4random(3) man page: @@ -383,16 +370,10 @@ void GetOSRand(unsigned char *ent32) The function call is always successful. */ arc4random_buf(ent32, NUM_OS_RANDOM_BYTES); - // Silence a compiler warning about unused function. - (void)GetDevURandom; #elif defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) - /* getentropy() is available on macOS 10.12 and later. - */ if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) { RandFailure(); } - // Silence a compiler warning about unused function. - (void)GetDevURandom; #elif defined(HAVE_SYSCTL_ARND) /* FreeBSD, NetBSD and similar. It is possible for the call to return less * bytes than requested, so need to read in a loop. @@ -406,8 +387,6 @@ void GetOSRand(unsigned char *ent32) } have += len; } while (have < NUM_OS_RANDOM_BYTES); - // Silence a compiler warning about unused function. - (void)GetDevURandom; #else /* Fall back to /dev/urandom if there is no specific method implemented to * get system entropy for this OS. From 6727036ae61aa5a9cf35814d3774daf69876ab6d Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 29 Jul 2026 17:44:13 +0700 Subject: [PATCH 23/26] ci: dashify the msan job configuration The preceding backports land upstream's msan config verbatim, which by the end is CMake-shaped and assumes ci/test/01_base_install.sh. Neither holds here, so adapt it: - BITCOIN_CONFIG back to autotools. Upstream's last autotools form was --with-sanitizers=memory CPPFLAGS='-U_FORTIFY_SOURCE' (bitcoin#27766); everything after that is -DSANITIZERS= and CMAKE_*_FLAGS_DEBUG, which only exist because CMake's Debug config would otherwise overwrite the -g -O1 in MSAN_FLAGS. Autotools puts user CXXFLAGS last, so that whole problem is absent. - LIBCXX_DIR points at /cxx_build/, where the instrumented libc++ is baked into the CI image, rather than at a scratch dir populated by 01_base_install.sh. - HOST is set, since Dash's depends is always built explicitly. - clang-19 to match LLVM_VERSION in the CI image. - Drop CI_IMAGE_NAME_TAG and PACKAGES, which nothing reads under GitHub Actions; the toolchain comes from the container. Three options are Dash-specific and have no upstream counterpart: --with-asm=no --with-backend=easy MSan cannot see through hand-written assembly. Dash reaches it twice, via secp256k1 and via relic's GMP arithmetic backend, so both need a pure C path. Upstream dropped --with-asm in bitcoin#27699 because it has no equivalent of relic. --disable-mimalloc mimalloc seeds itself from syscall(SYS_getrandom) in mi_process_attach, before main(). MSan intercepts libc calls, not raw syscalls, so every process aborted at startup until this was selectable. TEST_RUNNER_TIMEOUT_FACTOR is 15 rather than the default 4. MSan with origin tracking is far slower than ASan, and the LLMQ tests time out waiting on quorum formation well before anything is actually wrong. --- ci/test/00_setup_env_native_msan.sh | 30 +++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index c68ee49b6ec1..37ab9be7eb60 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -6,19 +6,33 @@ export LC_ALL=C.UTF-8 -export CI_IMAGE_NAME_TAG="docker.io/ubuntu:24.04" -LIBCXX_DIR="/msan/cxx_build/" +export CONTAINER_NAME="ci_native_msan" +export HOST=x86_64-pc-linux-gnu +# Built into the CI image by contrib/containers/ci/ci-msan.Dockerfile so that it +# lands in a cached layer instead of being rebuilt on every run. Upstream does +# the equivalent in ci/test/01_base_install.sh, which Dash does not have. +LIBCXX_DIR="/cxx_build/" export MSAN_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" LIBCXX_FLAGS="-nostdinc++ -nostdlib++ -isystem ${LIBCXX_DIR}include/c++/v1 -L${LIBCXX_DIR}lib -Wl,-rpath,${LIBCXX_DIR}lib -lc++ -lc++abi -lpthread -Wno-unused-command-line-argument" export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" -export CONTAINER_NAME="ci_native_msan" -export PACKAGES="ninja-build" # BDB generates false-positives and will be removed in future -export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 CC=clang CXX=clang++ CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" +export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 NO_UPNP=1 NO_NATPMP=1 CC=clang-19 CXX=clang++-19 CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" export GOAL="install" +# CC/CXX/CFLAGS/CXXFLAGS are repeated here rather than left to depends' +# config.site. Upstream dropped them in bitcoin#29800 because its +# ci/test/03_test_script.sh sets CONFIG_SITE explicitly (bitcoin#26683); +# ci/dash/build_src.sh still uses the older --prefix form, and this is the only +# target whose compiler differs from the system default, so nothing else in +# Dash's CI exercises that hand-off. # _FORTIFY_SOURCE is not compatible with MSAN. -export BITCOIN_CONFIG="--with-sanitizers=memory CPPFLAGS='-U_FORTIFY_SOURCE'" +# --with-asm=no and --with-backend=easy keep secp256k1 and relic off +# hand-written assembly, which MSan cannot see through. +# --disable-mimalloc selects the plain malloc secure allocator; mimalloc seeds +# itself with a raw getrandom syscall before main(), which MSan cannot track. +export BITCOIN_CONFIG="--with-sanitizers=memory --with-gui=no --without-bdb --with-sqlite \ +--with-asm=no --with-backend=easy --disable-mimalloc \ +CC=clang-19 CXX=clang++-19 CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' \ +CPPFLAGS='-U_FORTIFY_SOURCE'" export USE_MEMORY_SANITIZER="true" -export RUN_FUNCTIONAL_TESTS="true" -export CCACHE_MAXSIZE=250M +export TEST_RUNNER_TIMEOUT_FACTOR=15 From f07388c1d9e0021c27d5d1e2cde08d4af6f309cf Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 29 Jul 2026 18:03:02 +0700 Subject: [PATCH 24/26] ci: build an MSan-instrumented libc++ into a dedicated CI image MemorySanitizer reports every read of memory it did not watch being written, so an uninstrumented C++ standard library produces a stream of reports that cannot be distinguished from real findings. libc++ therefore has to be rebuilt with -fsanitize=memory. Upstream does this in ci/test/01_base_install.sh, which runs inside its docker build. Dash has no equivalent script, which is why the hunks touching it were dropped from the preceding backports. Their content is carried here instead, dashified into a Dockerfile so the result lands in a cached image layer keyed on the file's hash rather than being rebuilt on every run: bitcoin#27448 LIBCXX_HARDENING_MODE=debug bitcoin#27824 LLVM_TARGETS_TO_BUILD=Native rather than X86 bitcoin#27922 llvm-symbolizer available, so reports are symbolized bitcoin#27436 the LLVM version tracks the compiler in use fab27127f4 /cxx_build/ rather than a scratch directory Two details are load-bearing. Only libcxx and libcxxabi are built, with LIBCXXABI_USE_LLVM_UNWINDER=OFF, because libunwind mishandles exceptions under MSan (llvm/llvm-project#84348). And the LLVM tag matches the clang in the image; a mismatched libc++ ABI produces failures that look like sanitizer findings. Upstream compiled clang itself from source for a while (bitcoin#27737) to work around Debian packaging, and reverted that once it was fixed. The distro clang is used here for the same reason it is used upstream now. Also raise TEST_RUNNER_TIMEOUT_FACTOR to 40. MSan with origin tracking is several times slower than ASan, and locally 15 was not enough for p2p_quorum_data and feature_llmq_signing, which time out waiting on quorum formation well before anything is wrong. --- ci/test/00_setup_env_native_msan.sh | 2 +- contrib/containers/ci/ci-msan.Dockerfile | 37 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 contrib/containers/ci/ci-msan.Dockerfile diff --git a/ci/test/00_setup_env_native_msan.sh b/ci/test/00_setup_env_native_msan.sh index 37ab9be7eb60..af0008bf0d0c 100755 --- a/ci/test/00_setup_env_native_msan.sh +++ b/ci/test/00_setup_env_native_msan.sh @@ -35,4 +35,4 @@ export BITCOIN_CONFIG="--with-sanitizers=memory --with-gui=no --without-bdb --wi CC=clang-19 CXX=clang++-19 CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' \ CPPFLAGS='-U_FORTIFY_SOURCE'" export USE_MEMORY_SANITIZER="true" -export TEST_RUNNER_TIMEOUT_FACTOR=15 +export TEST_RUNNER_TIMEOUT_FACTOR=40 diff --git a/contrib/containers/ci/ci-msan.Dockerfile b/contrib/containers/ci/ci-msan.Dockerfile new file mode 100644 index 000000000000..00ad298b77d8 --- /dev/null +++ b/contrib/containers/ci/ci-msan.Dockerfile @@ -0,0 +1,37 @@ +# syntax = devthefuture/dockerfile-x + +FROM ./ci.Dockerfile + +# MemorySanitizer reports any read of memory it did not watch being written, +# so the C++ standard library has to be instrumented too. A stock libstdc++ or +# libc++ produces a flood of reports that cannot be told apart from real ones. +# +# Upstream builds this in ci/test/01_base_install.sh, which runs inside its +# docker build. Dash has no such script, so it lives here instead, which keeps +# the result in a cached image layer rather than rebuilding it on every run. + +USER root + +ARG LLVM_VERSION=19 +ARG LLVM_TAG=llvmorg-19.1.7 + +RUN set -ex; \ + apt-get update && apt-get install ${APT_ARGS} ninja-build; \ + rm -rf /var/lib/apt/lists/*; \ + git clone --depth=1 -b "${LLVM_TAG}" https://github.com/llvm/llvm-project /llvm-project; \ + cmake -G Ninja -B /cxx_build/ \ + -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_USE_SANITIZER=MemoryWithOrigins \ + -DCMAKE_C_COMPILER=clang-${LLVM_VERSION} \ + -DCMAKE_CXX_COMPILER=clang++-${LLVM_VERSION} \ + -DLLVM_TARGETS_TO_BUILD=Native \ + -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF \ + -DLIBCXXABI_USE_LLVM_UNWINDER=OFF \ + -DLIBCXX_HARDENING_MODE=debug \ + -S /llvm-project/runtimes; \ + ninja -C /cxx_build/; \ + du -sh /llvm-project; \ + rm -rf /llvm-project; + +USER dash From 475f809a9dc3f3dadf6c9da69252ab895f15a043 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 29 Jul 2026 14:09:59 +0700 Subject: [PATCH 25/26] dashbls: make mimalloc optional bls.cpp already picks its secure allocator at compile time and falls back from mimalloc to libsodium to plain malloc: #if BLSALLOC_MIMALLOC SetSecureAllocator(mi_malloc, mi_free); #elif BLSALLOC_SODIUM ... #else SetSecureAllocator(malloc, free); Only the build wiring was unconditional, so there was no way to select the fallback. Add --disable-mimalloc, following the existing tests and bench options, and guard the define, the sources and the LIBADD entry with the resulting USE_MIMALLOC conditional. Default is unchanged, so nothing about a normal build moves. Needed because mimalloc cannot run under MemorySanitizer. mi_process_attach runs from __libc_start_main before main(), and its entropy init calls syscall(SYS_getrandom, ...) directly, with a /dev/urandom fallback that also goes through raw syscalls. MSan intercepts libc functions rather than syscalls, so the key buffer stays poisoned and every process aborts at startup. There is no way out at runtime: MSan has no general suppression mechanism, and halt_on_error=0, keep_going=1 and exitcode=0 all still terminate. mimalloc's own track.h supports Valgrind and ASan but not MSan. Note this belongs upstream in dashpay/bls-signatures; carrying it here is a stopgap so the MSan job has something to build against. Making mimalloc optional moved $(LIBMIMALLOC) from the front of libdashbls_la_LIBADD to the end, inside the USE_MIMALLOC conditional. For static archives that changes symbol resolution: mimalloc compiles alloc-posix.c and runs mi_process_attach from a constructor, so it provides allocator symbols of its own. Linked after librelic and gmp, some objects resolve malloc and free to mimalloc and others to libc, and the process aborts with "free(): invalid size" as soon as memory allocated by one is released by the other. The conditional was unnecessary anyway. LIBMIMALLOC and MIMALLOC_H are only defined by Makefile.mimalloc.include, which is already included conditionally, so both expand to nothing when mimalloc is disabled and the original unconditional lines are correct as they stand. --- src/dashbls/Makefile.bls.include | 13 +++++++++++++ src/dashbls/configure.ac | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/dashbls/Makefile.bls.include b/src/dashbls/Makefile.bls.include index 7c35b3ced764..6c8c38139691 100644 --- a/src/dashbls/Makefile.bls.include +++ b/src/dashbls/Makefile.bls.include @@ -5,7 +5,11 @@ LIBDASHBLS = libdashbls.la +if USE_MIMALLOC DASHBLS_CPPFLAGS = -DBLSALLOC_MIMALLOC=1 +else +DASHBLS_CPPFLAGS = +endif DASHBLS_INCLUDES = \ -I$(builddir) \ @@ -43,6 +47,12 @@ libdashbls_la_SOURCES += \ $(MIMALLOC_H) \ $(RELIC_H) +# LIBMIMALLOC and MIMALLOC_H expand to nothing when Makefile.mimalloc.include +# is not pulled in, so these stay unconditional. Listing LIBMIMALLOC anywhere +# other than first changes static link order, which decides whether an object +# resolves malloc to mimalloc or to libc; mixing the two aborts the process +# with "free(): invalid size" as soon as anything allocated by one is released +# by the other. libdashbls_la_LIBADD = \ $(LIBMIMALLOC) \ $(LIBRELIC) \ @@ -52,7 +62,10 @@ libdashbls_la_CPPFLAGS = $(AM_CPPFLAGS) $(RELIC_INCLUDES) $(MIMALLOC_INCLUDES) $ libdashbls_la_CXXFLAGS = $(AM_CXXFLAGS) libdashbls_la_LDFLAGS = $(AM_LDFLAGS) +if USE_MIMALLOC include Makefile.mimalloc.include +endif + include Makefile.relic.include if USE_TESTS diff --git a/src/dashbls/configure.ac b/src/dashbls/configure.ac index 56b8a78339e0..e1bf13bc1a75 100644 --- a/src/dashbls/configure.ac +++ b/src/dashbls/configure.ac @@ -71,6 +71,12 @@ AC_ARG_ENABLE([bench], [use_bench=$enableval], [use_bench=yes]) +AC_ARG_ENABLE([mimalloc], + [AS_HELP_STRING([--enable-mimalloc], + [Use mimalloc as the secure allocator [default=yes]])], + [use_mimalloc=$enableval], + [use_mimalloc=yes]) + AC_ARG_ENABLE([hardening], [AS_HELP_STRING([--enable-hardening], [Enable hardening flags and arguments [default=auto]])], @@ -863,6 +869,7 @@ AM_CONDITIONAL(WITH_FBX, test 1 -eq 1) AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" = x"yes"]) AM_CONDITIONAL([USE_BENCH], [test x"$use_bench" = x"yes"]) +AM_CONDITIONAL([USE_MIMALLOC], [test x"$use_mimalloc" = x"yes"]) AM_CONDITIONAL([HARDEN], [test "$use_hardening" = "yes"]) AM_CONDITIONAL([OPTIMIZE], [test "$use_optimizations" = "yes"]) From 96abb1282656509c1c340e5374c118adccd9859b Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 29 Jul 2026 18:04:08 +0700 Subject: [PATCH 26/26] ci: add linux64_msan build and test jobs Wires up the MSan target added by the preceding backports. Unlike the asan job, this one cannot reuse anything: - its own container, because the MSan-instrumented libc++ is only in dashcore-ci-msan - its own depends, because every dependency has to be compiled with -fsanitize=memory. Sharing the linux64 depends would leave MSan reporting uninitialised reads out of libevent, sqlite and zeromq that are indistinguishable from real findings. Both build and test jobs run, matching upstream since bitcoin#31592. Gated on SKIP_LINUX64_MSAN so a repository can turn it off, and the container job is gated too, since building the instrumented libc++ is the expensive part and there is no reason to pay for it when the job is off. Not included: upstream sets vm.mmap_rnd_bits=28 on the runner for its MSan and TSan jobs, to stop high ASLR entropy breaking the sanitizer's shadow mappings. That cannot be done here. vm.* sysctls are not namespaced, so it is not settable from a Dockerfile, is rejected by docker --sysctl, and would need a privileged container mutating the host to apply at runtime. It was not needed locally on a 6.12 kernel, so nothing is done for now. If CI does hit shadow mapping failures, the fix is to wrap the test invocation in setarch -R, which disables ASLR for that process tree only and needs no privileges and no host changes. --- .github/workflows/build-container.yml | 30 ++++++++++------ .github/workflows/build.yml | 50 +++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml index 078a3e84a5ec..c7dc2ebea3cb 100644 --- a/.github/workflows/build-container.yml +++ b/.github/workflows/build-container.yml @@ -23,6 +23,11 @@ on: description: "Runner label to use for arm64 jobs" required: true type: string + build-arm64: + description: "Whether to also build an arm64 image" + required: false + type: boolean + default: true outputs: path: description: "Path to built container" @@ -79,6 +84,7 @@ jobs: build-arm64: name: Build container (arm64) + if: ${{ inputs.build-arm64 }} runs-on: ${{ inputs.runs-on-arm64 }} outputs: digest: ${{ steps.build.outputs.digest }} @@ -125,7 +131,12 @@ jobs: create-manifest: name: Create multi-arch manifest - runs-on: ${{ inputs.runs-on-arm64 }} + # build-arm64 is skipped when the arm64 image is not requested; the + # default success() condition would skip this job along with it. + if: | + !cancelled() && needs.build-amd64.result == 'success' && + (needs.build-arm64.result == 'success' || needs.build-arm64.result == 'skipped') + runs-on: ${{ inputs.build-arm64 && inputs.runs-on-arm64 || inputs.runs-on-amd64 }} needs: [build-amd64, build-arm64] steps: - name: Checkout code @@ -151,15 +162,14 @@ jobs: TAG="${{ needs.build-amd64.outputs.tag }}" HASH_TAG="${{ hashFiles(inputs.file) }}" + SOURCES=("${REPO}:${HASH_TAG}-amd64") + if [ "${{ inputs.build-arm64 }}" = "true" ]; then + SOURCES+=("${REPO}:${HASH_TAG}-arm64") + fi + # Create manifest from arch-specific images - docker buildx imagetools create -t "${REPO}:${HASH_TAG}" \ - "${REPO}:${HASH_TAG}-amd64" \ - "${REPO}:${HASH_TAG}-arm64" + docker buildx imagetools create -t "${REPO}:${HASH_TAG}" "${SOURCES[@]}" - docker buildx imagetools create -t "${REPO}:${TAG}" \ - "${REPO}:${HASH_TAG}-amd64" \ - "${REPO}:${HASH_TAG}-arm64" + docker buildx imagetools create -t "${REPO}:${TAG}" "${SOURCES[@]}" - docker buildx imagetools create -t "${REPO}:latest" \ - "${REPO}:${HASH_TAG}-amd64" \ - "${REPO}:${HASH_TAG}-arm64" + docker buildx imagetools create -t "${REPO}:latest" "${SOURCES[@]}" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce8191dc99ea..21a7b10f2bc6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -115,6 +115,21 @@ jobs: runs-on-amd64: ${{ needs.check-skip.outputs['runner-amd64'] }} runs-on-arm64: ${{ needs.check-skip.outputs['runner-arm64'] }} + container-msan: + name: Build msan container + needs: [check-skip] + if: ${{ needs.check-skip.outputs.skip == 'false' && vars.SKIP_LINUX64_MSAN == '' }} + uses: ./.github/workflows/build-container.yml + with: + context: ./contrib/containers/ci + file: ./contrib/containers/ci/ci-msan.Dockerfile + name: dashcore-ci-msan + runs-on-amd64: ${{ needs.check-skip.outputs['runner-amd64'] }} + runs-on-arm64: ${{ needs.check-skip.outputs['runner-arm64'] }} + # All linux64_msan jobs are pinned to amd64 runners, so an arm64 + # image (with its expensive MSan libc++ build) would go unused. + build-arm64: false + depends-aarch64-linux: name: aarch64-linux-gnu uses: ./.github/workflows/build-depends.yml @@ -141,6 +156,17 @@ jobs: base-image-digest: ${{ needs.check-skip.outputs.base-image-digest }} runs-on: ${{ needs.check-skip.outputs['runner-amd64'] }} + depends-linux64_msan: + name: x86_64-pc-linux-gnu_msan + uses: ./.github/workflows/build-depends.yml + needs: [check-skip, container-msan, cache-sources] + if: ${{ vars.SKIP_LINUX64_MSAN == '' }} + with: + build-target: linux64_msan + container-path: ${{ needs.container-msan.outputs.path }} + base-image-digest: ${{ needs.check-skip.outputs.base-image-digest }} + runs-on: ${{ needs.check-skip.outputs['runner-amd64'] }} + depends-linux64_multiprocess: name: linux64_multiprocess uses: ./.github/workflows/build-depends.yml @@ -250,6 +276,20 @@ jobs: depends-artifact: ${{ needs.depends-linux64.outputs.built-artifact }} runs-on: ${{ needs.check-skip.outputs['runner-amd64'] }} + src-linux64_msan: + name: linux64_msan-build + uses: ./.github/workflows/build-src.yml + needs: [check-skip, container-msan, depends-linux64_msan] + if: ${{ vars.SKIP_LINUX64_MSAN == '' }} + with: + build-target: linux64_msan + container-path: ${{ needs.container-msan.outputs.path }} + depends-key: ${{ needs.depends-linux64_msan.outputs.key }} + depends-host: ${{ needs.depends-linux64_msan.outputs.host }} + depends-dep-opts: ${{ needs.depends-linux64_msan.outputs.dep-opts }} + depends-artifact: ${{ needs.depends-linux64_msan.outputs.built-artifact }} + runs-on: ${{ needs.check-skip.outputs['runner-amd64'] }} + src-linux64_multiprocess: name: linux64_multiprocess-build uses: ./.github/workflows/build-src.yml @@ -352,6 +392,16 @@ jobs: container-path: ${{ needs.container-slim.outputs.path }} runs-on: ${{ needs.check-skip.outputs['runner-amd64'] }} + test-linux64_msan: + name: linux64_msan-test + uses: ./.github/workflows/test-src.yml + needs: [check-skip, container-msan, src-linux64_msan, lint] + with: + bundle-key: ${{ needs.src-linux64_msan.outputs.key }} + build-target: linux64_msan + container-path: ${{ needs.container-msan.outputs.path }} + runs-on: ${{ needs.check-skip.outputs['runner-amd64'] }} + test-linux64_multiprocess: name: linux64_multiprocess-test uses: ./.github/workflows/test-src.yml