Verified Commit 79f26574 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Fix redox ld_so

parent b1aad49d
......@@ -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 {
......
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment