Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6a14d06

Browse files
authored
Unrolled build for rust-lang#132552
Rollup merge of rust-lang#132552 - taiki-e:sparc-target-feature, r=workingjubilee Add v9, v8plus, and leoncasa target feature to sparc and use v8plus in create_object_file This adds the following three unstable target features: - `v9`: SPARC-V9 instructions ([LLVM definition][sparc-v9]) - Relevant to rust-lang#131222 (comment) - Relevant to rust-lang#132472 (comment) - This is also needed to implement taiki-e/atomic-maybe-uninit#31 (depends on inline assembly support) more robustly. - `v8plus`: SPARC-V8+ ABI ([LLVM definition][sparc-v8plus]) - This is added in LLVM 20. In LLVM 19 and older, it is emulated to work the same way as LLVM in each LLVM version. - See rust-lang#132585 (comment) for more. - `leoncasa`: CASA instruction[^1] of LEON3 and LEON4 processors ([LLVM definition][sparc-leoncasa], LLVM feature name: `hasleoncasa`) - This is needed to implement taiki-e/atomic-maybe-uninit#31 (depends on inline assembly support) more robustly. [^1]: Atomic CAS instruction [sparc-v9]: https://github.com/llvm/llvm-project/blob/f5e4ffaa49254706ad6fa209de8aec28e20f0041/llvm/lib/Target/Sparc/Sparc.td#L37-L39 [sparc-v8plus]: https://github.com/llvm/llvm-project/blob/f5e4ffaa49254706ad6fa209de8aec28e20f0041/llvm/lib/Target/Sparc/Sparc.td#L37-L39 [sparc-leoncasa]: https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/Sparc/LeonFeatures.td#L32-L37
2 parents 4b198d6 + c059eb7 commit 6a14d06

File tree

16 files changed

+113
-4
lines changed

16 files changed

+113
-4
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
228228
"x86"
229229
} else if sess.target.arch == "arm64ec" {
230230
"aarch64"
231+
} else if sess.target.arch == "sparc64" {
232+
"sparc"
231233
} else {
232234
&*sess.target.arch
233235
};
@@ -280,6 +282,13 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
280282
// Support for `wide-arithmetic` will first land in LLVM 20 as part of
281283
// llvm/llvm-project#111598
282284
("wasm32" | "wasm64", "wide-arithmetic") if get_version() < (20, 0, 0) => None,
285+
("sparc", "leoncasa") => Some(LLVMFeature::new("hasleoncasa")),
286+
// In LLVM 19, there is no `v8plus` feature and `v9` means "SPARC-V9 instruction available and SPARC-V8+ ABI used".
287+
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp#L27-L28
288+
// Before LLVM 19, there is no `v8plus` feature and `v9` means "SPARC-V9 instruction available".
289+
// https://github.com/llvm/llvm-project/blob/llvmorg-18.1.0/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp#L26
290+
("sparc", "v8plus") if get_version().0 == 19 => Some(LLVMFeature::new("v9")),
291+
("sparc", "v8plus") if get_version().0 < 19 => None,
283292
(_, s) => Some(LLVMFeature::new(s)),
284293
}
285294
}
@@ -619,6 +628,8 @@ pub(crate) fn global_llvm_features(
619628
.features
620629
.split(',')
621630
.filter(|v| !v.is_empty() && backend_feature_name(sess, v).is_some())
631+
// Drop +v8plus feature introduced in LLVM 20.
632+
.filter(|v| *v != "+v8plus" || get_version() >= (20, 0, 0))
622633
.map(String::from),
623634
);
624635

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
212212
"riscv32" => (Architecture::Riscv32, None),
213213
"riscv64" => (Architecture::Riscv64, None),
214214
"sparc" => {
215-
if sess.target.options.cpu == "v9" {
215+
if sess.unstable_target_features.contains(&sym::v8plus) {
216216
// Target uses V8+, aka EM_SPARC32PLUS, aka 64-bit V9 but in 32-bit mode
217217
(Architecture::Sparc32Plus, None)
218218
} else {

compiler/rustc_feature/src/unstable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ declare_features! (
336336
(unstable, riscv_target_feature, "1.45.0", Some(44839)),
337337
(unstable, rtm_target_feature, "1.35.0", Some(44839)),
338338
(unstable, s390x_target_feature, "1.82.0", Some(44839)),
339+
(unstable, sparc_target_feature, "CURRENT_RUSTC_VERSION", Some(132783)),
339340
(unstable, sse4a_target_feature, "1.27.0", Some(44839)),
340341
(unstable, tbm_target_feature, "1.27.0", Some(44839)),
341342
(unstable, wasm_target_feature, "1.30.0", Some(44839)),

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,7 @@ symbols! {
18671867
slice_patterns,
18681868
slicing_syntax,
18691869
soft,
1870+
sparc_target_feature,
18701871
specialization,
18711872
speed,
18721873
spotlight,
@@ -2109,6 +2110,7 @@ symbols! {
21092110
usize_legacy_fn_max_value,
21102111
usize_legacy_fn_min_value,
21112112
usize_legacy_mod,
2113+
v8plus,
21122114
va_arg,
21132115
va_copy,
21142116
va_end,

compiler/rustc_target/src/spec/targets/sparc_unknown_linux_gnu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(crate) fn target() -> Target {
1414
data_layout: "E-m:e-p:32:32-i64:64-i128:128-f128:64-n32-S64".into(),
1515
arch: "sparc".into(),
1616
options: TargetOptions {
17+
features: "+v8plus".into(),
1718
cpu: "v9".into(),
1819
endian: Endian::Big,
1920
late_link_args: TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[

compiler/rustc_target/src/target_features.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,14 @@ const IBMZ_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
545545
// tidy-alphabetical-end
546546
];
547547

548+
const SPARC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
549+
// tidy-alphabetical-start
550+
("leoncasa", Unstable(sym::sparc_target_feature), &[]),
551+
("v8plus", Unstable(sym::sparc_target_feature), &[]),
552+
("v9", Unstable(sym::sparc_target_feature), &[]),
553+
// tidy-alphabetical-end
554+
];
555+
548556
/// When rustdoc is running, provide a list of all known features so that all their respective
549557
/// primitives may be documented.
550558
///
@@ -563,6 +571,7 @@ pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
563571
.chain(CSKY_FEATURES)
564572
.chain(LOONGARCH_FEATURES)
565573
.chain(IBMZ_FEATURES)
574+
.chain(SPARC_FEATURES)
566575
.cloned()
567576
.map(|(f, s, _)| (f, s))
568577
}
@@ -582,6 +591,7 @@ impl super::spec::Target {
582591
"csky" => CSKY_FEATURES,
583592
"loongarch64" => LOONGARCH_FEATURES,
584593
"s390x" => IBMZ_FEATURES,
594+
"sparc" | "sparc64" => SPARC_FEATURES,
585595
_ => &[],
586596
}
587597
}

tests/ui/abi/sparcv8plus.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@ revisions: sparc sparcv8plus sparc_cpu_v9 sparc_feature_v8plus sparc_cpu_v9_feature_v8plus
2+
//@[sparc] compile-flags: --target sparc-unknown-none-elf
3+
//@[sparc] needs-llvm-components: sparc
4+
//@[sparcv8plus] compile-flags: --target sparc-unknown-linux-gnu
5+
//@[sparcv8plus] needs-llvm-components: sparc
6+
//@[sparc_cpu_v9] compile-flags: --target sparc-unknown-none-elf -C target-cpu=v9
7+
//@[sparc_cpu_v9] needs-llvm-components: sparc
8+
//@[sparc_feature_v8plus] compile-flags: --target sparc-unknown-none-elf -C target-feature=+v8plus
9+
//@[sparc_feature_v8plus] needs-llvm-components: sparc
10+
//@[sparc_cpu_v9_feature_v8plus] compile-flags: --target sparc-unknown-none-elf -C target-cpu=v9 -C target-feature=+v8plus
11+
//@[sparc_cpu_v9_feature_v8plus] needs-llvm-components: sparc
12+
//@ min-llvm-version: 19
13+
14+
#![crate_type = "rlib"]
15+
#![feature(no_core, rustc_attrs, lang_items)]
16+
#![no_core]
17+
18+
#[lang = "sized"]
19+
trait Sized {}
20+
#[lang = "copy"]
21+
trait Copy {}
22+
23+
#[rustc_builtin_macro]
24+
macro_rules! compile_error {
25+
() => {};
26+
}
27+
28+
#[cfg(all(not(target_feature = "v8plus"), not(target_feature = "v9")))]
29+
compile_error!("-v8plus,-v9");
30+
//[sparc]~^ ERROR -v8plus,-v9
31+
32+
// FIXME: sparc_cpu_v9 should be in "-v8plus,+v9" group (fixed in LLVM 20)
33+
#[cfg(all(target_feature = "v8plus", target_feature = "v9"))]
34+
compile_error!("+v8plus,+v9");
35+
//[sparcv8plus,sparc_cpu_v9_feature_v8plus,sparc_cpu_v9]~^ ERROR +v8plus,+v9
36+
37+
// FIXME: should be rejected
38+
#[cfg(all(target_feature = "v8plus", not(target_feature = "v9")))]
39+
compile_error!("+v8plus,-v9 (FIXME)");
40+
//[sparc_feature_v8plus]~^ ERROR +v8plus,-v9 (FIXME)
41+
42+
#[cfg(all(not(target_feature = "v8plus"), target_feature = "v9"))]
43+
compile_error!("-v8plus,+v9");

tests/ui/abi/sparcv8plus.sparc.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: -v8plus,-v9
2+
--> $DIR/sparcv8plus.rs:29:1
3+
|
4+
LL | compile_error!("-v8plus,-v9");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: +v8plus,+v9
2+
--> $DIR/sparcv8plus.rs:34:1
3+
|
4+
LL | compile_error!("+v8plus,+v9");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: +v8plus,+v9
2+
--> $DIR/sparcv8plus.rs:34:1
3+
|
4+
LL | compile_error!("+v8plus,+v9");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)