Commit bd364c6d81dac38ec42f6fe5ae2e5296a56e12de

Guillem Jover 2019-08-28T11:30:29

Switch SHA2 symbols from weak to strong aliases There is no good reason to have these as weak symbols at all. And it makes building on Windows (Cygwin, MinGW) harder as it does not support weak symbols. Based-on-patch-by: Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com> Signed-off-by: Guillem Jover <guillem@hadrons.org>

diff --git a/src/local-link.h b/src/local-link.h
index 7f84f9e..8a0c6c4 100644
--- a/src/local-link.h
+++ b/src/local-link.h
@@ -31,6 +31,9 @@
 	static const char libmd_emit_link_warning_##symbol[] \
 		__attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg;
 
+#define libmd_alias(alias, symbol) \
+	extern __typeof(symbol) alias __attribute__((__alias__(#symbol)))
+
 #ifdef __ELF__
 #define libmd_symver_default(alias, symbol, version) \
 	__asm__(".symver " #symbol "," #alias "@@" #version)
diff --git a/src/sha2.c b/src/sha2.c
index 849ebbb..8ba2d63 100644
--- a/src/sha2.c
+++ b/src/sha2.c
@@ -35,18 +35,13 @@
  */
 
 #include <config.h>
+#include "local-link.h"
 
 #include <sys/types.h>
 
 #include <string.h>
 #include <sha2.h>
 
-#define _C_LABEL_STRING(x)	x
-
-#define	__weak_alias(alias,sym)						\
-	__asm(".weak " _C_LABEL_STRING(#alias) "\n"			\
-		_C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
-
 /*
  * UNROLLED TRANSFORM LOOP NOTE:
  * You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform
@@ -820,9 +815,9 @@ SHA384Init(SHA2_CTX *context)
 	context->bitcount[0] = context->bitcount[1] = 0;
 }
 
-__weak_alias(SHA384Transform, SHA512Transform);
-__weak_alias(SHA384Update, SHA512Update);
-__weak_alias(SHA384Pad, SHA512Pad);
+libmd_alias(SHA384Transform, SHA512Transform);
+libmd_alias(SHA384Update, SHA512Update);
+libmd_alias(SHA384Pad, SHA512Pad);
 
 void
 SHA384Final(uint8_t digest[SHA384_DIGEST_LENGTH], SHA2_CTX *context)