Skip to content

Commit 8731b9b

Browse files
committed
add arm targets
1 parent 2df2d02 commit 8731b9b

File tree

9 files changed

+83
-13
lines changed

9 files changed

+83
-13
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{PanicStrategy, RelroLevel, TargetOptions};
1+
use crate::spec::{PanicStrategy, RelroLevel, StackProbeType, TargetOptions};
22

33
pub(crate) fn opts() -> TargetOptions {
44
TargetOptions {
@@ -10,6 +10,7 @@ pub(crate) fn opts() -> TargetOptions {
1010
has_rpath: true,
1111
relro_level: RelroLevel::Full,
1212
panic_strategy: PanicStrategy::Abort,
13+
stack_probes: StackProbeType::Inline,
1314

1415
..Default::default()
1516
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,8 @@ 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),
18411843
("i686-unknown-helenos", i686_unknown_helenos),
18421844
("x86_64-unknown-helenos", x86_64_unknown_helenos),
18431845

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+
}

compiler/rustc_target/src/spec/targets/i686_unknown_helenos.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
1+
use crate::spec::{Cc, LinkerFlavor, Lld, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::helenos::opts();
55
base.cpu = "pentium4".into();
66
base.max_atomic_width = Some(64);
7-
base.stack_probes = StackProbeType::Inline;
87
base.linker = Some("i686-helenos-gcc".into());
98
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
109

@@ -14,7 +13,7 @@ pub(crate) fn target() -> Target {
1413
description: Some("IA-32 (i686) HelenOS".into()),
1514
tier: Some(3),
1615
host_tools: Some(false),
17-
std: None,
16+
std: Some(true),
1817
},
1918
pointer_width: 32,
2019
data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\

compiler/rustc_target/src/spec/targets/x86_64_unknown_helenos.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
1+
use crate::spec::{Cc, LinkerFlavor, Lld, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::helenos::opts();
55
base.cpu = "x86-64".into();
66
base.plt_by_default = false;
77
base.max_atomic_width = Some(64);
8-
base.stack_probes = StackProbeType::Inline;
98
base.linker = Some("amd64-helenos-gcc".into());
109
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
1110

@@ -15,7 +14,7 @@ pub(crate) fn target() -> Target {
1514
description: Some("64-bit HelenOS".into()),
1615
tier: Some(3),
1716
host_tools: Some(false),
18-
std: None,
17+
std: Some(true),
1918
},
2019
pointer_width: 64,
2120
data_layout:

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+
"aarch64-unknown-helenos",
37+
"armv5te-unknown-helenos-eabi",
3638
"i686-unknown-helenos",
3739
"x86_64-unknown-helenos",
3840
// just a dummy comment so the list doesn't get onelined

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

Lines changed: 3 additions & 1 deletion
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
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,7 +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]
316-
[`i686-unknown-helenos`](platform-support/helenos.md) | ? | | HelenOS IA-32
318+
[`i686-unknown-helenos`](platform-support/helenos.md) | ? | | 32-bit (IA-32) HelenOS
317319
[`i686-unknown-hurd-gnu`](platform-support/hurd.md) | ✓ | ✓ | 32-bit GNU/Hurd (Pentium 4) [^x86_32-floats-return-ABI]
318320
[`i686-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/i386 (Pentium 4) [^x86_32-floats-return-ABI]
319321
[`i686-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 32-bit OpenBSD (Pentium 4) [^x86_32-floats-return-ABI]

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,36 @@ You need to have a local clone of the HelenOS repository and the HelenOS toolcha
2626

2727
### HelenOS toolchain setup
2828

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.
29+
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.
3030

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:
31+
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:
3232

3333
```sh
3434
touch /tmp/test.c
35-
i686-helenos-gcc -v -c /tmp/test.c 2>&1 | grep LIBRARY_PATH
35+
HELENOS_LIB_PATH="$(realpath "$(i686-helenos-gcc -v -c /tmp/test.c 2>&1 | grep LIBRARY_PATH | cut -d= -f2 | cut -d: -f3)")"
36+
# use amd64-helenos-gcc above for x86_64 toolchain, etc
37+
cp export-dev/lib/* dist/lib/libc.so.0 dist/lib/libposix.so.0 "$HELENOS_LIB_PATH"
38+
ln -s libposix.so.0 "$HELENOS_LIB_PATH/libposix.so"
39+
ln -s libc.so.0 "$HELENOS_LIB_PATH/libc.so"
3640
```
3741

42+
This automatically determines the library path, copies the libraries, and creates the necessary unversioned shared library symlinks.
43+
3844
### Building the target
3945

4046
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).
4147

48+
In the most simple case, this means that you can run `./x build library --stage 1 --target x86_64-unknown-linux-gnu,i686-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.
49+
4250
### Building Rust programs
4351

44-
Use the toolchain that you have built above and run `cargo build --target <arch>-unknown-helenos`.
52+
If you linked the toolchain above as `mytoolchain`, run `cargo +mytoolchain build --target <arch>-unknown-helenos`.
4553

4654
## Testing
4755

4856
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.
4957

50-
Running the Rust testsuite has not been attempted yet due to missing host tools and networking code.
58+
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).
5159

5260
## Cross-compilation toolchains and C code
5361

0 commit comments

Comments
 (0)