Skip to content

Commit 0e703ed

Browse files
committed
Add support for CloudABI targets to the rustc backend.
CloudABI is a sandboxed UNIX-like runtime environment. It is a programming environment that uses a capability-based security model. In practice this means that many POSIX interfaces are present, except for ones that try to access resources out of thin air. For example, open() is gone, but openat() is present. Right now I'm at the point where I can compile very basic CloudABI applications on all four supported architectures (ARM and x86, 32 and 64 bits). The next step will be to get libstd to work. Patches for that are outside the scope of this change. More info: https://nuxi.nl/cloudabi/ https://github.com/NuxiNL/cloudlibc/
1 parent 957dc8d commit 0e703ed

6 files changed

+174
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2017 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 LinkerFlavor;
12+
use target::{Target, TargetResult};
13+
14+
pub fn target() -> TargetResult {
15+
let mut base = super::cloudabi_base::opts();
16+
base.max_atomic_width = Some(128);
17+
base.abi_blacklist = super::arm_base::abi_blacklist();
18+
19+
Ok(Target {
20+
llvm_target: "aarch64-unknown-cloudabi".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: "cloudabi".to_string(),
27+
target_env: "".to_string(),
28+
target_vendor: "unknown".to_string(),
29+
linker_flavor: LinkerFlavor::Gcc,
30+
options: base,
31+
})
32+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017 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 LinkerFlavor;
12+
use target::{Target, TargetResult};
13+
14+
pub fn target() -> TargetResult {
15+
let mut base = super::cloudabi_base::opts();
16+
base.cpu = "cortex-a8".to_string();
17+
base.max_atomic_width = Some(64);
18+
base.features = "+v7,+vfp3,+neon".to_string();
19+
base.abi_blacklist = super::arm_base::abi_blacklist();
20+
21+
Ok(Target {
22+
llvm_target: "armv7-unknown-cloudabi-eabihf".to_string(),
23+
target_endian: "little".to_string(),
24+
target_pointer_width: "32".to_string(),
25+
target_c_int_width: "32".to_string(),
26+
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
27+
arch: "arm".to_string(),
28+
target_os: "cloudabi".to_string(),
29+
target_env: "".to_string(),
30+
target_vendor: "unknown".to_string(),
31+
linker_flavor: LinkerFlavor::Gcc,
32+
options: base,
33+
})
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017 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 LinkerFlavor;
12+
use target::{LinkArgs, TargetOptions, RelroLevel};
13+
use std::default::Default;
14+
15+
pub fn opts() -> TargetOptions {
16+
let mut args = LinkArgs::new();
17+
args.insert(LinkerFlavor::Gcc, vec![
18+
"-Wl,-Bstatic".to_string(),
19+
"-Wl,--no-dynamic-linker".to_string(),
20+
"-Wl,--eh-frame-hdr".to_string(),
21+
"-Wl,--gc-sections".to_string(),
22+
]);
23+
24+
TargetOptions {
25+
executables: true,
26+
target_family: Some("unix".to_string()),
27+
linker_is_gnu: true,
28+
pre_link_args: args,
29+
position_independent_executables: true,
30+
relro_level: RelroLevel::Full,
31+
exe_allocation_crate: super::maybe_jemalloc(),
32+
.. Default::default()
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017 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 LinkerFlavor;
12+
use target::{Target, TargetResult};
13+
14+
pub fn target() -> TargetResult {
15+
let mut base = super::cloudabi_base::opts();
16+
base.cpu = "pentium4".to_string();
17+
base.max_atomic_width = Some(64);
18+
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m32".to_string());
19+
base.stack_probes = true;
20+
21+
Ok(Target {
22+
llvm_target: "i686-unknown-cloudabi".to_string(),
23+
target_endian: "little".to_string(),
24+
target_pointer_width: "32".to_string(),
25+
target_c_int_width: "32".to_string(),
26+
data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(),
27+
arch: "x86".to_string(),
28+
target_os: "cloudabi".to_string(),
29+
target_env: "".to_string(),
30+
target_vendor: "unknown".to_string(),
31+
linker_flavor: LinkerFlavor::Gcc,
32+
options: base,
33+
})
34+
}

src/librustc_back/target/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ mod apple_base;
5757
mod apple_ios_base;
5858
mod arm_base;
5959
mod bitrig_base;
60+
mod cloudabi_base;
6061
mod dragonfly_base;
6162
mod emscripten_base;
6263
mod freebsd_base;
@@ -227,6 +228,11 @@ supported_targets! {
227228
("thumbv7em-none-eabihf", thumbv7em_none_eabihf),
228229

229230
("msp430-none-elf", msp430_none_elf),
231+
232+
("aarch64-unknown-cloudabi", aarch64_unknown_cloudabi),
233+
("armv7-unknown-cloudabi-eabihf", armv7_unknown_cloudabi_eabihf),
234+
("i686-unknown-cloudabi", i686_unknown_cloudabi),
235+
("x86_64-unknown-cloudabi", x86_64_unknown_cloudabi),
230236
}
231237

232238
/// Everything `rustc` knows about how to compile for a specific target.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017 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 LinkerFlavor;
12+
use target::{Target, TargetResult};
13+
14+
pub fn target() -> TargetResult {
15+
let mut base = super::cloudabi_base::opts();
16+
base.cpu = "x86-64".to_string();
17+
base.max_atomic_width = Some(64);
18+
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
19+
base.stack_probes = true;
20+
21+
Ok(Target {
22+
llvm_target: "x86_64-unknown-cloudabi".to_string(),
23+
target_endian: "little".to_string(),
24+
target_pointer_width: "64".to_string(),
25+
target_c_int_width: "32".to_string(),
26+
data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(),
27+
arch: "x86_64".to_string(),
28+
target_os: "cloudabi".to_string(),
29+
target_env: "".to_string(),
30+
target_vendor: "unknown".to_string(),
31+
linker_flavor: LinkerFlavor::Gcc,
32+
options: base,
33+
})
34+
}

0 commit comments

Comments
 (0)