[llvm] [BOLT] Extra lookup of library on target directory if bolt is invoked from symlink (PR #126386)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 8 11:45:42 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: YongKang Zhu (yozhu)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/126386.diff
1 Files Affected:
- (modified) bolt/lib/RuntimeLibs/RuntimeLibrary.cpp (+18)
``````````diff
diff --git a/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp b/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
index 336c6768a7f712..8f5719e84ecea8 100644
--- a/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
+++ b/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
@@ -18,6 +18,7 @@
#include "llvm/Object/Archive.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
#define DEBUG_TYPE "bolt-rtlib"
@@ -38,6 +39,23 @@ std::string RuntimeLibrary::getLibPathByToolPath(StringRef ToolPath,
llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
}
llvm::sys::path::append(LibPath, LibFileName);
+ if (!llvm::sys::fs::exists(LibPath)) {
+ // If it is a symlink, check the directory that the symlink points to.
+ if (llvm::sys::fs::is_symlink_file(ToolPath)) {
+ SmallString<256> RealPath;
+ llvm::sys::fs::real_path(ToolPath, RealPath);
+ if (llvm::ErrorOr<std::string> P =
+ llvm::sys::findProgramByName(RealPath)) {
+ outs() << "BOLT-INFO: library not found: " << LibPath << "\n"
+ << "BOLT-INFO: " << ToolPath << " is a symlink; will look up "
+ << LibFileName
+ << " at the target directory that the symlink points to\n";
+ return getLibPath(*P, LibFileName);
+ }
+ }
+ errs() << "BOLT-ERROR: library not found: " << LibPath << "\n";
+ exit(1);
+ }
return std::string(LibPath);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/126386
More information about the llvm-commits
mailing list