Skip to content

Commit dbdf43b

Browse files
authored
Rollup merge of rust-lang#113480 - Sword-Destiny:master, r=petrochenkov
add aarch64-unknown-teeos target TEEOS is a mini os run in TrustZone, for trusted/security apps. The libc of TEEOS is a part of musl. The kernel of TEEOS is micro kernel. This MR is to add a target for teeos. MRs for libc and rust-std are in progress. Compiler team MCP: [MCP](rust-lang/compiler-team#652)
2 parents b43fc1e + 72dd53c commit dbdf43b

File tree

9 files changed

+153
-3
lines changed

9 files changed

+153
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use crate::spec::Target;
2+
3+
pub fn target() -> Target {
4+
let mut base = super::teeos_base::opts();
5+
base.features = "+strict-align,+neon,+fp-armv8".into();
6+
base.max_atomic_width = Some(128);
7+
base.linker = Some("aarch64-linux-gnu-ld".into());
8+
9+
Target {
10+
llvm_target: "aarch64-unknown-none".into(),
11+
pointer_width: 64,
12+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
13+
arch: "aarch64".into(),
14+
options: base,
15+
}
16+
}

compiler/rustc_target/src/spec/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ mod openbsd_base;
8383
mod redox_base;
8484
mod solaris_base;
8585
mod solid_base;
86+
mod teeos_base;
8687
mod thumb_base;
8788
mod uefi_msvc_base;
8889
mod unikraft_linux_musl_base;
@@ -1494,6 +1495,8 @@ supported_targets! {
14941495

14951496
("x86_64-unknown-none", x86_64_unknown_none),
14961497

1498+
("aarch64-unknown-teeos", aarch64_unknown_teeos),
1499+
14971500
("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl),
14981501

14991502
("aarch64-unknown-nto-qnx710", aarch64_unknown_nto_qnx_710),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use super::{Cc, LinkerFlavor, Lld, PanicStrategy};
2+
use crate::spec::{RelroLevel, TargetOptions};
3+
4+
pub fn opts() -> TargetOptions {
5+
let lld_args = &["-zmax-page-size=4096", "-znow", "-ztext", "--execute-only"];
6+
let cc_args = &["-Wl,-zmax-page-size=4096", "-Wl,-znow", "-Wl,-ztext", "-mexecute-only"];
7+
8+
let mut pre_link_args = TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), lld_args);
9+
super::add_link_args(&mut pre_link_args, LinkerFlavor::Gnu(Cc::Yes, Lld::No), cc_args);
10+
11+
TargetOptions {
12+
os: "teeos".into(),
13+
vendor: "unknown".into(),
14+
dynamic_linking: true,
15+
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
16+
// rpath hardcodes -Wl, so it can't be used together with ld.lld.
17+
// C TAs also don't support rpath, so this is fine.
18+
has_rpath: false,
19+
// Note: Setting has_thread_local to true causes an error when
20+
// loading / dyn-linking the TA
21+
has_thread_local: false,
22+
position_independent_executables: true,
23+
relro_level: RelroLevel::Full,
24+
crt_static_respected: true,
25+
pre_link_args,
26+
panic_strategy: PanicStrategy::Abort,
27+
..Default::default()
28+
}
29+
}

src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &'static str, Option<&[&'static str]>)]
133133
// #[cfg(bootstrap)]
134134
(Some(Mode::Std), "target_vendor", Some(&["unikraft"])),
135135
(Some(Mode::Std), "target_env", Some(&["libnx"])),
136-
// (Some(Mode::Std), "target_os", Some(&[])),
136+
(Some(Mode::Std), "target_os", Some(&["teeos"])),
137137
// #[cfg(bootstrap)] mips32r6, mips64r6
138138
(
139139
Some(Mode::Std),

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
2929
- [\*-android and \*-androideabi](platform-support/android.md)
3030
- [\*-linux-ohos](platform-support/openharmony.md)
31+
- [aarch64-unknown-teeos](platform-support/aarch64-unknown-teeos.md)
3132
- [\*-esp-espidf](platform-support/esp-idf.md)
3233
- [\*-unknown-fuchsia](platform-support/fuchsia.md)
3334
- [\*-kmc-solid_\*](platform-support/kmc-solid.md)

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

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ target | std | host | notes
221221
[`aarch64-nintendo-switch-freestanding`](platform-support/aarch64-nintendo-switch-freestanding.md) | * | | ARM64 Nintendo Switch, Horizon
222222
[`aarch64-pc-windows-gnullvm`](platform-support/pc-windows-gnullvm.md) | ✓ | ✓ |
223223
[`aarch64-unknown-linux-ohos`](platform-support/openharmony.md) | ✓ | | ARM64 OpenHarmony |
224+
[`aarch64-unknown-teeos`](platform-support/aarch64-unknown-teeos.md) | ? | | ARM64 TEEOS |
224225
[`aarch64-unknown-nto-qnx710`](platform-support/nto-qnx.md) | ✓ | | ARM64 QNX Neutrino 7.1 RTOS |
225226
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
226227
[`aarch64-unknown-hermit`](platform-support/hermit.md) | ✓ | | ARM64 Hermit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# `aarch64-unknown-teeos`
2+
3+
**Tier: 3**
4+
5+
Target for the TEEOS operating system.
6+
7+
TEEOS is a mini os run in TrustZone, for trusted/security apps. The kernel of TEEOS is HongMeng/ChCore micro kernel. The libc for TEEOS is a part of musl.
8+
It's very small that there is no RwLock, no network, no stdin, and no file system for apps in TEEOS.
9+
10+
Some abbreviation:
11+
| Abbreviation | The full text | Description |
12+
| ---- | ---- | ---- |
13+
| TEE | Trusted Execution Environment | ARM TrustZone devide the system into two worlds/modes -- the secure world/mode and the normal world/mode. TEE is in the secure world/mode. |
14+
| REE | Rich Execution Environment | The normal world. for example, Linux for Android phone is in REE side. |
15+
| TA | Trusted Application | The app run in TEE side system. |
16+
| CA | Client Application | The progress run in REE side system. |
17+
18+
TEEOS is open source in progress. [MORE about](https://gitee.com/opentrustee-group)
19+
20+
## Target maintainers
21+
22+
- Petrochenkov Vadim
23+
- Sword-Destiny
24+
25+
## Setup
26+
We use OpenHarmony SDK for TEEOS.
27+
28+
The OpenHarmony SDK doesn't currently support Rust compilation directly, so
29+
some setup is required.
30+
31+
First, you must obtain the OpenHarmony SDK from [this page](https://gitee.com/openharmony/docs/tree/master/en/release-notes).
32+
Select the version of OpenHarmony you are developing for and download the "Public SDK package for the standard system".
33+
34+
Create the following shell scripts that wrap Clang from the OpenHarmony SDK:
35+
36+
`aarch64-unknown-teeos-clang.sh`
37+
38+
```sh
39+
#!/bin/sh
40+
exec /path/to/ohos-sdk/linux/native/llvm/bin/clang \
41+
--target aarch64-linux-gnu \
42+
"$@"
43+
```
44+
45+
`aarch64-unknown-teeos-clang++.sh`
46+
47+
```sh
48+
#!/bin/sh
49+
exec /path/to/ohos-sdk/linux/native/llvm/bin/clang++ \
50+
--target aarch64-linux-gnu \
51+
"$@"
52+
```
53+
54+
## Building the target
55+
56+
To build a rust toolchain, create a `config.toml` with the following contents:
57+
58+
```toml
59+
profile = "compiler"
60+
changelog-seen = 2
61+
62+
[build]
63+
sanitizers = true
64+
profiler = true
65+
target = ["x86_64-unknown-linux-gnu", "aarch64-unknown-teeos"]
66+
submodules = false
67+
compiler-docs = false
68+
extended = true
69+
70+
[install]
71+
bindir = "bin"
72+
libdir = "lib"
73+
74+
[target.aarch64-unknown-teeos]
75+
cc = "/path/to/scripts/aarch64-unknown-teeos-clang.sh"
76+
cxx = "/path/to/scripts/aarch64-unknown-teeos-clang.sh"
77+
linker = "/path/to/scripts/aarch64-unknown-teeos-clang.sh"
78+
ar = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ar"
79+
ranlib = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-ranlib"
80+
llvm-config = "/path/to/ohos-sdk/linux/native/llvm/bin/llvm-config"
81+
```
82+
83+
## Building Rust programs
84+
85+
Rust does not yet ship pre-compiled artifacts for this target. To compile for
86+
this target, you will either need to build Rust with the target enabled (see
87+
"Building the target" above), or build your own copy of `core` by using
88+
`build-std` or similar.
89+
90+
You will need to configure the linker to use in `~/.cargo/config`:
91+
```toml
92+
[target.aarch64-unknown-teeos]
93+
linker = "/path/to/aarch64-unknown-teeos-clang.sh"
94+
```
95+
96+
## Testing
97+
98+
Running the Rust testsuite is not possible now.
99+
100+
More information about how to test CA/TA. [See here](https://gitee.com/openharmony-sig/tee_tee_dev_kit/tree/master/docs)

tests/ui/check-cfg/values-target-json.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | #[cfg(target_os = "linuz")]
66
| |
77
| help: there is a expected value with a similar name: `"linux"`
88
|
9-
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `ericos`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
9+
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `ericos`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: 1 warning emitted

tests/ui/check-cfg/well-known-values.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | #[cfg(target_os = "linuz")]
66
| |
77
| help: there is a expected value with a similar name: `"linux"`
88
|
9-
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
9+
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: unexpected `cfg` condition value

0 commit comments

Comments
 (0)