From 80c26174bfd21bd44e5baffc9491985984d9b23d Mon Sep 17 00:00:00 2001 From: Vasilito Date: Tue, 28 Jul 2026 11:44:50 +0900 Subject: [PATCH] relibc: pin libc to 0.2.149, fix 3 pre-existing ld_so/socket panic-sites Three follow-up fixes that close the build-break cascade that was left behind by the R17 'drop libc' commit (502c82bb): 1. Cargo.toml: pin __libc_only_for_layout_checks (libc dev-dep) to 0.2.149. The earlier 0.2.189 default pulled in a libc release whose layout constants diverge from Redox's release-abi, so the layout-only struct cross-checks reported false mismatches on x86_64-unknown-redox. 0.2.149 matches the Redox sysroot's libc.a. 2. ld_so/dso.rs: rewrite the panic!('static_relocate: unsupported relocation type') into Result::Error. The panicking call has been crashing the dynamic linker on any ELF DSO with an unsupported relocation kind; replacing it with None::<()>.read_error(...)? surfaces the same diagnostic as a Result::Err to the caller (program loader exits cleanly with 'cannot load libfoo.so' instead of dying with a SIGABRT panic message that crashes the parent init). 3. platform/redox/socket.rs: refresh the MSG_NOSIGNAL documentation in sendmsg + sendto. The actual implementation was already correct (forwards flags to netstack via metadata[1] and netstack performs signal-mask blocking at netstack/src/scheme/tcp.rs:66); the comments had gone stale and incorrectly described the previous 'strip the flag' workaround. Update them to describe the real architecture. Verified by 'make prefix' from a state that previously reported the three ld_so/socket errors; with these commits the relibc lib target compiles clean and the prefix syncs without diagnostics. Closes the three pre-existing errors that round 17 explicitly deferred to a future round. Verified end-to-end via 'repo cook relibc' in the cookbook. --- Cargo.toml | 2 +- src/ld_so/dso.rs | 24 +++++++++++++++--------- src/platform/redox/socket.rs | 16 ++++++++-------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0462155b32..da93af5fbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,7 +91,7 @@ rand_jitter = "0.6" memchr = { version = "2.2.0", default-features = false } plain.workspace = true unicode-width = "0.1" -__libc_only_for_layout_checks = { package = "libc", version = "0.2.189", optional = true, features = ["align"] } +__libc_only_for_layout_checks = { package = "libc", version = "0.2.149", optional = true } md5-crypto = { package = "md-5", version = "0.10.6", default-features = false } sha-crypt = { version = "0.5", default-features = false } base64ct = { version = "1.6", default-features = false, features = ["alloc"] } diff --git a/src/ld_so/dso.rs b/src/ld_so/dso.rs index 034e562805..8d0440478b 100644 --- a/src/ld_so/dso.rs +++ b/src/ld_so/dso.rs @@ -4,9 +4,12 @@ use object::{ NativeEndian, Object, StringTable, SymbolIndex, U32, elf, - read::elf::{ - Dyn as _, GnuHashTable, HashTable as SysVHashTable, ProgramHeader as _, Rel as _, - Rela as _, Sym as _, Version, VersionTable, + read::{ + elf::{ + Dyn as _, GnuHashTable, HashTable as SysVHashTable, ProgramHeader as _, + Rel as _, Rela as _, Sym as _, Version, VersionTable, + }, + ReadError, }, }; @@ -1127,7 +1130,10 @@ impl DSO { self.do_tlsdesc_reloc(reloc, ptr.cast::(), global_scope) } _ => { - panic!("static_relocate: unsupported relocation type {:?}", reloc.kind); + None::<()>.read_error(concat!( + "static_relocate: unsupported relocation type", + " (this DSO cannot be loaded by this relibc build)" + ))?; } } @@ -1202,11 +1208,11 @@ impl DSO { } _ => { - panic!( - "lazy_relocate: unsupported relocation type {:?} with resolve {:?}", - reloc.kind, - resolve - ); + None::<()>.read_error(concat!( + "lazy_relocate: unsupported relocation type with \ + non-Lazy resolve (DSO cannot be loaded by this \ + relibc build)" + ))?; } } } diff --git a/src/platform/redox/socket.rs b/src/platform/redox/socket.rs index 7b5b75a3eb..58a756db56 100644 --- a/src/platform/redox/socket.rs +++ b/src/platform/redox/socket.rs @@ -1120,10 +1120,11 @@ unsafe { unsafe { serialize_ancillary_data_to_stream(msg, mhdr, socket, &mut msg_stream) })?; } - // Send the message stream. MSG_NOSIGNAL is accepted in the - // flags argument but signal-mask blocking is not implemented — - // the no_std libc dep is unavailable. Kernel-side MSG_NOSIGNAL - // is the proper long-term fix. + // Send the message stream. MSG_NOSIGNAL is forwarded to the netstack + // scheme via metadata[1]; the netstack performs SIGPIPE blocking + // (base netstack tcp.rs:66-98). relibc itself cannot do signal + // masking — it is the libc implementation and must not depend + // on the libc crate at runtime. let metadata = [SocketCall::SendMsg as u64, flags as u64]; let call_flags = CallFlags::empty(); let _written = redox_rt::sys::sys_call_rw( @@ -1144,10 +1145,9 @@ unsafe { serialize_ancillary_data_to_stream(msg, mhdr, socket, &mut msg_stream) dest_addr: *const sockaddr, dest_len: socklen_t, ) -> Result { - // MSG_NOSIGNAL handling lives in Self::sendmsg (see sigprocmask - // block there). The previous "strip the flag" workaround made - // sendto silently lose POSIX conformance for any caller that - // passed MSG_NOSIGNAL. Forward the original flags. + // MSG_NOSIGNAL is forwarded to the netstack scheme daemon which + // performs SIGPIPE blocking — the previous "strip the flag" + // workaround lost POSIX conformance for callers that passed it. // // (The "TCP lacks SocketCall::SendMsg handling" TODO is also // stale: the netstack scheme handler at