Skip to content

Commit 209db81

Browse files
Rollup merge of rust-lang#52861 - ColinFinck:master, r=alexcrichton
Add targets for HermitCore (https://hermitcore.org) to the Rust compiler and port libstd to it. As a start, the port uses the simplest possible configuration (no jemalloc, abort on panic) and makes use of existing Unix-specific code wherever possible. It adds targets for x86_64 (current main HermitCore platform) and aarch64 (HermitCore platform under development). Together with the patches to "liblibc" (rust-lang/libc#1048) and llvm (rust-lang/llvm#122), this enables HermitCore applications to be written in Rust.
2 parents df2055f + 4ad4ad0 commit 209db81

File tree

20 files changed

+585
-16
lines changed

20 files changed

+585
-16
lines changed

src/liballoc_system/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ mod platform {
174174
}
175175
}
176176

177-
#[cfg(any(target_os = "android", target_os = "redox", target_os = "solaris"))]
177+
#[cfg(any(target_os = "android",
178+
target_os = "hermit",
179+
target_os = "redox",
180+
target_os = "solaris"))]
178181
#[inline]
179182
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
180183
// On android we currently target API level 9 which unfortunately
@@ -197,7 +200,10 @@ mod platform {
197200
libc::memalign(layout.align(), layout.size()) as *mut u8
198201
}
199202

200-
#[cfg(not(any(target_os = "android", target_os = "redox", target_os = "solaris")))]
203+
#[cfg(not(any(target_os = "android",
204+
target_os = "hermit",
205+
target_os = "redox",
206+
target_os = "solaris")))]
201207
#[inline]
202208
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
203209
let mut out = ptr::null_mut();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use spec::{LinkerFlavor, Target, TargetResult};
12+
13+
pub fn target() -> TargetResult {
14+
let mut base = super::hermit_base::opts();
15+
base.max_atomic_width = Some(128);
16+
base.abi_blacklist = super::arm_base::abi_blacklist();
17+
base.linker = Some("aarch64-hermit-gcc".to_string());
18+
19+
Ok(Target {
20+
llvm_target: "aarch64-unknown-hermit".to_string(),
21+
target_endian: "little".to_string(),
22+
target_pointer_width: "64".to_string(),
23+
target_c_int_width: "32".to_string(),
24+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
25+
arch: "aarch64".to_string(),
26+
target_os: "hermit".to_string(),
27+
target_env: "".to_string(),
28+
target_vendor: "unknown".to_string(),
29+
linker_flavor: LinkerFlavor::Gcc,
30+
options: base,
31+
})
32+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use spec::{LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions};
12+
use std::default::Default;
13+
14+
pub fn opts() -> TargetOptions {
15+
let mut args = LinkArgs::new();
16+
args.insert(LinkerFlavor::Gcc, vec![
17+
"-Wl,-Bstatic".to_string(),
18+
"-Wl,--no-dynamic-linker".to_string(),
19+
"-Wl,--gc-sections".to_string(),
20+
"-Wl,--as-needed".to_string(),
21+
]);
22+
23+
TargetOptions {
24+
exe_allocation_crate: None,
25+
executables: true,
26+
has_elf_tls: true,
27+
linker_is_gnu: true,
28+
no_default_libraries: false,
29+
panic_strategy: PanicStrategy::Abort,
30+
position_independent_executables: false,
31+
pre_link_args: args,
32+
relocation_model: "static".to_string(),
33+
target_family: Some("unix".to_string()),
34+
tls_model: "local-exec".to_string(),
35+
.. Default::default()
36+
}
37+
}

src/librustc_target/spec/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod cloudabi_base;
6262
mod dragonfly_base;
6363
mod freebsd_base;
6464
mod haiku_base;
65+
mod hermit_base;
6566
mod linux_base;
6667
mod linux_musl_base;
6768
mod openbsd_base;
@@ -373,6 +374,9 @@ supported_targets! {
373374
("armv7-unknown-cloudabi-eabihf", armv7_unknown_cloudabi_eabihf),
374375
("i686-unknown-cloudabi", i686_unknown_cloudabi),
375376
("x86_64-unknown-cloudabi", x86_64_unknown_cloudabi),
377+
378+
("aarch64-unknown-hermit", aarch64_unknown_hermit),
379+
("x86_64-unknown-hermit", x86_64_unknown_hermit),
376380
}
377381

378382
/// Everything `rustc` knows about how to compile for a specific target.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use spec::{LinkerFlavor, Target, TargetResult};
12+
13+
pub fn target() -> TargetResult {
14+
let mut base = super::hermit_base::opts();
15+
base.cpu = "x86-64".to_string();
16+
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
17+
base.linker = Some("x86_64-hermit-gcc".to_string());
18+
base.max_atomic_width = Some(64);
19+
20+
Ok(Target {
21+
llvm_target: "x86_64-unknown-hermit".to_string(),
22+
target_endian: "little".to_string(),
23+
target_pointer_width: "64".to_string(),
24+
target_c_int_width: "32".to_string(),
25+
data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(),
26+
arch: "x86_64".to_string(),
27+
target_os: "hermit".to_string(),
28+
target_env: "".to_string(),
29+
target_vendor: "unknown".to_string(),
30+
linker_flavor: LinkerFlavor::Gcc,
31+
options: base,
32+
})
33+
}

0 commit comments

Comments
 (0)