From 0149d937efbc8fcc34428d2232d4b366b2d97663 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Sat, 17 Jan 2015 21:31:47 +0100
Subject: [PATCH] Reorganize symbols for fat routines.

---
 ChangeLog                             | 10 ++++++++++
 asm.m4                                | 11 ++++++-----
 config.m4.in                          |  2 +-
 fat-x86_64.c                          | 11 +++++------
 x86_64/fat/aes-decrypt-internal-2.asm |  2 +-
 x86_64/fat/aes-decrypt-internal.asm   |  2 +-
 x86_64/fat/aes-encrypt-internal-2.asm |  2 +-
 x86_64/fat/aes-encrypt-internal.asm   |  2 +-
 x86_64/fat/memxor-2.asm               |  2 +-
 x86_64/fat/memxor.asm                 |  2 +-
 10 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 79540d5b..c5f0b563 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2015-01-17  Niels Möller  <nisse@lysator.liu.se>
 
+	* config.m4.in (SYMBOL_PREFIX): Define from from autoconf
+	ASM_SYMBOL_PREFIX.
+	(C_NAMS): move definition to...
+	* asm.m4 (C_NAME): Define here, also take fat_transform.
+	(fat_suffix): Replaced by...
+	(fat_transform): New macro, taking symbol nama as argument.
+	Updated all uses of fat_suffix.
+	* fat-x86_64.c: Updated for internal "_nettle" prefix on
+	cpu-specific memxor functions.
+
 	* fat-x86_64.c: Set up for sse2 vs non-sse2 memxor. Patch by Nikos
 	Mavrogiannopoulos.
 	* configure.ac (asm_nettle_optional_list): Added memxor-2.asm.
diff --git a/asm.m4 b/asm.m4
index dc59ab68..bbc90bd4 100644
--- a/asm.m4
+++ b/asm.m4
@@ -13,7 +13,8 @@ dnl Including files from the srcdir
 define(<include_src>, <include(srcdir/$1)>)dnl
 
 dnl default definition, changed in fat builds
-define(<fat_suffix>, <>)
+define(<fat_transform>, <$1>)
+define(<C_NAME>, <SYMBOL_PREFIX<>fat_transform($1)>)
 
 dnl Pseudo ops
 define(<DECLARE_FUNC>,
@@ -27,13 +28,13 @@ COFF_STYLE, yes,
 <>)>)
 
 define(<PROLOGUE>,
-<.globl C_NAME($1)<>fat_suffix
-DECLARE_FUNC(C_NAME($1)<>fat_suffix)
-C_NAME($1)<>fat_suffix:>)
+<.globl C_NAME($1)
+DECLARE_FUNC(C_NAME($1))
+C_NAME($1):>)
 
 define(<EPILOGUE>,
 <ifelse(ELF_STYLE,yes,
-<.size C_NAME($1)<>fat_suffix, . - C_NAME($1)<>fat_suffix>,<>)>)
+<.size C_NAME($1), . - C_NAME($1)>,<>)>)
 
 define(<m4_log2>, <m4_log2_internal($1,1,0)>)
 define(<m4_log2_internal>,
diff --git a/config.m4.in b/config.m4.in
index 3f7700bb..e39c880c 100644
--- a/config.m4.in
+++ b/config.m4.in
@@ -1,5 +1,5 @@
 define(<srcdir>, <<@srcdir@>>)dnl
-define(<C_NAME>, <@ASM_SYMBOL_PREFIX@><$1>)dnl
+define(<SYMBOL_PREFIX>, <@ASM_SYMBOL_PREFIX@><$1>)dnl
 define(<ELF_STYLE>, <@ASM_ELF_STYLE@>)dnl
 define(<COFF_STYLE>, <@ASM_COFF_STYLE@>)dnl
 define(<TYPE_FUNCTION>, <@ASM_TYPE_FUNCTION@>)dnl
diff --git a/fat-x86_64.c b/fat-x86_64.c
index b6c1f442..61d62239 100644
--- a/fat-x86_64.c
+++ b/fat-x86_64.c
@@ -105,10 +105,9 @@ aes_crypt_internal_func _nettle_aes_decrypt_aesni;
 
 typedef void *(memxor_func)(void *dst_in, const void *src_in, size_t n);
 
-/* FIXME: Fix fat name-mangling to get _nettle prefix. */
 memxor_func nettle_memxor IFUNC ("_memxor_resolve");
-memxor_func nettle_memxor_x86_64;
-memxor_func nettle_memxor_sse2;
+memxor_func _nettle_memxor_x86_64;
+memxor_func _nettle_memxor_sse2;
 
 #if HAVE_LINK_IFUNC
 #define _aes_encrypt_init NULL
@@ -120,7 +119,7 @@ static aes_crypt_internal_func _aes_decrypt_init;
 
 static aes_crypt_internal_func *_aes_encrypt_vec = _aes_encrypt_init;
 static aes_crypt_internal_func *_aes_decrypt_vec = _aes_decrypt_init;
-static memxor_func *_memxor_vec = nettle_memxor_x86_64;
+static memxor_func *_memxor_vec = _nettle_memxor_x86_64;
 
 /* This function should usually be called only once, at startup. But
    it is idempotent, and on x86, pointer updates are atomic, so
@@ -167,13 +166,13 @@ fat_init (void)
     {
       if (verbose)
 	fprintf (stderr, "libnettle: intel SSE2 will be used for XOR.\n");
-      _memxor_vec = nettle_memxor_sse2;
+      _memxor_vec = _nettle_memxor_sse2;
     }
   else
     {
       if (verbose)
 	fprintf (stderr, "libnettle: intel SSE2 will not be used for XOR.\n");
-      _memxor_vec = nettle_memxor_x86_64;
+      _memxor_vec = _nettle_memxor_x86_64;
     }
 
   /* The x86_64 architecture should always make stores visible in the
diff --git a/x86_64/fat/aes-decrypt-internal-2.asm b/x86_64/fat/aes-decrypt-internal-2.asm
index 16fb5598..2dd45959 100644
--- a/x86_64/fat/aes-decrypt-internal-2.asm
+++ b/x86_64/fat/aes-decrypt-internal-2.asm
@@ -31,5 +31,5 @@ ifelse(<
    not, see http://www.gnu.org/licenses/.
 >)
 
-define(<fat_suffix>, <_aesni>)
+define(<fat_transform>, <$1_aesni>)
 include_src(<x86_64/aesni/aes-decrypt-internal.asm>)
diff --git a/x86_64/fat/aes-decrypt-internal.asm b/x86_64/fat/aes-decrypt-internal.asm
index b05f6a1e..26738d66 100644
--- a/x86_64/fat/aes-decrypt-internal.asm
+++ b/x86_64/fat/aes-decrypt-internal.asm
@@ -31,5 +31,5 @@ ifelse(<
    not, see http://www.gnu.org/licenses/.
 >)
 
-define(<fat_suffix>, <_x86_64>)
+define(<fat_transform>, <$1_x86_64>)
 include_src(<x86_64/aes-decrypt-internal.asm>)
diff --git a/x86_64/fat/aes-encrypt-internal-2.asm b/x86_64/fat/aes-encrypt-internal-2.asm
index c173d0a5..2a5ce7b1 100644
--- a/x86_64/fat/aes-encrypt-internal-2.asm
+++ b/x86_64/fat/aes-encrypt-internal-2.asm
@@ -31,5 +31,5 @@ ifelse(<
    not, see http://www.gnu.org/licenses/.
 >)
 
-define(<fat_suffix>, <_aesni>)
+define(<fat_transform>, <$1_aesni>)
 include_src(<x86_64/aesni/aes-encrypt-internal.asm>)
diff --git a/x86_64/fat/aes-encrypt-internal.asm b/x86_64/fat/aes-encrypt-internal.asm
index 50a721ab..f0bdf59e 100644
--- a/x86_64/fat/aes-encrypt-internal.asm
+++ b/x86_64/fat/aes-encrypt-internal.asm
@@ -31,5 +31,5 @@ ifelse(<
    not, see http://www.gnu.org/licenses/.
 >)
 
-define(<fat_suffix>, <_x86_64>)
+define(<fat_transform>, <$1_x86_64>)
 include_src(<x86_64/aes-encrypt-internal.asm>)
diff --git a/x86_64/fat/memxor-2.asm b/x86_64/fat/memxor-2.asm
index ffc84440..e3bf9da8 100644
--- a/x86_64/fat/memxor-2.asm
+++ b/x86_64/fat/memxor-2.asm
@@ -31,6 +31,6 @@ ifelse(<
    not, see http://www.gnu.org/licenses/.
 >)
 
-define(<fat_suffix>, <_sse2>)
+define(<fat_transform>, <_$1_sse2>)
 define(<USE_SSE2>, <yes>)	
 include_src(<x86_64/memxor.asm>)
diff --git a/x86_64/fat/memxor.asm b/x86_64/fat/memxor.asm
index a040bb39..be33d273 100644
--- a/x86_64/fat/memxor.asm
+++ b/x86_64/fat/memxor.asm
@@ -31,5 +31,5 @@ ifelse(<
    not, see http://www.gnu.org/licenses/.
 >)
 
-define(<fat_suffix>, <_x86_64>)
+define(<fat_transform>, <_$1_x86_64>)
 include_src(<x86_64/memxor.asm>)
-- 
GitLab