Skip to content

Commit

Permalink
Rollup merge of rust-lang#52861 - ColinFinck:master, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mark-Simulacrum authored Aug 1, 2018
2 parents df2055f + 4ad4ad0 commit 209db81
Show file tree
Hide file tree
Showing 20 changed files with 585 additions and 16 deletions.
10 changes: 8 additions & 2 deletions src/liballoc_system/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ mod platform {
}
}

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

#[cfg(not(any(target_os = "android", target_os = "redox", target_os = "solaris")))]
#[cfg(not(any(target_os = "android",
target_os = "hermit",
target_os = "redox",
target_os = "solaris")))]
#[inline]
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
let mut out = ptr::null_mut();
Expand Down
32 changes: 32 additions & 0 deletions src/librustc_target/spec/aarch64_unknown_hermit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use spec::{LinkerFlavor, Target, TargetResult};

pub fn target() -> TargetResult {
let mut base = super::hermit_base::opts();
base.max_atomic_width = Some(128);
base.abi_blacklist = super::arm_base::abi_blacklist();
base.linker = Some("aarch64-hermit-gcc".to_string());

Ok(Target {
llvm_target: "aarch64-unknown-hermit".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
target_c_int_width: "32".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "hermit".to_string(),
target_env: "".to_string(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: base,
})
}
37 changes: 37 additions & 0 deletions src/librustc_target/spec/hermit_base.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use spec::{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(),
]);

TargetOptions {
exe_allocation_crate: None,
executables: true,
has_elf_tls: true,
linker_is_gnu: true,
no_default_libraries: false,
panic_strategy: PanicStrategy::Abort,
position_independent_executables: false,
pre_link_args: args,
relocation_model: "static".to_string(),
target_family: Some("unix".to_string()),
tls_model: "local-exec".to_string(),
.. Default::default()
}
}
4 changes: 4 additions & 0 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ mod cloudabi_base;
mod dragonfly_base;
mod freebsd_base;
mod haiku_base;
mod hermit_base;
mod linux_base;
mod linux_musl_base;
mod openbsd_base;
Expand Down Expand Up @@ -373,6 +374,9 @@ supported_targets! {
("armv7-unknown-cloudabi-eabihf", armv7_unknown_cloudabi_eabihf),
("i686-unknown-cloudabi", i686_unknown_cloudabi),
("x86_64-unknown-cloudabi", x86_64_unknown_cloudabi),

("aarch64-unknown-hermit", aarch64_unknown_hermit),
("x86_64-unknown-hermit", x86_64_unknown_hermit),
}

/// Everything `rustc` knows about how to compile for a specific target.
Expand Down
33 changes: 33 additions & 0 deletions src/librustc_target/spec/x86_64_unknown_hermit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use spec::{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);

Ok(Target {
llvm_target: "x86_64-unknown-hermit".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
target_c_int_width: "32".to_string(),
data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(),
arch: "x86_64".to_string(),
target_os: "hermit".to_string(),
target_env: "".to_string(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: base,
})
}
Loading

0 comments on commit 209db81

Please sign in to comment.