From 3bd9821342d57081aea18cbb53271a20769eaf03 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 6 Aug 2022 13:34:55 +0100 Subject: [PATCH 1/7] Initial ABI Checker support --- .gitignore | 1 + build_system/abi_checker.rs | 67 +++++++++++++++++++++++++++++++++++++ build_system/mod.rs | 16 +++++++++ build_system/prepare.rs | 7 ++++ 4 files changed, 91 insertions(+) create mode 100644 build_system/abi_checker.rs diff --git a/.gitignore b/.gitignore index 38dd5b26063..6fd3e4443de 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ perf.data.old /regex /simple-raytracer /portable-simd +/abi-checker diff --git a/build_system/abi_checker.rs b/build_system/abi_checker.rs new file mode 100644 index 00000000000..1aff4acc21b --- /dev/null +++ b/build_system/abi_checker.rs @@ -0,0 +1,67 @@ +use super::build_sysroot; +use super::utils::spawn_and_wait_with_input; +use build_system::SysrootKind; +use std::env; +use std::path::Path; +use std::process::Command; + +pub(crate) fn run( + channel: &str, + sysroot_kind: SysrootKind, + target_dir: &Path, + cg_clif_build_dir: &Path, + host_triple: &str, + target_triple: &str, +) { + assert_eq!( + host_triple, target_triple, + "abi-checker not supported on cross-compilation scenarios" + ); + + eprintln!("Building sysroot for abi-checker"); + build_sysroot::build_sysroot( + channel, + sysroot_kind, + target_dir, + cg_clif_build_dir, + host_triple, + target_triple, + ); + + eprintln!("Running abi-checker"); + let mut abi_checker_path = env::current_dir().unwrap(); + abi_checker_path.push("abi-checker"); + env::set_current_dir(abi_checker_path.clone()).unwrap(); + + let build_dir = abi_checker_path.parent().unwrap().join("build"); + let cg_clif_dylib_path = build_dir.join(if cfg!(windows) { "bin" } else { "lib" }).join( + env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX, + ); + println!("cg_clif_dylib_path: {}", cg_clif_dylib_path.display()); + + let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"]; + + for pair in pairs { + eprintln!("[ABI-CHECKER] Running pair {pair}"); + + let mut cmd = Command::new("cargo"); + cmd.arg("run"); + cmd.arg("--target"); + cmd.arg(target_triple); + cmd.arg("--"); + cmd.arg("--pairs"); + cmd.arg(pair); + cmd.arg("--add-rustc-codegen-backend"); + cmd.arg(format!("cgclif:{}", cg_clif_dylib_path.display())); + + let output = spawn_and_wait_with_input(cmd, "".to_string()); + + // TODO: The correct thing to do here is to check the exit code, but abi-checker + // currently doesn't return 0 on success, so check for the test fail count. + // See: https://github.com/Gankra/abi-checker/issues/10 + let failed = !(output.contains("0 failed") && output.contains("0 completely failed")); + if failed { + panic!("abi-checker for pair {} failed!", pair); + } + } +} diff --git a/build_system/mod.rs b/build_system/mod.rs index 88c4150dbba..c5b3e6619b7 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -4,6 +4,7 @@ use std::process; use self::utils::is_ci; +mod abi_checker; mod build_backend; mod build_sysroot; mod config; @@ -21,6 +22,9 @@ fn usage() { eprintln!( " ./y.rs test [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" ); + eprintln!( + " ./y.rs abi-checker [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" + ); } macro_rules! arg_error { @@ -35,6 +39,7 @@ macro_rules! arg_error { enum Command { Build, Test, + AbiChecker, } #[derive(Copy, Clone, Debug)] @@ -66,6 +71,7 @@ pub fn main() { } Some("build") => Command::Build, Some("test") => Command::Test, + Some("abi-checker") => Command::AbiChecker, Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag), Some(command) => arg_error!("Unknown command {}", command), None => { @@ -152,5 +158,15 @@ pub fn main() { &target_triple, ); } + Command::AbiChecker => { + abi_checker::run( + channel, + sysroot_kind, + &target_dir, + &cg_clif_build_dir, + &host_triple, + &target_triple, + ); + } } } diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 7e0fd182d98..12aafdc1fb3 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -14,6 +14,13 @@ pub(crate) fn prepare() { eprintln!("[INSTALL] hyperfine"); Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap(); + clone_repo_shallow_github( + "abi-checker", + "Gankra", + "abi-checker", + "7c1571da6e43f9a37347623e7d5c7d51be664a7b", + ); + clone_repo_shallow_github( "rand", "rust-random", From fb6362e093eca9ad754327b0134aaee3cb3864c3 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 6 Aug 2022 15:59:45 +0100 Subject: [PATCH 2/7] Test adding abi-checker to CI --- .github/workflows/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e8897e9ae81..0b259369e61 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -105,6 +105,11 @@ jobs: ./y.rs test + + - name: Run abi-checker + if: matrix.env.TARGET_TRIPLE == '' + run: ./y.rs abi-checker + - name: Package prebuilt cg_clif run: tar cvfJ cg_clif.tar.xz build From 569312278f1d38cd5634d4fd6fa1beef6ded69e2 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 6 Aug 2022 20:51:20 +0100 Subject: [PATCH 3/7] Add abi-checker to clean_all.sh --- clean_all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean_all.sh b/clean_all.sh index ea1f8c1e892..62e52bd1958 100755 --- a/clean_all.sh +++ b/clean_all.sh @@ -3,4 +3,4 @@ set -e rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version} rm -rf target/ build/ perf.data{,.old} y.bin -rm -rf rand/ regex/ simple-raytracer/ portable-simd/ +rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ From e5ba71a71b79525fdd649624af63fc8770f90835 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 6 Aug 2022 20:51:47 +0100 Subject: [PATCH 4/7] Pass all pairs to abi-checker --- build_system/abi_checker.rs | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/build_system/abi_checker.rs b/build_system/abi_checker.rs index 1aff4acc21b..21d9afc8231 100644 --- a/build_system/abi_checker.rs +++ b/build_system/abi_checker.rs @@ -37,31 +37,26 @@ pub(crate) fn run( let cg_clif_dylib_path = build_dir.join(if cfg!(windows) { "bin" } else { "lib" }).join( env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX, ); - println!("cg_clif_dylib_path: {}", cg_clif_dylib_path.display()); let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"]; - for pair in pairs { - eprintln!("[ABI-CHECKER] Running pair {pair}"); + let mut cmd = Command::new("cargo"); + cmd.arg("run"); + cmd.arg("--target"); + cmd.arg(target_triple); + cmd.arg("--"); + cmd.arg("--pairs"); + cmd.args(pairs); + cmd.arg("--add-rustc-codegen-backend"); + cmd.arg(format!("cgclif:{}", cg_clif_dylib_path.display())); - let mut cmd = Command::new("cargo"); - cmd.arg("run"); - cmd.arg("--target"); - cmd.arg(target_triple); - cmd.arg("--"); - cmd.arg("--pairs"); - cmd.arg(pair); - cmd.arg("--add-rustc-codegen-backend"); - cmd.arg(format!("cgclif:{}", cg_clif_dylib_path.display())); + let output = spawn_and_wait_with_input(cmd, "".to_string()); - let output = spawn_and_wait_with_input(cmd, "".to_string()); - - // TODO: The correct thing to do here is to check the exit code, but abi-checker - // currently doesn't return 0 on success, so check for the test fail count. - // See: https://github.com/Gankra/abi-checker/issues/10 - let failed = !(output.contains("0 failed") && output.contains("0 completely failed")); - if failed { - panic!("abi-checker for pair {} failed!", pair); - } + // TODO: The correct thing to do here is to check the exit code, but abi-checker + // currently doesn't return 0 on success, so check for the test fail count. + // See: https://github.com/Gankra/abi-checker/issues/10 + let failed = !(output.contains("0 failed") && output.contains("0 completely failed")); + if failed { + panic!("abi-checker failed!"); } } From 7610be478f9e67a4e0e13cddb50f171e82cc3170 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 6 Aug 2022 21:24:38 +0100 Subject: [PATCH 5/7] Move abi-checker to y.rs test --- .github/workflows/main.yml | 5 ----- build_system/abi_checker.rs | 14 ++++++++++---- build_system/mod.rs | 24 +++++++++--------------- config.txt | 2 ++ 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0b259369e61..e8897e9ae81 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -105,11 +105,6 @@ jobs: ./y.rs test - - - name: Run abi-checker - if: matrix.env.TARGET_TRIPLE == '' - run: ./y.rs abi-checker - - name: Package prebuilt cg_clif run: tar cvfJ cg_clif.tar.xz build diff --git a/build_system/abi_checker.rs b/build_system/abi_checker.rs index 21d9afc8231..b6dc0fa6922 100644 --- a/build_system/abi_checker.rs +++ b/build_system/abi_checker.rs @@ -1,4 +1,5 @@ use super::build_sysroot; +use super::config; use super::utils::spawn_and_wait_with_input; use build_system::SysrootKind; use std::env; @@ -13,10 +14,15 @@ pub(crate) fn run( host_triple: &str, target_triple: &str, ) { - assert_eq!( - host_triple, target_triple, - "abi-checker not supported on cross-compilation scenarios" - ); + if !config::get_bool("testsuite.abi-checker") { + eprintln!("[SKIP] abi-checker"); + return; + } + + if host_triple != target_triple { + eprintln!("[SKIP] abi-checker (cross-compilation not supported)"); + return; + } eprintln!("Building sysroot for abi-checker"); build_sysroot::build_sysroot( diff --git a/build_system/mod.rs b/build_system/mod.rs index c5b3e6619b7..c3706dc6f82 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -22,9 +22,6 @@ fn usage() { eprintln!( " ./y.rs test [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" ); - eprintln!( - " ./y.rs abi-checker [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" - ); } macro_rules! arg_error { @@ -39,7 +36,6 @@ macro_rules! arg_error { enum Command { Build, Test, - AbiChecker, } #[derive(Copy, Clone, Debug)] @@ -71,7 +67,6 @@ pub fn main() { } Some("build") => Command::Build, Some("test") => Command::Test, - Some("abi-checker") => Command::AbiChecker, Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag), Some(command) => arg_error!("Unknown command {}", command), None => { @@ -147,6 +142,15 @@ pub fn main() { &host_triple, &target_triple, ); + + abi_checker::run( + channel, + sysroot_kind, + &target_dir, + &cg_clif_build_dir, + &host_triple, + &target_triple, + ); } Command::Build => { build_sysroot::build_sysroot( @@ -158,15 +162,5 @@ pub fn main() { &target_triple, ); } - Command::AbiChecker => { - abi_checker::run( - channel, - sysroot_kind, - &target_dir, - &cg_clif_build_dir, - &host_triple, - &target_triple, - ); - } } } diff --git a/config.txt b/config.txt index 5e4d230776d..2264d301d59 100644 --- a/config.txt +++ b/config.txt @@ -48,3 +48,5 @@ test.libcore test.regex-shootout-regex-dna test.regex test.portable-simd + +testsuite.abi-checker From 0706df5f8cfd5bdd164d10bb67facc2a6c5f6b8f Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Fri, 12 Aug 2022 21:47:36 +0100 Subject: [PATCH 6/7] Update abi-checker version --- build_system/abi_checker.rs | 12 ++---------- build_system/prepare.rs | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/build_system/abi_checker.rs b/build_system/abi_checker.rs index b6dc0fa6922..67dbd0a38a4 100644 --- a/build_system/abi_checker.rs +++ b/build_system/abi_checker.rs @@ -1,6 +1,6 @@ use super::build_sysroot; use super::config; -use super::utils::spawn_and_wait_with_input; +use super::utils::spawn_and_wait; use build_system::SysrootKind; use std::env; use std::path::Path; @@ -56,13 +56,5 @@ pub(crate) fn run( cmd.arg("--add-rustc-codegen-backend"); cmd.arg(format!("cgclif:{}", cg_clif_dylib_path.display())); - let output = spawn_and_wait_with_input(cmd, "".to_string()); - - // TODO: The correct thing to do here is to check the exit code, but abi-checker - // currently doesn't return 0 on success, so check for the test fail count. - // See: https://github.com/Gankra/abi-checker/issues/10 - let failed = !(output.contains("0 failed") && output.contains("0 completely failed")); - if failed { - panic!("abi-checker failed!"); - } + spawn_and_wait(cmd); } diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 12aafdc1fb3..24a233d3806 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -18,7 +18,7 @@ pub(crate) fn prepare() { "abi-checker", "Gankra", "abi-checker", - "7c1571da6e43f9a37347623e7d5c7d51be664a7b", + "a2232d45f202846f5c02203c9f27355360f9a2ff", ); clone_repo_shallow_github( From 69c6749aee93ee3c5dd3b9b394eef612d48dd6cd Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Fri, 12 Aug 2022 23:47:12 +0100 Subject: [PATCH 7/7] Disable some abi-checker tests --- build_system/prepare.rs | 1 + ...29-abi-checker-Disable-failing-tests.patch | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 patches/0029-abi-checker-Disable-failing-tests.patch diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 24a233d3806..d23b7f00dcf 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -20,6 +20,7 @@ pub(crate) fn prepare() { "abi-checker", "a2232d45f202846f5c02203c9f27355360f9a2ff", ); + apply_patches("abi-checker", Path::new("abi-checker")); clone_repo_shallow_github( "rand", diff --git a/patches/0029-abi-checker-Disable-failing-tests.patch b/patches/0029-abi-checker-Disable-failing-tests.patch new file mode 100644 index 00000000000..526366a7598 --- /dev/null +++ b/patches/0029-abi-checker-Disable-failing-tests.patch @@ -0,0 +1,36 @@ +From 1a315ba225577dbbd1f449d9609f16f984f68708 Mon Sep 17 00:00:00 2001 +From: Afonso Bordado +Date: Fri, 12 Aug 2022 22:51:58 +0000 +Subject: [PATCH] Disable abi-checker tests + +--- + src/report.rs | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +diff --git a/src/report.rs b/src/report.rs +index 7346f5e..8347762 100644 +--- a/src/report.rs ++++ b/src/report.rs +@@ -45,6 +45,20 @@ pub fn get_test_rules(test: &TestKey, caller: &dyn AbiImpl, callee: &dyn AbiImpl + // + // THIS AREA RESERVED FOR VENDORS TO APPLY PATCHES + ++ // Currently MSVC has some broken ABI issues. Furthermore, they cause ++ // a STATUS_ACCESS_VIOLATION, so we can't even run them. Ensure that they compile and link. ++ if cfg!(windows) && (test.test_name == "bool" || test.test_name == "ui128") { ++ result.run = Link; ++ result.check = Pass(Link); ++ } ++ ++ // structs is broken in the current release of cranelift for aarch64. ++ // It has been fixed for cranelift 0.88: https://github.com/bytecodealliance/wasmtime/pull/4634 ++ if cfg!(target_arch = "aarch64") && test.test_name == "structs" { ++ result.run = Link; ++ result.check = Pass(Link); ++ } ++ + // END OF VENDOR RESERVED AREA + // + // +-- +2.34.1