LibELF: Warn if resolving a library resulted in a relative path

This commit is contained in:
Tim Schumacher 2022-12-26 17:35:08 +01:00 committed by Andrew Kaster
parent 1011067a60
commit 83f6d5b26a
Notes: sideshowbarker 2024-07-17 02:23:54 +09:00

View file

@ -132,8 +132,16 @@ static Optional<DeprecatedString> resolve_library(DeprecatedString const& name,
LexicalPath library_path(search_path.replace("$ORIGIN"sv, LexicalPath::dirname(parent_object.filepath()), ReplaceMode::FirstOnly));
DeprecatedString library_name = library_path.append(name).string();
if (access(library_name.characters(), F_OK) == 0)
if (access(library_name.characters(), F_OK) == 0) {
if (!library_name.starts_with('/')) {
// FIXME: Non-absolute paths should resolve from the current working directory. However,
// since that's almost never the effect that is actually desired, let's print
// a warning and only implement it once something actually needs that behavior.
dbgln("\033[33mWarning:\033[0m Resolving library '{}' resulted in non-absolute path '{}'. Check your binary for relative RPATHs and RUNPATHs.", name, library_name);
}
return library_name;
}
}
return {};