Fix kernel build failure with CONFIG_GCOV_PROFILE_ALL=y
Subsystems (2)
v2 cover Fix kernel build failure with CONFIG_GCOV_PROFILE_ALL=y
This patch fixes a build failure in net/core/skbuff.c that occurs when CONFIG_GCOV_PROFILE_ALL=y is enabled.
v2: use __no_profile instead of preprocessor guards, as suggested
by Thomas Weißschuh. This solves the root cause (GCOV counters preventing constant folding) and also removes the existing CONFIG_KCOV_INSTRUMENT_ALL guard which is no longer needed.
Build failure without this patch
---------------------------------
With the following configuration:
CONFIG_GCOV_KERNEL=y
CONFIG_GCOV_PROFILE_ALL=y
# CONFIG_GCOV_PROFILE_FTRACE is not set
CONFIG_GCOV_PROFILE_RDS=y
CONFIG_GCOV_PROFILE_URING=y
The kernel fails to build with:
In file included from <command-line>:
In function 'skb_extensions_init',
inlined from 'skb_init' at net/core/skbuff.c:5214:2:
././include/linux/compiler_types.h:706:45: error: call to '__compiletime_assert_1490' declared with attribute error: BUILD_BUG_ON failed: skb_ext_total_length() > 255
706 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
././include/linux/compiler_types.h:687:25: note: in definition of macro '__compiletime_assert'
687 | prefix ## suffix(); \
| ^~~~~~
././include/linux/compiler_types.h:706:9: note: in expansion of macro '_compiletime_assert'
706 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:40:37: note: in expansion of macro 'compiletime_assert'
40 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:51:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
51 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^~~~~~~~~~~~~~~~
net/core/skbuff.c:5163:9: note: in expansion of macro 'BUILD_BUG_ON'
5163 | BUILD_BUG_ON(skb_ext_total_length() > 255);
| ^~~~~~~~~~~~ make[4]: *** [scripts/Makefile.build:289: net/core/skbuff.o] Error 1
Testing
-------
Tested with GCC 11.4.1 and GCC 16.0.1 20260327 (experimental) - both exhibit the same build failure without the patch. Both compile successfully with the patch applied.
Konstantin Khorenko (1):
net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL
net/core/skbuff.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Signature · 1 line
2.43.5
PATCH v2 1/1 net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL
When CONFIG_GCOV_PROFILE_ALL=y is enabled, the kernel fails to build:
In file included from <command-line>:
In function 'skb_extensions_init',
inlined from 'skb_init' at net/core/skbuff.c:5214:2:
././include/linux/compiler_types.h:706:45: error: call to
'__compiletime_assert_1490' declared with attribute error:
BUILD_BUG_ON failed: skb_ext_total_length() > 255
CONFIG_GCOV_PROFILE_ALL adds -fprofile-arcs -ftest-coverage -fno-tree-loop-im to CFLAGS globally. GCC inserts branch profiling counters into the skb_ext_total_length() loop and, combined with -fno-tree-loop-im (which disables loop invariant motion), cannot constant-fold the result. BUILD_BUG_ON requires a compile-time constant and fails.
The issue manifests in kernels with 5+ SKB extension types enabled (e.g., after addition of SKB_EXT_CAN, SKB_EXT_PSP). With 4 extensions GCC can still unroll and fold the loop despite GCOV instrumentation; with 5+ it gives up.
Mark skb_ext_total_length() with __no_profile to prevent GCOV from inserting counters into this function. Without counters the loop is "clean" and GCC can constant-fold it even with -fno-tree-loop-im active. This allows BUILD_BUG_ON to work correctly while keeping GCOV profiling for the rest of the kernel.
This also removes the CONFIG_KCOV_INSTRUMENT_ALL preprocessor guard introduced by d6e5794b06c0, as __no_profile handles both GCOV and KCOV instrumentation at the root cause level rather than just disabling the check.
--- net/core/skbuff.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/core/skbuff.c +1 -3
@@ -5145,7 +5145,7 @@ static const u8 skb_ext_type_len[] = {#endif }; -static __always_inline unsigned int skb_ext_total_length(void) +static __always_inline __no_profile unsigned int skb_ext_total_length(void) { unsigned int l = SKB_EXT_CHUNKSIZEOF(struct skb_ext);int i;
@@ -5159,9 +5159,7 @@ static __always_inline unsigned int skb_ext_total_length(void)static void skb_extensions_init (void ) {BUILD_BUG_ON (SKB_EXT_NUM >8 ); -#if !IS_ENABLED (CONFIG_KCOV_INSTRUMENT_ALL )BUILD_BUG_ON (skb_ext_total_length () >255 ); -#endif skbuff_ext_cache = kmem_cache_create("skbuff_ext_cache", SKB_EXT_ALIGN_VALUE * skb_ext_total_length(),
Signature · 1 line
2.43.5