forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
add riscv32im-unknown-openvm-elf as tier 3 target #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
arayikhalatyan
wants to merge
7
commits into
master
Choose a base branch
from
feat/rv32im-unknown-openvm-elf
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
20614c8
add riscv32im-unknown-openvm-elf tier 3 target
arayikhalatyan 0bd4f94
update platform doc
arayikhalatyan 5b5e109
feat(docs): update target docs (#2)
jonathanpwang 31e7b80
reviewer comments
arayikhalatyan 512959b
rebase fixes
arayikhalatyan d6a46ad
Fix test stderr
arayikhalatyan b8f847e
fix cfg-crate-features.stderr
arayikhalatyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
compiler/rustc_target/src/spec/targets/riscv32im_unknown_openvm_elf.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| use crate::spec::{ | ||
| Arch, Cc, LinkerFlavor, Lld, Os, PanicStrategy, RelocModel, Target, TargetMetadata, | ||
| TargetOptions, | ||
| }; | ||
|
|
||
| pub(crate) fn target() -> Target { | ||
| Target { | ||
| data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(), | ||
| llvm_target: "riscv32".into(), | ||
| metadata: TargetMetadata { | ||
| description: Some("OpenVM zero-knowledge Virtual Machine (RV32IM ISA)".into()), | ||
| tier: Some(3), | ||
| host_tools: Some(false), | ||
| std: Some(true), | ||
| }, | ||
| pointer_width: 32, | ||
| arch: Arch::RiscV32, | ||
|
|
||
| options: TargetOptions { | ||
| os: Os::Openvm, | ||
| vendor: "unknown".into(), | ||
| linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), | ||
| linker: Some("rust-lld".into()), | ||
| cpu: "generic-rv32".into(), | ||
|
|
||
| // We set atomic_width to 64 for compatibility with crates such as crossbeam, | ||
| // but this should never be triggered since compilation should always lower | ||
| // atomics and be single-threaded. | ||
| max_atomic_width: Some(64), | ||
| atomic_cas: true, | ||
|
|
||
| features: "+m".into(), | ||
| llvm_abiname: "ilp32".into(), | ||
| executables: true, | ||
| panic_strategy: PanicStrategy::Abort, | ||
| relocation_model: RelocModel::Static, | ||
| emit_debug_gdb_scripts: false, | ||
| eh_frame_header: false, | ||
| singlethread: true, | ||
| ..Default::default() | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| use alloc::string::String; | ||
| use core::panic::PanicPayload; | ||
|
|
||
| // Forward the abort message to OpenVM's sys_panic. | ||
| pub(crate) unsafe fn openvm_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::<String>() { | ||
| Some(msg) => msg.as_bytes(), | ||
| None => &[], | ||
| }, | ||
| }; | ||
| if msg.is_empty() { | ||
| return; | ||
| } | ||
|
|
||
| unsafe extern "C" { | ||
| fn sys_panic(msg_ptr: *const u8, len: usize) -> !; | ||
| } | ||
|
|
||
| unsafe { | ||
| sys_panic(msg.as_ptr(), msg.len()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| use crate::alloc::{GlobalAlloc, Layout, System}; | ||
| use crate::sys::pal::abi; | ||
|
|
||
| #[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()) } | ||
| } | ||
|
|
||
| #[inline] | ||
| unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) { | ||
| // this allocator never deallocates memory | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| use crate::ffi::{OsStr, OsString}; | ||
| use crate::num::NonZero; | ||
| use crate::sync::OnceLock; | ||
| use crate::sys::pal::{WORD_SIZE, abi}; | ||
| use crate::{fmt, ptr, slice}; | ||
|
|
||
| pub fn args() -> Args { | ||
| Args { iter: ARGS.get_or_init(|| get_args()).iter() } | ||
| } | ||
|
|
||
| fn get_args() -> Vec<&'static OsStr> { | ||
| let argc = unsafe { abi::sys_argc() }; | ||
| let mut args = Vec::with_capacity(argc); | ||
|
|
||
| for i in 0..argc { | ||
| // Get the size of the argument then the data. | ||
| let arg_len = unsafe { abi::sys_argv(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); | ||
|
|
||
| let arg_bytes = unsafe { slice::from_raw_parts(words.cast(), arg_len) }; | ||
| args.push(unsafe { OsStr::from_encoded_bytes_unchecked(arg_bytes) }); | ||
| } | ||
| args | ||
| } | ||
|
|
||
| static ARGS: OnceLock<Vec<&'static OsStr>> = OnceLock::new(); | ||
|
|
||
| pub struct Args { | ||
| iter: slice::Iter<'static, &'static OsStr>, | ||
| } | ||
|
|
||
| impl !Send for Args {} | ||
| impl !Sync for Args {} | ||
|
|
||
| impl fmt::Debug for Args { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| self.iter.as_slice().fmt(f) | ||
| } | ||
| } | ||
|
|
||
| impl Iterator for Args { | ||
| type Item = OsString; | ||
|
|
||
| fn next(&mut self) -> Option<OsString> { | ||
| self.iter.next().map(|arg| arg.to_os_string()) | ||
| } | ||
|
|
||
| #[inline] | ||
| fn size_hint(&self) -> (usize, Option<usize>) { | ||
| self.iter.size_hint() | ||
| } | ||
|
|
||
| #[inline] | ||
| fn count(self) -> usize { | ||
| self.iter.len() | ||
| } | ||
|
|
||
| fn last(self) -> Option<OsString> { | ||
| self.iter.last().map(|arg| arg.to_os_string()) | ||
| } | ||
|
|
||
| #[inline] | ||
| fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> { | ||
| self.iter.advance_by(n) | ||
| } | ||
| } | ||
|
|
||
| impl DoubleEndedIterator for Args { | ||
| fn next_back(&mut self) -> Option<OsString> { | ||
| self.iter.next_back().map(|arg| arg.to_os_string()) | ||
| } | ||
|
|
||
| #[inline] | ||
| fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> { | ||
| self.iter.advance_back_by(n) | ||
| } | ||
| } | ||
|
|
||
| impl ExactSizeIterator for Args { | ||
| #[inline] | ||
| fn len(&self) -> usize { | ||
| self.iter.len() | ||
| } | ||
|
|
||
| #[inline] | ||
| fn is_empty(&self) -> bool { | ||
| self.iter.is_empty() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #[expect(dead_code)] | ||
| #[path = "unsupported.rs"] | ||
| mod unsupported_env; | ||
| pub use unsupported_env::{Env, env, setenv, unsetenv}; | ||
|
|
||
| use crate::ffi::{OsStr, OsString}; | ||
| use crate::sys::os_str; | ||
| use crate::sys::pal::{WORD_SIZE, abi}; | ||
| use crate::sys_common::FromInner; | ||
|
|
||
| pub fn getenv(varname: &OsStr) -> Option<OsString> { | ||
| 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. | ||
| 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() })) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //! ABI definitions for symbols exported by OpenVM. | ||
|
|
||
| // We provide the ABI so that the OpenVM-specific implementations can be provided | ||
| // by linking the openvm crate without introducing the crate as a dependency here | ||
| #![allow(dead_code)] | ||
|
|
||
| /// 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; | ||
| } | ||
|
|
||
| unsafe extern "C" { | ||
| // Wrappers around syscalls provided by OpenVM: | ||
| pub fn sys_halt(); | ||
| 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_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; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to import from the pal/abi or is this needed even with no_std?
if so we should actually make sure in openvm we always make this extern even without the feature flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good point. Yes, it's needed with no_std.