[llvm-branch-commits] [llvm] release/20.x: [BOLT] Use getMainExecutable() (#126698) (PR #126881)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 12 02:16:57 PST 2025


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/126881

Backport 0abe058d7f99c9c7bbaf4ee98308c5e78d229897

Requested by: @nikic

>From 540c45e578ae099533ce459674557e8db4852ba5 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Wed, 12 Feb 2025 09:44:26 +0100
Subject: [PATCH] [BOLT] Use getMainExecutable() (#126698)

Use LLVM's getMainExecutable() helper instead of rolling our own. This
will result in standard behavior across platforms, such as making sure
that symlinks are always resolved.

(cherry picked from commit 0abe058d7f99c9c7bbaf4ee98308c5e78d229897)
---
 bolt/tools/driver/llvm-bolt.cpp | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/bolt/tools/driver/llvm-bolt.cpp b/bolt/tools/driver/llvm-bolt.cpp
index efa06cd68cb99..f151cf5f63fc5 100644
--- a/bolt/tools/driver/llvm-bolt.cpp
+++ b/bolt/tools/driver/llvm-bolt.cpp
@@ -173,16 +173,6 @@ void boltMode(int argc, char **argv) {
   }
 }
 
-static std::string GetExecutablePath(const char *Argv0) {
-  SmallString<256> ExecutablePath(Argv0);
-  // Do a PATH lookup if Argv0 isn't a valid path.
-  if (!llvm::sys::fs::exists(ExecutablePath))
-    if (llvm::ErrorOr<std::string> P =
-            llvm::sys::findProgramByName(ExecutablePath))
-      ExecutablePath = *P;
-  return std::string(ExecutablePath);
-}
-
 int main(int argc, char **argv) {
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal(argv[0]);
@@ -190,7 +180,7 @@ int main(int argc, char **argv) {
 
   llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
 
-  std::string ToolPath = GetExecutablePath(argv[0]);
+  std::string ToolPath = llvm::sys::fs::getMainExecutable(argv[0], nullptr);
 
   // Initialize targets and assembly printers/parsers.
   llvm::InitializeAllTargetInfos();



More information about the llvm-branch-commits mailing list