Skip to content

Commit 23f177d

Browse files
committed
rustc_session: Feature gate linker flavors for tier 3 targets
1 parent b0ce416 commit 23f177d

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1212

1313
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
1414
use rustc_target::abi::Align;
15-
use rustc_target::spec::{PanicStrategy, SanitizerSet, SplitDebuginfo};
15+
use rustc_target::spec::{LinkerFlavorCli, PanicStrategy, SanitizerSet, SplitDebuginfo};
1616
use rustc_target::spec::{Target, TargetTriple, TargetWarnings, TARGETS};
1717

1818
use crate::parse::{CrateCheckConfig, CrateConfig};
@@ -2525,6 +2525,19 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
25252525
}
25262526
}
25272527

2528+
if let Some(flavor) = cg.linker_flavor {
2529+
if matches!(flavor, LinkerFlavorCli::BpfLinker | LinkerFlavorCli::PtxLinker)
2530+
&& !nightly_options::is_unstable_enabled(matches)
2531+
{
2532+
let msg = format!(
2533+
"linker flavor `{}` is unstable, `-Z unstable-options` \
2534+
flag must also be passed to explicitly use it",
2535+
flavor.desc()
2536+
);
2537+
early_error(error_format, msg);
2538+
}
2539+
}
2540+
25282541
let prints = collect_print_requests(&mut cg, &mut unstable_opts, matches, error_format);
25292542

25302543
let cg = cg;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: linker flavor `bpf-linker` is unstable, `-Z unstable-options` flag must also be passed to explicitly use it
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: linker flavor `ptx-linker` is unstable, `-Z unstable-options` flag must also be passed to explicitly use it
2+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// revisions: bpf ptx
2+
// [bpf] compile-flags: --target=bpfel-unknown-none -C linker-flavor=bpf-linker --crate-type=rlib
3+
// [bpf] error-pattern: linker flavor `bpf-linker` is unstable, `-Z unstable-options` flag
4+
// [bpf] needs-llvm-components:
5+
// [ptx] compile-flags: --target=nvptx64-nvidia-cuda -C linker-flavor=ptx-linker --crate-type=rlib
6+
// [ptx] error-pattern: linker flavor `ptx-linker` is unstable, `-Z unstable-options` flag
7+
// [ptx] needs-llvm-components:
8+
9+
#![feature(no_core)]
10+
#![no_core]

0 commit comments

Comments
 (0)