From 27824786e6249cfaf0824b169d74f05b388c172d Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 2 Aug 2024 13:15:10 -0400 Subject: [PATCH 1/2] rewrite incr-add-rust-src-component to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../incr-add-rust-src-component/Makefile | 45 ------------------- .../incr-add-rust-src-component/rmake.rs | 22 +++++++++ 3 files changed, 22 insertions(+), 46 deletions(-) delete mode 100644 tests/run-make/incr-add-rust-src-component/Makefile create mode 100644 tests/run-make/incr-add-rust-src-component/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 2d25de46f6e4a..a0dc9aaec7d06 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -5,7 +5,6 @@ run-make/dep-info-spaces/Makefile run-make/dep-info/Makefile run-make/emit-to-stdout/Makefile run-make/extern-fn-reachable/Makefile -run-make/incr-add-rust-src-component/Makefile run-make/issue-84395-lto-embed-bitcode/Makefile run-make/jobserver-error/Makefile run-make/libs-through-symlinks/Makefile diff --git a/tests/run-make/incr-add-rust-src-component/Makefile b/tests/run-make/incr-add-rust-src-component/Makefile deleted file mode 100644 index fd09c2299f98e..0000000000000 --- a/tests/run-make/incr-add-rust-src-component/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# rust-lang/rust#70924: Test that if we add rust-src component in between two -# incremental compiles, the compiler does not ICE on the second. - -# This test uses `ln -s` rather than copying to save testing time, but its -# usage doesn't work on windows. So ignore windows. - -# ignore-windows - -SYSROOT:=$(shell $(RUSTC) --print sysroot) -FAKEROOT=$(TMPDIR)/fakeroot -INCR=$(TMPDIR)/incr - -# Make a local copy of the sysroot; then remove the rust-src part of it, if -# present, for the *first* build. Then put in a facsimile of the rust-src -# component for the second build, in order to expose the ICE from issue #70924. -# -# Note that it is much easier to just do `cp -a $(SYSROOT)/* $(FAKEROOT)` as a -# first step, but I am concerned that would be too expensive in a unit test -# compared to making symbolic links. -# -# Anyway, the pattern you'll see here is: For every prefix in -# root/lib/rustlib/src, link all of prefix parent content, then remove the -# prefix, then loop on the next prefix. This way, we basically create a copy of -# the context around root/lib/rustlib/src, and can freely add/remove the src -# component itself. -all: - mkdir $(FAKEROOT) - ln -s $(SYSROOT)/* $(FAKEROOT) - rm -f $(FAKEROOT)/lib - mkdir $(FAKEROOT)/lib - ln -s $(SYSROOT)/lib/* $(FAKEROOT)/lib - rm -f $(FAKEROOT)/lib/rustlib - mkdir $(FAKEROOT)/lib/rustlib - ln -s $(SYSROOT)/lib/rustlib/* $(FAKEROOT)/lib/rustlib - rm -f $(FAKEROOT)/lib/rustlib/src - mkdir $(FAKEROOT)/lib/rustlib/src - ln -s $(SYSROOT)/lib/rustlib/src/* $(FAKEROOT)/lib/rustlib/src - rm -f $(FAKEROOT)/lib/rustlib/src/rust - $(RUSTC) --sysroot $(FAKEROOT) -C incremental=$(INCR) main.rs - mkdir -p $(FAKEROOT)/lib/rustlib/src/rust/src/libstd - touch $(FAKEROOT)/lib/rustlib/src/rust/src/libstd/lib.rs - $(RUSTC) --sysroot $(FAKEROOT) -C incremental=$(INCR) main.rs diff --git a/tests/run-make/incr-add-rust-src-component/rmake.rs b/tests/run-make/incr-add-rust-src-component/rmake.rs new file mode 100644 index 0000000000000..b43cf9cb027ea --- /dev/null +++ b/tests/run-make/incr-add-rust-src-component/rmake.rs @@ -0,0 +1,22 @@ +// rust-lang/rust#70924: Test that if we add rust-src component in between two +// incremental compiles, the compiler does not ICE on the second. +// Remove the rust-src part of the sysroot for the *first* build. +// Then put in a facsimile of the rust-src +// component for the second build, in order to expose the ICE from issue #70924. +// See https://github.com/rust-lang/rust/pull/72952 + +//FIXME(Oneirical): try on test-various and windows +//FIXME(Oneirical): check that the direct edit of the sysroot is not messing things up + +use run_make_support::{path, rfs, rustc}; + +fn main() { + let sysroot = rustc().print("sysroot").run().stdout_utf8(); + let sysroot = sysroot.trim(); + let sysroot = format!("{sysroot}-sysroot"); + rfs::remove_dir_all(path(&sysroot).join("lib/rustlib/src/rust")); + rustc().arg("--sysroot").arg(&sysroot).incremental("incr").input("main.rs").run(); + rfs::create_dir_all(path(&sysroot).join("lib/rustlib/src/rust/src/libstd")); + rfs::create_file(path(&sysroot).join("lib/rustlib/src/rust/src/libstd/lib.rs")); + rustc().arg("--sysroot").arg(&sysroot).incremental("incr").input("main.rs").run(); +} From 3f4869289d579577cbbbadad495756d4144bd12d Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 2 Aug 2024 13:37:00 -0400 Subject: [PATCH 2/2] rewrite and rename issue-84395-lto-embed-bitcode to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../incr-add-rust-src-component/rmake.rs | 39 +++++++++++++------ .../issue-84395-lto-embed-bitcode/Makefile | 14 ------- .../run-make/lto-embed-bitcode-clang/rmake.rs | 30 ++++++++++++++ .../test.rs | 0 5 files changed, 58 insertions(+), 26 deletions(-) delete mode 100644 tests/run-make/issue-84395-lto-embed-bitcode/Makefile create mode 100644 tests/run-make/lto-embed-bitcode-clang/rmake.rs rename tests/run-make/{issue-84395-lto-embed-bitcode => lto-embed-bitcode-clang}/test.rs (100%) diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index a0dc9aaec7d06..937f98543b562 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -5,7 +5,6 @@ run-make/dep-info-spaces/Makefile run-make/dep-info/Makefile run-make/emit-to-stdout/Makefile run-make/extern-fn-reachable/Makefile -run-make/issue-84395-lto-embed-bitcode/Makefile run-make/jobserver-error/Makefile run-make/libs-through-symlinks/Makefile run-make/libtest-json/Makefile diff --git a/tests/run-make/incr-add-rust-src-component/rmake.rs b/tests/run-make/incr-add-rust-src-component/rmake.rs index b43cf9cb027ea..fa2bd24f127c9 100644 --- a/tests/run-make/incr-add-rust-src-component/rmake.rs +++ b/tests/run-make/incr-add-rust-src-component/rmake.rs @@ -1,22 +1,39 @@ -// rust-lang/rust#70924: Test that if we add rust-src component in between two -// incremental compiles, the compiler does not ICE on the second. +// rust-lang/rust#70924: Test that if we add rust-src component in between +// two incremental compiles, the compiler does not ICE on the second. // Remove the rust-src part of the sysroot for the *first* build. -// Then put in a facsimile of the rust-src +// Then put in a copy of the rust-src // component for the second build, in order to expose the ICE from issue #70924. // See https://github.com/rust-lang/rust/pull/72952 -//FIXME(Oneirical): try on test-various and windows -//FIXME(Oneirical): check that the direct edit of the sysroot is not messing things up +//@ needs-symlink + +//FIXME(Oneirical): try on test-various use run_make_support::{path, rfs, rustc}; fn main() { let sysroot = rustc().print("sysroot").run().stdout_utf8(); let sysroot = sysroot.trim(); - let sysroot = format!("{sysroot}-sysroot"); - rfs::remove_dir_all(path(&sysroot).join("lib/rustlib/src/rust")); - rustc().arg("--sysroot").arg(&sysroot).incremental("incr").input("main.rs").run(); - rfs::create_dir_all(path(&sysroot).join("lib/rustlib/src/rust/src/libstd")); - rfs::create_file(path(&sysroot).join("lib/rustlib/src/rust/src/libstd/lib.rs")); - rustc().arg("--sysroot").arg(&sysroot).incremental("incr").input("main.rs").run(); + rfs::create_dir("fakeroot"); + symlink_all_entries(&sysroot, "fakeroot"); + rfs::remove_file("fakeroot/lib"); + rfs::create_dir("fakeroot/lib"); + symlink_all_entries(path(&sysroot).join("lib"), "fakeroot/lib"); + rfs::remove_file("fakeroot/lib/rustlib"); + rfs::create_dir("fakeroot/lib/rustlib"); + symlink_all_entries(path(&sysroot).join("lib/rustlib"), "fakeroot/lib/rustlib"); + rfs::remove_file("fakeroot/lib/rustlib/src"); + rfs::create_dir("fakeroot/lib/rustlib/src"); + symlink_all_entries(path(&sysroot).join("lib/rustlib/src"), "fakeroot/lib/rustlib/src"); + rfs::remove_file("fakeroot/lib/rustlib/src/rust"); + rustc().sysroot("fakeroot").incremental("incr").input("main.rs").run(); + rfs::create_dir_all("fakeroot/lib/rustlib/src/rust/src/libstd"); + rfs::create_file("fakeroot/lib/rustlib/src/rust/src/libstd/lib.rs"); + rustc().sysroot("fakeroot").incremental("incr").input("main.rs").run(); +} + +fn symlink_all_entries>(dir: P, fakepath: &str) { + for found_path in rfs::shallow_find_dir_entries(dir) { + rfs::create_symlink(&found_path, path(fakepath).join(found_path.file_name().unwrap())); + } } diff --git a/tests/run-make/issue-84395-lto-embed-bitcode/Makefile b/tests/run-make/issue-84395-lto-embed-bitcode/Makefile deleted file mode 100644 index aabe90754a654..0000000000000 --- a/tests/run-make/issue-84395-lto-embed-bitcode/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# needs-force-clang-based-tests - -# FIXME(#126180): This test doesn't actually run anywhere, because the only -# CI job that sets RUSTBUILD_FORCE_CLANG_BASED_TESTS runs very few tests. - -# This test makes sure the embed bitcode in elf created with -# lto-embed-bitcode=optimized is valid llvm BC module. - -include ../tools.mk - -all: - $(RUSTC) test.rs --target $(TARGET) -Clink-arg=-fuse-ld=lld -Clinker-plugin-lto -Clinker=$(CLANG) -Clink-arg=-Wl,--plugin-opt=-lto-embed-bitcode=optimized -Zemit-thin-lto=no - $(LLVM_BIN_DIR)/objcopy --dump-section .llvmbc=$(TMPDIR)/test.bc $(TMPDIR)/test - $(LLVM_BIN_DIR)/llvm-dis $(TMPDIR)/test.bc diff --git a/tests/run-make/lto-embed-bitcode-clang/rmake.rs b/tests/run-make/lto-embed-bitcode-clang/rmake.rs new file mode 100644 index 0000000000000..db29fbe7aae2a --- /dev/null +++ b/tests/run-make/lto-embed-bitcode-clang/rmake.rs @@ -0,0 +1,30 @@ +// This test checks that the embed bitcode in elf created with +// lto-embed-bitcode=optimized is a valid llvm bitcode module. +// Otherwise, the `test.bc` file will cause an error when +// `llvm-dis` attempts to disassemble it. +// See https://github.com/rust-lang/rust/issues/84395 + +//@ needs-force-clang-based-tests +// NOTE(#126180): This test only runs on `x86_64-gnu-debug`, because that CI job sets +// RUSTBUILD_FORCE_CLANG_BASED_TESTS and only runs tests which contain "clang" in their +// name. + +use run_make_support::llvm::llvm_bin_dir; +use run_make_support::{cmd, env_var, rustc}; + +fn main() { + rustc() + .input("test.rs") + .link_arg("-fuse-ld=lld") + .arg("-Clinker-plugin-lto") + .linker(&env_var("CLANG")) + .link_arg("-Wl,--plugin-opt=-lto-embed-bitcode=optimized") + .arg("-Zemit-thin-lto=no") + .run(); + cmd(llvm_bin_dir().join("llvm-objcopy")) + .arg("--dump-section") + .arg(".llvmbc=test.bc") + .arg("test") + .run(); + cmd(llvm_bin_dir().join("llvm-dis")).arg("test.bc").run(); +} diff --git a/tests/run-make/issue-84395-lto-embed-bitcode/test.rs b/tests/run-make/lto-embed-bitcode-clang/test.rs similarity index 100% rename from tests/run-make/issue-84395-lto-embed-bitcode/test.rs rename to tests/run-make/lto-embed-bitcode-clang/test.rs