Skip to content

Commit 342b807

Browse files
committed
rewrite cross-lang-lto-upstream-rlibs to rmake
1 parent 60d1465 commit 342b807

File tree

3 files changed

+61
-33
lines changed

3 files changed

+61
-33
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
run-make/branch-protection-check-IBT/Makefile
22
run-make/cat-and-grep-sanity-check/Makefile
3-
run-make/cross-lang-lto-upstream-rlibs/Makefile
43
run-make/dep-info-doesnt-run-much/Makefile
54
run-make/dep-info-spaces/Makefile
65
run-make/dep-info/Makefile

tests/run-make/cross-lang-lto-upstream-rlibs/Makefile

-32
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// When using the flag -C linker-plugin-lto, static libraries could lose their upstream object
2+
// files during compilation. This bug was fixed in #53031, and this test compiles a staticlib
3+
// dependent on upstream, checking that the upstream object file still exists after no LTO and
4+
// thin LTO.
5+
// See https://github.com/rust-lang/rust/pull/53031
6+
7+
// ignore windows due to libLLVM being present in PATH and the PATH and library path being the same
8+
// (so fixing it is harder). See #57765 for context
9+
//FIXME(Oneirical): ignore-windows
10+
11+
use run_make_support::{
12+
cwd, has_extension, has_prefix, has_suffix, llvm_ar, rfs, rustc, shallow_find_files,
13+
static_lib_name,
14+
};
15+
16+
fn main() {
17+
// The test starts with no LTO enabled.
18+
rustc().input("upstream.rs").arg("-Clinker-plugin-lto").codegen_units(1).run();
19+
rustc()
20+
.input("staticlib.rs")
21+
.arg("-Clinker-plugin-lto")
22+
.codegen_units(1)
23+
.output(static_lib_name("staticlib"))
24+
.run();
25+
llvm_ar().arg("x").arg(static_lib_name("staticlib")).run();
26+
// Ensure the upstream object file was included.
27+
assert_eq!(
28+
shallow_find_files(cwd(), |path| {
29+
has_prefix(path, "upstream.") && has_suffix(path, ".rcgu.o")
30+
})
31+
.len(),
32+
1
33+
);
34+
// Remove all output files that are not source Rust code for cleanup.
35+
for file in shallow_find_files(cwd(), |path| !has_extension(path, "rs")) {
36+
rfs::remove_file(file)
37+
}
38+
39+
// Check it again, with Thin LTO.
40+
rustc()
41+
.input("upstream.rs")
42+
.arg("-Clinker-plugin-lto")
43+
.codegen_units(1)
44+
.arg("-Clto=thin")
45+
.run();
46+
rustc()
47+
.input("staticlib.rs")
48+
.arg("-Clinker-plugin-lto")
49+
.codegen_units(1)
50+
.arg("-Clto=thin")
51+
.output(static_lib_name("staticlib"))
52+
.run();
53+
llvm_ar().arg("x").arg(static_lib_name("staticlib")).run();
54+
assert_eq!(
55+
shallow_find_files(cwd(), |path| {
56+
has_prefix(path, "upstream.") && has_suffix(path, ".rcgu.o")
57+
})
58+
.len(),
59+
1
60+
);
61+
}

0 commit comments

Comments
 (0)