aboutsummaryrefslogtreecommitdiff
path: root/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
diff options
context:
space:
mode:
authorTristan Ross <tristan.ross@midstall.com>2024-07-25 08:18:14 -0700
committerGitHub <noreply@github.com>2024-07-25 08:18:14 -0700
commitabc2eae68290c453e1899a94eccc4ed5ea3b69c1 (patch)
tree66b52f2daa57b42ac8d0ac8230962c12318d446a /bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
parent51d4980a133db12888207698e39c469cb7055cac (diff)
downloadllvm-abc2eae68290c453e1899a94eccc4ed5ea3b69c1.zip
llvm-abc2eae68290c453e1899a94eccc4ed5ea3b69c1.tar.gz
llvm-abc2eae68290c453e1899a94eccc4ed5ea3b69c1.tar.bz2
[BOLT] Enable standalone build (#97130)
Continue from #87196 as author did not have much time, I have taken over working on this PR. We would like to have this so it'll be easier to package for Nix. Can be tested by copying cmake, bolt, third-party, and llvm directories out into their own directory with this PR applied and then build bolt. --------- Co-authored-by: pca006132 <john.lck40@gmail.com>
Diffstat (limited to 'bolt/lib/RuntimeLibs/RuntimeLibrary.cpp')
-rw-r--r--bolt/lib/RuntimeLibs/RuntimeLibrary.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp b/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
index 276b034..336c676 100644
--- a/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
+++ b/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
@@ -26,8 +26,8 @@ using namespace bolt;
void RuntimeLibrary::anchor() {}
-std::string RuntimeLibrary::getLibPath(StringRef ToolPath,
- StringRef LibFileName) {
+std::string RuntimeLibrary::getLibPathByToolPath(StringRef ToolPath,
+ StringRef LibFileName) {
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);
@@ -38,13 +38,36 @@ std::string RuntimeLibrary::getLibPath(StringRef ToolPath,
llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
}
llvm::sys::path::append(LibPath, LibFileName);
- if (!llvm::sys::fs::exists(LibPath)) {
- errs() << "BOLT-ERROR: library not found: " << LibPath << "\n";
- exit(1);
- }
return std::string(LibPath);
}
+std::string RuntimeLibrary::getLibPathByInstalled(StringRef LibFileName) {
+ SmallString<128> LibPath(CMAKE_INSTALL_FULL_LIBDIR);
+ llvm::sys::path::append(LibPath, LibFileName);
+ return std::string(LibPath);
+}
+
+std::string RuntimeLibrary::getLibPath(StringRef ToolPath,
+ StringRef LibFileName) {
+ if (llvm::sys::fs::exists(LibFileName)) {
+ return std::string(LibFileName);
+ }
+
+ std::string ByTool = getLibPathByToolPath(ToolPath, LibFileName);
+ if (llvm::sys::fs::exists(ByTool)) {
+ return ByTool;
+ }
+
+ std::string ByInstalled = getLibPathByInstalled(LibFileName);
+ if (llvm::sys::fs::exists(ByInstalled)) {
+ return ByInstalled;
+ }
+
+ errs() << "BOLT-ERROR: library not found: " << ByTool << ", " << ByInstalled
+ << ", or " << LibFileName << "\n";
+ exit(1);
+}
+
void RuntimeLibrary::loadLibrary(StringRef LibPath, BOLTLinker &Linker,
BOLTLinker::SectionsMapper MapSections) {
ErrorOr<std::unique_ptr<MemoryBuffer>> MaybeBuf =