[llvm] 8c6a0c8 - [llvm-rc] Resolve the executable path if not present in Argv[0]
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 8 13:20:27 PDT 2023
Author: Martin Storsjö
Date: 2023-08-08T23:18:56+03:00
New Revision: 8c6a0c8bf50bca6c3a0c4de1b84f21466ee31655
URL: https://github.com/llvm/llvm-project/commit/8c6a0c8bf50bca6c3a0c4de1b84f21466ee31655
DIFF: https://github.com/llvm/llvm-project/commit/8c6a0c8bf50bca6c3a0c4de1b84f21466ee31655.diff
LOG: [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 282744a9ce18120dc0a6eceb02693b36980d9498 actually have
the desired effect.
Differential Revision: https://reviews.llvm.org/D157241
Added:
Modified:
llvm/tools/llvm-rc/llvm-rc.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp
index 3a151cc600b676..5745901ea4a87a 100644
--- a/llvm/tools/llvm-rc/llvm-rc.cpp
+++ b/llvm/tools/llvm-rc/llvm-rc.cpp
@@ -123,7 +123,13 @@ std::string createTempFile(const Twine &Prefix, StringRef Suffix) {
}
ErrorOr<std::string> findClang(const char *Argv0, StringRef Triple) {
- StringRef Parent = llvm::sys::path::parent_path(Argv0);
+ // This just needs to be some symbol in the binary.
+ void *P = (void*) (intptr_t) findClang;
+ std::string MainExecPath = llvm::sys::fs::getMainExecutable(Argv0, P);
+ if (MainExecPath.empty())
+ MainExecPath = Argv0;
+
+ StringRef Parent = llvm::sys::path::parent_path(MainExecPath);
ErrorOr<std::string> Path = std::error_code();
std::string TargetClang = (Triple + "-clang").str();
std::string VersionedClang = ("clang-" + Twine(LLVM_VERSION_MAJOR)).str();
More information about the llvm-commits
mailing list