[PATCH 2/3] Use the alias attribute with GNU compiler only

Michael Haubenwallner michael.haubenwallner at ssi-schaefer.com
Thu Aug 22 14:55:43 UTC 2019


Simply provide real functions with compilers other than GCC.
---
 src/sha2.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/sha2.c b/src/sha2.c
index 8d70fad..3fddb0a 100644
--- a/src/sha2.c
+++ b/src/sha2.c
@@ -41,9 +41,23 @@
 #include <string.h>
 #include <sha2.h>
 
-#define __strong_alias(newsym, sym) \
+#ifdef __GNUC__
+
+#  define __strong_alias(newsym, sym, argsdecl, argspass) \
 	__typeof__ (sym) newsym __attribute__ ((alias (#sym)));
 
+#else /* !__GNUC__ */
+
+/*
+ * There is the undocumented MSVC linker flag "/alternatename" for some
+ * kind of weak aliasing, but that works for 32bit (x86) MSVC only.
+ * So for compilers other than GCC we just provide real functions.
+ */
+#  define __strong_alias(newsym, sym, argsdecl, argspass) \
+    void newsym argsdecl { sym argspass; }
+
+#endif /* !__GNUC__ */
+
 /*
  * UNROLLED TRANSFORM LOOP NOTE:
  * You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform
@@ -817,9 +831,9 @@ SHA384Init(SHA2_CTX *context)
 	context->bitcount[0] = context->bitcount[1] = 0;
 }
 
-__strong_alias(SHA384Transform, SHA512Transform)
-__strong_alias(SHA384Update, SHA512Update)
-__strong_alias(SHA384Pad, SHA512Pad)
+__strong_alias(SHA384Transform, SHA512Transform, (uint64_t state[8], const uint8_t data[SHA384_BLOCK_LENGTH]), (state, data))
+__strong_alias(SHA384Update, SHA512Update, (SHA2_CTX *context, const uint8_t *data, size_t len), (context, data, len))
+__strong_alias(SHA384Pad, SHA512Pad, (SHA2_CTX *context), (context))
 
 void
 SHA384Final(uint8_t digest[SHA384_DIGEST_LENGTH], SHA2_CTX *context)
-- 
2.21.0



More information about the libbsd mailing list