Skip to content

Commit 8c51e28

Browse files
committed
add rustc_codegen_ssa support for csky and correct some code
1 parent 8ed7aa1 commit 8c51e28

File tree

7 files changed

+26
-3
lines changed

7 files changed

+26
-3
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
209209
"hexagon" => Architecture::Hexagon,
210210
"bpf" => Architecture::Bpf,
211211
"loongarch64" => Architecture::LoongArch64,
212+
"csky" => Architecture::Csky,
212213
// Unsupported architecture.
213214
_ => return None,
214215
};
@@ -307,6 +308,13 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
307308
// the appropriate EF_AVR_ARCH flag.
308309
ef_avr_arch(&sess.target.options.cpu)
309310
}
311+
Architecture::Csky => {
312+
let e_flags = match sess.target.options.abi.as_ref() {
313+
"abiv2" => elf::EF_CSKY_ABIV2,
314+
_ => elf::EF_CSKY_ABIV1,
315+
};
316+
e_flags
317+
}
310318
_ => 0,
311319
};
312320
// adapted from LLVM's `MCELFObjectTargetWriter::getOSABI`

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,16 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
296296

297297
const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))];
298298

299+
const CSKY_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
300+
("hard-float", Some(sym::csky_target_feature)),
301+
("hard-float-abi", Some(sym::csky_target_feature)),
302+
("fpuv2_sf", Some(sym::csky_target_feature)),
303+
("fpuv2_df", Some(sym::csky_target_feature)),
304+
("fpuv3_sf", Some(sym::csky_target_feature)),
305+
("fpuv3_df", Some(sym::csky_target_feature)),
306+
("vdspv2", Some(sym::csky_target_feature)),
307+
("dspv2", Some(sym::csky_target_feature)),
308+
];
299309
/// When rustdoc is running, provide a list of all known features so that all their respective
300310
/// primitives may be documented.
301311
///
@@ -311,6 +321,7 @@ pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol
311321
.chain(RISCV_ALLOWED_FEATURES.iter())
312322
.chain(WASM_ALLOWED_FEATURES.iter())
313323
.chain(BPF_ALLOWED_FEATURES.iter())
324+
.chain(CSKY_ALLOWED_FEATURES)
314325
.cloned()
315326
}
316327

@@ -325,6 +336,7 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
325336
"riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
326337
"wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
327338
"bpf" => BPF_ALLOWED_FEATURES,
339+
"csky" => CSKY_ALLOWED_FEATURES,
328340
_ => &[],
329341
}
330342
}
@@ -396,6 +408,7 @@ pub fn from_target_feature(
396408
Some(sym::ermsb_target_feature) => rust_features.ermsb_target_feature,
397409
Some(sym::bpf_target_feature) => rust_features.bpf_target_feature,
398410
Some(sym::aarch64_ver_target_feature) => rust_features.aarch64_ver_target_feature,
411+
Some(sym::csky_target_feature) => rust_features.csky_target_feature,
399412
Some(name) => bug!("unknown target feature gate {}", name),
400413
None => true,
401414
};

compiler/rustc_feature/src/active.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ declare_features! (
282282
(active, arm_target_feature, "1.27.0", Some(44839), None),
283283
(active, avx512_target_feature, "1.27.0", Some(44839), None),
284284
(active, bpf_target_feature, "1.54.0", Some(44839), None),
285+
(active, csky_target_feature, "1.72.0", Some(44839), None),
285286
(active, ermsb_target_feature, "1.49.0", Some(44839), None),
286287
(active, hexagon_target_feature, "1.27.0", Some(44839), None),
287288
(active, mips_target_feature, "1.27.0", Some(44839), None),

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ symbols! {
574574
crate_type,
575575
crate_visibility_modifier,
576576
crt_dash_static: "crt-static",
577+
csky_target_feature,
577578
cstring_type,
578579
ctlz,
579580
ctlz_nonzero,

compiler/rustc_target/src/spec/csky_unknown_linux_gnuabiv2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::spec::{Target, TargetOptions};
66
pub fn target() -> Target {
77
Target {
88
//https://github.com/llvm/llvm-project/blob/8b76aea8d8b1b71f6220bc2845abc749f18a19b7/clang/lib/Basic/Targets/CSKY.h
9-
llvm_target: "csky-unknown-linux".into(),
9+
llvm_target: "csky-unknown-linux-gnuabiv2".into(),
1010
pointer_width: 32,
1111
data_layout: "e-m:e-S32-p:32:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32-v128:32:32-a:0:32-Fi32-n32".into(),
1212
arch: "csky".into(),

src/doc/rustc/src/platform-support/csky-unknown-linux-gnuabiv2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**Tier: 3**
44

5-
This target supports [C-SKY](https://github.com/c-sky) v2 CPUs with `glibc`.
5+
This target supports [C-SKY](https://github.com/c-sky) CPUs with `abi` v2 and `glibc`.
66

77
https://c-sky.github.io/
88
## Target maintainers

tests/ui/check-cfg/compact-values.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ warning: unexpected `cfg` condition value
44
LL | #[cfg(target(os = "linux", arch = "X"))]
55
| ^^^^^^^^^^
66
|
7-
= note: expected values for `target_arch` are: `aarch64`, `arm`, `avr`, `bpf`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips32r6`, `mips64`, `mips64r6`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64`
7+
= note: expected values for `target_arch` are: `aarch64`, `arm`, `avr`, `bpf`, `csky`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips32r6`, `mips64`, `mips64r6`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64`
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

1010
warning: 1 warning emitted

0 commit comments

Comments
 (0)