[PATCH] D138449: support: fix getProcessTriple in universal builds
Jon Roelofs via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 21 09:50:24 PST 2022
jroelofs created this revision.
jroelofs added reviewers: lhames, keith.
Herald added subscribers: StephenFan, pengfei, hiraditya, kristof.beyls.
Herald added a project: All.
jroelofs requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138449
Files:
llvm/lib/Support/Host.cpp
Index: llvm/lib/Support/Host.cpp
===================================================================
--- llvm/lib/Support/Host.cpp
+++ llvm/lib/Support/Host.cpp
@@ -1952,10 +1952,44 @@
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(const Triple &triple) {
+#if defined(__arm__)
+ triple.setArch(Triple::arm);
+ triple.setArchName("arm");
+#elif defined(__arm64e__)
+ triple.setArch(Triple::aarch64, Triple::AArch64SubArch_arm64e);
+ triple.setArchName("arm64e");
+#elif defined(__aarch64__)
+ triple.setArch(Triple::aarch64);
+ triple.setArchName("arm64");
+#elif defined(__x86_64h__)
+ triple.setArch(Triple::x86_64);
+ triple.setArchName("x86_64h");
+#elif defined(__x86_64__)
+ triple.setArch(Triple::x86_64);
+ triple.setArchName("x86_64");
+#elif defined(__powerpc__)
+ triple.setArch(Triple::ppc);
+ triple.setArchName("powerpc");
+#else
+# error "Unimplemented host arch fixup"
+#endif
+ return triple;
+}
+#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())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138449.476936.patch
Type: text/x-patch
Size: 1557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221121/47a67a63/attachment.bin>
More information about the llvm-commits
mailing list