diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp index 4bd3b228d0ff..af25d9598021 100644 --- a/clang/tools/driver/driver.cpp +++ b/clang/tools/driver/driver.cpp @@ -53,8 +53,15 @@ using namespace clang::driver; using namespace llvm::opt; std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) { - if (!CanonicalPrefixes) - return Argv0; + if (!CanonicalPrefixes) { + SmallString<128> ExecutablePath(Argv0); + // Do a PATH lookup if Argv0 isn't a valid path. + if (!llvm::sys::fs::exists(ExecutablePath)) + if (llvm::ErrorOr P = + llvm::sys::findProgramByName(ExecutablePath)) + ExecutablePath = *P; + return ExecutablePath.str(); + } // This just needs to be some symbol in the binary; C++ doesn't // allow taking the address of ::main however.