Skip to contentSkip to conversation

build: use native Linux strlcpy when available

PATCH New Bruce Richardson 2 participants 8 messages Jun 24 – Sep 16 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build: use native Linux strlcpy when available

Glibc added the strlcpy and strlcat functions to version 2.38, meaning they are natively available in modern linux distros without having to use libbsd, or a dpdk-specific fallback. Therefore, we adjust our fallback detection logic to have meson check for the presence of these functions before checking if we actually need libbsd. Then in rte_string_fns.h we rework our macros a little for setting the fallback:

1. If libbsd is to be used, just always include it as a standalone block. With new meson logic, we only use it if we have to, even if present.
2. For BSD, configure fallback functions only if __BSD_VISIBLE is not defined, otherwise just use native fns.
3. Otherwise for Linux and Windows, configure the fallback functions if meson has not set RTE_HAS_STRLCPY.

---
 config/meson.build               | 14 ++++++++++----
 lib/eal/include/rte_string_fns.h | 18 +++++++-----------
 2 files changed, 17 insertions(+), 15 deletions(-)
config/meson.build +10 -4
index d7f5e55c18..0049cd3807 100644
@@ -266,10 +266,16 @@ if libarchive.found()
     dpdk_conf.set('RTE_HAS_LIBARCHIVE', 1)
 endif
 
-# check for libbsd
-libbsd = dependency('libbsd', required: false, method: 'pkg-config')
-if libbsd.found()
-    dpdk_conf.set('RTE_USE_LIBBSD', 1)
+# check for strlcpy: first in native libc, then via libbsd as fallback
+if cc.has_function('strlcpy', prefix: '#include <string.h>')
+    dpdk_conf.set('RTE_HAS_STRLCPY', 1)
+    libbsd = dependency('', required: false)  # empty not-found dependency
+else
+    libbsd = dependency('libbsd', required: false, method: 'pkg-config')
+    if libbsd.found()
+        dpdk_conf.set('RTE_USE_LIBBSD', 1)
+        dpdk_conf.set('RTE_HAS_STRLCPY', 1)
+    endif
 endif
 
 jansson_dep = dependency('jansson', required: false, method: 'pkg-config')
lib/eal/include/rte_string_fns.h +7 -11
index 3713c94acb..4fb2a6c1ce 100644
@@ -14,6 +14,9 @@
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
+#ifdef RTE_USE_LIBBSD
+#include <bsd/string.h>
+#endif
 
 #include <rte_common.h>
 #include <rte_compat.h>
@@ -81,23 +84,16 @@ rte_strlcat(char *dst, const char *src, size_t size)
 }
 #endif
 
-/* pull in a strlcpy function */
+/* provide strlcpy/strlcat aliases where not natively available */
 #ifdef RTE_EXEC_ENV_FREEBSD
 #ifndef __BSD_VISIBLE /* non-standard functions are hidden */
 #define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
 #define strlcat(dst, src, size) rte_strlcat(dst, src, size)
-#endif
-
-#else /* non-BSD platforms */
-#ifdef RTE_USE_LIBBSD
-#include <bsd/string.h>
-
-#else /* no BSD header files, create own */
+#endif /* __BSD_VISIBLE */
+#elif !defined(RTE_HAS_STRLCPY)
 #define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
 #define strlcat(dst, src, size) rte_strlcat(dst, src, size)
-
-#endif /* RTE_USE_LIBBSD */
-#endif /* FREEBSD */
+#endif /* RTE_EXEC_ENV_FREEBSD */
 
 #ifdef __cplusplus
 extern "C" {
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/1 build: drop dependency on libbsd

Glibc added the strlcpy and strlcat functions to version 2.38, released in 2023, meaning they are natively available in modern linux distros. At this point, the value of having the libbsd provided versions of these functions is reduced, so let's simplify the code options here by providing just two options for strlcpy rather than three:

1. native implementation for BSD and recent Linux
2. DPDK-specific fallbacks using snprintf

Since the strlcpy and strlcat functions are the only two items used from libbsd, we can then drop completely any DPDK dependency on libbsd.

---
V2:
* took the work further than v1, dropping libbsd dependency entirely. Now DPDK just supports native strlcpy or it's own fallback version.

---
 app/test/test_string_fns.c        |  4 ++--
 buildtools/pkg-config/meson.build |  3 +--
 config/meson.build                |  7 +++----
 lib/eal/include/rte_string_fns.h  | 21 +++++----------------
 lib/eal/meson.build               |  4 +---
 lib/telemetry/telemetry.c         |  2 --
 lib/telemetry/telemetry_data.c    |  1 -
 lib/telemetry/telemetry_legacy.c  |  2 --
 8 files changed, 12 insertions(+), 32 deletions(-)
app/test/test_string_fns.c +2 -2
index 697cb7ed15..213a9312ea 100644
@@ -134,7 +134,7 @@ static int
 test_rte_strlcat(void)
 {
 	/* only run actual unit tests if we have system-provided strlcat */
-#if defined(__BSD_VISIBLE) || defined(RTE_USE_LIBBSD)
+#ifdef RTE_HAS_STRLCPY
 #define BUF_LEN 32
 	const char dst[BUF_LEN] = "Test string";
 	const char src[] = " appended";
@@ -168,7 +168,7 @@ test_rte_strlcat(void)
 	}
 	LOG("Checked %zu combinations\n", i);
 #undef BUF_LEN
-#endif /* defined(__BSD_VISIBLE) || defined(RTE_USE_LIBBSD) */
+#endif /* RTE_HAS_STRLCPY */
 
 	return 0;
 }
buildtools/pkg-config/meson.build +1 -2
index b36add17e3..a0a265ad92 100644
@@ -47,8 +47,7 @@ pkg.generate(name: 'DPDK', # main DPDK pkgconfig file
         description: '''The Data Plane Development Kit (DPDK).
 Note that CFLAGS might contain an -march flag higher than typical baseline.
 This is required for a number of static inline functions in the public headers.''',
-        requires: ['libdpdk-libs', libbsd], # may need libbsd for string funcs
-                      # if libbsd is not enabled, then this is blank
+        requires: ['libdpdk-libs'],
         libraries_private: ['-Wl,--whole-archive'] +
             dpdk_drivers + dpdk_static_libraries +
             ['-Wl,--no-whole-archive'] + platform_flags
config/meson.build +3 -4
index d7f5e55c18..237e747eec 100644
@@ -266,10 +266,9 @@ if libarchive.found()
     dpdk_conf.set('RTE_HAS_LIBARCHIVE', 1)
 endif
 
-# check for libbsd
-libbsd = dependency('libbsd', required: false, method: 'pkg-config')
-if libbsd.found()
-    dpdk_conf.set('RTE_USE_LIBBSD', 1)
+# check for strlcpy/strlcat in native libc, otherwise use DPDK fallback
+if cc.has_function('strlcpy', prefix: '#include <string.h>')
+    dpdk_conf.set('RTE_HAS_STRLCPY', 1)
 endif
 
 jansson_dep = dependency('jansson', required: false, method: 'pkg-config')
lib/eal/include/rte_string_fns.h +5 -16
index 3713c94acb..4b2323fc34 100644
@@ -55,7 +55,7 @@ rte_strsplit(char *string, int stringlen,
 /**
  * @internal
  * DPDK-specific version of strlcpy for systems without
- * libc or libbsd copies of the function
+ * a native libc copy of the function
  */
 static inline size_t
 rte_strlcpy(char *dst, const char *src, size_t size)
@@ -66,7 +66,7 @@ rte_strlcpy(char *dst, const char *src, size_t size)
 /**
  * @internal
  * DPDK-specific version of strlcat for systems without
- * libc or libbsd copies of the function
+ * a native libc copy of the function
  */
 static inline size_t
 rte_strlcat(char *dst, const char *src, size_t size)
@@ -81,24 +81,13 @@ rte_strlcat(char *dst, const char *src, size_t size)
 }
 #endif
 
-/* pull in a strlcpy function */
-#ifdef RTE_EXEC_ENV_FREEBSD
-#ifndef __BSD_VISIBLE /* non-standard functions are hidden */
+/* provide strlcpy/strlcat aliases where not natively available */
+#if !defined(RTE_HAS_STRLCPY) || \
+	(defined(RTE_EXEC_ENV_FREEBSD) && !defined(__BSD_VISIBLE))
 #define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
 #define strlcat(dst, src, size) rte_strlcat(dst, src, size)
 #endif
 
-#else /* non-BSD platforms */
-#ifdef RTE_USE_LIBBSD
-#include <bsd/string.h>
-
-#else /* no BSD header files, create own */
-#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
-#define strlcat(dst, src, size) rte_strlcat(dst, src, size)
-
-#endif /* RTE_USE_LIBBSD */
-#endif /* FREEBSD */
-
 #ifdef __cplusplus
 extern "C" {
 #endif
lib/eal/meson.build +1 -3
index f9fcee24ee..092f5c5261 100644
@@ -18,9 +18,7 @@ deps += ['argparse', 'kvargs']
 if not is_windows
     deps += ['telemetry']
 endif
-if dpdk_conf.has('RTE_USE_LIBBSD')
-    ext_deps += libbsd
-endif
+
 if dpdk_conf.has('RTE_HAS_LIBARCHIVE')
     ext_deps += libarchive
 endif
lib/telemetry/telemetry.c +0 -2
index e591c1e283..f863445798 100644
@@ -13,8 +13,6 @@
 #include <sys/stat.h>
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 
-/* we won't link against libbsd, so just always use DPDKs-specific strlcpy */
-#undef RTE_USE_LIBBSD
 #include <eal_export.h>
 #include <rte_string_fns.h>
 #include <rte_common.h>
lib/telemetry/telemetry_data.c +0 -1
index 0a006559ab..08bdc4ea36 100644
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 #include <inttypes.h>
 
-#undef RTE_USE_LIBBSD
 #include <stdbool.h>
 
 #include <eal_export.h>
lib/telemetry/telemetry_legacy.c +0 -2
index 1d73282ba8..af497a594a 100644
@@ -10,8 +10,6 @@
 #include <pthread.h>
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 
-/* we won't link against libbsd, so just always use DPDKs-specific strlcpy */
-#undef RTE_USE_LIBBSD
 #include <eal_export.h>
 #include <rte_string_fns.h>
 #include <rte_common.h>
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v2] build: drop dependency on libbsd

Quoted 13 lines · Bruce Richardson

Glibc added the strlcpy and strlcat functions to version 2.38, released in 2023, meaning they are natively available in modern linux distros. At this point, the value of having the libbsd provided versions of these functions is reduced, so let's simplify the code options here by providing just two options for strlcpy rather than three:

1. native implementation for BSD and recent Linux
2. DPDK-specific fallbacks using snprintf

Since the strlcpy and strlcat functions are the only two items used from libbsd, we can then drop completely any DPDK dependency on libbsd.

Quoted 6 lines

---
V2:
* took the work further than v1, dropping libbsd dependency entirely. Now DPDK just supports native strlcpy or it's own fallback version.

We still have some references:

$ git grep -i libbsd
.github/workflows/build.yml:        libbsd-dev \
.github/workflows/build.yml:        libbsd-devel \
devtools/process-iwyu.py:def uses_libbsd(builddir):
devtools/process-iwyu.py:    "return whether the build uses libbsd or not"
devtools/process-iwyu.py:    return bool(get_build_config(builddir,
lambda ln: 'RTE_USE_LIBBSD' in ln))
devtools/process-iwyu.py:    keep_str_fns = uses_libbsd(build_dir)  #
check for libbsd
devtools/process-iwyu.py:        print("Warning: libbsd is present,
build will fail to detect incorrect removal of rte_string_fns.h",
doc/guides/howto/af_xdp_dp.rst:          libbsd-devel \
Signature · 1 line
David Marchand
#3 lore raw

Re: [PATCH v2] build: drop dependency on libbsd

Quoted 24 lines · David Marchand
Quoted 13 lines · Bruce Richardson

Glibc added the strlcpy and strlcat functions to version 2.38, released in 2023, meaning they are natively available in modern linux distros. At this point, the value of having the libbsd provided versions of these functions is reduced, so let's simplify the code options here by providing just two options for strlcpy rather than three:

1. native implementation for BSD and recent Linux
2. DPDK-specific fallbacks using snprintf

Since the strlcpy and strlcat functions are the only two items used from libbsd, we can then drop completely any DPDK dependency on libbsd.

Quoted 6 lines

---
V2:
* took the work further than v1, dropping libbsd dependency entirely. Now DPDK just supports native strlcpy or it's own fallback version.

We still have some references:

Quoted 13 lines
$ git grep -i libbsd
.github/workflows/build.yml:        libbsd-dev \
.github/workflows/build.yml:        libbsd-devel \
devtools/process-iwyu.py:def uses_libbsd(builddir):
devtools/process-iwyu.py:    "return whether the build uses libbsd or not"
devtools/process-iwyu.py:    return bool(get_build_config(builddir,
lambda ln: 'RTE_USE_LIBBSD' in ln))
devtools/process-iwyu.py:    keep_str_fns = uses_libbsd(build_dir)  #
check for libbsd
devtools/process-iwyu.py:        print("Warning: libbsd is present,
build will fail to detect incorrect removal of rte_string_fns.h",
doc/guides/howto/af_xdp_dp.rst:          libbsd-devel \

Sure, will respin and try and clean these up a bit. I assume from the detailed feedback that there is no issue with the high-level approach here?

/Bruce

#4 lore raw

Re: [PATCH v2] build: drop dependency on libbsd

Quoted 40 lines · Bruce Richardson
Quoted 24 lines · David Marchand
Quoted 13 lines · Bruce Richardson

Glibc added the strlcpy and strlcat functions to version 2.38, released in 2023, meaning they are natively available in modern linux distros. At this point, the value of having the libbsd provided versions of these functions is reduced, so let's simplify the code options here by providing just two options for strlcpy rather than three:

1. native implementation for BSD and recent Linux
2. DPDK-specific fallbacks using snprintf

Since the strlcpy and strlcat functions are the only two items used from libbsd, we can then drop completely any DPDK dependency on libbsd.

Quoted 6 lines

---
V2:
* took the work further than v1, dropping libbsd dependency entirely. Now DPDK just supports native strlcpy or it's own fallback version.

We still have some references:

Quoted 13 lines
$ git grep -i libbsd
.github/workflows/build.yml:        libbsd-dev \
.github/workflows/build.yml:        libbsd-devel \
devtools/process-iwyu.py:def uses_libbsd(builddir):
devtools/process-iwyu.py:    "return whether the build uses libbsd or not"
devtools/process-iwyu.py:    return bool(get_build_config(builddir,
lambda ln: 'RTE_USE_LIBBSD' in ln))
devtools/process-iwyu.py:    keep_str_fns = uses_libbsd(build_dir)  #
check for libbsd
devtools/process-iwyu.py:        print("Warning: libbsd is present,
build will fail to detect incorrect removal of rte_string_fns.h",
doc/guides/howto/af_xdp_dp.rst:          libbsd-devel \
Quoted 2 lines

Sure, will respin and try and clean these up a bit. I assume from the detailed feedback that there is no issue with the high-level approach here?

Consumers of dpdk may have been relying on the libbsd dependency (and RTE_USE_LIBBSD config...) but I think we should proceed with this removal.

https://xkcd.com/1172/

Signature · 1 line
David Marchand
#5 lore raw

PATCH v3 1/1 build: drop dependency on libbsd

In reply to Bruce Richardson

Glibc added the strlcpy and strlcat functions to version 2.38, released in 2023, meaning they are natively available in modern linux distros. At this point, the value of having the libbsd provided versions of these functions is reduced, so let's simplify the code options here by providing just two options for strlcpy rather than three:

1. native implementation for BSD and recent Linux
2. DPDK-specific fallbacks using snprintf

Since the strlcpy and strlcat functions are the only two items used from libbsd, we can then drop completely any DPDK dependency on libbsd.

---
v3:
* removed additional references to libbsd in scripts and docs
* corrected detection of strlcpy by adding _GNU_SOURCE to detection check, which matches DPDK build.
* added extra macro check in fallback header, to handle case where strlcpy is available for DPDK build, but not for app builds, e.g. where strict c11 compliance is required.

v2:
* Took the work further than v1, dropping libbsd dependency entirely. Now DPDK just supports native strlcpy or it's own fallback version.

---
 .github/workflows/build.yml       |  2 --
 app/test/test_string_fns.c        |  4 ++--
 buildtools/pkg-config/meson.build |  3 +--
 config/meson.build                |  7 +++----
 devtools/process-iwyu.py          | 10 +++++-----
 doc/guides/howto/af_xdp_dp.rst    |  1 -
 lib/eal/include/rte_string_fns.h  | 22 ++++++----------------
 lib/eal/meson.build               |  4 +---
 lib/telemetry/telemetry.c         |  2 --
 lib/telemetry/telemetry_data.c    |  1 -
 lib/telemetry/telemetry_legacy.c  |  2 --
 11 files changed, 18 insertions(+), 40 deletions(-)
.github/workflows/build.yml +0 -2
index f0ef39d34f..a2a88ecb10 100644
@@ -58,7 +58,6 @@ jobs:
       build_deps: |
         ccache \
         libarchive-dev \
-        libbsd-dev \
         libbpf-dev \
         libfdt-dev \
         libibverbs-dev \
@@ -254,7 +253,6 @@ jobs:
         jansson-devel \
         libarchive-devel \
         libatomic \
-        libbsd-devel \
         libbpf-devel \
         libfdt-devel \
         libpcap-devel \
app/test/test_string_fns.c +2 -2
index 697cb7ed15..213a9312ea 100644
@@ -134,7 +134,7 @@ static int
 test_rte_strlcat(void)
 {
 	/* only run actual unit tests if we have system-provided strlcat */
-#if defined(__BSD_VISIBLE) || defined(RTE_USE_LIBBSD)
+#ifdef RTE_HAS_STRLCPY
 #define BUF_LEN 32
 	const char dst[BUF_LEN] = "Test string";
 	const char src[] = " appended";
@@ -168,7 +168,7 @@ test_rte_strlcat(void)
 	}
 	LOG("Checked %zu combinations\n", i);
 #undef BUF_LEN
-#endif /* defined(__BSD_VISIBLE) || defined(RTE_USE_LIBBSD) */
+#endif /* RTE_HAS_STRLCPY */
 
 	return 0;
 }
buildtools/pkg-config/meson.build +1 -2
index b36add17e3..a0a265ad92 100644
@@ -47,8 +47,7 @@ pkg.generate(name: 'DPDK', # main DPDK pkgconfig file
         description: '''The Data Plane Development Kit (DPDK).
 Note that CFLAGS might contain an -march flag higher than typical baseline.
 This is required for a number of static inline functions in the public headers.''',
-        requires: ['libdpdk-libs', libbsd], # may need libbsd for string funcs
-                      # if libbsd is not enabled, then this is blank
+        requires: ['libdpdk-libs'],
         libraries_private: ['-Wl,--whole-archive'] +
             dpdk_drivers + dpdk_static_libraries +
             ['-Wl,--no-whole-archive'] + platform_flags
config/meson.build +3 -4
index d7f5e55c18..344f68822b 100644
@@ -266,10 +266,9 @@ if libarchive.found()
     dpdk_conf.set('RTE_HAS_LIBARCHIVE', 1)
 endif
 
-# check for libbsd
-libbsd = dependency('libbsd', required: false, method: 'pkg-config')
-if libbsd.found()
-    dpdk_conf.set('RTE_USE_LIBBSD', 1)
+# check for strlcpy/strlcat in native libc, otherwise use DPDK fallback
+if cc.has_function('strlcpy', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
+    dpdk_conf.set('RTE_HAS_STRLCPY', 1)
 endif
 
 jansson_dep = dependency('jansson', required: false, method: 'pkg-config')
devtools/process-iwyu.py +5 -5
index 08a63b962b..0f9fc5837d 100755
@@ -60,9 +60,9 @@ def get_build_config(builddir, condition):
         return [ln for ln in f.readlines() if condition(ln)]
 
 
-def uses_libbsd(builddir):
-    "return whether the build uses libbsd or not"
-    return bool(get_build_config(builddir, lambda ln: 'RTE_USE_LIBBSD' in ln))
+def uses_native_strlcpy(builddir):
+    "return whether the build uses fallback strlcpy or libc native one"
+    return bool(get_build_config(builddir, lambda ln: 'RTE_HAS_STRLCPY' in ln))
 
 
 def process(args):
@@ -74,9 +74,9 @@ def process(args):
     print("Warning: The results of this script may include false positives which are required for different systems",
           file=sys.stderr)
 
-    keep_str_fns = uses_libbsd(build_dir)  # check for libbsd
+    keep_str_fns = uses_native_strlcpy(build_dir)  # check for strlcpy fallback in use
     if keep_str_fns:
-        print("Warning: libbsd is present, build will fail to detect incorrect removal of rte_string_fns.h",
+        print("Warning: strlcpy is present, build will fail to detect incorrect removal of rte_string_fns.h",
               file=sys.stderr)
     # turn on werror
     run_meson(['configure', build_dir, '-Dwerror=true'])
doc/guides/howto/af_xdp_dp.rst +0 -1
index b3681af2f7..e565b9b08d 100644
@@ -147,7 +147,6 @@ Build a DPDK container image (using Docker)
 
       # Setup container to build DPDK applications
       RUN dnf -y upgrade && dnf -y install \
-          libbsd-devel \
           numactl-libs \
           libbpf-devel \
           libbpf \
lib/eal/include/rte_string_fns.h +6 -16
index 3713c94acb..b3b5bdf275 100644
@@ -55,7 +55,7 @@ rte_strsplit(char *string, int stringlen,
 /**
  * @internal
  * DPDK-specific version of strlcpy for systems without
- * libc or libbsd copies of the function
+ * a native libc copy of the function
  */
 static inline size_t
 rte_strlcpy(char *dst, const char *src, size_t size)
@@ -66,7 +66,7 @@ rte_strlcpy(char *dst, const char *src, size_t size)
 /**
  * @internal
  * DPDK-specific version of strlcat for systems without
- * libc or libbsd copies of the function
+ * a native libc copy of the function
  */
 static inline size_t
 rte_strlcat(char *dst, const char *src, size_t size)
@@ -81,24 +81,14 @@ rte_strlcat(char *dst, const char *src, size_t size)
 }
 #endif
 
-/* pull in a strlcpy function */
-#ifdef RTE_EXEC_ENV_FREEBSD
-#ifndef __BSD_VISIBLE /* non-standard functions are hidden */
+/* provide strlcpy/strlcat aliases where not natively available */
+#if !defined(RTE_HAS_STRLCPY) || \
+	(defined(RTE_EXEC_ENV_FREEBSD) && !defined(__BSD_VISIBLE)) || \
+	(defined(__GLIBC__) && !defined(__USE_MISC))
 #define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
 #define strlcat(dst, src, size) rte_strlcat(dst, src, size)
 #endif
 
-#else /* non-BSD platforms */
-#ifdef RTE_USE_LIBBSD
-#include <bsd/string.h>
-
-#else /* no BSD header files, create own */
-#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
-#define strlcat(dst, src, size) rte_strlcat(dst, src, size)
-
-#endif /* RTE_USE_LIBBSD */
-#endif /* FREEBSD */
-
 #ifdef __cplusplus
 extern "C" {
 #endif
lib/eal/meson.build +1 -3
index f9fcee24ee..092f5c5261 100644
@@ -18,9 +18,7 @@ deps += ['argparse', 'kvargs']
 if not is_windows
     deps += ['telemetry']
 endif
-if dpdk_conf.has('RTE_USE_LIBBSD')
-    ext_deps += libbsd
-endif
+
 if dpdk_conf.has('RTE_HAS_LIBARCHIVE')
     ext_deps += libarchive
 endif
lib/telemetry/telemetry.c +0 -2
index e591c1e283..f863445798 100644
@@ -13,8 +13,6 @@
 #include <sys/stat.h>
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 
-/* we won't link against libbsd, so just always use DPDKs-specific strlcpy */
-#undef RTE_USE_LIBBSD
 #include <eal_export.h>
 #include <rte_string_fns.h>
 #include <rte_common.h>
lib/telemetry/telemetry_data.c +0 -1
index 0a006559ab..08bdc4ea36 100644
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 #include <inttypes.h>
 
-#undef RTE_USE_LIBBSD
 #include <stdbool.h>
 
 #include <eal_export.h>
lib/telemetry/telemetry_legacy.c +0 -2
index 1d73282ba8..af497a594a 100644
@@ -10,8 +10,6 @@
 #include <pthread.h>
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 
-/* we won't link against libbsd, so just always use DPDKs-specific strlcpy */
-#undef RTE_USE_LIBBSD
 #include <eal_export.h>
 #include <rte_string_fns.h>
 #include <rte_common.h>
Signature · 1 line
2.53.0
#6 lore raw

Re: [PATCH v3] build: drop dependency on libbsd

Quoted 25 lines · Bruce Richardson

Glibc added the strlcpy and strlcat functions to version 2.38, released in 2023, meaning they are natively available in modern linux distros. At this point, the value of having the libbsd provided versions of these functions is reduced, so let's simplify the code options here by providing just two options for strlcpy rather than three:

1. native implementation for BSD and recent Linux
2. DPDK-specific fallbacks using snprintf

Since the strlcpy and strlcat functions are the only two items used from libbsd, we can then drop completely any DPDK dependency on libbsd.

---
v3:
* removed additional references to libbsd in scripts and docs
* corrected detection of strlcpy by adding _GNU_SOURCE to detection check, which matches DPDK build.
* added extra macro check in fallback header, to handle case where strlcpy is available for DPDK build, but not for app builds, e.g. where strict c11 compliance is required.

v2:
* Took the work further than v1, dropping libbsd dependency entirely. Now DPDK just supports native strlcpy or it's own fallback version.

Quoted 14 lines
---
 .github/workflows/build.yml       |  2 --
 app/test/test_string_fns.c        |  4 ++--
 buildtools/pkg-config/meson.build |  3 +--
 config/meson.build                |  7 +++----
 devtools/process-iwyu.py          | 10 +++++-----
 doc/guides/howto/af_xdp_dp.rst    |  1 -
 lib/eal/include/rte_string_fns.h  | 22 ++++++----------------
 lib/eal/meson.build               |  4 +---
 lib/telemetry/telemetry.c         |  2 --
 lib/telemetry/telemetry_data.c    |  1 -
 lib/telemetry/telemetry_legacy.c  |  2 --
 11 files changed, 18 insertions(+), 40 deletions(-)

Ping for review or comments on this change!

Acked-by on v3 1/1 Applied
#7 lore raw

Re: [PATCH v3] build: drop dependency on libbsd

In reply to Bruce Richardson
Quoted 7 lines · Bruce Richardson

Glibc added the strlcpy and strlcat functions to version 2.38, released in 2023, meaning they are natively available in modern linux distros. At this point, the value of having the libbsd provided versions of these functions is reduced, so let's simplify the code options here by providing just two options for strlcpy rather than three:

Quoted 7 lines

1. native implementation for BSD and recent Linux
2. DPDK-specific fallbacks using snprintf

Since the strlcpy and strlcat functions are the only two items used from libbsd, we can then drop completely any DPDK dependency on libbsd.

I removed one last reference in doc.

Applied, thanks Bruce.

Signature · 1 line
David Marchand