LibELF: Always use parent object basename for $ORIGIN processing

Using the main executable basename produces the wrong $ORIGIN processing
for libraries that are secondary dependencies of the main executable,
or dependencies of an object loaded via dlopen.
This commit is contained in:
Andrew Kaster 2022-06-11 13:55:04 -06:00 committed by Linus Groh
parent 64d48bcdc1
commit 72066880c6
Notes: sideshowbarker 2024-07-17 10:18:25 +09:00

View file

@ -120,7 +120,7 @@ static Optional<String> resolve_library(String const& name, DynamicObject const&
search_paths.append("/usr/local/lib"sv);
for (auto const& search_path : search_paths) {
LexicalPath library_path(search_path.replace("$ORIGIN"sv, LexicalPath::dirname(s_main_program_name)));
LexicalPath library_path(search_path.replace("$ORIGIN"sv, LexicalPath::dirname(parent_object.filename())));
String library_name = library_path.append(name).string();
if (access(library_name.characters(), F_OK) == 0)