Skip to content

Commit d3e85a4

Browse files
committed
add compilation support for first HelenOS targets
1 parent 883f9f7 commit d3e85a4

File tree

8 files changed

+130
-0
lines changed

8 files changed

+130
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use crate::spec::{PanicStrategy, RelroLevel, TargetOptions};
2+
3+
pub(crate) fn opts() -> TargetOptions {
4+
TargetOptions {
5+
os: "helenos".into(),
6+
7+
dynamic_linking: true,
8+
// FIXME: this actually is supported by HelenOS, but then we run into issues
9+
// with linking libstartfiles.a (parts of which obviously can't be at randomized
10+
// positions). The crt_* flags also have some effect on this.
11+
// position_independent_executables: true,
12+
13+
relro_level: RelroLevel::Full,
14+
panic_strategy: PanicStrategy::Abort,
15+
16+
..Default::default()
17+
}
18+
}

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,9 @@ supported_targets! {
18381838
("i686-unknown-haiku", i686_unknown_haiku),
18391839
("x86_64-unknown-haiku", x86_64_unknown_haiku),
18401840

1841+
("i686-unknown-helenos", i686_unknown_helenos),
1842+
("x86_64-unknown-helenos", x86_64_unknown_helenos),
1843+
18411844
("i686-unknown-hurd-gnu", i686_unknown_hurd_gnu),
18421845
("x86_64-unknown-hurd-gnu", x86_64_unknown_hurd_gnu),
18431846

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, StackProbeType, 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.stack_probes = StackProbeType::Inline;
8+
base.linker = Some("i686-helenos-gcc".into());
9+
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
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: None,
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, 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.stack_probes = StackProbeType::Inline;
9+
base.linker = Some("amd64-helenos-gcc".into());
10+
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
11+
12+
Target {
13+
llvm_target: "x86_64-unknown-helenos".into(),
14+
metadata: crate::spec::TargetMetadata {
15+
description: Some("64-bit HelenOS".into()),
16+
tier: Some(3),
17+
host_tools: Some(false),
18+
std: None,
19+
},
20+
pointer_width: 64,
21+
data_layout:
22+
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
23+
arch: "x86_64".into(),
24+
options: base,
25+
}
26+
}

src/bootstrap/src/core/sanity.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ 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+
"i686-unknown-helenos",
37+
"x86_64-unknown-helenos",
3638
// just a dummy comment so the list doesn't get onelined
3739
"x86_64-lynx-lynxos178",
3840
];

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ target | std | host | notes
313313
[`i686-apple-darwin`](platform-support/apple-darwin.md) | ✓ | ✓ | 32-bit macOS (10.12+, Sierra+, Penryn) [^x86_32-floats-return-ABI]
314314
[`i686-pc-nto-qnx700`](platform-support/nto-qnx.md) | * | | 32-bit x86 QNX Neutrino 7.0 RTOS (Pentium 4) [^x86_32-floats-return-ABI]
315315
`i686-unknown-haiku` | ✓ | ✓ | 32-bit Haiku (Pentium 4) [^x86_32-floats-return-ABI]
316+
[`i686-unknown-helenos`](platform-support/helenos.md) | ? | | HelenOS IA-32
316317
[`i686-unknown-hurd-gnu`](platform-support/hurd.md) | ✓ | ✓ | 32-bit GNU/Hurd (Pentium 4) [^x86_32-floats-return-ABI]
317318
[`i686-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/i386 (Pentium 4) [^x86_32-floats-return-ABI]
318319
[`i686-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 32-bit OpenBSD (Pentium 4) [^x86_32-floats-return-ABI]
@@ -416,6 +417,7 @@ target | std | host | notes
416417
`x86_64-unknown-dragonfly` | ✓ | ✓ | 64-bit DragonFlyBSD
417418
`x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku
418419
[`x86_64-unknown-hermit`](platform-support/hermit.md) | ✓ | | x86_64 Hermit
420+
[`x86_64-unknown-helenos`](platform-support/helenos.md) | ? | | x86_64 (amd64) HelenOS
419421
[`x86_64-unknown-hurd-gnu`](platform-support/hurd.md) | ✓ | ✓ | 64-bit GNU/Hurd
420422
`x86_64-unknown-l4re-uclibc` | ? | |
421423
[`x86_64-unknown-linux-none`](platform-support/x86_64-unknown-linux-none.md) | * | | 64-bit Linux with no libc
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 so far:
9+
10+
- `x86_64-unknown-helenos`
11+
- `i686-unknown-helenos`
12+
13+
## Target maintainers
14+
15+
- Matěj Volf ([@mvolfik](https://github.com/mvolfik))
16+
17+
## Requirements
18+
19+
These targets only support cross-compilation. The targets will[^1] support libstd, although support of some platform features (filesystem, networking) may be limited.
20+
21+
You need to have a local clone of the HelenOS repository and the HelenOS toolchain set up, no HelenOS-Rust development artifacts are available.
22+
23+
[^1]: The support 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
24+
25+
## Building
26+
27+
### HelenOS toolchain setup
28+
29+
For compilation of standard library, you need to build the HelenOS toolchain (because Rust needs to use `*-helenos-gcc` as linker) and shared libraries. 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_), invoke `ninja export-dev` to build the shared libraries.
30+
31+
Then copy these shared libraries from `export-dev/lib` 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`). You can see this path with this command:
32+
33+
```sh
34+
touch /tmp/test.c
35+
i686-helenos-gcc -v -c /tmp/test.c 2>&1 | grep LIBRARY_PATH
36+
```
37+
38+
## Building the target
39+
40+
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).
41+
42+
## Building Rust programs
43+
44+
No special setup is needed. Simply use the toolchain you built above and run `cargo build --target <arch>-unknown-helenos`.
45+
46+
## Testing
47+
48+
Running the Rust test suite has not been attempted yet.
49+
50+
## Cross-compilation toolchains and C code
51+
52+
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` + in the cross-compilation toolchain (e.g. `~/.local/share/HelenOS/cross/lib/gcc/i686-helenos/14.2.0/include`).

0 commit comments

Comments
 (0)