Skip to content

Conversation

@nikic
Copy link
Contributor

@nikic nikic commented Feb 11, 2025

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Feb 11, 2025

@llvm/pr-subscribers-bolt

Author: Nikita Popov (nikic)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/126698.diff

1 Files Affected:

  • (modified) bolt/tools/driver/llvm-bolt.cpp (+1-11)
diff --git a/bolt/tools/driver/llvm-bolt.cpp b/bolt/tools/driver/llvm-bolt.cpp
index efa06cd68cb997d..f151cf5f63fc5da 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();

@nikic nikic merged commit 0abe058 into llvm:main Feb 12, 2025
9 checks passed
@nikic nikic deleted the bolt-main-executable branch February 12, 2025 08:44
@nikic nikic added this to the LLVM 20.X Release milestone Feb 12, 2025
@nikic
Copy link
Contributor Author

nikic commented Feb 12, 2025

/cherry-pick 0abe058

@llvmbot
Copy link
Member

llvmbot commented Feb 12, 2025

/pull-request #126881

swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 13, 2025
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 0abe058)
flovent pushed a commit to flovent/llvm-project that referenced this pull request Feb 13, 2025
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.
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
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.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
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.
liuyangxy pushed a commit to fedora-riscv/llvm that referenced this pull request Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Development

Successfully merging this pull request may close these issues.

3 participants