From e90d05f9785f7a5bbd15231d875be53c6113bcd7 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 31 Mar 2020 10:35:08 -0400 Subject: [PATCH 01/38] Fix NixOS --- src/bootstrap/bootstrap.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index c3f1bac177de7..f8077980c08de 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -470,8 +470,6 @@ def fix_bin_or_dylib(self, fname): if not os.path.exists("/etc/NIXOS"): return - if os.path.exists("/lib"): - return # At this point we're pretty sure the user is running NixOS nix_os_msg = "info: you seem to be running NixOS. Attempting to patch" From e07c6712cc459aecad1a7b97f3d0d282b62c661e Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 31 Mar 2020 10:35:23 -0400 Subject: [PATCH 02/38] Add aarch64-unknown-horizon-libnx target --- .../spec/aarch64_unknown_horizon_libnx.rs | 35 +++++++++++++++++++ src/librustc_target/spec/mod.rs | 1 + 2 files changed, 36 insertions(+) create mode 100644 src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs diff --git a/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs b/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs new file mode 100644 index 0000000000000..305b948740e84 --- /dev/null +++ b/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs @@ -0,0 +1,35 @@ +use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions}; + +pub fn target() -> Result { + let opts = TargetOptions { + linker: Some("aarch64-none-elf-gcc".to_owned()), + features: "+a53,+strict-align,+crc32".to_string(), + executables: true, + relocation_model: "pic".to_string(), + disable_redzone: true, + linker_is_gnu: true, + max_atomic_width: Some(128), + panic_strategy: PanicStrategy::Abort, + abi_blacklist: super::arm_base::abi_blacklist(), + target_family: Some("unix".to_string()), + position_independent_executables: true, + has_elf_tls: false, + trap_unreachable: true, + emit_debug_gdb_scripts: true, + requires_uwtable: true, + ..Default::default() + }; + Ok(Target { + llvm_target: "aarch64-unknown-none".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + target_os: "horizon".to_string(), + target_env: "newlib".to_string(), + target_vendor: String::new(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: opts, + }) +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 961a438fd233c..e1a5efe3e64db 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -678,6 +678,7 @@ supported_targets! { ("mipsel-sony-psp", mipsel_sony_psp), ("thumbv4t-none-eabi", thumbv4t_none_eabi), + ("aarch64-unknown-horizon-libnx", aarch64_unknown_horizon_libnx), } /// Everything `rustc` knows about how to compile for a specific target. From de95cc9b13fa472c719b13627ee90256924759b6 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 31 Mar 2020 11:27:33 -0400 Subject: [PATCH 03/38] Fix crc feature --- src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs b/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs index 305b948740e84..259d4a8217450 100644 --- a/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs +++ b/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs @@ -3,7 +3,7 @@ use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions}; pub fn target() -> Result { let opts = TargetOptions { linker: Some("aarch64-none-elf-gcc".to_owned()), - features: "+a53,+strict-align,+crc32".to_string(), + features: "+a53,+strict-align,+crc".to_string(), executables: true, relocation_model: "pic".to_string(), disable_redzone: true, From 9ebbfa4186fe2dc0c846ba79bb0e65ad84e3b650 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 31 Mar 2020 11:27:45 -0400 Subject: [PATCH 04/38] horizon is (currently) no_std --- src/bootstrap/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index d64ca95d24392..11bbe1c7062b6 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -244,7 +244,7 @@ pub struct Target { impl Target { pub fn from_triple(triple: &str) -> Self { let mut target: Self = Default::default(); - if triple.contains("-none") || triple.contains("nvptx") { + if triple.contains("-none") || triple.contains("nvptx") || triple.contains("horizon") { target.no_std = true; } target From 59daa56a31cc0a7ce03a6d2514ec7c3d3bf7fe64 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Sun, 12 Apr 2020 17:39:38 -0400 Subject: [PATCH 05/38] Port libstd to horizon/libnx --- library/std/Cargo.toml | 3 +- library/std/src/os/libnx/fs.rs | 312 +++++++++++++++ library/std/src/os/libnx/mod.rs | 6 + library/std/src/os/libnx/raw.rs | 363 ++++++++++++++++++ library/std/src/os/mod.rs | 2 + library/std/src/os/raw/mod.rs | 6 +- library/std/src/sys/unix/alloc.rs | 9 +- library/std/src/sys/unix/args.rs | 3 +- library/std/src/sys/unix/env.rs | 11 + library/std/src/sys/unix/ext/fs.rs | 15 + library/std/src/sys/unix/fd.rs | 7 +- library/std/src/sys/unix/fs.rs | 22 +- library/std/src/sys/unix/mod.rs | 2 + library/std/src/sys/unix/net.rs | 15 +- library/std/src/sys/unix/os.rs | 3 +- library/std/src/sys/unix/pipe.rs | 2 + library/std/src/sys/unix/process/mod.rs | 5 +- .../src/sys/unix/process/process_common.rs | 2 + .../std/src/sys/unix/process/process_dummy.rs | 94 +++++ library/std/src/sys/unix/time.rs | 4 +- library/std/src/sys/unix/weak.rs | 6 + library/std/src/sys_common/net.rs | 171 ++++++--- library/test/src/helpers/concurrency.rs | 6 + src/.gitignore | 1 + src/bootstrap/config.rs | 2 +- .../spec/aarch64_unknown_horizon_libnx.rs | 2 +- 26 files changed, 1008 insertions(+), 66 deletions(-) create mode 100644 library/std/src/os/libnx/fs.rs create mode 100644 library/std/src/os/libnx/mod.rs create mode 100644 library/std/src/os/libnx/raw.rs create mode 100644 library/std/src/sys/unix/process/process_dummy.rs create mode 100644 src/.gitignore diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index fc07fa77b85e7..a9288f9d2ddab 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -16,7 +16,8 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] } panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core" } -libc = { version = "0.2.51", default-features = false, features = ['rustc-dep-of-std'] } +#libc = { version = "0.2.51", default-features = false, features = ['rustc-dep-of-std'] } +libc = { git = "https://github.com/leo60228/libc.git", branch = "bindgen-newlib", default-features = false, features = ['rustc-dep-of-std'] } compiler_builtins = { version = "0.1.32" } profiler_builtins = { path = "../profiler_builtins", optional = true } unwind = { path = "../unwind" } diff --git a/library/std/src/os/libnx/fs.rs b/library/std/src/os/libnx/fs.rs new file mode 100644 index 0000000000000..bd2b6bb6050c9 --- /dev/null +++ b/library/std/src/os/libnx/fs.rs @@ -0,0 +1,312 @@ +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use crate::fs::Metadata; +use crate::sys_common::AsInner; + +#[allow(deprecated)] +use crate::os::libnx::raw; + +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned [`stat`] are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + /// + /// [`stat`]: ../../../../std/os/linux/raw/struct.stat.html + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// let stat = meta.as_raw_stat(); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", reason = "other methods of this trait are now preferred")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + /// Returns the device ID on which this file resides. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_dev()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + /// Returns the inode number. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_ino()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + /// Returns the file type and mode. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_mode()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + /// Returns the number of hard links to file. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_nlink()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + /// Returns the user ID of the file owner. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_uid()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + /// Returns the group ID of the file owner. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_gid()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + /// Returns the device ID that this file represents. Only relevant for special file. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_rdev()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + /// Returns the size of the file (if it is a regular file or a symbolic link) in bytes. + /// + /// The size of a symbolic link is the length of the pathname it contains, + /// without a terminating null byte. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_size()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + /// Returns the last access time of the file, in seconds since Unix Epoch. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_atime()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + /// Returns the last modification time of the file, in seconds since Unix Epoch. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_mtime()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + /// Returns the last status change time of the file, in seconds since Unix Epoch. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_ctime()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + /// Returns the "preferred" blocksize for efficient filesystem I/O. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_blksize()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + /// Returns the number of blocks allocated to the file, 512-byte units. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_blocks()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } +} diff --git a/library/std/src/os/libnx/mod.rs b/library/std/src/os/libnx/mod.rs new file mode 100644 index 0000000000000..1af6dd10ade6b --- /dev/null +++ b/library/std/src/os/libnx/mod.rs @@ -0,0 +1,6 @@ +//! libnx-specific definitions + +#![stable(feature = "raw_ext", since = "1.1.0")] + +pub mod fs; +pub mod raw; diff --git a/library/std/src/os/libnx/raw.rs b/library/std/src/os/libnx/raw.rs new file mode 100644 index 0000000000000..0caec97bb7b90 --- /dev/null +++ b/library/std/src/os/libnx/raw.rs @@ -0,0 +1,363 @@ +//! Linux-specific raw type definitions + +#![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated( + since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions" +)] +#![allow(deprecated)] +#![allow(missing_debug_implementations)] + +use crate::os::raw::c_ulong; + +#[stable(feature = "raw_ext", since = "1.1.0")] +pub type dev_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] +pub type mode_t = u32; + +#[stable(feature = "pthread_t", since = "1.8.0")] +pub type pthread_t = c_ulong; + +#[doc(inline)] +#[stable(feature = "raw_ext", since = "1.1.0")] +pub use self::arch::{blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t}; + +#[cfg(any( + target_arch = "x86", + target_arch = "le32", + target_arch = "powerpc", + target_arch = "arm", + target_arch = "asmjs", + target_arch = "wasm32" +))] +mod arch { + use crate::os::raw::{c_long, c_short, c_uint}; + + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blksize_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type nlink_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type time_t = i64; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad1: c_short, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __st_ino: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad2: c_uint, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: u64, + } +} + +#[cfg(target_arch = "mips")] +mod arch { + use crate::os::raw::{c_long, c_ulong}; + + #[cfg(target_env = "musl")] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = i64; + #[cfg(not(target_env = "musl"))] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blksize_t = u64; + #[cfg(target_env = "musl")] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = u64; + #[cfg(not(target_env = "musl"))] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type nlink_t = u64; + #[cfg(target_env = "musl")] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = u64; + #[cfg(not(target_env = "musl"))] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type time_t = i64; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: c_ulong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_pad1: [c_long; 3], + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: c_ulong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_pad2: [c_long; 2], + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_pad5: [c_long; 14], + } +} + +#[cfg(target_arch = "hexagon")] +mod arch { + use crate::os::raw::{c_int, c_long, c_longlong, culonglong}; + + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = c_longlong; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blksize_t = c_long; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = c_ulonglong; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type nlink_t = c_uint; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = c_longlong; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type time_t = c_long; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: ::dev_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: ::c_ulonglong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: ::c_uint, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: ::c_uint, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: ::c_uint, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: ::c_uint, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: ::c_ulonglong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad1: ::c_ulong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: ::c_longlong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: ::blksize_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad2: ::c_int, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: ::blkcnt_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: ::time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: ::c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: ::time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: ::c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: ::time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: ::c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad3: [::c_int; 2], + } +} + +#[cfg(any( + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64", + target_arch = "riscv64" +))] +mod arch { + pub use libc::{blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t}; +} + +#[cfg(target_arch = "aarch64")] +mod arch { + use crate::os::raw::{c_int, c_long}; + + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blksize_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type nlink_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type time_t = i64; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad1: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad2: c_int, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __unused: [c_int; 2], + } +} + +#[cfg(any(target_arch = "x86_64", target_arch = "powerpc64"))] +mod arch { + use crate::os::raw::{c_int, c_long}; + + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blksize_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type nlink_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type time_t = i64; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad0: c_int, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __unused: [c_long; 3], + } +} diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index fd6ee088e961c..a9bafd5dd611c 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -70,5 +70,7 @@ pub mod solaris; pub mod vxworks; #[cfg(target_os = "wasi")] pub mod wasi; +#[cfg(target_vendor = "libnx")] +pub mod libnx; pub mod raw; diff --git a/library/std/src/os/raw/mod.rs b/library/std/src/os/raw/mod.rs index 47daf0cce1b37..3a59662a80c69 100644 --- a/library/std/src/os/raw/mod.rs +++ b/library/std/src/os/raw/mod.rs @@ -47,7 +47,8 @@ target_arch = "powerpc" ) ), - all(target_os = "fuchsia", target_arch = "aarch64") + all(target_os = "fuchsia", target_arch = "aarch64"), + target_os = "horizon" ))] #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8; @@ -90,7 +91,8 @@ pub type c_char = u8; target_arch = "powerpc" ) ), - all(target_os = "fuchsia", target_arch = "aarch64") + all(target_os = "fuchsia", target_arch = "aarch64"), + target_os = "horizon" )))] #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8; diff --git a/library/std/src/sys/unix/alloc.rs b/library/std/src/sys/unix/alloc.rs index 8e193935460eb..499342386644b 100644 --- a/library/std/src/sys/unix/alloc.rs +++ b/library/std/src/sys/unix/alloc.rs @@ -84,7 +84,8 @@ unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { target_os = "android", target_os = "illumos", target_os = "redox", - target_os = "solaris" + target_os = "solaris", + target_env = "newlib" )))] #[inline] unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { @@ -95,3 +96,9 @@ unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { let ret = libc::posix_memalign(&mut out, align, layout.size()); if ret != 0 { ptr::null_mut() } else { out as *mut u8 } } + +#[cfg(target_env = "newlib")] +#[inline] +unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { + libc::aligned_alloc(layout.align(), layout.size()) as *mut u8 +} diff --git a/library/std/src/sys/unix/args.rs b/library/std/src/sys/unix/args.rs index 9bc44a59482a0..7aafdaa9907e9 100644 --- a/library/std/src/sys/unix/args.rs +++ b/library/std/src/sys/unix/args.rs @@ -70,7 +70,8 @@ impl DoubleEndedIterator for Args { target_os = "haiku", target_os = "l4re", target_os = "fuchsia", - target_os = "redox" + target_os = "redox", + target_vendor = "libnx" ))] mod imp { use super::Args; diff --git a/library/std/src/sys/unix/env.rs b/library/std/src/sys/unix/env.rs index 7f5e9b04dba4b..ce4428b779970 100644 --- a/library/std/src/sys/unix/env.rs +++ b/library/std/src/sys/unix/env.rs @@ -173,3 +173,14 @@ pub mod os { pub const EXE_SUFFIX: &str = ""; pub const EXE_EXTENSION: &str = ""; } + +#[cfg(target_os = "horizon")] +pub mod os { + pub const FAMILY: &str = "unix"; + pub const OS: &str = "horizon"; + pub const DLL_PREFIX: &str = "lib"; + pub const DLL_SUFFIX: &str = ".so"; + pub const DLL_EXTENSION: &str = "so"; + pub const EXE_SUFFIX: &str = ".nro"; + pub const EXE_EXTENSION: &str = "nro"; +} diff --git a/library/std/src/sys/unix/ext/fs.rs b/library/std/src/sys/unix/ext/fs.rs index f174a59b49a6b..19deded056e72 100644 --- a/library/std/src/sys/unix/ext/fs.rs +++ b/library/std/src/sys/unix/ext/fs.rs @@ -691,21 +691,36 @@ impl MetadataExt for fs::Metadata { fn atime(&self) -> i64 { self.st_atime() } + #[cfg(not(target_env = "newlib"))] fn atime_nsec(&self) -> i64 { self.st_atime_nsec() } + #[cfg(target_env = "newlib")] + fn atime_nsec(&self) -> i64 { + 0 + } fn mtime(&self) -> i64 { self.st_mtime() } + #[cfg(not(target_env = "newlib"))] fn mtime_nsec(&self) -> i64 { self.st_mtime_nsec() } + #[cfg(target_env = "newlib")] + fn mtime_nsec(&self) -> i64 { + 0 + } fn ctime(&self) -> i64 { self.st_ctime() } + #[cfg(not(target_env = "newlib"))] fn ctime_nsec(&self) -> i64 { self.st_ctime_nsec() } + #[cfg(target_env = "newlib")] + fn ctime_nsec(&self) -> i64 { + 0 + } fn blksize(&self) -> u64 { self.st_blksize() } diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index ba169b251b0bc..d0d62ebd01fc9 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -1,3 +1,4 @@ +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] #![unstable(reason = "not public", issue = "none", feature = "fd")] use crate::cmp; @@ -72,6 +73,7 @@ impl FileDesc { Ok(ret as usize) } + #[cfg(not(target_env = "newlib"))] pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { let ret = cvt(unsafe { libc::readv( @@ -85,7 +87,7 @@ impl FileDesc { #[inline] pub fn is_read_vectored(&self) -> bool { - true + !cfg!(target_env = "newlib") } pub fn read_to_end(&self, buf: &mut Vec) -> io::Result { @@ -129,6 +131,7 @@ impl FileDesc { Ok(ret as usize) } + #[cfg(not(target_env = "newlib"))] pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { let ret = cvt(unsafe { libc::writev( @@ -142,7 +145,7 @@ impl FileDesc { #[inline] pub fn is_write_vectored(&self) -> bool { - true + !cfg!(target_env = "newlib") } pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index acb18e6d064e6..e46a202e618bd 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -155,12 +155,14 @@ cfg_has_statx! {{ stat.st_blksize = buf.stx_blksize as libc::blksize_t; stat.st_blocks = buf.stx_blocks as libc::blkcnt64_t; stat.st_atime = buf.stx_atime.tv_sec as libc::time_t; - // `i64` on gnu-x86_64-x32, `c_ulong` otherwise. - stat.st_atime_nsec = buf.stx_atime.tv_nsec as _; stat.st_mtime = buf.stx_mtime.tv_sec as libc::time_t; - stat.st_mtime_nsec = buf.stx_mtime.tv_nsec as _; stat.st_ctime = buf.stx_ctime.tv_sec as libc::time_t; - stat.st_ctime_nsec = buf.stx_ctime.tv_nsec as _; + // `i64` on gnu-x86_64-x32, `c_ulong` otherwise. + #[cfg(not(target_env = "newlib"))] { + stat.st_atime_nsec = buf.stx_atime.tv_nsec as _; + stat.st_mtime_nsec = buf.stx_mtime.tv_nsec as _; + stat.st_ctime_nsec = buf.stx_ctime.tv_nsec as _; + } let extra = StatxExtraFields { stx_mask: buf.stx_mask, @@ -295,6 +297,9 @@ impl FileAttr { pub fn modified(&self) -> io::Result { Ok(SystemTime::from(libc::timespec { tv_sec: self.stat.st_mtime as libc::time_t, + #[cfg(target_env = "newlib")] + tv_nsec: 0, + #[cfg(not(target_env = "newlib"))] tv_nsec: self.stat.st_mtime_nsec as _, })) } @@ -302,6 +307,9 @@ impl FileAttr { pub fn accessed(&self) -> io::Result { Ok(SystemTime::from(libc::timespec { tv_sec: self.stat.st_atime as libc::time_t, + #[cfg(target_env = "newlib")] + tv_nsec: 0, + #[cfg(not(target_env = "newlib"))] tv_nsec: self.stat.st_atime_nsec as _, })) } @@ -560,7 +568,8 @@ impl DirEntry { target_os = "haiku", target_os = "l4re", target_os = "fuchsia", - target_os = "redox" + target_os = "redox", + target_env = "newlib" ))] pub fn ino(&self) -> u64 { self.entry.d_ino as u64 @@ -598,7 +607,8 @@ impl DirEntry { target_os = "linux", target_os = "emscripten", target_os = "l4re", - target_os = "haiku" + target_os = "haiku", + target_env = "newlib" ))] fn name_bytes(&self) -> &[u8] { unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes() } diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index eddf00d3979f5..bbbf6f5f2f97d 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -33,6 +33,8 @@ pub use crate::os::openbsd as platform; pub use crate::os::redox as platform; #[cfg(all(not(doc), target_os = "solaris"))] pub use crate::os::solaris as platform; +#[cfg(all(not(doc), target_vendor = "libnx"))] +pub use crate::os::libnx as platform; pub use self::rand::hashmap_random_keys; pub use libc::strlen; diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index 011325fddc5b9..0580692410748 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -1,3 +1,5 @@ +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] + use crate::cmp; use crate::ffi::CStr; use crate::io::{self, IoSlice, IoSliceMut}; @@ -305,14 +307,25 @@ impl Socket { } pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> { - setsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY, nodelay as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY, nodelay as c_int) + } + #[cfg(target_env = "newlib")] { + Ok(()) + } } + #[cfg(not(target_env = "newlib"))] pub fn nodelay(&self) -> io::Result { let raw: c_int = getsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY)?; Ok(raw != 0) } + #[cfg(target_env = "newlib")] + pub fn nodelay(&self) -> io::Result { + Ok(false) + } + #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { let mut nonblocking = nonblocking as libc::c_int; diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 2fcb5b9c4e66e..0b6ed2f398b12 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -1,6 +1,7 @@ //! Implementation of `std::os` functionality for unix systems #![allow(unused_imports)] // lots of cfg code here +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] use crate::os::unix::prelude::*; @@ -430,7 +431,7 @@ pub fn current_exe() -> io::Result { crate::fs::read_to_string("sys:exe").map(PathBuf::from) } -#[cfg(any(target_os = "fuchsia", target_os = "l4re"))] +#[cfg(any(target_os = "fuchsia", target_os = "l4re", target_vendor = "libnx"))] pub fn current_exe() -> io::Result { use crate::io::ErrorKind; Err(io::Error::new(ErrorKind::Other, "Not yet implemented!")) diff --git a/library/std/src/sys/unix/pipe.rs b/library/std/src/sys/unix/pipe.rs index 7ae37bdda70bd..89aebd1cc07ee 100644 --- a/library/std/src/sys/unix/pipe.rs +++ b/library/std/src/sys/unix/pipe.rs @@ -1,3 +1,5 @@ +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] + use crate::io::{self, IoSlice, IoSliceMut}; use crate::mem; use crate::sys::fd::FileDesc; diff --git a/library/std/src/sys/unix/process/mod.rs b/library/std/src/sys/unix/process/mod.rs index 553e980f08e97..41f0dc305af99 100644 --- a/library/std/src/sys/unix/process/mod.rs +++ b/library/std/src/sys/unix/process/mod.rs @@ -3,11 +3,14 @@ pub use self::process_inner::{ExitStatus, Process}; pub use crate::ffi::OsString as EnvKey; mod process_common; -#[cfg(not(target_os = "fuchsia"))] +#[cfg(not(any(target_os = "fuchsia", target_os = "horizon")))] #[path = "process_unix.rs"] mod process_inner; #[cfg(target_os = "fuchsia")] #[path = "process_fuchsia.rs"] mod process_inner; +#[cfg(target_os = "horizon")] +#[path = "process_dummy.rs"] +mod process_inner; #[cfg(target_os = "fuchsia")] mod zircon; diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 6e33cdd3c4826..689cf3e1ab441 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -1,3 +1,5 @@ +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] + use crate::os::unix::prelude::*; use crate::collections::BTreeMap; diff --git a/library/std/src/sys/unix/process/process_dummy.rs b/library/std/src/sys/unix/process/process_dummy.rs new file mode 100644 index 0000000000000..88db58559f510 --- /dev/null +++ b/library/std/src/sys/unix/process/process_dummy.rs @@ -0,0 +1,94 @@ +use crate::fmt; +use crate::io; +use crate::sys::process::process_common::*; +use crate::os::raw::c_int; + +pub use crate::ffi::OsString as EnvKey; + +fn unsupported() -> io::Result { + Err(unsupported_err()) +} + +fn unsupported_err() -> io::Error { + io::Error::new(io::ErrorKind::Other, "operation not supported") +} + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +pub enum Void {} + +//////////////////////////////////////////////////////////////////////////////// +// Command +//////////////////////////////////////////////////////////////////////////////// + +impl Command { + pub fn spawn( + &mut self, + _default: Stdio, + _needs_stdin: bool, + ) -> io::Result<(Process, StdioPipes)> { + unsupported() + } + + pub fn exec(&mut self, _default: Stdio) -> io::Error { + unsupported_err() + } +} + +/// Unix exit statuses +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +pub struct ExitStatus(c_int); + +impl ExitStatus { + fn exited(&self) -> bool { + libc::WIFEXITED(self.0) + } + + pub fn success(&self) -> bool { + self.code() == Some(0) + } + + pub fn code(&self) -> Option { + if self.exited() { Some(libc::WEXITSTATUS(self.0)) } else { None } + } + + pub fn signal(&self) -> Option { + if !self.exited() { Some(libc::WTERMSIG(self.0)) } else { None } + } +} + +impl From for ExitStatus { + fn from(a: c_int) -> ExitStatus { + ExitStatus(a) + } +} + +impl fmt::Display for ExitStatus { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if let Some(code) = self.code() { + write!(f, "exit code: {}", code) + } else { + let signal = self.signal().unwrap(); + write!(f, "signal: {}", signal) + } + } +} + +pub struct Process(Void); + +impl Process { + pub fn id(&self) -> u32 { + match self.0 {} + } + + pub fn kill(&mut self) -> io::Result<()> { + match self.0 {} + } + + pub fn wait(&mut self) -> io::Result { + match self.0 {} + } + + pub fn try_wait(&mut self) -> io::Result> { + match self.0 {} + } +} diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index 6707f790cab0a..69fe9106a13f2 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -339,9 +339,9 @@ mod inner { } } - #[cfg(not(target_os = "dragonfly"))] + #[cfg(not(any(target_os = "dragonfly", target_os = "horizon")))] pub type clock_t = libc::c_int; - #[cfg(target_os = "dragonfly")] + #[cfg(any(target_os = "dragonfly", target_os = "horizon"))] pub type clock_t = libc::c_ulong; fn now(clock: clock_t) -> Timespec { diff --git a/library/std/src/sys/unix/weak.rs b/library/std/src/sys/unix/weak.rs index f4b33a00f7c85..48ca65e750ce2 100644 --- a/library/std/src/sys/unix/weak.rs +++ b/library/std/src/sys/unix/weak.rs @@ -58,6 +58,7 @@ impl Weak { } } +#[cfg(not(target_env = "newlib"))] unsafe fn fetch(name: &str) -> usize { let name = match CStr::from_bytes_with_nul(name.as_bytes()) { Ok(cstr) => cstr, @@ -66,6 +67,11 @@ unsafe fn fetch(name: &str) -> usize { libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize } +#[cfg(target_env = "newlib")] +unsafe fn fetch(_name: &str) -> usize { + 0 +} + #[cfg(not(target_os = "linux"))] macro_rules! syscall { (fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => ( diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index 81a5ef95e82dc..5c8511a0dea9f 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -1,3 +1,5 @@ +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] + use crate::cmp; use crate::convert::{TryFrom, TryInto}; use crate::ffi::CString; @@ -21,7 +23,7 @@ cfg_if::cfg_if! { target_os = "solaris", target_os = "haiku", target_os = "l4re"))] { use crate::sys::net::netc::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP; use crate::sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP; - } else { + } else if #[cfg(not(target_env = "newlib"))] { use crate::sys::net::netc::IPV6_ADD_MEMBERSHIP; use crate::sys::net::netc::IPV6_DROP_MEMBERSHIP; } @@ -312,11 +314,19 @@ impl TcpStream { } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + } + #[cfg(target_env = "newlib")] { + Ok(()) + } } pub fn ttl(&self) -> io::Result { + #[cfg(not(target_env = "newlib"))] let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; + #[cfg(target_env = "newlib")] + let raw: c_int = 64; Ok(raw as u32) } @@ -412,21 +422,38 @@ impl TcpListener { } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + } + #[cfg(target_env = "newlib")] { + Ok(()) + } } pub fn ttl(&self) -> io::Result { + #[cfg(not(target_env = "newlib"))] let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; + #[cfg(target_env = "newlib")] + let raw: c_int = 64; Ok(raw as u32) } pub fn set_only_v6(&self, only_v6: bool) -> io::Result<()> { - setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY, only_v6 as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY, only_v6 as c_int) + } + #[cfg(target_env = "newlib")] { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } } pub fn only_v6(&self) -> io::Result { - let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)?; - Ok(raw != 0) + #[cfg(not(target_env = "newlib"))] { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)?; + Ok(raw != 0) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn take_error(&self) -> io::Result> { @@ -547,80 +574,132 @@ impl UdpSocket { } pub fn set_multicast_loop_v4(&self, multicast_loop_v4: bool) -> io::Result<()> { - setsockopt( - &self.inner, - c::IPPROTO_IP, - c::IP_MULTICAST_LOOP, - multicast_loop_v4 as IpV4MultiCastType, - ) + #[cfg(not(target_env = "newlib"))] { + setsockopt( + &self.inner, + c::IPPROTO_IP, + c::IP_MULTICAST_LOOP, + multicast_loop_v4 as IpV4MultiCastType, + ) + } + #[cfg(target_env = "newlib")] { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } } pub fn multicast_loop_v4(&self) -> io::Result { - let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP)?; - Ok(raw != 0) + #[cfg(not(target_env = "newlib"))] { + let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP)?; + Ok(raw != 0) + } + #[cfg(target_env = "newlib")] { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } } pub fn set_multicast_ttl_v4(&self, multicast_ttl_v4: u32) -> io::Result<()> { - setsockopt( - &self.inner, - c::IPPROTO_IP, - c::IP_MULTICAST_TTL, - multicast_ttl_v4 as IpV4MultiCastType, - ) + #[cfg(not(target_env = "newlib"))] { + setsockopt( + &self.inner, + c::IPPROTO_IP, + c::IP_MULTICAST_TTL, + multicast_ttl_v4 as IpV4MultiCastType, + ) + } + #[cfg(target_env = "newlib")] { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } } pub fn multicast_ttl_v4(&self) -> io::Result { - let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL)?; - Ok(raw as u32) + #[cfg(not(target_env = "newlib"))] { + let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL)?; + Ok(raw as u32) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn set_multicast_loop_v6(&self, multicast_loop_v6: bool) -> io::Result<()> { - setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP, multicast_loop_v6 as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP, multicast_loop_v6 as c_int) + } + #[cfg(target_env = "newlib")] { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } } pub fn multicast_loop_v6(&self) -> io::Result { - let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP)?; - Ok(raw != 0) + #[cfg(not(target_env = "newlib"))] { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP)?; + Ok(raw != 0) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn join_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> { - let mreq = c::ip_mreq { - imr_multiaddr: *multiaddr.as_inner(), - imr_interface: *interface.as_inner(), - }; - setsockopt(&self.inner, c::IPPROTO_IP, c::IP_ADD_MEMBERSHIP, mreq) + #[cfg(not(target_env = "newlib"))] { + let mreq = c::ip_mreq { + imr_multiaddr: *multiaddr.as_inner(), + imr_interface: *interface.as_inner(), + }; + setsockopt(&self.inner, c::IPPROTO_IP, c::IP_ADD_MEMBERSHIP, mreq) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn join_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> { - let mreq = c::ipv6_mreq { - ipv6mr_multiaddr: *multiaddr.as_inner(), - ipv6mr_interface: to_ipv6mr_interface(interface), - }; - setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq) + #[cfg(not(target_env = "newlib"))] { + let mreq = c::ipv6_mreq { + ipv6mr_multiaddr: *multiaddr.as_inner(), + ipv6mr_interface: to_ipv6mr_interface(interface), + }; + setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn leave_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> { - let mreq = c::ip_mreq { - imr_multiaddr: *multiaddr.as_inner(), - imr_interface: *interface.as_inner(), - }; - setsockopt(&self.inner, c::IPPROTO_IP, c::IP_DROP_MEMBERSHIP, mreq) + #[cfg(not(target_env = "newlib"))] { + let mreq = c::ip_mreq { + imr_multiaddr: *multiaddr.as_inner(), + imr_interface: *interface.as_inner(), + }; + setsockopt(&self.inner, c::IPPROTO_IP, c::IP_DROP_MEMBERSHIP, mreq) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn leave_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> { - let mreq = c::ipv6_mreq { - ipv6mr_multiaddr: *multiaddr.as_inner(), - ipv6mr_interface: to_ipv6mr_interface(interface), - }; - setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, mreq) + #[cfg(not(target_env = "newlib"))] { + let mreq = c::ipv6_mreq { + ipv6mr_multiaddr: *multiaddr.as_inner(), + ipv6mr_interface: to_ipv6mr_interface(interface), + }; + setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, mreq) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + } + #[cfg(target_env = "newlib")] { + Ok(()) + } } pub fn ttl(&self) -> io::Result { + #[cfg(not(target_env = "newlib"))] let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; + #[cfg(target_env = "newlib")] + let raw: c_int = 64; Ok(raw as u32) } diff --git a/library/test/src/helpers/concurrency.rs b/library/test/src/helpers/concurrency.rs index 7ca27bf0dc15e..a596fab0584be 100644 --- a/library/test/src/helpers/concurrency.rs +++ b/library/test/src/helpers/concurrency.rs @@ -114,4 +114,10 @@ cfg_if::cfg_if! { 1 } } + + #[cfg(target_vendor = "libnx")] + fn num_cpus() -> usize { + // FIXME: implement + 1 + } } diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000000000..0a9ce4f3e2c93 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +libc diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 11bbe1c7062b6..d64ca95d24392 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -244,7 +244,7 @@ pub struct Target { impl Target { pub fn from_triple(triple: &str) -> Self { let mut target: Self = Default::default(); - if triple.contains("-none") || triple.contains("nvptx") || triple.contains("horizon") { + if triple.contains("-none") || triple.contains("nvptx") { target.no_std = true; } target diff --git a/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs b/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs index 259d4a8217450..0df1ff41bda59 100644 --- a/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs +++ b/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs @@ -26,7 +26,7 @@ pub fn target() -> Result { target_c_int_width: "32".to_string(), target_os: "horizon".to_string(), target_env: "newlib".to_string(), - target_vendor: String::new(), + target_vendor: "libnx".to_string(), data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), linker_flavor: LinkerFlavor::Gcc, From fbb156a49cc4c05b13030f2ba35183a1007da93f Mon Sep 17 00:00:00 2001 From: leo60228 Date: Sun, 12 Apr 2020 18:25:03 -0400 Subject: [PATCH 06/38] Don't use sysconf on horizon --- library/std/src/sys/unix/os.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 0b6ed2f398b12..9d5fb2b30677c 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -546,10 +546,16 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { } } +#[cfg(not(target_os = "horizon"))] pub fn page_size() -> usize { unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize } } +#[cfg(target_os = "horizon")] +pub fn page_size() -> usize { + 0x1000 +} + pub fn temp_dir() -> PathBuf { crate::env::var_os("TMPDIR").map(PathBuf::from).unwrap_or_else(|| { if cfg!(target_os = "android") { @@ -567,7 +573,8 @@ pub fn home_dir() -> Option { target_os = "android", target_os = "ios", target_os = "emscripten", - target_os = "redox" + target_os = "redox", + target_os = "horizon" ))] unsafe fn fallback() -> Option { None @@ -576,7 +583,8 @@ pub fn home_dir() -> Option { target_os = "android", target_os = "ios", target_os = "emscripten", - target_os = "redox" + target_os = "redox", + target_os = "horizon" )))] unsafe fn fallback() -> Option { let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { From d9c1a136d7ced4510d6c5ad932a58fe2a221ecaa Mon Sep 17 00:00:00 2001 From: leo60228 Date: Thu, 16 Apr 2020 13:56:43 -0400 Subject: [PATCH 07/38] Emulate pread/pwrite on newlib --- library/std/src/sys/unix/fd.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index d0d62ebd01fc9..78bec58a6e5b1 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -99,7 +99,7 @@ impl FileDesc { #[cfg(target_os = "android")] use super::android::cvt_pread64; - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_env = "newlib")))] unsafe fn cvt_pread64( fd: c_int, buf: *mut c_void, @@ -113,6 +113,21 @@ impl FileDesc { cvt(pread64(fd, buf, count, offset)) } + #[cfg(target_env = "newlib")] + unsafe fn cvt_pread64( + fd: c_int, + buf: *mut c_void, + count: usize, + offset: i64, + ) -> io::Result { + // ported from newlib, because it inexplicably was not being compiled + let cur_pos = cvt(libc::lseek(fd, 0, libc::SEEK_CUR))?; + cvt(libc::lseek(fd, offset, libc::SEEK_SET))?; + let num_read = cvt(libc::read(fd, buf, count))?; + cvt(libc::lseek(fd, cur_pos, libc::SEEK_SET))?; + Ok(num_read as _) + } + unsafe { cvt_pread64( self.fd, @@ -152,7 +167,7 @@ impl FileDesc { #[cfg(target_os = "android")] use super::android::cvt_pwrite64; - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_env = "newlib")))] unsafe fn cvt_pwrite64( fd: c_int, buf: *const c_void, @@ -166,6 +181,21 @@ impl FileDesc { cvt(pwrite64(fd, buf, count, offset)) } + #[cfg(target_env = "newlib")] + unsafe fn cvt_pwrite64( + fd: c_int, + buf: *const c_void, + count: usize, + offset: i64, + ) -> io::Result { + // see pread + let cur_pos = cvt(libc::lseek(fd, 0, libc::SEEK_CUR))?; + cvt(libc::lseek(fd, offset, libc::SEEK_SET))?; + let num_written = cvt(libc::write(fd, buf, count))?; + cvt(libc::lseek(fd, cur_pos, libc::SEEK_SET))?; + Ok(num_written) + } + unsafe { cvt_pwrite64( self.fd, From eef24b9cc61ace6454f199a106a7b190d048b734 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Thu, 16 Apr 2020 13:57:05 -0400 Subject: [PATCH 08/38] Fake readlink/symlink on Horizon --- library/std/src/sys/unix/fs.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index e46a202e618bd..99f3b3fc1b319 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -984,6 +984,7 @@ pub fn rmdir(p: &Path) -> io::Result<()> { Ok(()) } +#[cfg(not(target_os = "horizon"))] pub fn readlink(p: &Path) -> io::Result { let c_path = cstr(p)?; let p = c_path.as_ptr(); @@ -1011,6 +1012,12 @@ pub fn readlink(p: &Path) -> io::Result { } } +#[cfg(target_os = "horizon")] +pub fn readlink(p: &Path) -> io::Result { + Ok(p.to_path_buf()) // horizon doesn't have symlinks +} + +#[cfg(not(target_os = "horizon"))] pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { let src = cstr(src)?; let dst = cstr(dst)?; @@ -1018,6 +1025,11 @@ pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { Ok(()) } +#[cfg(target_os = "horizon")] +pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> { + Err(io::Error::new(io::ErrorKind::Other, "not supported")) // horizon doesn't have symlinks +} + pub fn link(src: &Path, dst: &Path) -> io::Result<()> { let src = cstr(src)?; let dst = cstr(dst)?; From c96299052b1f52b9edae72c49200b949c335134a Mon Sep 17 00:00:00 2001 From: leo60228 Date: Thu, 16 Apr 2020 13:57:22 -0400 Subject: [PATCH 09/38] Emulate realpath on Horizon --- library/std/src/sys/unix/fs.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index 99f3b3fc1b319..cc8c455977475 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -1075,6 +1075,7 @@ pub fn lstat(p: &Path) -> io::Result { Ok(FileAttr::from_stat64(stat)) } +#[cfg(not(target_os = "horizon"))] pub fn canonicalize(p: &Path) -> io::Result { let path = CString::new(p.as_os_str().as_bytes())?; let buf; @@ -1089,6 +1090,14 @@ pub fn canonicalize(p: &Path) -> io::Result { Ok(PathBuf::from(OsString::from_vec(buf))) } +#[cfg(target_os = "horizon")] +pub fn canonicalize(p: &Path) -> io::Result { + // horizon has no symlinks or realpath + let mut cwd = crate::env::current_dir()?; + cwd.push(p); + Ok(cwd) +} + fn open_from(from: &Path) -> io::Result<(crate::fs::File, crate::fs::Metadata)> { use crate::fs::File; From fd200255b84d055ee18396f352d0dd67f6e255ef Mon Sep 17 00:00:00 2001 From: leo60228 Date: Thu, 16 Apr 2020 13:57:32 -0400 Subject: [PATCH 10/38] Emulate getppid on Horizon --- library/std/src/sys/unix/os.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 9d5fb2b30677c..8beef318eb003 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -619,10 +619,16 @@ pub fn getpid() -> u32 { unsafe { libc::getpid() as u32 } } +#[cfg(not(target_os = "horizon"))] pub fn getppid() -> u32 { unsafe { libc::getppid() as u32 } } +#[cfg(target_os = "horizon")] +pub fn getppid() -> u32 { + 1 // horizon doesn't have a process hierarchy +} + #[cfg(target_env = "gnu")] pub fn glibc_version() -> Option<(usize, usize)> { if let Some(Ok(version_str)) = glibc_version_cstr().map(CStr::to_str) { From 1ec98014152f99c8e9dbe04127c1b3b9e14e1ddf Mon Sep 17 00:00:00 2001 From: leo60228 Date: Fri, 17 Apr 2020 16:29:34 -0400 Subject: [PATCH 11/38] libunwind on Horizon --- .gitmodules | 4 ++-- library/unwind/build.rs | 8 ++++++++ src/llvm-project | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index a327aaa8d5a34..87bdeb44b15fb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -36,8 +36,8 @@ url = https://github.com/rust-lang/edition-guide.git [submodule "src/llvm-project"] path = src/llvm-project - url = https://github.com/rust-lang/llvm-project.git - branch = rustc/10.0-2020-05-05 + url = https://github.com/leo60228/llvm-project.git + branch = no-eh-frame-hdr [submodule "src/doc/embedded-book"] path = src/doc/embedded-book url = https://github.com/rust-embedded/book.git diff --git a/library/unwind/build.rs b/library/unwind/build.rs index ab09a6e324d8b..3a6552aec54cb 100644 --- a/library/unwind/build.rs +++ b/library/unwind/build.rs @@ -48,6 +48,8 @@ fn main() { // redox is handled in lib.rs } else if target.contains("cloudabi") { println!("cargo:rustc-link-lib=unwind"); + } else if target.contains("libnx") { + llvm_libunwind::compile(); } } @@ -120,6 +122,12 @@ mod llvm_libunwind { cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None); } + if target_vendor == "libnx" { + cfg.define("_LIBUNWIND_IS_BAREMETAL", None); + cfg.define("_LIBUNWIND_SUPPORT_DWARF_UNWIND", None); + cfg.define("_LIBUNWIND_SUPPORT_DWARF_INDEX", Some("0")); + } + let mut unwind_sources = vec![ "Unwind-EHABI.cpp", "Unwind-seh.cpp", diff --git a/src/llvm-project b/src/llvm-project index 86b120e6f302d..dfc60c7d97a63 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 86b120e6f302d39cd6973b6391fb299d7bc22122 +Subproject commit dfc60c7d97a63dd200fc447be2e4ff36583fe09e From 39ee014716629d3ee2c44e28af3740983b9980e4 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Sat, 18 Apr 2020 11:27:18 -0400 Subject: [PATCH 12/38] Implement current_exe --- library/std/src/sys/unix/os.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 8beef318eb003..f6c1a60cdf201 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -431,12 +431,21 @@ pub fn current_exe() -> io::Result { crate::fs::read_to_string("sys:exe").map(PathBuf::from) } -#[cfg(any(target_os = "fuchsia", target_os = "l4re", target_vendor = "libnx"))] +#[cfg(any(target_os = "fuchsia", target_os = "l4re"))] pub fn current_exe() -> io::Result { use crate::io::ErrorKind; Err(io::Error::new(ErrorKind::Other, "Not yet implemented!")) } +#[cfg(target_vendor = "libnx")] +pub fn current_exe() -> io::Result { + use crate::env; + // guaranteed by abi to be an absolute path to the executable + env::args_os().next().map(From::from).ok_or_else(|| { + io::Error::new(io::ErrorKind::Other, "no current exe available") + }) +} + pub struct Env { iter: vec::IntoIter<(OsString, OsString)>, _dont_send_or_sync_me: PhantomData<*mut ()>, From 7596eba3f14ffcfb37a7fe43098bb7d4b960fc64 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Sat, 18 Apr 2020 15:52:27 -0400 Subject: [PATCH 13/38] panic_unwind --- .gitmodules | 4 ++-- library/unwind/build.rs | 2 +- src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs | 2 +- src/llvm-project | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index 87bdeb44b15fb..a327aaa8d5a34 100644 --- a/.gitmodules +++ b/.gitmodules @@ -36,8 +36,8 @@ url = https://github.com/rust-lang/edition-guide.git [submodule "src/llvm-project"] path = src/llvm-project - url = https://github.com/leo60228/llvm-project.git - branch = no-eh-frame-hdr + url = https://github.com/rust-lang/llvm-project.git + branch = rustc/10.0-2020-05-05 [submodule "src/doc/embedded-book"] path = src/doc/embedded-book url = https://github.com/rust-embedded/book.git diff --git a/library/unwind/build.rs b/library/unwind/build.rs index 3a6552aec54cb..0890f1dbe471c 100644 --- a/library/unwind/build.rs +++ b/library/unwind/build.rs @@ -125,7 +125,7 @@ mod llvm_libunwind { if target_vendor == "libnx" { cfg.define("_LIBUNWIND_IS_BAREMETAL", None); cfg.define("_LIBUNWIND_SUPPORT_DWARF_UNWIND", None); - cfg.define("_LIBUNWIND_SUPPORT_DWARF_INDEX", Some("0")); + cfg.define("_LIBUNWIND_SUPPORT_DWARF_INDEX", None); } let mut unwind_sources = vec![ diff --git a/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs b/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs index 0df1ff41bda59..710df77f7fa38 100644 --- a/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs +++ b/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs @@ -9,7 +9,7 @@ pub fn target() -> Result { disable_redzone: true, linker_is_gnu: true, max_atomic_width: Some(128), - panic_strategy: PanicStrategy::Abort, + panic_strategy: PanicStrategy::Unwind, abi_blacklist: super::arm_base::abi_blacklist(), target_family: Some("unix".to_string()), position_independent_executables: true, diff --git a/src/llvm-project b/src/llvm-project index dfc60c7d97a63..86b120e6f302d 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit dfc60c7d97a63dd200fc447be2e4ff36583fe09e +Subproject commit 86b120e6f302d39cd6973b6391fb299d7bc22122 From f98dd7d1ccd913326b93a65bb8de9c09445126a8 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Fri, 17 Jul 2020 20:56:09 -0400 Subject: [PATCH 14/38] Cleanup cfgs, rename to aarch64-unknown-switch-devkita64 --- library/std/Cargo.toml | 2 +- library/std/src/os/raw/mod.rs | 4 +- library/std/src/sys/unix/alloc.rs | 4 +- library/std/src/sys/unix/env.rs | 4 +- library/std/src/sys/unix/ext/fs.rs | 12 +-- library/std/src/sys/unix/fd.rs | 24 +++--- library/std/src/sys/unix/fs.rs | 32 ++++---- library/std/src/sys/unix/net.rs | 10 +-- library/std/src/sys/unix/os.rs | 19 +++-- library/std/src/sys/unix/pipe.rs | 2 - library/std/src/sys/unix/process/mod.rs | 4 +- .../src/sys/unix/process/process_common.rs | 2 +- .../std/src/sys/unix/process/process_dummy.rs | 3 + library/std/src/sys/unix/thread.rs | 4 +- library/std/src/sys/unix/time.rs | 4 +- library/std/src/sys/unix/weak.rs | 4 +- library/std/src/sys_common/net.rs | 76 +++++++++---------- library/test/src/helpers/concurrency.rs | 8 +- ...rs => aarch64_unknown_switch_devkita64.rs} | 6 +- src/librustc_target/spec/mod.rs | 2 +- 20 files changed, 110 insertions(+), 116 deletions(-) rename src/librustc_target/spec/{aarch64_unknown_horizon_libnx.rs => aarch64_unknown_switch_devkita64.rs} (90%) diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index a9288f9d2ddab..b85a848bd6af7 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -17,7 +17,7 @@ panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core" } #libc = { version = "0.2.51", default-features = false, features = ['rustc-dep-of-std'] } -libc = { git = "https://github.com/leo60228/libc.git", branch = "bindgen-newlib", default-features = false, features = ['rustc-dep-of-std'] } +libc = { git = "https://github.com/leo60228/libc.git", branch = "bindgen-horizon", default-features = false, features = ['rustc-dep-of-std'] } compiler_builtins = { version = "0.1.32" } profiler_builtins = { path = "../profiler_builtins", optional = true } unwind = { path = "../unwind" } diff --git a/library/std/src/os/raw/mod.rs b/library/std/src/os/raw/mod.rs index 3a59662a80c69..631a8ee6c1843 100644 --- a/library/std/src/os/raw/mod.rs +++ b/library/std/src/os/raw/mod.rs @@ -48,7 +48,7 @@ ) ), all(target_os = "fuchsia", target_arch = "aarch64"), - target_os = "horizon" + target_env = "devkita64" ))] #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8; @@ -92,7 +92,7 @@ pub type c_char = u8; ) ), all(target_os = "fuchsia", target_arch = "aarch64"), - target_os = "horizon" + target_env = "devkita64" )))] #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8; diff --git a/library/std/src/sys/unix/alloc.rs b/library/std/src/sys/unix/alloc.rs index 499342386644b..f53532ecf23a4 100644 --- a/library/std/src/sys/unix/alloc.rs +++ b/library/std/src/sys/unix/alloc.rs @@ -85,7 +85,7 @@ unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { target_os = "illumos", target_os = "redox", target_os = "solaris", - target_env = "newlib" + target_env = "devkita64" )))] #[inline] unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { @@ -97,7 +97,7 @@ unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { if ret != 0 { ptr::null_mut() } else { out as *mut u8 } } -#[cfg(target_env = "newlib")] +#[cfg(target_env = "devkita64")] #[inline] unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { libc::aligned_alloc(layout.align(), layout.size()) as *mut u8 diff --git a/library/std/src/sys/unix/env.rs b/library/std/src/sys/unix/env.rs index ce4428b779970..a3b75500e601a 100644 --- a/library/std/src/sys/unix/env.rs +++ b/library/std/src/sys/unix/env.rs @@ -174,10 +174,10 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "horizon")] +#[cfg(target_env = "devkita64")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "horizon"; + pub const OS: &str = "switch"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; diff --git a/library/std/src/sys/unix/ext/fs.rs b/library/std/src/sys/unix/ext/fs.rs index 19deded056e72..c7a38ac31a4d3 100644 --- a/library/std/src/sys/unix/ext/fs.rs +++ b/library/std/src/sys/unix/ext/fs.rs @@ -691,33 +691,33 @@ impl MetadataExt for fs::Metadata { fn atime(&self) -> i64 { self.st_atime() } - #[cfg(not(target_env = "newlib"))] + #[cfg(not(target_env = "devkita64"))] fn atime_nsec(&self) -> i64 { self.st_atime_nsec() } - #[cfg(target_env = "newlib")] + #[cfg(target_env = "devkita64")] fn atime_nsec(&self) -> i64 { 0 } fn mtime(&self) -> i64 { self.st_mtime() } - #[cfg(not(target_env = "newlib"))] + #[cfg(not(target_env = "devkita64"))] fn mtime_nsec(&self) -> i64 { self.st_mtime_nsec() } - #[cfg(target_env = "newlib")] + #[cfg(target_env = "devkita64")] fn mtime_nsec(&self) -> i64 { 0 } fn ctime(&self) -> i64 { self.st_ctime() } - #[cfg(not(target_env = "newlib"))] + #[cfg(not(target_env = "devkita64"))] fn ctime_nsec(&self) -> i64 { self.st_ctime_nsec() } - #[cfg(target_env = "newlib")] + #[cfg(target_env = "devkita64")] fn ctime_nsec(&self) -> i64 { 0 } diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index 78bec58a6e5b1..913699ee4c675 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -1,4 +1,4 @@ -#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] +#![cfg_attr(target_env = "devkita64", allow(unused_variables, dead_code))] #![unstable(reason = "not public", issue = "none", feature = "fd")] use crate::cmp; @@ -73,7 +73,7 @@ impl FileDesc { Ok(ret as usize) } - #[cfg(not(target_env = "newlib"))] + #[cfg(not(target_env = "devkita64"))] pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { let ret = cvt(unsafe { libc::readv( @@ -87,7 +87,7 @@ impl FileDesc { #[inline] pub fn is_read_vectored(&self) -> bool { - !cfg!(target_env = "newlib") + !cfg!(target_env = "devkita64") } pub fn read_to_end(&self, buf: &mut Vec) -> io::Result { @@ -99,7 +99,7 @@ impl FileDesc { #[cfg(target_os = "android")] use super::android::cvt_pread64; - #[cfg(not(any(target_os = "android", target_env = "newlib")))] + #[cfg(not(any(target_os = "android", target_env = "devkita64")))] unsafe fn cvt_pread64( fd: c_int, buf: *mut c_void, @@ -113,14 +113,14 @@ impl FileDesc { cvt(pread64(fd, buf, count, offset)) } - #[cfg(target_env = "newlib")] + #[cfg(target_env = "devkita64")] unsafe fn cvt_pread64( fd: c_int, buf: *mut c_void, count: usize, offset: i64, ) -> io::Result { - // ported from newlib, because it inexplicably was not being compiled + // ported from devkita64, because it inexplicably was not being compiled let cur_pos = cvt(libc::lseek(fd, 0, libc::SEEK_CUR))?; cvt(libc::lseek(fd, offset, libc::SEEK_SET))?; let num_read = cvt(libc::read(fd, buf, count))?; @@ -146,7 +146,7 @@ impl FileDesc { Ok(ret as usize) } - #[cfg(not(target_env = "newlib"))] + #[cfg(not(target_env = "devkita64"))] pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { let ret = cvt(unsafe { libc::writev( @@ -160,14 +160,14 @@ impl FileDesc { #[inline] pub fn is_write_vectored(&self) -> bool { - !cfg!(target_env = "newlib") + !cfg!(target_env = "devkita64") } pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { #[cfg(target_os = "android")] use super::android::cvt_pwrite64; - #[cfg(not(any(target_os = "android", target_env = "newlib")))] + #[cfg(not(any(target_os = "android", target_env = "devkita64")))] unsafe fn cvt_pwrite64( fd: c_int, buf: *const c_void, @@ -181,7 +181,7 @@ impl FileDesc { cvt(pwrite64(fd, buf, count, offset)) } - #[cfg(target_env = "newlib")] + #[cfg(target_env = "devkita64")] unsafe fn cvt_pwrite64( fd: c_int, buf: *const c_void, @@ -213,7 +213,7 @@ impl FileDesc { } #[cfg(not(any( - target_env = "newlib", + target_env = "devkita64", target_os = "solaris", target_os = "illumos", target_os = "emscripten", @@ -230,7 +230,7 @@ impl FileDesc { } } #[cfg(any( - target_env = "newlib", + target_env = "devkita64", target_os = "solaris", target_os = "illumos", target_os = "emscripten", diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index cc8c455977475..15a458bf340a9 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -158,7 +158,7 @@ cfg_has_statx! {{ stat.st_mtime = buf.stx_mtime.tv_sec as libc::time_t; stat.st_ctime = buf.stx_ctime.tv_sec as libc::time_t; // `i64` on gnu-x86_64-x32, `c_ulong` otherwise. - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_env = "devkita64"))] { stat.st_atime_nsec = buf.stx_atime.tv_nsec as _; stat.st_mtime_nsec = buf.stx_mtime.tv_nsec as _; stat.st_ctime_nsec = buf.stx_ctime.tv_nsec as _; @@ -297,9 +297,9 @@ impl FileAttr { pub fn modified(&self) -> io::Result { Ok(SystemTime::from(libc::timespec { tv_sec: self.stat.st_mtime as libc::time_t, - #[cfg(target_env = "newlib")] + #[cfg(target_env = "devkita64")] tv_nsec: 0, - #[cfg(not(target_env = "newlib"))] + #[cfg(not(target_env = "devkita64"))] tv_nsec: self.stat.st_mtime_nsec as _, })) } @@ -307,9 +307,9 @@ impl FileAttr { pub fn accessed(&self) -> io::Result { Ok(SystemTime::from(libc::timespec { tv_sec: self.stat.st_atime as libc::time_t, - #[cfg(target_env = "newlib")] + #[cfg(target_env = "devkita64")] tv_nsec: 0, - #[cfg(not(target_env = "newlib"))] + #[cfg(not(target_env = "devkita64"))] tv_nsec: self.stat.st_atime_nsec as _, })) } @@ -569,7 +569,7 @@ impl DirEntry { target_os = "l4re", target_os = "fuchsia", target_os = "redox", - target_env = "newlib" + target_env = "devkita64" ))] pub fn ino(&self) -> u64 { self.entry.d_ino as u64 @@ -608,7 +608,7 @@ impl DirEntry { target_os = "emscripten", target_os = "l4re", target_os = "haiku", - target_env = "newlib" + target_env = "devkita64" ))] fn name_bytes(&self) -> &[u8] { unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes() } @@ -984,7 +984,7 @@ pub fn rmdir(p: &Path) -> io::Result<()> { Ok(()) } -#[cfg(not(target_os = "horizon"))] +#[cfg(not(target_os = "switch"))] pub fn readlink(p: &Path) -> io::Result { let c_path = cstr(p)?; let p = c_path.as_ptr(); @@ -1012,12 +1012,12 @@ pub fn readlink(p: &Path) -> io::Result { } } -#[cfg(target_os = "horizon")] +#[cfg(target_os = "switch")] pub fn readlink(p: &Path) -> io::Result { - Ok(p.to_path_buf()) // horizon doesn't have symlinks + Ok(p.to_path_buf()) // switch doesn't have symlinks } -#[cfg(not(target_os = "horizon"))] +#[cfg(not(target_os = "switch"))] pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { let src = cstr(src)?; let dst = cstr(dst)?; @@ -1025,9 +1025,9 @@ pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { Ok(()) } -#[cfg(target_os = "horizon")] +#[cfg(target_os = "switch")] pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> { - Err(io::Error::new(io::ErrorKind::Other, "not supported")) // horizon doesn't have symlinks + Err(io::Error::new(io::ErrorKind::Other, "not supported")) // switch doesn't have symlinks } pub fn link(src: &Path, dst: &Path) -> io::Result<()> { @@ -1075,7 +1075,7 @@ pub fn lstat(p: &Path) -> io::Result { Ok(FileAttr::from_stat64(stat)) } -#[cfg(not(target_os = "horizon"))] +#[cfg(not(target_os = "switch"))] pub fn canonicalize(p: &Path) -> io::Result { let path = CString::new(p.as_os_str().as_bytes())?; let buf; @@ -1090,9 +1090,9 @@ pub fn canonicalize(p: &Path) -> io::Result { Ok(PathBuf::from(OsString::from_vec(buf))) } -#[cfg(target_os = "horizon")] +#[cfg(target_os = "switch")] pub fn canonicalize(p: &Path) -> io::Result { - // horizon has no symlinks or realpath + // switch has no symlinks or realpath let mut cwd = crate::env::current_dir()?; cwd.push(p); Ok(cwd) diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index 0580692410748..0fb231fe46fbb 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -1,4 +1,4 @@ -#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] +#![cfg_attr(target_os = "switch", allow(unused_variables, dead_code))] use crate::cmp; use crate::ffi::CStr; @@ -307,21 +307,21 @@ impl Socket { } pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { setsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY, nodelay as c_int) } - #[cfg(target_env = "newlib")] { + #[cfg(target_os = "switch")] { Ok(()) } } - #[cfg(not(target_env = "newlib"))] + #[cfg(not(target_os = "switch"))] pub fn nodelay(&self) -> io::Result { let raw: c_int = getsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY)?; Ok(raw != 0) } - #[cfg(target_env = "newlib")] + #[cfg(target_os = "switch")] pub fn nodelay(&self) -> io::Result { Ok(false) } diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index f6c1a60cdf201..d9286e3ddfc46 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -1,7 +1,6 @@ //! Implementation of `std::os` functionality for unix systems #![allow(unused_imports)] // lots of cfg code here -#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] use crate::os::unix::prelude::*; @@ -51,7 +50,7 @@ extern "C" { target_os = "openbsd", target_os = "android", target_os = "redox", - target_env = "newlib" + target_env = "devkita64" ), link_name = "__errno" )] @@ -102,7 +101,7 @@ pub fn set_errno(e: i32) { /// Gets a detailed string description for the given error number. pub fn error_string(errno: i32) -> String { extern "C" { - #[cfg_attr(any(target_os = "linux", target_env = "newlib"), link_name = "__xpg_strerror_r")] + #[cfg_attr(any(target_os = "linux", target_env = "devkita64"), link_name = "__xpg_strerror_r")] fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: libc::size_t) -> c_int; } @@ -555,12 +554,12 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { } } -#[cfg(not(target_os = "horizon"))] +#[cfg(not(target_os = "switch"))] pub fn page_size() -> usize { unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize } } -#[cfg(target_os = "horizon")] +#[cfg(target_os = "switch")] pub fn page_size() -> usize { 0x1000 } @@ -583,7 +582,7 @@ pub fn home_dir() -> Option { target_os = "ios", target_os = "emscripten", target_os = "redox", - target_os = "horizon" + target_os = "switch" ))] unsafe fn fallback() -> Option { None @@ -593,7 +592,7 @@ pub fn home_dir() -> Option { target_os = "ios", target_os = "emscripten", target_os = "redox", - target_os = "horizon" + target_os = "switch" )))] unsafe fn fallback() -> Option { let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { @@ -628,14 +627,14 @@ pub fn getpid() -> u32 { unsafe { libc::getpid() as u32 } } -#[cfg(not(target_os = "horizon"))] +#[cfg(not(target_os = "switch"))] pub fn getppid() -> u32 { unsafe { libc::getppid() as u32 } } -#[cfg(target_os = "horizon")] +#[cfg(target_os = "switch")] pub fn getppid() -> u32 { - 1 // horizon doesn't have a process hierarchy + 1 // switch doesn't have a process hierarchy } #[cfg(target_env = "gnu")] diff --git a/library/std/src/sys/unix/pipe.rs b/library/std/src/sys/unix/pipe.rs index 89aebd1cc07ee..7ae37bdda70bd 100644 --- a/library/std/src/sys/unix/pipe.rs +++ b/library/std/src/sys/unix/pipe.rs @@ -1,5 +1,3 @@ -#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] - use crate::io::{self, IoSlice, IoSliceMut}; use crate::mem; use crate::sys::fd::FileDesc; diff --git a/library/std/src/sys/unix/process/mod.rs b/library/std/src/sys/unix/process/mod.rs index 41f0dc305af99..a0d609e57ad96 100644 --- a/library/std/src/sys/unix/process/mod.rs +++ b/library/std/src/sys/unix/process/mod.rs @@ -3,13 +3,13 @@ pub use self::process_inner::{ExitStatus, Process}; pub use crate::ffi::OsString as EnvKey; mod process_common; -#[cfg(not(any(target_os = "fuchsia", target_os = "horizon")))] +#[cfg(not(any(target_os = "fuchsia", target_env = "devkita64")))] #[path = "process_unix.rs"] mod process_inner; #[cfg(target_os = "fuchsia")] #[path = "process_fuchsia.rs"] mod process_inner; -#[cfg(target_os = "horizon")] +#[cfg(target_env = "devkita64")] #[path = "process_dummy.rs"] mod process_inner; #[cfg(target_os = "fuchsia")] diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 689cf3e1ab441..ec80154e0cbe1 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -1,4 +1,4 @@ -#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] +#![cfg_attr(target_env = "devkita64", allow(unused_variables, dead_code))] use crate::os::unix::prelude::*; diff --git a/library/std/src/sys/unix/process/process_dummy.rs b/library/std/src/sys/unix/process/process_dummy.rs index 88db58559f510..ca77c3e4b1fef 100644 --- a/library/std/src/sys/unix/process/process_dummy.rs +++ b/library/std/src/sys/unix/process/process_dummy.rs @@ -1,3 +1,6 @@ +//! DevkitA64 has very limited support for multiple processes, so a dummy implementation is used +//! there (similar to WebAssembly). + use crate::fmt; use crate::io; use crate::sys::process::process_common::*; diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs index c1bda6b430e13..3fd7d67b6ae5b 100644 --- a/library/std/src/sys/unix/thread.rs +++ b/library/std/src/sys/unix/thread.rs @@ -148,14 +148,14 @@ impl Thread { } #[cfg(any( - target_env = "newlib", + target_env = "devkita64", target_os = "haiku", target_os = "l4re", target_os = "emscripten", target_os = "redox" ))] pub fn set_name(_name: &CStr) { - // Newlib, Haiku, and Emscripten have no way to set a thread name. + // DevkitA64, Haiku, and Emscripten have no way to set a thread name. } #[cfg(target_os = "fuchsia")] pub fn set_name(_name: &CStr) { diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index 69fe9106a13f2..f48d720cc9684 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -339,9 +339,9 @@ mod inner { } } - #[cfg(not(any(target_os = "dragonfly", target_os = "horizon")))] + #[cfg(not(any(target_os = "dragonfly", target_env = "devkita64")))] pub type clock_t = libc::c_int; - #[cfg(any(target_os = "dragonfly", target_os = "horizon"))] + #[cfg(any(target_os = "dragonfly", target_env = "devkita64"))] pub type clock_t = libc::c_ulong; fn now(clock: clock_t) -> Timespec { diff --git a/library/std/src/sys/unix/weak.rs b/library/std/src/sys/unix/weak.rs index 48ca65e750ce2..d2e211bb43220 100644 --- a/library/std/src/sys/unix/weak.rs +++ b/library/std/src/sys/unix/weak.rs @@ -58,7 +58,7 @@ impl Weak { } } -#[cfg(not(target_env = "newlib"))] +#[cfg(not(target_env = "devkita64"))] unsafe fn fetch(name: &str) -> usize { let name = match CStr::from_bytes_with_nul(name.as_bytes()) { Ok(cstr) => cstr, @@ -67,7 +67,7 @@ unsafe fn fetch(name: &str) -> usize { libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize } -#[cfg(target_env = "newlib")] +#[cfg(target_env = "devkita64")] unsafe fn fetch(_name: &str) -> usize { 0 } diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index 5c8511a0dea9f..a0faa7130fcd9 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -1,4 +1,4 @@ -#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] +#![cfg_attr(target_os = "switch", allow(unused_variables, dead_code))] use crate::cmp; use crate::convert::{TryFrom, TryInto}; @@ -23,7 +23,7 @@ cfg_if::cfg_if! { target_os = "solaris", target_os = "haiku", target_os = "l4re"))] { use crate::sys::net::netc::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP; use crate::sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP; - } else if #[cfg(not(target_env = "newlib"))] { + } else if #[cfg(not(target_os = "switch"))] { use crate::sys::net::netc::IPV6_ADD_MEMBERSHIP; use crate::sys::net::netc::IPV6_DROP_MEMBERSHIP; } @@ -314,18 +314,18 @@ impl TcpStream { } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) } - #[cfg(target_env = "newlib")] { + #[cfg(target_os = "switch")] { Ok(()) } } pub fn ttl(&self) -> io::Result { - #[cfg(not(target_env = "newlib"))] + #[cfg(not(target_os = "switch"))] let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; - #[cfg(target_env = "newlib")] + #[cfg(target_os = "switch")] let raw: c_int = 64; Ok(raw as u32) } @@ -422,37 +422,37 @@ impl TcpListener { } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) } - #[cfg(target_env = "newlib")] { + #[cfg(target_os = "switch")] { Ok(()) } } pub fn ttl(&self) -> io::Result { - #[cfg(not(target_env = "newlib"))] + #[cfg(not(target_os = "switch"))] let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; - #[cfg(target_env = "newlib")] + #[cfg(target_os = "switch")] let raw: c_int = 64; Ok(raw as u32) } pub fn set_only_v6(&self, only_v6: bool) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY, only_v6 as c_int) } - #[cfg(target_env = "newlib")] { + #[cfg(target_os = "switch")] { Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } } pub fn only_v6(&self) -> io::Result { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)?; Ok(raw != 0) } - #[cfg(target_env = "newlib")] + #[cfg(target_os = "switch")] Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } @@ -574,7 +574,7 @@ impl UdpSocket { } pub fn set_multicast_loop_v4(&self, multicast_loop_v4: bool) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { setsockopt( &self.inner, c::IPPROTO_IP, @@ -582,23 +582,23 @@ impl UdpSocket { multicast_loop_v4 as IpV4MultiCastType, ) } - #[cfg(target_env = "newlib")] { + #[cfg(target_os = "switch")] { Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } } pub fn multicast_loop_v4(&self) -> io::Result { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP)?; Ok(raw != 0) } - #[cfg(target_env = "newlib")] { + #[cfg(target_os = "switch")] { Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } } pub fn set_multicast_ttl_v4(&self, multicast_ttl_v4: u32) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { setsockopt( &self.inner, c::IPPROTO_IP, @@ -606,99 +606,99 @@ impl UdpSocket { multicast_ttl_v4 as IpV4MultiCastType, ) } - #[cfg(target_env = "newlib")] { + #[cfg(target_os = "switch")] { Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } } pub fn multicast_ttl_v4(&self) -> io::Result { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL)?; Ok(raw as u32) } - #[cfg(target_env = "newlib")] + #[cfg(target_os = "switch")] Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn set_multicast_loop_v6(&self, multicast_loop_v6: bool) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP, multicast_loop_v6 as c_int) } - #[cfg(target_env = "newlib")] { + #[cfg(target_os = "switch")] { Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } } pub fn multicast_loop_v6(&self) -> io::Result { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP)?; Ok(raw != 0) } - #[cfg(target_env = "newlib")] + #[cfg(target_os = "switch")] Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn join_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { let mreq = c::ip_mreq { imr_multiaddr: *multiaddr.as_inner(), imr_interface: *interface.as_inner(), }; setsockopt(&self.inner, c::IPPROTO_IP, c::IP_ADD_MEMBERSHIP, mreq) } - #[cfg(target_env = "newlib")] + #[cfg(target_os = "switch")] Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn join_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { let mreq = c::ipv6_mreq { ipv6mr_multiaddr: *multiaddr.as_inner(), ipv6mr_interface: to_ipv6mr_interface(interface), }; setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq) } - #[cfg(target_env = "newlib")] + #[cfg(target_os = "switch")] Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn leave_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { let mreq = c::ip_mreq { imr_multiaddr: *multiaddr.as_inner(), imr_interface: *interface.as_inner(), }; setsockopt(&self.inner, c::IPPROTO_IP, c::IP_DROP_MEMBERSHIP, mreq) } - #[cfg(target_env = "newlib")] + #[cfg(target_os = "switch")] Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn leave_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { let mreq = c::ipv6_mreq { ipv6mr_multiaddr: *multiaddr.as_inner(), ipv6mr_interface: to_ipv6mr_interface(interface), }; setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, mreq) } - #[cfg(target_env = "newlib")] + #[cfg(target_os = "switch")] Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - #[cfg(not(target_env = "newlib"))] { + #[cfg(not(target_os = "switch"))] { setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) } - #[cfg(target_env = "newlib")] { + #[cfg(target_os = "switch")] { Ok(()) } } pub fn ttl(&self) -> io::Result { - #[cfg(not(target_env = "newlib"))] + #[cfg(not(target_os = "switch"))] let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; - #[cfg(target_env = "newlib")] + #[cfg(target_os = "switch")] let raw: c_int = 64; Ok(raw as u32) } diff --git a/library/test/src/helpers/concurrency.rs b/library/test/src/helpers/concurrency.rs index a596fab0584be..672335fd3d46b 100644 --- a/library/test/src/helpers/concurrency.rs +++ b/library/test/src/helpers/concurrency.rs @@ -109,15 +109,9 @@ cfg_if::cfg_if! { cpus as usize } } else { - // FIXME: implement on vxWorks, Redox, HermitCore, Haiku, l4re + // FIXME: implement on vxWorks, Redox, HermitCore, Haiku, l4re, libnx fn num_cpus() -> usize { 1 } } - - #[cfg(target_vendor = "libnx")] - fn num_cpus() -> usize { - // FIXME: implement - 1 - } } diff --git a/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs similarity index 90% rename from src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs rename to src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index 710df77f7fa38..99386023fa659 100644 --- a/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -24,9 +24,9 @@ pub fn target() -> Result { target_endian: "little".to_string(), target_pointer_width: "64".to_string(), target_c_int_width: "32".to_string(), - target_os: "horizon".to_string(), - target_env: "newlib".to_string(), - target_vendor: "libnx".to_string(), + target_os: "switch".to_string(), + target_env: "devkita64".to_string(), + target_vendor: "unknown".to_string(), data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), linker_flavor: LinkerFlavor::Gcc, diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index e1a5efe3e64db..3c038e07a71c8 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -678,7 +678,7 @@ supported_targets! { ("mipsel-sony-psp", mipsel_sony_psp), ("thumbv4t-none-eabi", thumbv4t_none_eabi), - ("aarch64-unknown-horizon-libnx", aarch64_unknown_horizon_libnx), + ("aarch64-unknown-switch-devkita64", aarch64_unknown_switch_devkita64), } /// Everything `rustc` knows about how to compile for a specific target. From 426735b8be14603db4195dfba4f8190da962f248 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Fri, 17 Jul 2020 21:33:46 -0400 Subject: [PATCH 15/38] Switch to new unsupported_abis name --- src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index 99386023fa659..7f053eb0163a4 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -10,7 +10,7 @@ pub fn target() -> Result { linker_is_gnu: true, max_atomic_width: Some(128), panic_strategy: PanicStrategy::Unwind, - abi_blacklist: super::arm_base::abi_blacklist(), + unsupported_abis: super::arm_base::unsupported_abis(), target_family: Some("unix".to_string()), position_independent_executables: true, has_elf_tls: false, From 480cb7f162e9fed40d5c13415b13cbb71f96b83d Mon Sep 17 00:00:00 2001 From: leo60228 Date: Fri, 17 Jul 2020 23:00:59 -0400 Subject: [PATCH 16/38] Add disabled CI Docker image --- .../disabled/aarch64-devkita64/Dockerfile | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/ci/docker/host-x86_64/disabled/aarch64-devkita64/Dockerfile diff --git a/src/ci/docker/host-x86_64/disabled/aarch64-devkita64/Dockerfile b/src/ci/docker/host-x86_64/disabled/aarch64-devkita64/Dockerfile new file mode 100644 index 0000000000000..d0674f48381f4 --- /dev/null +++ b/src/ci/docker/host-x86_64/disabled/aarch64-devkita64/Dockerfile @@ -0,0 +1,26 @@ +FROM devkitpro/devkita64:20200528 + +COPY scripts/cross-apt-packages.sh /scripts/ +RUN sh /scripts/cross-apt-packages.sh + +COPY scripts/rustbuild-setup.sh /scripts/ +RUN sh /scripts/rustbuild-setup.sh +USER rustbuild +WORKDIR /tmp + +USER root + +COPY scripts/sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +ENV PATH=$PATH:/opt/devkitpro/devkitA64/bin/ + +ENV CC_aarch64_unknown_switch_devkita64=aarch64-none-elf-gcc \ + AR_aarch64_unknown_switch_devkita64=aarch64-none-elf-ar \ + CXX_aarch64_unknown_switch_devkita64=aarch64-none-elf-g++ + +ENV TARGETS=aarch64-unknown-switch-devkita64 + +ENV RUST_CONFIGURE_ARGS \ + --disable-docs +ENV SCRIPT python3 ../x.py dist --target $TARGETS From 58a07500b4dacf8ca3f228e579d3ee8d36f12156 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Fri, 17 Jul 2020 23:01:06 -0400 Subject: [PATCH 17/38] Fix build --- Cargo.toml | 2 ++ library/std/Cargo.toml | 3 +-- library/std/build.rs | 1 + library/std/src/os/{libnx => devkita64}/fs.rs | 2 +- library/std/src/os/{libnx => devkita64}/mod.rs | 2 +- library/std/src/os/{libnx => devkita64}/raw.rs | 0 library/std/src/os/mod.rs | 4 ++-- library/std/src/sys/unix/args.rs | 2 +- library/std/src/sys/unix/fd.rs | 10 ++++++++++ library/std/src/sys/unix/mod.rs | 4 ++-- library/std/src/sys/unix/os.rs | 2 +- library/test/src/helpers/concurrency.rs | 2 +- library/unwind/build.rs | 4 ++-- .../spec/aarch64_unknown_switch_devkita64.rs | 4 ++-- 14 files changed, 27 insertions(+), 15 deletions(-) rename library/std/src/os/{libnx => devkita64}/fs.rs (99%) rename library/std/src/os/{libnx => devkita64}/mod.rs (68%) rename library/std/src/os/{libnx => devkita64}/raw.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 1936e35aa4c5d..4abe20eb30e09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,5 +98,7 @@ rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' } # source code for this crate. backtrace = { path = "library/backtrace" } +libc = { git = 'https://github.com/leo60228/libc.git', branch = 'bindgen-horizon' } + [patch."https://github.com/rust-lang/rust-clippy"] clippy_lints = { path = "src/tools/clippy/clippy_lints" } diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index b85a848bd6af7..fc07fa77b85e7 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -16,8 +16,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] } panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core" } -#libc = { version = "0.2.51", default-features = false, features = ['rustc-dep-of-std'] } -libc = { git = "https://github.com/leo60228/libc.git", branch = "bindgen-horizon", default-features = false, features = ['rustc-dep-of-std'] } +libc = { version = "0.2.51", default-features = false, features = ['rustc-dep-of-std'] } compiler_builtins = { version = "0.1.32" } profiler_builtins = { path = "../profiler_builtins", optional = true } unwind = { path = "../unwind" } diff --git a/library/std/build.rs b/library/std/build.rs index 83073cc77dd1a..d615e9bf8f399 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -71,6 +71,7 @@ fn main() { || target.contains("vxworks") || target.contains("wasm32") || target.contains("asmjs") + || target.contains("devkita64") { // These platforms don't have any special requirements. } else { diff --git a/library/std/src/os/libnx/fs.rs b/library/std/src/os/devkita64/fs.rs similarity index 99% rename from library/std/src/os/libnx/fs.rs rename to library/std/src/os/devkita64/fs.rs index bd2b6bb6050c9..53185267e224e 100644 --- a/library/std/src/os/libnx/fs.rs +++ b/library/std/src/os/devkita64/fs.rs @@ -4,7 +4,7 @@ use crate::fs::Metadata; use crate::sys_common::AsInner; #[allow(deprecated)] -use crate::os::libnx::raw; +use crate::os::devkita64::raw; /// OS-specific extensions to [`fs::Metadata`]. /// diff --git a/library/std/src/os/libnx/mod.rs b/library/std/src/os/devkita64/mod.rs similarity index 68% rename from library/std/src/os/libnx/mod.rs rename to library/std/src/os/devkita64/mod.rs index 1af6dd10ade6b..fe5be4d8a9de2 100644 --- a/library/std/src/os/libnx/mod.rs +++ b/library/std/src/os/devkita64/mod.rs @@ -1,4 +1,4 @@ -//! libnx-specific definitions +//! DevkitA64-specific definitions #![stable(feature = "raw_ext", since = "1.1.0")] diff --git a/library/std/src/os/libnx/raw.rs b/library/std/src/os/devkita64/raw.rs similarity index 100% rename from library/std/src/os/libnx/raw.rs rename to library/std/src/os/devkita64/raw.rs diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index a9bafd5dd611c..0365ec8eedf11 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -70,7 +70,7 @@ pub mod solaris; pub mod vxworks; #[cfg(target_os = "wasi")] pub mod wasi; -#[cfg(target_vendor = "libnx")] -pub mod libnx; +#[cfg(target_env = "devkita64")] +pub mod devkita64; pub mod raw; diff --git a/library/std/src/sys/unix/args.rs b/library/std/src/sys/unix/args.rs index 7aafdaa9907e9..f5557b6b3d201 100644 --- a/library/std/src/sys/unix/args.rs +++ b/library/std/src/sys/unix/args.rs @@ -71,7 +71,7 @@ impl DoubleEndedIterator for Args { target_os = "l4re", target_os = "fuchsia", target_os = "redox", - target_vendor = "libnx" + target_env = "devkita64" ))] mod imp { use super::Args; diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index 913699ee4c675..9a63115242629 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -85,6 +85,11 @@ impl FileDesc { Ok(ret as usize) } + #[cfg(target_env = "devkita64")] + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { + io::default_read_vectored(|x| self.read(x), bufs) + } + #[inline] pub fn is_read_vectored(&self) -> bool { !cfg!(target_env = "devkita64") @@ -158,6 +163,11 @@ impl FileDesc { Ok(ret as usize) } + #[cfg(target_env = "devkita64")] + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { + io::default_write_vectored(|x| self.write(x), bufs) + } + #[inline] pub fn is_write_vectored(&self) -> bool { !cfg!(target_env = "devkita64") diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index bbbf6f5f2f97d..aa08b146847d4 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -33,8 +33,8 @@ pub use crate::os::openbsd as platform; pub use crate::os::redox as platform; #[cfg(all(not(doc), target_os = "solaris"))] pub use crate::os::solaris as platform; -#[cfg(all(not(doc), target_vendor = "libnx"))] -pub use crate::os::libnx as platform; +#[cfg(all(not(doc), target_env = "devkita64"))] +pub use crate::os::devkita64 as platform; pub use self::rand::hashmap_random_keys; pub use libc::strlen; diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index d9286e3ddfc46..4607223818de0 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -436,7 +436,7 @@ pub fn current_exe() -> io::Result { Err(io::Error::new(ErrorKind::Other, "Not yet implemented!")) } -#[cfg(target_vendor = "libnx")] +#[cfg(target_env = "devkita64")] pub fn current_exe() -> io::Result { use crate::env; // guaranteed by abi to be an absolute path to the executable diff --git a/library/test/src/helpers/concurrency.rs b/library/test/src/helpers/concurrency.rs index 672335fd3d46b..992ab14f99ee0 100644 --- a/library/test/src/helpers/concurrency.rs +++ b/library/test/src/helpers/concurrency.rs @@ -109,7 +109,7 @@ cfg_if::cfg_if! { cpus as usize } } else { - // FIXME: implement on vxWorks, Redox, HermitCore, Haiku, l4re, libnx + // FIXME: implement on vxWorks, Redox, HermitCore, Haiku, l4re, devkita64 fn num_cpus() -> usize { 1 } diff --git a/library/unwind/build.rs b/library/unwind/build.rs index 0890f1dbe471c..9d734347c8fb0 100644 --- a/library/unwind/build.rs +++ b/library/unwind/build.rs @@ -48,7 +48,7 @@ fn main() { // redox is handled in lib.rs } else if target.contains("cloudabi") { println!("cargo:rustc-link-lib=unwind"); - } else if target.contains("libnx") { + } else if target.contains("devkita64") { llvm_libunwind::compile(); } } @@ -122,7 +122,7 @@ mod llvm_libunwind { cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None); } - if target_vendor == "libnx" { + if target_env == "devkita64" { cfg.define("_LIBUNWIND_IS_BAREMETAL", None); cfg.define("_LIBUNWIND_SUPPORT_DWARF_UNWIND", None); cfg.define("_LIBUNWIND_SUPPORT_DWARF_INDEX", None); diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index 7f053eb0163a4..40b35256bedc5 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -1,11 +1,11 @@ -use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions}; +use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions, RelocModel}; pub fn target() -> Result { let opts = TargetOptions { linker: Some("aarch64-none-elf-gcc".to_owned()), features: "+a53,+strict-align,+crc".to_string(), executables: true, - relocation_model: "pic".to_string(), + relocation_model: RelocModel::Pic, disable_redzone: true, linker_is_gnu: true, max_atomic_width: Some(128), From eb2c2194f62ab99921f78ef9c4c598a5bba8c024 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Sat, 18 Jul 2020 10:19:41 -0400 Subject: [PATCH 18/38] Add Switch linker configuration --- src/librustc_codegen_ssa/back/link.rs | 14 +- .../spec/aarch64_unknown_switch_devkita64.rs | 37 ++- ...aarch64_unknown_switch_devkita64_script.ld | 217 ++++++++++++++++++ 3 files changed, 265 insertions(+), 3 deletions(-) create mode 100644 src/librustc_target/spec/aarch64_unknown_switch_devkita64_script.ld diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index d725a60118e3c..62683fe832b87 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -1349,8 +1349,18 @@ fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_ty sess.fatal(&format!("failed to write link script to {}: {}", path.display(), e)); } - cmd.arg("--script"); - cmd.arg(path); + if sess.target.target.linker_flavor == LinkerFlavor::Gcc { + cmd.arg("-Wl,--script"); + let path_str = if let Some(s) = path.to_str() { + s + } else { + sess.fatal(&format!("linker script path {:?} is invalid Unicode", path)); + }; + cmd.arg(format!("-Wl,{}", path_str)); + } else { + cmd.arg("--script"); + cmd.arg(path); + } } _ => {} } diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index 40b35256bedc5..2cadf6b162c65 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -1,6 +1,39 @@ -use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions, RelocModel}; +use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions, RelocModel, LinkArgs}; + +// DevkitA64 has custom linker requirements. +const LINKER_SCRIPT: &str = include_str!("./aarch64_unknown_switch_devkita64_script.ld"); pub fn target() -> Result { + let mut link_args = LinkArgs::new(); + link_args.insert(LinkerFlavor::Gcc, vec![ + "-march=armv8-a".to_string(), + "-mtune=cortex-a57".to_string(), + "-mtp=soft".to_string(), + "-nodefaultlibs".to_string(), + "-nostdlib".to_string(), + "-nostartfiles".to_string(), + "-L/opt/devkitpro/portlibs/switch/lib".to_string(), + "-L/opt/devkitpro/libnx/lib".to_string(), + "-L/opt/devkitpro/devkitA64/lib/gcc/aarch64-none-elf/10.1.0/pic".to_string(), + "-L/opt/devkitpro/devkitA64/aarch64-none-elf/lib/pic".to_string(), + "-Wl,--start-group".to_string(), + "-lgcc".to_string(), + "-lc".to_string(), + "-lnx".to_string(), + "-lsysbase".to_string(), + "-lm".to_string(), + "-l:crtbegin.o".to_string(), + "-l:crtend.o".to_string(), + "-l:crti.o".to_string(), + "-l:crtn.o".to_string(), + "-Wl,--end-group".to_string(), + "-fPIE".to_string(), + "-pie".to_string(), + "-Wl,-z,text".to_string(), + "-Wl,-z,muldefs".to_string(), + "-Wl,--export-dynamic".to_string(), + "-Wl,--eh-frame-hdr".to_string(), + ]); let opts = TargetOptions { linker: Some("aarch64-none-elf-gcc".to_owned()), features: "+a53,+strict-align,+crc".to_string(), @@ -17,6 +50,8 @@ pub fn target() -> Result { trap_unreachable: true, emit_debug_gdb_scripts: true, requires_uwtable: true, + post_link_args: link_args, + link_script: Some(LINKER_SCRIPT.to_string()), ..Default::default() }; Ok(Target { diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64_script.ld b/src/librustc_target/spec/aarch64_unknown_switch_devkita64_script.ld new file mode 100644 index 0000000000000..2b0842fc359c4 --- /dev/null +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64_script.ld @@ -0,0 +1,217 @@ +OUTPUT_ARCH(aarch64) +ENTRY(_start) + +PHDRS +{ + code PT_LOAD FLAGS(5) /* Read | Execute */; + rodata PT_LOAD FLAGS(4) /* Read */; + data PT_LOAD FLAGS(6) /* Read | Write */; + dyn PT_DYNAMIC; +} + +SECTIONS +{ + /* =========== CODE section =========== */ + PROVIDE(__start__ = 0x0); + . = __start__; + __code_start = . ; + + .crt0 : + { + KEEP (*(.crt0)) + . = ALIGN(8); + } :code + + .init : + { + KEEP( *(.init) ) + . = ALIGN(8); + } :code + + .plt : + { + *(.plt) + *(.iplt) + . = ALIGN(8); + } :code + + .text : + { + *(.text.unlikely .text.*_unlikely .text.unlikely.*) + *(.text.exit .text.exit.*) + *(.text.startup .text.startup.*) + *(.text.hot .text.hot.*) + *(.text .stub .text.* .gnu.linkonce.t.*) + . = ALIGN(8); + } :code + + .fini : + { + KEEP( *(.fini) ) + . = ALIGN(8); + } :code + + /* =========== RODATA section =========== */ + . = ALIGN(0x1000); + __rodata_start = . ; + + .nx-module-name : { KEEP (*(.nx-module-name)) } :rodata + + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + . = ALIGN(8); + } :rodata + + .eh_frame_hdr : { __eh_frame_hdr_start = .; KEEP(*(.eh_frame_hdr)) KEEP(*(.eh_frame_entry .eh_frame_entry.*)) __eh_frame_hdr_end = .; } :rodata + .eh_frame : ONLY_IF_RO { __eh_frame_start = .; KEEP (*(.eh_frame)) *(.eh_frame.*) __eh_frame_end = .; } :rodata + .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } :rodata + .gnu_extab : ONLY_IF_RO { *(.gnu_extab*) } : rodata + + .dynamic : { *(.dynamic) } :rodata :dyn + .dynsym : { *(.dynsym) } :rodata + .dynstr : { *(.dynstr) } :rodata + .rela.dyn : { *(.rela.*) } :rodata + .interp : { *(.interp) } :rodata + .hash : { *(.hash) } :rodata + .gnu.hash : { *(.gnu.hash) } :rodata + .gnu.version : { *(.gnu.version) } :rodata + .gnu.version_d : { *(.gnu.version_d) } :rodata + .gnu.version_r : { *(.gnu.version_r) } :rodata + .note.gnu.build-id : { *(.note.gnu.build-id) } :rodata + + /* =========== DATA section =========== */ + . = ALIGN(0x1000); + __data_start = . ; + + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) } :data + .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } :data + .gnu_extab : ONLY_IF_RW { *(.gnu_extab*) } : data + .exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) } :data + + .tdata ALIGN(8) : + { + __tdata_lma = .; + *(.tdata .tdata.* .gnu.linkonce.td.*) + . = ALIGN(8); + __tdata_lma_end = .; + } :data + + .tbss ALIGN(8) : + { + *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) + . = ALIGN(8); + } :data + + .preinit_array ALIGN(8) : + { + PROVIDE (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE (__preinit_array_end = .); + } :data + + .init_array ALIGN(8) : + { + PROVIDE (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE (__init_array_end = .); + } :data + + .fini_array ALIGN(8) : + { + PROVIDE (__fini_array_start = .); + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + PROVIDE (__fini_array_end = .); + } :data + + .ctors ALIGN(8) : + { + KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } :data + + .dtors ALIGN(8) : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } :data + + __got_start__ = .; + + .got : { *(.got) *(.igot) } :data + .got.plt : { *(.got.plt) *(.igot.plt) } :data + + __got_end__ = .; + + .data ALIGN(8) : + { + *(.data .data.* .gnu.linkonce.d.*) + SORT(CONSTRUCTORS) + } :data + + __bss_start__ = .; + .bss ALIGN(8) : + { + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(8); + + /* Reserve space for the TLS segment of the main thread */ + __tls_start = .; + . += + SIZEOF(.tdata) + SIZEOF(.tbss); + __tls_end = .; + } : data + __bss_end__ = .; + + __end__ = ABSOLUTE(.) ; + + . = ALIGN(0x1000); + __argdata__ = ABSOLUTE(.) ; + + /* ================== + ==== Metadata ==== + ================== */ + + /* Discard sections that difficult post-processing */ + /DISCARD/ : { *(.group .comment .note) } + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } +} From bc9d603f6c5a5c0b9a06385d7ba6f734a30fea6a Mon Sep 17 00:00:00 2001 From: leo60228 Date: Sun, 19 Jul 2020 18:10:50 -0400 Subject: [PATCH 19/38] Initialize romfs on startup This is necessary for backtraces. --- library/std/src/os/devkita64/mod.rs | 13 +++++++++++++ library/std/src/rt.rs | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/library/std/src/os/devkita64/mod.rs b/library/std/src/os/devkita64/mod.rs index fe5be4d8a9de2..1761c5f54bf08 100644 --- a/library/std/src/os/devkita64/mod.rs +++ b/library/std/src/os/devkita64/mod.rs @@ -4,3 +4,16 @@ pub mod fs; pub mod raw; + +extern "C" { + fn romfsMountSelf(name: *const u8) -> u32; +} + +/// This is necessary for getting debug info (needed by backtraces). +pub(crate) fn initialize_romfs() { + unsafe { + // This will return an error if there isn't a romfs, which can be safely ignored. + // SAFETY: We're passing a valid C string to romfsMountSelf. + let _ = romfsMountSelf(b"romfs\0" as *const _); + } +} diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index 45af9f68a0f6b..dce3967655e8d 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -47,6 +47,10 @@ fn lang_start_internal( // Store our args if necessary in a squirreled away location sys::args::init(argc, argv); + // Load romfs (which contains debug info) on DevkitA64 + #[cfg(target_env = "devkita64")] + crate::os::devkita64::initialize_romfs(); + // Let's run some code! let exit_code = panic::catch_unwind(main); From 39bfc206e36533544abd9c81de1bb83578db8f4a Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 10:18:14 -0400 Subject: [PATCH 20/38] Support LLVM TLS on Switch --- .gitmodules | 4 ++-- library/std/src/sys/unix/thread_local_dtor.rs | 4 ++++ src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs | 4 ++-- src/llvm-project | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index a327aaa8d5a34..7ddb390c23f64 100644 --- a/.gitmodules +++ b/.gitmodules @@ -36,8 +36,8 @@ url = https://github.com/rust-lang/edition-guide.git [submodule "src/llvm-project"] path = src/llvm-project - url = https://github.com/rust-lang/llvm-project.git - branch = rustc/10.0-2020-05-05 + url = https://github.com/leo60228/llvm-project.git + branch = devkita64 [submodule "src/doc/embedded-book"] path = src/doc/embedded-book url = https://github.com/rust-embedded/book.git diff --git a/library/std/src/sys/unix/thread_local_dtor.rs b/library/std/src/sys/unix/thread_local_dtor.rs index c3275eb6f0e50..912cfbb934bdc 100644 --- a/library/std/src/sys/unix/thread_local_dtor.rs +++ b/library/std/src/sys/unix/thread_local_dtor.rs @@ -92,3 +92,7 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { } } } + +// DevkitA64 doesn't seem to have a way to register thread-local destructors. +#[cfg(target_env = "devkita64")] +pub use crate::sys_common::thread_local_dtor::register_dtor_fallback as register_dtor; diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index 2cadf6b162c65..053eaa65922ef 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -36,7 +36,7 @@ pub fn target() -> Result { ]); let opts = TargetOptions { linker: Some("aarch64-none-elf-gcc".to_owned()), - features: "+a53,+strict-align,+crc".to_string(), + features: "+a53,+strict-align,+crc,+read-tp-soft".to_string(), executables: true, relocation_model: RelocModel::Pic, disable_redzone: true, @@ -46,7 +46,7 @@ pub fn target() -> Result { unsupported_abis: super::arm_base::unsupported_abis(), target_family: Some("unix".to_string()), position_independent_executables: true, - has_elf_tls: false, + has_elf_tls: true, trap_unreachable: true, emit_debug_gdb_scripts: true, requires_uwtable: true, diff --git a/src/llvm-project b/src/llvm-project index 86b120e6f302d..695b33a20e882 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 86b120e6f302d39cd6973b6391fb299d7bc22122 +Subproject commit 695b33a20e882235a311bb9dbccffb4d121fb04d From fc0bb2f2e4e95dbeccac9ac45bb1d3ef827fdf3d Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 13:11:04 -0400 Subject: [PATCH 21/38] Handle Switch linker args properly (BROKEN) --- src/librustc_codegen_ssa/back/linker.rs | 2 +- .../spec/aarch64_unknown_switch_devkita64.rs | 50 +++++++++++-------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/librustc_codegen_ssa/back/linker.rs b/src/librustc_codegen_ssa/back/linker.rs index f9a782af24cda..456dbd6f95ed3 100644 --- a/src/librustc_codegen_ssa/back/linker.rs +++ b/src/librustc_codegen_ssa/back/linker.rs @@ -301,7 +301,7 @@ impl<'a> Linker for GccLinker<'a> { if !self.is_ld { // Note that combination `-static -pie` doesn't work as expected // for the gcc wrapper, `-static` in that case suppresses `-pie`. - self.cmd.arg("-static-pie"); + self.cmd.args(&["-static-pie", "-pie", "-fPIE"]); } else { // `--no-dynamic-linker` and `-z text` are not strictly necessary for producing // a static pie, but currently passed because gcc and clang pass them. diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index 053eaa65922ef..4ef689dda7b63 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -4,35 +4,38 @@ use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions, RelocModel, Link const LINKER_SCRIPT: &str = include_str!("./aarch64_unknown_switch_devkita64_script.ld"); pub fn target() -> Result { - let mut link_args = LinkArgs::new(); - link_args.insert(LinkerFlavor::Gcc, vec![ + let mut pre_link_args = LinkArgs::new(); + pre_link_args.insert(LinkerFlavor::Gcc, vec![ + // from https://github.com/switchbrew/switch-examples/blob/master/templates/application/Makefile#L50 "-march=armv8-a".to_string(), "-mtune=cortex-a57".to_string(), "-mtp=soft".to_string(), - "-nodefaultlibs".to_string(), - "-nostdlib".to_string(), - "-nostartfiles".to_string(), + // from https://github.com/switchbrew/switch-examples/blob/master/templates/application/Makefile#L68 "-L/opt/devkitpro/portlibs/switch/lib".to_string(), "-L/opt/devkitpro/libnx/lib".to_string(), - "-L/opt/devkitpro/devkitA64/lib/gcc/aarch64-none-elf/10.1.0/pic".to_string(), - "-L/opt/devkitpro/devkitA64/aarch64-none-elf/lib/pic".to_string(), - "-Wl,--start-group".to_string(), - "-lgcc".to_string(), - "-lc".to_string(), - "-lnx".to_string(), - "-lsysbase".to_string(), - "-lm".to_string(), - "-l:crtbegin.o".to_string(), - "-l:crtend.o".to_string(), + // from https://github.com/switchbrew/libnx/blob/master/nx/switch.specs + "-nostartfiles".to_string(), "-l:crti.o".to_string(), - "-l:crtn.o".to_string(), - "-Wl,--end-group".to_string(), - "-fPIE".to_string(), - "-pie".to_string(), + "-l:crtbegin.o".to_string(), + ]); + let mut late_link_args = LinkArgs::new(); + late_link_args.insert(LinkerFlavor::Gcc, vec![ + // from https://github.com/switchbrew/switch-examples/blob/master/templates/application/Makefile#L62 + "-lnx".to_string(), + ]); + let mut post_link_args = LinkArgs::new(); + post_link_args.insert(LinkerFlavor::Gcc, vec![ + // from https://github.com/switchbrew/libnx/blob/master/nx/switch.specs "-Wl,-z,text".to_string(), + "-Wl,-z,nodynamic-undefined-weak".to_string(), + "-Wl,--build-id=sha1".to_string(), + "-Wl,--nx-module-name".to_string(), + // from https://github.com/switchbrew/libnx/blob/master/nx/switch.specs (implicit) + "-l:crtend.o".to_string(), + // this shouldn't be necessary (it isn't used in C), maybe it's needed because libc explicitly links `-lc`? "-Wl,-z,muldefs".to_string(), + // force an _DYNAMIC symbol to be added even in static binaries (needed by crt0) "-Wl,--export-dynamic".to_string(), - "-Wl,--eh-frame-hdr".to_string(), ]); let opts = TargetOptions { linker: Some("aarch64-none-elf-gcc".to_owned()), @@ -46,11 +49,16 @@ pub fn target() -> Result { unsupported_abis: super::arm_base::unsupported_abis(), target_family: Some("unix".to_string()), position_independent_executables: true, + static_position_independent_executables: true, has_elf_tls: true, + crt_static_default: true, trap_unreachable: true, emit_debug_gdb_scripts: true, requires_uwtable: true, - post_link_args: link_args, + pre_link_args, + late_link_args, + post_link_args, + no_default_libraries: false, link_script: Some(LINKER_SCRIPT.to_string()), ..Default::default() }; From 49b553c3075c12f9a1a38ce73c73e838ba342352 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 13:11:09 -0400 Subject: [PATCH 22/38] Revert "Handle Switch linker args properly (BROKEN)" This reverts commit ce1a09590186118e9f822b99f58b091b230cf848. --- src/librustc_codegen_ssa/back/linker.rs | 2 +- .../spec/aarch64_unknown_switch_devkita64.rs | 50 ++++++++----------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/librustc_codegen_ssa/back/linker.rs b/src/librustc_codegen_ssa/back/linker.rs index 456dbd6f95ed3..f9a782af24cda 100644 --- a/src/librustc_codegen_ssa/back/linker.rs +++ b/src/librustc_codegen_ssa/back/linker.rs @@ -301,7 +301,7 @@ impl<'a> Linker for GccLinker<'a> { if !self.is_ld { // Note that combination `-static -pie` doesn't work as expected // for the gcc wrapper, `-static` in that case suppresses `-pie`. - self.cmd.args(&["-static-pie", "-pie", "-fPIE"]); + self.cmd.arg("-static-pie"); } else { // `--no-dynamic-linker` and `-z text` are not strictly necessary for producing // a static pie, but currently passed because gcc and clang pass them. diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index 4ef689dda7b63..053eaa65922ef 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -4,38 +4,35 @@ use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions, RelocModel, Link const LINKER_SCRIPT: &str = include_str!("./aarch64_unknown_switch_devkita64_script.ld"); pub fn target() -> Result { - let mut pre_link_args = LinkArgs::new(); - pre_link_args.insert(LinkerFlavor::Gcc, vec![ - // from https://github.com/switchbrew/switch-examples/blob/master/templates/application/Makefile#L50 + let mut link_args = LinkArgs::new(); + link_args.insert(LinkerFlavor::Gcc, vec![ "-march=armv8-a".to_string(), "-mtune=cortex-a57".to_string(), "-mtp=soft".to_string(), - // from https://github.com/switchbrew/switch-examples/blob/master/templates/application/Makefile#L68 + "-nodefaultlibs".to_string(), + "-nostdlib".to_string(), + "-nostartfiles".to_string(), "-L/opt/devkitpro/portlibs/switch/lib".to_string(), "-L/opt/devkitpro/libnx/lib".to_string(), - // from https://github.com/switchbrew/libnx/blob/master/nx/switch.specs - "-nostartfiles".to_string(), - "-l:crti.o".to_string(), - "-l:crtbegin.o".to_string(), - ]); - let mut late_link_args = LinkArgs::new(); - late_link_args.insert(LinkerFlavor::Gcc, vec![ - // from https://github.com/switchbrew/switch-examples/blob/master/templates/application/Makefile#L62 + "-L/opt/devkitpro/devkitA64/lib/gcc/aarch64-none-elf/10.1.0/pic".to_string(), + "-L/opt/devkitpro/devkitA64/aarch64-none-elf/lib/pic".to_string(), + "-Wl,--start-group".to_string(), + "-lgcc".to_string(), + "-lc".to_string(), "-lnx".to_string(), - ]); - let mut post_link_args = LinkArgs::new(); - post_link_args.insert(LinkerFlavor::Gcc, vec![ - // from https://github.com/switchbrew/libnx/blob/master/nx/switch.specs - "-Wl,-z,text".to_string(), - "-Wl,-z,nodynamic-undefined-weak".to_string(), - "-Wl,--build-id=sha1".to_string(), - "-Wl,--nx-module-name".to_string(), - // from https://github.com/switchbrew/libnx/blob/master/nx/switch.specs (implicit) + "-lsysbase".to_string(), + "-lm".to_string(), + "-l:crtbegin.o".to_string(), "-l:crtend.o".to_string(), - // this shouldn't be necessary (it isn't used in C), maybe it's needed because libc explicitly links `-lc`? + "-l:crti.o".to_string(), + "-l:crtn.o".to_string(), + "-Wl,--end-group".to_string(), + "-fPIE".to_string(), + "-pie".to_string(), + "-Wl,-z,text".to_string(), "-Wl,-z,muldefs".to_string(), - // force an _DYNAMIC symbol to be added even in static binaries (needed by crt0) "-Wl,--export-dynamic".to_string(), + "-Wl,--eh-frame-hdr".to_string(), ]); let opts = TargetOptions { linker: Some("aarch64-none-elf-gcc".to_owned()), @@ -49,16 +46,11 @@ pub fn target() -> Result { unsupported_abis: super::arm_base::unsupported_abis(), target_family: Some("unix".to_string()), position_independent_executables: true, - static_position_independent_executables: true, has_elf_tls: true, - crt_static_default: true, trap_unreachable: true, emit_debug_gdb_scripts: true, requires_uwtable: true, - pre_link_args, - late_link_args, - post_link_args, - no_default_libraries: false, + post_link_args: link_args, link_script: Some(LINKER_SCRIPT.to_string()), ..Default::default() }; From 056c5e179173f9cac6377f24201fc21ec7993268 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 13:29:33 -0400 Subject: [PATCH 23/38] fmt --- library/std/src/os/mod.rs | 4 +- library/std/src/sys/unix/mod.rs | 4 +- library/std/src/sys/unix/net.rs | 6 +- library/std/src/sys/unix/os.rs | 12 ++- .../std/src/sys/unix/process/process_dummy.rs | 2 +- library/std/src/sys_common/net.rs | 82 +++++++++++++------ .../spec/aarch64_unknown_switch_devkita64.rs | 63 +++++++------- 7 files changed, 106 insertions(+), 67 deletions(-) diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index 0365ec8eedf11..e71be01fe57a9 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -40,6 +40,8 @@ cfg_if::cfg_if! { #[cfg(target_os = "android")] pub mod android; +#[cfg(target_env = "devkita64")] +pub mod devkita64; #[cfg(target_os = "dragonfly")] pub mod dragonfly; #[cfg(target_os = "emscripten")] @@ -70,7 +72,5 @@ pub mod solaris; pub mod vxworks; #[cfg(target_os = "wasi")] pub mod wasi; -#[cfg(target_env = "devkita64")] -pub mod devkita64; pub mod raw; diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index aa08b146847d4..9bd9295d1dfe6 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -7,6 +7,8 @@ pub use crate::os::linux as platform; #[cfg(all(not(doc), target_os = "android"))] pub use crate::os::android as platform; +#[cfg(all(not(doc), target_env = "devkita64"))] +pub use crate::os::devkita64 as platform; #[cfg(all(not(doc), target_os = "dragonfly"))] pub use crate::os::dragonfly as platform; #[cfg(all(not(doc), target_os = "emscripten"))] @@ -33,8 +35,6 @@ pub use crate::os::openbsd as platform; pub use crate::os::redox as platform; #[cfg(all(not(doc), target_os = "solaris"))] pub use crate::os::solaris as platform; -#[cfg(all(not(doc), target_env = "devkita64"))] -pub use crate::os::devkita64 as platform; pub use self::rand::hashmap_random_keys; pub use libc::strlen; diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index 0fb231fe46fbb..6952f11e5b34f 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -307,10 +307,12 @@ impl Socket { } pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { setsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY, nodelay as c_int) } - #[cfg(target_os = "switch")] { + #[cfg(target_os = "switch")] + { Ok(()) } } diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 4607223818de0..f9050a0cf694a 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -101,7 +101,10 @@ pub fn set_errno(e: i32) { /// Gets a detailed string description for the given error number. pub fn error_string(errno: i32) -> String { extern "C" { - #[cfg_attr(any(target_os = "linux", target_env = "devkita64"), link_name = "__xpg_strerror_r")] + #[cfg_attr( + any(target_os = "linux", target_env = "devkita64"), + link_name = "__xpg_strerror_r" + )] fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: libc::size_t) -> c_int; } @@ -440,9 +443,10 @@ pub fn current_exe() -> io::Result { pub fn current_exe() -> io::Result { use crate::env; // guaranteed by abi to be an absolute path to the executable - env::args_os().next().map(From::from).ok_or_else(|| { - io::Error::new(io::ErrorKind::Other, "no current exe available") - }) + env::args_os() + .next() + .map(From::from) + .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "no current exe available")) } pub struct Env { diff --git a/library/std/src/sys/unix/process/process_dummy.rs b/library/std/src/sys/unix/process/process_dummy.rs index ca77c3e4b1fef..19832487ad46e 100644 --- a/library/std/src/sys/unix/process/process_dummy.rs +++ b/library/std/src/sys/unix/process/process_dummy.rs @@ -3,8 +3,8 @@ use crate::fmt; use crate::io; -use crate::sys::process::process_common::*; use crate::os::raw::c_int; +use crate::sys::process::process_common::*; pub use crate::ffi::OsString as EnvKey; diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index a0faa7130fcd9..4ef7ffda05b8e 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -314,10 +314,12 @@ impl TcpStream { } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) } - #[cfg(target_os = "switch")] { + #[cfg(target_os = "switch")] + { Ok(()) } } @@ -422,10 +424,12 @@ impl TcpListener { } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) } - #[cfg(target_os = "switch")] { + #[cfg(target_os = "switch")] + { Ok(()) } } @@ -439,16 +443,19 @@ impl TcpListener { } pub fn set_only_v6(&self, only_v6: bool) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY, only_v6 as c_int) } - #[cfg(target_os = "switch")] { + #[cfg(target_os = "switch")] + { Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } } pub fn only_v6(&self) -> io::Result { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)?; Ok(raw != 0) } @@ -574,7 +581,8 @@ impl UdpSocket { } pub fn set_multicast_loop_v4(&self, multicast_loop_v4: bool) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { setsockopt( &self.inner, c::IPPROTO_IP, @@ -582,23 +590,28 @@ impl UdpSocket { multicast_loop_v4 as IpV4MultiCastType, ) } - #[cfg(target_os = "switch")] { + #[cfg(target_os = "switch")] + { Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } } pub fn multicast_loop_v4(&self) -> io::Result { - #[cfg(not(target_os = "switch"))] { - let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP)?; + #[cfg(not(target_os = "switch"))] + { + let raw: IpV4MultiCastType = + getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP)?; Ok(raw != 0) } - #[cfg(target_os = "switch")] { + #[cfg(target_os = "switch")] + { Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } } pub fn set_multicast_ttl_v4(&self, multicast_ttl_v4: u32) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { setsockopt( &self.inner, c::IPPROTO_IP, @@ -606,14 +619,17 @@ impl UdpSocket { multicast_ttl_v4 as IpV4MultiCastType, ) } - #[cfg(target_os = "switch")] { + #[cfg(target_os = "switch")] + { Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } } pub fn multicast_ttl_v4(&self) -> io::Result { - #[cfg(not(target_os = "switch"))] { - let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL)?; + #[cfg(not(target_os = "switch"))] + { + let raw: IpV4MultiCastType = + getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL)?; Ok(raw as u32) } #[cfg(target_os = "switch")] @@ -621,16 +637,24 @@ impl UdpSocket { } pub fn set_multicast_loop_v6(&self, multicast_loop_v6: bool) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { - setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP, multicast_loop_v6 as c_int) + #[cfg(not(target_os = "switch"))] + { + setsockopt( + &self.inner, + c::IPPROTO_IPV6, + c::IPV6_MULTICAST_LOOP, + multicast_loop_v6 as c_int, + ) } - #[cfg(target_os = "switch")] { + #[cfg(target_os = "switch")] + { Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } } pub fn multicast_loop_v6(&self) -> io::Result { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP)?; Ok(raw != 0) } @@ -639,7 +663,8 @@ impl UdpSocket { } pub fn join_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { let mreq = c::ip_mreq { imr_multiaddr: *multiaddr.as_inner(), imr_interface: *interface.as_inner(), @@ -651,7 +676,8 @@ impl UdpSocket { } pub fn join_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { let mreq = c::ipv6_mreq { ipv6mr_multiaddr: *multiaddr.as_inner(), ipv6mr_interface: to_ipv6mr_interface(interface), @@ -663,7 +689,8 @@ impl UdpSocket { } pub fn leave_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { let mreq = c::ip_mreq { imr_multiaddr: *multiaddr.as_inner(), imr_interface: *interface.as_inner(), @@ -675,7 +702,8 @@ impl UdpSocket { } pub fn leave_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { let mreq = c::ipv6_mreq { ipv6mr_multiaddr: *multiaddr.as_inner(), ipv6mr_interface: to_ipv6mr_interface(interface), @@ -687,10 +715,12 @@ impl UdpSocket { } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - #[cfg(not(target_os = "switch"))] { + #[cfg(not(target_os = "switch"))] + { setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) } - #[cfg(target_os = "switch")] { + #[cfg(target_os = "switch")] + { Ok(()) } } diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index 053eaa65922ef..4fbd20cb1b960 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -1,39 +1,42 @@ -use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions, RelocModel, LinkArgs}; +use super::{LinkArgs, LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions}; // DevkitA64 has custom linker requirements. const LINKER_SCRIPT: &str = include_str!("./aarch64_unknown_switch_devkita64_script.ld"); pub fn target() -> Result { let mut link_args = LinkArgs::new(); - link_args.insert(LinkerFlavor::Gcc, vec![ - "-march=armv8-a".to_string(), - "-mtune=cortex-a57".to_string(), - "-mtp=soft".to_string(), - "-nodefaultlibs".to_string(), - "-nostdlib".to_string(), - "-nostartfiles".to_string(), - "-L/opt/devkitpro/portlibs/switch/lib".to_string(), - "-L/opt/devkitpro/libnx/lib".to_string(), - "-L/opt/devkitpro/devkitA64/lib/gcc/aarch64-none-elf/10.1.0/pic".to_string(), - "-L/opt/devkitpro/devkitA64/aarch64-none-elf/lib/pic".to_string(), - "-Wl,--start-group".to_string(), - "-lgcc".to_string(), - "-lc".to_string(), - "-lnx".to_string(), - "-lsysbase".to_string(), - "-lm".to_string(), - "-l:crtbegin.o".to_string(), - "-l:crtend.o".to_string(), - "-l:crti.o".to_string(), - "-l:crtn.o".to_string(), - "-Wl,--end-group".to_string(), - "-fPIE".to_string(), - "-pie".to_string(), - "-Wl,-z,text".to_string(), - "-Wl,-z,muldefs".to_string(), - "-Wl,--export-dynamic".to_string(), - "-Wl,--eh-frame-hdr".to_string(), - ]); + link_args.insert( + LinkerFlavor::Gcc, + vec![ + "-march=armv8-a".to_string(), + "-mtune=cortex-a57".to_string(), + "-mtp=soft".to_string(), + "-nodefaultlibs".to_string(), + "-nostdlib".to_string(), + "-nostartfiles".to_string(), + "-L/opt/devkitpro/portlibs/switch/lib".to_string(), + "-L/opt/devkitpro/libnx/lib".to_string(), + "-L/opt/devkitpro/devkitA64/lib/gcc/aarch64-none-elf/10.1.0/pic".to_string(), + "-L/opt/devkitpro/devkitA64/aarch64-none-elf/lib/pic".to_string(), + "-Wl,--start-group".to_string(), + "-lgcc".to_string(), + "-lc".to_string(), + "-lnx".to_string(), + "-lsysbase".to_string(), + "-lm".to_string(), + "-l:crtbegin.o".to_string(), + "-l:crtend.o".to_string(), + "-l:crti.o".to_string(), + "-l:crtn.o".to_string(), + "-Wl,--end-group".to_string(), + "-fPIE".to_string(), + "-pie".to_string(), + "-Wl,-z,text".to_string(), + "-Wl,-z,muldefs".to_string(), + "-Wl,--export-dynamic".to_string(), + "-Wl,--eh-frame-hdr".to_string(), + ], + ); let opts = TargetOptions { linker: Some("aarch64-none-elf-gcc".to_owned()), features: "+a53,+strict-align,+crc,+read-tp-soft".to_string(), From 6ea2b7705b06f195847fb3db1bc01bac7721dc32 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 14:08:36 -0400 Subject: [PATCH 24/38] Move romfs initialization to sys::unix::init --- library/std/src/rt.rs | 4 ---- library/std/src/sys/unix/mod.rs | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index dce3967655e8d..45af9f68a0f6b 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -47,10 +47,6 @@ fn lang_start_internal( // Store our args if necessary in a squirreled away location sys::args::init(argc, argv); - // Load romfs (which contains debug info) on DevkitA64 - #[cfg(target_env = "devkita64")] - crate::os::devkita64::initialize_romfs(); - // Let's run some code! let exit_code = panic::catch_unwind(main); diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 9bd9295d1dfe6..14ab03651f1d5 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -77,6 +77,10 @@ pub use crate::sys_common::os_str_bytes as os_str; #[cfg(not(test))] pub fn init() { + // Load romfs (which contains debug info) on DevkitA64 + #[cfg(target_env = "devkita64")] + platform::initialize_romfs(); + // By default, some platforms will send a *signal* when an EPIPE error // would otherwise be delivered. This runtime doesn't install a SIGPIPE // handler, causing it to kill the program, which isn't exactly what we From f14034e87eb6b21c626dc5cf4558dbf339a66640 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 14:36:30 -0400 Subject: [PATCH 25/38] Whitelist libc fork for tidy (TEMPORARY) --- src/tools/tidy/src/extdeps.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index 1cf0d24e26ff5..9f0175fd074e0 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -4,7 +4,10 @@ use std::fs; use std::path::Path; /// List of allowed sources for packages. -const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\""]; +const ALLOWED_SOURCES: &[&str] = &[ + "\"registry+https://github.com/rust-lang/crates.io-index\"", + "\"git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#47fce90a5e10da634efe9cef76276c4fdb5cb35d\"", +]; /// Checks for external package sources. `root` is the path to the directory that contains the /// workspace `Cargo.toml`. From 1298bdfc436dbec879ad1ce6054889d2c2bf650d Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 14:36:59 -0400 Subject: [PATCH 26/38] Don't unnecessarily add library paths --- src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index 4fbd20cb1b960..c34ea8e053601 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -16,8 +16,6 @@ pub fn target() -> Result { "-nostartfiles".to_string(), "-L/opt/devkitpro/portlibs/switch/lib".to_string(), "-L/opt/devkitpro/libnx/lib".to_string(), - "-L/opt/devkitpro/devkitA64/lib/gcc/aarch64-none-elf/10.1.0/pic".to_string(), - "-L/opt/devkitpro/devkitA64/aarch64-none-elf/lib/pic".to_string(), "-Wl,--start-group".to_string(), "-lgcc".to_string(), "-lc".to_string(), From 8d1bff2f577b5ee45930de8ef7a7e9e4feca6c04 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 14:53:10 -0400 Subject: [PATCH 27/38] Add short blurb about building in Docker --- .../spec/aarch64_unknown_switch_devkita64.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index c34ea8e053601..7fcd86579ebce 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -1,3 +1,10 @@ +//! DevkitA64 Nintendo Switch homebrew toolchain. +//! +//! # Building +//! The recommended way to build Rust for this target is using Docker. You can start a build in a +//! container with `./src/ci/docker/run.sh aarch64-devkita64` from the Rust source tree. For +//! development, you can add `--dev` as the first argument to get a shell inside the container. + use super::{LinkArgs, LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions}; // DevkitA64 has custom linker requirements. From b6d25857ba07a1c70a30a51062a4935f74c7befb Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 15:24:05 -0400 Subject: [PATCH 28/38] Update libc --- Cargo.lock | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3f8bf0ac8e890..2347c7e127f36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1586,8 +1586,7 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" [[package]] name = "libc" version = "0.2.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10" +source = "git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#84597a8e80fbb7bb058a35677846006fc2bafa5c" dependencies = [ "rustc-std-workspace-core", ] From e600298183d07e6b7ec7e3ab6f4d05faadedabfa Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 15:49:07 -0400 Subject: [PATCH 29/38] Update tidy whitelist --- src/tools/tidy/src/extdeps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index 9f0175fd074e0..5e009fadd8367 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -6,7 +6,7 @@ use std::path::Path; /// List of allowed sources for packages. const ALLOWED_SOURCES: &[&str] = &[ "\"registry+https://github.com/rust-lang/crates.io-index\"", - "\"git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#47fce90a5e10da634efe9cef76276c4fdb5cb35d\"", + "\"git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#c64fc22e37bca14e942e0f7e8c365fc7b2d4c963\"", ]; /// Checks for external package sources. `root` is the path to the directory that contains the From 6b99f732225ffb81dd17a39cf161c6910e1560bd Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 15:54:01 -0400 Subject: [PATCH 30/38] Revert "Support LLVM TLS on Switch" This reverts commit cf82394a65b0ba08aaaf682910b4972618c03e61. pthreads TLS works fine for now, and has less of a maintenance burden. --- .gitmodules | 4 ++-- library/std/src/sys/unix/thread_local_dtor.rs | 4 ---- src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs | 4 ++-- src/llvm-project | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.gitmodules b/.gitmodules index 7ddb390c23f64..a327aaa8d5a34 100644 --- a/.gitmodules +++ b/.gitmodules @@ -36,8 +36,8 @@ url = https://github.com/rust-lang/edition-guide.git [submodule "src/llvm-project"] path = src/llvm-project - url = https://github.com/leo60228/llvm-project.git - branch = devkita64 + url = https://github.com/rust-lang/llvm-project.git + branch = rustc/10.0-2020-05-05 [submodule "src/doc/embedded-book"] path = src/doc/embedded-book url = https://github.com/rust-embedded/book.git diff --git a/library/std/src/sys/unix/thread_local_dtor.rs b/library/std/src/sys/unix/thread_local_dtor.rs index 912cfbb934bdc..c3275eb6f0e50 100644 --- a/library/std/src/sys/unix/thread_local_dtor.rs +++ b/library/std/src/sys/unix/thread_local_dtor.rs @@ -92,7 +92,3 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { } } } - -// DevkitA64 doesn't seem to have a way to register thread-local destructors. -#[cfg(target_env = "devkita64")] -pub use crate::sys_common::thread_local_dtor::register_dtor_fallback as register_dtor; diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index 7fcd86579ebce..f09bd704d9a0c 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -44,7 +44,7 @@ pub fn target() -> Result { ); let opts = TargetOptions { linker: Some("aarch64-none-elf-gcc".to_owned()), - features: "+a53,+strict-align,+crc,+read-tp-soft".to_string(), + features: "+a53,+strict-align,+crc".to_string(), executables: true, relocation_model: RelocModel::Pic, disable_redzone: true, @@ -54,7 +54,7 @@ pub fn target() -> Result { unsupported_abis: super::arm_base::unsupported_abis(), target_family: Some("unix".to_string()), position_independent_executables: true, - has_elf_tls: true, + has_elf_tls: false, trap_unreachable: true, emit_debug_gdb_scripts: true, requires_uwtable: true, diff --git a/src/llvm-project b/src/llvm-project index 695b33a20e882..86b120e6f302d 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 695b33a20e882235a311bb9dbccffb4d121fb04d +Subproject commit 86b120e6f302d39cd6973b6391fb299d7bc22122 From 8ed3f5f07f4a38ee176a5b214f966847c313c064 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 16:12:53 -0400 Subject: [PATCH 31/38] Revert "Emulate pread/pwrite on newlib" This reverts commit 775ccbb6a855aef4a1b755e3ead85d60bd6e6ed8. --- library/std/src/sys/unix/fd.rs | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index 9a63115242629..594462340ae3f 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -104,7 +104,7 @@ impl FileDesc { #[cfg(target_os = "android")] use super::android::cvt_pread64; - #[cfg(not(any(target_os = "android", target_env = "devkita64")))] + #[cfg(not(target_os = "android"))] unsafe fn cvt_pread64( fd: c_int, buf: *mut c_void, @@ -118,21 +118,6 @@ impl FileDesc { cvt(pread64(fd, buf, count, offset)) } - #[cfg(target_env = "devkita64")] - unsafe fn cvt_pread64( - fd: c_int, - buf: *mut c_void, - count: usize, - offset: i64, - ) -> io::Result { - // ported from devkita64, because it inexplicably was not being compiled - let cur_pos = cvt(libc::lseek(fd, 0, libc::SEEK_CUR))?; - cvt(libc::lseek(fd, offset, libc::SEEK_SET))?; - let num_read = cvt(libc::read(fd, buf, count))?; - cvt(libc::lseek(fd, cur_pos, libc::SEEK_SET))?; - Ok(num_read as _) - } - unsafe { cvt_pread64( self.fd, @@ -177,7 +162,7 @@ impl FileDesc { #[cfg(target_os = "android")] use super::android::cvt_pwrite64; - #[cfg(not(any(target_os = "android", target_env = "devkita64")))] + #[cfg(not(target_os = "android"))] unsafe fn cvt_pwrite64( fd: c_int, buf: *const c_void, @@ -191,21 +176,6 @@ impl FileDesc { cvt(pwrite64(fd, buf, count, offset)) } - #[cfg(target_env = "devkita64")] - unsafe fn cvt_pwrite64( - fd: c_int, - buf: *const c_void, - count: usize, - offset: i64, - ) -> io::Result { - // see pread - let cur_pos = cvt(libc::lseek(fd, 0, libc::SEEK_CUR))?; - cvt(libc::lseek(fd, offset, libc::SEEK_SET))?; - let num_written = cvt(libc::write(fd, buf, count))?; - cvt(libc::lseek(fd, cur_pos, libc::SEEK_SET))?; - Ok(num_written) - } - unsafe { cvt_pwrite64( self.fd, From f0cdfa695718596dde01d449a4abfa0c88372511 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 16:16:28 -0400 Subject: [PATCH 32/38] Make FileExt unimplemented!() on DevkitA64 --- library/std/src/sys/unix/ext/fs.rs | 12 ++++++++++++ library/std/src/sys/unix/fd.rs | 2 ++ library/std/src/sys/unix/fs.rs | 2 ++ 3 files changed, 16 insertions(+) diff --git a/library/std/src/sys/unix/ext/fs.rs b/library/std/src/sys/unix/ext/fs.rs index c7a38ac31a4d3..f6903d20207dc 100644 --- a/library/std/src/sys/unix/ext/fs.rs +++ b/library/std/src/sys/unix/ext/fs.rs @@ -213,6 +213,7 @@ pub trait FileExt { } #[stable(feature = "file_offset", since = "1.15.0")] +#[cfg(not(target_env = "devkita64"))] impl FileExt for fs::File { fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { self.as_inner().read_at(buf, offset) @@ -222,6 +223,17 @@ impl FileExt for fs::File { } } +#[stable(feature = "file_offset", since = "1.15.0")] +#[cfg(target_env = "devkita64")] +impl FileExt for fs::File { + fn read_at(&self, _buf: &mut [u8], _offset: u64) -> io::Result { + unimplemented!() + } + fn write_at(&self, _buf: &[u8], _offset: u64) -> io::Result { + unimplemented!() + } +} + /// Unix-specific extensions to [`fs::Permissions`]. /// /// [`fs::Permissions`]: ../../../../std/fs/struct.Permissions.html diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index 594462340ae3f..e9d6b0302f765 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -100,6 +100,7 @@ impl FileDesc { (&mut me).read_to_end(buf) } + #[cfg(not(target_env = "devkita64"))] pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { #[cfg(target_os = "android")] use super::android::cvt_pread64; @@ -158,6 +159,7 @@ impl FileDesc { !cfg!(target_env = "devkita64") } + #[cfg(not(target_env = "devkita64"))] pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { #[cfg(target_os = "android")] use super::android::cvt_pwrite64; diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index 15a458bf340a9..8fb33fb02c5c8 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -798,6 +798,7 @@ impl File { self.0.is_read_vectored() } + #[cfg(not(target_env = "devkita64"))] pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { self.0.read_at(buf, offset) } @@ -815,6 +816,7 @@ impl File { self.0.is_write_vectored() } + #[cfg(not(target_env = "devkita64"))] pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { self.0.write_at(buf, offset) } From e409a279aeb32ba3903a7a21227cd3c62cc6400e Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 20 Jul 2020 19:13:21 -0400 Subject: [PATCH 33/38] Correct devkitA64 capitalization --- library/std/src/os/devkita64/mod.rs | 2 +- library/std/src/sys/unix/mod.rs | 2 +- library/std/src/sys/unix/process/process_dummy.rs | 2 +- library/std/src/sys/unix/thread.rs | 2 +- src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library/std/src/os/devkita64/mod.rs b/library/std/src/os/devkita64/mod.rs index 1761c5f54bf08..111c79dfad566 100644 --- a/library/std/src/os/devkita64/mod.rs +++ b/library/std/src/os/devkita64/mod.rs @@ -1,4 +1,4 @@ -//! DevkitA64-specific definitions +//! devkitA64-specific definitions #![stable(feature = "raw_ext", since = "1.1.0")] diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 14ab03651f1d5..f48b3b3f4df3a 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -77,7 +77,7 @@ pub use crate::sys_common::os_str_bytes as os_str; #[cfg(not(test))] pub fn init() { - // Load romfs (which contains debug info) on DevkitA64 + // Load romfs (which contains debug info) on devkitA64 #[cfg(target_env = "devkita64")] platform::initialize_romfs(); diff --git a/library/std/src/sys/unix/process/process_dummy.rs b/library/std/src/sys/unix/process/process_dummy.rs index 19832487ad46e..6b8be49303ce1 100644 --- a/library/std/src/sys/unix/process/process_dummy.rs +++ b/library/std/src/sys/unix/process/process_dummy.rs @@ -1,4 +1,4 @@ -//! DevkitA64 has very limited support for multiple processes, so a dummy implementation is used +//! devkitA64 has very limited support for multiple processes, so a dummy implementation is used //! there (similar to WebAssembly). use crate::fmt; diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs index 3fd7d67b6ae5b..aaf5b608c01de 100644 --- a/library/std/src/sys/unix/thread.rs +++ b/library/std/src/sys/unix/thread.rs @@ -155,7 +155,7 @@ impl Thread { target_os = "redox" ))] pub fn set_name(_name: &CStr) { - // DevkitA64, Haiku, and Emscripten have no way to set a thread name. + // devkitA64, Haiku, and Emscripten have no way to set a thread name. } #[cfg(target_os = "fuchsia")] pub fn set_name(_name: &CStr) { diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs index f09bd704d9a0c..505a3a042e810 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs @@ -1,4 +1,4 @@ -//! DevkitA64 Nintendo Switch homebrew toolchain. +//! devkitA64 Nintendo Switch homebrew toolchain. //! //! # Building //! The recommended way to build Rust for this target is using Docker. You can start a build in a @@ -7,7 +7,7 @@ use super::{LinkArgs, LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions}; -// DevkitA64 has custom linker requirements. +// devkitA64 has custom linker requirements. const LINKER_SCRIPT: &str = include_str!("./aarch64_unknown_switch_devkita64_script.ld"); pub fn target() -> Result { From 6bf632589c96cb8dfefdf73e6c6f9955bd7290cf Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 21 Jul 2020 10:22:25 -0400 Subject: [PATCH 34/38] Rename to aarch64-unknown-switch-libnx --- library/std/build.rs | 2 +- library/std/src/os/{devkita64 => libnx}/fs.rs | 2 +- .../std/src/os/{devkita64 => libnx}/mod.rs | 2 +- .../std/src/os/{devkita64 => libnx}/raw.rs | 0 library/std/src/os/mod.rs | 4 ++-- library/std/src/os/raw/mod.rs | 4 ++-- library/std/src/sys/unix/alloc.rs | 4 ++-- library/std/src/sys/unix/args.rs | 2 +- library/std/src/sys/unix/env.rs | 2 +- library/std/src/sys/unix/ext/fs.rs | 16 +++++++------- library/std/src/sys/unix/fd.rs | 22 +++++++++---------- library/std/src/sys/unix/fs.rs | 18 +++++++-------- library/std/src/sys/unix/mod.rs | 8 +++---- library/std/src/sys/unix/os.rs | 9 +++----- library/std/src/sys/unix/process/mod.rs | 4 ++-- .../src/sys/unix/process/process_common.rs | 2 +- .../std/src/sys/unix/process/process_dummy.rs | 2 +- library/std/src/sys/unix/thread.rs | 4 ++-- library/std/src/sys/unix/time.rs | 4 ++-- library/std/src/sys/unix/weak.rs | 4 ++-- library/test/src/helpers/concurrency.rs | 2 +- library/unwind/build.rs | 4 ++-- .../Dockerfile | 8 +++---- ...a64.rs => aarch64_unknown_switch_libnx.rs} | 10 ++++----- ...=> aarch64_unknown_switch_libnx_script.ld} | 0 src/librustc_target/spec/mod.rs | 2 +- src/tools/tidy/src/extdeps.rs | 2 +- 27 files changed, 70 insertions(+), 73 deletions(-) rename library/std/src/os/{devkita64 => libnx}/fs.rs (99%) rename library/std/src/os/{devkita64 => libnx}/mod.rs (93%) rename library/std/src/os/{devkita64 => libnx}/raw.rs (100%) rename src/ci/docker/host-x86_64/disabled/{aarch64-devkita64 => aarch64-libnx}/Dockerfile (65%) rename src/librustc_target/spec/{aarch64_unknown_switch_devkita64.rs => aarch64_unknown_switch_libnx.rs} (91%) rename src/librustc_target/spec/{aarch64_unknown_switch_devkita64_script.ld => aarch64_unknown_switch_libnx_script.ld} (100%) diff --git a/library/std/build.rs b/library/std/build.rs index d615e9bf8f399..07653e6cd3b6e 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -71,7 +71,7 @@ fn main() { || target.contains("vxworks") || target.contains("wasm32") || target.contains("asmjs") - || target.contains("devkita64") + || target.contains("libnx") { // These platforms don't have any special requirements. } else { diff --git a/library/std/src/os/devkita64/fs.rs b/library/std/src/os/libnx/fs.rs similarity index 99% rename from library/std/src/os/devkita64/fs.rs rename to library/std/src/os/libnx/fs.rs index 53185267e224e..bd2b6bb6050c9 100644 --- a/library/std/src/os/devkita64/fs.rs +++ b/library/std/src/os/libnx/fs.rs @@ -4,7 +4,7 @@ use crate::fs::Metadata; use crate::sys_common::AsInner; #[allow(deprecated)] -use crate::os::devkita64::raw; +use crate::os::libnx::raw; /// OS-specific extensions to [`fs::Metadata`]. /// diff --git a/library/std/src/os/devkita64/mod.rs b/library/std/src/os/libnx/mod.rs similarity index 93% rename from library/std/src/os/devkita64/mod.rs rename to library/std/src/os/libnx/mod.rs index 111c79dfad566..e75580a3a3f3e 100644 --- a/library/std/src/os/devkita64/mod.rs +++ b/library/std/src/os/libnx/mod.rs @@ -1,4 +1,4 @@ -//! devkitA64-specific definitions +//! libnx-specific definitions #![stable(feature = "raw_ext", since = "1.1.0")] diff --git a/library/std/src/os/devkita64/raw.rs b/library/std/src/os/libnx/raw.rs similarity index 100% rename from library/std/src/os/devkita64/raw.rs rename to library/std/src/os/libnx/raw.rs diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index e71be01fe57a9..7fdcc984d0e35 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -40,8 +40,6 @@ cfg_if::cfg_if! { #[cfg(target_os = "android")] pub mod android; -#[cfg(target_env = "devkita64")] -pub mod devkita64; #[cfg(target_os = "dragonfly")] pub mod dragonfly; #[cfg(target_os = "emscripten")] @@ -58,6 +56,8 @@ pub mod haiku; pub mod illumos; #[cfg(target_os = "ios")] pub mod ios; +#[cfg(target_env = "libnx")] +pub mod libnx; #[cfg(target_os = "macos")] pub mod macos; #[cfg(target_os = "netbsd")] diff --git a/library/std/src/os/raw/mod.rs b/library/std/src/os/raw/mod.rs index 631a8ee6c1843..ad7accafbece2 100644 --- a/library/std/src/os/raw/mod.rs +++ b/library/std/src/os/raw/mod.rs @@ -48,7 +48,7 @@ ) ), all(target_os = "fuchsia", target_arch = "aarch64"), - target_env = "devkita64" + target_env = "libnx" ))] #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8; @@ -92,7 +92,7 @@ pub type c_char = u8; ) ), all(target_os = "fuchsia", target_arch = "aarch64"), - target_env = "devkita64" + target_env = "libnx" )))] #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8; diff --git a/library/std/src/sys/unix/alloc.rs b/library/std/src/sys/unix/alloc.rs index f53532ecf23a4..69163364cf87b 100644 --- a/library/std/src/sys/unix/alloc.rs +++ b/library/std/src/sys/unix/alloc.rs @@ -85,7 +85,7 @@ unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { target_os = "illumos", target_os = "redox", target_os = "solaris", - target_env = "devkita64" + target_env = "libnx" )))] #[inline] unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { @@ -97,7 +97,7 @@ unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { if ret != 0 { ptr::null_mut() } else { out as *mut u8 } } -#[cfg(target_env = "devkita64")] +#[cfg(target_env = "libnx")] #[inline] unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { libc::aligned_alloc(layout.align(), layout.size()) as *mut u8 diff --git a/library/std/src/sys/unix/args.rs b/library/std/src/sys/unix/args.rs index f5557b6b3d201..bf37ec418a3b7 100644 --- a/library/std/src/sys/unix/args.rs +++ b/library/std/src/sys/unix/args.rs @@ -71,7 +71,7 @@ impl DoubleEndedIterator for Args { target_os = "l4re", target_os = "fuchsia", target_os = "redox", - target_env = "devkita64" + target_env = "libnx" ))] mod imp { use super::Args; diff --git a/library/std/src/sys/unix/env.rs b/library/std/src/sys/unix/env.rs index a3b75500e601a..f3e50b153acb1 100644 --- a/library/std/src/sys/unix/env.rs +++ b/library/std/src/sys/unix/env.rs @@ -174,7 +174,7 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_env = "devkita64")] +#[cfg(target_env = "libnx")] pub mod os { pub const FAMILY: &str = "unix"; pub const OS: &str = "switch"; diff --git a/library/std/src/sys/unix/ext/fs.rs b/library/std/src/sys/unix/ext/fs.rs index f6903d20207dc..dffb9e886e0e5 100644 --- a/library/std/src/sys/unix/ext/fs.rs +++ b/library/std/src/sys/unix/ext/fs.rs @@ -213,7 +213,7 @@ pub trait FileExt { } #[stable(feature = "file_offset", since = "1.15.0")] -#[cfg(not(target_env = "devkita64"))] +#[cfg(not(target_env = "libnx"))] impl FileExt for fs::File { fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { self.as_inner().read_at(buf, offset) @@ -224,7 +224,7 @@ impl FileExt for fs::File { } #[stable(feature = "file_offset", since = "1.15.0")] -#[cfg(target_env = "devkita64")] +#[cfg(target_env = "libnx")] impl FileExt for fs::File { fn read_at(&self, _buf: &mut [u8], _offset: u64) -> io::Result { unimplemented!() @@ -703,33 +703,33 @@ impl MetadataExt for fs::Metadata { fn atime(&self) -> i64 { self.st_atime() } - #[cfg(not(target_env = "devkita64"))] + #[cfg(not(target_env = "libnx"))] fn atime_nsec(&self) -> i64 { self.st_atime_nsec() } - #[cfg(target_env = "devkita64")] + #[cfg(target_env = "libnx")] fn atime_nsec(&self) -> i64 { 0 } fn mtime(&self) -> i64 { self.st_mtime() } - #[cfg(not(target_env = "devkita64"))] + #[cfg(not(target_env = "libnx"))] fn mtime_nsec(&self) -> i64 { self.st_mtime_nsec() } - #[cfg(target_env = "devkita64")] + #[cfg(target_env = "libnx")] fn mtime_nsec(&self) -> i64 { 0 } fn ctime(&self) -> i64 { self.st_ctime() } - #[cfg(not(target_env = "devkita64"))] + #[cfg(not(target_env = "libnx"))] fn ctime_nsec(&self) -> i64 { self.st_ctime_nsec() } - #[cfg(target_env = "devkita64")] + #[cfg(target_env = "libnx")] fn ctime_nsec(&self) -> i64 { 0 } diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index e9d6b0302f765..cf3992211a764 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -1,4 +1,4 @@ -#![cfg_attr(target_env = "devkita64", allow(unused_variables, dead_code))] +#![cfg_attr(target_env = "libnx", allow(unused_variables, dead_code))] #![unstable(reason = "not public", issue = "none", feature = "fd")] use crate::cmp; @@ -73,7 +73,7 @@ impl FileDesc { Ok(ret as usize) } - #[cfg(not(target_env = "devkita64"))] + #[cfg(not(target_env = "libnx"))] pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { let ret = cvt(unsafe { libc::readv( @@ -85,14 +85,14 @@ impl FileDesc { Ok(ret as usize) } - #[cfg(target_env = "devkita64")] + #[cfg(target_env = "libnx")] pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { io::default_read_vectored(|x| self.read(x), bufs) } #[inline] pub fn is_read_vectored(&self) -> bool { - !cfg!(target_env = "devkita64") + !cfg!(target_env = "libnx") } pub fn read_to_end(&self, buf: &mut Vec) -> io::Result { @@ -100,7 +100,7 @@ impl FileDesc { (&mut me).read_to_end(buf) } - #[cfg(not(target_env = "devkita64"))] + #[cfg(not(target_env = "libnx"))] pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { #[cfg(target_os = "android")] use super::android::cvt_pread64; @@ -137,7 +137,7 @@ impl FileDesc { Ok(ret as usize) } - #[cfg(not(target_env = "devkita64"))] + #[cfg(not(target_env = "libnx"))] pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { let ret = cvt(unsafe { libc::writev( @@ -149,17 +149,17 @@ impl FileDesc { Ok(ret as usize) } - #[cfg(target_env = "devkita64")] + #[cfg(target_env = "libnx")] pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { io::default_write_vectored(|x| self.write(x), bufs) } #[inline] pub fn is_write_vectored(&self) -> bool { - !cfg!(target_env = "devkita64") + !cfg!(target_env = "libnx") } - #[cfg(not(target_env = "devkita64"))] + #[cfg(not(target_env = "libnx"))] pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { #[cfg(target_os = "android")] use super::android::cvt_pwrite64; @@ -195,7 +195,7 @@ impl FileDesc { } #[cfg(not(any( - target_env = "devkita64", + target_env = "libnx", target_os = "solaris", target_os = "illumos", target_os = "emscripten", @@ -212,7 +212,7 @@ impl FileDesc { } } #[cfg(any( - target_env = "devkita64", + target_env = "libnx", target_os = "solaris", target_os = "illumos", target_os = "emscripten", diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index 8fb33fb02c5c8..1b030760bf2ec 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -158,7 +158,7 @@ cfg_has_statx! {{ stat.st_mtime = buf.stx_mtime.tv_sec as libc::time_t; stat.st_ctime = buf.stx_ctime.tv_sec as libc::time_t; // `i64` on gnu-x86_64-x32, `c_ulong` otherwise. - #[cfg(not(target_env = "devkita64"))] { + #[cfg(not(target_env = "libnx"))] { stat.st_atime_nsec = buf.stx_atime.tv_nsec as _; stat.st_mtime_nsec = buf.stx_mtime.tv_nsec as _; stat.st_ctime_nsec = buf.stx_ctime.tv_nsec as _; @@ -297,9 +297,9 @@ impl FileAttr { pub fn modified(&self) -> io::Result { Ok(SystemTime::from(libc::timespec { tv_sec: self.stat.st_mtime as libc::time_t, - #[cfg(target_env = "devkita64")] + #[cfg(target_env = "libnx")] tv_nsec: 0, - #[cfg(not(target_env = "devkita64"))] + #[cfg(not(target_env = "libnx"))] tv_nsec: self.stat.st_mtime_nsec as _, })) } @@ -307,9 +307,9 @@ impl FileAttr { pub fn accessed(&self) -> io::Result { Ok(SystemTime::from(libc::timespec { tv_sec: self.stat.st_atime as libc::time_t, - #[cfg(target_env = "devkita64")] + #[cfg(target_env = "libnx")] tv_nsec: 0, - #[cfg(not(target_env = "devkita64"))] + #[cfg(not(target_env = "libnx"))] tv_nsec: self.stat.st_atime_nsec as _, })) } @@ -569,7 +569,7 @@ impl DirEntry { target_os = "l4re", target_os = "fuchsia", target_os = "redox", - target_env = "devkita64" + target_env = "libnx" ))] pub fn ino(&self) -> u64 { self.entry.d_ino as u64 @@ -608,7 +608,7 @@ impl DirEntry { target_os = "emscripten", target_os = "l4re", target_os = "haiku", - target_env = "devkita64" + target_env = "libnx" ))] fn name_bytes(&self) -> &[u8] { unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes() } @@ -798,7 +798,7 @@ impl File { self.0.is_read_vectored() } - #[cfg(not(target_env = "devkita64"))] + #[cfg(not(target_env = "libnx"))] pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { self.0.read_at(buf, offset) } @@ -816,7 +816,7 @@ impl File { self.0.is_write_vectored() } - #[cfg(not(target_env = "devkita64"))] + #[cfg(not(target_env = "libnx"))] pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { self.0.write_at(buf, offset) } diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index f48b3b3f4df3a..465ac1f8065d8 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -7,8 +7,6 @@ pub use crate::os::linux as platform; #[cfg(all(not(doc), target_os = "android"))] pub use crate::os::android as platform; -#[cfg(all(not(doc), target_env = "devkita64"))] -pub use crate::os::devkita64 as platform; #[cfg(all(not(doc), target_os = "dragonfly"))] pub use crate::os::dragonfly as platform; #[cfg(all(not(doc), target_os = "emscripten"))] @@ -23,6 +21,8 @@ pub use crate::os::haiku as platform; pub use crate::os::illumos as platform; #[cfg(all(not(doc), target_os = "ios"))] pub use crate::os::ios as platform; +#[cfg(all(not(doc), target_env = "libnx"))] +pub use crate::os::libnx as platform; #[cfg(all(not(doc), target_os = "l4re"))] pub use crate::os::linux as platform; #[cfg(all(not(doc), target_os = "macos"))] @@ -77,8 +77,8 @@ pub use crate::sys_common::os_str_bytes as os_str; #[cfg(not(test))] pub fn init() { - // Load romfs (which contains debug info) on devkitA64 - #[cfg(target_env = "devkita64")] + // Load romfs (which contains debug info) on libnx + #[cfg(target_env = "libnx")] platform::initialize_romfs(); // By default, some platforms will send a *signal* when an EPIPE error diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index f9050a0cf694a..16db75264553a 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -50,7 +50,7 @@ extern "C" { target_os = "openbsd", target_os = "android", target_os = "redox", - target_env = "devkita64" + target_env = "libnx" ), link_name = "__errno" )] @@ -101,10 +101,7 @@ pub fn set_errno(e: i32) { /// Gets a detailed string description for the given error number. pub fn error_string(errno: i32) -> String { extern "C" { - #[cfg_attr( - any(target_os = "linux", target_env = "devkita64"), - link_name = "__xpg_strerror_r" - )] + #[cfg_attr(any(target_os = "linux", target_env = "libnx"), link_name = "__xpg_strerror_r")] fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: libc::size_t) -> c_int; } @@ -439,7 +436,7 @@ pub fn current_exe() -> io::Result { Err(io::Error::new(ErrorKind::Other, "Not yet implemented!")) } -#[cfg(target_env = "devkita64")] +#[cfg(target_env = "libnx")] pub fn current_exe() -> io::Result { use crate::env; // guaranteed by abi to be an absolute path to the executable diff --git a/library/std/src/sys/unix/process/mod.rs b/library/std/src/sys/unix/process/mod.rs index a0d609e57ad96..c7c90f1aba152 100644 --- a/library/std/src/sys/unix/process/mod.rs +++ b/library/std/src/sys/unix/process/mod.rs @@ -3,13 +3,13 @@ pub use self::process_inner::{ExitStatus, Process}; pub use crate::ffi::OsString as EnvKey; mod process_common; -#[cfg(not(any(target_os = "fuchsia", target_env = "devkita64")))] +#[cfg(not(any(target_os = "fuchsia", target_env = "libnx")))] #[path = "process_unix.rs"] mod process_inner; #[cfg(target_os = "fuchsia")] #[path = "process_fuchsia.rs"] mod process_inner; -#[cfg(target_env = "devkita64")] +#[cfg(target_env = "libnx")] #[path = "process_dummy.rs"] mod process_inner; #[cfg(target_os = "fuchsia")] diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index ec80154e0cbe1..646f3486bbf36 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -1,4 +1,4 @@ -#![cfg_attr(target_env = "devkita64", allow(unused_variables, dead_code))] +#![cfg_attr(target_env = "libnx", allow(unused_variables, dead_code))] use crate::os::unix::prelude::*; diff --git a/library/std/src/sys/unix/process/process_dummy.rs b/library/std/src/sys/unix/process/process_dummy.rs index 6b8be49303ce1..5d7a9e0bda95b 100644 --- a/library/std/src/sys/unix/process/process_dummy.rs +++ b/library/std/src/sys/unix/process/process_dummy.rs @@ -1,4 +1,4 @@ -//! devkitA64 has very limited support for multiple processes, so a dummy implementation is used +//! libnx has very limited support for multiple processes, so a dummy implementation is used //! there (similar to WebAssembly). use crate::fmt; diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs index aaf5b608c01de..acfd50a53ca84 100644 --- a/library/std/src/sys/unix/thread.rs +++ b/library/std/src/sys/unix/thread.rs @@ -148,14 +148,14 @@ impl Thread { } #[cfg(any( - target_env = "devkita64", + target_env = "libnx", target_os = "haiku", target_os = "l4re", target_os = "emscripten", target_os = "redox" ))] pub fn set_name(_name: &CStr) { - // devkitA64, Haiku, and Emscripten have no way to set a thread name. + // libnx, Haiku, and Emscripten have no way to set a thread name. } #[cfg(target_os = "fuchsia")] pub fn set_name(_name: &CStr) { diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index f48d720cc9684..6e720a2f187f9 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -339,9 +339,9 @@ mod inner { } } - #[cfg(not(any(target_os = "dragonfly", target_env = "devkita64")))] + #[cfg(not(any(target_os = "dragonfly", target_env = "libnx")))] pub type clock_t = libc::c_int; - #[cfg(any(target_os = "dragonfly", target_env = "devkita64"))] + #[cfg(any(target_os = "dragonfly", target_env = "libnx"))] pub type clock_t = libc::c_ulong; fn now(clock: clock_t) -> Timespec { diff --git a/library/std/src/sys/unix/weak.rs b/library/std/src/sys/unix/weak.rs index d2e211bb43220..4283de44e9d0b 100644 --- a/library/std/src/sys/unix/weak.rs +++ b/library/std/src/sys/unix/weak.rs @@ -58,7 +58,7 @@ impl Weak { } } -#[cfg(not(target_env = "devkita64"))] +#[cfg(not(target_env = "libnx"))] unsafe fn fetch(name: &str) -> usize { let name = match CStr::from_bytes_with_nul(name.as_bytes()) { Ok(cstr) => cstr, @@ -67,7 +67,7 @@ unsafe fn fetch(name: &str) -> usize { libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize } -#[cfg(target_env = "devkita64")] +#[cfg(target_env = "libnx")] unsafe fn fetch(_name: &str) -> usize { 0 } diff --git a/library/test/src/helpers/concurrency.rs b/library/test/src/helpers/concurrency.rs index 992ab14f99ee0..672335fd3d46b 100644 --- a/library/test/src/helpers/concurrency.rs +++ b/library/test/src/helpers/concurrency.rs @@ -109,7 +109,7 @@ cfg_if::cfg_if! { cpus as usize } } else { - // FIXME: implement on vxWorks, Redox, HermitCore, Haiku, l4re, devkita64 + // FIXME: implement on vxWorks, Redox, HermitCore, Haiku, l4re, libnx fn num_cpus() -> usize { 1 } diff --git a/library/unwind/build.rs b/library/unwind/build.rs index 9d734347c8fb0..bbc54f7b6f712 100644 --- a/library/unwind/build.rs +++ b/library/unwind/build.rs @@ -48,7 +48,7 @@ fn main() { // redox is handled in lib.rs } else if target.contains("cloudabi") { println!("cargo:rustc-link-lib=unwind"); - } else if target.contains("devkita64") { + } else if target.contains("libnx") { llvm_libunwind::compile(); } } @@ -122,7 +122,7 @@ mod llvm_libunwind { cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None); } - if target_env == "devkita64" { + if target_env == "libnx" { cfg.define("_LIBUNWIND_IS_BAREMETAL", None); cfg.define("_LIBUNWIND_SUPPORT_DWARF_UNWIND", None); cfg.define("_LIBUNWIND_SUPPORT_DWARF_INDEX", None); diff --git a/src/ci/docker/host-x86_64/disabled/aarch64-devkita64/Dockerfile b/src/ci/docker/host-x86_64/disabled/aarch64-libnx/Dockerfile similarity index 65% rename from src/ci/docker/host-x86_64/disabled/aarch64-devkita64/Dockerfile rename to src/ci/docker/host-x86_64/disabled/aarch64-libnx/Dockerfile index d0674f48381f4..6b317ece1dabd 100644 --- a/src/ci/docker/host-x86_64/disabled/aarch64-devkita64/Dockerfile +++ b/src/ci/docker/host-x86_64/disabled/aarch64-libnx/Dockerfile @@ -15,11 +15,11 @@ RUN sh /scripts/sccache.sh ENV PATH=$PATH:/opt/devkitpro/devkitA64/bin/ -ENV CC_aarch64_unknown_switch_devkita64=aarch64-none-elf-gcc \ - AR_aarch64_unknown_switch_devkita64=aarch64-none-elf-ar \ - CXX_aarch64_unknown_switch_devkita64=aarch64-none-elf-g++ +ENV CC_aarch64_unknown_switch_libnx=aarch64-none-elf-gcc \ + AR_aarch64_unknown_switch_libnx=aarch64-none-elf-ar \ + CXX_aarch64_unknown_switch_libnx=aarch64-none-elf-g++ -ENV TARGETS=aarch64-unknown-switch-devkita64 +ENV TARGETS=aarch64-unknown-switch-libnx ENV RUST_CONFIGURE_ARGS \ --disable-docs diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs b/src/librustc_target/spec/aarch64_unknown_switch_libnx.rs similarity index 91% rename from src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs rename to src/librustc_target/spec/aarch64_unknown_switch_libnx.rs index 505a3a042e810..8976ed649a9d1 100644 --- a/src/librustc_target/spec/aarch64_unknown_switch_devkita64.rs +++ b/src/librustc_target/spec/aarch64_unknown_switch_libnx.rs @@ -1,14 +1,14 @@ -//! devkitA64 Nintendo Switch homebrew toolchain. +//! libnx Nintendo Switch homebrew toolchain. //! //! # Building //! The recommended way to build Rust for this target is using Docker. You can start a build in a -//! container with `./src/ci/docker/run.sh aarch64-devkita64` from the Rust source tree. For +//! container with `./src/ci/docker/run.sh aarch64-libnx` from the Rust source tree. For //! development, you can add `--dev` as the first argument to get a shell inside the container. use super::{LinkArgs, LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions}; -// devkitA64 has custom linker requirements. -const LINKER_SCRIPT: &str = include_str!("./aarch64_unknown_switch_devkita64_script.ld"); +// libnx has custom linker requirements. +const LINKER_SCRIPT: &str = include_str!("./aarch64_unknown_switch_libnx_script.ld"); pub fn target() -> Result { let mut link_args = LinkArgs::new(); @@ -68,7 +68,7 @@ pub fn target() -> Result { target_pointer_width: "64".to_string(), target_c_int_width: "32".to_string(), target_os: "switch".to_string(), - target_env: "devkita64".to_string(), + target_env: "libnx".to_string(), target_vendor: "unknown".to_string(), data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), diff --git a/src/librustc_target/spec/aarch64_unknown_switch_devkita64_script.ld b/src/librustc_target/spec/aarch64_unknown_switch_libnx_script.ld similarity index 100% rename from src/librustc_target/spec/aarch64_unknown_switch_devkita64_script.ld rename to src/librustc_target/spec/aarch64_unknown_switch_libnx_script.ld diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 3c038e07a71c8..b4ed6533367a9 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -678,7 +678,7 @@ supported_targets! { ("mipsel-sony-psp", mipsel_sony_psp), ("thumbv4t-none-eabi", thumbv4t_none_eabi), - ("aarch64-unknown-switch-devkita64", aarch64_unknown_switch_devkita64), + ("aarch64-unknown-switch-libnx", aarch64_unknown_switch_libnx), } /// Everything `rustc` knows about how to compile for a specific target. diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index 5e009fadd8367..7d962fb307adb 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -6,7 +6,7 @@ use std::path::Path; /// List of allowed sources for packages. const ALLOWED_SOURCES: &[&str] = &[ "\"registry+https://github.com/rust-lang/crates.io-index\"", - "\"git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#c64fc22e37bca14e942e0f7e8c365fc7b2d4c963\"", + "\"git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#9db9538ce95d61b75964b3223cf03cafe1023327\"", ]; /// Checks for external package sources. `root` is the path to the directory that contains the From 0d36e7dec13751a9dfbbcf3ad13f0ce372399561 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 21 Jul 2020 12:52:30 -0400 Subject: [PATCH 35/38] Use OsString::push instead of OsStr::to_str + format! --- src/librustc_codegen_ssa/back/link.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 62683fe832b87..e5f9af4af139c 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -1351,12 +1351,9 @@ fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_ty if sess.target.target.linker_flavor == LinkerFlavor::Gcc { cmd.arg("-Wl,--script"); - let path_str = if let Some(s) = path.to_str() { - s - } else { - sess.fatal(&format!("linker script path {:?} is invalid Unicode", path)); - }; - cmd.arg(format!("-Wl,{}", path_str)); + let mut arg = OsString::from("-Wl,"); + arg.push(path); + cmd.arg(&arg); } else { cmd.arg("--script"); cmd.arg(path); From 4ba0fe7cd3c27642fd91151ebb9ef2d251725e2b Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 11 Aug 2020 13:14:54 -0400 Subject: [PATCH 36/38] Update libc --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 2347c7e127f36..3c41b3248f315 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1586,7 +1586,7 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" [[package]] name = "libc" version = "0.2.74" -source = "git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#84597a8e80fbb7bb058a35677846006fc2bafa5c" +source = "git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#d4a706f30bc0be2b6d4827a017e86a275c3dc611" dependencies = [ "rustc-std-workspace-core", ] From 9e4f6314bba2a10485e34f2cb8da5b0fad25bdd2 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 11 Aug 2020 13:21:07 -0400 Subject: [PATCH 37/38] Update libc --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 3c41b3248f315..7beade3888971 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1586,7 +1586,7 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" [[package]] name = "libc" version = "0.2.74" -source = "git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#d4a706f30bc0be2b6d4827a017e86a275c3dc611" +source = "git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#9f1d51f1276ac6967065b0fd7c3d814ec86dd391" dependencies = [ "rustc-std-workspace-core", ] From ef03c4ccf423f3f1dd7e25d27dcf21b370901fba Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 11 Aug 2020 13:41:49 -0400 Subject: [PATCH 38/38] Update tidy --- src/tools/tidy/src/extdeps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index 7d962fb307adb..4353dcc59f023 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -6,7 +6,7 @@ use std::path::Path; /// List of allowed sources for packages. const ALLOWED_SOURCES: &[&str] = &[ "\"registry+https://github.com/rust-lang/crates.io-index\"", - "\"git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#9db9538ce95d61b75964b3223cf03cafe1023327\"", + "\"git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#9f1d51f1276ac6967065b0fd7c3d814ec86dd391\"", ]; /// Checks for external package sources. `root` is the path to the directory that contains the