From: Andre Muezerie <andre...@linux.microsoft.com>

DPDK uses GCC attribute "used" through macro __rte_used to indicate
that a variable not referenced in the code should be assumed being
used and therefore not be optimized away. This technique is used to embed
information in the binaries, by having crafted information stored in
them.

MSVC offers similar functionality, but it differs significantly: MSVC
requires a pragma to be used to send a command to the linker telling it
explicitly the name of the symbol that should be included (even if not
referenced). As a side-effect, variables called out to be included cannot
be static, otherwise their symbols are not "seen" by the linker. This
restriction requires some DPDK code to be refactored.

To assimilate these requirements/restrictions, a new macro
RTE_PMD_EXPORT_SYMBOL is added in this patch to ensure these special
variables make it to the final binaries.

Signed-off-by: Andre Muezerie <andre...@linux.microsoft.com>
Signed-off-by: David Marchand <david.march...@redhat.com>
---
 drivers/bus/cdx/bus_cdx_driver.h    |  3 +--
 lib/eal/common/eal_common_options.c |  2 +-
 lib/eal/include/dev_driver.h        | 19 ++++++++++++-------
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/bus/cdx/bus_cdx_driver.h b/drivers/bus/cdx/bus_cdx_driver.h
index 4febf1fd3b..f0780a84ad 100644
--- a/drivers/bus/cdx/bus_cdx_driver.h
+++ b/drivers/bus/cdx/bus_cdx_driver.h
@@ -35,8 +35,7 @@ struct rte_cdx_bus;
 #define RTE_CDX_ANY_ID (0xffff)
 
 #define RTE_PMD_REGISTER_CDX_TABLE(name, table) \
-static const char DRV_EXP_TAG(name, cdx_tbl_export)[] __rte_used = \
-RTE_STR(table)
+RTE_PMD_EXPORT_SYMBOL(const char, DRV_EXP_TAG(name, cdx_tbl_export))[] = 
RTE_STR(table)
 
 /** Device needs resource mapping */
 #define RTE_CDX_DRV_NEED_MAPPING 0x0001
diff --git a/lib/eal/common/eal_common_options.c 
b/lib/eal/common/eal_common_options.c
index b4f0e23a9c..83b6fc7e89 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -137,7 +137,7 @@ static const char *default_solib_dir = RTE_EAL_PMD_PATH;
  * Note: PLEASE DO NOT ALTER THIS without making a corresponding
  * change to usertools/dpdk-pmdinfo.py
  */
-static const char dpdk_solib_path[] __rte_used =
+RTE_PMD_EXPORT_SYMBOL(const char, dpdk_solib_path)[] =
 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
 
 TAILQ_HEAD(device_option_list, device_option);
diff --git a/lib/eal/include/dev_driver.h b/lib/eal/include/dev_driver.h
index 7766038b1b..a2517ac1d4 100644
--- a/lib/eal/include/dev_driver.h
+++ b/lib/eal/include/dev_driver.h
@@ -30,18 +30,24 @@ struct rte_device {
        struct rte_devargs *devargs;  /**< Arguments for latest probing */
 };
 
+#ifdef RTE_TOOLCHAIN_MSVC
+#define RTE_PMD_EXPORT_SYMBOL(type, name) \
+__pragma(comment(linker, "/include:" RTE_STR(name))) type name
+#else
+#define RTE_PMD_EXPORT_SYMBOL(type, name) \
+__attribute__((used)) type name
+#endif
+
 #define RTE_PMD_EXPORT_NAME(name) \
-static const char this_pmd_name ## name __rte_used = RTE_STR(name)
+RTE_PMD_EXPORT_SYMBOL(const char, this_pmd_name ## name)[] = RTE_STR(name)
 
 #define DRV_EXP_TAG(name, tag) __##name##_##tag
 
 #define RTE_PMD_REGISTER_PCI_TABLE(name, table) \
-static const char DRV_EXP_TAG(name, pci_tbl_export)[] __rte_used = \
-RTE_STR(table)
+RTE_PMD_EXPORT_SYMBOL(const char, DRV_EXP_TAG(name, pci_tbl_export))[] = 
RTE_STR(table)
 
 #define RTE_PMD_REGISTER_PARAM_STRING(name, str) \
-static const char DRV_EXP_TAG(name, param_string_export)[] \
-__rte_used = str
+RTE_PMD_EXPORT_SYMBOL(const char, DRV_EXP_TAG(name, param_string_export))[] = 
str
 
 /**
  * Advertise the list of kernel modules required to run this driver
@@ -65,7 +71,6 @@ __rte_used = str
  * - "* igb_uio | uio_pci_generic | vfio"
  */
 #define RTE_PMD_REGISTER_KMOD_DEP(name, str) \
-static const char DRV_EXP_TAG(name, kmod_dep_export)[] \
-__rte_used = str
+RTE_PMD_EXPORT_SYMBOL(const char, DRV_EXP_TAG(name, kmod_dep_export))[] = str
 
 #endif /* DEV_DRIVER_H */
-- 
2.49.0

Reply via email to