package/libcap: fix build with C libraries lacking static_assert
PATCH 1/1 package/libcap: fix build with C libraries lacking static_assert
Since libcap 2.77, libcap_static_assert() expands to static_assert() in C11 mode. Before C23, static_assert is a macro that <assert.h> has to provide, which older C libraries such as uClibc-ng < 1.0.42 lack, so the build fails, e.g. with the br-arm-full-static toolchain:
cap_alloc.c:53:25: error: expected declaration specifiers or '...' before '__builtin_offsetof'
53 | #define CAP_ALLOC_OFF_U offsetof(struct _cap_alloc_s, u)
libcap.h:342:19: note: in definition of macro 'libcap_static_assert'
342 | static_assert(cond, #text)
Add a patch, submitted upstream, using the _Static_assert keyword instead, which C11 compilers provide regardless of the C library.
This issue has been present since commit 42f2b480a5a8 ("package/libcap: bump version to 2.77"), as libcap_static_assert() was introduced in libcap 2.77. It therefore affects 2025.11 and later; the 2025.02.x LTS branch still has libcap 2.73 and is not affected.
--- ...tatic_assert-in-libcap_static_assert.patch | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 package/libcap/0001-libcap-use-_Static_assert-in-libcap_static_assert.patch
package/libcap/0001-libcap-use-_Static_assert-in-libcap_static_assert.patch new file +41 -0
@@ -0,0 +1,41 @@ +From 09ac731fe0e3e28d70344062dbbad2e19a86b86d Mon Sep 17 00:00:00 2001 +From: Yegor Yefremov <[email protected]> +Date: Thu, 5 Nov 2026 13:45:08 +0100 +Subject: [PATCH] libcap: use _Static_assert in libcap_static_assert() + +In C11 mode, libcap_static_assert() expands to static_assert(), which +is not a keyword before C23 but a macro that <assert.h> has to define. +C libraries that predate this, such as uClibc-ng before 1.0.42, lack +it, so the compiler parses the call as a function declaration: + + cap_alloc.c:53:25: error: expected declaration specifiers or '...' before '__builtin_offsetof' + 53 | #define CAP_ALLOC_OFF_U offsetof(struct _cap_alloc_s, u) + libcap.h:342:19: note: in definition of macro 'libcap_static_assert' + 342 | static_assert(cond, #text) + +Use the _Static_assert keyword instead, which C11 compilers provide +regardless of the C library. + +Assisted-by: Claude:claude-opus-5-5 +Upstream: https://github.com/AndrewGMorgan/libcap_mirror/issues/17 +Signed-off-by: Yegor Yefremov <[email protected]> +--- + libcap/libcap.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libcap/libcap.h b/libcap/libcap.h +index 829886b..268e1e5 100644 +--- a/libcap/libcap.h ++++ b/libcap/libcap.h +@@ -339,7 +339,7 @@ struct cap_launch_s { + + #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + #define libcap_static_assert(cond, text) \ +- static_assert(cond, #text) ++ _Static_assert(cond, #text) + #else + #define libcap_static_assert(cond, text) \ + typedef char _compilation_time_static_assert_##text [cond ? 1:-1] +-- +2.34.1 +
Signature · 6 lines
2.34.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 1/1 package/libcap: fix build with C libraries lacking static_assert
Since libcap 2.77, libcap_static_assert() expands to static_assert() in C11 mode. Before C23, static_assert is a macro that <assert.h> has to provide, which older C libraries such as uClibc-ng < 1.0.42 lack, so the build fails, e.g. with the br-arm-full-static toolchain:
cap_alloc.c:53:25: error: expected declaration specifiers or '...' before '__builtin_offsetof'
53 | #define CAP_ALLOC_OFF_U offsetof(struct _cap_alloc_s, u)
libcap.h:342:19: note: in definition of macro 'libcap_static_assert'
342 | static_assert(cond, #text)
Backport the upstream fix, which defines static_assert as the _Static_assert keyword on uClibc-ng < 1.0.42.
This issue has been present since commit 42f2b480a5a8 ("package/libcap: bump version to 2.77"), as libcap_static_assert() was introduced in libcap 2.77. It therefore affects 2025.11 and later; the 2025.02.x LTS branch still has libcap 2.73 and is not affected.
---
Changes v1 -> v2:
- replace the local patch with the fix merged upstream as 7bb5a1d487a9 ("Work around the lack of static_assert() in older ulibc-ng headers."), which only defines static_assert on uClibc-ng < 1.0.42 (suggested by Andrew G. Morgan)
...tic_assert-in-older-ulibc-ng-headers.patch | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 package/libcap/0001-Work-around-the-lack-of-static_assert-in-older-ulibc-ng-headers.patch
package/libcap/0001-Work-around-the-lack-of-static_assert-in-older-ulibc-ng-headers.patch new file +42 -0
@@ -0,0 +1,42 @@ +From 7bb5a1d487a94b708ae34a5da7e71fa1fd5aff8b Mon Sep 17 00:00:00 2001 +From: "Andrew G. Morgan" <[email protected]> +Date: Sat, 7 Nov 2026 09:45:18 -0800 +Subject: Work around the lack of static_assert() in older ulibc-ng headers. + +Yegor Yefremov reported that builds were failing with an old version +of ARM ulibc-ng. In particular uClibc-ng < 1.0.42 lack it. Issue +described more fully here: + +https://github.com/AndrewGMorgan/libcap_mirror/issues/17 + +Upstream: https://git.kernel.org/pub/scm/libs/libcap/libcap.git/commit/?id=7bb5a1d487a94b708ae34a5da7e71fa1fd5aff8b +Signed-off-by: Andrew G. Morgan <[email protected]> +--- + libcap/libcap.h | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/libcap/libcap.h b/libcap/libcap.h +index 829886b..bce3a4d 100644 +--- a/libcap/libcap.h ++++ b/libcap/libcap.h +@@ -337,6 +337,17 @@ struct cap_launch_s { + #define good_cap_iab_t(x) (CAP_IAB_MAGIC == magic_of(x)) + #define good_cap_launch_t(x) (CAP_LAUNCH_MAGIC == magic_of(x)) + ++/* Older uClibc-ng environments lack the static_assert macro */ ++#if !defined(__cplusplus) && !defined(static_assert) ++ #if defined(__UCLIBC__) ++ /* Check if we are on uClibc-ng < 1.0.42 */ ++ #if (__UCLIBC_MAJOR__ < 1) || \ ++ (__UCLIBC_MAJOR__ == 1 && __UCLIBC_MINOR__ == 0 && __UCLIBC_SUBLEVEL__ < 42) ++ #define static_assert _Static_assert ++ #endif ++ #endif ++#endif ++ + #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + #define libcap_static_assert(cond, text) \ + static_assert(cond, #text) +-- +cgit 1.3.1-korg +
Signature · 6 lines
2.34.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot