Skip to content

Commit c1e440a

Browse files
committed
redesign of the interface to the unikernel HermitCore
- 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
1 parent 7870050 commit c1e440a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2388
-451
lines changed

src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ mod job {
160160
}
161161
}
162162

163-
#[cfg(any(target_os = "haiku", not(any(unix, windows))))]
163+
#[cfg(any(target_os = "haiku", target_os = "hermit", not(any(unix, windows))))]
164164
mod job {
165165
pub unsafe fn setup(_build: &mut crate::Build) {
166166
}

src/libpanic_abort/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ pub unsafe extern fn __rust_start_panic(_payload: usize) -> u32 {
5454
core::intrinsics::abort();
5555
}
5656

57-
#[cfg(all(target_vendor="fortanix", target_env="sgx"))]
57+
#[cfg(any(target_os = "hermit",
58+
all(target_vendor="fortanix", target_env="sgx")))]
5859
unsafe fn abort() -> ! {
5960
// call std::sys::abort_internal
6061
extern "C" { pub fn __rust_abort() -> !; }

src/libpanic_unwind/hermit.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Unwinding for *hermit* target.
2+
//!
3+
//! Right now we don't support this, so this is just stubs.
4+
5+
use alloc::boxed::Box;
6+
use core::ptr;
7+
use core::any::Any;
8+
9+
pub fn payload() -> *mut u8 {
10+
ptr::null_mut()
11+
}
12+
13+
pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
14+
extern "C" { pub fn __rust_abort() -> !; }
15+
__rust_abort();
16+
}
17+
18+
pub unsafe fn panic(_data: Box<dyn Any + Send>) -> u32 {
19+
extern "C" { pub fn __rust_abort() -> !; }
20+
__rust_abort();
21+
}

src/libpanic_unwind/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ cfg_if::cfg_if! {
4343
} else if #[cfg(target_arch = "wasm32")] {
4444
#[path = "dummy.rs"]
4545
mod imp;
46+
} else if #[cfg(target_os = "hermit")] {
47+
#[path = "hermit.rs"]
48+
mod imp;
4649
} else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
4750
#[path = "dummy.rs"]
4851
mod imp;
+12-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
use crate::spec::{LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions};
1+
use crate::spec::{LldFlavor, LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions};
22
use std::default::Default;
33

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

1312
TargetOptions {
13+
linker: Some("rust-lld".to_owned()),
1414
executables: true,
1515
has_elf_tls: true,
1616
linker_is_gnu: true,
17-
no_default_libraries: false,
17+
pre_link_args,
18+
no_default_libraries: true,
1819
panic_strategy: PanicStrategy::Abort,
19-
position_independent_executables: false,
20-
pre_link_args: args,
20+
position_independent_executables: true,
2121
relocation_model: "static".to_string(),
22-
target_family: Some("unix".to_string()),
23-
tls_model: "local-exec".to_string(),
22+
target_family: None,
23+
tls_model: "initial-exec".to_string(),
2424
.. Default::default()
2525
}
2626
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::spec::{LinkerFlavor, Target, TargetResult};
1+
use crate::spec::{LldFlavor, LinkerFlavor, Target, TargetResult};
22

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

1010
Ok(Target {
1111
llvm_target: "x86_64-unknown-hermit".to_string(),
@@ -17,7 +17,7 @@ pub fn target() -> TargetResult {
1717
target_os: "hermit".to_string(),
1818
target_env: String::new(),
1919
target_vendor: "unknown".to_string(),
20-
linker_flavor: LinkerFlavor::Gcc,
20+
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
2121
options: base,
2222
})
2323
}

src/librustdoc/clean/cfg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ impl<'a> fmt::Display for Html<'a> {
346346
"freebsd" => "FreeBSD",
347347
"fuchsia" => "Fuchsia",
348348
"haiku" => "Haiku",
349+
"hermit" => "HermitCore",
349350
"ios" => "iOS",
350351
"l4re" => "L4Re",
351352
"linux" => "Linux",

src/libstd/build.rs

+2
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,7 @@ fn main() {
5454
}
5555
println!("cargo:rustc-link-lib=c");
5656
println!("cargo:rustc-link-lib=compiler_rt");
57+
} else if target.contains("hermit") {
58+
println!("cargo:rustc-link-lib=hermit");
5759
}
5860
}

0 commit comments

Comments
 (0)