Skip to content

Commit ed3097d

Browse files
committed
Check that -Clinker-features=[-+]lld is used only on x64 (or custom) targets
1 parent d7e02c2 commit ed3097d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,21 @@ 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+
if !cg.linker_features.disabled.is_empty() || !cg.linker_features.enabled.is_empty() {
2538+
// Allow the features for custom targets, as those are unstable anyway
2539+
if target_triple.tuple() != "x86_64-unknown-linux-gnu"
2540+
&& matches!(target_triple, TargetTuple::TargetTuple(_))
2541+
{
2542+
early_dcx.early_fatal(
2543+
"`-C linker-features` is stable only for the `x86_64-unknown-linux-gnu` target, \
2544+
the `-Z unstable-options` flag must also be passed to use it on other targets",
2545+
);
2546+
}
2547+
}
2548+
}
2549+
25352550
let crate_name = matches.opt_str("crate-name");
25362551
let unstable_features = UnstableFeatures::from_environment(crate_name.as_deref());
25372552
// Parse any `-l` flags, which link to native libraries.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Even though this test only checks 2 of the 10 or so unstable linker flavors, it exercizes the
2+
// unique codepath checking all unstable options (see `LinkerFlavorCli::is_unstable` and its
3+
// caller). If it passes, all the other unstable options are rejected as well.
4+
//
5+
//@ check-fail
6+
//@ compile-flags: --target=x86_64-unknown-linux-musl -C linker-features=-lld --crate-type=rlib
7+
8+
#![feature(no_core)]
9+
#![no_core]
Lines changed: 2 additions & 0 deletions
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)