[1/5] lib/eal: add portable macro for weak linking

Message ID 1735009552-31906-2-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Rejected
Delegated to: David Marchand
Headers
Series use portable macro for weak linking |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andre Muezerie Dec. 24, 2024, 3:05 a.m. UTC
MSVC uses pragmas to indicate weak linking, so the old __rte_weak
attribute needs to made into a macro so that the same syntax can
be used for MSVC and other compilers like gcc.

This patch adds macro RTE_WEAK and deprecates __rte_weak.

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

Patch

diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index 4d299f2b36..904b3ba5ec 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -137,10 +137,22 @@  typedef uint16_t unaligned_uint16_t;
 #define RTE_DEPRECATED(x)
 #endif
 
+/**
+ * @deprecated
+ * @see RTE_WEAK
+ */
+#define __rte_weak (RTE_DEPRECATED(__rte_weak) __attribute__((__weak__)))
+
 /**
  * Mark a function or variable to a weak reference.
  */
-#define __rte_weak __attribute__((__weak__))
+#ifdef RTE_TOOLCHAIN_MSVC
+#define RTE_WEAK(FUNC_NAME) \
+	(__pragma(comment(linker, "/alternatename:" #FUNC_NAME "=rte_weak_" \
+	#FUNC_NAME)) rte_weak_ ## FUNC_NAME)
+#else
+#define RTE_WEAK(FUNC_NAME) (__attribute__((__weak__)) FUNC_NAME)
+#endif
 
 /**
  * Mark a function to be pure.