Skip to content

Commit 8c6a0c8

Browse files
committed
[llvm-rc] Resolve the executable path if not present in Argv[0]
The llvm-rc tool tries to locate a suitable Clang executable to use for preprocessing. For this purpose, it first checks within the same directory as the llvm-rc tool, checking with a couple different names, followed by checking all of $PATH for another couple names. On Windows, the InitLLVM() function always sets up Argv[0] with the full path to the executable, while on Unix, Argv[0] is kept as is. Therefore, call getMainExecutable to try to resolve the directory of the executable before looking for colocated Clang executables. This makes 282744a actually have the desired effect. Differential Revision: https://reviews.llvm.org/D157241
1 parent 10ae8ae commit 8c6a0c8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

llvm/tools/llvm-rc/llvm-rc.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ std::string createTempFile(const Twine &Prefix, StringRef Suffix) {
123123
}
124124

125125
ErrorOr<std::string> findClang(const char *Argv0, StringRef Triple) {
126-
StringRef Parent = llvm::sys::path::parent_path(Argv0);
126+
// This just needs to be some symbol in the binary.
127+
void *P = (void*) (intptr_t) findClang;
128+
std::string MainExecPath = llvm::sys::fs::getMainExecutable(Argv0, P);
129+
if (MainExecPath.empty())
130+
MainExecPath = Argv0;
131+
132+
StringRef Parent = llvm::sys::path::parent_path(MainExecPath);
127133
ErrorOr<std::string> Path = std::error_code();
128134
std::string TargetClang = (Triple + "-clang").str();
129135
std::string VersionedClang = ("clang-" + Twine(LLVM_VERSION_MAJOR)).str();

0 commit comments

Comments
 (0)