From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: Andre Muezerie <andremue@linux.microsoft.com>,
Nipun Gupta <nipun.gupta@amd.com>,
Nikhil Agarwal <nikhil.agarwal@amd.com>,
Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH v7 3/5] dev: export driver information with MSVC
Date: Wed, 11 Jun 2025 11:45:30 +0200 [thread overview]
Message-ID: <20250611094532.1242167-4-david.marchand@redhat.com> (raw)
In-Reply-To: <20250611094532.1242167-1-david.marchand@redhat.com>
From: Andre Muezerie <andremue@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 <andremue@linux.microsoft.com>
Signed-off-by: David Marchand <david.marchand@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
next prev parent reply other threads:[~2025-06-11 9:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 10:09 [PATCH v6 0/4] allow pmdinfo to be inserted and parsed using MSVC David Marchand
2025-06-10 10:09 ` [PATCH v6 1/4] dev: hide driver export macros David Marchand
2025-06-10 10:09 ` [PATCH v6 2/4] dev: export driver information with MSVC David Marchand
2025-06-10 12:13 ` David Marchand
2025-06-10 10:09 ` [PATCH v6 3/4] buildtools: embed " David Marchand
2025-06-10 10:09 ` [PATCH v6 4/4] usertools: enable pmdinfo " David Marchand
2025-06-10 10:17 ` Robin Jarry
2025-06-11 9:45 ` [PATCH v7 0/5] allow pmdinfo to be inserted and parsed using MSVC David Marchand
2025-06-11 9:45 ` [PATCH v7 1/5] dev: hide driver export macros David Marchand
2025-06-11 13:24 ` Andre Muezerie
2025-06-11 9:45 ` [PATCH v7 2/5] dev: rename pmdinfo internal symbols David Marchand
2025-06-11 13:26 ` Andre Muezerie
2025-06-11 9:45 ` David Marchand [this message]
2025-06-11 13:27 ` [PATCH v7 3/5] dev: export driver information with MSVC Andre Muezerie
2025-06-11 9:45 ` [PATCH v7 4/5] buildtools: embed " David Marchand
2025-06-11 13:28 ` Andre Muezerie
2025-06-11 9:45 ` [PATCH v7 5/5] usertools: enable pmdinfo " David Marchand
2025-06-12 13:23 ` [PATCH v7 0/5] allow pmdinfo to be inserted and parsed using MSVC David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250611094532.1242167-4-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=andremue@linux.microsoft.com \
--cc=dev@dpdk.org \
--cc=nikhil.agarwal@amd.com \
--cc=nipun.gupta@amd.com \
--cc=roretzla@linux.microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).