From e66c6e3ee07b05675eb560e7d2dd79b30bed92c6 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 01:32:40 -0400 Subject: [PATCH 01/35] Initial implementation of tests with sanitizers --- .github/workflows/{ci.yml => ci-miri.yaml} | 22 +-- .github/workflows/ci-sanitizers.yaml | 88 +++++++++ Cargo.toml | 6 +- .../Cargo.toml | 4 +- ci-setup.sh => ci-miri-setup.sh | 0 ci-test.sh => ci-miri-test.sh | 13 +- ci-sanitizers-setup.sh | 18 ++ ci-sanitizers-test.sh | 174 ++++++++++++++++++ .../Cargo.toml | 4 +- ...tdarch-test.sh => miri-run-stdarch-test.sh | 2 +- run-test.sh => miri-run-test.sh | 0 sanitizers-run-stdarch-test.sh | 63 +++++++ sanitizers-run-test.sh | 40 ++++ {std_miri_test => std_sanity_test}/Cargo.toml | 4 +- 14 files changed, 411 insertions(+), 27 deletions(-) rename .github/workflows/{ci.yml => ci-miri.yaml} (82%) create mode 100644 .github/workflows/ci-sanitizers.yaml rename {alloc_miri_test => alloc_sanity_test}/Cargo.toml (92%) rename ci-setup.sh => ci-miri-setup.sh (100%) rename ci-test.sh => ci-miri-test.sh (94%) create mode 100644 ci-sanitizers-setup.sh create mode 100755 ci-sanitizers-test.sh rename {core_miri_test => core_sanity_test}/Cargo.toml (92%) rename run-stdarch-test.sh => miri-run-stdarch-test.sh (98%) rename run-test.sh => miri-run-test.sh (100%) create mode 100755 sanitizers-run-stdarch-test.sh create mode 100755 sanitizers-run-test.sh rename {std_miri_test => std_sanity_test}/Cargo.toml (96%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci-miri.yaml similarity index 82% rename from .github/workflows/ci.yml rename to .github/workflows/ci-miri.yaml index 0d5c3a8..c8c60a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci-miri.yaml @@ -1,4 +1,4 @@ -name: CI +name: Miri CI on: push: @@ -16,45 +16,45 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup environment - run: bash ./ci-setup.sh + run: bash ./ci-miri-setup.sh - name: Test - run: bash ./ci-test.sh core + run: bash ./ci-miri-test.sh core test-alloc: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup environment - run: bash ./ci-setup.sh + run: bash ./ci-miri-setup.sh - name: Test - run: bash ./ci-test.sh alloc + run: bash ./ci-miri-test.sh alloc test-std: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup environment - run: bash ./ci-setup.sh + run: bash ./ci-miri-setup.sh - name: Test - run: bash ./ci-test.sh std + run: bash ./ci-miri-test.sh std test-simd: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup environment - run: bash ./ci-setup.sh + run: bash ./ci-miri-setup.sh - name: Test - run: bash ./ci-test.sh simd + run: bash ./ci-miri-test.sh simd test-stdarch: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup environment - run: bash ./ci-setup.sh + run: bash ./ci-miri-setup.sh - name: Test - run: bash ./ci-test.sh stdarch + run: bash ./ci-miri-test.sh stdarch # Send a Zulip notification when a cron job fails cron-fail-notify: diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml new file mode 100644 index 0000000..f54e21f --- /dev/null +++ b/.github/workflows/ci-sanitizers.yaml @@ -0,0 +1,88 @@ +name: Sanitizers CI + +on: + push: + branches: + - 'master' + pull_request: + branches: + - 'master' + schedule: + - cron: '00 2 * * *' # At 02:00 UTC every day (like rustup-components-history). + +jobs: + test-core: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup environment + run: bash ./ci-sanitizers-setup.sh + - name: Test ASAN + run: bash ./ci-sanitizers-test.sh core address + - name: Test MSAN + run: bash ./ci-sanitizers-test.sh core memory + - name: Test TSAN + run: bash ./ci-sanitizers-test.sh core thread + - name: Test CFISAN + run: bash ./ci-sanitizers-test.sh core cfi + + # test-alloc: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-sanitizers-setup.sh + # - name: Test + # run: bash ./ci-sanitizers-test.sh alloc + + # test-std: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-sanitizers-setup.sh + # - name: Test + # run: bash ./ci-sanitizers-test.sh std + + # test-simd: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-sanitizers-setup.sh + # - name: Test + # run: bash ./ci-sanitizers-test.sh simd + + # test-stdarch: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-sanitizers-setup.sh + # - name: Test + # run: bash ./ci-sanitizers-test.sh stdarch + + # Send a Zulip notification when a cron job fails + # cron-fail-notify: + # name: cronjob failure notification + # runs-on: ubuntu-latest + # needs: [test-core, test-alloc, test-std, test-simd] + # if: github.event_name == 'schedule' && (failure() || cancelled()) + # steps: + # - name: Install zulip-send + # run: pip3 install zulip + # - name: Send Zulip notification + # shell: bash + # env: + # ZULIP_BOT_EMAIL: ${{ secrets.ZULIP_BOT_EMAIL }} + # ZULIP_API_TOKEN: ${{ secrets.ZULIP_API_TOKEN }} + # run: | + # ~/.local/bin/zulip-send --stream miri --subject "Cron Job Failure (miri-test-libstd, $(date -u +%Y-%m))" \ + # --message 'Dear @*T-miri*, + + # The standard library test suite is [failing under Miri]('"https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"'). Would you mind investigating this issue? + + # Thanks in advance! + # Sincerely, + # The Miri Cronjobs Bot' \ + # --user $ZULIP_BOT_EMAIL --api-key $ZULIP_API_TOKEN --site https://rust-lang.zulipchat.com diff --git a/Cargo.toml b/Cargo.toml index acaab28..8826ef6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [workspace] members = [ - "core_miri_test", - "alloc_miri_test", - "std_miri_test", + "core_sanity_test", + "alloc_sanity_test", + "std_sanity_test", ] exclude = [ diff --git a/alloc_miri_test/Cargo.toml b/alloc_sanity_test/Cargo.toml similarity index 92% rename from alloc_miri_test/Cargo.toml rename to alloc_sanity_test/Cargo.toml index ac870d2..4133f8c 100644 --- a/alloc_miri_test/Cargo.toml +++ b/alloc_sanity_test/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "alloc_miri_test" +name = "alloc_sanity_test" version = "0.0.0" autotests = false autobenches = false edition = "2021" [lib] -name = "alloc_miri_test" +name = "alloc_sanity_test" path = "../library/alloc/src/lib.rs" [features] diff --git a/ci-setup.sh b/ci-miri-setup.sh similarity index 100% rename from ci-setup.sh rename to ci-miri-setup.sh diff --git a/ci-test.sh b/ci-miri-test.sh similarity index 94% rename from ci-test.sh rename to ci-miri-test.sh index 4cc514a..6c2b64f 100644 --- a/ci-test.sh +++ b/ci-miri-test.sh @@ -5,9 +5,10 @@ DEFAULTFLAGS="-Zmiri-retag-fields -Zrandomize-layout -Zmiri-strict-provenance" # apply our patch rm -rf rust-src-patched -cp -a $(rustc --print sysroot)/lib/rustlib/src/rust/ rust-src-patched +cp -a "$(rustc --print sysroot)/lib/rustlib/src/rust/" rust-src-patched ( cd rust-src-patched && patch -f -p1 < ../rust-src.diff >/dev/null ) || ( echo "Applying rust-src.diff failed!" && exit 1 ) -export MIRI_LIB_SRC=$(pwd)/rust-src-patched/library +MIRI_LIB_SRC="$(pwd)/rust-src-patched/library" +export MIRI_LIB_SRC # run the tests (some also without validation, to exercise those code paths in Miri) case "$1" in @@ -60,13 +61,13 @@ std) echo "::group::Testing std core ($CORE on $TARGET)" MIRIFLAGS="$DEFAULTFLAGS -Zmiri-disable-isolation" \ ./run-test.sh std --target $TARGET --lib --tests \ - -- $CORE \ + -- "$CORE" \ 2>&1 | ts -i '%.s ' echo "::endgroup::" echo "::group::Testing std core docs ($CORE on $TARGET, ignore leaks)" MIRIFLAGS="$DEFAULTFLAGS -Zmiri-ignore-leaks -Zmiri-disable-isolation" \ ./run-test.sh std --target $TARGET --doc \ - -- $CORE \ + -- "$CORE" \ 2>&1 | ts -i '%.s ' echo "::endgroup::" done @@ -85,7 +86,7 @@ std) echo "::endgroup::" ;; simd) - cd $MIRI_LIB_SRC/portable-simd + cd "$MIRI_LIB_SRC/portable-simd" export RUSTFLAGS="-Ainternal_features ${RUSTFLAGS:-}" export RUSTDOCFLAGS="-Ainternal_features ${RUSTDOCFLAGS:-}" @@ -108,7 +109,7 @@ stdarch) for TARGET in x86_64-unknown-linux-gnu i686-unknown-linux-gnu; do echo "::group::Testing stdarch ($TARGET)" MIRIFLAGS="$DEFAULTFLAGS" \ - ./run-stdarch-test.sh $TARGET \ + ./miri-run-stdarch-test.sh $TARGET \ 2>&1 | ts -i '%.s ' echo "::endgroup::" done diff --git a/ci-sanitizers-setup.sh b/ci-sanitizers-setup.sh new file mode 100644 index 0000000..a996424 --- /dev/null +++ b/ci-sanitizers-setup.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -eauxo pipefail + +## Shared setup code for CI jobs + +# We need 'ts' +sudo apt-get -y install moreutils +echo + +# And of course we need Rust +if [[ "$GITHUB_EVENT_NAME" == 'schedule' ]]; then + RUST_TOOLCHAIN=nightly +else + RUST_TOOLCHAIN=$(cat rust-version) +fi +echo "Installing Rust version: $RUST_TOOLCHAIN" +rustup toolchain install "$RUST_TOOLCHAIN" +rustup override set "$RUST_TOOLCHAIN" diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh new file mode 100755 index 0000000..2c912db --- /dev/null +++ b/ci-sanitizers-test.sh @@ -0,0 +1,174 @@ +#!/bin/bash +set -eauxo pipefail + +DEFAULTFLAGS="-Zrandomize-layout" + +# apply our patch +rm -rf rust-src-patched +cp -a "$(rustc --print sysroot)/lib/rustlib/src/rust/" rust-src-patched +( cd rust-src-patched && patch -f -p1 < ../rust-src.diff >/dev/null ) || ( echo "Applying rust-src.diff failed!" && exit 1 ) +LIB_SRC="$(pwd)/rust-src-patched/library" +export LIB_SRC + +case "$2" in +address) + # FIXME: if on aarch64-{unknown}-linux-{android, gnu}, we can use `hwaddress` + # instead of `address` which should be faster. Unfortunately we probably + # don't have that in CI + SANITIZER=address + ;; +hwaddress) + # see above + echo "we don't have a CI target for this yet" + exit 1 + ;; +kasan) + echo "we aren't a kernel, can't use kasan" + exit 1 + ;; +memory) + SANITIZER=memory + ;; +memtag) + # FIXME: alternative to MSAN with the same target restrictions as hwaddress + SANITIZER=memtag + ecbo "we don't have a CI target for this yet" + exit 1 + ;; +cfi) + SANITIZER=cfi + # cfi needs LTO + EXTRAFLAGS="-Clto" + ;; +kcfi) + SANITIZER=kcfi + ;; +safestack) + # FIXME: aarch64-linux-android only + SANITIZER=safestack + ;; +shadow-call-stack) + SANITIZER=shadow-call-stack + echo "we don't have a CI target for this yet" + exit 1 + ;; +leak) + SANITIZER=leak + ;; +thread) + SANITIZER=thread + ;; +*) + echo "unknown sanitizer $2" + exit 1 +esac + + +# run the tests (some also without validation, to exercise those code paths in Miri) +case "$1" in +core) + # A 64bit little-endian and a 32bit big-endian target. + # (Varying the OS is totally pointless for core.) + for TARGET in x86_64-unknown-linux-gnu mips-unknown-linux-gnu; do + echo "::group::Testing core ($TARGET, $SANITIZER)" + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + ./run-test.sh core --target $TARGET --lib --tests \ + -- --skip align \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + echo "::group::Testing core ($TARGET, $SANITIZER)" + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + ./run-test.sh core --target $TARGET --lib --tests \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + echo "::group::Testing core docs ($TARGET, $SANITIZER)" && echo + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + ./run-test.sh core --target $TARGET --doc \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + done + ;; +alloc) + # A 64bit little-endian and a 32bit big-endian target. + # (Varying the OS is not really worth it for alloc.) + for TARGET in x86_64-unknown-linux-gnu mips-unknown-linux-gnu; do + echo "::group::Testing alloc ($SANITIZER, $TARGET, $SANITIZER)" + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + ./run-test.sh alloc --target $TARGET --lib --tests \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + echo "::group::Testing alloc docs ($TARGET, $SANITIZER)" + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + ./run-test.sh alloc --target $TARGET --doc \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + done + ;; +std) + # Modules that we skip entirely, because they need a lot of shims we don't support. + SKIP="fs:: net:: process:: sys:: sys_common::net::" + # Core modules, that we are testing on a bunch of targets. + # These are the most OS-specific (among the modules we do not skip). + CORE="time:: sync:: thread:: env::" + + for TARGET in x86_64-unknown-linux-gnu aarch64-apple-darwin x86_64-pc-windows-msvc i686-pc-windows-gnu; do + echo "::group::Testing std core ($CORE on $TARGET)" + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + ./run-test.sh std --target $TARGET --lib --tests \ + -- $CORE \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + echo "::group::Testing std core docs ($CORE on $TARGET, $SANITIZER)" + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + ./run-test.sh std --target $TARGET --doc \ + -- $CORE \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + done + # "sleep" has a thread leak that we have to ignore + echo "::group::Testing remaining std (all except for $SKIP, $SANITIZER)" + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + ./run-test.sh std --lib --tests \ + -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + echo "::group::Testing remaining std docs (all except for $SKIP, $SANITIZER)" + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + ./run-test.sh std --doc \ + -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + ;; +simd) + cd $LIB_SRC/portable-simd + export RUSTFLAGS="-Ainternal_features ${RUSTFLAGS:-}" + export RUSTDOCFLAGS="-Ainternal_features ${RUSTDOCFLAGS:-}" + + echo "::group::Testing portable-simd" + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + cargo miri test --lib --tests -- --skip ptr \ + 2>&1 | ts -i '%.s ' + # This contains some pointer tests that do int/ptr casts, so we need permissive provenance. + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + cargo miri test --lib --tests -- ptr \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + echo "::group::Testing portable-simd docs" + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + cargo miri test --doc \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + ;; +stdarch) + for TARGET in x86_64-unknown-linux-gnu i686-unknown-linux-gnu; do + echo "::group::Testing stdarch ($TARGET, $SANITIZER)" + RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ + ./run-stdarch-test.sh $TARGET \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + done + ;; +*) + echo "Unknown command" + exit 1 +esac diff --git a/core_miri_test/Cargo.toml b/core_sanity_test/Cargo.toml similarity index 92% rename from core_miri_test/Cargo.toml rename to core_sanity_test/Cargo.toml index 3188dea..b2709fe 100644 --- a/core_miri_test/Cargo.toml +++ b/core_sanity_test/Cargo.toml @@ -1,13 +1,13 @@ [package] authors = ["The Rust Project Developers"] -name = "core_miri_test" +name = "core_sanity_test" version = "0.0.0" autotests = false autobenches = false edition = "2021" [lib] -name = "core_miri_test" +name = "core_sanity_test" path = "../library/core/src/lib.rs" test = false bench = false diff --git a/run-stdarch-test.sh b/miri-run-stdarch-test.sh similarity index 98% rename from run-stdarch-test.sh rename to miri-run-stdarch-test.sh index f978302..a22f913 100755 --- a/run-stdarch-test.sh +++ b/miri-run-stdarch-test.sh @@ -58,7 +58,7 @@ export STDARCH_TEST_EVERYTHING=1 # Needed to pass the STDARCH_TEST_EVERYTHING environment variable export MIRIFLAGS="${MIRIFLAGS:-} -Zmiri-disable-isolation" -cd $MIRI_LIB_SRC/stdarch +cd "$MIRI_LIB_SRC/stdarch" cargo miri test \ --target "$TARGET" \ --manifest-path=crates/core_arch/Cargo.toml \ diff --git a/run-test.sh b/miri-run-test.sh similarity index 100% rename from run-test.sh rename to miri-run-test.sh diff --git a/sanitizers-run-stdarch-test.sh b/sanitizers-run-stdarch-test.sh new file mode 100755 index 0000000..8777d7a --- /dev/null +++ b/sanitizers-run-stdarch-test.sh @@ -0,0 +1,63 @@ +#!/bin/bash +set -eauxo pipefail + +## Run stdarch test suite with sanitizers. +## Usage: +## ./run-test.sh TARGET +## Environment variables: +## LIB_SRC: The path to the Rust library directory (`library`). +## RUSTFLAGS: rustc flags (optional) +## MIRIFLAGS: Miri flags (optional) + +if [ $# -ne 1 ]; then + echo "Usage: $0 TARGET" + exit 1 +fi + +export TARGET="$1" + +case "$TARGET" in +i586-*|i686-*|x86_64-*) + RUSTFLAGS="$RUSTFLAGS -C target-feature=+ssse3" + # TEST_ARGS=( + # core_arch::x86::{sse,sse2,sse3,ssse3}:: + # core_arch::x86_64::{sse,sse2}:: + # # FIXME add `#[cfg_attr(miri, ignore)]` to those tests in stdarch + # # These are nontemporal stores, fences, and CSR (FP env status register) accesses + # --skip test_mm_comieq_ss_vs_ucomieq_ss + # --skip test_mm_getcsr_setcsr_1 + # --skip test_mm_getcsr_setcsr_2 + # --skip test_mm_getcsr_setcsr_underflow + # --skip test_mm_sfence + # --skip test_mm_stream_ps + # --skip test_mm_clflush + # --skip test_mm_lfence + # --skip test_mm_maskmoveu_si128 + # --skip test_mm_mfence + # --skip test_mm_stream_pd + # --skip test_mm_stream_si128 + # --skip test_mm_stream_si32 + # --skip test_mm_stream_si64 + # # FIXME fix those in stdarch + # --skip test_mm_rcp_ss # __m128(0.24997461, 13.0, 16.0, 100.0) != __m128(0.24993896, 13.0, 16.0, 100.0) + # --skip test_mm_store1_ps # attempt to subtract with overflow + # --skip test_mm_store_ps # attempt to subtract with overflow + # --skip test_mm_storer_ps # attempt to subtract with overflow + # ) + ;; +*) + echo "Unknown target $TARGET" + exit 1 +esac + +export RUSTFLAGS="$RUSTFLAGS -Ainternal_features" + +# Make sure all tested target features are enabled +export STDARCH_TEST_EVERYTHING=1 +# Needed to pass the STDARCH_TEST_EVERYTHING environment variable + +cd "$LIB_SRC/stdarch" +cargo test \ + --target "$TARGET" \ + --manifest-path=crates/core_arch/Cargo.toml \ + -- "${TEST_ARGS[@]}" diff --git a/sanitizers-run-test.sh b/sanitizers-run-test.sh new file mode 100755 index 0000000..d21d9bd --- /dev/null +++ b/sanitizers-run-test.sh @@ -0,0 +1,40 @@ +#!/bin/bash +set -eauxo pipefail + +## Run a Rust libstd test suite with Miri. +## Usage: +## ./run-test.sh CRATE_NAME CARGO_TEST_ARGS +## Environment variables: +## LIB_SRC: The path to the Rust library directory (`library`). +## Defaults to `$(rustc --print sysroot)/lib/rustlib/src/rust/library`. + +CRATE=${1:-} +if [[ -z "$CRATE" ]]; then + echo "Usage: $0 CRATE_NAME" + exit 1 +fi +shift + +# compute the library directory +LIB_SRC=${LIB_SRC:-$(rustc --print sysroot)/lib/rustlib/src/rust/library} +if ! test -d "$LIB_SRC/core"; then + echo "Rust source dir ($LIB_SRC) does not contain a 'core' subdirectory." + echo "Set LIB_SRC to the Rust source directory, or install the rust-src component." + exit 1 +fi +# macOS does not have a useful readlink/realpath so we have to use Python instead... +LIB_SRC=$(python3 -c 'import os, sys; print(os.path.realpath(sys.argv[1]))' "$LIB_SRC") +export LIB_SRC + +# update symlink +rm -f library +ln -s "$LIB_SRC" library + +# use the rust-src lockfile +cp "$LIB_SRC/../Cargo.lock" Cargo.lock + +echo "running test with RUSTFLAGS ${RUSTFLAGS}" + +# run test +cd "./${CRATE}_sanity_test" +cargo test "$@" diff --git a/std_miri_test/Cargo.toml b/std_sanity_test/Cargo.toml similarity index 96% rename from std_miri_test/Cargo.toml rename to std_sanity_test/Cargo.toml index 2240c34..31954d4 100644 --- a/std_miri_test/Cargo.toml +++ b/std_sanity_test/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "std_miri_test" +name = "std_sanity_test" version = "0.0.0" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/rust.git" @@ -10,7 +10,7 @@ edition = "2021" build = "../library/std/build.rs" [lib] -name = "std_miri_test" +name = "std_sanity_test" path = "../library/std/src/lib.rs" [dependencies] From fcf463dc92dd39be6f1b52d9616f153d1c472773 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 03:15:11 -0400 Subject: [PATCH 02/35] Install lib source, update scripts --- .github/workflows/ci-miri.yaml | 124 ++++++++++++++++---------------- ci-sanitizers-setup.sh | 2 +- ci-sanitizers-test.sh | 125 +++++++++++++++------------------ 3 files changed, 118 insertions(+), 133 deletions(-) diff --git a/.github/workflows/ci-miri.yaml b/.github/workflows/ci-miri.yaml index c8c60a4..c09a79b 100644 --- a/.github/workflows/ci-miri.yaml +++ b/.github/workflows/ci-miri.yaml @@ -11,72 +11,72 @@ on: - cron: '00 2 * * *' # At 02:00 UTC every day (like rustup-components-history). jobs: - test-core: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup environment - run: bash ./ci-miri-setup.sh - - name: Test - run: bash ./ci-miri-test.sh core + # test-core: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-miri-setup.sh + # - name: Test + # run: bash ./ci-miri-test.sh core - test-alloc: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup environment - run: bash ./ci-miri-setup.sh - - name: Test - run: bash ./ci-miri-test.sh alloc + # test-alloc: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-miri-setup.sh + # - name: Test + # run: bash ./ci-miri-test.sh alloc - test-std: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup environment - run: bash ./ci-miri-setup.sh - - name: Test - run: bash ./ci-miri-test.sh std + # test-std: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-miri-setup.sh + # - name: Test + # run: bash ./ci-miri-test.sh std - test-simd: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup environment - run: bash ./ci-miri-setup.sh - - name: Test - run: bash ./ci-miri-test.sh simd + # test-simd: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-miri-setup.sh + # - name: Test + # run: bash ./ci-miri-test.sh simd - test-stdarch: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup environment - run: bash ./ci-miri-setup.sh - - name: Test - run: bash ./ci-miri-test.sh stdarch + # test-stdarch: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-miri-setup.sh + # - name: Test + # run: bash ./ci-miri-test.sh stdarch - # Send a Zulip notification when a cron job fails - cron-fail-notify: - name: cronjob failure notification - runs-on: ubuntu-latest - needs: [test-core, test-alloc, test-std, test-simd] - if: github.event_name == 'schedule' && (failure() || cancelled()) - steps: - - name: Install zulip-send - run: pip3 install zulip - - name: Send Zulip notification - shell: bash - env: - ZULIP_BOT_EMAIL: ${{ secrets.ZULIP_BOT_EMAIL }} - ZULIP_API_TOKEN: ${{ secrets.ZULIP_API_TOKEN }} - run: | - ~/.local/bin/zulip-send --stream miri --subject "Cron Job Failure (miri-test-libstd, $(date -u +%Y-%m))" \ - --message 'Dear @*T-miri*, + # # Send a Zulip notification when a cron job fails + # cron-fail-notify: + # name: cronjob failure notification + # runs-on: ubuntu-latest + # needs: [test-core, test-alloc, test-std, test-simd] + # if: github.event_name == 'schedule' && (failure() || cancelled()) + # steps: + # - name: Install zulip-send + # run: pip3 install zulip + # - name: Send Zulip notification + # shell: bash + # env: + # ZULIP_BOT_EMAIL: ${{ secrets.ZULIP_BOT_EMAIL }} + # ZULIP_API_TOKEN: ${{ secrets.ZULIP_API_TOKEN }} + # run: | + # ~/.local/bin/zulip-send --stream miri --subject "Cron Job Failure (miri-test-libstd, $(date -u +%Y-%m))" \ + # --message 'Dear @*T-miri*, - The standard library test suite is [failing under Miri]('"https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"'). Would you mind investigating this issue? + # The standard library test suite is [failing under Miri]('"https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"'). Would you mind investigating this issue? - Thanks in advance! - Sincerely, - The Miri Cronjobs Bot' \ - --user $ZULIP_BOT_EMAIL --api-key $ZULIP_API_TOKEN --site https://rust-lang.zulipchat.com + # Thanks in advance! + # Sincerely, + # The Miri Cronjobs Bot' \ + # --user $ZULIP_BOT_EMAIL --api-key $ZULIP_API_TOKEN --site https://rust-lang.zulipchat.com diff --git a/ci-sanitizers-setup.sh b/ci-sanitizers-setup.sh index a996424..2bcfe52 100644 --- a/ci-sanitizers-setup.sh +++ b/ci-sanitizers-setup.sh @@ -14,5 +14,5 @@ else RUST_TOOLCHAIN=$(cat rust-version) fi echo "Installing Rust version: $RUST_TOOLCHAIN" -rustup toolchain install "$RUST_TOOLCHAIN" +rustup toolchain install "$RUST_TOOLCHAIN" --components rust-src rustup override set "$RUST_TOOLCHAIN" diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index 2c912db..c82a97d 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -3,6 +3,11 @@ set -eauxo pipefail DEFAULTFLAGS="-Zrandomize-layout" +if [ -Z "${TARGET+x}" ]; then + echo "Env TARGET must be set" + exit 1 +fi + # apply our patch rm -rf rust-src-patched cp -a "$(rustc --print sysroot)/lib/rustlib/src/rust/" rust-src-patched @@ -63,46 +68,38 @@ thread) exit 1 esac +export RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" + +echo "Running tests with sanitizer=$SANITIZER on target $TARGET" # run the tests (some also without validation, to exercise those code paths in Miri) case "$1" in core) - # A 64bit little-endian and a 32bit big-endian target. - # (Varying the OS is totally pointless for core.) - for TARGET in x86_64-unknown-linux-gnu mips-unknown-linux-gnu; do - echo "::group::Testing core ($TARGET, $SANITIZER)" - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ - ./run-test.sh core --target $TARGET --lib --tests \ - -- --skip align \ - 2>&1 | ts -i '%.s ' - echo "::endgroup::" - echo "::group::Testing core ($TARGET, $SANITIZER)" - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ - ./run-test.sh core --target $TARGET --lib --tests \ - 2>&1 | ts -i '%.s ' - echo "::endgroup::" - echo "::group::Testing core docs ($TARGET, $SANITIZER)" && echo - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ - ./run-test.sh core --target $TARGET --doc \ - 2>&1 | ts -i '%.s ' - echo "::endgroup::" - done + echo "::group::Testing core" + ./run-test.sh core --target "$TARGET" --lib --tests -- --skip align \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + + echo "::group::Testing core" + ./run-test.sh core --target "$TARGET" --lib --tests \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + + echo "::group::Testing core docs" && echo + ./run-test.sh core --target "$TARGET" --doc \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" ;; alloc) - # A 64bit little-endian and a 32bit big-endian target. - # (Varying the OS is not really worth it for alloc.) - for TARGET in x86_64-unknown-linux-gnu mips-unknown-linux-gnu; do - echo "::group::Testing alloc ($SANITIZER, $TARGET, $SANITIZER)" - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ - ./run-test.sh alloc --target $TARGET --lib --tests \ - 2>&1 | ts -i '%.s ' - echo "::endgroup::" - echo "::group::Testing alloc docs ($TARGET, $SANITIZER)" - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ - ./run-test.sh alloc --target $TARGET --doc \ - 2>&1 | ts -i '%.s ' - echo "::endgroup::" - done + echo "::group::Testing alloc" + ./run-test.sh alloc --target "$TARGET" --lib --tests \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + + echo "::group::Testing alloc docs" + ./run-test.sh alloc --target "$TARGET" --doc \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" ;; std) # Modules that we skip entirely, because they need a lot of shims we don't support. @@ -111,62 +108,50 @@ std) # These are the most OS-specific (among the modules we do not skip). CORE="time:: sync:: thread:: env::" - for TARGET in x86_64-unknown-linux-gnu aarch64-apple-darwin x86_64-pc-windows-msvc i686-pc-windows-gnu; do - echo "::group::Testing std core ($CORE on $TARGET)" - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ - ./run-test.sh std --target $TARGET --lib --tests \ - -- $CORE \ - 2>&1 | ts -i '%.s ' - echo "::endgroup::" - echo "::group::Testing std core docs ($CORE on $TARGET, $SANITIZER)" - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ - ./run-test.sh std --target $TARGET --doc \ - -- $CORE \ - 2>&1 | ts -i '%.s ' - echo "::endgroup::" - done + echo "::group::Testing std core ($CORE on $TARGET)" + ./run-test.sh std --target "$TARGET" --lib --tests \ + -- $CORE \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + + echo "::group::Testing std core docs ($CORE on $TARGET, $SANITIZER)" + ./run-test.sh std --target "$TARGET" --doc \ + -- $CORE \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + # "sleep" has a thread leak that we have to ignore echo "::group::Testing remaining std (all except for $SKIP, $SANITIZER)" - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ ./run-test.sh std --lib --tests \ - -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ 2>&1 | ts -i '%.s ' + # -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ echo "::endgroup::" + echo "::group::Testing remaining std docs (all except for $SKIP, $SANITIZER)" - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ ./run-test.sh std --doc \ - -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ 2>&1 | ts -i '%.s ' + # -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ echo "::endgroup::" ;; simd) - cd $LIB_SRC/portable-simd - export RUSTFLAGS="-Ainternal_features ${RUSTFLAGS:-}" + cd "$LIB_SRC/portable-simd" + export RUSTFLAGS="-Ainternal_features ${RUSTFLAGS}" export RUSTDOCFLAGS="-Ainternal_features ${RUSTDOCFLAGS:-}" echo "::group::Testing portable-simd" - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ - cargo miri test --lib --tests -- --skip ptr \ - 2>&1 | ts -i '%.s ' + cargo test --lib --tests -- --skip ptr 2>&1 | ts -i '%.s ' # This contains some pointer tests that do int/ptr casts, so we need permissive provenance. - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ - cargo miri test --lib --tests -- ptr \ - 2>&1 | ts -i '%.s ' + cargo test --lib --tests -- ptr 2>&1 | ts -i '%.s ' echo "::endgroup::" + echo "::group::Testing portable-simd docs" - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ - cargo miri test --doc \ - 2>&1 | ts -i '%.s ' + cargo test --doc 2>&1 | ts -i '%.s ' echo "::endgroup::" ;; stdarch) - for TARGET in x86_64-unknown-linux-gnu i686-unknown-linux-gnu; do - echo "::group::Testing stdarch ($TARGET, $SANITIZER)" - RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" \ - ./run-stdarch-test.sh $TARGET \ - 2>&1 | ts -i '%.s ' - echo "::endgroup::" - done + echo "::group::Testing stdarch" + ./run-stdarch-test.sh "$TARGET" 2>&1 | ts -i '%.s ' + echo "::endgroup::" ;; *) echo "Unknown command" From 1a7aec555de8fcd81c1c8293c71fda88519e36c2 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 03:17:37 -0400 Subject: [PATCH 03/35] Command typo --- ci-sanitizers-setup.sh | 2 +- ci-sanitizers-test.sh | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ci-sanitizers-setup.sh b/ci-sanitizers-setup.sh index 2bcfe52..c285f21 100644 --- a/ci-sanitizers-setup.sh +++ b/ci-sanitizers-setup.sh @@ -14,5 +14,5 @@ else RUST_TOOLCHAIN=$(cat rust-version) fi echo "Installing Rust version: $RUST_TOOLCHAIN" -rustup toolchain install "$RUST_TOOLCHAIN" --components rust-src +rustup toolchain install "$RUST_TOOLCHAIN" --component rust-src rustup override set "$RUST_TOOLCHAIN" diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index c82a97d..4990053 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -109,14 +109,12 @@ std) CORE="time:: sync:: thread:: env::" echo "::group::Testing std core ($CORE on $TARGET)" - ./run-test.sh std --target "$TARGET" --lib --tests \ - -- $CORE \ + ./run-test.sh std --target "$TARGET" --lib --tests -- $CORE \ 2>&1 | ts -i '%.s ' echo "::endgroup::" echo "::group::Testing std core docs ($CORE on $TARGET, $SANITIZER)" - ./run-test.sh std --target "$TARGET" --doc \ - -- $CORE \ + ./run-test.sh std --target "$TARGET" --doc -- $CORE \ 2>&1 | ts -i '%.s ' echo "::endgroup::" From 554f05b1670e3ea771bf1e72d058e27cf1339341 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 03:21:48 -0400 Subject: [PATCH 04/35] Unbound var --- ci-sanitizers-test.sh | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index 4990053..5f9a141 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -1,9 +1,9 @@ #!/bin/bash set -eauxo pipefail -DEFAULTFLAGS="-Zrandomize-layout" +RUSTFLAGS="-Zrandomize-layout" -if [ -Z "${TARGET+x}" ]; then +if [ -z "${TARGET+x}" ]; then echo "Env TARGET must be set" exit 1 fi @@ -20,7 +20,7 @@ address) # FIXME: if on aarch64-{unknown}-linux-{android, gnu}, we can use `hwaddress` # instead of `address` which should be faster. Unfortunately we probably # don't have that in CI - SANITIZER=address + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=address" ;; hwaddress) # see above @@ -32,45 +32,42 @@ kasan) exit 1 ;; memory) - SANITIZER=memory + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=memory" ;; memtag) # FIXME: alternative to MSAN with the same target restrictions as hwaddress - SANITIZER=memtag + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=memtag" ecbo "we don't have a CI target for this yet" exit 1 ;; cfi) - SANITIZER=cfi # cfi needs LTO - EXTRAFLAGS="-Clto" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Clto" ;; kcfi) - SANITIZER=kcfi + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=kcfi" ;; safestack) # FIXME: aarch64-linux-android only - SANITIZER=safestack + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=safestack" ;; shadow-call-stack) - SANITIZER=shadow-call-stack + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=shadow-call-stack" echo "we don't have a CI target for this yet" exit 1 ;; leak) - SANITIZER=leak + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=leak" ;; thread) - SANITIZER=thread + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=thread" ;; *) echo "unknown sanitizer $2" exit 1 esac -export RUSTFLAGS="$DEFAULTFLAGS -Zsanitizer=$SANITIZER $EXTRAFLAGS" - -echo "Running tests with sanitizer=$SANITIZER on target $TARGET" +echo "Running tests with on target $TARGET with flags '$RUSTFLAGS'" # run the tests (some also without validation, to exercise those code paths in Miri) case "$1" in @@ -109,12 +106,12 @@ std) CORE="time:: sync:: thread:: env::" echo "::group::Testing std core ($CORE on $TARGET)" - ./run-test.sh std --target "$TARGET" --lib --tests -- $CORE \ + ./run-test.sh std --target "$TARGET" --lib --tests -- "$CORE" \ 2>&1 | ts -i '%.s ' echo "::endgroup::" echo "::group::Testing std core docs ($CORE on $TARGET, $SANITIZER)" - ./run-test.sh std --target "$TARGET" --doc -- $CORE \ + ./run-test.sh std --target "$TARGET" --doc -- "$CORE" \ 2>&1 | ts -i '%.s ' echo "::endgroup::" From d8c1612f9236e1c6210dac52e3fa9c5a630e32c1 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 03:28:39 -0400 Subject: [PATCH 05/35] Fix more bash errors --- .github/workflows/ci-sanitizers.yaml | 4 ++++ ci-sanitizers-test.sh | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index f54e21f..53ebbc1 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -10,6 +10,10 @@ on: schedule: - cron: '00 2 * * *' # At 02:00 UTC every day (like rustup-components-history). +# only one target for now +env: + TARGET: x86_64-unknown-linux-gnu + jobs: test-core: runs-on: ubuntu-latest diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index 5f9a141..a8d8402 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -8,6 +8,11 @@ if [ -z "${TARGET+x}" ]; then exit 1 fi +if [ "$#" -ne 2 ]; then + echo "usage: TARGET=target ./this-script.sh lib-name sanitizer-name" + exit 1 +fi + # apply our patch rm -rf rust-src-patched cp -a "$(rustc --print sysroot)/lib/rustlib/src/rust/" rust-src-patched @@ -73,28 +78,28 @@ echo "Running tests with on target $TARGET with flags '$RUSTFLAGS'" case "$1" in core) echo "::group::Testing core" - ./run-test.sh core --target "$TARGET" --lib --tests -- --skip align \ + ./sanitizers-run-test.sh core --target "$TARGET" --lib --tests -- --skip align \ 2>&1 | ts -i '%.s ' echo "::endgroup::" echo "::group::Testing core" - ./run-test.sh core --target "$TARGET" --lib --tests \ + ./sanitizers-run-test.sh core --target "$TARGET" --lib --tests \ 2>&1 | ts -i '%.s ' echo "::endgroup::" echo "::group::Testing core docs" && echo - ./run-test.sh core --target "$TARGET" --doc \ + ./sanitizers-run-test.sh core --target "$TARGET" --doc \ 2>&1 | ts -i '%.s ' echo "::endgroup::" ;; alloc) echo "::group::Testing alloc" - ./run-test.sh alloc --target "$TARGET" --lib --tests \ + ./sanitizers-run-test.sh alloc --target "$TARGET" --lib --tests \ 2>&1 | ts -i '%.s ' echo "::endgroup::" echo "::group::Testing alloc docs" - ./run-test.sh alloc --target "$TARGET" --doc \ + ./sanitizers-run-test.sh alloc --target "$TARGET" --doc \ 2>&1 | ts -i '%.s ' echo "::endgroup::" ;; @@ -106,24 +111,24 @@ std) CORE="time:: sync:: thread:: env::" echo "::group::Testing std core ($CORE on $TARGET)" - ./run-test.sh std --target "$TARGET" --lib --tests -- "$CORE" \ + ./sanitizers-run-test.sh std --target "$TARGET" --lib --tests -- "$CORE" \ 2>&1 | ts -i '%.s ' echo "::endgroup::" echo "::group::Testing std core docs ($CORE on $TARGET, $SANITIZER)" - ./run-test.sh std --target "$TARGET" --doc -- "$CORE" \ + ./sanitizers-run-test.sh std --target "$TARGET" --doc -- "$CORE" \ 2>&1 | ts -i '%.s ' echo "::endgroup::" # "sleep" has a thread leak that we have to ignore echo "::group::Testing remaining std (all except for $SKIP, $SANITIZER)" - ./run-test.sh std --lib --tests \ + ./sanitizers-run-test.sh std --lib --tests \ 2>&1 | ts -i '%.s ' # -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ echo "::endgroup::" echo "::group::Testing remaining std docs (all except for $SKIP, $SANITIZER)" - ./run-test.sh std --doc \ + ./sanitizers-run-test.sh std --doc \ 2>&1 | ts -i '%.s ' # -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ echo "::endgroup::" From cf1f8815a346ce9cc3b862cf8ea257a1209af02f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 03:37:33 -0400 Subject: [PATCH 06/35] Enable tests for all crates --- .github/workflows/ci-sanitizers.yaml | 61 ++++++++-------------------- ci-sanitizers-test.sh | 2 +- 2 files changed, 17 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index 53ebbc1..55e5df2 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -15,56 +15,27 @@ env: TARGET: x86_64-unknown-linux-gnu jobs: - test-core: + enable_matrix: + strategy: + matrix: + crate: [core, alloc, std, simd, stdarch] + name: Test ${{ matrix.crate }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup environment run: bash ./ci-sanitizers-setup.sh - - name: Test ASAN - run: bash ./ci-sanitizers-test.sh core address - - name: Test MSAN - run: bash ./ci-sanitizers-test.sh core memory - - name: Test TSAN - run: bash ./ci-sanitizers-test.sh core thread - - name: Test CFISAN - run: bash ./ci-sanitizers-test.sh core cfi - - # test-alloc: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - # - name: Setup environment - # run: bash ./ci-sanitizers-setup.sh - # - name: Test - # run: bash ./ci-sanitizers-test.sh alloc - - # test-std: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - # - name: Setup environment - # run: bash ./ci-sanitizers-setup.sh - # - name: Test - # run: bash ./ci-sanitizers-test.sh std - - # test-simd: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - # - name: Setup environment - # run: bash ./ci-sanitizers-setup.sh - # - name: Test - # run: bash ./ci-sanitizers-test.sh simd - - # test-stdarch: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - # - name: Setup environment - # run: bash ./ci-sanitizers-setup.sh - # - name: Test - # run: bash ./ci-sanitizers-test.sh stdarch + - name: Test ASAN (Address Sanitizer) + run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} address + - name: Test MSAN (MemorySanitizer) + run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} memory + - name: Test TSAN (ThreadSanitizer) + run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} thread + - name: Test CFISAN (ControlFlowIntegrity) + run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} cfi + - name: Test SafeStack + run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} leak + - name: Test LSAN (LeakSanitizer) # Send a Zulip notification when a cron job fails # cron-fail-notify: diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index a8d8402..6c5080d 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -53,10 +53,10 @@ kcfi) RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=kcfi" ;; safestack) - # FIXME: aarch64-linux-android only RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=safestack" ;; shadow-call-stack) + # FIXME: aarch64-linux-android only RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=shadow-call-stack" echo "we don't have a CI target for this yet" exit 1 From 5417399eefaa9bbeac303b0907e867c18b72d223 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 03:42:10 -0400 Subject: [PATCH 07/35] Fix workflow --- .github/workflows/ci-sanitizers.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index 55e5df2..3740f31 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -34,8 +34,9 @@ jobs: - name: Test CFISAN (ControlFlowIntegrity) run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} cfi - name: Test SafeStack - run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} leak + run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} safestack - name: Test LSAN (LeakSanitizer) + run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} leak # Send a Zulip notification when a cron job fails # cron-fail-notify: From 89838b6a1bc8bf2bffb0958f13eb1a45e59b603b Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 03:49:48 -0400 Subject: [PATCH 08/35] Update test matrix --- .github/workflows/ci-sanitizers.yaml | 18 +++++------------- ci-sanitizers-test.sh | 2 +- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index 3740f31..f984f01 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -17,26 +17,18 @@ env: jobs: enable_matrix: strategy: + max-parallel: 10 # 30 jobs to run... matrix: crate: [core, alloc, std, simd, stdarch] - name: Test ${{ matrix.crate }} + sanitizers: [address, memory, thread, cfi, safestack, leak] + name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup environment run: bash ./ci-sanitizers-setup.sh - - name: Test ASAN (Address Sanitizer) - run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} address - - name: Test MSAN (MemorySanitizer) - run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} memory - - name: Test TSAN (ThreadSanitizer) - run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} thread - - name: Test CFISAN (ControlFlowIntegrity) - run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} cfi - - name: Test SafeStack - run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} safestack - - name: Test LSAN (LeakSanitizer) - run: bash ./ci-sanitizers-test.sh ${{ matrix.crate }} leak + - name: Run ${{ matrix.sanitizer }} + run: ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} # Send a Zulip notification when a cron job fails # cron-fail-notify: diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index 6c5080d..02000f6 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -150,7 +150,7 @@ simd) ;; stdarch) echo "::group::Testing stdarch" - ./run-stdarch-test.sh "$TARGET" 2>&1 | ts -i '%.s ' + ./sanitizers-run-stdarch-test.sh "$TARGET" 2>&1 | ts -i '%.s ' echo "::endgroup::" ;; *) From 1241d067aa38b54d499a33e679759a94bfe7c363 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 03:53:35 -0400 Subject: [PATCH 09/35] fix workflow --- .github/workflows/ci-sanitizers.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index f984f01..f879866 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -20,7 +20,7 @@ jobs: max-parallel: 10 # 30 jobs to run... matrix: crate: [core, alloc, std, simd, stdarch] - sanitizers: [address, memory, thread, cfi, safestack, leak] + sanitizer: [address, memory, thread, cfi, safestack, leak] name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer runs-on: ubuntu-latest steps: From 88be5116e2e3608d1a0f0ae08c8a9b87262fbfa4 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 03:58:00 -0400 Subject: [PATCH 10/35] fix workflow --- Cargo.toml | 1 + ci-sanitizers-test.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8826ef6..df245f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +workspace.resolver = "2" members = [ "core_sanity_test", "alloc_sanity_test", diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index 02000f6..ef3c6a9 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -46,8 +46,8 @@ memtag) exit 1 ;; cfi) - # cfi needs LTO - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Clto" + # cfi needs LTO and 1 CGU... + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Clto -Ccodegen-units=1" ;; kcfi) RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=kcfi" From 86b2c452fb56164a4a7e60740582f13ab955e989 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 04:10:06 -0400 Subject: [PATCH 11/35] Update workflow --- Cargo.toml | 9 +++++---- {alloc_sanity_test => alloc_run_test}/Cargo.toml | 4 ++-- ci-sanitizers-test.sh | 4 +++- {core_sanity_test => core_run_test}/Cargo.toml | 4 ++-- sanitizers-run-test.sh | 2 +- {std_sanity_test => std_run_test}/Cargo.toml | 4 ++-- 6 files changed, 15 insertions(+), 12 deletions(-) rename {alloc_sanity_test => alloc_run_test}/Cargo.toml (92%) rename {core_sanity_test => core_run_test}/Cargo.toml (92%) rename {std_sanity_test => std_run_test}/Cargo.toml (96%) diff --git a/Cargo.toml b/Cargo.toml index df245f3..6c6eda1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,10 @@ [workspace] -workspace.resolver = "2" +resolver = "2" + members = [ - "core_sanity_test", - "alloc_sanity_test", - "std_sanity_test", + "core_run_test", + "alloc_run_test", + "std_run_test", ] exclude = [ diff --git a/alloc_sanity_test/Cargo.toml b/alloc_run_test/Cargo.toml similarity index 92% rename from alloc_sanity_test/Cargo.toml rename to alloc_run_test/Cargo.toml index 4133f8c..6c9084a 100644 --- a/alloc_sanity_test/Cargo.toml +++ b/alloc_run_test/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "alloc_sanity_test" +name = "alloc_run_test" version = "0.0.0" autotests = false autobenches = false edition = "2021" [lib] -name = "alloc_sanity_test" +name = "alloc_run_test" path = "../library/alloc/src/lib.rs" [features] diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index ef3c6a9..c1e0152 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -46,7 +46,9 @@ memtag) exit 1 ;; cfi) - # cfi needs LTO and 1 CGU... + # CFI needs LTO and 1CGU, seems like randomize-layout enables `embed-bitcode=no` + # which conflicts + RUSTFLAGS=${RUSTFLAGS//-Zrandomize-layout/} RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Clto -Ccodegen-units=1" ;; kcfi) diff --git a/core_sanity_test/Cargo.toml b/core_run_test/Cargo.toml similarity index 92% rename from core_sanity_test/Cargo.toml rename to core_run_test/Cargo.toml index b2709fe..aeadb7b 100644 --- a/core_sanity_test/Cargo.toml +++ b/core_run_test/Cargo.toml @@ -1,13 +1,13 @@ [package] authors = ["The Rust Project Developers"] -name = "core_sanity_test" +name = "core_run_test" version = "0.0.0" autotests = false autobenches = false edition = "2021" [lib] -name = "core_sanity_test" +name = "core_run_test" path = "../library/core/src/lib.rs" test = false bench = false diff --git a/sanitizers-run-test.sh b/sanitizers-run-test.sh index d21d9bd..c341330 100755 --- a/sanitizers-run-test.sh +++ b/sanitizers-run-test.sh @@ -36,5 +36,5 @@ cp "$LIB_SRC/../Cargo.lock" Cargo.lock echo "running test with RUSTFLAGS ${RUSTFLAGS}" # run test -cd "./${CRATE}_sanity_test" +cd "./${CRATE}_run_test" cargo test "$@" diff --git a/std_sanity_test/Cargo.toml b/std_run_test/Cargo.toml similarity index 96% rename from std_sanity_test/Cargo.toml rename to std_run_test/Cargo.toml index 31954d4..c45eb7e 100644 --- a/std_sanity_test/Cargo.toml +++ b/std_run_test/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "std_sanity_test" +name = "std_run_test" version = "0.0.0" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/rust.git" @@ -10,7 +10,7 @@ edition = "2021" build = "../library/std/build.rs" [lib] -name = "std_sanity_test" +name = "std_run_test" path = "../library/std/src/lib.rs" [dependencies] From 8c7cb7208236fd2ef2cede6abe49790c451a034b Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 04:14:24 -0400 Subject: [PATCH 12/35] Disable cfi for now --- .github/workflows/ci-sanitizers.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index f879866..7b538f6 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -21,6 +21,10 @@ jobs: matrix: crate: [core, alloc, std, simd, stdarch] sanitizer: [address, memory, thread, cfi, safestack, leak] + exclude: + # FIXME can't get this to compile because of conflicts with lto + # and embed-bitcode + sanitizer: cfi name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer runs-on: ubuntu-latest steps: From b477e377b5e82bcbf4d0aa9385582e8e787b9077 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 04:16:28 -0400 Subject: [PATCH 13/35] Update workflow --- .github/workflows/ci-sanitizers.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index 7b538f6..4a4b1e8 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -24,7 +24,7 @@ jobs: exclude: # FIXME can't get this to compile because of conflicts with lto # and embed-bitcode - sanitizer: cfi + - sanitizer: cfi name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer runs-on: ubuntu-latest steps: From a93f53c1f731df3d6ec52ec243a3e37255832813 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 04:28:12 -0400 Subject: [PATCH 14/35] Update CI once again --- .github/workflows/ci-sanitizers.yaml | 7 +++---- ci-sanitizers-test.sh | 3 +-- sanitizers-run-test.sh | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index 4a4b1e8..f4b1bda 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -13,6 +13,7 @@ on: # only one target for now env: TARGET: x86_64-unknown-linux-gnu + RUST_BACKTRACE: full jobs: enable_matrix: @@ -21,10 +22,8 @@ jobs: matrix: crate: [core, alloc, std, simd, stdarch] sanitizer: [address, memory, thread, cfi, safestack, leak] - exclude: - # FIXME can't get this to compile because of conflicts with lto - # and embed-bitcode - - sanitizer: cfi + # exclude: + # - sanitizer: cfi name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer runs-on: ubuntu-latest steps: diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index c1e0152..b920c92 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -48,8 +48,7 @@ memtag) cfi) # CFI needs LTO and 1CGU, seems like randomize-layout enables `embed-bitcode=no` # which conflicts - RUSTFLAGS=${RUSTFLAGS//-Zrandomize-layout/} - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Clto -Ccodegen-units=1" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Clto -Cembed-bitcode=yes -Ccodegen-units=1" ;; kcfi) RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=kcfi" diff --git a/sanitizers-run-test.sh b/sanitizers-run-test.sh index c341330..61450c9 100755 --- a/sanitizers-run-test.sh +++ b/sanitizers-run-test.sh @@ -37,4 +37,4 @@ echo "running test with RUSTFLAGS ${RUSTFLAGS}" # run test cd "./${CRATE}_run_test" -cargo test "$@" +cargo test -vvv "$@" From 7b57cc205a7399656ba631210c1a46dc84a3269f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 04:31:54 -0400 Subject: [PATCH 15/35] Update wf --- .github/workflows/ci-sanitizers.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index f4b1bda..4cce6aa 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -22,8 +22,11 @@ jobs: matrix: crate: [core, alloc, std, simd, stdarch] sanitizer: [address, memory, thread, cfi, safestack, leak] - # exclude: - # - sanitizer: cfi + exclude: + # FIXME: cfi is a mix of lto, bitcode, 1-cgu, and it doesn't seem to + # even compile + - sanitizer: cfi + crate: core name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer runs-on: ubuntu-latest steps: From d3753c829f4ddb57b5383a5bef7449e2144b5d27 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 04:34:17 -0400 Subject: [PATCH 16/35] Update wf --- .github/workflows/ci-sanitizers.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index 4cce6aa..a8828ba 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -26,7 +26,6 @@ jobs: # FIXME: cfi is a mix of lto, bitcode, 1-cgu, and it doesn't seem to # even compile - sanitizer: cfi - crate: core name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer runs-on: ubuntu-latest steps: From 0cdc3bf7d0dffd1f79aefbf6fa68f21a1dccc5a4 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 04:37:45 -0400 Subject: [PATCH 17/35] Update wf --- .github/workflows/ci-sanitizers.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index a8828ba..349dc6a 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -28,6 +28,9 @@ jobs: - sanitizer: cfi name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer runs-on: ubuntu-latest + # continue running if other tests fail. Disable this once we get out of the + # prototype phase + if: always() steps: - uses: actions/checkout@v3 - name: Setup environment From 6b283c0d4474318c0618b80b6bbef3c65c0c637a Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 04:52:26 -0400 Subject: [PATCH 18/35] Update wf --- .github/workflows/ci-sanitizers.yaml | 4 +++- ci-sanitizers-test.sh | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index 349dc6a..7c4d6dd 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -25,7 +25,9 @@ jobs: exclude: # FIXME: cfi is a mix of lto, bitcode, 1-cgu, and it doesn't seem to # even compile - - sanitizer: cfi + - sanitizer: cfi + # FIXME: we get some failures pretty early here + - sanitizer: memory name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer runs-on: ubuntu-latest # continue running if other tests fail. Disable this once we get out of the diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index b920c92..b2a3c9b 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -20,6 +20,8 @@ cp -a "$(rustc --print sysroot)/lib/rustlib/src/rust/" rust-src-patched LIB_SRC="$(pwd)/rust-src-patched/library" export LIB_SRC +echo "SYMBOLIZER: $(which llvm-symbolizer || none)" + case "$2" in address) # FIXME: if on aarch64-{unknown}-linux-{android, gnu}, we can use `hwaddress` From 3951c0887c25815cb8b66eda4bd8a094382d2a2a Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 05:01:37 -0400 Subject: [PATCH 19/35] Update wf --- ci-sanitizers-test.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index b2a3c9b..967592b 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -113,24 +113,24 @@ std) # These are the most OS-specific (among the modules we do not skip). CORE="time:: sync:: thread:: env::" - echo "::group::Testing std core ($CORE on $TARGET)" + echo "::group::Testing std core" ./sanitizers-run-test.sh std --target "$TARGET" --lib --tests -- "$CORE" \ 2>&1 | ts -i '%.s ' echo "::endgroup::" - echo "::group::Testing std core docs ($CORE on $TARGET, $SANITIZER)" + echo "::group::Testing std core docs" ./sanitizers-run-test.sh std --target "$TARGET" --doc -- "$CORE" \ 2>&1 | ts -i '%.s ' echo "::endgroup::" # "sleep" has a thread leak that we have to ignore - echo "::group::Testing remaining std (all except for $SKIP, $SANITIZER)" + echo "::group::Testing remaining std (all except for $SKIP)" ./sanitizers-run-test.sh std --lib --tests \ 2>&1 | ts -i '%.s ' # -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ echo "::endgroup::" - echo "::group::Testing remaining std docs (all except for $SKIP, $SANITIZER)" + echo "::group::Testing remaining std docs (all except for $SKIP)" ./sanitizers-run-test.sh std --doc \ 2>&1 | ts -i '%.s ' # -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ From e258e7ed40e64d4de19d9869b269c7b9cb39baba Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 05:04:39 -0400 Subject: [PATCH 20/35] Update wf --- .github/workflows/ci-sanitizers.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index 7c4d6dd..9826133 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -28,6 +28,7 @@ jobs: - sanitizer: cfi # FIXME: we get some failures pretty early here - sanitizer: memory + - sanitizer: leak name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer runs-on: ubuntu-latest # continue running if other tests fail. Disable this once we get out of the From e9034487e06c49cd2f1b8f4e3e2771e648f46b62 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 05:14:14 -0400 Subject: [PATCH 21/35] Update wf to not exist so fast --- .github/workflows/ci-sanitizers.yaml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index 9826133..96aa0cd 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -25,10 +25,10 @@ jobs: exclude: # FIXME: cfi is a mix of lto, bitcode, 1-cgu, and it doesn't seem to # even compile - - sanitizer: cfi + # - sanitizer: cfi # FIXME: we get some failures pretty early here - - sanitizer: memory - - sanitizer: leak + # - sanitizer: memory + # - sanitizer: leak name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer runs-on: ubuntu-latest # continue running if other tests fail. Disable this once we get out of the @@ -39,7 +39,12 @@ jobs: - name: Setup environment run: bash ./ci-sanitizers-setup.sh - name: Run ${{ matrix.sanitizer }} - run: ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} + # Mark everything as pass just so GH doesn't cancel on us as soon as there is a failure + run: ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} && echo good! || echo fail! + mark_failure: + runs-on: ubuntu-latest + steps: + - run: sleep 2000 && echo that's enough time!; exit 1 # Send a Zulip notification when a cron job fails # cron-fail-notify: From e9eb56c0d004748e94943ad2f4d7151f6f7e1888 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 05:15:34 -0400 Subject: [PATCH 22/35] update wf --- .github/workflows/ci-sanitizers.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index 96aa0cd..e6bad2b 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -22,7 +22,7 @@ jobs: matrix: crate: [core, alloc, std, simd, stdarch] sanitizer: [address, memory, thread, cfi, safestack, leak] - exclude: + # exclude: # FIXME: cfi is a mix of lto, bitcode, 1-cgu, and it doesn't seem to # even compile # - sanitizer: cfi From 87114574e8740d1d0600c2912532c85d8622ccdf Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 05:16:56 -0400 Subject: [PATCH 23/35] update wf --- .github/workflows/ci-sanitizers.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index e6bad2b..c6f7ba5 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -40,11 +40,11 @@ jobs: run: bash ./ci-sanitizers-setup.sh - name: Run ${{ matrix.sanitizer }} # Mark everything as pass just so GH doesn't cancel on us as soon as there is a failure - run: ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} && echo good! || echo fail! + run: ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} && echo 'good!' || echo 'fail!'' mark_failure: runs-on: ubuntu-latest steps: - - run: sleep 2000 && echo that's enough time!; exit 1 + - run: sleep 2000 && echo that's enough 'time!'; exit 1 # Send a Zulip notification when a cron job fails # cron-fail-notify: From 8f89583383921fa79649ad1e8e6e50d333a15f10 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 05:46:12 -0400 Subject: [PATCH 24/35] Remove filtering of tests --- .github/workflows/ci-sanitizers.yaml | 5 +++-- ci-sanitizers-test.sh | 24 +++++++----------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index c6f7ba5..ad56a24 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -34,17 +34,18 @@ jobs: # continue running if other tests fail. Disable this once we get out of the # prototype phase if: always() + timeout-minutes: 60 steps: - uses: actions/checkout@v3 - name: Setup environment run: bash ./ci-sanitizers-setup.sh - - name: Run ${{ matrix.sanitizer }} + - name: Run ${{ matrix.sanitizer }} sanitizer # Mark everything as pass just so GH doesn't cancel on us as soon as there is a failure run: ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} && echo 'good!' || echo 'fail!'' mark_failure: runs-on: ubuntu-latest steps: - - run: sleep 2000 && echo that's enough 'time!'; exit 1 + - run: sleep 2000 && echo 'that is enough time!'; exit 1 # Send a Zulip notification when a cron job fails # cron-fail-notify: diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index 967592b..f8863c1 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -50,7 +50,7 @@ memtag) cfi) # CFI needs LTO and 1CGU, seems like randomize-layout enables `embed-bitcode=no` # which conflicts - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Clto -Cembed-bitcode=yes -Ccodegen-units=1" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Cembed-bitcode=yes -Ccodegen-units=1" ;; kcfi) RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=kcfi" @@ -81,7 +81,8 @@ echo "Running tests with on target $TARGET with flags '$RUSTFLAGS'" case "$1" in core) echo "::group::Testing core" - ./sanitizers-run-test.sh core --target "$TARGET" --lib --tests -- --skip align \ + # ./sanitizers-run-test.sh core --target "$TARGET" --lib --tests -- --skip align \ + ./sanitizers-run-test.sh core --target "$TARGET" --lib --tests \ 2>&1 | ts -i '%.s ' echo "::endgroup::" @@ -108,33 +109,22 @@ alloc) ;; std) # Modules that we skip entirely, because they need a lot of shims we don't support. - SKIP="fs:: net:: process:: sys:: sys_common::net::" + # SKIP="fs:: net:: process:: sys:: sys_common::net::" # Core modules, that we are testing on a bunch of targets. # These are the most OS-specific (among the modules we do not skip). - CORE="time:: sync:: thread:: env::" + # CORE="time:: sync:: thread:: env::" echo "::group::Testing std core" - ./sanitizers-run-test.sh std --target "$TARGET" --lib --tests -- "$CORE" \ + ./sanitizers-run-test.sh std --target "$TARGET" --lib --tests -- \ 2>&1 | ts -i '%.s ' echo "::endgroup::" echo "::group::Testing std core docs" - ./sanitizers-run-test.sh std --target "$TARGET" --doc -- "$CORE" \ + ./sanitizers-run-test.sh std --target "$TARGET" --doc -- \ 2>&1 | ts -i '%.s ' echo "::endgroup::" # "sleep" has a thread leak that we have to ignore - echo "::group::Testing remaining std (all except for $SKIP)" - ./sanitizers-run-test.sh std --lib --tests \ - 2>&1 | ts -i '%.s ' - # -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ - echo "::endgroup::" - - echo "::group::Testing remaining std docs (all except for $SKIP)" - ./sanitizers-run-test.sh std --doc \ - 2>&1 | ts -i '%.s ' - # -- $(for M in $CORE; do echo "--skip $M "; done) $(for M in $SKIP; do echo "--skip $M "; done) \ - echo "::endgroup::" ;; simd) cd "$LIB_SRC/portable-simd" From 75cbfc30fba782926dcaf50d0cc29d4034d84581 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 05:47:26 -0400 Subject: [PATCH 25/35] Fix misquote in ci --- .github/workflows/ci-sanitizers.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index ad56a24..b657dbe 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -41,7 +41,7 @@ jobs: run: bash ./ci-sanitizers-setup.sh - name: Run ${{ matrix.sanitizer }} sanitizer # Mark everything as pass just so GH doesn't cancel on us as soon as there is a failure - run: ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} && echo 'good!' || echo 'fail!'' + run: ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} && echo 'good!' || echo 'fail!' mark_failure: runs-on: ubuntu-latest steps: From a2173139a1bd4f4b4726a5ac0d90f5d158349856 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 13:52:05 -0400 Subject: [PATCH 26/35] Add llvm-symbolizer to CI --- ci-sanitizers-setup.sh | 4 ++-- ci-sanitizers-test.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ci-sanitizers-setup.sh b/ci-sanitizers-setup.sh index c285f21..edb98d8 100644 --- a/ci-sanitizers-setup.sh +++ b/ci-sanitizers-setup.sh @@ -3,8 +3,8 @@ set -eauxo pipefail ## Shared setup code for CI jobs -# We need 'ts' -sudo apt-get -y install moreutils +# We need 'ts' and 'llvm-symbolizer' +sudo apt-get -y install moreutils llvm echo # And of course we need Rust diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index f8863c1..8618848 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -1,7 +1,7 @@ #!/bin/bash set -eauxo pipefail -RUSTFLAGS="-Zrandomize-layout" +RUSTFLAGS="-Zrandomize-layout -Cdebuginfo=full" if [ -z "${TARGET+x}" ]; then echo "Env TARGET must be set" @@ -50,7 +50,7 @@ memtag) cfi) # CFI needs LTO and 1CGU, seems like randomize-layout enables `embed-bitcode=no` # which conflicts - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Cembed-bitcode=yes -Ccodegen-units=1" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Cembed-bitcode=yes -Cinker-plugin-lto -Ccodegen-units=1" ;; kcfi) RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=kcfi" From a799c45538aef2df8bf00a533b5da30063f5a382 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 14:41:08 -0400 Subject: [PATCH 27/35] Add patches to rust source --- .gitignore | 2 +- ci-sanitizers-setup.sh | 1 + ci-sanitizers-test.sh | 12 ++++++----- rust-src-san.diff | 45 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) mode change 100644 => 100755 ci-sanitizers-setup.sh create mode 100644 rust-src-san.diff diff --git a/.gitignore b/.gitignore index c6696cc..6308e1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ target Cargo.lock -rust-src-patched +rust-src-patched* library diff --git a/ci-sanitizers-setup.sh b/ci-sanitizers-setup.sh old mode 100644 new mode 100755 index edb98d8..5fabcf0 --- a/ci-sanitizers-setup.sh +++ b/ci-sanitizers-setup.sh @@ -13,6 +13,7 @@ if [[ "$GITHUB_EVENT_NAME" == 'schedule' ]]; then else RUST_TOOLCHAIN=$(cat rust-version) fi + echo "Installing Rust version: $RUST_TOOLCHAIN" rustup toolchain install "$RUST_TOOLCHAIN" --component rust-src rustup override set "$RUST_TOOLCHAIN" diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index 8618848..6850fcc 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -1,7 +1,8 @@ #!/bin/bash set -eauxo pipefail -RUSTFLAGS="-Zrandomize-layout -Cdebuginfo=full" +# llvm-symbolizer supports v0 mangling +RUSTFLAGS="-Zrandomize-layout -Cdebuginfo=full -Csymbol-mangling-version=v0 --cfg=skip-slow-tests" if [ -z "${TARGET+x}" ]; then echo "Env TARGET must be set" @@ -14,9 +15,10 @@ if [ "$#" -ne 2 ]; then fi # apply our patch -rm -rf rust-src-patched -cp -a "$(rustc --print sysroot)/lib/rustlib/src/rust/" rust-src-patched -( cd rust-src-patched && patch -f -p1 < ../rust-src.diff >/dev/null ) || ( echo "Applying rust-src.diff failed!" && exit 1 ) +rm -rf rust-src-patched-san +cp -a "$(rustc --print sysroot)/lib/rustlib/src/rust/" rust-src-patched-san +( cd rust-src-patched-san && patch -f -p1 < ../rust-src-san.diff ) || + ( echo "Applying rust-src-san.diff failed!" && exit 1 ) LIB_SRC="$(pwd)/rust-src-patched/library" export LIB_SRC @@ -50,7 +52,7 @@ memtag) cfi) # CFI needs LTO and 1CGU, seems like randomize-layout enables `embed-bitcode=no` # which conflicts - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Cembed-bitcode=yes -Cinker-plugin-lto -Ccodegen-units=1" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Cembed-bitcode=yes -Clinker-plugin-lto -Ccodegen-units=1" ;; kcfi) RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=kcfi" diff --git a/rust-src-san.diff b/rust-src-san.diff new file mode 100644 index 0000000..c281d73 --- /dev/null +++ b/rust-src-san.diff @@ -0,0 +1,45 @@ +diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs +index d44dcfbf673..d3bacbc1586 100644 +--- a/library/alloc/tests/vec.rs ++++ b/library/alloc/tests/vec.rs +@@ -1636,6 +1636,7 @@ fn test_reserve_exact() { + } + + #[test] ++#[no_sanitize] // ASAN throws an error for requesting max allocation size + #[cfg_attr(miri, ignore)] // Miri does not support signalling OOM + #[cfg_attr(target_os = "android", ignore)] // Android used in CI has a broken dlmalloc + fn test_try_reserve() { +diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs +index 865e702b5c2..5efad11a463 100644 +--- a/library/core/tests/slice.rs ++++ b/library/core/tests/slice.rs +@@ -1876,7 +1876,7 @@ fn sort_unstable() { + } + + #[test] +-#[cfg(not(target_arch = "wasm32"))] ++#[cfg(not(any(skip_slow_tests, target_arch = "wasm32")))] + #[cfg_attr(miri, ignore)] // Miri is too slow + fn select_nth_unstable() { + use core::cmp::Ordering::{Equal, Greater, Less}; +@@ -2573,7 +2573,8 @@ macro_rules! empty_max_mut { + }; + } + +-#[cfg(not(miri))] // Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) ++// Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) ++#[cfg(not(any(miri, skip_slow_tests)))] + take_tests! { + slice: &[(); usize::MAX], method: take, + (take_in_bounds_max_range_to, (..usize::MAX), Some(EMPTY_MAX), &[(); 0]), +@@ -2581,7 +2582,8 @@ macro_rules! empty_max_mut { + (take_in_bounds_max_range_from, (usize::MAX..), Some(&[] as _), EMPTY_MAX), + } + +-#[cfg(not(miri))] // Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) ++// Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) ++#[cfg(not(any(miri, skip_slow_tests)))] + take_tests! { + slice: &mut [(); usize::MAX], method: take_mut, + (take_mut_in_bounds_max_range_to, (..usize::MAX), Some(empty_max_mut!()), &mut [(); 0]), From f10922a1a1ec0819537e2b7e236dde14ac1c7e8b Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 15:06:13 -0400 Subject: [PATCH 28/35] Update pathces and cfg --- ci-sanitizers-test.sh | 23 +++++++++++++---------- rust-src-san.diff | 19 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index 6850fcc..a099794 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -2,7 +2,8 @@ set -eauxo pipefail # llvm-symbolizer supports v0 mangling -RUSTFLAGS="-Zrandomize-layout -Cdebuginfo=full -Csymbol-mangling-version=v0 --cfg=skip-slow-tests" +RUSTFLAGS="-Zrandomize-layout -Cdebuginfo=full -Csymbol-mangling-version=v0 \ + --cfg skip_slow_tests" if [ -z "${TARGET+x}" ]; then echo "Env TARGET must be set" @@ -29,7 +30,7 @@ address) # FIXME: if on aarch64-{unknown}-linux-{android, gnu}, we can use `hwaddress` # instead of `address` which should be faster. Unfortunately we probably # don't have that in CI - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=address" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=address --cfg sanitizer=\"address\"" ;; hwaddress) # see above @@ -41,36 +42,38 @@ kasan) exit 1 ;; memory) - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=memory" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=memory --cfg sanitizer=\"memory\"" ;; memtag) # FIXME: alternative to MSAN with the same target restrictions as hwaddress - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=memtag" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=memtag --cfg sanitizer=\"memory\"" ecbo "we don't have a CI target for this yet" exit 1 ;; cfi) # CFI needs LTO and 1CGU, seems like randomize-layout enables `embed-bitcode=no` # which conflicts - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi -Cembed-bitcode=yes -Clinker-plugin-lto -Ccodegen-units=1" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi --cfg sanitizer=\"cfi\" \ + -Cembed-bitcode=yes -Clinker-plugin-lto -Ccodegen-units=1" ;; kcfi) - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=kcfi" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=kcfi --cfg sanitizer=\"cfi\"" ;; safestack) - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=safestack" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=safestack --cfg sanitizer=\"safestack\"" ;; shadow-call-stack) # FIXME: aarch64-linux-android only - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=shadow-call-stack" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=shadow-call-stack \ + --cfg sanitizer=\"shadow-call-stack\"" echo "we don't have a CI target for this yet" exit 1 ;; leak) - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=leak" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=leak --cfg sanitizer=\"leak\"" ;; thread) - RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=thread" + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=thread --cfg sanitizer=\"thread\"" ;; *) echo "unknown sanitizer $2" diff --git a/rust-src-san.diff b/rust-src-san.diff index c281d73..a34e06e 100644 --- a/rust-src-san.diff +++ b/rust-src-san.diff @@ -1,28 +1,29 @@ diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs -index d44dcfbf673..d3bacbc1586 100644 +index d44dcfbf673..28809512f07 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs -@@ -1636,6 +1636,7 @@ fn test_reserve_exact() { +@@ -1636,6 +1636,8 @@ fn test_reserve_exact() { } #[test] -+#[no_sanitize] // ASAN throws an error for requesting max allocation size ++// ASAN throws an error for requesting max allocation size ++#[cfg_attr(sanitzer = "memory", no_sanitize)] #[cfg_attr(miri, ignore)] // Miri does not support signalling OOM #[cfg_attr(target_os = "android", ignore)] // Android used in CI has a broken dlmalloc fn test_try_reserve() { diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs -index 865e702b5c2..5efad11a463 100644 +index 865e702b5c2..c28fb2660aa 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs -@@ -1876,7 +1876,7 @@ fn sort_unstable() { - } +@@ -1877,7 +1877,7 @@ fn sort_unstable() { #[test] --#[cfg(not(target_arch = "wasm32"))] -+#[cfg(not(any(skip_slow_tests, target_arch = "wasm32")))] - #[cfg_attr(miri, ignore)] // Miri is too slow + #[cfg(not(target_arch = "wasm32"))] +-#[cfg_attr(miri, ignore)] // Miri is too slow ++#[cfg_attr(any(miri. skip_slow_tests), ignore)] // Miri is too slow fn select_nth_unstable() { use core::cmp::Ordering::{Equal, Greater, Less}; + use rand::seq::SliceRandom; @@ -2573,7 +2573,8 @@ macro_rules! empty_max_mut { }; } From 12fad0adce52290168bb8b5f21a14a3d46281fe7 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 15:07:56 -0400 Subject: [PATCH 29/35] Fix path --- ci-sanitizers-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index a099794..a8c0889 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -20,7 +20,7 @@ rm -rf rust-src-patched-san cp -a "$(rustc --print sysroot)/lib/rustlib/src/rust/" rust-src-patched-san ( cd rust-src-patched-san && patch -f -p1 < ../rust-src-san.diff ) || ( echo "Applying rust-src-san.diff failed!" && exit 1 ) -LIB_SRC="$(pwd)/rust-src-patched/library" +LIB_SRC="$(pwd)/rust-src-patched-san/library" export LIB_SRC echo "SYMBOLIZER: $(which llvm-symbolizer || none)" From aa9b07cfc58f4fc5723231cfc649ce7ec58063ca Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 15:11:57 -0400 Subject: [PATCH 30/35] Fix syntax --- rust-src-san.diff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-src-san.diff b/rust-src-san.diff index a34e06e..bc9ae2a 100644 --- a/rust-src-san.diff +++ b/rust-src-san.diff @@ -20,7 +20,7 @@ index 865e702b5c2..c28fb2660aa 100644 #[test] #[cfg(not(target_arch = "wasm32"))] -#[cfg_attr(miri, ignore)] // Miri is too slow -+#[cfg_attr(any(miri. skip_slow_tests), ignore)] // Miri is too slow ++#[cfg_attr(any(miri, skip_slow_tests), ignore)] // Miri is too slow fn select_nth_unstable() { use core::cmp::Ordering::{Equal, Greater, Less}; use rand::seq::SliceRandom; From a2ea0ffec70a17f456f4bb5a368f555a7aacb33d Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 15:50:59 -0400 Subject: [PATCH 31/35] Fix stdarch test, clean CI script and unused warnings --- .github/workflows/ci-sanitizers.yaml | 5 ++++- Cargo.toml | 1 + ci-sanitizers-test.sh | 18 +++++------------- rust-src-san.diff | 16 ++++++++++++---- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index b657dbe..6079087 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -41,7 +41,10 @@ jobs: run: bash ./ci-sanitizers-setup.sh - name: Run ${{ matrix.sanitizer }} sanitizer # Mark everything as pass just so GH doesn't cancel on us as soon as there is a failure - run: ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} && echo 'good!' || echo 'fail!' + run: > + ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} && + echo 'good!' || + echo "::endgroup::"; echo 'fail!' mark_failure: runs-on: ubuntu-latest steps: diff --git a/Cargo.toml b/Cargo.toml index 6c6eda1..a1a21b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,5 @@ exclude = [ # stdarch has its own Cargo workspace "library/stdarch", "rust-src-patched/library/stdarch", + "rust-src-patched-san/library/stdarch", ] diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index a8c0889..d1783bc 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -54,7 +54,7 @@ cfi) # CFI needs LTO and 1CGU, seems like randomize-layout enables `embed-bitcode=no` # which conflicts RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi --cfg sanitizer=\"cfi\" \ - -Cembed-bitcode=yes -Clinker-plugin-lto -Ccodegen-units=1" + -Cembed-bitcode=yes -Clto -Ccodegen-units=1" ;; kcfi) RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=kcfi --cfg sanitizer=\"cfi\"" @@ -85,12 +85,6 @@ echo "Running tests with on target $TARGET with flags '$RUSTFLAGS'" # run the tests (some also without validation, to exercise those code paths in Miri) case "$1" in core) - echo "::group::Testing core" - # ./sanitizers-run-test.sh core --target "$TARGET" --lib --tests -- --skip align \ - ./sanitizers-run-test.sh core --target "$TARGET" --lib --tests \ - 2>&1 | ts -i '%.s ' - echo "::endgroup::" - echo "::group::Testing core" ./sanitizers-run-test.sh core --target "$TARGET" --lib --tests \ 2>&1 | ts -i '%.s ' @@ -119,12 +113,12 @@ std) # These are the most OS-specific (among the modules we do not skip). # CORE="time:: sync:: thread:: env::" - echo "::group::Testing std core" + echo "::group::Testing std" ./sanitizers-run-test.sh std --target "$TARGET" --lib --tests -- \ 2>&1 | ts -i '%.s ' echo "::endgroup::" - echo "::group::Testing std core docs" + echo "::group::Testing std docs" ./sanitizers-run-test.sh std --target "$TARGET" --doc -- \ 2>&1 | ts -i '%.s ' echo "::endgroup::" @@ -137,13 +131,11 @@ simd) export RUSTDOCFLAGS="-Ainternal_features ${RUSTDOCFLAGS:-}" echo "::group::Testing portable-simd" - cargo test --lib --tests -- --skip ptr 2>&1 | ts -i '%.s ' - # This contains some pointer tests that do int/ptr casts, so we need permissive provenance. - cargo test --lib --tests -- ptr 2>&1 | ts -i '%.s ' + cargo test --lib --target "$TARGET" --tests -- 2>&1 | ts -i '%.s ' echo "::endgroup::" echo "::group::Testing portable-simd docs" - cargo test --doc 2>&1 | ts -i '%.s ' + cargo test --doc --target "$TARGET" 2>&1 | ts -i '%.s ' echo "::endgroup::" ;; stdarch) diff --git a/rust-src-san.diff b/rust-src-san.diff index bc9ae2a..4e2460d 100644 --- a/rust-src-san.diff +++ b/rust-src-san.diff @@ -1,5 +1,5 @@ diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs -index d44dcfbf673..28809512f07 100644 +index d44dcfbf673..cfa668c28e5 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1636,6 +1636,8 @@ fn test_reserve_exact() { @@ -7,12 +7,12 @@ index d44dcfbf673..28809512f07 100644 #[test] +// ASAN throws an error for requesting max allocation size -+#[cfg_attr(sanitzer = "memory", no_sanitize)] ++#[cfg_attr(any(sanitzer = "memory", sanitizer = "address"), no_sanitize)] #[cfg_attr(miri, ignore)] // Miri does not support signalling OOM #[cfg_attr(target_os = "android", ignore)] // Android used in CI has a broken dlmalloc fn test_try_reserve() { diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs -index 865e702b5c2..c28fb2660aa 100644 +index 865e702b5c2..2e892672248 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs @@ -1877,7 +1877,7 @@ fn sort_unstable() { @@ -24,7 +24,15 @@ index 865e702b5c2..c28fb2660aa 100644 fn select_nth_unstable() { use core::cmp::Ordering::{Equal, Greater, Less}; use rand::seq::SliceRandom; -@@ -2573,7 +2573,8 @@ macro_rules! empty_max_mut { +@@ -2566,14 +2566,15 @@ fn $test_name() { + const EMPTY_MAX: &'static [()] = &[(); usize::MAX]; + + // can't be a constant due to const mutability rules +-#[cfg(not(miri))] // unused in Miri ++#[cfg(not(any(miri, skip_slow_tests)))] // not used if the below tests are disabled + macro_rules! empty_max_mut { + () => { + &mut [(); usize::MAX] as _ }; } From b44c6ee3a024c9ee946df0c38008fd67211a9f31 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 16:03:36 -0400 Subject: [PATCH 32/35] Cleanup attributes in alloc --- rust-src-san.diff | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/rust-src-san.diff b/rust-src-san.diff index 4e2460d..05ded1a 100644 --- a/rust-src-san.diff +++ b/rust-src-san.diff @@ -1,5 +1,17 @@ +diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs +index cd3648214a4..c16d3451da5 100644 +--- a/library/alloc/src/lib.rs ++++ b/library/alloc/src/lib.rs +@@ -138,6 +138,7 @@ + #![feature(maybe_uninit_slice)] + #![feature(maybe_uninit_uninit_array)] + #![feature(maybe_uninit_uninit_array_transpose)] ++#![feature(no_sanitize)] + #![feature(pattern)] + #![feature(pointer_byte_offsets)] + #![feature(ptr_addr_eq)] diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs -index d44dcfbf673..cfa668c28e5 100644 +index d44dcfbf673..386865df6a5 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1636,6 +1636,8 @@ fn test_reserve_exact() { @@ -7,7 +19,7 @@ index d44dcfbf673..cfa668c28e5 100644 #[test] +// ASAN throws an error for requesting max allocation size -+#[cfg_attr(any(sanitzer = "memory", sanitizer = "address"), no_sanitize)] ++#[no_sanitize(address, memory, leak)] #[cfg_attr(miri, ignore)] // Miri does not support signalling OOM #[cfg_attr(target_os = "android", ignore)] // Android used in CI has a broken dlmalloc fn test_try_reserve() { From 299c0221ac91dad54fd94e7cbdd21c6db3cef4e2 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 17:08:39 -0400 Subject: [PATCH 33/35] Update ASAN config --- .github/workflows/ci-sanitizers.yaml | 2 +- ci-sanitizers-test.sh | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml index 6079087..0d7e016 100644 --- a/.github/workflows/ci-sanitizers.yaml +++ b/.github/workflows/ci-sanitizers.yaml @@ -44,7 +44,7 @@ jobs: run: > ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} && echo 'good!' || - echo "::endgroup::"; echo 'fail!' + printf "::endgroup::\nfail!\n"; mark_failure: runs-on: ubuntu-latest steps: diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index d1783bc..c7c3d00 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -5,6 +5,26 @@ set -eauxo pipefail RUSTFLAGS="-Zrandomize-layout -Cdebuginfo=full -Csymbol-mangling-version=v0 \ --cfg skip_slow_tests" +# see https://github.com/google/sanitizers/wiki/AddressSanitizerFlags +# and https://github.com/google/sanitizers/wiki/SanitizerCommonFlags +asan_opts_arr=( + # catch bad global dependencies + check_initialization_order=true + detect_stack_use_after_return=true + # we don't use cstrings much but it could be easy to miss the null + strict_string_checks=true + # give a bit of a hand tracing segfaults + dump_instruction_bytes=true + # detect operations on pointers to different objects + detect_invalid_pointer_pairs=2 + # allow the allocator to return 0 (which we should generally handle well) + # rather than crashing on OOM + allocator_may_return_null=true +) + +export ASAN_OPTIONS="${ASAN_OPTIONS:-} ${asan_opts_arr[*]}" + + if [ -z "${TARGET+x}" ]; then echo "Env TARGET must be set" exit 1 @@ -27,6 +47,10 @@ echo "SYMBOLIZER: $(which llvm-symbolizer || none)" case "$2" in address) + # ASAN poisons regions around allocated memory and memory that has been + # freed, then tracks all pointer use to see whether poisoned regions are + # accessed + # FIXME: if on aarch64-{unknown}-linux-{android, gnu}, we can use `hwaddress` # instead of `address` which should be faster. Unfortunately we probably # don't have that in CI From fafc1d7b9be305576dc8074fc6bb90555bb5183d Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 17:17:59 -0400 Subject: [PATCH 34/35] Fix alloc test --- rust-src-san.diff | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/rust-src-san.diff b/rust-src-san.diff index 05ded1a..68960ea 100644 --- a/rust-src-san.diff +++ b/rust-src-san.diff @@ -11,7 +11,7 @@ index cd3648214a4..c16d3451da5 100644 #![feature(pointer_byte_offsets)] #![feature(ptr_addr_eq)] diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs -index d44dcfbf673..386865df6a5 100644 +index d44dcfbf673..af08cb46ea9 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1636,6 +1636,8 @@ fn test_reserve_exact() { @@ -19,12 +19,12 @@ index d44dcfbf673..386865df6a5 100644 #[test] +// ASAN throws an error for requesting max allocation size -+#[no_sanitize(address, memory, leak)] ++#[no_sanitize(address, memory)] #[cfg_attr(miri, ignore)] // Miri does not support signalling OOM #[cfg_attr(target_os = "android", ignore)] // Android used in CI has a broken dlmalloc fn test_try_reserve() { diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs -index 865e702b5c2..2e892672248 100644 +index 865e702b5c2..7e4eb6d524e 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs @@ -1877,7 +1877,7 @@ fn sort_unstable() { @@ -36,12 +36,17 @@ index 865e702b5c2..2e892672248 100644 fn select_nth_unstable() { use core::cmp::Ordering::{Equal, Greater, Less}; use rand::seq::SliceRandom; -@@ -2566,14 +2566,15 @@ fn $test_name() { +@@ -2562,18 +2562,19 @@ fn $test_name() { + (take_last_mut_empty, (), None, &mut []), + } + +-#[cfg(not(miri))] // unused in Miri ++#[cfg(not(any(miri, skip_slow_tests)))] // not used if the below test macro is disabled const EMPTY_MAX: &'static [()] = &[(); usize::MAX]; // can't be a constant due to const mutability rules -#[cfg(not(miri))] // unused in Miri -+#[cfg(not(any(miri, skip_slow_tests)))] // not used if the below tests are disabled ++#[cfg(not(any(miri, skip_slow_tests)))] // not used if the below test macro is disabled macro_rules! empty_max_mut { () => { &mut [(); usize::MAX] as _ From 705d153fc37bdc01652771e6f70b86d63dfa3ab3 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 6 Oct 2023 18:47:37 -0400 Subject: [PATCH 35/35] Adjust san flags --- ci-sanitizers-test.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh index c7c3d00..68728a3 100755 --- a/ci-sanitizers-test.sh +++ b/ci-sanitizers-test.sh @@ -10,6 +10,8 @@ RUSTFLAGS="-Zrandomize-layout -Cdebuginfo=full -Csymbol-mangling-version=v0 \ asan_opts_arr=( # catch bad global dependencies check_initialization_order=true + # additional global checks + strict_init_order=true detect_stack_use_after_return=true # we don't use cstrings much but it could be easy to miss the null strict_string_checks=true @@ -43,7 +45,8 @@ cp -a "$(rustc --print sysroot)/lib/rustlib/src/rust/" rust-src-patched-san LIB_SRC="$(pwd)/rust-src-patched-san/library" export LIB_SRC -echo "SYMBOLIZER: $(which llvm-symbolizer || none)" +# make sure we have symbolizer so we get useful traces +echo which llvm-symbolizer case "$2" in address) @@ -66,6 +69,8 @@ kasan) exit 1 ;; memory) + # MSAN tracks memory initialization and gives an error if it is read before + # being written. It is somewhat more fragile than other sanitizers RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=memory --cfg sanitizer=\"memory\"" ;; memtag) @@ -94,6 +99,9 @@ shadow-call-stack) exit 1 ;; leak) + # LeakSanitizer looks for memory leaks at the end. It is actually part of + # ASAN so we don't really need to run it on its own. Integration test I guess? + # https://clang.llvm.org/docs/AddressSanitizer.html#id8 RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=leak --cfg sanitizer=\"leak\"" ;; thread)