From 52b845be34a6b5cfa48f34bfbcddd83069d8c0c3 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Fri, 14 Jun 2013 11:36:56 +0200
Subject: [PATCH] Fixed bignum.c and bn_mul.h to support Thumb2 and LLVM
compiler
---
ChangeLog | 1 +
include/polarssl/bn_mul.h | 2 +-
library/bignum.c | 12 ++++++++++--
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a4e24d9d6..e9fdb11f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -24,6 +24,7 @@ Bugfix
instead of the x509parse_crt() wrapper that can also parse PEM
certificates
* x509parse_crtpath() is now reentrant and uses more portable stat()
+ * Fixed bignum.c and bn_mul.h to support Thumb2 and LLVM compiler
= Version 1.2.7 released 2013-04-13
Features
diff --git a/include/polarssl/bn_mul.h b/include/polarssl/bn_mul.h
index cffcd6bd4..1c2da136a 100644
--- a/include/polarssl/bn_mul.h
+++ b/include/polarssl/bn_mul.h
@@ -548,7 +548,7 @@
#if defined(__arm__)
-#if defined(__thumb__)
+#if defined(__thumb__) && !defined(__thumb2__)
#define MULADDC_INIT \
asm( \
diff --git a/library/bignum.c b/library/bignum.c
index d9845da5d..1422d5026 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -934,8 +934,16 @@ int mpi_sub_int( mpi *X, const mpi *A, t_sint b )
/*
* Helper for mpi multiplication
- */
-static void mpi_mul_hlp( size_t i, t_uint *s, t_uint *d, t_uint b )
+ */
+static
+#if defined(__APPLE__) && defined(__arm__)
+/*
+ * Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
+ * appears to need this to prevent bad ARM code generation at -O3.
+ */
+__attribute__ ((noinline))
+#endif
+void mpi_mul_hlp( size_t i, t_uint *s, t_uint *d, t_uint b )
{
t_uint c = 0, t = 0;