aarch64 support.
This is an initial cut at aarch64 support. I have only qemu to test it
however—hopefully hardware will be coming soon.
This also affects 32-bit ARM in that aarch64 chips can run 32-bit code
and we would like to be able to take advantage of the crypto operations
even in 32-bit mode. AES and GHASH should Just Work in this case: the
-armx.pl files can be built for either 32- or 64-bit mode based on the
flavour argument given to the Perl script.
SHA-1 and SHA-256 don't work like this however because they've never
support for multiple implementations, thus BoringSSL built for 32-bit
won't use the SHA instructions on an aarch64 chip.
No dedicated ChaCha20 or Poly1305 support yet.
Change-Id: Ib275bc4894a365c8ec7c42f4e91af6dba3bd686c
Reviewed-on: https://boringssl-review.googlesource.com/2801
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/crypto.c b/crypto/crypto.c
index ee7c405..c463d5e 100644
--- a/crypto/crypto.c
+++ b/crypto/crypto.c
@@ -16,10 +16,12 @@
#include "internal.h"
+
#if !defined(OPENSSL_NO_ASM) && \
- (defined(OPENSSL_X86) || defined(OPENSSL_X86_64))
-/* x86 and x86_64 need to record the result of a cpuid call for the asm to work
- * correctly, unless compiled without asm code. */
+ (defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \
+ defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
+/* x86, x86_64 and the ARMs need to record the result of a cpuid call for the
+ * asm to work correctly, unless compiled without asm code. */
#define NEED_CPUID
#else
@@ -30,7 +32,39 @@
#define BORINGSSL_NO_STATIC_INITIALIZER
#endif
-#endif /* !OPENSSL_NO_ASM && (OPENSSL_X86 || OPENSSL_X86_64) */
+#endif /* !OPENSSL_NO_ASM && (OPENSSL_X86 || OPENSSL_X86_64 ||
+ OPENSSL_ARM || OPENSSL_AARCH64) */
+
+
+/* The capability variables are defined in this file in order to work around a
+ * linker bug. When linking with a .a, if no symbols in a .o are referenced
+ * then the .o is discarded, even if it has constructor functions.
+ *
+ * This still means that any binaries that don't include some functionality
+ * that tests the capability values will still skip the constructor but, so
+ * far, the init constructor function only sets the capability variables. */
+
+#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
+/* This value must be explicitly initialised to zero in order to work around a
+ * bug in libtool or the linker on OS X.
+ *
+ * If not initialised then it becomes a "common symbol". When put into an
+ * archive, linking on OS X will fail to resolve common symbols. By
+ * initialising it to zero, it becomes a "data symbol", which isn't so
+ * affected. */
+uint32_t OPENSSL_ia32cap_P[4] = {0};
+#elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
+
+#include "arm_arch.h"
+
+#if defined(__ARM_NEON__)
+uint32_t OPENSSL_armcap_P = ARMV7_NEON | ARMV7_NEON_FUNCTIONAL;
+#else
+uint32_t OPENSSL_armcap_P = ARMV7_NEON_FUNCTIONAL;
+#endif
+
+#endif
+
#if defined(OPENSSL_WINDOWS)
#define OPENSSL_CDECL __cdecl
@@ -53,6 +87,8 @@
* BORINGSSL_NO_STATIC_INITIALIZER isn't defined, this is set as a static
* initializer. Otherwise, it is called by CRYPTO_library_init. */
static void OPENSSL_CDECL do_library_init(void) {
+ /* WARNING: this function may only configure the capability variables. See the
+ * note above about the linker bug. */
#if defined(NEED_CPUID)
OPENSSL_cpuid_setup();
#endif