Skip to content

Commit 9779592

Browse files
committed
port rust-lld test to rmake
also check that turning off the linker feature does not use lld
1 parent 682535e commit 9779592

File tree

3 files changed

+64
-13
lines changed

3 files changed

+64
-13
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ run-make/rlib-format-packed-bundled-libs-3/Makefile
250250
run-make/rlib-format-packed-bundled-libs/Makefile
251251
run-make/rmeta-preferred/Makefile
252252
run-make/rust-lld-custom-target/Makefile
253-
run-make/rust-lld/Makefile
254253
run-make/rustc-macro-dep-files/Makefile
255254
run-make/rustdoc-determinism/Makefile
256255
run-make/rustdoc-error-lines/Makefile

tests/run-make/rust-lld/Makefile

-12
This file was deleted.

tests/run-make/rust-lld/rmake.rs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Test linking using `cc` with `rust-lld`, using the unstable CLI described in MCP 510
2+
// see https://github.com/rust-lang/compiler-team/issues/510 for more info
3+
4+
//@ needs-rust-lld
5+
//@ ignore-msvc
6+
//@ ignore-s390x lld does not yet support s390x as target
7+
8+
extern crate run_make_support;
9+
10+
use run_make_support::regex::Regex;
11+
use run_make_support::rustc;
12+
use std::process::Output;
13+
14+
fn main() {
15+
// Opt-in to lld and the self-contained linker, to link with rust-lld. We'll check that by
16+
// asking the linker to display its version number with a link-arg.
17+
let output = rustc()
18+
.env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info")
19+
.arg("-Zlinker-features=+lld")
20+
.arg("-Clink-self-contained=+linker")
21+
.arg("-Zunstable-options")
22+
.arg("-Clink-args=-Wl,-v")
23+
.input("main.rs")
24+
.run();
25+
assert!(
26+
find_lld_version_in_logs(output),
27+
"the LLD version string should be present in the output logs"
28+
);
29+
30+
// It should not be used when we explictly opt-out of lld.
31+
let output = rustc()
32+
.env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info")
33+
.arg("-Clink-args=-Wl,-v")
34+
.arg("-Zlinker-features=-lld")
35+
.input("main.rs")
36+
.run();
37+
assert!(
38+
!find_lld_version_in_logs(output),
39+
"the LLD version string should not be present in the output logs"
40+
);
41+
42+
// While we're here, also check that the last linker feature flag "wins" when passed multiple
43+
// times to rustc.
44+
let output = rustc()
45+
.env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info")
46+
.arg("-Clink-args=-Wl,-v")
47+
.arg("-Clink-self-contained=+linker")
48+
.arg("-Zunstable-options")
49+
.arg("-Zlinker-features=-lld")
50+
.arg("-Zlinker-features=+lld")
51+
.arg("-Zlinker-features=-lld,+lld")
52+
.input("main.rs")
53+
.run();
54+
assert!(
55+
find_lld_version_in_logs(output),
56+
"the LLD version string should be present in the output logs"
57+
);
58+
}
59+
60+
fn find_lld_version_in_logs(output: Output) -> bool {
61+
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
62+
let stderr = std::str::from_utf8(&output.stderr).unwrap();
63+
stderr.lines().any(|line| lld_version_re.is_match(line))
64+
}

0 commit comments

Comments
 (0)