Refactor Linker::Link

This patch does basically two things:
- First make `global` variable not public, And make it accessable via a
function `get_sym`.
- Isolate the procedure that collect global symbols into single function
that does that and call it `collect_syms`.

The motivation of this patch is the second one where this procedure is
extended, thus it needs a seamless way to access those symbols
This commit is contained in:
oddcoder
2020-03-07 23:27:25 +02:00
parent 77a0294114
commit 04ea2f9397
2 changed files with 61 additions and 36 deletions
+3 -3
View File
@@ -108,9 +108,9 @@ pub unsafe extern "C" fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *m
eprintln!("dlsym: linker_ptr: {:p}", tcb.linker_ptr);
let linker = (&*tcb.linker_ptr).lock();
if let Some(global) = linker.globals.get(symbol_str) {
eprintln!("dlsym({:p}, {}) = 0x{:x}", handle, symbol_str, *global);
*global as *mut c_void
if let Some(global) = linker.get_sym(symbol_str) {
eprintln!("dlsym({:p}, {}) = 0x{:x}", handle, symbol_str, global);
global as *mut c_void
} else {
eprintln!("dlsym: symbol not found");
ERROR.store(ERROR_NOT_SUPPORTED.as_ptr() as usize, Ordering::SeqCst);