[llvm] [llvm-bolt] Modify `getLibPath` to enable `--runtime-instrumentation-lib` option handle full path correctly.(llvm#99772) (PR #99806)
Zimo Ji via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 21 05:16:23 PDT 2024
https://github.com/lltsdyp updated https://github.com/llvm/llvm-project/pull/99806
>From ede137b646939fa78dd454fb961d55678bbea2a9 Mon Sep 17 00:00:00 2001
From: Jizimo <jizimo0430 at outlook.com>
Date: Sun, 21 Jul 2024 17:24:18 +0800
Subject: [PATCH 1/2] [llvm-bolt] Modify `getLibPath` to enable
`--runtime-instrumentation-lib` option handle full path correctly.
---
bolt/lib/RuntimeLibs/RuntimeLibrary.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp b/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
index 276b034d71f96..0826847ee1189 100644
--- a/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
+++ b/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
@@ -28,6 +28,12 @@ void RuntimeLibrary::anchor() {}
std::string RuntimeLibrary::getLibPath(StringRef ToolPath,
StringRef LibFileName) {
+ // Handle full path.
+ // It is weird that append LibFileName to LibPath when user gives a full path.
+ if(LibFileName[0]=='/')
+ {
+ return LibFileName.str();
+ }
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);
>From 0abdfd5d5ffc4d94bbf4418002b22f11d6e89af8 Mon Sep 17 00:00:00 2001
From: Jizimo <jizimo0430 at outlook.com>
Date: Sun, 21 Jul 2024 20:14:54 +0800
Subject: [PATCH 2/2] Add an error handler in my previous commit
In my previous commit, I forget to add an error ha
ndler when given full path.
---
bolt/lib/RuntimeLibs/RuntimeLibrary.cpp | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp b/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
index 0826847ee1189..f1a086867a299 100644
--- a/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
+++ b/bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
@@ -30,20 +30,20 @@ std::string RuntimeLibrary::getLibPath(StringRef ToolPath,
StringRef LibFileName) {
// Handle full path.
// It is weird that append LibFileName to LibPath when user gives a full path.
- if(LibFileName[0]=='/')
- {
- return LibFileName.str();
- }
- 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);
- if (!llvm::sys::fs::exists(LibPath)) {
- // In some cases we install bolt binary into one level deeper in bin/,
- // we need to go back one more level to find lib directory.
- LibPath = llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
+ if (LibFileName[0] == '/') {
+ LibPath = LibFileName;
+ } else {
+ 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);
+ if (!llvm::sys::fs::exists(LibPath)) {
+ // In some cases we install bolt binary into one level deeper in bin/,
+ // we need to go back one more level to find lib directory.
+ LibPath = llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
+ llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
+ }
+ llvm::sys::path::append(LibPath, LibFileName);
}
- llvm::sys::path::append(LibPath, LibFileName);
if (!llvm::sys::fs::exists(LibPath)) {
errs() << "BOLT-ERROR: library not found: " << LibPath << "\n";
exit(1);
More information about the llvm-commits
mailing list