[PATCH] D82428: [clang][driver] allow `-arch arm64` to be used to build for mac when on Apple Silicon Mac without explicit `-target`
Alex Lorenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 23 19:27:04 PDT 2020
arphaman created this revision.
arphaman added reviewers: steven_wu, dexonsmith.
Herald added subscribers: llvm-commits, danielkiss, ributzka, jkorous, kristof.beyls, mgorny.
Herald added a project: LLVM.
steven_wu accepted this revision.
steven_wu added a comment.
This revision is now accepted and ready to land.
LGTM.
Not sure if it makes more sense to break the patch into two commits:
- config.guess change is for building the correct host triple on apple silicon machine without explicitly specify it.
- the driver change is for better default on Apple silicon Mac.
This patch allows a user to compile for the `arm64-apple-macos` target when invoking a clang running on an Apple Silicon machine by passing `-arch arm64` only.
https://reviews.llvm.org/D82428
Files:
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/apple-arm64-arch.c
clang/test/Driver/apple-silicon-arch.c
clang/test/lit.cfg.py
llvm/cmake/config.guess
Index: llvm/cmake/config.guess
===================================================================
--- llvm/cmake/config.guess
+++ llvm/cmake/config.guess
@@ -1263,6 +1263,23 @@
UNAME_PROCESSOR="x86_64"
fi
fi ;;
+ arm)
+ eval $set_cc_for_build
+ if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+ if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
+ (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+ grep IS_64BIT_ARCH >/dev/null
+ then
+ if (echo '#ifdef __PTRAUTH_INTRINSICS__'; echo HAS_AUTH; echo '#endif') | \
+ (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+ grep HAS_AUTH >/dev/null
+ then
+ UNAME_PROCESSOR="arm64e"
+ else
+ UNAME_PROCESSOR="arm64"
+ fi
+ fi
+ fi ;;
unknown) UNAME_PROCESSOR=powerpc ;;
esac
echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
Index: clang/test/lit.cfg.py
===================================================================
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -155,6 +155,10 @@
if not re.match(r'.*-(cygwin)$', config.target_triple):
config.available_features.add('clang-driver')
+# Tests that are specific to the Apple Silicon macOS.
+if re.match(r'^arm64(e)?-apple-(macos|darwin)', config.target_triple):
+ config.available_features.add('apple-silicon-mac')
+
# [PR18856] Depends to remove opened file. On win32, a file could be removed
# only if all handles were closed.
if platform.system() not in ['Windows']:
Index: clang/test/Driver/apple-silicon-arch.c
===================================================================
--- /dev/null
+++ clang/test/Driver/apple-silicon-arch.c
@@ -0,0 +1,6 @@
+// RUN: env SDKROOT="/" %clang -arch arm64 -c -### %s 2>&1 | \
+// RUN: FileCheck %s
+//
+// REQUIRES: apple-silicon-mac
+//
+// CHECK: "-triple" "arm64-apple-macosx{{[0-9.]+}}"
Index: clang/test/Driver/apple-arm64-arch.c
===================================================================
--- /dev/null
+++ clang/test/Driver/apple-arm64-arch.c
@@ -0,0 +1,6 @@
+// RUN: env SDKROOT="/" %clang -arch arm64 -c -### %s 2>&1 | \
+// RUN: FileCheck %s
+//
+// XFAIL: apple-silicon-mac
+//
+// CHECK: "-triple" "arm64-apple-ios{{[0-9.]+}}"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1672,8 +1672,16 @@
llvm::Triple::OSType OSTy = llvm::Triple::UnknownOS;
StringRef MachOArchName = Toolchain.getMachOArchName(Args);
- if (MachOArchName == "armv7" || MachOArchName == "armv7s" ||
- MachOArchName == "arm64")
+ if (MachOArchName == "arm64") {
+#if __arm64__
+ // A clang running on an Apple Silicon mac defaults
+ // to building for mac when building for arm64 rather than
+ // defaulting to iOS.
+ OSTy = llvm::Triple::MacOSX;
+#else
+ OSTy = llvm::Triple::IOS;
+#endif
+ } else if (MachOArchName == "armv7" || MachOArchName == "armv7s")
OSTy = llvm::Triple::IOS;
else if (MachOArchName == "armv7k" || MachOArchName == "arm64_32")
OSTy = llvm::Triple::WatchOS;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82428.272891.patch
Type: text/x-patch
Size: 3126 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200624/17623f8d/attachment-0001.bin>
More information about the cfe-commits
mailing list