Skip to content

Commit 1c0cd94

Browse files
committed
Add x86_64-unknown-motor (Motor OS) tier 3 target
Add the initial no-std Motor OS compiler target. Motor OS has been developed for several years in the open: https://github.com/moturus/motor-os. It has a more or less full implementation of Rust std library, as well as tokio/mio ports. Build instructions can be found here: https://github.com/moturus/motor-os/blob/main/docs/build.md. Signed-off-by: U. Lasiotus <lasiotus@motor-os.org>
1 parent 1d23da6 commit 1c0cd94

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

compiler/rustc_target/src/spec/base/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub(crate) mod bpf;
66
pub(crate) mod cygwin;
77
pub(crate) mod dragonfly;
88
pub(crate) mod freebsd;
9+
pub(crate) mod motor;
910
pub(crate) mod fuchsia;
1011
pub(crate) mod haiku;
1112
pub(crate) mod hermit;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, StackProbeType, TargetOptions};
2+
use crate::spec::FramePointer;
3+
4+
pub(crate) fn opts() -> TargetOptions {
5+
let pre_link_args = TargetOptions::link_args(
6+
LinkerFlavor::Gnu(Cc::No, Lld::No),
7+
&[
8+
"-e",
9+
"motor_start",
10+
"--no-undefined",
11+
"--error-unresolved-symbols",
12+
"--no-undefined-version",
13+
"-u",
14+
"__rust_abort",
15+
],
16+
);
17+
TargetOptions {
18+
os: "motor".into(),
19+
executables: true,
20+
// TLS is false below because if true, the compiler assumes
21+
// we handle TLS at the ELF loading level, which we don't.
22+
// We use "OS level" TLS (see thread/local.rs in stdlib).
23+
has_thread_local: false,
24+
frame_pointer: FramePointer::NonLeaf,
25+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::No),
26+
main_needs_argc_argv: true,
27+
panic_strategy: PanicStrategy::Abort,
28+
pre_link_args,
29+
30+
// Note: disabling stack probles and stack protector below leads
31+
// to weird bugs that can only be explained by compiler errors.
32+
stack_probes: StackProbeType::Inline,
33+
supports_stack_protector: true,
34+
..Default::default()
35+
}
36+
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,7 @@ supported_targets! {
16421642
("aarch64-unknown-hermit", aarch64_unknown_hermit),
16431643
("riscv64gc-unknown-hermit", riscv64gc_unknown_hermit),
16441644
("x86_64-unknown-hermit", x86_64_unknown_hermit),
1645+
("x86_64-unknown-motor", x86_64_unknown_motor),
16451646

16461647
("x86_64-unikraft-linux-musl", x86_64_unikraft_linux_musl),
16471648

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use crate::spec::{base, CodeModel, LldFlavor, LinkSelfContainedDefault, RelocModel, RelroLevel, Target};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = base::motor::opts();
5+
base.cpu = "x86-64".into();
6+
base.max_atomic_width = Some(64);
7+
base.code_model = Some(CodeModel::Small);
8+
9+
// We want fully static relocatable binaries. It was surprisingly
10+
// difficult to make it happen reliably, especially various
11+
// linker-related options below. Mostly trial and error.
12+
base.position_independent_executables = true;
13+
base.relro_level = RelroLevel::Full;
14+
base.static_position_independent_executables = true;
15+
base.relocation_model = RelocModel::Pic;
16+
base.lld_flavor_json = LldFlavor::Ld;
17+
base.link_self_contained = LinkSelfContainedDefault::True;
18+
base.dynamic_linking = false;
19+
base.crt_static_default = true;
20+
base.crt_static_respected = true;
21+
22+
23+
Target {
24+
llvm_target: "x86_64-unknown-none-elf".into(),
25+
metadata: crate::spec::TargetMetadata {
26+
description: None,
27+
tier: None,
28+
host_tools: None,
29+
std: None,
30+
},
31+
pointer_width: 64,
32+
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
33+
arch: "x86_64".into(),
34+
options: base,
35+
}
36+
}

src/bootstrap/src/core/sanity.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const STAGE0_MISSING_TARGETS: &[&str] = &[
3838
// just a dummy comment so the list doesn't get onelined
3939
"aarch64_be-unknown-hermit",
4040
"aarch64_be-unknown-none-softfloat",
41+
"x86_64-unknown-motor",
4142
];
4243

4344
/// Minimum version threshold for libstdc++ required when using prebuilt LLVM
@@ -239,6 +240,10 @@ than building it.
239240
continue;
240241
}
241242

243+
if target.contains("motor") {
244+
continue;
245+
}
246+
242247
// skip check for cross-targets
243248
if skip_target_sanity && target != &build.host_target {
244249
continue;

src/doc/rustc/src/platform-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ target | std | host | notes
431431
`x86_64-unknown-l4re-uclibc` | ? | |
432432
[`x86_64-unknown-linux-none`](platform-support/x86_64-unknown-linux-none.md) | * | | 64-bit Linux with no libc
433433
[`x86_64-unknown-managarm-mlibc`](platform-support/managarm.md) | ? | | x86_64 Managarm
434+
`x86_64-unknown-motor` | ? | | x86_64 Motor OS
434435
[`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD
435436
[`x86_64-unknown-trusty`](platform-support/trusty.md) | ✓ | |
436437
`x86_64-uwp-windows-gnu` | ✓ | |

0 commit comments

Comments
 (0)