|
| 1 | +From 0abe058d7f99c9c7bbaf4ee98308c5e78d229897 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Nikita Popov < [email protected]> |
| 3 | +Date: Wed, 12 Feb 2025 09:44:26 +0100 |
| 4 | +Subject: [PATCH] [BOLT] Use getMainExecutable() (#126698) |
| 5 | + |
| 6 | +Use LLVM's getMainExecutable() helper instead of rolling our own. This |
| 7 | +will result in standard behavior across platforms, such as making sure |
| 8 | +that symlinks are always resolved. |
| 9 | +--- |
| 10 | + bolt/tools/driver/llvm-bolt.cpp | 12 +----------- |
| 11 | + 1 file changed, 1 insertion(+), 11 deletions(-) |
| 12 | + |
| 13 | +diff --git a/bolt/tools/driver/llvm-bolt.cpp b/bolt/tools/driver/llvm-bolt.cpp |
| 14 | +index efa06cd68cb9..f151cf5f63fc 100644 |
| 15 | +--- a/bolt/tools/driver/llvm-bolt.cpp |
| 16 | ++++ b/bolt/tools/driver/llvm-bolt.cpp |
| 17 | +@@ -173,16 +173,6 @@ void boltMode(int argc, char **argv) { |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | +-static std::string GetExecutablePath(const char *Argv0) { |
| 22 | +- SmallString<256> ExecutablePath(Argv0); |
| 23 | +- // Do a PATH lookup if Argv0 isn't a valid path. |
| 24 | +- if (!llvm::sys::fs::exists(ExecutablePath)) |
| 25 | +- if (llvm::ErrorOr<std::string> P = |
| 26 | +- llvm::sys::findProgramByName(ExecutablePath)) |
| 27 | +- ExecutablePath = *P; |
| 28 | +- return std::string(ExecutablePath); |
| 29 | +-} |
| 30 | +- |
| 31 | + int main(int argc, char **argv) { |
| 32 | + // Print a stack trace if we signal out. |
| 33 | + sys::PrintStackTraceOnErrorSignal(argv[0]); |
| 34 | +@@ -190,7 +180,7 @@ int main(int argc, char **argv) { |
| 35 | + |
| 36 | + llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| 37 | + |
| 38 | +- std::string ToolPath = GetExecutablePath(argv[0]); |
| 39 | ++ std::string ToolPath = llvm::sys::fs::getMainExecutable(argv[0], nullptr); |
| 40 | + |
| 41 | + // Initialize targets and assembly printers/parsers. |
| 42 | + llvm::InitializeAllTargetInfos(); |
| 43 | +-- |
| 44 | +2.48.1 |
| 45 | + |
0 commit comments