From 8f2f25837085ce38dbc31356d0753b830b4cfcba Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Tue, 16 Apr 2024 15:47:51 +0100 Subject: [PATCH 01/18] add jolt toolchain --- compiler/rustc_target/src/spec/mod.rs | 1 + .../spec/targets/riscv32i_jolt_zkvm_elf.rs | 35 +++++++++++++++++++ src/tools/build-manifest/src/main.rs | 1 + 3 files changed, 37 insertions(+) create mode 100644 compiler/rustc_target/src/spec/targets/riscv32i_jolt_zkvm_elf.rs diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 946947124c6e..fbf998d6f5b1 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1751,6 +1751,7 @@ supported_targets! { ("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf), ("riscv32im-risc0-zkvm-elf", riscv32im_risc0_zkvm_elf), + ("riscv32i-jolt-zkvm-elf", riscv32i_jolt_zkvm_elf), ("riscv32im-unknown-none-elf", riscv32im_unknown_none_elf), ("riscv32ima-unknown-none-elf", riscv32ima_unknown_none_elf), ("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf), diff --git a/compiler/rustc_target/src/spec/targets/riscv32i_jolt_zkvm_elf.rs b/compiler/rustc_target/src/spec/targets/riscv32i_jolt_zkvm_elf.rs new file mode 100644 index 000000000000..9ac044a5963f --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/riscv32i_jolt_zkvm_elf.rs @@ -0,0 +1,35 @@ +use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel}; +use crate::spec::{Target, TargetOptions}; + +pub fn target() -> Target { + Target { + data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(), + llvm_target: "riscv32".into(), + pointer_width: 32, + arch: "riscv32".into(), + + metadata: crate::spec::TargetMetadata { + description: None, + tier: None, + host_tools: None, + std: None, + }, + + options: TargetOptions { + os: "zkvm".into(), + vendor: "jolt".into(), + linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), + linker: Some("rust-lld".into()), + cpu: "generic-rv32".into(), + max_atomic_width: Some(64), + atomic_cas: true, + 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 ff475b9571b8..c79c4a5dc3c5 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -131,6 +131,7 @@ static TARGETS: &[&str] = &[ "powerpc64le-unknown-linux-gnu", "riscv32i-unknown-none-elf", "riscv32im-risc0-zkvm-elf", + "riscv32i-jolt-zkvm-elf", "riscv32im-unknown-none-elf", "riscv32ima-unknown-none-elf", "riscv32imc-unknown-none-elf", From c56019984a9984281f7277f0874e44df50bc624b Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Tue, 16 Apr 2024 17:11:38 +0100 Subject: [PATCH 02/18] remove sys functions --- library/panic_abort/src/zkvm.rs | 38 ++-- library/std/src/sys/pal/zkvm/abi.rs | 106 +++++----- library/std/src/sys/pal/zkvm/alloc.rs | 11 +- library/std/src/sys/pal/zkvm/args.rs | 138 ++++++------- library/std/src/sys/pal/zkvm/mod.rs | 21 +- library/std/src/sys/pal/zkvm/os.rs | 278 +++++++++++++------------- library/std/src/sys/pal/zkvm/stdio.rs | 102 +++++----- 7 files changed, 346 insertions(+), 348 deletions(-) diff --git a/library/panic_abort/src/zkvm.rs b/library/panic_abort/src/zkvm.rs index a6a02abf1097..3eca5c07f5e6 100644 --- a/library/panic_abort/src/zkvm.rs +++ b/library/panic_abort/src/zkvm.rs @@ -1,24 +1,24 @@ -use alloc::string::String; +// use alloc::string::String; use core::panic::PanicPayload; -// Forward the abort message to zkVM's sys_panic. This is implemented by RISC Zero's -// platform crate which exposes system calls specifically for the zkVM. -pub(crate) unsafe fn zkvm_set_abort_message(payload: &mut dyn PanicPayload) { - let payload = payload.get(); - let msg = match payload.downcast_ref::<&'static str>() { - Some(msg) => msg.as_bytes(), - None => match payload.downcast_ref::() { - Some(msg) => msg.as_bytes(), - None => &[], - }, - }; - if msg.is_empty() { - return; - } +pub(crate) unsafe fn zkvm_set_abort_message(_payload: &mut dyn PanicPayload) { + // TODO: fix - extern "C" { - fn sys_panic(msg_ptr: *const u8, len: usize) -> !; - } + // let payload = payload.get(); + // let msg = match payload.downcast_ref::<&'static str>() { + // Some(msg) => msg.as_bytes(), + // None => match payload.downcast_ref::() { + // Some(msg) => msg.as_bytes(), + // None => &[], + // }, + // }; + // if msg.is_empty() { + // return; + // } - sys_panic(msg.as_ptr(), msg.len()); + // extern "C" { + // fn sys_panic(msg_ptr: *const u8, len: usize) -> !; + // } + + // sys_panic(msg.as_ptr(), msg.len()); } diff --git a/library/std/src/sys/pal/zkvm/abi.rs b/library/std/src/sys/pal/zkvm/abi.rs index 53332d90e02c..4eb7904d615c 100644 --- a/library/std/src/sys/pal/zkvm/abi.rs +++ b/library/std/src/sys/pal/zkvm/abi.rs @@ -1,55 +1,55 @@ -//! ABI definitions for symbols exported by risc0-zkvm-platform. - -// Included here so we don't have to depend on risc0-zkvm-platform. +// //! ABI definitions for symbols exported by risc0-zkvm-platform. // -// FIXME: Should we move this to the "libc" crate? It seems like other -// architectures put a lot of this kind of stuff there. But there's -// currently no risc0 fork of the libc crate, so we'd either have to -// fork it or upstream it. - -#![allow(dead_code)] -pub const DIGEST_WORDS: usize = 8; - -/// Standard IO file descriptors for use with sys_read and sys_write. -pub mod fileno { - pub const STDIN: u32 = 0; - pub const STDOUT: u32 = 1; - pub const STDERR: u32 = 2; - pub const JOURNAL: u32 = 3; -} - -extern "C" { - // Wrappers around syscalls provided by risc0-zkvm-platform: - pub fn sys_halt(); - pub fn sys_output(output_id: u32, output_value: u32); - pub fn sys_sha_compress( - out_state: *mut [u32; DIGEST_WORDS], - in_state: *const [u32; DIGEST_WORDS], - block1_ptr: *const [u32; DIGEST_WORDS], - block2_ptr: *const [u32; DIGEST_WORDS], - ); - pub fn sys_sha_buffer( - out_state: *mut [u32; DIGEST_WORDS], - in_state: *const [u32; DIGEST_WORDS], - buf: *const u8, - count: u32, - ); - pub fn sys_rand(recv_buf: *mut u32, words: usize); - pub fn sys_panic(msg_ptr: *const u8, len: usize) -> !; - pub fn sys_log(msg_ptr: *const u8, len: usize); - pub fn sys_cycle_count() -> usize; - pub fn sys_read(fd: u32, recv_buf: *mut u8, nrequested: usize) -> usize; - pub fn sys_write(fd: u32, write_buf: *const u8, nbytes: usize); - pub fn sys_getenv( - recv_buf: *mut u32, - words: usize, - varname: *const u8, - varname_len: usize, - ) -> usize; - pub fn sys_argc() -> usize; - pub fn sys_argv(out_words: *mut u32, out_nwords: usize, arg_index: usize) -> usize; +// // Included here so we don't have to depend on risc0-zkvm-platform. +// // +// // FIXME: Should we move this to the "libc" crate? It seems like other +// // architectures put a lot of this kind of stuff there. But there's +// // currently no risc0 fork of the libc crate, so we'd either have to +// // fork it or upstream it. +// +// #![allow(dead_code)] +// pub const DIGEST_WORDS: usize = 8; +// +// /// Standard IO file descriptors for use with sys_read and sys_write. +// pub mod fileno { +// pub const STDIN: u32 = 0; +// pub const STDOUT: u32 = 1; +// pub const STDERR: u32 = 2; +// pub const JOURNAL: u32 = 3; +// } - // Allocate memory from global HEAP. - pub fn sys_alloc_words(nwords: usize) -> *mut u32; - pub fn sys_alloc_aligned(nwords: usize, align: usize) -> *mut u8; -} +// extern "C" { +// // Wrappers around syscalls provided by risc0-zkvm-platform: +// pub fn sys_halt(); +// pub fn sys_output(output_id: u32, output_value: u32); +// pub fn sys_sha_compress( +// out_state: *mut [u32; DIGEST_WORDS], +// in_state: *const [u32; DIGEST_WORDS], +// block1_ptr: *const [u32; DIGEST_WORDS], +// block2_ptr: *const [u32; DIGEST_WORDS], +// ); +// pub fn sys_sha_buffer( +// out_state: *mut [u32; DIGEST_WORDS], +// in_state: *const [u32; DIGEST_WORDS], +// buf: *const u8, +// count: u32, +// ); +// pub fn sys_rand(recv_buf: *mut u32, words: usize); +// pub fn sys_panic(msg_ptr: *const u8, len: usize) -> !; +// pub fn sys_log(msg_ptr: *const u8, len: usize); +// pub fn sys_cycle_count() -> usize; +// pub fn sys_read(fd: u32, recv_buf: *mut u8, nrequested: usize) -> usize; +// pub fn sys_write(fd: u32, write_buf: *const u8, nbytes: usize); +// pub fn sys_getenv( +// recv_buf: *mut u32, +// words: usize, +// varname: *const u8, +// varname_len: usize, +// ) -> usize; +// pub fn sys_argc() -> usize; +// pub fn sys_argv(out_words: *mut u32, out_nwords: usize, arg_index: usize) -> usize; +// +// // Allocate memory from global HEAP. +// pub fn sys_alloc_words(nwords: usize) -> *mut u32; +// pub fn sys_alloc_aligned(nwords: usize, align: usize) -> *mut u8; +// } diff --git a/library/std/src/sys/pal/zkvm/alloc.rs b/library/std/src/sys/pal/zkvm/alloc.rs index 2fdca2235247..737fd6b1fe19 100644 --- a/library/std/src/sys/pal/zkvm/alloc.rs +++ b/library/std/src/sys/pal/zkvm/alloc.rs @@ -1,15 +1,10 @@ -use super::abi; use crate::alloc::{GlobalAlloc, Layout, System}; #[stable(feature = "alloc_system_type", since = "1.28.0")] unsafe impl GlobalAlloc for System { - #[inline] - unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - unsafe { abi::sys_alloc_aligned(layout.size(), layout.align()) } + unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { + core::ptr::null_mut() } - #[inline] - unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) { - // this allocator never deallocates memory - } + unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} } diff --git a/library/std/src/sys/pal/zkvm/args.rs b/library/std/src/sys/pal/zkvm/args.rs index 583c16e3a472..50db1034a0bb 100644 --- a/library/std/src/sys/pal/zkvm/args.rs +++ b/library/std/src/sys/pal/zkvm/args.rs @@ -1,81 +1,81 @@ -use super::{abi, WORD_SIZE}; -use crate::ffi::OsString; -use crate::fmt; -use crate::sys::os_str; -use crate::sys_common::FromInner; +// use super::{abi, WORD_SIZE}; +// use crate::ffi::OsString; +// use crate::fmt; +// use crate::sys::os_str; +// use crate::sys_common::FromInner; -pub struct Args { - i_forward: usize, - i_back: usize, - count: usize, -} +// pub struct Args { +// i_forward: usize, +// i_back: usize, +// count: usize, +// } -pub fn args() -> Args { - let count = unsafe { abi::sys_argc() }; - Args { i_forward: 0, i_back: 0, count } -} +// pub fn args() -> Args { +// let count = unsafe { abi::sys_argc() }; +// Args { i_forward: 0, i_back: 0, count } +// } -impl Args { - /// Use sys_argv to get the arg at the requested index. Does not check that i is less than argc - /// and will not return if the index is out of bounds. - fn argv(i: usize) -> OsString { - let arg_len = unsafe { abi::sys_argv(crate::ptr::null_mut(), 0, i) }; +// impl Args { +// /// Use sys_argv to get the arg at the requested index. Does not check that i is less than argc +// /// and will not return if the index is out of bounds. +// fn argv(i: usize) -> OsString { +// let arg_len = unsafe { abi::sys_argv(crate::ptr::null_mut(), 0, i) }; - let arg_len_words = (arg_len + WORD_SIZE - 1) / WORD_SIZE; - let words = unsafe { abi::sys_alloc_words(arg_len_words) }; +// let arg_len_words = (arg_len + WORD_SIZE - 1) / WORD_SIZE; +// let words = unsafe { abi::sys_alloc_words(arg_len_words) }; - let arg_len2 = unsafe { abi::sys_argv(words, arg_len_words, i) }; - debug_assert_eq!(arg_len, arg_len2); +// let arg_len2 = unsafe { abi::sys_argv(words, arg_len_words, i) }; +// debug_assert_eq!(arg_len, arg_len2); - // Convert to OsString. - // - // FIXME: We can probably get rid of the extra copy here if we - // reimplement "os_str" instead of just using the generic unix - // "os_str". - let arg_bytes: &[u8] = - unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, arg_len) }; - OsString::from_inner(os_str::Buf { inner: arg_bytes.to_vec() }) - } -} +// // Convert to OsString. +// // +// // FIXME: We can probably get rid of the extra copy here if we +// // reimplement "os_str" instead of just using the generic unix +// // "os_str". +// let arg_bytes: &[u8] = +// unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, arg_len) }; +// OsString::from_inner(os_str::Buf { inner: arg_bytes.to_vec() }) +// } +// } -impl fmt::Debug for Args { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_list().finish() - } -} +// impl fmt::Debug for Args { +// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +// f.debug_list().finish() +// } +// } -impl Iterator for Args { - type Item = OsString; +// impl Iterator for Args { +// type Item = OsString; - fn next(&mut self) -> Option { - if self.i_forward >= self.count - self.i_back { - None - } else { - let arg = Self::argv(self.i_forward); - self.i_forward += 1; - Some(arg) - } - } +// fn next(&mut self) -> Option { +// if self.i_forward >= self.count - self.i_back { +// None +// } else { +// let arg = Self::argv(self.i_forward); +// self.i_forward += 1; +// Some(arg) +// } +// } - fn size_hint(&self) -> (usize, Option) { - (self.count, Some(self.count)) - } -} +// fn size_hint(&self) -> (usize, Option) { +// (self.count, Some(self.count)) +// } +// } -impl ExactSizeIterator for Args { - fn len(&self) -> usize { - self.count - } -} +// impl ExactSizeIterator for Args { +// fn len(&self) -> usize { +// self.count +// } +// } -impl DoubleEndedIterator for Args { - fn next_back(&mut self) -> Option { - if self.i_back >= self.count - self.i_forward { - None - } else { - let arg = Self::argv(self.count - 1 - self.i_back); - self.i_back += 1; - Some(arg) - } - } -} +// impl DoubleEndedIterator for Args { +// fn next_back(&mut self) -> Option { +// if self.i_back >= self.count - self.i_forward { +// None +// } else { +// let arg = Self::argv(self.count - 1 - self.i_back); +// self.i_back += 1; +// Some(arg) +// } +// } +// } diff --git a/library/std/src/sys/pal/zkvm/mod.rs b/library/std/src/sys/pal/zkvm/mod.rs index 651f25d66236..c19dc3ab08fb 100644 --- a/library/std/src/sys/pal/zkvm/mod.rs +++ b/library/std/src/sys/pal/zkvm/mod.rs @@ -1,4 +1,4 @@ -//! System bindings for the risc0 zkvm platform +//! System bindings for the jolt zkvm platform //! //! This module contains the facade (aka platform-specific) implementations of //! OS level functionality for zkvm. @@ -8,11 +8,10 @@ //! will likely change over time. #![forbid(unsafe_op_in_unsafe_fn)] -const WORD_SIZE: usize = core::mem::size_of::(); - pub mod alloc; -#[path = "../zkvm/args.rs"] +#[path = "../unsupported/args.rs"] pub mod args; +#[path = "../unsupported/env.rs"] pub mod env; #[path = "../unsupported/fs.rs"] pub mod fs; @@ -20,11 +19,13 @@ pub mod fs; pub mod io; #[path = "../unsupported/net.rs"] pub mod net; +#[path = "../unsupported/os.rs"] pub mod os; #[path = "../unsupported/pipe.rs"] pub mod pipe; #[path = "../unsupported/process.rs"] pub mod process; +#[path = "../unsupported/stdio.rs"] pub mod stdio; #[path = "../unsupported/time.rs"] pub mod time; @@ -65,9 +66,11 @@ pub fn abort_internal() -> ! { } pub fn hashmap_random_keys() -> (u64, u64) { - let mut buf = [0u32; 4]; - unsafe { - abi::sys_rand(buf.as_mut_ptr(), 4); - }; - ((buf[0] as u64) << 32 + buf[1] as u64, (buf[2] as u64) << 32 + buf[3] as u64) + // let mut buf = [0u32; 4]; + // unsafe { + // abi::sys_rand(buf.as_mut_ptr(), 4); + // }; + // (buf[0] as u64) << 32 + buf[1] as u64, (buf[2] as u64) << 32 + buf[3] as u64) + + (0, 0) } diff --git a/library/std/src/sys/pal/zkvm/os.rs b/library/std/src/sys/pal/zkvm/os.rs index 68d91a123acd..6b1503f2d204 100644 --- a/library/std/src/sys/pal/zkvm/os.rs +++ b/library/std/src/sys/pal/zkvm/os.rs @@ -1,139 +1,139 @@ -use super::{abi, unsupported, WORD_SIZE}; -use crate::error::Error as StdError; -use crate::ffi::{OsStr, OsString}; -use crate::marker::PhantomData; -use crate::path::{self, PathBuf}; -use crate::sys::os_str; -use crate::sys_common::FromInner; -use crate::{fmt, io}; - -pub fn errno() -> i32 { - 0 -} - -pub fn error_string(_errno: i32) -> String { - "operation successful".to_string() -} - -pub fn getcwd() -> io::Result { - unsupported() -} - -pub fn chdir(_: &path::Path) -> io::Result<()> { - unsupported() -} - -pub struct SplitPaths<'a>(!, PhantomData<&'a ()>); - -pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> { - panic!("unsupported") -} - -impl<'a> Iterator for SplitPaths<'a> { - type Item = PathBuf; - fn next(&mut self) -> Option { - self.0 - } -} - -#[derive(Debug)] -pub struct JoinPathsError; - -pub fn join_paths(_paths: I) -> Result -where - I: Iterator, - T: AsRef, -{ - Err(JoinPathsError) -} - -impl fmt::Display for JoinPathsError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - "not supported on this platform yet".fmt(f) - } -} - -impl StdError for JoinPathsError { - #[allow(deprecated)] - fn description(&self) -> &str { - "not supported on this platform yet" - } -} - -pub fn current_exe() -> io::Result { - unsupported() -} - -pub struct Env(!); - -impl Iterator for Env { - type Item = (OsString, OsString); - fn next(&mut self) -> Option<(OsString, OsString)> { - self.0 - } -} - -pub fn env() -> Env { - panic!("not supported on this platform") -} - -impl Env { - pub fn str_debug(&self) -> impl fmt::Debug + '_ { - let Self(inner) = self; - match *inner {} - } -} - -impl fmt::Debug for Env { - fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self(inner) = self; - match *inner {} - } -} - -pub fn getenv(varname: &OsStr) -> Option { - let varname = varname.as_encoded_bytes(); - let nbytes = - unsafe { abi::sys_getenv(crate::ptr::null_mut(), 0, varname.as_ptr(), varname.len()) }; - if nbytes == usize::MAX { - return None; - } - - let nwords = (nbytes + WORD_SIZE - 1) / WORD_SIZE; - let words = unsafe { abi::sys_alloc_words(nwords) }; - - let nbytes2 = unsafe { abi::sys_getenv(words, nwords, varname.as_ptr(), varname.len()) }; - debug_assert_eq!(nbytes, nbytes2); - - // Convert to OsString. - // - // FIXME: We can probably get rid of the extra copy here if we - // reimplement "os_str" instead of just using the generic unix - // "os_str". - let u8s: &[u8] = unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, nbytes) }; - Some(OsString::from_inner(os_str::Buf { inner: u8s.to_vec() })) -} - -pub unsafe fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> { - Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform")) -} - -pub unsafe fn unsetenv(_: &OsStr) -> io::Result<()> { - Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform")) -} - -pub fn temp_dir() -> PathBuf { - panic!("no filesystem on this platform") -} - -pub fn home_dir() -> Option { - None -} - -pub fn exit(_code: i32) -> ! { - crate::intrinsics::abort() -} - -pub fn getpid() -> u32 { - panic!("no pids on this platform") -} +// use super::{abi, unsupported, WORD_SIZE}; +// use crate::error::Error as StdError; +// use crate::ffi::{OsStr, OsString}; +// use crate::marker::PhantomData; +// use crate::path::{self, PathBuf}; +// use crate::sys::os_str; +// use crate::sys_common::FromInner; +// use crate::{fmt, io}; + +// pub fn errno() -> i32 { +// 0 +// } + +// pub fn error_string(_errno: i32) -> String { +// "operation successful".to_string() +// } + +// pub fn getcwd() -> io::Result { +// unsupported() +// } + +// pub fn chdir(_: &path::Path) -> io::Result<()> { +// unsupported() +// } + +// pub struct SplitPaths<'a>(!, PhantomData<&'a ()>); + +// pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> { +// panic!("unsupported") +// } + +// impl<'a> Iterator for SplitPaths<'a> { +// type Item = PathBuf; +// fn next(&mut self) -> Option { +// self.0 +// } +// } + +// #[derive(Debug)] +// pub struct JoinPathsError; + +// pub fn join_paths(_paths: I) -> Result +// where +// I: Iterator, +// T: AsRef, +// { +// Err(JoinPathsError) +// } + +// impl fmt::Display for JoinPathsError { +// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +// "not supported on this platform yet".fmt(f) +// } +// } + +// impl StdError for JoinPathsError { +// #[allow(deprecated)] +// fn description(&self) -> &str { +// "not supported on this platform yet" +// } +// } + +// pub fn current_exe() -> io::Result { +// unsupported() +// } + +// pub struct Env(!); + +// impl Iterator for Env { +// type Item = (OsString, OsString); +// fn next(&mut self) -> Option<(OsString, OsString)> { +// self.0 +// } +// } + +// pub fn env() -> Env { +// panic!("not supported on this platform") +// } + +// impl Env { +// pub fn str_debug(&self) -> impl fmt::Debug + '_ { +// let Self(inner) = self; +// match *inner {} +// } +// } + +// impl fmt::Debug for Env { +// fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { +// let Self(inner) = self; +// match *inner {} +// } +// } + +// pub fn getenv(varname: &OsStr) -> Option { +// let varname = varname.as_encoded_bytes(); +// let nbytes = +// unsafe { abi::sys_getenv(crate::ptr::null_mut(), 0, varname.as_ptr(), varname.len()) }; +// if nbytes == usize::MAX { +// return None; +// } + +// let nwords = (nbytes + WORD_SIZE - 1) / WORD_SIZE; +// let words = unsafe { abi::sys_alloc_words(nwords) }; + +// let nbytes2 = unsafe { abi::sys_getenv(words, nwords, varname.as_ptr(), varname.len()) }; +// debug_assert_eq!(nbytes, nbytes2); + +// // Convert to OsString. +// // +// // FIXME: We can probably get rid of the extra copy here if we +// // reimplement "os_str" instead of just using the generic unix +// // "os_str". +// let u8s: &[u8] = unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, nbytes) }; +// Some(OsString::from_inner(os_str::Buf { inner: u8s.to_vec() })) +// } + +// pub unsafe fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> { +// Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform")) +// } + +// pub unsafe fn unsetenv(_: &OsStr) -> io::Result<()> { +// Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform")) +// } + +// pub fn temp_dir() -> PathBuf { +// panic!("no filesystem on this platform") +// } + +// pub fn home_dir() -> Option { +// None +// } + +// pub fn exit(_code: i32) -> ! { +// crate::intrinsics::abort() +// } + +// pub fn getpid() -> u32 { +// panic!("no pids on this platform") +// } diff --git a/library/std/src/sys/pal/zkvm/stdio.rs b/library/std/src/sys/pal/zkvm/stdio.rs index dd218c8894ca..9e5273a405f9 100644 --- a/library/std/src/sys/pal/zkvm/stdio.rs +++ b/library/std/src/sys/pal/zkvm/stdio.rs @@ -1,65 +1,65 @@ -use super::abi; -use super::abi::fileno; -use crate::io; +// use super::abi; +// use super::abi::fileno; +// use crate::io; -pub struct Stdin; -pub struct Stdout; -pub struct Stderr; +// pub struct Stdin; +// pub struct Stdout; +// pub struct Stderr; -impl Stdin { - pub const fn new() -> Stdin { - Stdin - } -} +// impl Stdin { +// pub const fn new() -> Stdin { +// Stdin +// } +// } -impl io::Read for Stdin { - fn read(&mut self, buf: &mut [u8]) -> io::Result { - Ok(unsafe { abi::sys_read(fileno::STDIN, buf.as_mut_ptr(), buf.len()) }) - } -} +// impl io::Read for Stdin { +// fn read(&mut self, buf: &mut [u8]) -> io::Result { +// Ok(unsafe { abi::sys_read(fileno::STDIN, buf.as_mut_ptr(), buf.len()) }) +// } +// } -impl Stdout { - pub const fn new() -> Stdout { - Stdout - } -} +// impl Stdout { +// pub const fn new() -> Stdout { +// Stdout +// } +// } -impl io::Write for Stdout { - fn write(&mut self, buf: &[u8]) -> io::Result { - unsafe { abi::sys_write(fileno::STDOUT, buf.as_ptr(), buf.len()) } +// impl io::Write for Stdout { +// fn write(&mut self, buf: &[u8]) -> io::Result { +// unsafe { abi::sys_write(fileno::STDOUT, buf.as_ptr(), buf.len()) } - Ok(buf.len()) - } +// Ok(buf.len()) +// } - fn flush(&mut self) -> io::Result<()> { - Ok(()) - } -} +// fn flush(&mut self) -> io::Result<()> { +// Ok(()) +// } +// } -impl Stderr { - pub const fn new() -> Stderr { - Stderr - } -} +// impl Stderr { +// pub const fn new() -> Stderr { +// Stderr +// } +// } -impl io::Write for Stderr { - fn write(&mut self, buf: &[u8]) -> io::Result { - unsafe { abi::sys_write(fileno::STDERR, buf.as_ptr(), buf.len()) } +// impl io::Write for Stderr { +// fn write(&mut self, buf: &[u8]) -> io::Result { +// unsafe { abi::sys_write(fileno::STDERR, buf.as_ptr(), buf.len()) } - Ok(buf.len()) - } +// Ok(buf.len()) +// } - fn flush(&mut self) -> io::Result<()> { - Ok(()) - } -} +// fn flush(&mut self) -> io::Result<()> { +// Ok(()) +// } +// } -pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; +// pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; -pub fn is_ebadf(_err: &io::Error) -> bool { - true -} +// pub fn is_ebadf(_err: &io::Error) -> bool { +// true +// } -pub fn panic_output() -> Option { - Some(Stderr::new()) -} +// pub fn panic_output() -> Option { +// Some(Stderr::new()) +// } From 58807f45f5cd0bbfbb19e6e330cdd716a282f56d Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Tue, 16 Apr 2024 19:05:18 +0100 Subject: [PATCH 03/18] fix allocator --- .../spec/targets/riscv32i_jolt_zkvm_elf.rs | 1 + library/std/src/lib.rs | 2 +- library/std/src/sys/pal/zkvm/alloc.rs | 50 +++++++++++++++++-- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_target/src/spec/targets/riscv32i_jolt_zkvm_elf.rs b/compiler/rustc_target/src/spec/targets/riscv32i_jolt_zkvm_elf.rs index 9ac044a5963f..783b9a744a10 100644 --- a/compiler/rustc_target/src/spec/targets/riscv32i_jolt_zkvm_elf.rs +++ b/compiler/rustc_target/src/spec/targets/riscv32i_jolt_zkvm_elf.rs @@ -29,6 +29,7 @@ pub fn target() -> Target { emit_debug_gdb_scripts: false, eh_frame_header: false, singlethread: true, + supports_stack_protector: false, ..Default::default() }, } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 6bd9c59a949c..f1bedc896461 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -251,7 +251,7 @@ #![allow(unused_lifetimes)] #![allow(internal_features)] #![deny(rustc::existing_doc_keyword)] -#![deny(fuzzy_provenance_casts)] +// #![deny(fuzzy_provenance_casts)] #![deny(unsafe_op_in_unsafe_fn)] #![allow(rustdoc::redundant_explicit_links)] #![warn(rustdoc::unescaped_backticks)] diff --git a/library/std/src/sys/pal/zkvm/alloc.rs b/library/std/src/sys/pal/zkvm/alloc.rs index 737fd6b1fe19..7ce4efb12502 100644 --- a/library/std/src/sys/pal/zkvm/alloc.rs +++ b/library/std/src/sys/pal/zkvm/alloc.rs @@ -1,10 +1,54 @@ -use crate::alloc::{GlobalAlloc, Layout, System}; +use crate::{alloc::{GlobalAlloc, Layout, System}, cell::UnsafeCell}; + +static mut BUMP_ALLOC: BumpAllocator = BumpAllocator::new(); #[stable(feature = "alloc_system_type", since = "1.28.0")] unsafe impl GlobalAlloc for System { - unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { - core::ptr::null_mut() + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + BUMP_ALLOC.alloc(layout) } unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} } + +extern "C" { + static _HEAP_PTR: u8; +} + +pub struct BumpAllocator { + offset: UnsafeCell, +} + +unsafe impl Sync for BumpAllocator {} + +fn heap_start() -> usize { + unsafe { _HEAP_PTR as *const u8 as usize } +} + +impl BumpAllocator { + pub const fn new() -> Self { + Self { + offset: UnsafeCell::new(0), + } + } + + pub fn free_memory(&self) -> usize { + heap_start() + (self.offset.get() as usize) + } +} + +unsafe impl GlobalAlloc for BumpAllocator { + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + let alloc_start = align_up(self.free_memory(), layout.align()); + let alloc_end = alloc_start + layout.size(); + *self.offset.get() = alloc_end - self.free_memory(); + + alloc_start as *mut u8 + } + + unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} +} + +fn align_up(addr: usize, align: usize) -> usize { + (addr + align - 1) & !(align - 1) +} From 827c5b48996d28e39113ac18f5fa99f0ff41c558 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Tue, 16 Apr 2024 19:16:04 +0100 Subject: [PATCH 04/18] add config --- .gitignore | 1 - config.toml | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 config.toml diff --git a/.gitignore b/.gitignore index 87d02563ed04..ce51bdb05a48 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,6 @@ Session.vim !/tests/run-make/thumb-none-qemu/example/.cargo ## Configuration -/config.toml /Makefile config.mk config.stamp diff --git a/config.toml b/config.toml new file mode 100644 index 000000000000..cc954b2c2349 --- /dev/null +++ b/config.toml @@ -0,0 +1,14 @@ +changelog-seen = 2 + +[build] +target = ["riscv32i-jolt-zkvm-elf"] +extended = true +tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"] +configure-args = [] + +[rust] +lld = true +llvm-tools = true + +[llvm] +download-ci-llvm = false From 615514cdca1932f9752ad73877a2426f8c9dd9bc Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Tue, 16 Apr 2024 22:24:09 +0100 Subject: [PATCH 05/18] refactor allocator --- library/std/src/sys/pal/zkvm/abi.rs | 58 ++------------------------- library/std/src/sys/pal/zkvm/alloc.rs | 17 ++++---- 2 files changed, 10 insertions(+), 65 deletions(-) diff --git a/library/std/src/sys/pal/zkvm/abi.rs b/library/std/src/sys/pal/zkvm/abi.rs index 4eb7904d615c..2c73268f5556 100644 --- a/library/std/src/sys/pal/zkvm/abi.rs +++ b/library/std/src/sys/pal/zkvm/abi.rs @@ -1,55 +1,3 @@ -// //! ABI definitions for symbols exported by risc0-zkvm-platform. -// -// // Included here so we don't have to depend on risc0-zkvm-platform. -// // -// // FIXME: Should we move this to the "libc" crate? It seems like other -// // architectures put a lot of this kind of stuff there. But there's -// // currently no risc0 fork of the libc crate, so we'd either have to -// // fork it or upstream it. -// -// #![allow(dead_code)] -// pub const DIGEST_WORDS: usize = 8; -// -// /// Standard IO file descriptors for use with sys_read and sys_write. -// pub mod fileno { -// pub const STDIN: u32 = 0; -// pub const STDOUT: u32 = 1; -// pub const STDERR: u32 = 2; -// pub const JOURNAL: u32 = 3; -// } - -// extern "C" { -// // Wrappers around syscalls provided by risc0-zkvm-platform: -// pub fn sys_halt(); -// pub fn sys_output(output_id: u32, output_value: u32); -// pub fn sys_sha_compress( -// out_state: *mut [u32; DIGEST_WORDS], -// in_state: *const [u32; DIGEST_WORDS], -// block1_ptr: *const [u32; DIGEST_WORDS], -// block2_ptr: *const [u32; DIGEST_WORDS], -// ); -// pub fn sys_sha_buffer( -// out_state: *mut [u32; DIGEST_WORDS], -// in_state: *const [u32; DIGEST_WORDS], -// buf: *const u8, -// count: u32, -// ); -// pub fn sys_rand(recv_buf: *mut u32, words: usize); -// pub fn sys_panic(msg_ptr: *const u8, len: usize) -> !; -// pub fn sys_log(msg_ptr: *const u8, len: usize); -// pub fn sys_cycle_count() -> usize; -// pub fn sys_read(fd: u32, recv_buf: *mut u8, nrequested: usize) -> usize; -// pub fn sys_write(fd: u32, write_buf: *const u8, nbytes: usize); -// pub fn sys_getenv( -// recv_buf: *mut u32, -// words: usize, -// varname: *const u8, -// varname_len: usize, -// ) -> usize; -// pub fn sys_argc() -> usize; -// pub fn sys_argv(out_words: *mut u32, out_nwords: usize, arg_index: usize) -> usize; -// -// // Allocate memory from global HEAP. -// pub fn sys_alloc_words(nwords: usize) -> *mut u32; -// pub fn sys_alloc_aligned(nwords: usize, align: usize) -> *mut u8; -// } +extern "C" { + pub static _HEAP_PTR: u8; +} diff --git a/library/std/src/sys/pal/zkvm/alloc.rs b/library/std/src/sys/pal/zkvm/alloc.rs index 7ce4efb12502..76fe1212841c 100644 --- a/library/std/src/sys/pal/zkvm/alloc.rs +++ b/library/std/src/sys/pal/zkvm/alloc.rs @@ -1,4 +1,5 @@ use crate::{alloc::{GlobalAlloc, Layout, System}, cell::UnsafeCell}; +use super::abi::_HEAP_PTR; static mut BUMP_ALLOC: BumpAllocator = BumpAllocator::new(); @@ -11,20 +12,10 @@ unsafe impl GlobalAlloc for System { unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} } -extern "C" { - static _HEAP_PTR: u8; -} - pub struct BumpAllocator { offset: UnsafeCell, } -unsafe impl Sync for BumpAllocator {} - -fn heap_start() -> usize { - unsafe { _HEAP_PTR as *const u8 as usize } -} - impl BumpAllocator { pub const fn new() -> Self { Self { @@ -49,6 +40,12 @@ unsafe impl GlobalAlloc for BumpAllocator { unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} } +unsafe impl Sync for BumpAllocator {} + fn align_up(addr: usize, align: usize) -> usize { (addr + align - 1) & !(align - 1) } + +fn heap_start() -> usize { + unsafe { _HEAP_PTR as *const u8 as usize } +} From 9addcb7d4371a3ee8faa085e48c88d1c5018cbb7 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Tue, 16 Apr 2024 22:43:06 +0100 Subject: [PATCH 06/18] remove commented out code --- library/std/src/sys/pal/zkvm/args.rs | 81 --------------- library/std/src/sys/pal/zkvm/os.rs | 139 -------------------------- library/std/src/sys/pal/zkvm/stdio.rs | 65 ------------ 3 files changed, 285 deletions(-) delete mode 100644 library/std/src/sys/pal/zkvm/args.rs delete mode 100644 library/std/src/sys/pal/zkvm/os.rs delete mode 100644 library/std/src/sys/pal/zkvm/stdio.rs diff --git a/library/std/src/sys/pal/zkvm/args.rs b/library/std/src/sys/pal/zkvm/args.rs deleted file mode 100644 index 50db1034a0bb..000000000000 --- a/library/std/src/sys/pal/zkvm/args.rs +++ /dev/null @@ -1,81 +0,0 @@ -// use super::{abi, WORD_SIZE}; -// use crate::ffi::OsString; -// use crate::fmt; -// use crate::sys::os_str; -// use crate::sys_common::FromInner; - -// pub struct Args { -// i_forward: usize, -// i_back: usize, -// count: usize, -// } - -// pub fn args() -> Args { -// let count = unsafe { abi::sys_argc() }; -// Args { i_forward: 0, i_back: 0, count } -// } - -// impl Args { -// /// Use sys_argv to get the arg at the requested index. Does not check that i is less than argc -// /// and will not return if the index is out of bounds. -// fn argv(i: usize) -> OsString { -// let arg_len = unsafe { abi::sys_argv(crate::ptr::null_mut(), 0, i) }; - -// let arg_len_words = (arg_len + WORD_SIZE - 1) / WORD_SIZE; -// let words = unsafe { abi::sys_alloc_words(arg_len_words) }; - -// let arg_len2 = unsafe { abi::sys_argv(words, arg_len_words, i) }; -// debug_assert_eq!(arg_len, arg_len2); - -// // Convert to OsString. -// // -// // FIXME: We can probably get rid of the extra copy here if we -// // reimplement "os_str" instead of just using the generic unix -// // "os_str". -// let arg_bytes: &[u8] = -// unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, arg_len) }; -// OsString::from_inner(os_str::Buf { inner: arg_bytes.to_vec() }) -// } -// } - -// impl fmt::Debug for Args { -// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { -// f.debug_list().finish() -// } -// } - -// impl Iterator for Args { -// type Item = OsString; - -// fn next(&mut self) -> Option { -// if self.i_forward >= self.count - self.i_back { -// None -// } else { -// let arg = Self::argv(self.i_forward); -// self.i_forward += 1; -// Some(arg) -// } -// } - -// fn size_hint(&self) -> (usize, Option) { -// (self.count, Some(self.count)) -// } -// } - -// impl ExactSizeIterator for Args { -// fn len(&self) -> usize { -// self.count -// } -// } - -// impl DoubleEndedIterator for Args { -// fn next_back(&mut self) -> Option { -// if self.i_back >= self.count - self.i_forward { -// None -// } else { -// let arg = Self::argv(self.count - 1 - self.i_back); -// self.i_back += 1; -// Some(arg) -// } -// } -// } diff --git a/library/std/src/sys/pal/zkvm/os.rs b/library/std/src/sys/pal/zkvm/os.rs deleted file mode 100644 index 6b1503f2d204..000000000000 --- a/library/std/src/sys/pal/zkvm/os.rs +++ /dev/null @@ -1,139 +0,0 @@ -// use super::{abi, unsupported, WORD_SIZE}; -// use crate::error::Error as StdError; -// use crate::ffi::{OsStr, OsString}; -// use crate::marker::PhantomData; -// use crate::path::{self, PathBuf}; -// use crate::sys::os_str; -// use crate::sys_common::FromInner; -// use crate::{fmt, io}; - -// pub fn errno() -> i32 { -// 0 -// } - -// pub fn error_string(_errno: i32) -> String { -// "operation successful".to_string() -// } - -// pub fn getcwd() -> io::Result { -// unsupported() -// } - -// pub fn chdir(_: &path::Path) -> io::Result<()> { -// unsupported() -// } - -// pub struct SplitPaths<'a>(!, PhantomData<&'a ()>); - -// pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> { -// panic!("unsupported") -// } - -// impl<'a> Iterator for SplitPaths<'a> { -// type Item = PathBuf; -// fn next(&mut self) -> Option { -// self.0 -// } -// } - -// #[derive(Debug)] -// pub struct JoinPathsError; - -// pub fn join_paths(_paths: I) -> Result -// where -// I: Iterator, -// T: AsRef, -// { -// Err(JoinPathsError) -// } - -// impl fmt::Display for JoinPathsError { -// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { -// "not supported on this platform yet".fmt(f) -// } -// } - -// impl StdError for JoinPathsError { -// #[allow(deprecated)] -// fn description(&self) -> &str { -// "not supported on this platform yet" -// } -// } - -// pub fn current_exe() -> io::Result { -// unsupported() -// } - -// pub struct Env(!); - -// impl Iterator for Env { -// type Item = (OsString, OsString); -// fn next(&mut self) -> Option<(OsString, OsString)> { -// self.0 -// } -// } - -// pub fn env() -> Env { -// panic!("not supported on this platform") -// } - -// impl Env { -// pub fn str_debug(&self) -> impl fmt::Debug + '_ { -// let Self(inner) = self; -// match *inner {} -// } -// } - -// impl fmt::Debug for Env { -// fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { -// let Self(inner) = self; -// match *inner {} -// } -// } - -// pub fn getenv(varname: &OsStr) -> Option { -// let varname = varname.as_encoded_bytes(); -// let nbytes = -// unsafe { abi::sys_getenv(crate::ptr::null_mut(), 0, varname.as_ptr(), varname.len()) }; -// if nbytes == usize::MAX { -// return None; -// } - -// let nwords = (nbytes + WORD_SIZE - 1) / WORD_SIZE; -// let words = unsafe { abi::sys_alloc_words(nwords) }; - -// let nbytes2 = unsafe { abi::sys_getenv(words, nwords, varname.as_ptr(), varname.len()) }; -// debug_assert_eq!(nbytes, nbytes2); - -// // Convert to OsString. -// // -// // FIXME: We can probably get rid of the extra copy here if we -// // reimplement "os_str" instead of just using the generic unix -// // "os_str". -// let u8s: &[u8] = unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, nbytes) }; -// Some(OsString::from_inner(os_str::Buf { inner: u8s.to_vec() })) -// } - -// pub unsafe fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> { -// Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform")) -// } - -// pub unsafe fn unsetenv(_: &OsStr) -> io::Result<()> { -// Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform")) -// } - -// pub fn temp_dir() -> PathBuf { -// panic!("no filesystem on this platform") -// } - -// pub fn home_dir() -> Option { -// None -// } - -// pub fn exit(_code: i32) -> ! { -// crate::intrinsics::abort() -// } - -// pub fn getpid() -> u32 { -// panic!("no pids on this platform") -// } diff --git a/library/std/src/sys/pal/zkvm/stdio.rs b/library/std/src/sys/pal/zkvm/stdio.rs deleted file mode 100644 index 9e5273a405f9..000000000000 --- a/library/std/src/sys/pal/zkvm/stdio.rs +++ /dev/null @@ -1,65 +0,0 @@ -// use super::abi; -// use super::abi::fileno; -// use crate::io; - -// pub struct Stdin; -// pub struct Stdout; -// pub struct Stderr; - -// impl Stdin { -// pub const fn new() -> Stdin { -// Stdin -// } -// } - -// impl io::Read for Stdin { -// fn read(&mut self, buf: &mut [u8]) -> io::Result { -// Ok(unsafe { abi::sys_read(fileno::STDIN, buf.as_mut_ptr(), buf.len()) }) -// } -// } - -// impl Stdout { -// pub const fn new() -> Stdout { -// Stdout -// } -// } - -// impl io::Write for Stdout { -// fn write(&mut self, buf: &[u8]) -> io::Result { -// unsafe { abi::sys_write(fileno::STDOUT, buf.as_ptr(), buf.len()) } - -// Ok(buf.len()) -// } - -// fn flush(&mut self) -> io::Result<()> { -// Ok(()) -// } -// } - -// impl Stderr { -// pub const fn new() -> Stderr { -// Stderr -// } -// } - -// impl io::Write for Stderr { -// fn write(&mut self, buf: &[u8]) -> io::Result { -// unsafe { abi::sys_write(fileno::STDERR, buf.as_ptr(), buf.len()) } - -// Ok(buf.len()) -// } - -// fn flush(&mut self) -> io::Result<()> { -// Ok(()) -// } -// } - -// pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; - -// pub fn is_ebadf(_err: &io::Error) -> bool { -// true -// } - -// pub fn panic_output() -> Option { -// Some(Stderr::new()) -// } From 1682ff613104bb979d6e573361fc74cec0516785 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Tue, 16 Apr 2024 23:17:48 +0100 Subject: [PATCH 07/18] use jolt panic handler --- library/panic_abort/src/zkvm.rs | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/library/panic_abort/src/zkvm.rs b/library/panic_abort/src/zkvm.rs index 3eca5c07f5e6..c816145b7654 100644 --- a/library/panic_abort/src/zkvm.rs +++ b/library/panic_abort/src/zkvm.rs @@ -1,24 +1,9 @@ -// use alloc::string::String; use core::panic::PanicPayload; pub(crate) unsafe fn zkvm_set_abort_message(_payload: &mut dyn PanicPayload) { - // TODO: fix + extern "C" { + fn jolt_panic() -> !; + } - // let payload = payload.get(); - // let msg = match payload.downcast_ref::<&'static str>() { - // Some(msg) => msg.as_bytes(), - // None => match payload.downcast_ref::() { - // Some(msg) => msg.as_bytes(), - // None => &[], - // }, - // }; - // if msg.is_empty() { - // return; - // } - - // extern "C" { - // fn sys_panic(msg_ptr: *const u8, len: usize) -> !; - // } - - // sys_panic(msg.as_ptr(), msg.len()); + jolt_panic() } From 5d3808c38d15f7d3fbd529ce49dead7589efd745 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Wed, 17 Apr 2024 02:02:35 +0100 Subject: [PATCH 08/18] add makefile --- .gitignore | 1 - Makefile | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index ce51bdb05a48..de53237ef284 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,6 @@ Session.vim !/tests/run-make/thumb-none-qemu/example/.cargo ## Configuration -/Makefile config.mk config.stamp no_llvm_build diff --git a/Makefile b/Makefile new file mode 100644 index 000000000000..ef3de5bd60a5 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +build-toolchain: + CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" ./x build + CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" ./x build --stage 2 + +install-toolchain: + rustup toolchain link riscv32i-jolt-zkvm-elf build/host/stage2 + +build-install-toolchain: + make build-toolchain + make install-toolchain From f3b8665d7794601c400f8f939d9e2295b11800f2 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Wed, 17 Apr 2024 10:09:37 +0100 Subject: [PATCH 09/18] add archive make command --- .gitignore | 3 ++- Makefile | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index de53237ef284..061cab6e3e34 100644 --- a/.gitignore +++ b/.gitignore @@ -77,4 +77,5 @@ package.json ## Rustdoc GUI tests tests/rustdoc-gui/src/**.lock -# Before adding new lines, see the comment at the top. +# Arhive +toolchain.tar.gz diff --git a/Makefile b/Makefile index ef3de5bd60a5..db71eb310147 100644 --- a/Makefile +++ b/Makefile @@ -8,3 +8,6 @@ install-toolchain: build-install-toolchain: make build-toolchain make install-toolchain + +archive: + tar -czvf toolchain.tar.gz build/host/stage2 From b67f49070eac0db7664a8d7dbb0bb8e87d2d590a Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Thu, 18 Apr 2024 11:05:25 -0400 Subject: [PATCH 10/18] add build ci (#4) * add ci * run on pr * specify branch * use ref * fix repo name * use nightly toolchain * use cargo native static * fix ci build * do a bad bad thing * remove stage 2 ci check * use ci branch * add release * disable gh action env * fix * fix archive * fix ubuntu runner * finalize --- .github/workflows/ci.yml | 240 ----------------------------- .github/workflows/dependencies.yml | 148 ------------------ .github/workflows/release.yml | 64 ++++++++ Makefile | 4 +- config.toml | 1 + 5 files changed, 67 insertions(+), 390 deletions(-) delete mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/dependencies.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 8032154a7365..000000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,240 +0,0 @@ -# This file defines our primary CI workflow that runs on pull requests -# and also on pushes to special branches (auto, try). -# -# The actual definition of the executed jobs is calculated by a Python -# script located at src/ci/github-actions/calculate-job-matrix.py, which -# uses job definition data from src/ci/github-actions/jobs.yml. -# You should primarily modify the `jobs.yml` file if you want to modify -# what jobs are executed in CI. - -name: CI -on: - push: - branches: - - auto - - try - - try-perf - - automation/bors/try - pull_request: - branches: - - "**" - -permissions: - contents: read - packages: write - -defaults: - run: - # On Linux, macOS, and Windows, use the system-provided bash as the default - # shell. (This should only make a difference on Windows, where the default - # shell is PowerShell.) - shell: bash - -concurrency: - # For a given workflow, if we push to the same branch, cancel all previous builds on that branch. - # We add an exception for try builds (try branch) and unrolled rollup builds (try-perf), which - # are all triggered on the same branch, but which should be able to run concurrently. - group: ${{ github.workflow }}-${{ ((github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.sha) || github.ref }} - cancel-in-progress: true -env: - TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" - # This will be empty in PR jobs. - TOOLSTATE_REPO_ACCESS_TOKEN: ${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }} -jobs: - # The job matrix for `calculate_matrix` is defined in src/ci/github-actions/jobs.yml. - # It calculates which jobs should be executed, based on the data of the ${{ github }} context. - # If you want to modify CI jobs, take a look at src/ci/github-actions/jobs.yml. - calculate_matrix: - name: Calculate job matrix - runs-on: ubuntu-latest - outputs: - jobs: ${{ steps.jobs.outputs.jobs }} - run_type: ${{ steps.jobs.outputs.run_type }} - steps: - - name: Checkout the source code - uses: actions/checkout@v4 - - name: Calculate the CI job matrix - env: - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} - run: python3 src/ci/github-actions/calculate-job-matrix.py >> $GITHUB_OUTPUT - id: jobs - job: - name: ${{ matrix.name }} - needs: [ calculate_matrix ] - runs-on: "${{ matrix.os }}" - defaults: - run: - shell: ${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }} - timeout-minutes: 240 - env: - CI_JOB_NAME: ${{ matrix.image }} - CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - # commit of PR sha or commit sha. `GITHUB_SHA` is not accurate for PRs. - HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }} - DOCKER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SCCACHE_BUCKET: rust-lang-ci-sccache2 - CACHE_DOMAIN: ci-caches.rust-lang.org - continue-on-error: ${{ matrix.continue_on_error || false }} - strategy: - matrix: - # Check the `calculate_matrix` job to see how is the matrix defined. - include: ${{ fromJSON(needs.calculate_matrix.outputs.jobs) }} - steps: - - if: contains(matrix.os, 'windows') - uses: msys2/setup-msys2@v2.22.0 - with: - # i686 jobs use mingw32. x86_64 and cross-compile jobs use mingw64. - msystem: ${{ contains(matrix.name, 'i686') && 'mingw32' || 'mingw64' }} - # don't try to download updates for already installed packages - update: false - # don't try to use the msys that comes built-in to the github runner, - # so we can control what is installed (i.e. not python) - release: true - # Inherit the full path from the Windows environment, with MSYS2's */bin/ - # dirs placed in front. This lets us run Windows-native Python etc. - path-type: inherit - install: > - make - - - name: disable git crlf conversion - run: git config --global core.autocrlf false - - - name: checkout the source code - uses: actions/checkout@v4 - with: - fetch-depth: 2 - - # Rust Log Analyzer can't currently detect the PR number of a GitHub - # Actions build on its own, so a hint in the log message is needed to - # point it in the right direction. - - name: configure the PR in which the error message will be posted - run: echo "[CI_PR_NUMBER=$num]" - env: - num: ${{ github.event.number }} - if: needs.calculate_matrix.outputs.run_type == 'pr' - - - name: add extra environment variables - run: src/ci/scripts/setup-environment.sh - env: - # Since it's not possible to merge `${{ matrix.env }}` with the other - # variables in `job..env`, the variables defined in the matrix - # are passed to the `setup-environment.sh` script encoded in JSON, - # which then uses log commands to actually set them. - EXTRA_VARIABLES: ${{ toJson(matrix.env) }} - - - name: ensure the channel matches the target branch - run: src/ci/scripts/verify-channel.sh - - - name: collect CPU statistics - run: src/ci/scripts/collect-cpu-stats.sh - - - name: show the current environment - run: src/ci/scripts/dump-environment.sh - - - name: install awscli - run: src/ci/scripts/install-awscli.sh - - - name: install sccache - run: src/ci/scripts/install-sccache.sh - - - name: select Xcode - run: src/ci/scripts/select-xcode.sh - - - name: install clang - run: src/ci/scripts/install-clang.sh - - - name: install tidy - run: src/ci/scripts/install-tidy.sh - - - name: install WIX - run: src/ci/scripts/install-wix.sh - - - name: disable git crlf conversion - run: src/ci/scripts/disable-git-crlf-conversion.sh - - - name: checkout submodules - run: src/ci/scripts/checkout-submodules.sh - - - name: install MinGW - run: src/ci/scripts/install-mingw.sh - - - name: install ninja - run: src/ci/scripts/install-ninja.sh - - - name: enable ipv6 on Docker - run: src/ci/scripts/enable-docker-ipv6.sh - - # Disable automatic line ending conversion (again). On Windows, when we're - # installing dependencies, something switches the git configuration directory or - # re-enables autocrlf. We've not tracked down the exact cause -- and there may - # be multiple -- but this should ensure submodules are checked out with the - # appropriate line endings. - - name: disable git crlf conversion - run: src/ci/scripts/disable-git-crlf-conversion.sh - - - name: ensure line endings are correct - run: src/ci/scripts/verify-line-endings.sh - - - name: ensure backported commits are in upstream branches - run: src/ci/scripts/verify-backported-commits.sh - - - name: ensure the stable version number is correct - run: src/ci/scripts/verify-stable-version-number.sh - - - name: run the build - # Redirect stderr to stdout to avoid reordering the two streams in the GHA logs. - run: src/ci/scripts/run-build-from-ci.sh 2>&1 - env: - AWS_ACCESS_KEY_ID: ${{ env.CACHES_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }} - - - name: create github artifacts - run: src/ci/scripts/create-doc-artifacts.sh - - - name: upload artifacts to github - uses: actions/upload-artifact@v4 - with: - # name is set in previous step - name: ${{ env.DOC_ARTIFACT_NAME }} - path: obj/artifacts/doc - if-no-files-found: ignore - retention-days: 5 - - - name: upload artifacts to S3 - run: src/ci/scripts/upload-artifacts.sh - env: - AWS_ACCESS_KEY_ID: ${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }} - # Adding a condition on DEPLOY=1 or DEPLOY_ALT=1 is not needed as all deploy - # builders *should* have the AWS credentials available. Still, explicitly - # adding the condition is helpful as this way CI will not silently skip - # deploying artifacts from a dist builder if the variables are misconfigured, - # erroring about invalid credentials instead. - if: github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1' - - # This job isused to tell bors the final status of the build, as there is no practical way to detect - # when a workflow is successful listening to webhooks only in our current bors implementation (homu). - outcome: - name: bors build finished - runs-on: ubuntu-latest - needs: [ calculate_matrix, job ] - # !cancelled() executes the job regardless of whether the previous jobs passed or failed - if: ${{ !cancelled() && contains(fromJSON('["auto", "try"]'), needs.calculate_matrix.outputs.run_type) }} - steps: - - name: checkout the source code - uses: actions/checkout@v4 - with: - fetch-depth: 2 - # Calculate the exit status of the whole CI workflow. - # If all dependent jobs were successful, this exits with 0 (and the outcome job continues successfully). - # If a some dependent job has failed, this exits with 1. - - name: calculate the correct exit status - run: jq --exit-status 'all(.result == "success" or .result == "skipped")' <<< '${{ toJson(needs) }}' - # Publish the toolstate if an auto build succeeds (just before push to master) - - name: publish toolstate - run: src/ci/publish_toolstate.sh - shell: bash - if: needs.calculate_matrix.outputs.run_type == 'auto' - env: - TOOLSTATE_ISSUES_API_URL: https://api.github.com/repos/rust-lang/rust/issues - TOOLSTATE_PUBLISH: 1 diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml deleted file mode 100644 index b137497594f2..000000000000 --- a/.github/workflows/dependencies.yml +++ /dev/null @@ -1,148 +0,0 @@ -# Automatically run `cargo update` periodically - ---- -name: Bump dependencies in Cargo.lock -on: - schedule: - # Run weekly - - cron: '0 0 * * Sun' - workflow_dispatch: - # Needed so we can run it manually -permissions: - contents: read -defaults: - run: - shell: bash -env: - # So cargo doesn't complain about unstable features - RUSTC_BOOTSTRAP: 1 - PR_TITLE: Weekly `cargo update` - PR_MESSAGE: | - Automation to keep dependencies in `Cargo.lock` current. - - The following is the output from `cargo update`: - COMMIT_MESSAGE: "cargo update \n\n" - -jobs: - not-waiting-on-bors: - if: github.repository_owner == 'rust-lang' - name: skip if S-waiting-on-bors - runs-on: ubuntu-latest - steps: - - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # Fetch state and labels of PR - # Or exit successfully if PR does not exist - JSON=$(gh pr view cargo_update --repo $GITHUB_REPOSITORY --json labels,state || exit 0) - STATE=$(echo "$JSON" | jq -r '.state') - WAITING_ON_BORS=$(echo "$JSON" | jq '.labels[] | any(.name == "S-waiting-on-bors"; .)') - - # Exit with error if open and S-waiting-on-bors - if [[ "$STATE" == "OPEN" && "$WAITING_ON_BORS" == "true" ]]; then - exit 1 - fi - - update: - if: github.repository_owner == 'rust-lang' - name: update dependencies - needs: not-waiting-on-bors - runs-on: ubuntu-latest - steps: - - name: checkout the source code - uses: actions/checkout@v4 - with: - submodules: recursive - - name: install the bootstrap toolchain - run: | - # Extract the stage0 version - TOOLCHAIN=$(awk -F= '{a[$1]=$2} END {print(a["compiler_version"] "-" a["compiler_date"])}' src/stage0) - # Install and set as default - rustup toolchain install --no-self-update --profile minimal $TOOLCHAIN - rustup default $TOOLCHAIN - - - name: cargo update - # Remove first line that always just says "Updating crates.io index" - run: cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log - - name: cargo update rustbook - run: | - echo -e "\nrustbook dependencies:" >> cargo_update.log - cargo update --manifest-path src/tools/rustbook 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log - - name: upload Cargo.lock artifact for use in PR - uses: actions/upload-artifact@v4 - with: - name: Cargo-lock - path: | - Cargo.lock - src/tools/rustbook/Cargo.lock - retention-days: 1 - - name: upload cargo-update log artifact for use in PR - uses: actions/upload-artifact@v4 - with: - name: cargo-updates - path: cargo_update.log - retention-days: 1 - - pr: - if: github.repository_owner == 'rust-lang' - name: amend PR - needs: update - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - steps: - - name: checkout the source code - uses: actions/checkout@v4 - - - name: download Cargo.lock from update job - uses: actions/download-artifact@v4 - with: - name: Cargo-lock - - name: download cargo-update log from update job - uses: actions/download-artifact@v4 - with: - name: cargo-updates - - - name: craft PR body and commit message - run: | - echo "${COMMIT_MESSAGE}" > commit.txt - cat cargo_update.log >> commit.txt - - echo "${PR_MESSAGE}" > body.md - echo '```txt' >> body.md - cat cargo_update.log >> body.md - echo '```' >> body.md - - - name: commit - run: | - git config user.name github-actions - git config user.email github-actions@github.com - git switch --force-create cargo_update - git add ./Cargo.lock ./src/tools/rustbook/Cargo.lock - git commit --no-verify --file=commit.txt - - - name: push - run: git push --no-verify --force --set-upstream origin cargo_update - - - name: edit existing open pull request - id: edit - # Don't fail job if we need to open new PR - continue-on-error: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # Exit with error if PR is closed - STATE=$(gh pr view cargo_update --repo $GITHUB_REPOSITORY --json state --jq '.state') - if [[ "$STATE" != "OPEN" ]]; then - exit 1 - fi - - gh pr edit cargo_update --title "${PR_TITLE}" --body-file body.md --repo $GITHUB_REPOSITORY - - - name: open new pull request - # Only run if there wasn't an existing PR - if: steps.edit.outcome != 'success' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh pr create --title "${PR_TITLE}" --body-file body.md --repo $GITHUB_REPOSITORY diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000000..2ec22f2f0626 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,64 @@ +name: release + +on: + workflow_call: + workflow_dispatch: + +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - os: macos-14 + triple: aarch64-apple-darwin + - os: macos-13 + triple: x86_64-apple-darwin + - os: ubuntu-latest + triple: x86_64-unknown-linux-gnu + runs-on: ${{ matrix.os }} + steps: + - name: Install nightly toolchain + id: rustc-toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly-2024-01-25 + default: true + + - uses: lukka/get-cmake@v3.27.4 + + - name: Show rust version + run: | + cargo version + rustup toolchain list + + - name: Check out a16z/rust + uses: actions/checkout@v3 + with: + repository: a16z/rust + submodules: "recursive" + path: rust + fetch-depth: 0 + ref: jolt + + - name: Build + run: make build-toolchain + working-directory: rust + + - name: Archive + run: tar -czvf rust-toolchain-${{ matrix.triple }}.tar.gz rust/build/host/stage2 + + - name: Generate tag name + id: tag + run: | + echo "::set-output name=release_tag::nightly-${GITHUB_SHA}" + + - name: Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ steps.tag.outputs.release_tag }} + prerelease: true + files: | + rust-toolchain-${{ matrix.triple }}.tar.gz + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile index db71eb310147..c9683964f26e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ build-toolchain: - CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" ./x build - CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" ./x build --stage 2 + GITHUB_ACTIONS=false CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" ./x build + GITHUB_ACTIONS=false CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" ./x build --stage 2 install-toolchain: rustup toolchain link riscv32i-jolt-zkvm-elf build/host/stage2 diff --git a/config.toml b/config.toml index cc954b2c2349..7f24cb0cb2ec 100644 --- a/config.toml +++ b/config.toml @@ -12,3 +12,4 @@ llvm-tools = true [llvm] download-ci-llvm = false + From 11070d6af08909f1c503194fe006627aa8cf73d8 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Fri, 19 Apr 2024 20:46:24 +0100 Subject: [PATCH 11/18] use externally defined allocator --- library/std/src/sys/pal/zkvm/abi.rs | 2 +- library/std/src/sys/pal/zkvm/alloc.rs | 46 ++------------------------- 2 files changed, 4 insertions(+), 44 deletions(-) diff --git a/library/std/src/sys/pal/zkvm/abi.rs b/library/std/src/sys/pal/zkvm/abi.rs index 2c73268f5556..e0a4d990c5c5 100644 --- a/library/std/src/sys/pal/zkvm/abi.rs +++ b/library/std/src/sys/pal/zkvm/abi.rs @@ -1,3 +1,3 @@ extern "C" { - pub static _HEAP_PTR: u8; + pub fn sys_alloc(size: usize, align: usize) -> *mut u8; } diff --git a/library/std/src/sys/pal/zkvm/alloc.rs b/library/std/src/sys/pal/zkvm/alloc.rs index 76fe1212841c..56904d4dbc23 100644 --- a/library/std/src/sys/pal/zkvm/alloc.rs +++ b/library/std/src/sys/pal/zkvm/alloc.rs @@ -1,51 +1,11 @@ -use crate::{alloc::{GlobalAlloc, Layout, System}, cell::UnsafeCell}; -use super::abi::_HEAP_PTR; - -static mut BUMP_ALLOC: BumpAllocator = BumpAllocator::new(); +use crate::alloc::{GlobalAlloc, Layout, System}; +use super::abi::sys_alloc; #[stable(feature = "alloc_system_type", since = "1.28.0")] unsafe impl GlobalAlloc for System { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - BUMP_ALLOC.alloc(layout) - } - - unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} -} - -pub struct BumpAllocator { - offset: UnsafeCell, -} - -impl BumpAllocator { - pub const fn new() -> Self { - Self { - offset: UnsafeCell::new(0), - } - } - - pub fn free_memory(&self) -> usize { - heap_start() + (self.offset.get() as usize) - } -} - -unsafe impl GlobalAlloc for BumpAllocator { - unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - let alloc_start = align_up(self.free_memory(), layout.align()); - let alloc_end = alloc_start + layout.size(); - *self.offset.get() = alloc_end - self.free_memory(); - - alloc_start as *mut u8 + sys_alloc(layout.size(), layout.align()) } unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} } - -unsafe impl Sync for BumpAllocator {} - -fn align_up(addr: usize, align: usize) -> usize { - (addr + align - 1) & !(align - 1) -} - -fn heap_start() -> usize { - unsafe { _HEAP_PTR as *const u8 as usize } -} From 6338555c7ececc29520c9e3a68e5aea8d65bd430 Mon Sep 17 00:00:00 2001 From: Michael Zhu Date: Mon, 5 Aug 2024 14:10:49 -0400 Subject: [PATCH 12/18] Fix build --- .github/workflows/release.yml | 2 +- Makefile | 4 ++-- config.toml | 3 +-- library/std/src/sys/pal/zkvm/alloc.rs | 4 ++-- src/bootstrap/src/core/sanity.rs | 8 ++++---- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2ec22f2f0626..c85961928020 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: id: rustc-toolchain uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2024-01-25 + toolchain: nightly-2024-07-30 default: true - uses: lukka/get-cmake@v3.27.4 diff --git a/Makefile b/Makefile index c9683964f26e..88f0b3a560d9 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ build-toolchain: - GITHUB_ACTIONS=false CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" ./x build - GITHUB_ACTIONS=false CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=loweratomic" ./x build --stage 2 + GITHUB_ACTIONS=false CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=lower-atomic" ./x build + GITHUB_ACTIONS=false CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=lower-atomic" ./x build --stage 2 install-toolchain: rustup toolchain link riscv32i-jolt-zkvm-elf build/host/stage2 diff --git a/config.toml b/config.toml index 7f24cb0cb2ec..c5f472d0f2b9 100644 --- a/config.toml +++ b/config.toml @@ -1,4 +1,4 @@ -changelog-seen = 2 +change-id = 125181 [build] target = ["riscv32i-jolt-zkvm-elf"] @@ -12,4 +12,3 @@ llvm-tools = true [llvm] download-ci-llvm = false - diff --git a/library/std/src/sys/pal/zkvm/alloc.rs b/library/std/src/sys/pal/zkvm/alloc.rs index 56904d4dbc23..e73af293109d 100644 --- a/library/std/src/sys/pal/zkvm/alloc.rs +++ b/library/std/src/sys/pal/zkvm/alloc.rs @@ -1,10 +1,10 @@ -use crate::alloc::{GlobalAlloc, Layout, System}; use super::abi::sys_alloc; +use crate::alloc::{GlobalAlloc, Layout, System}; #[stable(feature = "alloc_system_type", since = "1.28.0")] unsafe impl GlobalAlloc for System { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - sys_alloc(layout.size(), layout.align()) + unsafe { sys_alloc(layout.size(), layout.align()) } } unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 45f4090ef228..5ddd057d3e55 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -274,10 +274,10 @@ than building it. } if !has_target { - panic!( - "No such target exists in the target list, - specify a correct location of the JSON specification file for custom targets!" - ); + // panic!( + // "No such target exists in the target list, + // specify a correct location of the JSON specification file for custom targets!" + // ); } } From 006734406d6be3154b20cf9aed7f29532c4511a0 Mon Sep 17 00:00:00 2001 From: Michael Zhu Date: Tue, 6 Aug 2024 10:06:25 -0400 Subject: [PATCH 13/18] God, are you there? --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c85961928020..03f534f7f21b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: id: rustc-toolchain uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2024-07-30 + toolchain: nightly-2024-08-01 default: true - uses: lukka/get-cmake@v3.27.4 From 140fc9ae4f28956ae704bcd91755e75937d98153 Mon Sep 17 00:00:00 2001 From: Michael Zhu Date: Tue, 6 Aug 2024 12:40:43 -0400 Subject: [PATCH 14/18] Fix checkout --- .github/workflows/release.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 03f534f7f21b..a33cf93d382d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,13 +33,11 @@ jobs: rustup toolchain list - name: Check out a16z/rust - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: - repository: a16z/rust submodules: "recursive" path: rust fetch-depth: 0 - ref: jolt - name: Build run: make build-toolchain From e1f7f2bced08d7f582e0fe747372dca74310f346 Mon Sep 17 00:00:00 2001 From: Michael Zhu Date: Thu, 8 Aug 2024 20:00:28 -0400 Subject: [PATCH 15/18] Reduce space usage --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a33cf93d382d..5bfbd0eb880c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,7 +37,6 @@ jobs: with: submodules: "recursive" path: rust - fetch-depth: 0 - name: Build run: make build-toolchain From 8af9d45d5e09a04832cc9b2e1df993fd1ce49d02 Mon Sep 17 00:00:00 2001 From: Michael Zhu Date: Fri, 9 Aug 2024 11:18:23 -0400 Subject: [PATCH 16/18] feat: enable m extension (#5) (#8) * feat: add m extension * chore: rename target Co-authored-by: Noah Citron --- Makefile | 6 +++--- compiler/rustc_target/src/spec/mod.rs | 2 +- ...riscv32i_jolt_zkvm_elf.rs => riscv32im_jolt_zkvm_elf.rs} | 1 + config.toml | 2 +- src/tools/build-manifest/src/main.rs | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) rename compiler/rustc_target/src/spec/targets/{riscv32i_jolt_zkvm_elf.rs => riscv32im_jolt_zkvm_elf.rs} (97%) diff --git a/Makefile b/Makefile index 88f0b3a560d9..d262975f836d 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ build-toolchain: - GITHUB_ACTIONS=false CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=lower-atomic" ./x build - GITHUB_ACTIONS=false CARGO_TARGET_RISCV32I_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=lower-atomic" ./x build --stage 2 + GITHUB_ACTIONS=false CARGO_TARGET_RISCV32IM_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=lower-atomic" ./x build + GITHUB_ACTIONS=false CARGO_TARGET_RISCV32IM_JOLT_ZKVM_ELF_RUSTFLAGS="-Cpasses=lower-atomic" ./x build --stage 2 install-toolchain: - rustup toolchain link riscv32i-jolt-zkvm-elf build/host/stage2 + rustup toolchain link riscv32im-jolt-zkvm-elf build/host/stage2 build-install-toolchain: make build-toolchain diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index fbf998d6f5b1..68727d8b7718 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1751,7 +1751,7 @@ supported_targets! { ("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf), ("riscv32im-risc0-zkvm-elf", riscv32im_risc0_zkvm_elf), - ("riscv32i-jolt-zkvm-elf", riscv32i_jolt_zkvm_elf), + ("riscv32im-jolt-zkvm-elf", riscv32im_jolt_zkvm_elf), ("riscv32im-unknown-none-elf", riscv32im_unknown_none_elf), ("riscv32ima-unknown-none-elf", riscv32ima_unknown_none_elf), ("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf), diff --git a/compiler/rustc_target/src/spec/targets/riscv32i_jolt_zkvm_elf.rs b/compiler/rustc_target/src/spec/targets/riscv32im_jolt_zkvm_elf.rs similarity index 97% rename from compiler/rustc_target/src/spec/targets/riscv32i_jolt_zkvm_elf.rs rename to compiler/rustc_target/src/spec/targets/riscv32im_jolt_zkvm_elf.rs index 783b9a744a10..2b1c3b455665 100644 --- a/compiler/rustc_target/src/spec/targets/riscv32i_jolt_zkvm_elf.rs +++ b/compiler/rustc_target/src/spec/targets/riscv32im_jolt_zkvm_elf.rs @@ -21,6 +21,7 @@ pub fn target() -> Target { linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), linker: Some("rust-lld".into()), cpu: "generic-rv32".into(), + features: "+m".into(), max_atomic_width: Some(64), atomic_cas: true, executables: true, diff --git a/config.toml b/config.toml index c5f472d0f2b9..4f36f169c8a1 100644 --- a/config.toml +++ b/config.toml @@ -1,7 +1,7 @@ change-id = 125181 [build] -target = ["riscv32i-jolt-zkvm-elf"] +target = ["riscv32im-jolt-zkvm-elf"] extended = true tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"] configure-args = [] diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index c79c4a5dc3c5..ca08f4954f0b 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -131,7 +131,7 @@ static TARGETS: &[&str] = &[ "powerpc64le-unknown-linux-gnu", "riscv32i-unknown-none-elf", "riscv32im-risc0-zkvm-elf", - "riscv32i-jolt-zkvm-elf", + "riscv32im-jolt-zkvm-elf", "riscv32im-unknown-none-elf", "riscv32ima-unknown-none-elf", "riscv32imc-unknown-none-elf", From c45196e53674f032dffe6083a2fbfc3e6b000631 Mon Sep 17 00:00:00 2001 From: Michael Zhu Date: Fri, 9 Aug 2024 13:07:09 -0400 Subject: [PATCH 17/18] typo --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 061cab6e3e34..84551cf0ccee 100644 --- a/.gitignore +++ b/.gitignore @@ -77,5 +77,5 @@ package.json ## Rustdoc GUI tests tests/rustdoc-gui/src/**.lock -# Arhive +# Archive toolchain.tar.gz From 0e2f5a6fb8e406c145144721426d75d0cd9553ca Mon Sep 17 00:00:00 2001 From: Will Papper Date: Fri, 22 Nov 2024 18:11:49 +0100 Subject: [PATCH 18/18] chore: Update toolchain to nightly-2024-09-30 (#10) This matches the toolchain used by Jolt in this PR: https://github.com/a16z/jolt/pull/510 The compiler is updated to align with features used by Binius (in particular the use of `iter::repeat_n`) --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5bfbd0eb880c..82f01f3f09f2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: id: rustc-toolchain uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2024-08-01 + toolchain: nightly-2024-09-30 default: true - uses: lukka/get-cmake@v3.27.4