Skip to content

Commit

Permalink
Auto merge of rust-lang#65167 - hermitcore:rusty-hermit, r=alexcrichton
Browse files Browse the repository at this point in the history
Redesign the interface to the unikernel HermitCore

We are developing the unikernel HermitCore, where the kernel is written in Rust and is already part of the Rust Standard Library. The interface between the standard library and the kernel based on a small C library. With this pull request, we remove completely the dependency to C and use lld as linker. Currently, the kernel will be linked to the application as static library, which is published at https://github.com/hermitcore/libhermit-rs.

We don’t longer support the C interface to the kernel. Consequently, we remove this part from the Rust Standard Library.
  • Loading branch information
bors committed Oct 26, 2019
2 parents 46e6c53 + 805a330 commit fae75cd
Show file tree
Hide file tree
Showing 51 changed files with 2,322 additions and 450 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,17 @@ dependencies = [
"unicode-segmentation",
]

[[package]]
name = "hermit-abi"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f22b8f315b98f415780ddbe9163c7dbbc5a07225b6d102ace1d8aeef85775140"
dependencies = [
"compiler_builtins",
"libc",
"rustc-std-workspace-core",
]

[[package]]
name = "hex"
version = "0.3.2"
Expand Down Expand Up @@ -4159,6 +4170,7 @@ dependencies = [
"dlmalloc",
"fortanix-sgx-abi",
"hashbrown 0.6.2",
"hermit-abi",
"libc",
"panic_abort",
"panic_unwind",
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ mod job {
}
}

#[cfg(any(target_os = "haiku", not(any(unix, windows))))]
#[cfg(any(target_os = "haiku", target_os = "hermit", not(any(unix, windows))))]
mod job {
pub unsafe fn setup(_build: &mut crate::Build) {
}
Expand Down
3 changes: 2 additions & 1 deletion src/libpanic_abort/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ pub unsafe extern fn __rust_start_panic(_payload: usize) -> u32 {
core::intrinsics::abort();
}

#[cfg(all(target_vendor="fortanix", target_env="sgx"))]
#[cfg(any(target_os = "hermit",
all(target_vendor="fortanix", target_env="sgx")))]
unsafe fn abort() -> ! {
// call std::sys::abort_internal
extern "C" { pub fn __rust_abort() -> !; }
Expand Down
21 changes: 21 additions & 0 deletions src/libpanic_unwind/hermit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Unwinding for *hermit* target.
//!
//! Right now we don't support this, so this is just stubs.

use alloc::boxed::Box;
use core::ptr;
use core::any::Any;

pub fn payload() -> *mut u8 {
ptr::null_mut()
}

pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
extern "C" { pub fn __rust_abort() -> !; }
__rust_abort();
}

pub unsafe fn panic(_data: Box<dyn Any + Send>) -> u32 {
extern "C" { pub fn __rust_abort() -> !; }
__rust_abort();
}
3 changes: 3 additions & 0 deletions src/libpanic_unwind/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ cfg_if::cfg_if! {
} else if #[cfg(target_arch = "wasm32")] {
#[path = "dummy.rs"]
mod imp;
} else if #[cfg(target_os = "hermit")] {
#[path = "hermit.rs"]
mod imp;
} else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
#[path = "dummy.rs"]
mod imp;
Expand Down
24 changes: 12 additions & 12 deletions src/librustc_target/spec/hermit_base.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
use crate::spec::{LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions};
use crate::spec::{LldFlavor, LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions};
use std::default::Default;

pub fn opts() -> TargetOptions {
let mut args = LinkArgs::new();
args.insert(LinkerFlavor::Gcc, vec![
"-Wl,-Bstatic".to_string(),
"-Wl,--no-dynamic-linker".to_string(),
"-Wl,--gc-sections".to_string(),
"-Wl,--as-needed".to_string(),
let mut pre_link_args = LinkArgs::new();
pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec![
"--build-id".to_string(),
"--hash-style=gnu".to_string(),
"--Bstatic".to_string(),
]);

TargetOptions {
linker: Some("rust-lld".to_owned()),
executables: true,
has_elf_tls: true,
linker_is_gnu: true,
no_default_libraries: false,
pre_link_args,
no_default_libraries: true,
panic_strategy: PanicStrategy::Abort,
position_independent_executables: false,
pre_link_args: args,
position_independent_executables: true,
relocation_model: "static".to_string(),
target_family: Some("unix".to_string()),
tls_model: "local-exec".to_string(),
target_family: None,
tls_model: "initial-exec".to_string(),
.. Default::default()
}
}
8 changes: 4 additions & 4 deletions src/librustc_target/spec/x86_64_unknown_hermit.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::spec::{LinkerFlavor, Target, TargetResult};
use crate::spec::{LldFlavor, LinkerFlavor, Target, TargetResult};

pub fn target() -> TargetResult {
let mut base = super::hermit_base::opts();
base.cpu = "x86-64".to_string();
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
base.linker = Some("x86_64-hermit-gcc".to_string());
base.max_atomic_width = Some(64);
base.features = "+rdrnd,+rdseed".to_string();
base.stack_probes = true;

Ok(Target {
llvm_target: "x86_64-unknown-hermit".to_string(),
Expand All @@ -17,7 +17,7 @@ pub fn target() -> TargetResult {
target_os: "hermit".to_string(),
target_env: String::new(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
options: base,
})
}
1 change: 1 addition & 0 deletions src/librustdoc/clean/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ impl<'a> fmt::Display for Html<'a> {
"freebsd" => "FreeBSD",
"fuchsia" => "Fuchsia",
"haiku" => "Haiku",
"hermit" => "HermitCore",
"ios" => "iOS",
"l4re" => "L4Re",
"linux" => "Linux",
Expand Down
3 changes: 3 additions & 0 deletions src/libstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ dlmalloc = { version = "0.1", features = ['rustc-dep-of-std'] }
[target.x86_64-fortanix-unknown-sgx.dependencies]
fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] }

[target.'cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_os = "hermit"))'.dependencies]
hermit-abi = { version = "0.1", features = ['rustc-dep-of-std'] }

[target.wasm32-wasi.dependencies]
wasi = { version = "0.7.0", features = ['rustc-dep-of-std', 'alloc'] }

Expand Down
2 changes: 2 additions & 0 deletions src/libstd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ fn main() {
}
println!("cargo:rustc-link-lib=c");
println!("cargo:rustc-link-lib=compiler_rt");
} else if target.contains("hermit") {
println!("cargo:rustc-link-lib=hermit");
}
}
Loading

0 comments on commit fae75cd

Please sign in to comment.