[1/5] lib/eal: add portable macro for weak linking
Checks
Commit Message
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(-)
@@ -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.