DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] build: use native Linux strlcpy when available
@ 2026-06-24 11:35 Bruce Richardson
  2026-06-25 13:08 ` [PATCH v2] build: drop dependency on libbsd Bruce Richardson
  2026-06-29 14:29 ` [PATCH v3] " Bruce Richardson
  0 siblings, 2 replies; 6+ messages in thread
From: Bruce Richardson @ 2026-06-24 11:35 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson

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.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 config/meson.build               | 14 ++++++++++----
 lib/eal/include/rte_string_fns.h | 18 +++++++-----------
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/config/meson.build b/config/meson.build
index d7f5e55c18..0049cd3807 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -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')
diff --git a/lib/eal/include/rte_string_fns.h b/lib/eal/include/rte_string_fns.h
index 3713c94acb..4fb2a6c1ce 100644
--- a/lib/eal/include/rte_string_fns.h
+++ b/lib/eal/include/rte_string_fns.h
@@ -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" {
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2] build: drop dependency on libbsd
  2026-06-24 11:35 [PATCH] build: use native Linux strlcpy when available Bruce Richardson
@ 2026-06-25 13:08 ` Bruce Richardson
  2026-06-29 11:30   ` David Marchand
  2026-06-29 14:29 ` [PATCH v3] " Bruce Richardson
  1 sibling, 1 reply; 6+ messages in thread
From: Bruce Richardson @ 2026-06-25 13:08 UTC (permalink / raw)
  To: dev; +Cc: 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.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

---
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(-)

diff --git a/app/test/test_string_fns.c b/app/test/test_string_fns.c
index 697cb7ed15..213a9312ea 100644
--- a/app/test/test_string_fns.c
+++ b/app/test/test_string_fns.c
@@ -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;
 }
diff --git a/buildtools/pkg-config/meson.build b/buildtools/pkg-config/meson.build
index b36add17e3..a0a265ad92 100644
--- a/buildtools/pkg-config/meson.build
+++ b/buildtools/pkg-config/meson.build
@@ -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
diff --git a/config/meson.build b/config/meson.build
index d7f5e55c18..237e747eec 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -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')
diff --git a/lib/eal/include/rte_string_fns.h b/lib/eal/include/rte_string_fns.h
index 3713c94acb..4b2323fc34 100644
--- a/lib/eal/include/rte_string_fns.h
+++ b/lib/eal/include/rte_string_fns.h
@@ -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
diff --git a/lib/eal/meson.build b/lib/eal/meson.build
index f9fcee24ee..092f5c5261 100644
--- a/lib/eal/meson.build
+++ b/lib/eal/meson.build
@@ -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
diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index e591c1e283..f863445798 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -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>
diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c
index 0a006559ab..08bdc4ea36 100644
--- a/lib/telemetry/telemetry_data.c
+++ b/lib/telemetry/telemetry_data.c
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 #include <inttypes.h>
 
-#undef RTE_USE_LIBBSD
 #include <stdbool.h>
 
 #include <eal_export.h>
diff --git a/lib/telemetry/telemetry_legacy.c b/lib/telemetry/telemetry_legacy.c
index 1d73282ba8..af497a594a 100644
--- a/lib/telemetry/telemetry_legacy.c
+++ b/lib/telemetry/telemetry_legacy.c
@@ -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>
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] build: drop dependency on libbsd
  2026-06-25 13:08 ` [PATCH v2] build: drop dependency on libbsd Bruce Richardson
@ 2026-06-29 11:30   ` David Marchand
  2026-06-29 11:52     ` Bruce Richardson
  0 siblings, 1 reply; 6+ messages in thread
From: David Marchand @ 2026-06-29 11:30 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

On Thu, 25 Jun 2026 at 15:08, Bruce Richardson
<bruce.richardson@intel.com> wrote:
>
> 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.
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
>
> ---
> 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 \


-- 
David Marchand


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] build: drop dependency on libbsd
  2026-06-29 11:30   ` David Marchand
@ 2026-06-29 11:52     ` Bruce Richardson
  2026-06-29 11:55       ` David Marchand
  0 siblings, 1 reply; 6+ messages in thread
From: Bruce Richardson @ 2026-06-29 11:52 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On Mon, Jun 29, 2026 at 01:30:32PM +0200, David Marchand wrote:
> On Thu, 25 Jun 2026 at 15:08, Bruce Richardson
> <bruce.richardson@intel.com> wrote:
> >
> > 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.
> >
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> >
> > ---
> > 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 \
> 

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] build: drop dependency on libbsd
  2026-06-29 11:52     ` Bruce Richardson
@ 2026-06-29 11:55       ` David Marchand
  0 siblings, 0 replies; 6+ messages in thread
From: David Marchand @ 2026-06-29 11:55 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev, Thomas Monjalon, Stephen Hemminger

On Mon, 29 Jun 2026 at 13:52, Bruce Richardson
<bruce.richardson@intel.com> wrote:
>
> On Mon, Jun 29, 2026 at 01:30:32PM +0200, David Marchand wrote:
> > On Thu, 25 Jun 2026 at 15:08, Bruce Richardson
> > <bruce.richardson@intel.com> wrote:
> > >
> > > 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.
> > >
> > > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> > >
> > > ---
> > > 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 \
> >
>
> 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/


-- 
David Marchand


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3] build: drop dependency on libbsd
  2026-06-24 11:35 [PATCH] build: use native Linux strlcpy when available Bruce Richardson
  2026-06-25 13:08 ` [PATCH v2] build: drop dependency on libbsd Bruce Richardson
@ 2026-06-29 14:29 ` Bruce Richardson
  1 sibling, 0 replies; 6+ messages in thread
From: Bruce Richardson @ 2026-06-29 14:29 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, 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.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
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(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index f0ef39d34f..a2a88ecb10 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -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 \
diff --git a/app/test/test_string_fns.c b/app/test/test_string_fns.c
index 697cb7ed15..213a9312ea 100644
--- a/app/test/test_string_fns.c
+++ b/app/test/test_string_fns.c
@@ -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;
 }
diff --git a/buildtools/pkg-config/meson.build b/buildtools/pkg-config/meson.build
index b36add17e3..a0a265ad92 100644
--- a/buildtools/pkg-config/meson.build
+++ b/buildtools/pkg-config/meson.build
@@ -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
diff --git a/config/meson.build b/config/meson.build
index d7f5e55c18..344f68822b 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -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')
diff --git a/devtools/process-iwyu.py b/devtools/process-iwyu.py
index 08a63b962b..0f9fc5837d 100755
--- a/devtools/process-iwyu.py
+++ b/devtools/process-iwyu.py
@@ -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'])
diff --git a/doc/guides/howto/af_xdp_dp.rst b/doc/guides/howto/af_xdp_dp.rst
index b3681af2f7..e565b9b08d 100644
--- a/doc/guides/howto/af_xdp_dp.rst
+++ b/doc/guides/howto/af_xdp_dp.rst
@@ -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 \
diff --git a/lib/eal/include/rte_string_fns.h b/lib/eal/include/rte_string_fns.h
index 3713c94acb..b3b5bdf275 100644
--- a/lib/eal/include/rte_string_fns.h
+++ b/lib/eal/include/rte_string_fns.h
@@ -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
diff --git a/lib/eal/meson.build b/lib/eal/meson.build
index f9fcee24ee..092f5c5261 100644
--- a/lib/eal/meson.build
+++ b/lib/eal/meson.build
@@ -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
diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index e591c1e283..f863445798 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -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>
diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c
index 0a006559ab..08bdc4ea36 100644
--- a/lib/telemetry/telemetry_data.c
+++ b/lib/telemetry/telemetry_data.c
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 #include <inttypes.h>
 
-#undef RTE_USE_LIBBSD
 #include <stdbool.h>
 
 #include <eal_export.h>
diff --git a/lib/telemetry/telemetry_legacy.c b/lib/telemetry/telemetry_legacy.c
index 1d73282ba8..af497a594a 100644
--- a/lib/telemetry/telemetry_legacy.c
+++ b/lib/telemetry/telemetry_legacy.c
@@ -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>
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-06-29 14:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-24 11:35 [PATCH] build: use native Linux strlcpy when available Bruce Richardson
2026-06-25 13:08 ` [PATCH v2] build: drop dependency on libbsd Bruce Richardson
2026-06-29 11:30   ` David Marchand
2026-06-29 11:52     ` Bruce Richardson
2026-06-29 11:55       ` David Marchand
2026-06-29 14:29 ` [PATCH v3] " Bruce Richardson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox