Skip to content

Commit fd84667

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 fd84667

File tree

8 files changed

+131
-0
lines changed

8 files changed

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

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

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`[(platform-support/motor.md) | ? | | 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` | ✓ | |
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# `x86_64-unknown-motor`
2+
3+
**Tier: 3**
4+
5+
[Motor OS](https://motor-os.org/) is a new operating system for virtualized
6+
environments.
7+
8+
## Target maintainers
9+
10+
[@lasiotus](https://github.com/lasiotus)
11+
12+
## Requirements
13+
14+
This target is cross-compiled. There are no special requirements for the host.
15+
16+
Motor OS uses the ELF file format.
17+
18+
## Building the target
19+
20+
The target can be built by enabling it for a `rustc` build, for example:
21+
22+
```toml
23+
[build]
24+
build-stage = 2
25+
target = ["x86_64-unknown-motor"]
26+
```
27+
28+
## Building Rust programs
29+
30+
Rust standard library is fully supported/implemented, but is not yet part of
31+
the official Rust repo, so an out-of-tree building process should be
32+
followed, as described in the official
33+
[build doc](https://github.com/moturus/motor-os/blob/main/docs/build.md).
34+
35+
## Testing
36+
37+
Cross-compiled Rust binaries and test artifacts can be executed in Motor OS VMs,
38+
as described in e.g.
39+
[Hello Motor OS](https://github.com/moturus/motor-os/blob/main/docs/recipes/hello-motor-os.md)
40+
example.
41+
42+
## Cross-compilation toolchains and C code
43+
44+
C code can be compiled as part of Rust cargo projects. However, there is
45+
no libc support.

tests/assembly-llvm/targets/targets-elf.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,9 @@
658658
//@ revisions: x86_64_unknown_managarm_mlibc
659659
//@ [x86_64_unknown_managarm_mlibc] compile-flags: --target x86_64-unknown-managarm-mlibc
660660
//@ [x86_64_unknown_managarm_mlibc] needs-llvm-components: x86
661+
//@ revisions: x86_64_unknown_motor
662+
//@ [x86_64_unknown_motor] compile-flags: --target x86_64-unknown-motor
663+
//@ [x86_64_unknown_motor] needs-llvm-components: x86
661664
//@ revisions: x86_64_unknown_netbsd
662665
//@ [x86_64_unknown_netbsd] compile-flags: --target x86_64-unknown-netbsd
663666
//@ [x86_64_unknown_netbsd] needs-llvm-components: x86

0 commit comments

Comments
 (0)