Skip to contentSkip to conversation

RFC fix import/export MSVC data variables

PATCH In review Tyler Retzlaff 2 participants 5 messages Mar 12, 2024 – Oct 7, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover RFC fix import/export MSVC data variables

MSVC requires that data variables within DPDK to be explicitly exported and when consumed by applications be explicitly imported. Further, MSVC and the Microsoft Linker need additional information when exporting data variables that are thread local storage that cannot be conveyed through the version.map -> exports.def generation. The generation script has been updated to allow data exports to be excluded during a build with MSVC where the intent is to export them via the macros.

This RFC series proposes per-library macro that can be used to mark the data variables for export so that when processed appropriate declaration of import or export is achieved either within the dpdk build or by a consuming application.

I have only supplied an example series that uses the macro on a handful of variables to demonstrate their use, after feedback on the RFC all libs will have whatever method is arrived at applied to exported data variables.

Thanks!

Tyler Retzlaff (3):
buildtools: ignore exports for MSVC
eal: import and export data variables for MSVC
ethdev: import and export data variables for MSVC

 buildtools/map_to_win.py         | 13 +++++++++----
 lib/eal/include/meson.build      |  1 +
 lib/eal/include/rte_common.h     |  8 ++++++++
 lib/eal/include/rte_eal.h        |  2 ++
 lib/eal/include/rte_eal_export.h | 23 +++++++++++++++++++++++
 lib/eal/include/rte_errno.h      |  2 ++
 lib/eal/version.map              |  6 +++---
 lib/ethdev/meson.build           |  1 +
 lib/ethdev/rte_ethdev_core.h     |  3 +++
 lib/ethdev/rte_ethdev_export.h   | 23 +++++++++++++++++++++++
 lib/ethdev/version.map           |  2 +-
 lib/meson.build                  |  6 ++++--
 12 files changed, 80 insertions(+), 10 deletions(-)
 create mode 100644 lib/eal/include/rte_eal_export.h
 create mode 100644 lib/ethdev/rte_ethdev_export.h
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/3 buildtools: ignore exports for MSVC

Update map_to_def to allow exports to be ignored only when building with MSVC. Some data variables need to be exported within code (not via .def) file depending on their type so allow them to be ignored in the .map file.

---
 buildtools/map_to_win.py | 13 +++++++++----
 lib/meson.build          |  4 ++--
 2 files changed, 11 insertions(+), 6 deletions(-)
buildtools/map_to_win.py +9 -4
index aa1752c..2d547f8 100644
@@ -4,9 +4,11 @@
 
 import sys
 
+def is_function_line(ln, cc):
+    if not ln.startswith('\t') or ":" in ln or ";" not in ln:
+        return False
 
-def is_function_line(ln):
-    return ln.startswith('\t') and ln.endswith(';\n') and ":" not in ln and "# WINDOWS_NO_EXPORT" not in ln
+    return not (cc == 'msvc' and "# MSVC_NO_EXPORT" in ln or "# WINDOWS_NO_EXPORT" in ln)
 
 # MinGW keeps the original .map file but replaces per_lcore* to __emutls_v.per_lcore*
 def create_mingw_map_file(input_map, output_map):
@@ -27,9 +29,12 @@ def main(args):
 # This works taking indented lines only which end with a ";" and which don't
 # have a colon in them, i.e. the lines defining functions only.
     else:
+        cc = 'notmsvc'
+        if len(args) == 4:
+            cc = args[3]
         with open(args[1]) as f_in:
-            functions = [ln[:-2] + '\n' for ln in sorted(f_in.readlines())
-                         if is_function_line(ln)]
+            functions = [ln.split(';', 1)[0] + '\n' for ln in sorted(f_in.readlines())
+                          if is_function_line(ln, cc)]
             functions = ["EXPORTS\n"] + functions
 
     with open(args[2], 'w') as f_out:
lib/meson.build +2 -2
index 179a272..f8836a4 100644
@@ -262,7 +262,7 @@ foreach l:libraries
 
     if is_ms_linker
         def_file = custom_target(libname + '_def',
-                command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
+                command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@', cc.get_id()],
                 input: version_map,
                 output: '@0@_exports.def'.format(libname))
         lk_deps += [def_file]
@@ -281,7 +281,7 @@ foreach l:libraries
     else
         if is_windows
             mingw_map = custom_target(libname + '_mingw',
-                    command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
+                    command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@', cc.get_id()],
                     input: version_map,
                     output: '@0@_mingw.map'.format(libname))
             lk_deps += [mingw_map]
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/3 eal: import and export data variables for MSVC

In reply to Tyler Retzlaff

MSVC requires that data variables be explicitly declared as either imported or exported. Provide macros that allow dpdk to correctly declare data variables as exported for itself and imported for applications.

Use new per-library macro to declare variables exported or imported for per-lcore data variables.

---
 lib/eal/include/meson.build      |  1 +
 lib/eal/include/rte_common.h     |  8 ++++++++
 lib/eal/include/rte_eal.h        |  2 ++
 lib/eal/include/rte_eal_export.h | 23 +++++++++++++++++++++++
 lib/eal/include/rte_errno.h      |  2 ++
 lib/eal/version.map              |  6 +++---
 lib/meson.build                  |  2 ++
 7 files changed, 41 insertions(+), 3 deletions(-)
 create mode 100644 lib/eal/include/rte_eal_export.h
lib/eal/include/meson.build +1 -0
index e94b056..376ae81 100644
@@ -16,6 +16,7 @@ headers += files(
         'rte_dev.h',
         'rte_devargs.h',
         'rte_eal.h',
+        'rte_eal_export.h',
         'rte_eal_memconfig.h',
         'rte_eal_trace.h',
         'rte_errno.h',
lib/eal/include/rte_common.h +8 -0
index 298a5c6..ad80122 100644
@@ -26,6 +26,14 @@
 /* OS specific include */
 #include <rte_os.h>
 
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_declare_import __declspec(dllimport)
+#define __rte_declare_export __declspec(dllexport)
+#else
+#define __rte_declare_import
+#define __rte_declare_export
+#endif
+
 #ifndef RTE_TOOLCHAIN_MSVC
 #ifndef typeof
 #define typeof __typeof__
lib/eal/include/rte_eal.h +2 -0
index c2256f8..d0dc91b 100644
@@ -16,6 +16,7 @@
 
 #include <rte_config.h>
 #include <rte_compat.h>
+#include <rte_eal_export.h>
 #include <rte_per_lcore.h>
 #include <rte_uuid.h>
 
@@ -426,6 +427,7 @@ typedef int (*rte_mp_async_reply_t)(const struct rte_mp_msg *request,
  */
 int rte_sys_gettid(void);
 
+__rte_eal_export
 RTE_DECLARE_PER_LCORE(int, _thread_id);
 
 /**
lib/eal/include/rte_eal_export.h new file +23 -0
new file mode 100644
index 0000000..3901760
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 Microsoft Corporation
+ */
+
+#ifndef _RTE_EAL_EXPORT_H_
+#define _RTE_EAL_EXPORT_H_
+
+/**
+ * @file
+ *
+ * Import / Export macros for eal data variables.
+ */
+
+#include <rte_common.h>
+
+#ifndef __rte_eal_export
+#define __rte_eal_export __rte_declare_import
+#else
+#undef __rte_eal_export
+#define __rte_eal_export __rte_declare_export
+#endif
+
+#endif
lib/eal/include/rte_errno.h +2 -0
index ba45591..311732f 100644
@@ -15,8 +15,10 @@
 extern "C" {
 #endif
 
+#include <rte_eal_export.h>
 #include <rte_per_lcore.h>
 
+__rte_eal_export
 RTE_DECLARE_PER_LCORE(int, _rte_errno); /**< Per core error number. */
 
 /**
lib/eal/version.map +3 -3
index c06ceaa..62914d2 100644
@@ -4,9 +4,9 @@ DPDK_24 {
 	__rte_panic;
 	eal_parse_sysfs_value; # WINDOWS_NO_EXPORT
 	eal_timer_source; # WINDOWS_NO_EXPORT
-	per_lcore__lcore_id;
-	per_lcore__rte_errno;
-	per_lcore__thread_id;
+	per_lcore__lcore_id; # MSVC_NO_EXPORT
+	per_lcore__rte_errno; # MSVC_NO_EXPORT
+	per_lcore__thread_id; # MSVC_NO_EXPORT
 	rte_bus_dump;
 	rte_bus_find;
 	rte_bus_find_by_device;
lib/meson.build +2 -0
index f8836a4..f8d88d2 100644
@@ -235,6 +235,8 @@ foreach l:libraries
         cflags += '-Wthread-safety'
     endif
 
+    cflags += '-D__rte_@0@_export'.format(name)
+
     # first build static lib
     static_lib = static_library(libname,
             sources,
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/3 ethdev: import and export data variables for MSVC

In reply to Tyler Retzlaff

MSVC requires that data variables be explicitly declared as either imported or exported. Provide macros that allow dpdk to correctly declare data variables as exported for itself and imported for applications.

Use new per-library macro to declare variables exported or imported for per-lcore data variables.

---
 lib/ethdev/meson.build         |  1 +
 lib/ethdev/rte_ethdev_core.h   |  3 +++
 lib/ethdev/rte_ethdev_export.h | 23 +++++++++++++++++++++++
 lib/ethdev/version.map         |  2 +-
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 lib/ethdev/rte_ethdev_export.h
lib/ethdev/meson.build +1 -0
index f1d2586..b270e02 100644
@@ -23,6 +23,7 @@ sources = files(
 headers = files(
         'rte_cman.h',
         'rte_ethdev.h',
+        'rte_ethdev_export.h',
         'rte_ethdev_trace_fp.h',
         'rte_dev_info.h',
         'rte_flow.h',
lib/ethdev/rte_ethdev_core.h +3 -0
index e55fb42..4e7939f 100644
@@ -16,6 +16,8 @@
  * Applications should not use these directly.
  */
 
+#include <rte_ethdev_export.h>
+
 struct rte_eth_dev_callback;
 /** @internal Structure to keep track of registered callbacks */
 RTE_TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback);
@@ -126,6 +128,7 @@ struct __rte_cache_aligned rte_eth_fp_ops {
 
 };
 
+__rte_ethdev_export
 extern struct rte_eth_fp_ops rte_eth_fp_ops[RTE_MAX_ETHPORTS];
 
 #endif /* _RTE_ETHDEV_CORE_H_ */
lib/ethdev/rte_ethdev_export.h new file +23 -0
new file mode 100644
index 0000000..7887bee
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 Microsoft Corporation
+ */
+
+#ifndef _RTE_ETHDEV_EXPORT_H_
+#define _RTE_ETHDEV_EXPORT_H_
+
+/**
+ * @file
+ *
+ * Import / Export macros for ethdev data variables.
+ */
+
+#include <rte_common.h>
+
+#ifndef __rte_ethdev_export
+#define __rte_ethdev_export __rte_declare_import
+#else
+#undef __rte_ethdev_export
+#define __rte_ethdev_export __rte_declare_export
+#endif
+
+#endif
lib/ethdev/version.map +1 -1
index 79f6f52..efe426f 100644
@@ -83,7 +83,7 @@ DPDK_24 {
 	rte_eth_find_next_of;
 	rte_eth_find_next_owned_by;
 	rte_eth_find_next_sibling;
-	rte_eth_fp_ops;
+	rte_eth_fp_ops; # MSVC_NO_EXPORT
 	rte_eth_iterator_cleanup;
 	rte_eth_iterator_init;
 	rte_eth_iterator_next;
Signature · 1 line
1.8.3.1
#4 lore raw

Re: [PATCH 3/3] ethdev: import and export data variables for MSVC

Quoted 19 lines · On Tue, 12 Mar 2024 00:51:48 -0700 Tyler Retzlaff…
lib/ethdev/rte_ethdev_export.h new file +13 -0
new file mode 100644
index 0000000..7887bee
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 Microsoft Corporation
+ */
+
+#ifndef _RTE_ETHDEV_EXPORT_H_
+#define _RTE_ETHDEV_EXPORT_H_
+
+/**
+ * @file
+ *
+ * Import / Export macros for ethdev data variables.
+ */
+

lib/ethdev/rte_ethdev_export.h line 23

Quoted 10 lines
lib/ethdev/rte_ethdev_export.h new file +10 -0
+#include <rte_common.h>
+
+#ifndef __rte_ethdev_export
+#define __rte_ethdev_export __rte_declare_import
+#else
+#undef __rte_ethdev_export
+#define __rte_ethdev_export __rte_declare_export
+#endif
+
+#endif

Why not put this in rte_ethdev_core.h rather than a new file??

Patch needs to be resubmitted anyway because it fails github build from missing C++ guards.