Commit 6b3f9f75d8f79a93792dedb5e3541a228d38fa62

Guillem Jover 2021-01-02T16:26:38

build: Provide wrapper functions instead of aliases in DLL built with MSVC On Windows we cannot use proper aliases, and using the /EXPORT linker flag is too cumbersome, as it does not work when static linking, and when dynamic linking it does not make the aliases visible within the DLL itself. Just use normal function wrapper in those cases, which are way more maintainable.

diff --git a/src/local-link.h b/src/local-link.h
index 8a0c6c4..7560c4f 100644
--- a/src/local-link.h
+++ b/src/local-link.h
@@ -31,8 +31,18 @@
 	static const char libmd_emit_link_warning_##symbol[] \
 		__attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg;
 
+/*
+ * On Windows we cannot use proper aliases, and using the /EXPORT linker flag
+ * is too cumbersome, as it does not work when static linking, and when
+ * dynamic linking it does not make the aliases visible within the DLL itself.
+ *
+ * Instead we use normal function wrapper in those cases, which are way more
+ * maintainable.
+ */
+#ifndef _MSC_VER
 #define libmd_alias(alias, symbol) \
 	extern __typeof(symbol) alias __attribute__((__alias__(#symbol)))
+#endif
 
 #ifdef __ELF__
 #define libmd_symver_default(alias, symbol, version) \
diff --git a/src/sha2.c b/src/sha2.c
index 8ba2d63..dbb6100 100644
--- a/src/sha2.c
+++ b/src/sha2.c
@@ -815,9 +815,29 @@ SHA384Init(SHA2_CTX *context)
 	context->bitcount[0] = context->bitcount[1] = 0;
 }
 
+#ifdef libmd_alias
 libmd_alias(SHA384Transform, SHA512Transform);
 libmd_alias(SHA384Update, SHA512Update);
 libmd_alias(SHA384Pad, SHA512Pad);
+#else
+void
+SHA384Transform(uint64_t state[8], const uint8_t data[SHA512_BLOCK_LENGTH])
+{
+	SHA512Transform(state, data);
+}
+
+void
+SHA384Update(SHA2_CTX *context, const uint8_t *data, size_t len)
+{
+	SHA512Update(context, data, len);
+}
+
+void
+SHA384Pad(SHA2_CTX *context)
+{
+	SHA512Pad(context);
+}
+#endif
 
 void
 SHA384Final(uint8_t digest[SHA384_DIGEST_LENGTH], SHA2_CTX *context)