103,23 → 103,50 |
return sym; /* Found */ |
} |
|
|
elf_symbol_t *symbol_def_find(char *name, module_t **m) |
/** Find the definition of a symbol. |
* |
* By definition in System V ABI, if module origin has the flag DT_SYMBOLIC, |
* origin is searched first. Otherwise, or if the symbol hasn't been found, |
* the module dependency graph is searched breadth-first, beginning |
* from the executable program. |
* |
* @param name Name of the symbol to search for. |
* @param origin Module in which the dependency originates. |
* @param mod (output) Will be filled with a pointer to the module |
* that contains the symbol. |
*/ |
elf_symbol_t *symbol_def_find(char *name, module_t *origin, module_t **mod) |
{ |
module_t *m; |
elf_symbol_t *sym; |
|
sym = def_find_in_module(name, runtime_env.program); |
if (sym != NULL) { *m = runtime_env.program; return sym; } |
/* FIXME: support DT_SYMBOLIC */ |
//m = origin; |
|
sym = def_find_in_module(name, runtime_env.libc); |
if (sym != NULL) { *m = runtime_env.libc; return sym; } |
/* Start in the executable program */ |
m = runtime_env.program; |
|
sym = def_find_in_module(name, &runtime_env.rtld); |
if (sym != NULL) { *m = &runtime_env.rtld; return sym; } |
while (true) { |
sym = def_find_in_module(name, m); |
if (sym != NULL) { |
*mod = m; |
return sym; |
} |
|
printf("symbol found nowhere\n"); |
*m = NULL; |
return NULL; |
if (m->n_deps < 1) break; |
|
/* FIXME: support branching */ |
if (m->n_deps > 1) { |
printf("error: BFS unimplemented\n"); |
exit(1); |
} |
|
m = m->deps[0]; |
} |
|
printf("Error, symbol '%s' not found anywhere\n", name); |
exit(1); |
return NULL; /* Not found */ |
} |
|
uintptr_t symbol_get_addr(elf_symbol_t *sym, module_t *m) |