mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 19:57:45 +03:00
LibELF: Look up symbols in all global modules
dlsym() called with RTLD_DEFAULT (nullptr) should look up symbol in all global modules instead of only looking into the executable file
This commit is contained in:
parent
fbbea77fa4
commit
33d19a562f
Notes:
sideshowbarker
2024-07-17 22:09:47 +09:00
Author: https://github.com/TSultanov Commit: https://github.com/SerenityOS/serenity/commit/33d19a562f Pull-request: https://github.com/SerenityOS/serenity/pull/12683 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/IdanHo
@ -458,17 +458,21 @@ static Result<void*, DlErrorMessage> __dlsym(void* handle, char const* symbol_na
|
|||||||
__pthread_mutex_lock(&s_loader_lock);
|
__pthread_mutex_lock(&s_loader_lock);
|
||||||
ScopeGuard unlock_guard = [] { __pthread_mutex_unlock(&s_loader_lock); };
|
ScopeGuard unlock_guard = [] { __pthread_mutex_unlock(&s_loader_lock); };
|
||||||
|
|
||||||
auto object = static_cast<DynamicObject*>(handle);
|
Optional<DynamicObject::SymbolLookupResult> symbol;
|
||||||
if (!handle) {
|
|
||||||
auto library_name = get_library_name(s_main_program_name);
|
if (handle) {
|
||||||
auto global_object = s_global_objects.get(library_name);
|
auto object = static_cast<DynamicObject*>(handle);
|
||||||
object = *global_object;
|
symbol = object->lookup_symbol(symbol_name);
|
||||||
|
} else {
|
||||||
|
// When handle is 0 (RTLD_DEFAULT) we should look up the symbol in all global modules
|
||||||
|
// https://pubs.opengroup.org/onlinepubs/009604499/functions/dlsym.html
|
||||||
|
symbol = DynamicLinker::lookup_global_symbol(symbol_name);
|
||||||
}
|
}
|
||||||
auto symbol = object->lookup_symbol(symbol_name);
|
|
||||||
if (!symbol.has_value()) {
|
if (symbol.has_value())
|
||||||
return DlErrorMessage { String::formatted("Symbol {} not found", symbol_name) };
|
return symbol.value().address.as_ptr();
|
||||||
}
|
|
||||||
return symbol.value().address.as_ptr();
|
return DlErrorMessage { String::formatted("Symbol {} not found", symbol_name) };
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result<void, DlErrorMessage> __dladdr(void* addr, Dl_info* info)
|
static Result<void, DlErrorMessage> __dladdr(void* addr, Dl_info* info)
|
||||||
|
Loading…
Reference in New Issue
Block a user