From 2de8fea79fcf24bab044ae650cac75163647b689 Mon Sep 17 00:00:00 2001 From: Marius Melzer Date: Fri, 9 Jan 2026 17:47:34 +0100 Subject: [PATCH 1/3] L4Re: Repair build and move to rustc linking Fixes the builds of rustc and library/std for the L4Re target OS. A major change was done in linking binaries: The need for the L4Bender tool was removed and linking parameters are now fully configured in the rustc target config. --- compiler/rustc_codegen_ssa/messages.ftl | 2 - compiler/rustc_codegen_ssa/src/back/linker.rs | 126 ------- compiler/rustc_codegen_ssa/src/errors.rs | 4 - compiler/rustc_target/src/spec/base/l4re.rs | 55 ++- .../targets/x86_64_unknown_l4re_uclibc.rs | 6 +- library/Cargo.lock | 4 +- library/panic_unwind/src/lib.rs | 5 - library/std/Cargo.toml | 2 +- library/std/src/net/tcp.rs | 1 + library/std/src/net/udp.rs | 1 + library/std/src/os/fd/mod.rs | 2 +- library/std/src/os/fd/owned.rs | 18 +- library/std/src/os/l4re/fs.rs | 15 +- library/std/src/os/l4re/raw.rs | 349 +----------------- library/std/src/os/unix/mod.rs | 1 + library/std/src/sys/fd/unix.rs | 6 +- library/std/src/sys/fs/unix.rs | 44 ++- .../std/src/sys/net/connection/unsupported.rs | 2 +- library/std/src/sys/pal/unix/mod.rs | 10 +- library/std/src/sys/pal/unix/os.rs | 3 +- library/std/src/sys/personality/mod.rs | 2 +- library/std/src/sys/process/unix/unix.rs | 7 +- library/std/src/sys/random/mod.rs | 3 +- library/unwind/src/lib.rs | 2 +- src/bootstrap/src/utils/helpers.rs | 3 +- 25 files changed, 141 insertions(+), 532 deletions(-) diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index 1d87dc5da8d2d..1a9cc3a4f0500 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -1,5 +1,3 @@ -codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not implemented yet for L4Bender - codegen_ssa_aarch64_softfloat_neon = enabling the `neon` target feature on the current target is unsound due to ABI issues codegen_ssa_add_native_library = failed to add native library {$library_path}: {$error} diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index b47652092ed5c..98281732b3178 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -137,9 +137,6 @@ pub(crate) fn get_linker<'a>( // to the linker args construction. assert!(cmd.get_args().is_empty() || sess.target.abi == Abi::Uwp); match flavor { - LinkerFlavor::Unix(Cc::No) if sess.target.os == Os::L4Re => { - Box::new(L4Bender::new(cmd, sess)) as Box - } LinkerFlavor::Unix(Cc::No) if sess.target.os == Os::Aix => { Box::new(AixLinker::new(cmd, sess)) as Box } @@ -280,7 +277,6 @@ generate_arg_methods! { MsvcLinker<'_> EmLinker<'_> WasmLd<'_> - L4Bender<'_> AixLinker<'_> LlbcLinker<'_> PtxLinker<'_> @@ -1475,128 +1471,6 @@ impl<'a> WasmLd<'a> { } } -/// Linker shepherd script for L4Re (Fiasco) -struct L4Bender<'a> { - cmd: Command, - sess: &'a Session, - hinted_static: bool, -} - -impl<'a> Linker for L4Bender<'a> { - fn cmd(&mut self) -> &mut Command { - &mut self.cmd - } - - fn set_output_kind( - &mut self, - _output_kind: LinkOutputKind, - _crate_type: CrateType, - _out_filename: &Path, - ) { - } - - fn link_staticlib_by_name(&mut self, name: &str, _verbatim: bool, whole_archive: bool) { - self.hint_static(); - if !whole_archive { - self.link_arg(format!("-PC{name}")); - } else { - self.link_arg("--whole-archive") - .link_or_cc_arg(format!("-l{name}")) - .link_arg("--no-whole-archive"); - } - } - - fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool) { - self.hint_static(); - if !whole_archive { - self.link_or_cc_arg(path); - } else { - self.link_arg("--whole-archive").link_or_cc_arg(path).link_arg("--no-whole-archive"); - } - } - - fn full_relro(&mut self) { - self.link_args(&["-z", "relro", "-z", "now"]); - } - - fn partial_relro(&mut self) { - self.link_args(&["-z", "relro"]); - } - - fn no_relro(&mut self) { - self.link_args(&["-z", "norelro"]); - } - - fn gc_sections(&mut self, keep_metadata: bool) { - if !keep_metadata { - self.link_arg("--gc-sections"); - } - } - - fn optimize(&mut self) { - // GNU-style linkers support optimization with -O. GNU ld doesn't - // need a numeric argument, but other linkers do. - if self.sess.opts.optimize == config::OptLevel::More - || self.sess.opts.optimize == config::OptLevel::Aggressive - { - self.link_arg("-O1"); - } - } - - fn pgo_gen(&mut self) {} - - fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) { - match strip { - Strip::None => {} - Strip::Debuginfo => { - self.link_arg("--strip-debug"); - } - Strip::Symbols => { - self.link_arg("--strip-all"); - } - } - } - - fn no_default_libraries(&mut self) { - self.cc_arg("-nostdlib"); - } - - fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[(String, SymbolExportKind)]) { - // ToDo, not implemented, copy from GCC - self.sess.dcx().emit_warn(errors::L4BenderExportingSymbolsUnimplemented); - } - - fn windows_subsystem(&mut self, subsystem: WindowsSubsystemKind) { - let subsystem = subsystem.as_str(); - self.link_arg(&format!("--subsystem {subsystem}")); - } - - fn reset_per_library_state(&mut self) { - self.hint_static(); // Reset to default before returning the composed command line. - } - - fn linker_plugin_lto(&mut self) {} - - fn control_flow_guard(&mut self) {} - - fn ehcont_guard(&mut self) {} - - fn no_crt_objects(&mut self) {} -} - -impl<'a> L4Bender<'a> { - fn new(cmd: Command, sess: &'a Session) -> L4Bender<'a> { - L4Bender { cmd, sess, hinted_static: false } - } - - fn hint_static(&mut self) { - if !self.hinted_static { - self.link_or_cc_arg("-static"); - self.hinted_static = true; - } - } -} - /// Linker for AIX. struct AixLinker<'a> { cmd: Command, diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index 95306c140895c..5e74407d01154 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -113,10 +113,6 @@ pub(crate) struct Ld64UnimplementedModifier; #[diag(codegen_ssa_linker_unsupported_modifier)] pub(crate) struct LinkerUnsupportedModifier; -#[derive(Diagnostic)] -#[diag(codegen_ssa_L4Bender_exporting_symbols_unimplemented)] -pub(crate) struct L4BenderExportingSymbolsUnimplemented; - #[derive(Diagnostic)] #[diag(codegen_ssa_no_natvis_directory)] pub(crate) struct NoNatvisDirectory { diff --git a/compiler/rustc_target/src/spec/base/l4re.rs b/compiler/rustc_target/src/spec/base/l4re.rs index 8722c8a71e23a..cc67bd6d3a487 100644 --- a/compiler/rustc_target/src/spec/base/l4re.rs +++ b/compiler/rustc_target/src/spec/base/l4re.rs @@ -1,14 +1,59 @@ -use crate::spec::{Cc, Env, LinkerFlavor, Os, PanicStrategy, RelocModel, TargetOptions, cvs}; +use crate::spec::{ + Cc, Env, LinkOutputKind, LinkSelfContainedComponents, LinkSelfContainedDefault, LinkerFlavor, + Os, PanicStrategy, TargetOptions, add_link_args, crt_objects, cvs, +}; pub(crate) fn opts() -> TargetOptions { + // add ld- and cc-style args + macro_rules! prepare_args { + ($($val:expr),+) => {{ + let ld_args = &[$($val),+]; + let cc_args = &[$(concat!("-Wl,", $val)),+]; + + let mut ret = TargetOptions::link_args(LinkerFlavor::Unix(Cc::No), ld_args); + add_link_args(&mut ret, LinkerFlavor::Unix(Cc::Yes), cc_args); + ret + }}; + } + + let pre_link_args = prepare_args!("-nostdlib", "-dynamic-linker=rom/libld-l4.so"); + + let late_link_args = prepare_args!("-lc", "-lgcc_eh"); + + let pre_link_objects_self_contained = crt_objects::new(&[ + (LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o", "crtbeginT.o"]), + (LinkOutputKind::StaticPicExe, &["crt1.p.o", "crti.o", "crtbegin.o"]), + (LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]), + (LinkOutputKind::DynamicPicExe, &["crt1.s.o", "crti.o", "crtbeginS.o"]), + (LinkOutputKind::DynamicDylib, &["crti.s.o", "crtbeginS.o"]), + (LinkOutputKind::StaticDylib, &["crti.s.o", "crtbeginS.o"]), + ]); + + let post_link_objects_self_contained = crt_objects::new(&[ + (LinkOutputKind::StaticNoPicExe, &["crtendT.o", "crtn.o"]), + (LinkOutputKind::StaticPicExe, &["crtend.o", "crtn.o"]), + (LinkOutputKind::DynamicNoPicExe, &["crtend.o", "crtn.o"]), + (LinkOutputKind::DynamicPicExe, &["crtendS.o", "crtn.o"]), + (LinkOutputKind::DynamicDylib, &["crtendS.o", "crtn.s.o"]), + (LinkOutputKind::StaticDylib, &["crtendS.o", "crtn.s.o"]), + ]); + TargetOptions { os: Os::L4Re, env: Env::Uclibc, - linker_flavor: LinkerFlavor::Unix(Cc::No), - panic_strategy: PanicStrategy::Abort, - linker: Some("l4-bender".into()), families: cvs!["unix"], - relocation_model: RelocModel::Static, + panic_strategy: PanicStrategy::Abort, + linker_flavor: LinkerFlavor::Unix(Cc::No), + dynamic_linking: true, + position_independent_executables: true, + has_thread_local: true, + pre_link_args, + late_link_args, + pre_link_objects_self_contained, + post_link_objects_self_contained, + link_self_contained: LinkSelfContainedDefault::WithComponents( + LinkSelfContainedComponents::LIBC | LinkSelfContainedComponents::CRT_OBJECTS, + ), ..Default::default() } } diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_l4re_uclibc.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_l4re_uclibc.rs index 5ab6b094dfa06..7030a98305a0b 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_l4re_uclibc.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_l4re_uclibc.rs @@ -1,11 +1,13 @@ -use crate::spec::{Arch, PanicStrategy, Target, TargetMetadata, base}; +use crate::spec::{Arch, Cc, LinkerFlavor, Target, TargetMetadata, base}; pub(crate) fn target() -> Target { let mut base = base::l4re::opts(); base.cpu = "x86-64".into(); base.plt_by_default = false; base.max_atomic_width = Some(64); - base.panic_strategy = PanicStrategy::Abort; + let extra_link_args = &["-zmax-page-size=0x1000", "-zcommon-page-size=0x1000"]; + base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), extra_link_args); + base.add_pre_link_args(LinkerFlavor::Unix(Cc::No), extra_link_args); Target { llvm_target: "x86_64-unknown-l4re-gnu".into(), diff --git a/library/Cargo.lock b/library/Cargo.lock index f6c14bc58a044..98677f571112c 100644 --- a/library/Cargo.lock +++ b/library/Cargo.lock @@ -146,9 +146,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.178" +version = "0.2.179" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" +checksum = "c5a2d376baa530d1238d133232d15e239abad80d05838b4b59354e5268af431f" dependencies = [ "rustc-std-workspace-core", ] diff --git a/library/panic_unwind/src/lib.rs b/library/panic_unwind/src/lib.rs index 1be19913f260f..cfd4d1a9bc72d 100644 --- a/library/panic_unwind/src/lib.rs +++ b/library/panic_unwind/src/lib.rs @@ -41,11 +41,6 @@ cfg_select! { #[path = "hermit.rs"] mod imp; } - target_os = "l4re" => { - // L4Re is unix family but does not yet support unwinding. - #[path = "dummy.rs"] - mod imp; - } any( all(target_family = "windows", target_env = "gnu"), target_os = "psp", diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 43caf7734fdbd..997adef2d1f20 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -33,7 +33,7 @@ miniz_oxide = { version = "0.8.0", optional = true, default-features = false } addr2line = { version = "0.25.0", optional = true, default-features = false } [target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies] -libc = { version = "0.2.178", default-features = false, features = [ +libc = { version = "0.2.179", default-features = false, features = [ 'rustc-dep-of-std', ], public = true } diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index dac568e419f3f..167e69c1e0836 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -7,6 +7,7 @@ all(target_os = "wasi", target_env = "p1"), target_os = "xous", target_os = "trusty", + target_os = "l4re", )) ))] mod tests; diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index 136803ab16f1f..c20199104b475 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -6,6 +6,7 @@ target_env = "sgx", target_os = "xous", target_os = "trusty", + target_os = "l4re", )) ))] mod tests; diff --git a/library/std/src/os/fd/mod.rs b/library/std/src/os/fd/mod.rs index 95cf4932e6e2c..4ec9d0d5c573a 100644 --- a/library/std/src/os/fd/mod.rs +++ b/library/std/src/os/fd/mod.rs @@ -13,7 +13,7 @@ mod raw; mod owned; // Implementations for `AsRawFd` etc. for network types. -#[cfg(not(target_os = "trusty"))] +#[cfg(not(any(target_os = "trusty", target_os = "l4re")))] mod net; #[cfg(test)] diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index 8a39fe073bf95..541141c6b0e6c 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -344,7 +344,7 @@ impl From for fs::File { } #[stable(feature = "io_safety", since = "1.63.0")] -#[cfg(not(target_os = "trusty"))] +#[cfg(not(any(target_os = "trusty", target_os = "l4re")))] impl AsFd for crate::net::TcpStream { #[inline] fn as_fd(&self) -> BorrowedFd<'_> { @@ -353,7 +353,7 @@ impl AsFd for crate::net::TcpStream { } #[stable(feature = "io_safety", since = "1.63.0")] -#[cfg(not(target_os = "trusty"))] +#[cfg(not(any(target_os = "trusty", target_os = "l4re")))] impl From for OwnedFd { /// Takes ownership of a [`TcpStream`](crate::net::TcpStream)'s socket file descriptor. #[inline] @@ -363,7 +363,7 @@ impl From for OwnedFd { } #[stable(feature = "io_safety", since = "1.63.0")] -#[cfg(not(target_os = "trusty"))] +#[cfg(not(any(target_os = "trusty", target_os = "l4re")))] impl From for crate::net::TcpStream { #[inline] fn from(owned_fd: OwnedFd) -> Self { @@ -374,7 +374,7 @@ impl From for crate::net::TcpStream { } #[stable(feature = "io_safety", since = "1.63.0")] -#[cfg(not(target_os = "trusty"))] +#[cfg(not(any(target_os = "trusty", target_os = "l4re")))] impl AsFd for crate::net::TcpListener { #[inline] fn as_fd(&self) -> BorrowedFd<'_> { @@ -383,7 +383,7 @@ impl AsFd for crate::net::TcpListener { } #[stable(feature = "io_safety", since = "1.63.0")] -#[cfg(not(target_os = "trusty"))] +#[cfg(not(any(target_os = "trusty", target_os = "l4re")))] impl From for OwnedFd { /// Takes ownership of a [`TcpListener`](crate::net::TcpListener)'s socket file descriptor. #[inline] @@ -393,7 +393,7 @@ impl From for OwnedFd { } #[stable(feature = "io_safety", since = "1.63.0")] -#[cfg(not(target_os = "trusty"))] +#[cfg(not(any(target_os = "trusty", target_os = "l4re")))] impl From for crate::net::TcpListener { #[inline] fn from(owned_fd: OwnedFd) -> Self { @@ -404,7 +404,7 @@ impl From for crate::net::TcpListener { } #[stable(feature = "io_safety", since = "1.63.0")] -#[cfg(not(target_os = "trusty"))] +#[cfg(not(any(target_os = "trusty", target_os = "l4re")))] impl AsFd for crate::net::UdpSocket { #[inline] fn as_fd(&self) -> BorrowedFd<'_> { @@ -413,7 +413,7 @@ impl AsFd for crate::net::UdpSocket { } #[stable(feature = "io_safety", since = "1.63.0")] -#[cfg(not(target_os = "trusty"))] +#[cfg(not(any(target_os = "trusty", target_os = "l4re")))] impl From for OwnedFd { /// Takes ownership of a [`UdpSocket`](crate::net::UdpSocket)'s file descriptor. #[inline] @@ -423,7 +423,7 @@ impl From for OwnedFd { } #[stable(feature = "io_safety", since = "1.63.0")] -#[cfg(not(target_os = "trusty"))] +#[cfg(not(any(target_os = "trusty", target_os = "l4re")))] impl From for crate::net::UdpSocket { #[inline] fn from(owned_fd: OwnedFd) -> Self { diff --git a/library/std/src/os/l4re/fs.rs b/library/std/src/os/l4re/fs.rs index 1f0bacae1ca68..5c171d1119718 100644 --- a/library/std/src/os/l4re/fs.rs +++ b/library/std/src/os/l4re/fs.rs @@ -116,7 +116,6 @@ pub trait MetadataExt { /// ```no_run /// use std::fs; /// use std::io; - /// use std::os::linux::fs::MetadataExt; /// /// fn main() -> io::Result<()> { /// let meta = fs::metadata("some_file")?; @@ -328,7 +327,7 @@ pub trait MetadataExt { impl MetadataExt for Metadata { #[allow(deprecated)] fn as_raw_stat(&self) -> &raw::stat { - unsafe { &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat) } + panic!("as_raw_stat not supported for L4Re"); } fn st_dev(&self) -> u64 { self.as_inner().as_inner().st_dev as u64 @@ -355,22 +354,22 @@ impl MetadataExt for Metadata { self.as_inner().as_inner().st_size as u64 } fn st_atime(&self) -> i64 { - self.as_inner().as_inner().st_atime as i64 + self.as_inner().as_inner().st_atim.tv_sec as i64 } fn st_atime_nsec(&self) -> i64 { - self.as_inner().as_inner().st_atime_nsec as i64 + self.as_inner().as_inner().st_atim.tv_nsec as i64 } fn st_mtime(&self) -> i64 { - self.as_inner().as_inner().st_mtime as i64 + self.as_inner().as_inner().st_mtim.tv_sec as i64 } fn st_mtime_nsec(&self) -> i64 { - self.as_inner().as_inner().st_mtime_nsec as i64 + self.as_inner().as_inner().st_mtim.tv_nsec as i64 } fn st_ctime(&self) -> i64 { - self.as_inner().as_inner().st_ctime as i64 + self.as_inner().as_inner().st_ctim.tv_sec as i64 } fn st_ctime_nsec(&self) -> i64 { - self.as_inner().as_inner().st_ctime_nsec as i64 + self.as_inner().as_inner().st_ctim.tv_nsec as i64 } fn st_blksize(&self) -> u64 { self.as_inner().as_inner().st_blksize as u64 diff --git a/library/std/src/os/l4re/raw.rs b/library/std/src/os/l4re/raw.rs index 8fb6e99ecfa1e..f41fff015cab6 100644 --- a/library/std/src/os/l4re/raw.rs +++ b/library/std/src/os/l4re/raw.rs @@ -10,355 +10,14 @@ )] #![allow(deprecated)] -use crate::os::raw::c_ulong; - #[stable(feature = "raw_ext", since = "1.1.0")] -pub type dev_t = u64; +pub type dev_t = libc::dev_t; #[stable(feature = "raw_ext", since = "1.1.0")] -pub type mode_t = u32; +pub type mode_t = libc::mode_t; #[stable(feature = "pthread_t", since = "1.8.0")] -pub type pthread_t = c_ulong; +pub type pthread_t = libc::pthread_t; #[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 = "m68k", - target_arch = "csky", - target_arch = "powerpc", - target_arch = "sparc", - target_arch = "arm", - 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_uint}; - - #[stable(feature = "raw_ext", since = "1.1.0")] - pub type blkcnt_t = i64; - #[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 = u64; - #[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 = i64; - #[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: u32, - #[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: i32, - #[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 __pad3: [c_int; 2], - } -} - -#[cfg(any( - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64", - target_arch = "riscv64", - target_arch = "riscv32" -))] -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 = i64; - #[stable(feature = "raw_ext", since = "1.1.0")] - pub type blksize_t = i32; - #[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 = u32; - #[stable(feature = "raw_ext", since = "1.1.0")] - pub type off_t = i64; - #[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: 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: 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 __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], - } -} +pub use libc::{blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t}; diff --git a/library/std/src/os/unix/mod.rs b/library/std/src/os/unix/mod.rs index 78c957270c451..2c418e59f77f9 100644 --- a/library/std/src/os/unix/mod.rs +++ b/library/std/src/os/unix/mod.rs @@ -90,6 +90,7 @@ mod platform { pub mod ffi; pub mod fs; pub mod io; +#[cfg(not(target_os = "l4re"))] pub mod net; pub mod process; pub mod raw; diff --git a/library/std/src/sys/fd/unix.rs b/library/std/src/sys/fd/unix.rs index bb6c0ac9e18e6..27c72515d219a 100644 --- a/library/std/src/sys/fd/unix.rs +++ b/library/std/src/sys/fd/unix.rs @@ -394,13 +394,15 @@ impl FileDesc { #[cfg(not(any( all(target_os = "linux", not(target_env = "musl")), target_os = "android", - target_os = "hurd" + target_os = "hurd", + target_os = "l4re" )))] use libc::pwrite as pwrite64; #[cfg(any( all(target_os = "linux", not(target_env = "musl")), target_os = "android", - target_os = "hurd" + target_os = "hurd", + target_os = "l4re" ))] use libc::pwrite64; diff --git a/library/std/src/sys/fs/unix.rs b/library/std/src/sys/fs/unix.rs index bb2ee6ae10ed4..a8ec9e31336b4 100644 --- a/library/std/src/sys/fs/unix.rs +++ b/library/std/src/sys/fs/unix.rs @@ -32,6 +32,7 @@ use libc::fstatat64; target_os = "solaris", target_os = "vita", target_os = "wasi", + target_os = "l4re", all(target_os = "linux", target_env = "musl"), ))] use libc::readdir as readdir64; @@ -53,8 +54,6 @@ use libc::readdir as readdir64; use libc::readdir_r as readdir64_r; #[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "hurd"))] use libc::readdir64; -#[cfg(target_os = "l4re")] -use libc::readdir64_r; use libc::{c_int, mode_t}; #[cfg(target_os = "android")] use libc::{ @@ -63,7 +62,6 @@ use libc::{ }; #[cfg(not(any( all(target_os = "linux", not(target_env = "musl")), - target_os = "l4re", target_os = "android", target_os = "hurd", )))] @@ -71,11 +69,7 @@ use libc::{ dirent as dirent64, fstat as fstat64, ftruncate as ftruncate64, lseek as lseek64, lstat as lstat64, off_t as off64_t, open as open64, stat as stat64, }; -#[cfg(any( - all(target_os = "linux", not(target_env = "musl")), - target_os = "l4re", - target_os = "hurd" -))] +#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "hurd"))] use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64}; use crate::ffi::{CStr, OsStr, OsString}; @@ -414,6 +408,7 @@ fn get_path_from_fd(fd: c_int) -> Option { target_os = "solaris", target_os = "vita", target_os = "wasi", + target_os = "l4re", ))] pub struct DirEntry { dir: Arc, @@ -440,6 +435,7 @@ pub struct DirEntry { target_os = "solaris", target_os = "vita", target_os = "wasi", + target_os = "l4re", ))] struct dirent64_min { d_ino: u64, @@ -466,6 +462,7 @@ struct dirent64_min { target_os = "solaris", target_os = "vita", target_os = "wasi", + target_os = "l4re", )))] pub struct DirEntry { dir: Arc, @@ -611,7 +608,13 @@ impl FileAttr { } } -#[cfg(not(any(target_os = "netbsd", target_os = "nto", target_os = "aix", target_os = "wasi")))] +#[cfg(not(any( + target_os = "netbsd", + target_os = "nto", + target_os = "aix", + target_os = "wasi", + target_os = "l4re" +)))] impl FileAttr { #[cfg(not(any( target_os = "vxworks", @@ -726,7 +729,7 @@ impl FileAttr { } } -#[cfg(any(target_os = "nto", target_os = "wasi"))] +#[cfg(any(target_os = "nto", target_os = "wasi", target_os = "l4re"))] impl FileAttr { pub fn modified(&self) -> io::Result { SystemTime::new(self.stat.st_mtim.tv_sec, self.stat.st_mtim.tv_nsec.into()) @@ -848,6 +851,7 @@ impl Iterator for ReadDir { target_os = "solaris", target_os = "vita", target_os = "wasi", + target_os = "l4re", ))] fn next(&mut self) -> Option> { use crate::sys::os::{errno, set_errno}; @@ -946,6 +950,7 @@ impl Iterator for ReadDir { target_os = "solaris", target_os = "vita", target_os = "wasi", + target_os = "l4re", )))] fn next(&mut self) -> Option> { if self.end_of_stream { @@ -1198,6 +1203,7 @@ impl DirEntry { target_os = "vita", target_os = "hurd", target_os = "wasi", + target_os = "l4re", )))] fn name_cstr(&self) -> &CStr { unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()) } @@ -1215,6 +1221,7 @@ impl DirEntry { target_os = "vita", target_os = "hurd", target_os = "wasi", + target_os = "l4re", ))] fn name_cstr(&self) -> &CStr { &self.name @@ -1410,6 +1417,7 @@ impl File { target_os = "openbsd", target_os = "nto", target_os = "hurd", + target_os = "l4re", ))] unsafe fn os_datasync(fd: c_int) -> c_int { libc::fdatasync(fd) @@ -1424,6 +1432,7 @@ impl File { target_os = "openbsd", target_os = "nto", target_os = "hurd", + target_os = "l4re", target_vendor = "apple", )))] unsafe fn os_datasync(fd: c_int) -> c_int { @@ -1441,6 +1450,7 @@ impl File { target_os = "cygwin", target_os = "illumos", target_os = "aix", + target_os = "l4re", target_vendor = "apple", ))] pub fn lock(&self) -> io::Result<()> { @@ -1468,6 +1478,7 @@ impl File { target_os = "solaris", target_os = "illumos", target_os = "aix", + target_os = "l4re", target_vendor = "apple", )))] pub fn lock(&self) -> io::Result<()> { @@ -1484,6 +1495,7 @@ impl File { target_os = "cygwin", target_os = "illumos", target_os = "aix", + target_os = "l4re", target_vendor = "apple", ))] pub fn lock_shared(&self) -> io::Result<()> { @@ -1511,6 +1523,7 @@ impl File { target_os = "solaris", target_os = "illumos", target_os = "aix", + target_os = "l4re", target_vendor = "apple", )))] pub fn lock_shared(&self) -> io::Result<()> { @@ -1527,6 +1540,7 @@ impl File { target_os = "cygwin", target_os = "illumos", target_os = "aix", + target_os = "l4re", target_vendor = "apple", ))] pub fn try_lock(&self) -> Result<(), TryLockError> { @@ -1570,6 +1584,7 @@ impl File { target_os = "solaris", target_os = "illumos", target_os = "aix", + target_os = "l4re", target_vendor = "apple", )))] pub fn try_lock(&self) -> Result<(), TryLockError> { @@ -1589,6 +1604,7 @@ impl File { target_os = "cygwin", target_os = "illumos", target_os = "aix", + target_os = "l4re", target_vendor = "apple", ))] pub fn try_lock_shared(&self) -> Result<(), TryLockError> { @@ -1632,6 +1648,7 @@ impl File { target_os = "solaris", target_os = "illumos", target_os = "aix", + target_os = "l4re", target_vendor = "apple", )))] pub fn try_lock_shared(&self) -> Result<(), TryLockError> { @@ -1651,6 +1668,7 @@ impl File { target_os = "cygwin", target_os = "illumos", target_os = "aix", + target_os = "l4re", target_vendor = "apple", ))] pub fn unlock(&self) -> io::Result<()> { @@ -1678,6 +1696,7 @@ impl File { target_os = "solaris", target_os = "illumos", target_os = "aix", + target_os = "l4re", target_vendor = "apple", )))] pub fn unlock(&self) -> io::Result<()> { @@ -1781,7 +1800,7 @@ impl File { pub fn set_times(&self, times: FileTimes) -> io::Result<()> { cfg_select! { - any(target_os = "redox", target_os = "espidf", target_os = "horizon", target_os = "nuttx") => { + any(target_os = "redox", target_os = "espidf", target_os = "horizon", target_os = "nuttx", target_os = "l4re") => { // Redox doesn't appear to support `UTIME_OMIT`. // ESP-IDF and HorizonOS do not support `futimens` at all and the behavior for those OS is therefore // the same as for Redox. @@ -2138,6 +2157,7 @@ pub fn link(original: &CStr, link: &CStr) -> io::Result<()> { // Other misc platforms target_os = "horizon", target_os = "vita", + target_os = "l4re", target_env = "nto70", ) => { cvt(unsafe { libc::link(original.as_ptr(), link.as_ptr()) })?; @@ -2505,6 +2525,7 @@ pub use remove_dir_impl::remove_dir_all; target_os = "vita", target_os = "nto", target_os = "vxworks", + target_os = "l4re", miri ))] mod remove_dir_impl { @@ -2519,6 +2540,7 @@ mod remove_dir_impl { target_os = "vita", target_os = "nto", target_os = "vxworks", + target_os = "l4re", miri )))] mod remove_dir_impl { diff --git a/library/std/src/sys/net/connection/unsupported.rs b/library/std/src/sys/net/connection/unsupported.rs index fb18e8dec557c..38941ebbb5f43 100644 --- a/library/std/src/sys/net/connection/unsupported.rs +++ b/library/std/src/sys/net/connection/unsupported.rs @@ -1,7 +1,7 @@ use crate::fmt; use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr, ToSocketAddrs}; -use crate::sys::unsupported; +use crate::sys::unsupported::unsupported; use crate::time::Duration; pub struct TcpStream(!); diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs index f24898671af82..bed3dabb81c2d 100644 --- a/library/std/src/sys/pal/unix/mod.rs +++ b/library/std/src/sys/pal/unix/mod.rs @@ -151,6 +151,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { target_os = "horizon", target_os = "vxworks", target_os = "vita", + target_os = "l4re", // Unikraft's `signal` implementation is currently broken: // https://github.com/unikraft/lib-musl/issues/57 target_vendor = "unikraft", @@ -267,6 +268,7 @@ pub fn decode_error_kind(errno: i32) -> io::ErrorKind { libc::ETIMEDOUT => TimedOut, libc::ETXTBSY => ExecutableFileBusy, libc::EXDEV => CrossesDevices, + #[cfg(not(target_os = "l4re"))] libc::EINPROGRESS => InProgress, libc::EOPNOTSUPP => Unsupported, @@ -426,7 +428,13 @@ cfg_select! { _ => {} } -#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita", target_os = "nuttx"))] +#[cfg(any( + target_os = "espidf", + target_os = "horizon", + target_os = "vita", + target_os = "nuttx", + target_os = "l4re" +))] pub mod unsupported { use crate::io; diff --git a/library/std/src/sys/pal/unix/os.rs b/library/std/src/sys/pal/unix/os.rs index ef3b4a02f8ae4..7f42a31ad96b8 100644 --- a/library/std/src/sys/pal/unix/os.rs +++ b/library/std/src/sys/pal/unix/os.rs @@ -117,6 +117,7 @@ pub fn error_string(errno: i32) -> String { all( any( target_os = "linux", + target_os = "l4re", target_os = "hurd", target_env = "newlib", target_os = "cygwin" @@ -133,7 +134,7 @@ pub fn error_string(errno: i32) -> String { let p = buf.as_mut_ptr(); unsafe { if strerror_r(errno as c_int, p, buf.len()) < 0 { - panic!("strerror_r failure"); + panic!("strerror_r failure. errno: {errno}, p: {:?}, buf: {:?}", p, buf); } let p = p as *const _; diff --git a/library/std/src/sys/personality/mod.rs b/library/std/src/sys/personality/mod.rs index eabef92244d01..f9b833023cd23 100644 --- a/library/std/src/sys/personality/mod.rs +++ b/library/std/src/sys/personality/mod.rs @@ -33,7 +33,7 @@ cfg_select! { target_os = "psp", target_os = "xous", target_os = "solid_asp3", - all(target_family = "unix", not(target_os = "espidf"), not(target_os = "l4re"), not(target_os = "nuttx")), + all(target_family = "unix", not(target_os = "espidf"), not(target_os = "nuttx")), all(target_vendor = "fortanix", target_env = "sgx"), ) => { mod gcc; diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index df64a1716d523..2e80f802c7377 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -1,7 +1,7 @@ #[cfg(target_os = "vxworks")] use libc::RTP_ID as pid_t; #[cfg(not(target_os = "vxworks"))] -use libc::{c_int, pid_t}; +use libc::{c_char, c_int, pid_t}; #[cfg(not(any( target_os = "vxworks", target_os = "l4re", @@ -405,7 +405,10 @@ impl Command { *sys::env::environ() = envp.as_ptr(); } - libc::execvp(self.get_program_cstr().as_ptr(), self.get_argv().as_ptr()); + libc::execvp( + self.get_program_cstr().as_ptr(), + self.get_argv().as_ptr() as *const *const c_char, + ); Err(io::Error::last_os_error()) } diff --git a/library/std/src/sys/random/mod.rs b/library/std/src/sys/random/mod.rs index 91f72d0738790..ab91c9ac61dde 100644 --- a/library/std/src/sys/random/mod.rs +++ b/library/std/src/sys/random/mod.rs @@ -52,7 +52,6 @@ cfg_select! { any( target_os = "aix", target_os = "hurd", - target_os = "l4re", target_os = "nto", ) => { mod unix_legacy; @@ -106,6 +105,7 @@ cfg_select! { all(target_family = "wasm", target_os = "unknown"), target_os = "xous", target_os = "vexos", + target_os = "l4re", ) => { // FIXME: finally remove std support for wasm32-unknown-unknown // FIXME: add random data generation to xous @@ -122,6 +122,7 @@ cfg_select! { all(target_os = "wasi", not(target_env = "p1")), target_os = "xous", target_os = "vexos", + target_os = "l4re", )))] pub fn hashmap_random_keys() -> (u64, u64) { let mut buf = [0; 16]; diff --git a/library/unwind/src/lib.rs b/library/unwind/src/lib.rs index cff2aa7b08b93..a625b650152a0 100644 --- a/library/unwind/src/lib.rs +++ b/library/unwind/src/lib.rs @@ -21,7 +21,6 @@ cfg_select! { // Windows MSVC no extra unwinder support needed } any( - target_os = "l4re", target_os = "none", target_os = "espidf", target_os = "nuttx", @@ -33,6 +32,7 @@ cfg_select! { windows, target_os = "psp", target_os = "solid_asp3", + target_os = "l4re", all(target_vendor = "fortanix", target_env = "sgx"), ) => { mod libunwind; diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index c670ae88fc549..094f1eb8110d8 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -222,7 +222,8 @@ pub fn use_host_linker(target: TargetSelection) -> bool { || target.contains("fortanix") || target.contains("fuchsia") || target.contains("bpf") - || target.contains("switch")) + || target.contains("switch") + || target.contains("l4re")) } pub fn target_supports_cranelift_backend(target: TargetSelection) -> bool { From 325f3b4fb15b85167c1214ddae60d0968c85c77b Mon Sep 17 00:00:00 2001 From: Marius Melzer Date: Fri, 9 Jan 2026 17:57:53 +0100 Subject: [PATCH 2/3] Add aarch64 architecture for L4Re target --- compiler/rustc_target/src/spec/mod.rs | 1 + .../targets/aarch64_unknown_l4re_uclibc.rs | 28 +++++++++++++++++++ src/bootstrap/src/core/sanity.rs | 1 + tests/assembly-llvm/targets/targets-elf.rs | 3 ++ 4 files changed, 33 insertions(+) create mode 100644 compiler/rustc_target/src/spec/targets/aarch64_unknown_l4re_uclibc.rs diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 89c9fdc935cc5..bac251b82d709 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1559,6 +1559,7 @@ supported_targets! { ("avr-none", avr_none), + ("aarch64-unknown-l4re-uclibc", aarch64_unknown_l4re_uclibc), ("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc), ("aarch64-unknown-redox", aarch64_unknown_redox), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_unknown_l4re_uclibc.rs b/compiler/rustc_target/src/spec/targets/aarch64_unknown_l4re_uclibc.rs new file mode 100644 index 0000000000000..bca1195ddad72 --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/aarch64_unknown_l4re_uclibc.rs @@ -0,0 +1,28 @@ +use crate::spec::{Arch, Cc, LinkerFlavor, Target, TargetOptions, base}; + +pub(crate) fn target() -> Target { + let mut base = base::l4re::opts(); + + let extra_link_args = &["-zmax-page-size=0x1000", "-zcommon-page-size=0x1000"]; + base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), extra_link_args); + base.add_pre_link_args(LinkerFlavor::Unix(Cc::No), extra_link_args); + + Target { + llvm_target: "aarch64-unknown-l4re-uclibc".into(), + metadata: crate::spec::TargetMetadata { + description: Some("Arm64 L4Re".into()), + tier: Some(3), + host_tools: Some(false), + std: Some(true), + }, + pointer_width: 64, + data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(), + arch: Arch::AArch64, + options: TargetOptions { + features: "+v8a".into(), + mcount: "__mcount".into(), + max_atomic_width: Some(128), + ..base + } + } +} diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 67f4eb37b2c11..a3efc0051b91a 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -38,6 +38,7 @@ pub struct Finder { const STAGE0_MISSING_TARGETS: &[&str] = &[ // just a dummy comment so the list doesn't get onelined "riscv64im-unknown-none-elf", + "aarch64-unknown-l4re-uclibc", ]; /// Minimum version threshold for libstdc++ required when using prebuilt LLVM diff --git a/tests/assembly-llvm/targets/targets-elf.rs b/tests/assembly-llvm/targets/targets-elf.rs index c8b81cc858d6a..82a662c234b19 100644 --- a/tests/assembly-llvm/targets/targets-elf.rs +++ b/tests/assembly-llvm/targets/targets-elf.rs @@ -43,6 +43,9 @@ //@ revisions: aarch64_unknown_illumos //@ [aarch64_unknown_illumos] compile-flags: --target aarch64-unknown-illumos //@ [aarch64_unknown_illumos] needs-llvm-components: aarch64 +//@ revisions: aarch64_unknown_l4re_uclibc +//@ [aarch64_unknown_l4re_uclibc] compile-flags: --target aarch64-unknown-l4re-uclibc +//@ [aarch64_unknown_l4re_uclibc] needs-llvm-components: aarch64 //@ revisions: aarch64_unknown_linux_gnu //@ [aarch64_unknown_linux_gnu] compile-flags: --target aarch64-unknown-linux-gnu //@ [aarch64_unknown_linux_gnu] needs-llvm-components: aarch64 From cd3369f92e5297dc7bb4b6394a05c6ad2671c7e0 Mon Sep 17 00:00:00 2001 From: Marius Melzer Date: Fri, 9 Jan 2026 18:07:12 +0100 Subject: [PATCH 3/3] Add documentation and maintainer for L4Re target --- src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 3 +- src/doc/rustc/src/platform-support/l4re.md | 63 ++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/doc/rustc/src/platform-support/l4re.md diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 3b8852f8ff9f7..4a921f6918136 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -82,6 +82,7 @@ - [avr-none](platform-support/avr-none.md) - [\*-espidf](platform-support/esp-idf.md) - [\*-unknown-fuchsia](platform-support/fuchsia.md) + - [\*-unknown-l4re](platform-support/l4re.md) - [\*-unknown-trusty](platform-support/trusty.md) - [\*-kmc-solid_\*](platform-support/kmc-solid.md) - [csky-unknown-linux-gnuabiv2\*](platform-support/csky-unknown-linux-gnuabiv2.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 754d0c975ec36..f2e3932a023bb 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -259,6 +259,7 @@ target | std | host | notes [`aarch64-unknown-helenos`](platform-support/helenos.md) | ✓ | | ARM64 HelenOS [`aarch64-unknown-hermit`](platform-support/hermit.md) | ✓ | | ARM64 Hermit [`aarch64-unknown-illumos`](platform-support/illumos.md) | ✓ | ✓ | ARM64 illumos +[`aarch64-unknown-l4re-uclibc`](platform-support/l4re.md) | ✓ | | ARM64 L4Re with uclibc `aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI) [`aarch64-unknown-managarm-mlibc`](platform-support/managarm.md) | ? | | ARM64 Managarm [`aarch64-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | ARM64 NetBSD @@ -437,7 +438,7 @@ target | std | host | notes [`x86_64-unknown-hermit`](platform-support/hermit.md) | ✓ | | x86_64 Hermit [`x86_64-unknown-helenos`](platform-support/helenos.md) | ✓ | | x86_64 (amd64) HelenOS [`x86_64-unknown-hurd-gnu`](platform-support/hurd.md) | ✓ | ✓ | 64-bit GNU/Hurd -`x86_64-unknown-l4re-uclibc` | ? | | +[`x86_64-unknown-l4re-uclibc`](platform-support/l4re.md) | ✓ | | x86_64 L4Re with uclibc [`x86_64-unknown-linux-none`](platform-support/x86_64-unknown-linux-none.md) | * | | 64-bit Linux with no libc [`x86_64-unknown-managarm-mlibc`](platform-support/managarm.md) | ? | | x86_64 Managarm [`x86_64-unknown-motor`](platform-support/motor.md) | ✓ | | x86_64 Motor OS diff --git a/src/doc/rustc/src/platform-support/l4re.md b/src/doc/rustc/src/platform-support/l4re.md new file mode 100644 index 0000000000000..56044319dc77a --- /dev/null +++ b/src/doc/rustc/src/platform-support/l4re.md @@ -0,0 +1,63 @@ +# `*-l4re-uclibc` + +**Tier: 3** + +[L4Re] is an open source, microkernel-based operating system and hypervisor. + +Target triplets available so far: + +- x86_64-unknown-l4re-uclibc +- aarch64-unknown-l4re-uclibc + +## Target maintainers + +- Marius Melzer ([@farao](https://github.com/farao)) + +## Requirements + +The L4Re targets are cross-compiled from a host environment, commonly Linux. +See [Getting Started] for options to set up L4Re. + +The L4Re sources can be found in the [Github Repos]. + +## Building an L4Re Rust Toolchain + +Configure one or several of the above L4Re targets and also add the host triple +in config.toml and build Rust as documented. Start off the toolchain by copying +`build/host/stage2/` to a self-chosen location. + +For each target, build an L4Re sysroot directory by running `make sysroot` in +the L4Re build directory. Copy the content of `sysroot/usr/lib/` into the +`self-contained` directory of the respective target in the Rust Toolchain +directory tree. + +Use rustup to install the L4Re Rust Toolchain locally: + +```sh +rustup toolchain link l4re +``` + +Now use the toolchain via a cargo (or directly a rustc) installed via `rustup`: + +```sh +cargo +l4re build --target +``` + +or + +```sh +rustc +l4re --target +``` + +## Run Rust Programs on L4Re + +You can run an L4Re application written in Rust just like any other externally +built (meaning not build with the L4Re build system) L4Re binary. A good option +is to build an L4Re image and add the application binary to the image and run it +via the ned script. The image can then be put on hardware or run on Qemu. + +See [l4re.org](https://l4re.org) for more information. + +[L4Re]: https://l4re.org +[Getting Started]: https://l4re.org/getting_started +[Github Repos]: https://github.com/L4Re