Skip to content

Commit ef99848

Browse files
committed
only stabilize -Clinker-features=-lld on x64 linux
Some combinations of opt-ins and other flags need more work to be stabilized, so we can only stabilize the opt-outs.
1 parent 50170a3 commit ef99848

9 files changed

+37
-36
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -474,22 +474,17 @@ impl LinkerFeaturesCli {
474474
/// The caller should ensure that e.g. `nightly_options::is_unstable_enabled()`
475475
/// returns false.
476476
pub(crate) fn check_unstable_variants(&self, target_tuple: &TargetTuple) -> Result<(), String> {
477-
// `-C linker-features=[-+]lld` is only stable on x64 linux.
478-
let check_lld = |features: LinkerFeatures, polarity: &str| {
479-
let has_lld = features.is_lld_enabled();
480-
if has_lld && target_tuple.tuple() != "x86_64-unknown-linux-gnu" {
481-
return Err(format!(
482-
"`-C linker-features={polarity}lld` is unstable on the `{target_tuple}` \
477+
// `-C linker-features=-lld` is only stable on x64 linux.
478+
let has_minus_lld = self.disabled.is_lld_enabled();
479+
if has_minus_lld && target_tuple.tuple() != "x86_64-unknown-linux-gnu" {
480+
return Err(format!(
481+
"`-C linker-features=-lld` is unstable on the `{target_tuple}` \
483482
target. The `-Z unstable-options` flag must also be passed to use it on this target",
484-
));
485-
}
486-
Ok(())
487-
};
488-
check_lld(self.enabled, "+")?;
489-
check_lld(self.disabled, "-")?;
483+
));
484+
}
490485

491-
// Since only lld is stable, any non-lld feature used is unstable, and that's an error.
492-
let unstable_enabled = self.enabled - LinkerFeatures::LLD;
486+
// Any `+lld` or non-lld feature used is unstable, and that's an error.
487+
let unstable_enabled = self.enabled;
493488
let unstable_disabled = self.disabled - LinkerFeatures::LLD;
494489
if !unstable_enabled.union(unstable_disabled).is_empty() {
495490
let unstable_features: Vec<_> = unstable_enabled
@@ -498,8 +493,8 @@ impl LinkerFeaturesCli {
498493
.chain(unstable_disabled.iter().map(|f| format!("-{}", f.as_str().unwrap())))
499494
.collect();
500495
return Err(format!(
501-
"the requested `-C linker-features={}` are unstable, and also require the \
502-
`-Z unstable-options` flag to be usable",
496+
"`-C linker-features={}` is unstable, and also requires the \
497+
`-Z unstable-options` flag to be used",
503498
unstable_features.join(","),
504499
));
505500
}

tests/run-make/rust-lld-link-script-provide/rmake.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn main() {
1212
.input("main.rs")
1313
.arg("-Clinker-features=+lld")
1414
.arg("-Clink-self-contained=+linker")
15+
.arg("-Zunstable-options")
1516
.link_arg("-Tscript.t")
1617
.run();
1718
}

tests/ui/linking/linker-features-lld-disallowed-target.positive.stderr

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/ui/linking/linker-features-lld-disallowed-target.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Check that only `-C linker-features=-lld` is stable on x64 linux. Any other value or target,
2+
// needs `-Z unstable-options`.
3+
4+
// ignore-tidy-linelength
5+
6+
//@ revisions: unstable_target_positive unstable_target_negative unstable_positive
7+
//@ [unstable_target_negative] compile-flags: --target=x86_64-unknown-linux-musl -C linker-features=-lld --crate-type=rlib
8+
//@ [unstable_target_negative] needs-llvm-components: x86
9+
//@ [unstable_target_positive] compile-flags: --target=x86_64-unknown-linux-musl -C linker-features=+lld --crate-type=rlib
10+
//@ [unstable_target_positive] needs-llvm-components: x86
11+
//@ [unstable_positive] compile-flags: --target=x86_64-unknown-linux-gnu -C linker-features=+lld --crate-type=rlib
12+
//@ [unstable_positive] needs-llvm-components: x86
13+
14+
15+
#![feature(no_core)]
16+
#![no_core]
17+
18+
//[unstable_target_negative]~? ERROR `-C linker-features=-lld` is unstable on the `x86_64-unknown-linux-musl` target
19+
//[unstable_target_positive]~? ERROR `-C linker-features=+lld` is unstable, and also requires the `-Z unstable-options`
20+
//[unstable_positive]~? ERROR `-C linker-features=+lld` is unstable, and also requires the `-Z unstable-options`
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: `-C linker-features=+lld` is unstable, and also requires the `-Z unstable-options` flag to be used
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: `-C linker-features=+lld` is unstable, and also requires the `-Z unstable-options` flag to be used
2+

tests/ui/linking/linker-features-unstable-cc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Check that only `-C linker-features=[+-]lld` is stable on x64 linux, and that other linker
2-
// features require using `-Z unstable-options`.
1+
// Check that non-lld linker features require using `-Z unstable-options`.
32
//
43
// Note that, currently, only `lld` is parsed on the CLI, but that other linker features can exist
54
// internally (`cc`).

0 commit comments

Comments
 (0)