Skip to content

Commit fae75cd

Browse files
committed
Auto merge of #65167 - hermitcore:rusty-hermit, r=alexcrichton
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.
2 parents 46e6c53 + 805a330 commit fae75cd

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

+2322
-450
lines changed

Cargo.lock

+12
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,17 @@ dependencies = [
13281328
"unicode-segmentation",
13291329
]
13301330

1331+
[[package]]
1332+
name = "hermit-abi"
1333+
version = "0.1.1"
1334+
source = "registry+https://github.com/rust-lang/crates.io-index"
1335+
checksum = "f22b8f315b98f415780ddbe9163c7dbbc5a07225b6d102ace1d8aeef85775140"
1336+
dependencies = [
1337+
"compiler_builtins",
1338+
"libc",
1339+
"rustc-std-workspace-core",
1340+
]
1341+
13311342
[[package]]
13321343
name = "hex"
13331344
version = "0.3.2"
@@ -4159,6 +4170,7 @@ dependencies = [
41594170
"dlmalloc",
41604171
"fortanix-sgx-abi",
41614172
"hashbrown 0.6.2",
4173+
"hermit-abi",
41624174
"libc",
41634175
"panic_abort",
41644176
"panic_unwind",

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/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ dlmalloc = { version = "0.1", features = ['rustc-dep-of-std'] }
5050
[target.x86_64-fortanix-unknown-sgx.dependencies]
5151
fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] }
5252

53+
[target.'cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_os = "hermit"))'.dependencies]
54+
hermit-abi = { version = "0.1", features = ['rustc-dep-of-std'] }
55+
5356
[target.wasm32-wasi.dependencies]
5457
wasi = { version = "0.7.0", features = ['rustc-dep-of-std', 'alloc'] }
5558

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)