From 6382b174dccc769d1ac980c4574298cd39c3783e Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Fri, 28 Oct 2022 19:30:46 +0200 Subject: [PATCH] LibELF: Drop the "resolve and map" all-in-one Both users of this function now have to do their resolving separately before anyways, so let's just drop the resolving part inside the function and require absolute paths to be fed in instead. --- Userland/Libraries/LibELF/DynamicLinker.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibELF/DynamicLinker.cpp b/Userland/Libraries/LibELF/DynamicLinker.cpp index 9ee6c59bb7..1658d99c36 100644 --- a/Userland/Libraries/LibELF/DynamicLinker.cpp +++ b/Userland/Libraries/LibELF/DynamicLinker.cpp @@ -137,17 +137,15 @@ static Optional resolve_library(String const& name, DynamicObject const& return {}; } -static Result, DlErrorMessage> resolve_and_map_library(String const& name, DynamicObject const& parent_object) +static Result, DlErrorMessage> map_library(String const& path) { - auto resolved_library_name = resolve_library(name, parent_object); - if (!resolved_library_name.has_value()) - return DlErrorMessage { String::formatted("Could not find required shared library: {}", name) }; + VERIFY(path.starts_with('/')); - int fd = open(resolved_library_name.value().characters(), O_RDONLY); + int fd = open(path.characters(), O_RDONLY); if (fd < 0) - return DlErrorMessage { String::formatted("Could not open resolved shared library '{}': {}", resolved_library_name.value(), strerror(errno)) }; + return DlErrorMessage { String::formatted("Could not open shared library '{}': {}", path, strerror(errno)) }; - return map_library(resolved_library_name.value(), fd); + return map_library(path, fd); } static Vector get_dependencies(String const& path) @@ -183,7 +181,7 @@ static Result map_dependencies(String const& path) return DlErrorMessage { String::formatted("Could not find required shared library: {}", needed_name) }; if (!s_loaders.contains(dependency_path.value()) && !s_global_objects.contains(dependency_path.value())) { - auto loader = TRY(resolve_and_map_library(dependency_path.value(), parent_object)); + auto loader = TRY(map_library(dependency_path.value())); TRY(map_dependencies(loader->filepath())); } } @@ -482,7 +480,7 @@ static Result __dlopen(char const* filename, int flags) return *existing_elf_object; } - auto loader = TRY(resolve_and_map_library(library_path.value(), parent_object)); + auto loader = TRY(map_library(library_path.value())); if (auto error = verify_tls_for_dlopen(loader); error.has_value()) return error.value();