Fix redox ld_so

This commit is contained in:
Jeremy Soller
2020-02-28 19:33:20 -07:00
parent b1aad49df4
commit 79f265745a
2 changed files with 17 additions and 16 deletions
+8 -4
View File
@@ -41,7 +41,8 @@ pub struct Linker {
pub globals: BTreeMap<String, usize>,
/// Loaded library in-memory data
mmaps: BTreeMap<String, &'static mut [u8]>,
verbose: bool
verbose: bool,
tls_index_offset: usize,
}
impl Linker {
@@ -51,7 +52,8 @@ impl Linker {
objects: BTreeMap::new(),
globals: BTreeMap::new(),
mmaps: BTreeMap::new(),
verbose: verbose
verbose,
tls_index_offset: 0,
}
}
@@ -329,14 +331,14 @@ impl Linker {
);
}
if Some(*elf_name) == primary_opt {
tls_ranges.insert(elf_name.to_string(), (0, tcb_master.range()));
tls_ranges.insert(elf_name.to_string(), (self.tls_index_offset, tcb_master.range()));
tcb_masters[0] = tcb_master;
} else {
tcb_master.offset -= tls_offset;
tls_offset += vsize;
tls_ranges.insert(
elf_name.to_string(),
(tcb_masters.len(), tcb_master.range()),
(self.tls_index_offset + tcb_masters.len(), tcb_master.range()),
);
tcb_masters.push(tcb_master);
}
@@ -346,6 +348,8 @@ impl Linker {
}
}
self.tls_index_offset += tcb_masters.len();
// Set master images for TLS and copy TLS data
if let Some(ref mut tcb) = tcb_opt {
unsafe {
+9 -12
View File
@@ -121,11 +121,11 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) ->
(argv, envs, auxv)
};
let img_entry = *auxv.get(&AT_ENTRY).unwrap_or_else(|| {
eprintln!("failed to find AT_ENTRY");
unistd::_exit(1);
loop {}
});
let is_manual = if let Some(img_entry) = auxv.get(&AT_ENTRY) {
*img_entry == ld_entry
} else {
true
};
// Some variables that will be overridden by environment and auxiliary vectors
let library_path = match envs.get("LD_LIBRARY_PATH") {
@@ -133,10 +133,7 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) ->
None => "/lib",
};
let path;
let is_manual = img_entry == ld_entry;
if is_manual {
let path = if is_manual {
// ld.so is run directly by user and not via execve() or similar systemcall
println!("argv: {:#?}", argv);
println!("envs: {:#?}", envs);
@@ -148,10 +145,10 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) ->
loop {}
}
unsafe { adjust_stack(sp) };
path = &argv[1];
&argv[1]
} else {
path = &argv[0];
}
&argv[0]
};
let mut linker = Linker::new(library_path, is_manual);
match linker.load(&path, &path) {