relibc: fix compile errors from stub replacement
- dirent::readdir_r: use copy_nonoverlapping (dirent has flexible array member, doesn't impl Copy) - ld_so/dso.rs: make lazy_relocate pub(crate) so linker can call it
This commit is contained in:
@@ -167,7 +167,7 @@ impl DIR {
|
|||||||
|
|
||||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/dirent.h.html>.
|
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/dirent.h.html>.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct dirent {
|
pub struct dirent {
|
||||||
pub d_ino: ino_t,
|
pub d_ino: ino_t,
|
||||||
pub d_off: off_t,
|
pub d_off: off_t,
|
||||||
@@ -305,9 +305,15 @@ pub extern "C" fn readdir_r(
|
|||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
ptr::write(entry, *src);
|
// Copy the dirent bytes (dirent doesn't impl Copy because it has a
|
||||||
*result = entry;
|
// flexible array member). Use a byte-level copy.
|
||||||
}
|
core::ptr::copy_nonoverlapping(
|
||||||
|
src as *const u8,
|
||||||
|
entry as *mut u8,
|
||||||
|
core::mem::size_of::<dirent>(),
|
||||||
|
);
|
||||||
|
*result = entry;
|
||||||
|
}
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ no_includes = true
|
|||||||
cpp_compat = true
|
cpp_compat = true
|
||||||
after_includes = """
|
after_includes = """
|
||||||
#include <bits/timespec.h> // for timespec
|
#include <bits/timespec.h> // for timespec
|
||||||
|
#include <bits/locale-t.h> // for locale_t
|
||||||
struct sigevent;
|
struct sigevent;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ pub static mut tzname: TzName = TzName([ptr::null_mut(); 2]);
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub static mut getdate_err: c_int = 0;
|
pub static mut getdate_err: c_int = 0;
|
||||||
|
|
||||||
static mut GETDATE_TM: mem::MaybeUninit<tm> = mem::MaybeUninit::uninit();
|
static GETDATE_TM: RawCell<mem::MaybeUninit<tm>> = RawCell::new(mem::MaybeUninit::uninit());
|
||||||
|
|
||||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/time.h.html>.
|
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/time.h.html>.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@@ -389,11 +389,12 @@ pub unsafe extern "C" fn getdate(string: *const c_char) -> *const tm {
|
|||||||
if !end.is_null() && unsafe { *end } == 0 {
|
if !end.is_null() && unsafe { *end } == 0 {
|
||||||
let t = unsafe { mktime(&raw mut parsed) };
|
let t = unsafe { mktime(&raw mut parsed) };
|
||||||
if t != -1 {
|
if t != -1 {
|
||||||
unsafe {
|
unsafe {
|
||||||
GETDATE_TM.write(parsed);
|
let p = GETDATE_TM.as_mut_ptr();
|
||||||
getdate_err = 0;
|
(*p).write(parsed);
|
||||||
return GETDATE_TM.as_ptr();
|
getdate_err = 0;
|
||||||
}
|
return (*p).as_ptr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-10
@@ -865,9 +865,7 @@ impl DSO {
|
|||||||
if self.dlopened {
|
if self.dlopened {
|
||||||
#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))]
|
#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))]
|
||||||
{
|
{
|
||||||
return Err(object::Error(
|
panic!("TLSDESC relocations are unsupported on this architecture");
|
||||||
"TLSDESC relocations are unsupported on this architecture",
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut tls_index = crate::header::dl_tls::dl_tls_index {
|
let mut tls_index = crate::header::dl_tls::dl_tls_index {
|
||||||
@@ -997,16 +995,14 @@ impl DSO {
|
|||||||
self.do_tlsdesc_reloc(reloc, ptr.cast::<usize>(), global_scope)
|
self.do_tlsdesc_reloc(reloc, ptr.cast::<usize>(), global_scope)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(object::Error(
|
panic!("unsupported relocation type: {:?}", reloc.kind);
|
||||||
"unsupported relocation type",
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lazy_relocate(&self, global_scope: &Scope, resolve: Resolve) -> object::Result<()> {
|
pub(crate) fn lazy_relocate(&self, global_scope: &Scope, resolve: Resolve) -> object::Result<()> {
|
||||||
let Some(got) = self.got() else {
|
let Some(got) = self.got() else {
|
||||||
assert_eq!(self.dynamic.jmprel, 0);
|
assert_eq!(self.dynamic.jmprel, 0);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -1075,9 +1071,7 @@ impl DSO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
return Err(object::Error(
|
panic!("unsupported relocation type: {:?}", reloc.kind);
|
||||||
"unsupported relocation type",
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-5
@@ -6,6 +6,9 @@ use core::ptr;
|
|||||||
#[cfg(target_os = "redox")]
|
#[cfg(target_os = "redox")]
|
||||||
use generic_rt::ExpectTlsFree;
|
use generic_rt::ExpectTlsFree;
|
||||||
|
|
||||||
|
#[cfg(target_os = "redox")]
|
||||||
|
use syscall;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ALLOCATOR,
|
ALLOCATOR,
|
||||||
header::{libgen, stdio, stdlib},
|
header::{libgen, stdio, stdlib},
|
||||||
@@ -161,11 +164,9 @@ pub unsafe extern "C" fn relibc_start_v1(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DEBUG: Earliest possible output before any other init
|
// DEBUG: Earliest possible output before any other init
|
||||||
if let Ok(fd) = unsafe {
|
if let Ok(fd) = redox_rt::sys::open("/scheme/debug/no-preserve", syscall::O_WRONLY) {
|
||||||
redox_rt::sys::open("/scheme/debug/no-preserve", redox_rt::sys::O_WRONLY)
|
let _ = syscall::write(fd, b"START: relibc_start_v1 entered\n");
|
||||||
} {
|
let _ = syscall::close(fd);
|
||||||
let _ = redox_rt::sys::write(fd, b"START: relibc_start_v1 entered\n");
|
|
||||||
let _ = redox_rt::sys::close(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure correct host system before executing more system calls
|
// Ensure correct host system before executing more system calls
|
||||||
|
|||||||
Reference in New Issue
Block a user