Skip to content

Commit cf52c0f

Browse files
committed
add tier 3 HelenOS compiler targets
1 parent b8005bf commit cf52c0f

File tree

15 files changed

+288
-2
lines changed

15 files changed

+288
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use crate::spec::{PanicStrategy, RelroLevel, StackProbeType, TargetOptions};
2+
3+
pub(crate) fn opts() -> TargetOptions {
4+
TargetOptions {
5+
os: "helenos".into(),
6+
7+
dynamic_linking: true,
8+
// we need the linker to keep libgcc and friends
9+
no_default_libraries: false,
10+
has_rpath: true,
11+
relro_level: RelroLevel::Full,
12+
panic_strategy: PanicStrategy::Abort,
13+
stack_probes: StackProbeType::Inline,
14+
15+
..Default::default()
16+
}
17+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) mod dragonfly;
88
pub(crate) mod freebsd;
99
pub(crate) mod fuchsia;
1010
pub(crate) mod haiku;
11+
pub(crate) mod helenos;
1112
pub(crate) mod hermit;
1213
pub(crate) mod hurd;
1314
pub(crate) mod hurd_gnu;

compiler/rustc_target/src/spec/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,13 @@ supported_targets! {
18381838
("i686-unknown-haiku", i686_unknown_haiku),
18391839
("x86_64-unknown-haiku", x86_64_unknown_haiku),
18401840

1841+
("aarch64-unknown-helenos", aarch64_unknown_helenos),
1842+
("armv5te-unknown-helenos-eabi", armv5te_unknown_helenos_eabi),
1843+
("i686-unknown-helenos", i686_unknown_helenos),
1844+
("powerpc-unknown-helenos", powerpc_unknown_helenos),
1845+
("sparc64-unknown-helenos", sparc64_unknown_helenos),
1846+
("x86_64-unknown-helenos", x86_64_unknown_helenos),
1847+
18411848
("i686-unknown-hurd-gnu", i686_unknown_hurd_gnu),
18421849
("x86_64-unknown-hurd-gnu", x86_64_unknown_hurd_gnu),
18431850

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::spec::{Target, base};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = base::helenos::opts();
5+
base.max_atomic_width = Some(128);
6+
base.features = "+v8a".into();
7+
base.linker = Some("aarch64-helenos-gcc".into());
8+
9+
Target {
10+
llvm_target: "aarch64-unknown-helenos".into(),
11+
metadata: crate::spec::TargetMetadata {
12+
description: Some("ARM64 HelenOS".into()),
13+
tier: Some(3),
14+
host_tools: Some(false),
15+
std: Some(true),
16+
},
17+
pointer_width: 64,
18+
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
19+
arch: "aarch64".into(),
20+
options: base,
21+
}
22+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::spec::{Cc, FloatAbi, LinkerFlavor, Lld, Target, base};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = base::helenos::opts();
5+
base.abi = "eabi".into();
6+
base.llvm_floatabi = Some(FloatAbi::Soft);
7+
base.max_atomic_width = Some(32);
8+
base.features = "+soft-float,+strict-align,+atomics-32".into();
9+
base.has_thumb_interworking = true;
10+
base.linker = Some("arm-helenos-gcc".into());
11+
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-march=armv5te"]);
12+
13+
// FIXME: these 3 flags are a hack to avoid generating R_*_RELATIVE relocations in code segment,
14+
// which cause the HelenOS loader to segfault. I believe the underlying issue is that HelenOS
15+
// doesn't map the code segment as writable, so the loader can't apply the relocations.
16+
// The same issue was with the i686-helenos target, I don't recall why the current combination
17+
// of flags avoids the issue there.
18+
base.crt_static_default = true;
19+
base.crt_static_respected = false;
20+
base.crt_static_allows_dylibs = true;
21+
22+
Target {
23+
llvm_target: "armv5te-unknown-helenos-eabi".into(),
24+
metadata: crate::spec::TargetMetadata {
25+
description: Some("ARMv5te HelenOS".into()),
26+
tier: Some(3),
27+
host_tools: Some(false),
28+
std: Some(true),
29+
},
30+
pointer_width: 32,
31+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
32+
arch: "arm".into(),
33+
options: base,
34+
}
35+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, RustcAbi, Target, base};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = base::helenos::opts();
5+
base.cpu = "pentium4".into();
6+
base.max_atomic_width = Some(64);
7+
base.linker = Some("i686-helenos-gcc".into());
8+
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
9+
base.rustc_abi = Some(RustcAbi::X86Sse2);
10+
11+
Target {
12+
llvm_target: "i686-unknown-helenos".into(),
13+
metadata: crate::spec::TargetMetadata {
14+
description: Some("IA-32 (i686) HelenOS".into()),
15+
tier: Some(3),
16+
host_tools: Some(false),
17+
std: Some(true),
18+
},
19+
pointer_width: 32,
20+
data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
21+
i128:128-f64:32:64-f80:32-n8:16:32-S128"
22+
.into(),
23+
arch: "x86".into(),
24+
options: base,
25+
}
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use rustc_abi::Endian;
2+
3+
use crate::spec::{Target, TargetMetadata, base};
4+
5+
pub(crate) fn target() -> Target {
6+
let mut base = base::helenos::opts();
7+
base.endian = Endian::Big;
8+
base.max_atomic_width = Some(32);
9+
base.linker = Some("ppc-helenos-gcc".into());
10+
11+
Target {
12+
llvm_target: "powerpc-unknown-helenos".into(),
13+
metadata: TargetMetadata {
14+
description: Some("PowerPC HelenOS".into()),
15+
tier: Some(3),
16+
host_tools: Some(false),
17+
std: Some(true),
18+
},
19+
pointer_width: 32,
20+
data_layout: "E-m:e-p:32:32-Fn32-i64:64-n32".into(),
21+
arch: "powerpc".into(),
22+
options: base,
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use rustc_abi::Endian;
2+
3+
use crate::spec::{Cc, LinkerFlavor, Lld, Target, TargetMetadata, base};
4+
5+
pub(crate) fn target() -> Target {
6+
let mut base = base::helenos::opts();
7+
base.endian = Endian::Big;
8+
base.cpu = "v9".into();
9+
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
10+
base.max_atomic_width = Some(64);
11+
base.linker = Some("sparc64-helenos-gcc".into());
12+
13+
Target {
14+
llvm_target: "sparc64-unknown-helenos".into(),
15+
metadata: TargetMetadata {
16+
description: Some("SPARC HelenOS".into()),
17+
tier: Some(3),
18+
host_tools: Some(false),
19+
std: Some(true),
20+
},
21+
pointer_width: 64,
22+
data_layout: "E-m:e-i64:64-i128:128-n32:64-S128".into(),
23+
arch: "sparc64".into(),
24+
options: base,
25+
}
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, Target, base};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = base::helenos::opts();
5+
base.cpu = "x86-64".into();
6+
base.plt_by_default = false;
7+
base.max_atomic_width = Some(64);
8+
base.linker = Some("amd64-helenos-gcc".into());
9+
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
10+
11+
Target {
12+
llvm_target: "x86_64-unknown-helenos".into(),
13+
metadata: crate::spec::TargetMetadata {
14+
description: Some("64-bit HelenOS".into()),
15+
tier: Some(3),
16+
host_tools: Some(false),
17+
std: Some(true),
18+
},
19+
pointer_width: 64,
20+
data_layout:
21+
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
22+
arch: "x86_64".into(),
23+
options: base,
24+
}
25+
}

src/bootstrap/src/core/sanity.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ pub struct Finder {
3333
//
3434
// Targets can be removed from this list once they are present in the stage0 compiler (usually by updating the beta compiler of the bootstrap).
3535
const STAGE0_MISSING_TARGETS: &[&str] = &[
36+
"aarch64-unknown-helenos",
37+
"armv5te-unknown-helenos-eabi",
38+
"i686-unknown-helenos",
39+
"x86_64-unknown-helenos",
40+
"powerpc-unknown-helenos",
41+
"sparc64-unknown-helenos",
3642
// just a dummy comment so the list doesn't get onelined
3743
"x86_64-lynx-lynxos178",
3844
];

src/doc/rustc/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
- [solaris](platform-support/solaris.md)
107107
- [\*-nto-qnx-\*](platform-support/nto-qnx.md)
108108
- [\*-unikraft-linux-musl](platform-support/unikraft-linux-musl.md)
109+
- [\*-unknown-helenos](platform-support/helenos.md)
109110
- [\*-unknown-hermit](platform-support/hermit.md)
110111
- [\*-unknown-freebsd](platform-support/freebsd.md)
111112
- [\*-unknown-netbsd\*](platform-support/netbsd.md)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ target | std | host | notes
253253
[`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3
254254
[`aarch64-nintendo-switch-freestanding`](platform-support/aarch64-nintendo-switch-freestanding.md) | * | | ARM64 Nintendo Switch, Horizon
255255
[`aarch64-unknown-freebsd`](platform-support/freebsd.md) | ✓ | ✓ | ARM64 FreeBSD
256+
[`aarch64-unknown-helenos`](platform-support/helenos.md) | ✓ | | ARM64 HelenOS
256257
[`aarch64-unknown-hermit`](platform-support/hermit.md) | ✓ | | ARM64 Hermit
257258
[`aarch64-unknown-illumos`](platform-support/illumos.md) | ✓ | ✓ | ARM64 illumos
258259
`aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI)
@@ -280,6 +281,7 @@ target | std | host | notes
280281
[`armv4t-none-eabi`](platform-support/armv4t-none-eabi.md) | * | | Bare Armv4T
281282
`armv4t-unknown-linux-gnueabi` | ? | | Armv4T Linux
282283
[`armv5te-none-eabi`](platform-support/armv5te-none-eabi.md) | * | | Bare Armv5TE
284+
[`armv5te-unknown-helenos-eabi`](platform-support/helenos.md) | ✓ | | Armv5TE HelenOS (see docs for pending issues)
283285
`armv5te-unknown-linux-uclibceabi` | ? | | Armv5TE Linux with uClibc
284286
[`armv6-unknown-freebsd`](platform-support/freebsd.md) | ✓ | ✓ | Armv6 FreeBSD
285287
[`armv6-unknown-netbsd-eabihf`](platform-support/netbsd.md) | ✓ | ✓ | Armv6 NetBSD w/hard-float
@@ -313,6 +315,7 @@ target | std | host | notes
313315
[`i686-apple-darwin`](platform-support/apple-darwin.md) | ✓ | ✓ | 32-bit macOS (10.12+, Sierra+, Penryn) [^x86_32-floats-return-ABI]
314316
[`i686-pc-nto-qnx700`](platform-support/nto-qnx.md) | * | | 32-bit x86 QNX Neutrino 7.0 RTOS (Pentium 4) [^x86_32-floats-return-ABI]
315317
`i686-unknown-haiku` | ✓ | ✓ | 32-bit Haiku (Pentium 4) [^x86_32-floats-return-ABI]
318+
[`i686-unknown-helenos`](platform-support/helenos.md) | ✓ | | HelenOS IA-32 (see docs for pending issues)
316319
[`i686-unknown-hurd-gnu`](platform-support/hurd.md) | ✓ | ✓ | 32-bit GNU/Hurd (Pentium 4) [^x86_32-floats-return-ABI]
317320
[`i686-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/i386 (Pentium 4) [^x86_32-floats-return-ABI]
318321
[`i686-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 32-bit OpenBSD (Pentium 4) [^x86_32-floats-return-ABI]
@@ -347,6 +350,7 @@ target | std | host | notes
347350
[`mipsisa64r6el-unknown-linux-gnuabi64`](platform-support/mips-release-6.md) | ✓ | ✓ | 64-bit MIPS Release 6 Little Endian
348351
`msp430-none-elf` | * | | 16-bit MSP430 microcontrollers
349352
[`powerpc-unknown-freebsd`](platform-support/freebsd.md) | ? | | PowerPC FreeBSD
353+
[`powerpc-unknown-helenos`](platform-support/helenos.md) | ✓ | | PowerPC HelenOS
350354
[`powerpc-unknown-linux-gnuspe`](platform-support/powerpc-unknown-linux-gnuspe.md) | ✓ | | PowerPC SPE Linux
351355
`powerpc-unknown-linux-musl` | ? | | PowerPC Linux with musl 1.2.3
352356
[`powerpc-unknown-linux-muslspe`](platform-support/powerpc-unknown-linux-muslspe.md) | ? | | PowerPC SPE Linux with musl 1.2.3
@@ -387,6 +391,7 @@ target | std | host | notes
387391
[`s390x-unknown-linux-musl`](platform-support/s390x-unknown-linux-musl.md) | ✓ | | S390x Linux (kernel 3.2, musl 1.2.3)
388392
`sparc-unknown-linux-gnu` | ✓ | | 32-bit SPARC Linux
389393
[`sparc-unknown-none-elf`](./platform-support/sparc-unknown-none-elf.md) | * | | Bare 32-bit SPARC V7+
394+
[`sparc64-unknown-helenos`](platform-support/helenos.md) | ✓ | | sparc64 HelenOS
390395
[`sparc64-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/sparc64
391396
[`sparc64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | OpenBSD/sparc64
392397
[`thumbv4t-none-eabi`](platform-support/armv4t-none-eabi.md) | * | | Thumb-mode Bare Armv4T
@@ -416,6 +421,7 @@ target | std | host | notes
416421
`x86_64-unknown-dragonfly` | ✓ | ✓ | 64-bit DragonFlyBSD
417422
`x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku
418423
[`x86_64-unknown-hermit`](platform-support/hermit.md) | ✓ | | x86_64 Hermit
424+
[`x86_64-unknown-helenos`](platform-support/helenos.md) | ✓ | | x86_64 (amd64) HelenOS
419425
[`x86_64-unknown-hurd-gnu`](platform-support/hurd.md) | ✓ | ✓ | 64-bit GNU/Hurd
420426
`x86_64-unknown-l4re-uclibc` | ? | |
421427
[`x86_64-unknown-linux-none`](platform-support/x86_64-unknown-linux-none.md) | * | | 64-bit Linux with no libc
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# `*-unknown-helenos`
2+
3+
**Tier: 3**
4+
5+
Targets for [HelenOS](https://www.helenos.org).
6+
These targets allow compiling user-space applications, that you can then copy into your HelenOS ISO image to run them.
7+
8+
Target triplets available:
9+
10+
- `x86_64-unknown-helenos`
11+
- `sparc64-unknown-helenos`
12+
- `powerpc-unknown-helenos`
13+
- `aarch64-unknown-helenos`
14+
- `i686-unknown-helenos`*
15+
- `armv5te-unknown-helenos`*
16+
17+
Support of the latter two platforms is available in the compiler, however, the toolchains are not fully functional:
18+
19+
- On i686, some portions of native HelenOS libraries run into issues due to vector instructions accessing variables from stack that seems
20+
to be misaligned. It is not clear if this is fault of HelenOS or Rust. Most programs work, but for example calling `ui_window_create` from HelenOS
21+
libui does not work.
22+
- On 32-bit Arm, HelenOS libc is missing atomic primitives, and even after attempting to fill them, the resulting executables weren't functional,
23+
again for reasons that weren't fully understood yet.
24+
25+
## Target maintainers
26+
27+
- Matěj Volf ([@mvolfik](https://github.com/mvolfik))
28+
29+
## Requirements
30+
31+
These targets only support cross-compilation. The targets will[^helenos-libstd-pending] support libstd, although support of some platform features (filesystem, networking) may be limited.
32+
33+
You need to have a local clone of the HelenOS repository and the HelenOS toolchain set up, no HelenOS-Rust development artifacts are available.
34+
35+
[^helenos-libstd-pending]: libstd is not yet available, because it needs to be done in a separate PR, because compiler support needs to be merged first to allow creating libc bindings
36+
37+
## Building
38+
39+
If you want to avoid the full setup, fully automated Docker-based build system is available at https://github.com/mvolfik/helenos-rust-autobuild
40+
41+
### HelenOS toolchain setup
42+
43+
For compilation of standard library, you need to build the HelenOS toolchain (because Rust needs to use `*-helenos-gcc` as linker) and its libraries (libc and a few others). See [this HelenOS wiki page](https://www.helenos.org/wiki/UsersGuide/CompilingFromSource#a2.Buildasupportedcross-compiler) for instruction on setting up the build. At the end of step 4 (_Configure and build_), after `ninja image_path`, invoke `ninja export-dev` to build the shared libraries.
44+
45+
Copy the libraries to the path where the compiler automatically searches for them. This will be the directory where you installed the toolchain (for example `~/.local/share/HelenOS/cross/i686-helenos/lib`). In the folder where you built HelenOS, you can run these commands:
46+
47+
```sh
48+
touch /tmp/test.c
49+
HELENOS_LIB_PATH="$(realpath "$(amd64-helenos-gcc -v -c /tmp/test.c 2>&1 | grep LIBRARY_PATH | cut -d= -f2 | cut -d: -f2)")"
50+
# use sparc64-helenos-gcc above for the SPARC toolchain, etc
51+
cp -P export-dev/lib/* "$HELENOS_LIB_PATH"
52+
```
53+
54+
### Building the target
55+
56+
When you have the HelenOS toolchain set up and installed in your path, you can build the Rust toolchain using the standard procedure. See [rustc dev guide](https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html).
57+
58+
In the most simple case, this means that you can run `./x build library --stage 1 --target x86_64-unknown-linux-gnu,<arch>-unknown-helenos` (the first target triple should be your host machine, adjust accordingly). Then run `rustup toolchain link mytoolchain build/host/stage1` to allow using your toolchain for building Rust programs.
59+
60+
### Building Rust programs
61+
62+
If you linked the toolchain above as `mytoolchain`, run `cargo +mytoolchain build --target <arch>-unknown-helenos`.
63+
64+
## Testing
65+
66+
After you build a Rust program for HelenOS, you can put it into the `dist` directory of the HelenOS build, build the ISO image, and then run it either in an emulator, or on real hardware. See HelenOS wiki for further instructions on running the OS.
67+
68+
Running the Rust testsuite has not been attempted yet due to missing host tools (thus the test suite can't be run natively) and insufficient networking support (thus we can't use the `remote-test-server` tool).
69+
70+
## Cross-compilation toolchains and C code
71+
72+
You should be able to cross-compile and link any needed C code using `<arch>-helenos-gcc` that you built above. However, note that clang support is highly lacking. Therefore, to run tools such as `bindgen`, you will need to provide flag `-nostdinc` and manually specify the include paths to HelenOS headers, which you will find in the `export-dev` folder + in the cross-compilation toolchain (e.g. `~/.local/share/HelenOS/cross/lib/gcc/i686-helenos/14.2.0/include`). You can see an example of proper build.rs at https://github.com/mvolfik/helenos-ui-rs/blob/master/build.rs

0 commit comments

Comments
 (0)