-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite cross-lang-lto-upstream-rlibs to rmake
- Loading branch information
Showing
3 changed files
with
61 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
); | ||
} |