Skip to content

Commit 5bdf06b

Browse files
committed
Auto merge of #128196 - Oneirical:poltergeist-manitestation, r=<try>
Migrate `cross-lang-lto-upstream-rlibs`, `long-linker-command-lines` and `long-linker-command-lines-cmd-exe` `run-make` tests to rmake Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). The `long-linker` tests are certainly doing something... interesting - they summon `rustc` calls with obscene quantities of arguments and check that this is appropriately handled. I removed the `RUSTC_ORIGINAL` magic - it's equivalent to `RUSTC` in `tools.mk`, so what is the purpose? Making it so the massive pile of flags doesn't modify rustc itself and start leaking into other tests? Tell me what you think. Please try: try-job: x86_64-msvc
2 parents 54be9ad + 9ed58e6 commit 5bdf06b

File tree

9 files changed

+110
-87
lines changed

9 files changed

+110
-87
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ run-make/cdylib-dylib-linkage/Makefile
55
run-make/compiler-rt-works-on-mingw/Makefile
66
run-make/cross-lang-lto-clang/Makefile
77
run-make/cross-lang-lto-pgo-smoketest/Makefile
8-
run-make/cross-lang-lto-upstream-rlibs/Makefile
98
run-make/cross-lang-lto/Makefile
109
run-make/dep-info-doesnt-run-much/Makefile
1110
run-make/dep-info-spaces/Makefile
@@ -34,8 +33,6 @@ run-make/libtest-json/Makefile
3433
run-make/libtest-junit/Makefile
3534
run-make/libtest-thread-limit/Makefile
3635
run-make/link-cfg/Makefile
37-
run-make/long-linker-command-lines-cmd-exe/Makefile
38-
run-make/long-linker-command-lines/Makefile
3936
run-make/macos-deployment-target/Makefile
4037
run-make/min-global-align/Makefile
4138
run-make/native-link-modifier-bundle/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+
}

tests/run-make/long-linker-command-lines-cmd-exe/Makefile

-7
This file was deleted.

tests/run-make/long-linker-command-lines-cmd-exe/foo.rs

+3-23
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
1-
// Like the `long-linker-command-lines` test this test attempts to blow
2-
// a command line limit for running the linker. Unlike that test, however,
3-
// this test is testing `cmd.exe` specifically rather than the OS.
4-
//
5-
// Unfortunately `cmd.exe` has a 8192 limit which is relatively small
6-
// in the grand scheme of things and anyone sripting rustc's linker
7-
// is probably using a `*.bat` script and is likely to hit this limit.
8-
//
9-
// This test uses a `foo.bat` script as the linker which just simply
10-
// delegates back to this program. The compiler should use a lower
11-
// limit for arguments before passing everything via `@`, which
12-
// means that everything should still succeed here.
13-
141
use std::env;
152
use std::fs::{self, File};
163
use std::io::{BufWriter, Read, Write};
174
use std::path::PathBuf;
185
use std::process::Command;
196

207
fn main() {
21-
if !cfg!(windows) {
22-
return;
23-
}
24-
25-
let tmpdir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
26-
let ok = tmpdir.join("ok");
27-
let not_ok = tmpdir.join("not_ok");
8+
let ok = PathBuf::from("ok");
9+
let not_ok = PathBuf::from("not_ok");
2810
if env::var("YOU_ARE_A_LINKER").is_ok() {
2911
match env::args_os().find(|a| a.to_string_lossy().contains("@")) {
3012
Some(file) => {
@@ -45,7 +27,7 @@ fn main() {
4527
for i in (1..).map(|i| i * 10) {
4628
println!("attempt: {}", i);
4729

48-
let file = tmpdir.join("bar.rs");
30+
let file = PathBuf::from("bar.rs");
4931
let mut f = BufWriter::new(File::create(&file).unwrap());
5032
let mut lib_name = String::new();
5133
for _ in 0..i {
@@ -63,8 +45,6 @@ fn main() {
6345
.arg(&file)
6446
.arg("-C")
6547
.arg(&bat_linker)
66-
.arg("--out-dir")
67-
.arg(&tmpdir)
6848
.env("YOU_ARE_A_LINKER", "1")
6949
.env("MY_LINKER", &me)
7050
.status()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Like the `long-linker-command-lines` test this test attempts to blow
2+
// a command line limit for running the linker. Unlike that test, however,
3+
// this test is testing `cmd.exe` specifically rather than the OS.
4+
//
5+
// Unfortunately `cmd.exe` has a 8192 limit which is relatively small
6+
// in the grand scheme of things and anyone sripting rustc's linker
7+
// is probably using a `*.bat` script and is likely to hit this limit.
8+
//
9+
// This test uses a `foo.bat` script as the linker which just simply
10+
// delegates back to this program. The compiler should use a lower
11+
// limit for arguments before passing everything via `@`, which
12+
// means that everything should still succeed here.
13+
// See https://github.com/rust-lang/rust/pull/47507
14+
15+
//@ ignore-cross-compile
16+
// Reason: the compiled binary is executed
17+
//@ only-windows
18+
// Reason: this test is specific to Windows executables
19+
20+
use run_make_support::{run, rustc};
21+
22+
fn main() {
23+
rustc().input("foo.rs").arg("-g").run();
24+
run("foo");
25+
}

tests/run-make/long-linker-command-lines/Makefile

-8
This file was deleted.

tests/run-make/long-linker-command-lines/foo.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// This is a test which attempts to blow out the system limit with how many
2-
// arguments can be passed to a process. This'll successively call rustc with
3-
// larger and larger argument lists in an attempt to find one that's way too
4-
// big for the system at hand. This file itself is then used as a "linker" to
5-
// detect when the process creation succeeds.
6-
//
7-
// Eventually we should see an argument that looks like `@` as we switch from
8-
// passing literal arguments to passing everything in the file.
9-
101
use std::collections::HashSet;
112
use std::env;
123
use std::fs::{self, File};
@@ -43,8 +34,7 @@ fn read_linker_args(path: &Path) -> String {
4334
}
4435

4536
fn main() {
46-
let tmpdir = PathBuf::from(env::var_os("TMPDIR").unwrap());
47-
let ok = tmpdir.join("ok");
37+
let ok = PathBuf::from("ok");
4838
if env::var("YOU_ARE_A_LINKER").is_ok() {
4939
if let Some(file) = env::args_os().find(|a| a.to_string_lossy().contains("@")) {
5040
let file = file.to_str().expect("non-utf8 file argument");
@@ -57,16 +47,14 @@ fn main() {
5747
let me_as_linker = format!("linker={}", env::current_exe().unwrap().display());
5848
for i in (1..).map(|i| i * 100) {
5949
println!("attempt: {}", i);
60-
let file = tmpdir.join("bar.rs");
50+
let file = PathBuf::from("bar.rs");
6151
let mut expected_libs = write_test_case(&file, i);
6252

6353
drop(fs::remove_file(&ok));
6454
let output = Command::new(&rustc)
6555
.arg(&file)
6656
.arg("-C")
6757
.arg(&me_as_linker)
68-
.arg("--out-dir")
69-
.arg(&tmpdir)
7058
.env("YOU_ARE_A_LINKER", "1")
7159
.output()
7260
.unwrap();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This is a test which attempts to blow out the system limit with how many
2+
// arguments can be passed to a process. This'll successively call rustc with
3+
// larger and larger argument lists in an attempt to find one that's way too
4+
// big for the system at hand. This file itself is then used as a "linker" to
5+
// detect when the process creation succeeds.
6+
//
7+
// Eventually we should see an argument that looks like `@` as we switch from
8+
// passing literal arguments to passing everything in the file.
9+
// See https://github.com/rust-lang/rust/issues/41190
10+
11+
//@ ignore-cross-compile
12+
// Reason: the compiled binary is executed
13+
14+
use run_make_support::{run, rustc};
15+
16+
fn main() {
17+
rustc().input("foo.rs").arg("-g").opt().run();
18+
run("foo");
19+
}

0 commit comments

Comments
 (0)