Skip to content

Commit

Permalink
Add patches to rust source
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Oct 6, 2023
1 parent a217313 commit a799c45
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target
Cargo.lock
rust-src-patched
rust-src-patched*
library
1 change: 1 addition & 0 deletions ci-sanitizers-setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 7 additions & 5 deletions ci-sanitizers-test.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand Down
45 changes: 45 additions & 0 deletions rust-src-san.diff
Original file line number Diff line number Diff line change
@@ -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]),

0 comments on commit a799c45

Please sign in to comment.