Re: r305600 - [Driver] Do a PATH lookup if needed when using -no-canonical-prefixes
On Fri, Jun 16, 2017 at 10:40:18PM -, Petr Hosek via cfe-commits wrote: > @@ -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. This will fail if the current directory contains a file with the name of the program, won't it? I think the correct order here would be to check if ExecutablePath contains a path separator and if it doesn't, call findProgramByName. Joerg ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r305600 - [Driver] Do a PATH lookup if needed when using -no-canonical-prefixes
Author: phosek Date: Fri Jun 16 17:40:18 2017 New Revision: 305600 URL: http://llvm.org/viewvc/llvm-project?rev=305600=rev Log: [Driver] Do a PATH lookup if needed when using -no-canonical-prefixes When -no-canonical-prefixes option is used and argv0 contains only a program name, we need to do a PATH lookup to get an executable path, otherwise the return value won't be a valid path and any subsequent uses of it (e.g. when invoking -cc1) will fail with an error. This patch fixes PR9576. Differential Revision: https://reviews.llvm.org/D34290 Modified: cfe/trunk/tools/driver/driver.cpp Modified: cfe/trunk/tools/driver/driver.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=305600=305599=305600=diff == --- cfe/trunk/tools/driver/driver.cpp (original) +++ cfe/trunk/tools/driver/driver.cpp Fri Jun 16 17:40:18 2017 @@ -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. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits