Skip to content

Commit

Permalink
redesign of the interface to the unikernel HermitCore
Browse files Browse the repository at this point in the history
- the old interface between HermitCore and the Rust Standard Library
  based on a small C library (newlib)
- remove this interface and call directly the unikernel
- remove the dependency to the HermitCore linker
- use rust-lld as linker
  • Loading branch information
stlankes committed Oct 6, 2019
1 parent 7870050 commit c1e440a
Show file tree
Hide file tree
Showing 51 changed files with 2,388 additions and 451 deletions.
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
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 c1e440a

Please sign in to comment.