aboutsummaryrefslogtreecommitdiff
path: root/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
diff options
context:
space:
mode:
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 =