[v3,3/6] eal: update versioning macros

Message ID 1740083508-6703-4-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Changes Requested
Delegated to: David Marchand
Headers
Series mbuf: enable to be compiled with MSVC |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andre Muezerie Feb. 20, 2025, 8:31 p.m. UTC
When compiling with MSVC the error below shows up due to function
versioning:

../lib/net/rte_net_crc.c(418): error C2061: syntax error:
    identifier '__attribute__'

MSVC allows alias function names to be exported, but the mechanism is
different than the one used by gcc. It was considered to enhance the logic
in the existing version.map files but that file is also passed to other
tools on Linux, making this challenging. A simpler approach is to have an
optional version.map file to be used only when Microsoft's linker is to be
used. This optional map file is only necessary for libraries that have
versioned code.

Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
 lib/eal/include/rte_function_versioning.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
  

Patch

diff --git a/lib/eal/include/rte_function_versioning.h b/lib/eal/include/rte_function_versioning.h
index eb6dd2bc17..aa3165a659 100644
--- a/lib/eal/include/rte_function_versioning.h
+++ b/lib/eal/include/rte_function_versioning.h
@@ -82,6 +82,13 @@ 
  */
 #define MAP_STATIC_SYMBOL(f, p)
 
+/*
+ * MAP_STATIC_BASE_SYMBOL
+ * Has the same purpose as MAP_STATIC_SYMBOL, but takes a base function name
+ * instead of the whole function prototype. It is used to support MSVC.
+ */
+#define MAP_STATIC_BASE_SYMBOL(b, p)
+
 #else
 /*
  * No symbol versioning in use
@@ -90,7 +97,19 @@ 
 #define VERSION_SYMBOL_EXPERIMENTAL(b, e)
 #define __vsym
 #define BIND_DEFAULT_SYMBOL(b, e, n)
+
+#ifdef RTE_TOOLCHAIN_MSVC
+#define MAP_STATIC_SYMBOL(f, p)
+#define MAP_STATIC_BASE_SYMBOL(b, p) __pragma(comment(linker, "/alternatename:" #b "=" #p))
+/*
+ * version.map file should also be updated with "b=p;", like
+ *     rte_net_crc_set_alg=rte_net_crc_set_alg_v26;
+ */
+#else
 #define MAP_STATIC_SYMBOL(f, p) f __attribute__((alias(RTE_STR(p))))
+#define MAP_STATIC_BASE_SYMBOL(b, p)
+#endif
+
 /*
  * RTE_BUILD_SHARED_LIB=n
  */