From 342b807e1a344c01a10e5e591ad22cdc56911b39 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 25 Jul 2024 11:43:52 -0400 Subject: [PATCH] rewrite cross-lang-lto-upstream-rlibs to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../cross-lang-lto-upstream-rlibs/Makefile | 32 ---------- .../cross-lang-lto-upstream-rlibs/rmake.rs | 61 +++++++++++++++++++ 3 files changed, 61 insertions(+), 33 deletions(-) delete mode 100644 tests/run-make/cross-lang-lto-upstream-rlibs/Makefile create mode 100644 tests/run-make/cross-lang-lto-upstream-rlibs/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 a2cfdea712e..b248b96d8e1 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -1,6 +1,5 @@ run-make/branch-protection-check-IBT/Makefile run-make/cat-and-grep-sanity-check/Makefile -run-make/cross-lang-lto-upstream-rlibs/Makefile run-make/dep-info-doesnt-run-much/Makefile run-make/dep-info-spaces/Makefile run-make/dep-info/Makefile diff --git a/tests/run-make/cross-lang-lto-upstream-rlibs/Makefile b/tests/run-make/cross-lang-lto-upstream-rlibs/Makefile deleted file mode 100644 index 6f1caa31a80..00000000000 --- a/tests/run-make/cross-lang-lto-upstream-rlibs/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -include ../tools.mk - -# ignore windows due to libLLVM being present in PATH and the PATH and library path being the same -# (so fixing it is harder). See #57765 for context -ifndef IS_WINDOWS - -# This test makes sure that we don't loose upstream object files when compiling -# staticlibs with -C linker-plugin-lto - -all: staticlib.rs upstream.rs - $(RUSTC) upstream.rs -C linker-plugin-lto -Ccodegen-units=1 - - # Check No LTO - $(RUSTC) staticlib.rs -C linker-plugin-lto -Ccodegen-units=1 -L. -o $(TMPDIR)/staticlib.a - (cd $(TMPDIR); "$(LLVM_BIN_DIR)"/llvm-ar x ./staticlib.a) - # Make sure the upstream object file was included - ls $(TMPDIR)/upstream.*.rcgu.o - - # Cleanup - rm $(TMPDIR)/* - - # Check ThinLTO - $(RUSTC) upstream.rs -C linker-plugin-lto -Ccodegen-units=1 -Clto=thin - $(RUSTC) staticlib.rs -C linker-plugin-lto -Ccodegen-units=1 -Clto=thin -L. -o $(TMPDIR)/staticlib.a - (cd $(TMPDIR); "$(LLVM_BIN_DIR)"/llvm-ar x ./staticlib.a) - ls $(TMPDIR)/upstream.*.rcgu.o - -else - -all: - -endif diff --git a/tests/run-make/cross-lang-lto-upstream-rlibs/rmake.rs b/tests/run-make/cross-lang-lto-upstream-rlibs/rmake.rs new file mode 100644 index 00000000000..964be01bc05 --- /dev/null +++ b/tests/run-make/cross-lang-lto-upstream-rlibs/rmake.rs @@ -0,0 +1,61 @@ +// When using the flag -C linker-plugin-lto, static libraries could lose their upstream object +// files during compilation. This bug was fixed in #53031, and this test compiles a staticlib +// dependent on upstream, checking that the upstream object file still exists after no LTO and +// thin LTO. +// See https://github.com/rust-lang/rust/pull/53031 + +// ignore windows due to libLLVM being present in PATH and the PATH and library path being the same +// (so fixing it is harder). See #57765 for context +//FIXME(Oneirical): ignore-windows + +use run_make_support::{ + cwd, has_extension, has_prefix, has_suffix, llvm_ar, rfs, rustc, shallow_find_files, + static_lib_name, +}; + +fn main() { + // The test starts with no LTO enabled. + rustc().input("upstream.rs").arg("-Clinker-plugin-lto").codegen_units(1).run(); + rustc() + .input("staticlib.rs") + .arg("-Clinker-plugin-lto") + .codegen_units(1) + .output(static_lib_name("staticlib")) + .run(); + llvm_ar().arg("x").arg(static_lib_name("staticlib")).run(); + // Ensure the upstream object file was included. + assert_eq!( + shallow_find_files(cwd(), |path| { + has_prefix(path, "upstream.") && has_suffix(path, ".rcgu.o") + }) + .len(), + 1 + ); + // Remove all output files that are not source Rust code for cleanup. + for file in shallow_find_files(cwd(), |path| !has_extension(path, "rs")) { + rfs::remove_file(file) + } + + // Check it again, with Thin LTO. + rustc() + .input("upstream.rs") + .arg("-Clinker-plugin-lto") + .codegen_units(1) + .arg("-Clto=thin") + .run(); + rustc() + .input("staticlib.rs") + .arg("-Clinker-plugin-lto") + .codegen_units(1) + .arg("-Clto=thin") + .output(static_lib_name("staticlib")) + .run(); + llvm_ar().arg("x").arg(static_lib_name("staticlib")).run(); + assert_eq!( + shallow_find_files(cwd(), |path| { + has_prefix(path, "upstream.") && has_suffix(path, ".rcgu.o") + }) + .len(), + 1 + ); +}