From dbac2192072a2a8b964be9858d06570da1cc86ba Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 31 Jul 2019 14:04:00 +0200 Subject: [PATCH] Libtest support --- .gitignore | 1 + build_sysroot/Cargo.toml | 2 +- build_sysroot/build_sysroot.sh | 14 ++++++- patches/0017-Fix-libtest-compilation.patch | 49 ++++++++++++++++++++++ src/intrinsics.rs | 14 +++++++ test.sh | 2 +- 6 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 patches/0017-Fix-libtest-compilation.patch diff --git a/.gitignore b/.gitignore index c455aa46a0c..d00d779cb28 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ perf.data.old /build_sysroot/sysroot /build_sysroot/sysroot_src /build_sysroot/Cargo.lock +/build_sysroot/test_target/Cargo.lock /rust /regex diff --git a/build_sysroot/Cargo.toml b/build_sysroot/Cargo.toml index e7d90b730eb..7776f1bd383 100644 --- a/build_sysroot/Cargo.toml +++ b/build_sysroot/Cargo.toml @@ -7,7 +7,7 @@ version = "0.0.0" core = { path = "./sysroot_src/src/libcore" } compiler_builtins = "0.1" alloc = { path = "./sysroot_src/src/liballoc" } -std = { path = "./sysroot_src/src/libstd" } +std = { path = "./sysroot_src/src/libstd", features = ["panic_unwind"] } alloc_system = { path = "./alloc_system" } diff --git a/build_sysroot/build_sysroot.sh b/build_sysroot/build_sysroot.sh index 165d67a8146..4e58858f133 100755 --- a/build_sysroot/build_sysroot.sh +++ b/build_sysroot/build_sysroot.sh @@ -12,7 +12,8 @@ popd >/dev/null # Cleanup for previous run # v Clean target dir except for build scripts and incremental cache rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} || true -rm Cargo.lock 2>/dev/null || true +rm -r sysroot_src/src/{libcore,libtest}/target/$TARGET_TRIPLE/$sysroot_channel/ || true +rm Cargo.lock test_target/Cargo.lock 2>/dev/null || true rm -r sysroot 2>/dev/null || true # Build libs @@ -28,3 +29,14 @@ fi # Copy files to sysroot mkdir -p sysroot/lib/rustlib/$TARGET_TRIPLE/lib/ cp target/$TARGET_TRIPLE/$sysroot_channel/deps/*.rlib sysroot/lib/rustlib/$TARGET_TRIPLE/lib/ + +if [[ "$1" == "--release" ]]; then + channel='release' + RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target $TARGET_TRIPLE --release --manifest-path ./sysroot_src/src/libtest/Cargo.toml +else + channel='debug' + cargo build --target $TARGET_TRIPLE --manifest-path ./sysroot_src/src/libtest/Cargo.toml +fi + +# Copy files to sysroot +cp sysroot_src/src/libtest/target/$TARGET_TRIPLE/$sysroot_channel/deps/*.rlib sysroot/lib/rustlib/$TARGET_TRIPLE/lib/ diff --git a/patches/0017-Fix-libtest-compilation.patch b/patches/0017-Fix-libtest-compilation.patch new file mode 100644 index 00000000000..de035f52f33 --- /dev/null +++ b/patches/0017-Fix-libtest-compilation.patch @@ -0,0 +1,49 @@ +From a25405f1fc4a168c9c370524be48aff8c8ebc529 Mon Sep 17 00:00:00 2001 +From: bjorn3 +Date: Wed, 12 Jun 2019 18:07:23 +0200 +Subject: [PATCH] Fix libtest compilation + +--- + src/libtest/lib.rs | 11 +++++------ + 1 file changed, 5 insertions(+), 6 deletions(-) + +diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs +index 810a98e..4fdde0e 100644 +--- a/src/libtest/lib.rs ++++ b/src/libtest/lib.rs +@@ -1441,11 +1441,11 @@ pub fn run_test( + return; + } + +- fn run_test_inner( ++ fn run_test_inner( + desc: TestDesc, + monitor_ch: Sender, + nocapture: bool, +- testfn: Box, ++ testfn: F, + concurrency: Concurrent, + ) { + // Buffer for capturing standard I/O +@@ -1500,15 +1500,14 @@ pub fn run_test( + (benchfn.clone())(harness) + }); + } +- DynTestFn(f) => { +- let cb = move || __rust_begin_short_backtrace(f); +- run_test_inner(desc, monitor_ch, opts.nocapture, Box::new(cb), concurrency) ++ DynTestFn(_f) => { ++ unimplemented!(); + } + StaticTestFn(f) => run_test_inner( + desc, + monitor_ch, + opts.nocapture, +- Box::new(move || __rust_begin_short_backtrace(f)), ++ move || __rust_begin_short_backtrace(f), + concurrency, + ), + } +-- +2.11.0 + diff --git a/src/intrinsics.rs b/src/intrinsics.rs index 9c5565fa2b5..5beabfb5ee2 100644 --- a/src/intrinsics.rs +++ b/src/intrinsics.rs @@ -1011,6 +1011,20 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>( simd_fmax, (c x, c y) { simd_flt_binop!(fx, intrinsic, fmax(x, y) -> ret); }; + + try, (v f, v data, v _local_ptr) { + // FIXME once unwinding is supported, change this to actually catch panics + let f_sig = fx.bcx.func.import_signature(Signature { + call_conv: cranelift::codegen::isa::CallConv::SystemV, + params: vec![AbiParam::new(fx.bcx.func.dfg.value_type(data))], + returns: vec![], + }); + + fx.bcx.ins().call_indirect(f_sig, f, &[data]); + + let ret_val = CValue::const_val(fx, ret.layout().ty, 0); + ret.write_cvalue(fx, ret_val); + }; } if let Some((_, dest)) = destination { diff --git a/test.sh b/test.sh index 8df6b207964..dc4029bfb33 100755 --- a/test.sh +++ b/test.sh @@ -58,7 +58,7 @@ echo "[TEST] rust-lang/regex example shootout-regex-dna" cat examples/regexdna-input.txt | ../cargo.sh run --example shootout-regex-dna > res.txt diff -u res.txt examples/regexdna-output.txt -# FIXME compile libtest +# FIXME fix "memory allocation of k bytes failed" # echo "[TEST] rust-lang/regex standalone tests" # ../cargo.sh test popd