From dcd0c587b799110481d48bf4fd42cb9be937a69f Mon Sep 17 00:00:00 2001 From: David LeGare Date: Thu, 13 Oct 2022 13:37:07 -0700 Subject: [PATCH 1/8] Add Trusty OS as tier 3 target --- Cargo.toml | 2 + .../src/spec/aarch64_unknown_trusty.rs | 27 +++++++ .../src/spec/armv7_unknown_trusty.rs | 31 +++++++ compiler/rustc_target/src/spec/mod.rs | 3 + library/core/src/ffi/mod.rs | 4 + library/std/build.rs | 1 + library/std/src/sys/mod.rs | 3 + library/std/src/sys/trusty/mod.rs | 42 ++++++++++ library/std/src/sys/trusty/stdio.rs | 81 +++++++++++++++++++ .../std/src/sys/trusty/thread_local_key.rs | 31 +++++++ library/std/src/sys_common/mod.rs | 1 + src/bootstrap/lib.rs | 3 +- src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 2 + src/doc/rustc/src/platform-support/trusty.md | 51 ++++++++++++ 15 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs create mode 100644 compiler/rustc_target/src/spec/armv7_unknown_trusty.rs create mode 100644 library/std/src/sys/trusty/mod.rs create mode 100644 library/std/src/sys/trusty/stdio.rs create mode 100644 library/std/src/sys/trusty/thread_local_key.rs create mode 100644 src/doc/rustc/src/platform-support/trusty.md diff --git a/Cargo.toml b/Cargo.toml index 15cbb2659c9b3..0d42210f0f67e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -115,5 +115,7 @@ rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' } rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' } rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' } +libc = { git = "https://github.com/randomPoison/libc.git", rev = "7ccd2753aa1e26301c73bdb6f9e2df8085ac39e6" } + [patch."https://github.com/rust-lang/rust-clippy"] clippy_lints = { path = "src/tools/clippy/clippy_lints" } diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs b/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs new file mode 100644 index 0000000000000..f1d4f69abcbfe --- /dev/null +++ b/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs @@ -0,0 +1,27 @@ +// Trusty OS target for AArch64. + +use super::{PanicStrategy, RelroLevel, Target, TargetOptions}; + +pub fn target() -> Target { + Target { + llvm_target: "aarch64-unknown-linux-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".into(), + executables: true, + max_atomic_width: Some(128), + panic_strategy: PanicStrategy::Abort, + os: "trusty".into(), + position_independent_executables: true, + crt_static_default: true, + crt_static_respected: true, + dynamic_linking: false, + env: "musl".into(), + relro_level: RelroLevel::Full, + mcount: "\u{1}_mcount".into(), + ..Default::default() + }, + } +} diff --git a/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs b/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs new file mode 100644 index 0000000000000..e688f593683f7 --- /dev/null +++ b/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs @@ -0,0 +1,31 @@ +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-linux-gnueabi".into(), + 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".into(), + max_atomic_width: Some(64), + mcount: "\u{1}mcount".into(), + os: "trusty".into(), + env: "musl".into(), + link_self_contained: LinkSelfContainedDefault::Musl, + dynamic_linking: false, + executables: true, + relro_level: RelroLevel::Full, + panic_strategy: PanicStrategy::Abort, + position_independent_executables: true, + + ..Default::default() + }, + } +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index a094c2c545269..f3c7952b7a8e9 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -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), diff --git a/library/core/src/ffi/mod.rs b/library/core/src/ffi/mod.rs index 76daceecd7bef..c83d45520ab2d 100644 --- a/library/core/src/ffi/mod.rs +++ b/library/core/src/ffi/mod.rs @@ -144,6 +144,10 @@ mod c_char_definition { ) ), all(target_os = "fuchsia", target_arch = "aarch64"), + all( + target_os = "trusty", + any(target_arch = "aarch64", target_arch = "arm") + ), target_os = "horizon" ))] { pub type c_char = u8; diff --git a/library/std/build.rs b/library/std/build.rs index 8b1a06ee750fb..c0594b9b176e3 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -21,6 +21,7 @@ fn main() { || target.contains("fuchsia") || (target.contains("sgx") && target.contains("fortanix")) || target.contains("hermit") + || target.contains("trusty") || target.contains("l4re") || target.contains("redox") || target.contains("haiku") diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index c080c176a2ace..acd483f243f84 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -37,6 +37,9 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "hermit")] { mod hermit; pub use self::hermit::*; + } else if #[cfg(target_os = "trusty")] { + mod trusty; + pub use self::trusty::*; } else if #[cfg(target_os = "wasi")] { mod wasi; pub use self::wasi::*; diff --git a/library/std/src/sys/trusty/mod.rs b/library/std/src/sys/trusty/mod.rs new file mode 100644 index 0000000000000..9e97c315e450c --- /dev/null +++ b/library/std/src/sys/trusty/mod.rs @@ -0,0 +1,42 @@ +//! System bindings for the Trusty OS. + +#[path = "../unix/alloc.rs"] +pub mod alloc; +#[path = "../unsupported/args.rs"] +pub mod args; +#[path = "../unix/cmath.rs"] +pub mod cmath; +#[path = "../unsupported/common.rs"] +#[deny(unsafe_op_in_unsafe_fn)] +mod common; +#[path = "../unsupported/env.rs"] +pub mod env; +#[path = "../unsupported/fs.rs"] +pub mod fs; +#[path = "../unsupported/io.rs"] +pub mod io; +#[path = "../unsupported/locks/mod.rs"] +pub mod locks; +#[path = "../unsupported/net.rs"] +pub mod net; +#[path = "../unsupported/os.rs"] +pub mod os; +#[path = "../unix/os_str.rs"] +pub mod os_str; +#[path = "../unix/path.rs"] +pub mod path; +#[path = "../unsupported/pipe.rs"] +pub mod pipe; +#[path = "../unsupported/process.rs"] +pub mod process; +pub mod stdio; +#[path = "../unsupported/thread.rs"] +pub mod thread; +#[cfg(target_thread_local)] +#[path = "../unsupported/thread_local_dtor.rs"] +pub mod thread_local_dtor; +pub mod thread_local_key; +#[path = "../unsupported/time.rs"] +pub mod time; + +pub use common::*; diff --git a/library/std/src/sys/trusty/stdio.rs b/library/std/src/sys/trusty/stdio.rs new file mode 100644 index 0000000000000..d393e95394d1a --- /dev/null +++ b/library/std/src/sys/trusty/stdio.rs @@ -0,0 +1,81 @@ +use crate::io; + +pub struct Stdin; +pub struct Stdout; +pub struct Stderr; + +impl Stdin { + pub const fn new() -> Stdin { + Stdin + } +} + +impl io::Read for Stdin { + fn read(&mut self, _buf: &mut [u8]) -> io::Result { + Ok(0) + } +} + +impl Stdout { + pub const fn new() -> Stdout { + Stdout + } +} + +impl io::Write for Stdout { + fn write(&mut self, buf: &[u8]) -> io::Result { + _write(libc::STDOUT_FILENO, buf) + } + + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} + +impl Stderr { + pub const fn new() -> Stderr { + Stderr + } +} + +impl io::Write for Stderr { + fn write(&mut self, buf: &[u8]) -> io::Result { + _write(libc::STDERR_FILENO, buf) + } + + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} + +pub const STDIN_BUF_SIZE: usize = 0; + +pub fn is_ebadf(_err: &io::Error) -> bool { + true +} + +pub fn panic_output() -> Option { + Some(Stderr) +} + +fn _write(fd: i32, message: &[u8]) -> io::Result { + let mut iov = libc::iovec { iov_base: message.as_ptr() as *mut _, iov_len: message.len() }; + loop { + // SAFETY: syscall, safe arguments. + let ret = unsafe { libc::writev(fd, &iov, 1) }; + if ret < 0 { + return Err(io::Error::last_os_error()); + } + let ret = ret as usize; + if ret > iov.iov_len { + return Err(io::Error::last_os_error()); + } + if ret == iov.iov_len { + return Ok(message.len()); + } + // SAFETY: ret has been checked to be less than the length of + // the buffer + iov.iov_base = unsafe { iov.iov_base.add(ret) }; + iov.iov_len -= ret; + } +} diff --git a/library/std/src/sys/trusty/thread_local_key.rs b/library/std/src/sys/trusty/thread_local_key.rs new file mode 100644 index 0000000000000..56e14f71367ac --- /dev/null +++ b/library/std/src/sys/trusty/thread_local_key.rs @@ -0,0 +1,31 @@ +use crate::ptr; + +pub type Key = usize; +type Dtor = unsafe extern "C" fn(*mut u8); + +static mut STORAGE: crate::vec::Vec<(*mut u8, Option)> = Vec::new(); + +#[inline] +pub unsafe fn create(dtor: Option) -> Key { + let key = STORAGE.len(); + STORAGE.push((ptr::null_mut(), dtor)); + key +} + +#[inline] +pub unsafe fn set(key: Key, value: *mut u8) { + STORAGE[key].0 = value; +} + +#[inline] +pub unsafe fn get(key: Key) -> *mut u8 { + STORAGE[key].0 +} + +#[inline] +pub unsafe fn destroy(_key: Key) {} + +#[inline] +pub fn requires_synchronized_create() -> bool { + false +} diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs index 6b24b0e9aa8be..753979c529cef 100644 --- a/library/std/src/sys_common/mod.rs +++ b/library/std/src/sys_common/mod.rs @@ -45,6 +45,7 @@ cfg_if::cfg_if! { cfg_if::cfg_if! { if #[cfg(any(target_os = "l4re", target_os = "hermit", + target_os = "trusty", feature = "restricted-std", all(target_family = "wasm", not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))] { diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 267aa3278d8ff..9b14164d8ee99 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -213,7 +213,8 @@ const EXTRA_CHECK_CFGS: &[(Option, &'static str, Option<&[&'static str]>)] (Some(Mode::Std), "backtrace_in_libstd", None), /* Extra values not defined in the built-in targets yet, but used in std */ (Some(Mode::Std), "target_env", Some(&["libnx"])), - // (Some(Mode::Std), "target_os", Some(&[])), + // #[cfg(bootstrap)] trusty + (Some(Mode::Std), "target_os", Some(&["trusty"])), (Some(Mode::Std), "target_arch", Some(&["asmjs", "spirv", "nvptx", "xtensa"])), /* Extra names used by dependencies */ // FIXME: Used by serde_json, but we should not be triggering on external dependencies. diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 752f1cc4aba03..b01a0b50d39eb 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -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) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 16057048259bf..65578b68be724 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -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) @@ -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 diff --git a/src/doc/rustc/src/platform-support/trusty.md b/src/doc/rustc/src/platform-support/trusty.md new file mode 100644 index 0000000000000..3ab0323b2a78e --- /dev/null +++ b/src/doc/rustc/src/platform-support/trusty.md @@ -0,0 +1,51 @@ +# `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 + +- David LeGare, `dgl@immunant.com`, https://github.com/randomPoison + +## 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 From f1971456d19349f3143a1e57d384f878caf61717 Mon Sep 17 00:00:00 2001 From: Nicole L Date: Tue, 31 Jan 2023 11:38:40 -0800 Subject: [PATCH 2/8] Revert libstd support for Trusty --- Cargo.toml | 2 - library/core/src/ffi/mod.rs | 4 - library/std/build.rs | 1 - library/std/src/sys/mod.rs | 3 - library/std/src/sys/trusty/mod.rs | 42 ---------- library/std/src/sys/trusty/stdio.rs | 81 ------------------- .../std/src/sys/trusty/thread_local_key.rs | 31 ------- library/std/src/sys_common/mod.rs | 1 - src/bootstrap/lib.rs | 3 +- 9 files changed, 1 insertion(+), 167 deletions(-) delete mode 100644 library/std/src/sys/trusty/mod.rs delete mode 100644 library/std/src/sys/trusty/stdio.rs delete mode 100644 library/std/src/sys/trusty/thread_local_key.rs diff --git a/Cargo.toml b/Cargo.toml index 0d42210f0f67e..15cbb2659c9b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -115,7 +115,5 @@ rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' } rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' } rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' } -libc = { git = "https://github.com/randomPoison/libc.git", rev = "7ccd2753aa1e26301c73bdb6f9e2df8085ac39e6" } - [patch."https://github.com/rust-lang/rust-clippy"] clippy_lints = { path = "src/tools/clippy/clippy_lints" } diff --git a/library/core/src/ffi/mod.rs b/library/core/src/ffi/mod.rs index c83d45520ab2d..76daceecd7bef 100644 --- a/library/core/src/ffi/mod.rs +++ b/library/core/src/ffi/mod.rs @@ -144,10 +144,6 @@ mod c_char_definition { ) ), all(target_os = "fuchsia", target_arch = "aarch64"), - all( - target_os = "trusty", - any(target_arch = "aarch64", target_arch = "arm") - ), target_os = "horizon" ))] { pub type c_char = u8; diff --git a/library/std/build.rs b/library/std/build.rs index c0594b9b176e3..8b1a06ee750fb 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -21,7 +21,6 @@ fn main() { || target.contains("fuchsia") || (target.contains("sgx") && target.contains("fortanix")) || target.contains("hermit") - || target.contains("trusty") || target.contains("l4re") || target.contains("redox") || target.contains("haiku") diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index acd483f243f84..c080c176a2ace 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -37,9 +37,6 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "hermit")] { mod hermit; pub use self::hermit::*; - } else if #[cfg(target_os = "trusty")] { - mod trusty; - pub use self::trusty::*; } else if #[cfg(target_os = "wasi")] { mod wasi; pub use self::wasi::*; diff --git a/library/std/src/sys/trusty/mod.rs b/library/std/src/sys/trusty/mod.rs deleted file mode 100644 index 9e97c315e450c..0000000000000 --- a/library/std/src/sys/trusty/mod.rs +++ /dev/null @@ -1,42 +0,0 @@ -//! System bindings for the Trusty OS. - -#[path = "../unix/alloc.rs"] -pub mod alloc; -#[path = "../unsupported/args.rs"] -pub mod args; -#[path = "../unix/cmath.rs"] -pub mod cmath; -#[path = "../unsupported/common.rs"] -#[deny(unsafe_op_in_unsafe_fn)] -mod common; -#[path = "../unsupported/env.rs"] -pub mod env; -#[path = "../unsupported/fs.rs"] -pub mod fs; -#[path = "../unsupported/io.rs"] -pub mod io; -#[path = "../unsupported/locks/mod.rs"] -pub mod locks; -#[path = "../unsupported/net.rs"] -pub mod net; -#[path = "../unsupported/os.rs"] -pub mod os; -#[path = "../unix/os_str.rs"] -pub mod os_str; -#[path = "../unix/path.rs"] -pub mod path; -#[path = "../unsupported/pipe.rs"] -pub mod pipe; -#[path = "../unsupported/process.rs"] -pub mod process; -pub mod stdio; -#[path = "../unsupported/thread.rs"] -pub mod thread; -#[cfg(target_thread_local)] -#[path = "../unsupported/thread_local_dtor.rs"] -pub mod thread_local_dtor; -pub mod thread_local_key; -#[path = "../unsupported/time.rs"] -pub mod time; - -pub use common::*; diff --git a/library/std/src/sys/trusty/stdio.rs b/library/std/src/sys/trusty/stdio.rs deleted file mode 100644 index d393e95394d1a..0000000000000 --- a/library/std/src/sys/trusty/stdio.rs +++ /dev/null @@ -1,81 +0,0 @@ -use crate::io; - -pub struct Stdin; -pub struct Stdout; -pub struct Stderr; - -impl Stdin { - pub const fn new() -> Stdin { - Stdin - } -} - -impl io::Read for Stdin { - fn read(&mut self, _buf: &mut [u8]) -> io::Result { - Ok(0) - } -} - -impl Stdout { - pub const fn new() -> Stdout { - Stdout - } -} - -impl io::Write for Stdout { - fn write(&mut self, buf: &[u8]) -> io::Result { - _write(libc::STDOUT_FILENO, buf) - } - - fn flush(&mut self) -> io::Result<()> { - Ok(()) - } -} - -impl Stderr { - pub const fn new() -> Stderr { - Stderr - } -} - -impl io::Write for Stderr { - fn write(&mut self, buf: &[u8]) -> io::Result { - _write(libc::STDERR_FILENO, buf) - } - - fn flush(&mut self) -> io::Result<()> { - Ok(()) - } -} - -pub const STDIN_BUF_SIZE: usize = 0; - -pub fn is_ebadf(_err: &io::Error) -> bool { - true -} - -pub fn panic_output() -> Option { - Some(Stderr) -} - -fn _write(fd: i32, message: &[u8]) -> io::Result { - let mut iov = libc::iovec { iov_base: message.as_ptr() as *mut _, iov_len: message.len() }; - loop { - // SAFETY: syscall, safe arguments. - let ret = unsafe { libc::writev(fd, &iov, 1) }; - if ret < 0 { - return Err(io::Error::last_os_error()); - } - let ret = ret as usize; - if ret > iov.iov_len { - return Err(io::Error::last_os_error()); - } - if ret == iov.iov_len { - return Ok(message.len()); - } - // SAFETY: ret has been checked to be less than the length of - // the buffer - iov.iov_base = unsafe { iov.iov_base.add(ret) }; - iov.iov_len -= ret; - } -} diff --git a/library/std/src/sys/trusty/thread_local_key.rs b/library/std/src/sys/trusty/thread_local_key.rs deleted file mode 100644 index 56e14f71367ac..0000000000000 --- a/library/std/src/sys/trusty/thread_local_key.rs +++ /dev/null @@ -1,31 +0,0 @@ -use crate::ptr; - -pub type Key = usize; -type Dtor = unsafe extern "C" fn(*mut u8); - -static mut STORAGE: crate::vec::Vec<(*mut u8, Option)> = Vec::new(); - -#[inline] -pub unsafe fn create(dtor: Option) -> Key { - let key = STORAGE.len(); - STORAGE.push((ptr::null_mut(), dtor)); - key -} - -#[inline] -pub unsafe fn set(key: Key, value: *mut u8) { - STORAGE[key].0 = value; -} - -#[inline] -pub unsafe fn get(key: Key) -> *mut u8 { - STORAGE[key].0 -} - -#[inline] -pub unsafe fn destroy(_key: Key) {} - -#[inline] -pub fn requires_synchronized_create() -> bool { - false -} diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs index 753979c529cef..6b24b0e9aa8be 100644 --- a/library/std/src/sys_common/mod.rs +++ b/library/std/src/sys_common/mod.rs @@ -45,7 +45,6 @@ cfg_if::cfg_if! { cfg_if::cfg_if! { if #[cfg(any(target_os = "l4re", target_os = "hermit", - target_os = "trusty", feature = "restricted-std", all(target_family = "wasm", not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))] { diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 9b14164d8ee99..267aa3278d8ff 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -213,8 +213,7 @@ const EXTRA_CHECK_CFGS: &[(Option, &'static str, Option<&[&'static str]>)] (Some(Mode::Std), "backtrace_in_libstd", None), /* Extra values not defined in the built-in targets yet, but used in std */ (Some(Mode::Std), "target_env", Some(&["libnx"])), - // #[cfg(bootstrap)] trusty - (Some(Mode::Std), "target_os", Some(&["trusty"])), + // (Some(Mode::Std), "target_os", Some(&[])), (Some(Mode::Std), "target_arch", Some(&["asmjs", "spirv", "nvptx", "xtensa"])), /* Extra names used by dependencies */ // FIXME: Used by serde_json, but we should not be triggering on external dependencies. From 12053c9f64c99db13761509b0a31118d3ac9a2ac Mon Sep 17 00:00:00 2001 From: Nicole L Date: Tue, 31 Jan 2023 11:53:23 -0800 Subject: [PATCH 3/8] Address review feedback --- .../src/spec/aarch64_unknown_trusty.rs | 14 ++++++++------ .../rustc_target/src/spec/armv7_unknown_trusty.rs | 9 +++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs b/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs index f1d4f69abcbfe..847226de33284 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs @@ -1,24 +1,26 @@ // Trusty OS target for AArch64. -use super::{PanicStrategy, RelroLevel, Target, TargetOptions}; +use super::{ + crt_objects::LinkSelfContainedDefault, PanicStrategy, RelroLevel, Target, TargetOptions, +}; pub fn target() -> Target { Target { - llvm_target: "aarch64-unknown-linux-musl".into(), + 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".into(), + 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, + static_position_independent_executables: true, crt_static_default: true, - crt_static_respected: true, + crt_static_respected: false, dynamic_linking: false, - env: "musl".into(), + link_self_contained: LinkSelfContainedDefault::Musl, relro_level: RelroLevel::Full, mcount: "\u{1}_mcount".into(), ..Default::default() diff --git a/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs b/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs index e688f593683f7..9de2413016776 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs @@ -7,23 +7,24 @@ pub fn 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-linux-gnueabi".into(), + llvm_target: "armv7-unknown-unknown-gnueabi".into(), 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".into(), + features: "+v7,+thumb2,+soft-float,-neon,+reserve-x18".into(), max_atomic_width: Some(64), mcount: "\u{1}mcount".into(), os: "trusty".into(), - env: "musl".into(), link_self_contained: LinkSelfContainedDefault::Musl, dynamic_linking: false, executables: true, + crt_static_default: true, + crt_static_respected: false, relro_level: RelroLevel::Full, panic_strategy: PanicStrategy::Abort, - position_independent_executables: true, + static_position_independent_executables: true, ..Default::default() }, From c7f87525b4d9cedb51eb60f94174fb838b97a19a Mon Sep 17 00:00:00 2001 From: Nicole L Date: Tue, 31 Jan 2023 12:02:42 -0800 Subject: [PATCH 4/8] Update target maintainers list --- src/doc/rustc/src/platform-support/trusty.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support/trusty.md b/src/doc/rustc/src/platform-support/trusty.md index 3ab0323b2a78e..97a03d3de04c2 100644 --- a/src/doc/rustc/src/platform-support/trusty.md +++ b/src/doc/rustc/src/platform-support/trusty.md @@ -7,7 +7,9 @@ Environment (TEE) for Android. ## Target maintainers -- David LeGare, `dgl@immunant.com`, https://github.com/randomPoison +- Nicole LeGare (@randomPoison) +- Stephen Crane (@rinon) +- As a fallback trusty-dev-team@google.com can be contacted ## Requirements From 884f30775e730520727e3f23ad4ed884aea3878f Mon Sep 17 00:00:00 2001 From: Nicole L Date: Tue, 31 Jan 2023 13:17:48 -0800 Subject: [PATCH 5/8] Update UI tests to include trusty --- tests/ui/check-cfg/well-known-values.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index 69d799783a94b..ae738c32b7dfc 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -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 From 43c1e77800cc5e00aca7e39059d0b4f521acea27 Mon Sep 17 00:00:00 2001 From: Nicole L Date: Wed, 1 Feb 2023 13:57:32 -0800 Subject: [PATCH 6/8] Fix spec consistency issues for Trusty targets --- compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs | 1 + compiler/rustc_target/src/spec/armv7_unknown_trusty.rs | 1 + compiler/rustc_target/src/spec/tests/tests_impl.rs | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs b/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs index 847226de33284..344ed1db02ae7 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs @@ -16,6 +16,7 @@ pub fn target() -> Target { max_atomic_width: Some(128), panic_strategy: PanicStrategy::Abort, os: "trusty".into(), + position_independent_executables: true, static_position_independent_executables: true, crt_static_default: true, crt_static_respected: false, diff --git a/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs b/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs index 9de2413016776..fed2d28f0896a 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs @@ -24,6 +24,7 @@ pub fn target() -> Target { crt_static_respected: false, relro_level: RelroLevel::Full, panic_strategy: PanicStrategy::Abort, + position_independent_executables: true, static_position_independent_executables: true, ..Default::default() diff --git a/compiler/rustc_target/src/spec/tests/tests_impl.rs b/compiler/rustc_target/src/spec/tests/tests_impl.rs index e0ecf8037c3e5..08eb2c126ed82 100644 --- a/compiler/rustc_target/src/spec/tests/tests_impl.rs +++ b/compiler/rustc_target/src/spec/tests/tests_impl.rs @@ -143,8 +143,9 @@ impl Target { assert!(self.executables); } - // Check crt static stuff - if self.crt_static_default || self.crt_static_allows_dylibs { + // Check crt static stuff. Trusy only supports crt static and so does not enable + // `crt_static_respected`. + if (self.crt_static_default || self.crt_static_allows_dylibs) && self.os != "trusty" { assert!(self.crt_static_respected); } } From ab51f647a505c5868429f3137e65c90bdfc0a8bd Mon Sep 17 00:00:00 2001 From: Nicole L Date: Wed, 1 Feb 2023 14:17:03 -0800 Subject: [PATCH 7/8] Fix spelling --- compiler/rustc_target/src/spec/tests/tests_impl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/tests/tests_impl.rs b/compiler/rustc_target/src/spec/tests/tests_impl.rs index 08eb2c126ed82..21629be26866f 100644 --- a/compiler/rustc_target/src/spec/tests/tests_impl.rs +++ b/compiler/rustc_target/src/spec/tests/tests_impl.rs @@ -143,7 +143,7 @@ impl Target { assert!(self.executables); } - // Check crt static stuff. Trusy only supports crt static and so does not enable + // Check crt static stuff. Trusty only supports crt static and so does not enable // `crt_static_respected`. if (self.crt_static_default || self.crt_static_allows_dylibs) && self.os != "trusty" { assert!(self.crt_static_respected); From 83369cd339388dd4318f17e88b938471c09570f0 Mon Sep 17 00:00:00 2001 From: Nicole L Date: Fri, 3 Feb 2023 09:51:18 -0800 Subject: [PATCH 8/8] Revert crt_static changes --- compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs | 2 +- compiler/rustc_target/src/spec/armv7_unknown_trusty.rs | 2 +- compiler/rustc_target/src/spec/tests/tests_impl.rs | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs b/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs index 344ed1db02ae7..380b0b7d2207f 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_trusty.rs @@ -19,7 +19,7 @@ pub fn target() -> Target { position_independent_executables: true, static_position_independent_executables: true, crt_static_default: true, - crt_static_respected: false, + crt_static_respected: true, dynamic_linking: false, link_self_contained: LinkSelfContainedDefault::Musl, relro_level: RelroLevel::Full, diff --git a/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs b/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs index fed2d28f0896a..4784ae6cfac52 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_trusty.rs @@ -21,7 +21,7 @@ pub fn target() -> Target { dynamic_linking: false, executables: true, crt_static_default: true, - crt_static_respected: false, + crt_static_respected: true, relro_level: RelroLevel::Full, panic_strategy: PanicStrategy::Abort, position_independent_executables: true, diff --git a/compiler/rustc_target/src/spec/tests/tests_impl.rs b/compiler/rustc_target/src/spec/tests/tests_impl.rs index 21629be26866f..724d6cd1756dd 100644 --- a/compiler/rustc_target/src/spec/tests/tests_impl.rs +++ b/compiler/rustc_target/src/spec/tests/tests_impl.rs @@ -143,9 +143,8 @@ impl Target { assert!(self.executables); } - // Check crt static stuff. Trusty only supports crt static and so does not enable - // `crt_static_respected`. - if (self.crt_static_default || self.crt_static_allows_dylibs) && self.os != "trusty" { + // Check crt static stuff. + if self.crt_static_default || self.crt_static_allows_dylibs { assert!(self.crt_static_respected); } }