about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt1
-rw-r--r--tests/run-make/rust-lld-custom-target/Makefile7
-rw-r--r--tests/run-make/rust-lld-custom-target/rmake.rs51
3 files changed, 51 insertions, 8 deletions
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 45d3acd8fd4..f0ed0ae806f 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -249,7 +249,6 @@ run-make/rlib-format-packed-bundled-libs-2/Makefile
 run-make/rlib-format-packed-bundled-libs-3/Makefile
 run-make/rlib-format-packed-bundled-libs/Makefile
 run-make/rmeta-preferred/Makefile
-run-make/rust-lld-custom-target/Makefile
 run-make/rustc-macro-dep-files/Makefile
 run-make/rustdoc-determinism/Makefile
 run-make/rustdoc-error-lines/Makefile
diff --git a/tests/run-make/rust-lld-custom-target/Makefile b/tests/run-make/rust-lld-custom-target/Makefile
deleted file mode 100644
index 007493ab0b9..00000000000
--- a/tests/run-make/rust-lld-custom-target/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-include ../tools.mk
-
-# needs-rust-lld
-# only-x86_64-unknown-linux-gnu
-all:
-	RUSTC_LOG=rustc_codegen_ssa::back::link=info $(RUSTC) --crate-type cdylib --target custom-target.json -Clink-args=-Wl,-v lib.rs 2> $(TMPDIR)/output.txt
-	$(CGREP) -e "^LLD [0-9]+\.[0-9]+\.[0-9]+" < $(TMPDIR)/output.txt
diff --git a/tests/run-make/rust-lld-custom-target/rmake.rs b/tests/run-make/rust-lld-custom-target/rmake.rs
new file mode 100644
index 00000000000..1b6e7c65b47
--- /dev/null
+++ b/tests/run-make/rust-lld-custom-target/rmake.rs
@@ -0,0 +1,51 @@
+// Test linking using `cc` with `rust-lld`, using a custom target with features described in MCP 510
+// see https://github.com/rust-lang/compiler-team/issues/510 for more info:
+//
+// Starting from the `x86_64-unknown-linux-gnu` target spec, we add the following options:
+// - a linker-flavor using lld via a C compiler
+// - the self-contained linker component is enabled
+
+//@ needs-rust-lld
+//@ only-x86_64-unknown-linux-gnu
+
+extern crate run_make_support;
+
+use run_make_support::regex::Regex;
+use run_make_support::rustc;
+use std::process::Output;
+
+fn main() {
+    // Compile to a custom target spec with rust-lld enabled by default. We'll check that by asking
+    // the linker to display its version number with a link-arg.
+    let output = rustc()
+        .env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info")
+        .crate_type("cdylib")
+        .target("custom-target.json")
+        .arg("-Clink-args=-Wl,-v")
+        .input("lib.rs")
+        .run();
+    assert!(
+        find_lld_version_in_logs(output),
+        "the LLD version string should be present in the output logs"
+    );
+
+    // But it can also be disabled via linker features.
+    let output = rustc()
+        .env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info")
+        .crate_type("cdylib")
+        .target("custom-target.json")
+        .arg("-Zlinker-features=-lld")
+        .arg("-Clink-args=-Wl,-v")
+        .input("lib.rs")
+        .run();
+    assert!(
+        !find_lld_version_in_logs(output),
+        "the LLD version string should not be present in the output logs"
+    );
+}
+
+fn find_lld_version_in_logs(output: Output) -> bool {
+    let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
+    let stderr = std::str::from_utf8(&output.stderr).unwrap();
+    stderr.lines().any(|line| lld_version_re.is_match(line))
+}