Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Trusty OS as tier 3 target #103895

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Trusty OS target for AArch64.

use super::{
crt_objects::LinkSelfContainedDefault, PanicStrategy, RelroLevel, Target, TargetOptions,
};

pub fn target() -> Target {
Target {
llvm_target: "aarch64-unknown-unknown-musl".into(),
pointer_width: 64,
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
options: TargetOptions {
features: "+neon,+fp-armv8,+reserve-x18".into(),
executables: true,
max_atomic_width: Some(128),
panic_strategy: PanicStrategy::Abort,
os: "trusty".into(),
position_independent_executables: true,
randomPoison marked this conversation as resolved.
Show resolved Hide resolved
static_position_independent_executables: true,
crt_static_default: true,
crt_static_respected: true,
randomPoison marked this conversation as resolved.
Show resolved Hide resolved
dynamic_linking: false,
link_self_contained: LinkSelfContainedDefault::Musl,
relro_level: RelroLevel::Full,
mcount: "\u{1}_mcount".into(),
..Default::default()
},
}
}
33 changes: 33 additions & 0 deletions compiler/rustc_target/src/spec/armv7_unknown_trusty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::spec::{Target, TargetOptions};

use super::{crt_objects::LinkSelfContainedDefault, PanicStrategy, RelroLevel};

pub fn target() -> Target {
Target {
// It's important we use "gnueabi" and not "musleabi" here. LLVM uses it
// to determine the calling convention and float ABI, and it doesn't
// support the "musleabi" value.
llvm_target: "armv7-unknown-unknown-gnueabi".into(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? unknown-unknown instead of e.g. unknown-linux? That makes sense to LLVM? Huh. Learn something new every day.

pointer_width: 32,
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
arch: "arm".into(),
options: TargetOptions {
abi: "eabi".into(),
features: "+v7,+thumb2,+soft-float,-neon,+reserve-x18".into(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly surprised to see this target enables Thumb instructions but is not named thumbv7.

Copy link

@thedataking thedataking Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+reserve-x18: Wondering if this is a cut-and-paste error. Only aarch64 has a x18 register.

max_atomic_width: Some(64),
mcount: "\u{1}mcount".into(),
os: "trusty".into(),
link_self_contained: LinkSelfContainedDefault::Musl,
randomPoison marked this conversation as resolved.
Show resolved Hide resolved
dynamic_linking: false,
executables: true,
crt_static_default: true,
crt_static_respected: true,
relro_level: RelroLevel::Full,
panic_strategy: PanicStrategy::Abort,
position_independent_executables: true,
static_position_independent_executables: true,

..Default::default()
},
}
}
3 changes: 3 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,9 @@ supported_targets! {
("aarch64-unknown-hermit", aarch64_unknown_hermit),
("x86_64-unknown-hermit", x86_64_unknown_hermit),

("armv7-unknown-trusty", armv7_unknown_trusty),
("aarch64-unknown-trusty", aarch64_unknown_trusty),

("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf),
("riscv32im-unknown-none-elf", riscv32im_unknown_none_elf),
("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/tests/tests_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Target {
assert!(self.executables);
}

// Check crt static stuff
// Check crt static stuff.
if self.crt_static_default || self.crt_static_allows_dylibs {
assert!(self.crt_static_respected);
}
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
- [\*-android and \*-androideabi](platform-support/android.md)
- [\*-unknown-fuchsia](platform-support/fuchsia.md)
- [\*-unknown-trusty](platform-support/trusty.md)
- [\*-kmc-solid_\*](platform-support/kmc-solid.md)
- [m68k-unknown-linux-gnu](platform-support/m68k-unknown-linux-gnu.md)
- [mips64-openwrt-linux-musl](platform-support/mips64-openwrt-linux-musl.md)
Expand Down
2 changes: 2 additions & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ target | std | host | notes
`aarch64-unknown-netbsd` | ✓ | ✓ |
[`aarch64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | ARM64 OpenBSD
`aarch64-unknown-redox` | ? | | ARM64 Redox OS
[`aarch64-unknown-trusty`](platform-support/trusty.md) | ? | |
`aarch64-uwp-windows-msvc` | ? | |
`aarch64-wrs-vxworks` | ? | |
`aarch64_be-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (big-endian, ILP32 ABI)
Expand All @@ -242,6 +243,7 @@ target | std | host | notes
[`armv7-unknown-linux-uclibceabihf`](platform-support/armv7-unknown-linux-uclibceabihf.md) | ✓ | ? | ARMv7 Linux with uClibc, hardfloat
`armv7-unknown-freebsd` | ✓ | ✓ | ARMv7 FreeBSD
`armv7-unknown-netbsd-eabihf` | ✓ | ✓ |
[`armv7-unknown-trusty`](platform-support/trusty.md) | ? | |
`armv7-wrs-vxworks-eabihf` | ? | |
[`armv7a-kmc-solid_asp3-eabi`](platform-support/kmc-solid.md) | ✓ | | ARM SOLID with TOPPERS/ASP3
[`armv7a-kmc-solid_asp3-eabihf`](platform-support/kmc-solid.md) | ✓ | | ARM SOLID with TOPPERS/ASP3, hardfloat
Expand Down
53 changes: 53 additions & 0 deletions src/doc/rustc/src/platform-support/trusty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# `aarch64-unknown-trusty` and `armv7-unknown-trusty`

**Tier: 3**

[Trusty] is a secure Operating System that provides a Trusted Execution
Environment (TEE) for Android.

## Target maintainers

- Nicole LeGare (@randomPoison)
- Stephen Crane (@rinon)
- As a fallback [email protected] can be contacted

## Requirements

This target is cross-compiled. It has no special requirements for the host.

It fully supports alloc with the default allocator, and partially supports std.
Notably, most I/O functionality is not supported, e.g. filesystem support and
networking support are not present and any APIs that rely on them will panic at
runtime.

Trusty uses the ELF file format.

## Building the target

The targets can be built by enabling them for a `rustc` build, for example:

```toml
[build]
build-stage = 1
target = ["aarch64-unknown-trusty", "armv7-unknown-trusty"]
```

## Building Rust programs

There is currently no supported way to build a Trusty app with Cargo. You can
follow the [Trusty build instructions] to build the Trusty kernel along with any
Rust apps that are setup in the project.

## Testing

See the [Trusty build instructions] for information on how to build Rust code
within the main Trusty project. The main project also includes infrastructure
for testing Rust applications within a QEMU emulator.

## Cross-compilation toolchains and C code

See the [Trusty build instructions] for information on how C code is built
within Trusty.

[Trusty]: https://source.android.com/docs/security/features/trusty
[Trusty build instructions]: https://source.android.com/docs/security/features/trusty/download-and-build
2 changes: 1 addition & 1 deletion tests/ui/check-cfg/well-known-values.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | #[cfg(target_os = "linuz")]
| |
| help: did you mean: `"linux"`
|
= 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
= 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, trusty, tvos, uefi, unknown, vita, vxworks, wasi, watchos, windows, xous
= note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition value
Expand Down