Skip to content

Commit 94b7099

Browse files
committed
Check that -Clinker-features=[-+]lld can be used only on the x64 target without -Zunstable-options
1 parent d7e02c2 commit 94b7099

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

compiler/rustc_session/src/config.rs

+13
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,19 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
25322532
let debuginfo = select_debuginfo(matches, &cg);
25332533
let debuginfo_compression = unstable_opts.debuginfo_compression;
25342534

2535+
if !nightly_options::is_unstable_enabled(matches) {
2536+
// Check that -Clinker-features=[-+]lld is not used anywhere else than on x64
2537+
// without -Zunstable-options.
2538+
if !cg.linker_features.disabled.is_empty() || !cg.linker_features.enabled.is_empty() {
2539+
if target_triple.tuple() != "x86_64-unknown-linux-gnu" {
2540+
early_dcx.early_fatal(
2541+
"`-C linker-features` is stable only for the `x86_64-unknown-linux-gnu` target, \
2542+
the `-Z unstable-options` flag must also be passed to use it on other targets",
2543+
);
2544+
}
2545+
}
2546+
}
2547+
25352548
let crate_name = matches.opt_str("crate-name");
25362549
let unstable_features = UnstableFeatures::from_environment(crate_name.as_deref());
25372550
// Parse any `-l` flags, which link to native libraries.

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

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fn main() {
2424
.crate_type("cdylib")
2525
.target("custom-target.json")
2626
.arg("-Clinker-features=-lld")
27+
.arg("-Zunstable-options")
2728
.input("lib.rs"),
2829
);
2930
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Check that -CLinker-features can only be used on x64.
2+
//
3+
//@ check-fail
4+
//@ compile-flags: --target=x86_64-unknown-linux-musl -C linker-features=-lld --crate-type=rlib
5+
//@ needs-llvm-components: x86
6+
7+
#![feature(no_core)]
8+
#![no_core]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: `-C linker-features` is stable only for the `x86_64-unknown-linux-gnu` target, the `-Z unstable-options` flag must also be passed to use it on other targets
2+

0 commit comments

Comments
 (0)