-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[BOLT] Resolve symlink for library lookup #126386
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
Conversation
…voked from symlink
@llvm/pr-subscribers-bolt Author: YongKang Zhu (yozhu) ChangesFull diff: https://github.com/llvm/llvm-project/pull/126386.diff 1 Files Affected:
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);
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is fine, but I was wondering what scenario you hit where the library is symlinked and you need to perform the extra step to resovle.
I hit this in our internal build system where a symlink to |
LG, thanks. |
No description provided.