[llvm] dc078e6 - TargetParser: fix getProcessTriple in universal builds
Jon Roelofs via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 14 13:45:01 PDT 2023
Author: Jon Roelofs
Date: 2023-07-14T13:44:43-07:00
New Revision: dc078e6eaacff66596fac76b6104aa504f77d45d
URL: https://github.com/llvm/llvm-project/commit/dc078e6eaacff66596fac76b6104aa504f77d45d
DIFF: https://github.com/llvm/llvm-project/commit/dc078e6eaacff66596fac76b6104aa504f77d45d.diff
LOG: TargetParser: fix getProcessTriple in universal builds
The bug happens when you build e.g. an x64_64;arm64 JIT with
LLVM_HOST_TRIPLE=x86_64-apple-macos, and then run it on an apple-m1 not under
Rosetta. In that case, sys::getProcessTriple() will return an x86_64 triple,
not an arm64 one.
Differential revision: https://reviews.llvm.org/D138449
Added:
Modified:
llvm/lib/TargetParser/Host.cpp
Removed:
################################################################################
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 44b36b12142458..8b17118401cb47 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1878,10 +1878,44 @@ bool sys::getHostCPUFeatures(StringMap<bool> &Features) {
bool sys::getHostCPUFeatures(StringMap<bool> &Features) { return false; }
#endif
+#if __APPLE__
+/// \returns the \p triple, but with the Host's arch spliced in.
+static Triple withHostArch(Triple T) {
+#if defined(__arm__)
+ T.setArch(Triple::arm);
+ T.setArchName("arm");
+#elif defined(__arm64e__)
+ T.setArch(Triple::aarch64, Triple::AArch64SubArch_arm64e);
+ T.setArchName("arm64e");
+#elif defined(__aarch64__)
+ T.setArch(Triple::aarch64);
+ T.setArchName("arm64");
+#elif defined(__x86_64h__)
+ T.setArch(Triple::x86_64);
+ T.setArchName("x86_64h");
+#elif defined(__x86_64__)
+ T.setArch(Triple::x86_64);
+ T.setArchName("x86_64");
+#elif defined(__powerpc__)
+ T.setArch(Triple::ppc);
+ T.setArchName("powerpc");
+#else
+# error "Unimplemented host arch fixup"
+#endif
+ return T;
+}
+#endif
+
std::string sys::getProcessTriple() {
std::string TargetTripleString = updateTripleOSVersion(LLVM_HOST_TRIPLE);
Triple PT(Triple::normalize(TargetTripleString));
+#if __APPLE__
+ /// In Universal builds, LLVM_HOST_TRIPLE will have the wrong arch in one of
+ /// the slices. This fixes that up.
+ PT = withHostArch(PT);
+#endif
+
if (sizeof(void *) == 8 && PT.isArch32Bit())
PT = PT.get64BitArchVariant();
if (sizeof(void *) == 4 && PT.isArch64Bit())
More information about the llvm-commits
mailing list