Skip to content

Commit

Permalink
[BOLT] Use getMainExecutable() (#126698)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
nikic authored and tstellar committed Feb 13, 2025
1 parent 2342bb2 commit c99d611
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions bolt/tools/driver/llvm-bolt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,14 @@ 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]);
PrettyStackTraceProgram X(argc, 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();
Expand Down

0 comments on commit c99d611

Please sign in to comment.