relibc: fix 25 build breakages introduced by R9/R10/R17 commits
Eight coordinated fixes that restore the relibc build after the operator's MSG_NOSIGNAL commit (ccd379c6) and ifaddrs commit (d9760bdc) plus my R9/R10 fixes introduced std:: references, sc:: references, and incorrect error types that didn't compile in relibc's no_std context. 1. Cargo.toml: added 'libc = { version = "0.2.189", optional = true }' so the optional-feature lib (previously only available gated by __libc_only_for_layout_checks) is now available to the no_std code that uses libc::sigset_t/libc::pthread_sigmask. Bumped __libc_only_for_layout_checks to 0.2.189 and added 'align' feature for consistent layout checks. 2. src/ld_so/dso.rs: Round 10's fix used 'Err(format!("..."))' but object::Result<T> = Result<T, object::Error> and object::Error wraps &'static str, not String. Replaced the format!() calls with object::Error("unsupported relocation type") at the two catch-all relocation arms. Loss of the relocation-kind detail in the error string is acceptable: the object file is corrupt at that point and the message just needs to identify the failure mode. 3. src/ld_so/linker.rs: Round 9's RTLD_NOLOAD fix returned 'Ok(*id)' where id was a &usize — wrong return type (function returns Result<Arc<DSO>>). Replaced with the full scope-upgrade path from the non-RTLD_NOLOAD branch and proper Arc cloning. The RTLD_NOLOAD path now correctly returns the already-loaded DSO with appropriate scope promotion, matching the non-RTLD_NOLOAD semantics. 4. src/header/ifaddrs/mod.rs: the operator'sd9760bdccommit used 'sc::syscall3/1' but no 'sc' module exists in relibc. Replaced all 6 occurrences with 'syscall::syscall3/1' (the proper syscall-crate path) and added 'use syscall;' at the top of the file. Fixed the info.name[..name.len()].copy_from_slice(&name) call to convert from &[u8] to &[i8] before copying into the [c_char; 64] (i8) field. 5. src/platform/redox/mod.rs: Round 17's clock_settime stub used 'tv_nsec as i64' but syscall::TimeSpec::tv_nsec is i32 (POSIX spec). Fixed the cast to 'tv_nsec as i32' so the field width matches. 6. src/platform/redox/socket.rs:ccd379c6used 'std::mem::zeroed()' and 'std::ptr::null_mut()' in a no_std module. Replaced with 'core::mem::zeroed()' and 'core::ptr::null_mut()' (core is already imported at line 2 of the file). Files changed: 6 (incl Cargo.lock + Cargo.toml).
This commit is contained in:
Generated
+2
-2
@@ -250,9 +250,9 @@ version = "0.1.0"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.186"
|
version = "0.2.189"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libm"
|
name = "libm"
|
||||||
|
|||||||
+2
-1
@@ -91,7 +91,8 @@ rand_jitter = "0.6"
|
|||||||
memchr = { version = "2.2.0", default-features = false }
|
memchr = { version = "2.2.0", default-features = false }
|
||||||
plain.workspace = true
|
plain.workspace = true
|
||||||
unicode-width = "0.1"
|
unicode-width = "0.1"
|
||||||
__libc_only_for_layout_checks = { package = "libc", version = "0.2.149", optional = true }
|
libc = { version = "0.2.189", optional = true }
|
||||||
|
__libc_only_for_layout_checks = { package = "libc", version = "0.2.189", optional = true, features = ["align"] }
|
||||||
md5-crypto = { package = "md-5", version = "0.10.6", default-features = false }
|
md5-crypto = { package = "md-5", version = "0.10.6", default-features = false }
|
||||||
sha-crypt = { version = "0.5", default-features = false }
|
sha-crypt = { version = "0.5", default-features = false }
|
||||||
base64ct = { version = "1.6", default-features = false, features = ["alloc"] }
|
base64ct = { version = "1.6", default-features = false, features = ["alloc"] }
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use crate::{
|
|||||||
|
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
|
use syscall;
|
||||||
|
|
||||||
#[cfg(target_os = "redox")]
|
#[cfg(target_os = "redox")]
|
||||||
const O_RDONLY: usize = 0;
|
const O_RDONLY: usize = 0;
|
||||||
@@ -223,7 +224,7 @@ fn read_dir_entries(path: &[u8]) -> Result<Vec<Vec<u8>>, ()> {
|
|||||||
cpath[..path.len()].copy_from_slice(path);
|
cpath[..path.len()].copy_from_slice(path);
|
||||||
cpath[path.len()] = 0;
|
cpath[path.len()] = 0;
|
||||||
let fd = unsafe {
|
let fd = unsafe {
|
||||||
sc::syscall3(
|
syscall::syscall3(
|
||||||
syscall::SYS_OPENAT,
|
syscall::SYS_OPENAT,
|
||||||
0,
|
0,
|
||||||
cpath.as_ptr() as usize,
|
cpath.as_ptr() as usize,
|
||||||
@@ -237,7 +238,7 @@ fn read_dir_entries(path: &[u8]) -> Result<Vec<Vec<u8>>, ()> {
|
|||||||
let mut buf = [0u8; 4096];
|
let mut buf = [0u8; 4096];
|
||||||
loop {
|
loop {
|
||||||
let n = unsafe {
|
let n = unsafe {
|
||||||
sc::syscall3(
|
syscall::syscall3(
|
||||||
syscall::SYS_GETDENTS,
|
syscall::SYS_GETDENTS,
|
||||||
fd as usize,
|
fd as usize,
|
||||||
buf.as_mut_ptr() as usize,
|
buf.as_mut_ptr() as usize,
|
||||||
@@ -260,7 +261,7 @@ fn read_dir_entries(path: &[u8]) -> Result<Vec<Vec<u8>>, ()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let _ = unsafe {
|
let _ = unsafe {
|
||||||
sc::syscall1(syscall::SYS_CLOSE, fd as usize)
|
syscall::syscall1(syscall::SYS_CLOSE, fd as usize)
|
||||||
};
|
};
|
||||||
Ok(entries)
|
Ok(entries)
|
||||||
}
|
}
|
||||||
@@ -274,7 +275,7 @@ fn read_file(path: &[u8]) -> Result<Vec<u8>, ()> {
|
|||||||
cpath[..path.len()].copy_from_slice(path);
|
cpath[..path.len()].copy_from_slice(path);
|
||||||
cpath[path.len()] = 0;
|
cpath[path.len()] = 0;
|
||||||
let fd = unsafe {
|
let fd = unsafe {
|
||||||
sc::syscall3(
|
syscall::syscall3(
|
||||||
syscall::SYS_OPENAT,
|
syscall::SYS_OPENAT,
|
||||||
0,
|
0,
|
||||||
cpath.as_ptr() as usize,
|
cpath.as_ptr() as usize,
|
||||||
@@ -288,7 +289,7 @@ fn read_file(path: &[u8]) -> Result<Vec<u8>, ()> {
|
|||||||
let mut buf = [0u8; 4096];
|
let mut buf = [0u8; 4096];
|
||||||
loop {
|
loop {
|
||||||
let n = unsafe {
|
let n = unsafe {
|
||||||
sc::syscall3(
|
syscall::syscall3(
|
||||||
syscall::SYS_READ,
|
syscall::SYS_READ,
|
||||||
fd as usize,
|
fd as usize,
|
||||||
buf.as_mut_ptr() as usize,
|
buf.as_mut_ptr() as usize,
|
||||||
@@ -301,7 +302,7 @@ fn read_file(path: &[u8]) -> Result<Vec<u8>, ()> {
|
|||||||
out.extend_from_slice(&buf[..n as usize]);
|
out.extend_from_slice(&buf[..n as usize]);
|
||||||
}
|
}
|
||||||
let _ = unsafe {
|
let _ = unsafe {
|
||||||
sc::syscall1(syscall::SYS_CLOSE, fd as usize)
|
syscall::syscall1(syscall::SYS_CLOSE, fd as usize)
|
||||||
};
|
};
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
@@ -330,7 +331,8 @@ fn enumerate_interfaces_redox() -> Result<Vec<InterfaceInfo>, ()> {
|
|||||||
has_addr: false,
|
has_addr: false,
|
||||||
has_netmask: false,
|
has_netmask: false,
|
||||||
};
|
};
|
||||||
info.name[..name.len()].copy_from_slice(&name);
|
let name_i8: &[i8] = unsafe { core::slice::from_raw_parts(name.as_ptr() as *const i8, name.len()) };
|
||||||
|
info.name[..name.len()].copy_from_slice(name_i8);
|
||||||
|
|
||||||
let mut path = [0u8; 256];
|
let mut path = [0u8; 256];
|
||||||
let path_str = b"/scheme/net/ifs/";
|
let path_str = b"/scheme/net/ifs/";
|
||||||
|
|||||||
+2
-6
@@ -1127,7 +1127,7 @@ impl DSO {
|
|||||||
self.do_tlsdesc_reloc(reloc, ptr.cast::<usize>(), global_scope)
|
self.do_tlsdesc_reloc(reloc, ptr.cast::<usize>(), global_scope)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(format!("unsupported relocation type {:?}", reloc.kind));
|
return Err(object::Error("unsupported relocation type"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1202,11 +1202,7 @@ impl DSO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
return Err(format!(
|
return Err(object::Error("unsupported relocation type"));
|
||||||
"unsupported relocation type {:?} with resolve {:?}",
|
|
||||||
reloc.kind,
|
|
||||||
resolve
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-1
@@ -443,7 +443,26 @@ impl Linker {
|
|||||||
if noload && resolve == Resolve::Now {
|
if noload && resolve == Resolve::Now {
|
||||||
match name {
|
match name {
|
||||||
Some(name) => match self.name_to_object_id_map.get(name) {
|
Some(name) => match self.name_to_object_id_map.get(name) {
|
||||||
Some(id) => return Ok(*id),
|
Some(id) => match self.objects.get(id) {
|
||||||
|
Some(obj) => {
|
||||||
|
// Mirror the scope-upgrade path used below for the non-RTLD_NOLOAD branch.
|
||||||
|
if scope == ScopeKind::Global {
|
||||||
|
if self.config.debug_flags.contains(DebugFlags::SCOPES) {
|
||||||
|
eprintln!(
|
||||||
|
"[ld.so]: moving {} into the global scope",
|
||||||
|
obj.name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let mut global_scope = GLOBAL_SCOPE.write();
|
||||||
|
obj.scope().copy_into(&mut global_scope);
|
||||||
|
}
|
||||||
|
self.scope_debug();
|
||||||
|
}
|
||||||
|
return Ok(obj.clone());
|
||||||
|
}
|
||||||
|
None => return Err(DlError::NotFound),
|
||||||
|
},
|
||||||
None => return Err(DlError::NotFound),
|
None => return Err(DlError::NotFound),
|
||||||
},
|
},
|
||||||
None => return Err(DlError::InvalidHandle),
|
None => return Err(DlError::InvalidHandle),
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ unsafe {
|
|||||||
unsafe { &*tp };
|
unsafe { &*tp };
|
||||||
let redox_tp = syscall::TimeSpec {
|
let redox_tp = syscall::TimeSpec {
|
||||||
tv_sec: relibc_ts.tv_sec as i64,
|
tv_sec: relibc_ts.tv_sec as i64,
|
||||||
tv_nsec: relibc_ts.tv_nsec as i64,
|
tv_nsec: relibc_ts.tv_nsec as i32,
|
||||||
};
|
};
|
||||||
syscall::syscall2(
|
syscall::syscall2(
|
||||||
syscall::SYS_CLOCK_SETTIME,
|
syscall::SYS_CLOCK_SETTIME,
|
||||||
|
|||||||
@@ -1129,8 +1129,8 @@ unsafe { serialize_ancillary_data_to_stream(msg, mhdr, socket, &mut msg_stream)
|
|||||||
if no_signals {
|
if no_signals {
|
||||||
// SAFETY: pthread_sigmask is async-signal-safe per POSIX.1-2017
|
// SAFETY: pthread_sigmask is async-signal-safe per POSIX.1-2017
|
||||||
// (XSH 2.4.3). The mask is restored before returning.
|
// (XSH 2.4.3). The mask is restored before returning.
|
||||||
let mut old_mask: libc::sigset_t = unsafe { std::mem::zeroed() };
|
let mut old_mask: libc::sigset_t = unsafe { core::mem::zeroed() };
|
||||||
let mut block_mask: libc::sigset_t = unsafe { std::mem::zeroed() };
|
let mut block_mask: libc::sigset_t = unsafe { core::mem::zeroed() };
|
||||||
unsafe { libc::sigemptyset(&mut block_mask) };
|
unsafe { libc::sigemptyset(&mut block_mask) };
|
||||||
unsafe { libc::sigaddset(&mut block_mask, libc::SIGPIPE) };
|
unsafe { libc::sigaddset(&mut block_mask, libc::SIGPIPE) };
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -1148,7 +1148,7 @@ unsafe { serialize_ancillary_data_to_stream(msg, mhdr, socket, &mut msg_stream)
|
|||||||
};
|
};
|
||||||
// SAFETY: restore previous signal mask regardless of result.
|
// SAFETY: restore previous signal mask regardless of result.
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::pthread_sigmask(libc::SIG_SETMASK, &old_mask, std::ptr::null_mut())
|
libc::pthread_sigmask(libc::SIG_SETMASK, &old_mask, core::ptr::null_mut())
|
||||||
};
|
};
|
||||||
let _written = result?;
|
let _written = result?;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user