Skip to content

Commit 0033c13

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 5347f67 commit 0033c13

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
@@ -476,22 +476,17 @@ impl LinkerFeaturesCli {
476476
/// The caller should ensure that e.g. `nightly_options::is_unstable_enabled()`
477477
/// returns false.
478478
pub(crate) fn check_unstable_variants(&self, target_tuple: &TargetTuple) -> Result<(), String> {
479-
// `-C linker-features=[-+]lld` is only stable on x64 linux.
480-
let check_lld = |features: LinkerFeatures, polarity: &str| {
481-
let has_lld = features.is_lld_enabled();
482-
if has_lld && target_tuple.tuple() != "x86_64-unknown-linux-gnu" {
483-
return Err(format!(
484-
"`-C linker-features={polarity}lld` is unstable on the `{target_tuple}` \
479+
// `-C linker-features=-lld` is only stable on x64 linux.
480+
let has_minus_lld = self.disabled.is_lld_enabled();
481+
if has_minus_lld && target_tuple.tuple() != "x86_64-unknown-linux-gnu" {
482+
return Err(format!(
483+
"`-C linker-features=-lld` is unstable on the `{target_tuple}` \
485484
target. The `-Z unstable-options` flag must also be passed to use it on this target",
486-
));
487-
}
488-
Ok(())
489-
};
490-
check_lld(self.enabled, "+")?;
491-
check_lld(self.disabled, "-")?;
485+
));
486+
}
492487

493-
// Since only lld is stable, any non-lld feature used is unstable, and that's an error.
494-
let unstable_enabled = self.enabled - LinkerFeatures::LLD;
488+
// Any `+lld` or non-lld feature used is unstable, and that's an error.
489+
let unstable_enabled = self.enabled;
495490
let unstable_disabled = self.disabled - LinkerFeatures::LLD;
496491
if !unstable_enabled.union(unstable_disabled).is_empty() {
497492
let unstable_features: Vec<_> = unstable_enabled
@@ -500,8 +495,8 @@ impl LinkerFeaturesCli {
500495
.chain(unstable_disabled.iter().map(|f| format!("-{}", f.as_str().unwrap())))
501496
.collect();
502497
return Err(format!(
503-
"the requested `-C linker-features={}` are unstable, and also require the \
504-
`-Z unstable-options` flag to be usable",
498+
"`-C linker-features={}` is unstable, and also requires the \
499+
`-Z unstable-options` flag to be used",
505500
unstable_features.join(","),
506501
));
507502
}

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)