|WARNING| [v3] build: drop dependency on libbsd
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Mon Jun 29 17:15:39 CEST 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/166399
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-06-29
# DPDK Patch Review
## Summary
This patch removes the libbsd dependency from DPDK by relying on native strlcpy/strlcat implementations (available in glibc 2.38+) or falling back to DPDK's own implementations. The patch is generally well-structured, but has several issues related to macro naming clarity and test correctness.
---
## Errors
### 1. Incorrect preprocessor condition in rte_string_fns.h
**Location:** `lib/eal/include/rte_string_fns.h:84-89`
The condition for providing strlcpy/strlcat aliases is inverted logic.
When `RTE_HAS_STRLCPY` is defined (meaning native strlcpy exists),
the code **should not** define the macro aliases, but the current condition
includes `!defined(RTE_HAS_STRLCPY)` in an OR expression with platform-specific checks,
making the logic confusing and potentially incorrect.
**Current code:**
```c
#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
```
**Problem:** This defines the macros when `RTE_HAS_STRLCPY` is NOT defined (correct),
but ALSO when it IS defined on FreeBSD without `__BSD_VISIBLE` or glibc without `__USE_MISC`.
The latter case is the "strlcpy available for DPDK build but not for app build" scenario
mentioned in the commit message, but the condition should be separate for clarity.
**Suggested fix:**
Split into two clear cases:
```c
/* Use DPDK fallback when native strlcpy not available */
#ifndef RTE_HAS_STRLCPY
#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
#define strlcat(dst, src, size) rte_strlcat(dst, src, size)
#endif
/* On platforms where strlcpy exists but is hidden by strict standards mode,
* also provide the alias (e.g., FreeBSD without __BSD_VISIBLE,
* glibc 2.38+ without __USE_MISC) */
#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
```
Or more simply, check for the actual declarations being available:
```c
#if !__has_builtin(strlcpy) && \
(!defined(__GLIBC__) || !defined(__USE_MISC)) && \
(!defined(__BSD_VISIBLE))
#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
#define strlcat(dst, src, size) rte_strlcat(dst, src, size)
#endif
```
However, given the complexity, the original OR logic may be intentional to handle all cases.
At minimum, add a comment explaining when each branch applies.
---
### 2. Test disabled based on wrong macro
**Location:** `app/test/test_string_fns.c:136`
The test is guarded by `#ifdef RTE_HAS_STRLCPY`, but the comment says
"only run actual unit tests if we have system-provided strlcat".
The macro name `RTE_HAS_STRLCPY` is confusing here --
it indicates whether the platform provides native strlcpy,
but the test is for `rte_strlcat()` which is DPDK's fallback implementation.
**Current code:**
```c
#ifdef RTE_HAS_STRLCPY
/* test rte_strlcat behavior */
#endif
```
**Problem:** If `RTE_HAS_STRLCPY` is defined (native strlcpy available),
the test runs, but `rte_strlcat()` may be implemented via the DPDK fallback (snprintf),
not the native libc strlcat. The test assumes the native behavior but may be testing the fallback.
The old condition was `#if defined(__BSD_VISIBLE) || defined(RTE_USE_LIBBSD)`,
which explicitly checked for native implementations (BSD libc or libbsd).
The new macro conflates "has native strlcpy" with "should test strlcat behavior",
which are different questions.
**Suggested fix:**
Either:
1. Always run the test (DPDK fallback should match native behavior), OR
2. Introduce a separate macro (e.g., `RTE_HAS_NATIVE_STRLCAT`) if testing only native implementations
The comment suggests the intent is to test only when a native (non-DPDK) implementation is available,
so option 2 is more accurate.
---
## Warnings
### 1. Misleading function name in process-iwyu.py
**Location:** `devtools/process-iwyu.py:63-65`
The function is renamed from `uses_libbsd()` to `uses_native_strlcpy()`,
but the logic is inverted: it returns `True` when `RTE_HAS_STRLCPY` is defined,
which means the build does NOT use the fallback (it uses native strlcpy).
The function name should reflect that it checks for native availability, not fallback usage.
**Current code:**
```python
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))
```
**Suggested fix:**
Rename to `has_native_strlcpy()` and update the comment:
```python
def has_native_strlcpy(builddir):
"return whether the build has native strlcpy (True) or uses DPDK fallback (False)"
return bool(get_build_config(builddir, lambda ln: 'RTE_HAS_STRLCPY' in ln))
```
And update line 77:
```python
keep_str_fns = not has_native_strlcpy(build_dir) # True if using DPDK fallback
```
The warning message on line 79 should also be updated to match the new logic.
---
### 2. Release notes not updated
**Location:** N/A (missing file)
This is a significant change that removes a dependency and changes how strlcpy is provided.
The release notes should document this change, including:
- Removal of libbsd dependency
- Minimum glibc version for native strlcpy (2.38)
- Systems using older glibc will use DPDK fallback
The patch should add a section to `doc/guides/rel_notes/release_26_07.rst` (or the appropriate current release).
---
## Info
### 1. Consider documenting the fallback behavior
The DPDK fallback implementations use `snprintf()` under the hood (visible in earlier DPDK code).
Consider adding a brief comment in `rte_string_fns.h` explaining that the fallback
implementations have the same semantics as the BSD/glibc versions (null-terminated,
return value is source length, etc.).
---
### 2. Test coverage gap
With the removal of libbsd, the test suite should verify that the DPDK fallback
implementations work correctly on systems without native strlcpy.
The current test at line 136 explicitly skips testing when using the fallback,
which means the fallback code path is untested.
Consider enabling the test unconditionally and verifying it passes on both
native and fallback implementations.
---
## Conclusion
The patch is mostly correct in its approach but has clarity issues with the preprocessor
conditions and test guards. The macro naming (`RTE_HAS_STRLCPY` vs actual test requirements)
creates confusion about when the fallback is used versus when native implementations are available.
The most critical issue is ensuring the strlcpy/strlcat alias definitions are correct
for all platform/standards-mode combinations.
More information about the test-report
mailing list