Commit 4d71257e authored by Jeremy Soller's avatar Jeremy Soller

Add Redox scheme prefix

Fixes for Redox Path handling

Update to new system calls and enviromental variables

Remove unused type parameter

Don't forget to close executable file

Interpret shebangs on redox

This is no longer handled on the kernel side

Fix for missing setenv/unsetenv

Use mangled names for compiler builtins to avoid conflicts with relibc

Another attempt to fix build issues

WIP aarch64-unknown-redox support

Untested.

Introduce a target family for Redox

The Redox base target spec located within the rustc source did not
specify a 'target_family' attribute. However, the x86_64 specific target
spec located within the redox source did.

Now AArch64 could have done something similar but unfortunately can't
since there are rust compiler mods needed to support Redox on AArch64
which imply that any AArch64 target spec file in the Redox source shall
be ignored in favour of the target spec within the rustc source.

The target_family attribute is eventually translated into an environment
variable called CARGO_CFG_TARGET_FAMILY whose presence can be tested by
software built with the compiler generated from the target spec.

Some crates expect this variable to contain something failing which they
crash. Eg onig_sys within rust-onig. Since the Redox base target spec in
the rustc source doesn't specify target_family for AArch64, such crates
don't build.

The solution is to introduce target_family in the Redox base
target spec within the rustc source so both x86_64 and AArch64 have it
defined by default. It is set to "redox".

"unix" would perhaps be more preferable but using that breaks the rustc
build which starts making incorrect assumptions about the support libs
that Redox has.
parent 8159f389
// 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::redox_base::opts();
base.max_atomic_width = Some(128);
Ok(Target {
llvm_target: "aarch64-unknown-redox".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: "redox".to_string(),
target_env: "".to_string(),
target_vendor: "unknown".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: base,
})
}
......@@ -416,6 +416,7 @@ supported_targets! {
("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc),
("aarch64-unknown-redox", aarch64_unknown_redox),
("x86_64-unknown-redox", x86_64_unknown_redox),
("i386-apple-ios", i386_apple_ios),
......
......@@ -23,7 +23,7 @@ pub fn opts() -> TargetOptions {
relocation_model: "static".to_string(),
disable_redzone: true,
eliminate_frame_pointer: false,
target_family: None,
target_family: Some("redox".to_string()),
linker_is_gnu: true,
has_elf_tls: true,
.. Default::default()
......
......@@ -182,6 +182,11 @@ pub enum Prefix<'a> {
/// Prefix `C:` for the given disk drive.
#[stable(feature = "rust1", since = "1.0.0")]
Disk(#[stable(feature = "rust1", since = "1.0.0")] u8),
/// Scheme `file:` used on Redox
#[cfg(target_os = "redox")]
#[stable(feature = "rust1", since = "1.0.0")]
Scheme(#[stable(feature = "rust1", since = "1.0.0")] &'a OsStr),
}
impl<'a> Prefix<'a> {
......@@ -212,6 +217,7 @@ impl<'a> Prefix<'a> {
},
DeviceNS(x) => 4 + os_str_len(x),
Disk(_) => 2,
Scheme(x) => 1 + os_str_len(x),
}
}
......@@ -313,11 +319,6 @@ unsafe fn u8_slice_as_os_str(s: &[u8]) -> &OsStr {
&*(s as *const [u8] as *const OsStr)
}
// Detect scheme on Redox
fn has_redox_scheme(s: &[u8]) -> bool {
cfg!(target_os = "redox") && s.split(|b| *b == b'/').next().unwrap_or(b"").contains(&b':')
}
////////////////////////////////////////////////////////////////////////////////
// Cross-platform, iterator-independent parsing
////////////////////////////////////////////////////////////////////////////////
......@@ -1900,12 +1901,7 @@ impl Path {
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
pub fn is_absolute(&self) -> bool {
if cfg!(target_os = "redox") {
// FIXME: Allow Redox prefixes
self.has_root() || has_redox_scheme(self.as_u8_slice())
} else {
self.has_root() && (cfg!(unix) || self.prefix().is_some())
}
self.has_root() && (cfg!(unix) || self.prefix().is_some())
}
/// Returns `true` if the `Path` is relative, i.e., not absolute.
......@@ -2310,8 +2306,7 @@ impl Path {
Components {
path: self.as_u8_slice(),
prefix,
has_physical_root: has_physical_root(self.as_u8_slice(), prefix) ||
has_redox_scheme(self.as_u8_slice()),
has_physical_root: has_physical_root(self.as_u8_slice(), prefix),
front: State::Prefix,
back: State::Body,
}
......
......@@ -92,6 +92,29 @@ pub fn cvt_libc<T: IsMinusOne>(t: T) -> crate::io::Result<T> {
}
}
#[doc(hidden)]
pub trait IsMinusOne {
fn is_minus_one(&self) -> bool;
}
macro_rules! impl_is_minus_one {
($($t:ident)*) => ($(impl IsMinusOne for $t {
fn is_minus_one(&self) -> bool {
*self == -1
}
})*)
}
impl_is_minus_one! { i8 i16 i32 i64 isize }
pub fn cvt_libc<T: IsMinusOne>(t: T) -> io::Result<T> {
if t.is_minus_one() {
Err(io::Error::last_os_error())
} else {
Ok(t)
}
}
/// On Redox, use an illegal instruction to abort
pub unsafe fn abort_internal() -> ! {
core::intrinsics::abort();
......
......@@ -13,10 +13,8 @@ pub fn is_verbatim_sep(b: u8) -> bool {
pub fn parse_prefix(path: &OsStr) -> Option<Prefix<'_>> {
if let Some(path_str) = path.to_str() {
if let Some(_i) = path_str.find(':') {
// FIXME: Redox specific prefix
// Some(Prefix::Verbatim(OsStr::new(&path_str[..i])))
None
if let Some(i) = path_str.find(':') {
Some(Prefix::Scheme(OsStr::new(&path_str[..i])))
} else {
None
}
......
use super::error::{Error, Result};
pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
asm!("svc 0"
: "={x0}"(a)
: "{x8}"(a)
: "x0", "x8"
: "volatile");
Error::demux(a)
}
pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
asm!("svc 0"
: "={x0}"(a)
: "{x8}"(a), "{x0}"(b)
: "x0", "x8"
: "volatile");
Error::demux(a)
}
// Clobbers all registers - special for clone
pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
asm!("svc 0"
: "={x0}"(a)
: "{x8}"(a), "{x0}"(b)
: "memory",
"x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
"x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
"x16", "x17","x18", "x19", "x20", "x21", "x22", "x23",
"x24", "x25", "x26", "x27", "x28", "x29", "x30"
: "volatile");
Error::demux(a)
}
pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
asm!("svc 0"
: "={x0}"(a)
: "{x8}"(a), "{x0}"(b), "{x1}"(c)
: "x0", "x1", "x8"
: "volatile");
Error::demux(a)
}
pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result<usize> {
asm!("svc 0"
: "={x0}"(a)
: "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d)
: "x0", "x1", "x2", "x8"
: "volatile");
Error::demux(a)
}
pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result<usize> {
asm!("svc 0"
: "={x0}"(a)
: "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d), "{x3}"(e)
: "x0", "x1", "x2", "x3", "x8"
: "volatile");
Error::demux(a)
}
pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
-> Result<usize> {
asm!("svc 0"
: "={x0}"(a)
: "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d), "{x3}"(e), "{x4}"(f)
: "x0", "x1", "x2", "x3", "x4", "x8"
: "volatile");
Error::demux(a)
}
......@@ -9,6 +9,10 @@ pub use self::number::*;
#[path="arch/arm.rs"]
mod arch;
#[cfg(target_arch = "aarch64")]
#[path="arch/aarch64.rs"]
mod arch;
#[cfg(target_arch = "x86")]
#[path="arch/x86.rs"]
mod arch;
......
......@@ -48,6 +48,7 @@ static TARGETS: &[&str] = &[
"aarch64-unknown-cloudabi",
"aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl",
"aarch64-unknown-redox",
"arm-linux-androideabi",
"arm-unknown-linux-gnueabi",
"arm-unknown-linux-gnueabihf",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment