[llvm] [BOLT] Enable standalone build (PR #97130)

Rafael Auler via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 16:20:52 PDT 2024


================
@@ -38,13 +38,33 @@ 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 =
+      llvm::sys::path::root_path(CMAKE_INSTALL_FULL_LIBDIR);
+  llvm::sys::path::append(LibPath, LibFileName);
+  return std::string(LibPath);
+}
+
+std::string RuntimeLibrary::getLibPath(StringRef ToolPath,
+                                       StringRef 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 << " or " << ByInstalled
+         << "\n";
+  exit(1);
+}
+
----------------
rafaelauler wrote:

All usages of the string in command line option RuntimeHugifyLib (and the equivalent instrumentation lib one)  go through RuntimeLibrary::getLibPath(), but I don't see any check here that matches against "LibFileName" alone. So I think this will still fail if the user provides a full path in RuntimeHugifyLib. We need to first try to match against "LibFileName" alone and only try the additional mechanisms (getLibPathByToolPath, getLibPathByInstalled) after this initial try failed.

https://github.com/llvm/llvm-project/pull/97130


More information about the llvm-commits mailing list