From 5ba1d4e119c1a9bce214219e60cd33bb79900b4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Tue, 31 Mar 2015 22:08:39 +0200
Subject: [PATCH] Exclude asm files which fail when building on w64 using
 mini-gmp.

---
 ChangeLog               | 10 ++++++++++
 asm.m4                  |  2 ++
 configure.ac            |  7 +++++++
 x86_64/ecc-224-modp.asm |  2 ++
 x86_64/ecc-521-modp.asm |  2 ++
 5 files changed, 23 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 9b416ecc..058691eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,17 @@
 2015-03-31  Niels Möller  <nisse@diamant.hack.org>
 
+	* x86_64/ecc-224-modp.asm: Require that GMP_NUMB_BITS == 64.
+	* x86_64/ecc-521-modp.asm: Likewise. Note that the other
+	ecc-*-modp.asm files happen to work fine on x86_64, with either 32
+	or 64 bits.
+
+	* asm.m4 (GMP_NUMB_BITS): New macro, expanding to nothing.
+
 	* configure.ac: Move tests for compiler characteristics,
 	libraries, and GMP_NUMB_BITS, before assembler-related tests.
+	For files in $asm_hogweed_optional_list, check if they declare
+	a GMP_NUMB_BITS requirement, and skip files which are incompatible
+	with the configuration. Needed for --enable-mini-gmp om w64.
 
 	* Makefile.in (clean-here): Unconditionally delete *.a (including
 	stub libraries like *.dll.a).
diff --git a/asm.m4 b/asm.m4
index bbc90bd4..4018c235 100644
--- a/asm.m4
+++ b/asm.m4
@@ -27,6 +27,8 @@ COFF_STYLE, yes,
 .endef>,
 <>)>)
 
+define(<GMP_NUMB_BITS>,<>)dnl
+
 define(<PROLOGUE>,
 <.globl C_NAME($1)
 DECLARE_FUNC(C_NAME($1))
diff --git a/configure.ac b/configure.ac
index 30071f9f..5a16151d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -464,6 +464,13 @@ EOF
       tmp_b=`echo "$tmp_h" | sed 's/\.[[^.]]*$//'`
       for asm_dir in $asm_path ; do
 	if test -f "$srcdir/$asm_dir/$tmp_h"; then
+	  dnl Note double square brackets, for extra m4 quoting.
+	  tmp_bits=`grep GMP_NUMB_BITS "$srcdir/$asm_dir/$tmp_h" \
+            | sed 's/^.*GMP_NUMB_BITS(\([[0-9]]*\)).*$/\1/'`
+	  if test "$tmp_bits" && test "$tmp_bits" != '${GMP_NUMB_BITS}' ; then
+	     AC_MSG_WARN([skipping $tmp_h, because GMP_NUMB_BITS != $tmp_bits])
+	     continue
+	  fi
 	  asm_file_list="$asm_file_list $tmp_h"
 	  AC_CONFIG_LINKS($tmp_h:$asm_dir/$tmp_h)
 	  while read tmp_func ; do
diff --git a/x86_64/ecc-224-modp.asm b/x86_64/ecc-224-modp.asm
index 282859c6..07bd4003 100644
--- a/x86_64/ecc-224-modp.asm
+++ b/x86_64/ecc-224-modp.asm
@@ -32,6 +32,8 @@ ifelse(<
 
 	.file "ecc-224-modp.asm"
 
+GMP_NUMB_BITS(64)
+
 define(<RP>, <%rsi>)
 define(<T0>, <%rdi>) C Overlaps unused modulo input
 define(<T1>, <%rcx>)
diff --git a/x86_64/ecc-521-modp.asm b/x86_64/ecc-521-modp.asm
index 69dc1f06..6e818ad8 100644
--- a/x86_64/ecc-521-modp.asm
+++ b/x86_64/ecc-521-modp.asm
@@ -32,6 +32,8 @@ ifelse(<
 
 	.file "ecc-521-modp.asm"
 
+GMP_NUMB_BITS(64)
+
 define(<RP>, <%rsi>)
 define(<U0>, <%rax>)
 define(<U1>, <%rbx>)
-- 
GitLab