From 459d1cf0f68d1fb729eee6ab17146c8f22ba515a Mon Sep 17 00:00:00 2001 From: Qethu <190734095+qethu@users.noreply.github.com> Date: Thu, 5 Dec 2024 21:28:08 +0800 Subject: [PATCH 1/4] Add mips-zkm-zkvm-elf triple --- compiler/rustc_target/src/spec/mod.rs | 1 + .../src/spec/targets/mips_zkm_zkvm_elf.rs | 43 +++++++++++++++++++ src/tools/build-manifest/src/main.rs | 1 + 3 files changed, 45 insertions(+) create mode 100644 compiler/rustc_target/src/spec/targets/mips_zkm_zkvm_elf.rs diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index ad746d3f26b85..ba69fc0627226 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1679,6 +1679,7 @@ supported_targets! { ("mips-unknown-linux-uclibc", mips_unknown_linux_uclibc), ("mipsel-unknown-linux-uclibc", mipsel_unknown_linux_uclibc), + ("mips-zkm-zkvm-elf", mips_zkm_zkvm_elf), ("i686-linux-android", i686_linux_android), ("x86_64-linux-android", x86_64_linux_android), diff --git a/compiler/rustc_target/src/spec/targets/mips_zkm_zkvm_elf.rs b/compiler/rustc_target/src/spec/targets/mips_zkm_zkvm_elf.rs new file mode 100644 index 0000000000000..8499a41eaf29c --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/mips_zkm_zkvm_elf.rs @@ -0,0 +1,43 @@ +use crate::abi::Endian; +use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions}; + +pub(crate) fn target() -> Target { + Target { + data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + llvm_target: "mips".into(), + metadata: crate::spec::TargetMetadata { + description: Some("ZKM's zero-knowledge Virtual Machine (MIPS32r2 ISA)".into()), + tier: Some(3), + host_tools: Some(false), + std: None, // ? + }, + pointer_width: 32, + arch: "mips".into(), + + options: TargetOptions { + os: "zkvm".into(), + vendor: "zkm".into(), + linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), + linker: Some("rust-lld".into()), + endian: Endian::Big, + cpu: "mips32r2".into(), + + // Some crates (*cough* crossbeam) assume you have 64 bit + // atomics if the target name is not in a hardcoded list. + // Since zkvm is singlethreaded and all operations are + // atomic, I guess we can just say we support 64-bit + // atomics. + max_atomic_width: Some(64), + atomic_cas: true, + + features: "+mips32r2,+soft-float,+noabicalls".into(), + executables: true, + panic_strategy: PanicStrategy::Abort, + relocation_model: RelocModel::Static, + emit_debug_gdb_scripts: false, + eh_frame_header: false, + singlethread: true, + ..Default::default() + }, + } +} diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 561b611148a20..45156ea181d3c 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -128,6 +128,7 @@ static TARGETS: &[&str] = &[ "mipsisa64r6el-unknown-linux-gnuabi64", "mipsel-unknown-linux-gnu", "mipsel-unknown-linux-musl", + "mips-zkm-zkvm-elf", "nvptx64-nvidia-cuda", "powerpc-unknown-linux-gnu", "powerpc64-unknown-linux-gnu", From f243e9be492d4583f2374b4ef6bb8c7a023e8d02 Mon Sep 17 00:00:00 2001 From: Qethu <190734095+qethu@users.noreply.github.com> Date: Tue, 24 Dec 2024 20:09:17 +0800 Subject: [PATCH 2/4] fix test --- tests/assembly/targets/targets-elf.rs | 3 +++ tests/ui/check-cfg/well-known-values.stderr | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/assembly/targets/targets-elf.rs b/tests/assembly/targets/targets-elf.rs index 7d50647bed18e..7ef28604ce528 100644 --- a/tests/assembly/targets/targets-elf.rs +++ b/tests/assembly/targets/targets-elf.rs @@ -285,6 +285,9 @@ //@ revisions: mips_unknown_linux_uclibc //@ [mips_unknown_linux_uclibc] compile-flags: --target mips-unknown-linux-uclibc //@ [mips_unknown_linux_uclibc] needs-llvm-components: mips +//@ revisions: mips_zkm_zkvm_elf +//@ [mips_unknown_linux_uclibc] compile-flags: --target mips-zkm-zkvm-elf +//@ [mips_unknown_linux_uclibc] needs-llvm-components: mips //@ revisions: mipsel_sony_psp //@ [mipsel_sony_psp] compile-flags: --target mipsel-sony-psp //@ [mipsel_sony_psp] needs-llvm-components: mips diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index 7c03d0570db59..db807876ef2ce 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -230,7 +230,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_vendor = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `nintendo`, `nvidia`, `pc`, `risc0`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `win7`, and `wrs` + = note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `nintendo`, `nvidia`, `pc`, `risc0`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `win7`, `wrs` and `zkm` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` From 818b56a707457b2af415781cd64926b5437bf41f Mon Sep 17 00:00:00 2001 From: Qethu <190734095+qethu@users.noreply.github.com> Date: Tue, 24 Dec 2024 21:15:18 +0800 Subject: [PATCH 3/4] fix max_atomic_width --- .../rustc_target/src/spec/targets/mips_zkm_zkvm_elf.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/compiler/rustc_target/src/spec/targets/mips_zkm_zkvm_elf.rs b/compiler/rustc_target/src/spec/targets/mips_zkm_zkvm_elf.rs index 8499a41eaf29c..8869a26e796e3 100644 --- a/compiler/rustc_target/src/spec/targets/mips_zkm_zkvm_elf.rs +++ b/compiler/rustc_target/src/spec/targets/mips_zkm_zkvm_elf.rs @@ -22,13 +22,7 @@ pub(crate) fn target() -> Target { endian: Endian::Big, cpu: "mips32r2".into(), - // Some crates (*cough* crossbeam) assume you have 64 bit - // atomics if the target name is not in a hardcoded list. - // Since zkvm is singlethreaded and all operations are - // atomic, I guess we can just say we support 64-bit - // atomics. - max_atomic_width: Some(64), - atomic_cas: true, + max_atomic_width: Some(32), features: "+mips32r2,+soft-float,+noabicalls".into(), executables: true, From 9677a8f013f8aa4b4870b584a7c42c2444f49709 Mon Sep 17 00:00:00 2001 From: Qethu <190734095+qethu@users.noreply.github.com> Date: Wed, 25 Dec 2024 21:31:36 +0800 Subject: [PATCH 4/4] fix test --- tests/assembly/targets/targets-elf.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/assembly/targets/targets-elf.rs b/tests/assembly/targets/targets-elf.rs index 7ef28604ce528..be2439c335dcf 100644 --- a/tests/assembly/targets/targets-elf.rs +++ b/tests/assembly/targets/targets-elf.rs @@ -286,8 +286,8 @@ //@ [mips_unknown_linux_uclibc] compile-flags: --target mips-unknown-linux-uclibc //@ [mips_unknown_linux_uclibc] needs-llvm-components: mips //@ revisions: mips_zkm_zkvm_elf -//@ [mips_unknown_linux_uclibc] compile-flags: --target mips-zkm-zkvm-elf -//@ [mips_unknown_linux_uclibc] needs-llvm-components: mips +//@ [mips_zkm_zkvm_elf] compile-flags: --target mips-zkm-zkvm-elf +//@ [mips_zkm_zkvm_elf] needs-llvm-components: mips //@ revisions: mipsel_sony_psp //@ [mipsel_sony_psp] compile-flags: --target mipsel-sony-psp //@ [mipsel_sony_psp] needs-llvm-components: mips