Skip to content

[llvm-bolt] Modify getLibPath to enable --runtime-instrumentation-lib option handle full path correctly.(llvm#99772) #99806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@ void RuntimeLibrary::anchor() {}

std::string RuntimeLibrary::getLibPath(StringRef ToolPath,
StringRef LibFileName) {
// Handle full path.
// It is weird that append LibFileName to LibPath when user gives a full path.

StringRef Dir = llvm::sys::path::parent_path(ToolPath);
SmallString<128> LibPath = llvm::sys::path::parent_path(Dir);
llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
if (!llvm::sys::fs::exists(LibPath)) {
// In some cases we install bolt binary into one level deeper in bin/,
// we need to go back one more level to find lib directory.
LibPath = llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
if (LibFileName[0] == '/') {
LibPath = LibFileName;
} else {
llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
if (!llvm::sys::fs::exists(LibPath)) {
// In some cases we install bolt binary into one level deeper in bin/,
// we need to go back one more level to find lib directory.
LibPath = llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
}
llvm::sys::path::append(LibPath, LibFileName);
}
llvm::sys::path::append(LibPath, LibFileName);
if (!llvm::sys::fs::exists(LibPath)) {
errs() << "BOLT-ERROR: library not found: " << LibPath << "\n";
exit(1);
Expand Down
Loading