[PATCH] gcov: Disable GCOV_PROFILE_ALL on 32-bit UML with Clang 20/21
From: Kees Cook
Date: Tue Apr 07 2026 - 21:00:24 EST
Clang 20 and 21 miscompute __builtin_object_size() when -fprofile-arcs
is active on 32-bit UML targets, which passes incorrect object size
calculations for local variables through always_inline copy_to_user()
and check_copy_size(), causing spurious compile-time errors:
include/linux/ucopysize.h:52:4: error: call to '__bad_copy_from' declared with 'error' attribute: copy source size is too small
The regression was introduced in LLVM commit 02b8ee281947 ("[llvm]
Improve llvm.objectsize computation by computing GEP, alloca and malloc
parameters bound"), which shipped in Clang 20. It was fixed in LLVM
by commit 45b697e610fd ("[MemoryBuiltins] Consider index type size
when aggregating gep offsets"), which was backported to the LLVM 22.x
release branch.
The bug requires 32-bit UML + GCOV_PROFILE_ALL (which uses -fprofile-arcs),
though the exact trigger depends on optimizer decisions influenced by other
enabled configs.
Prevent the broken combination by disabling GCOV_PROFILE_ALL on 32-bit
UML when using Clang 20.x or 21.x.
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202604030531.O6FveVgn-lkp@xxxxxxxxx/
Assisted-by: Claude:claude-opus-4-6[1m]
Signed-off-by: Kees Cook <kees@xxxxxxxxxx>
---
Cc: Peter Oberparleiter <oberpar@xxxxxxxxxxxxx>
Cc: Nathan Chancellor <nathan@xxxxxxxxxx>
Cc: Nick Desaulniers <nick.desaulniers+lkml@xxxxxxxxx>
Cc: Bill Wendling <morbo@xxxxxxxxxx>
Cc: Justin Stitt <justinstitt@xxxxxxxxxx>
Cc: <llvm@xxxxxxxxxxxxxxx>
---
kernel/gcov/Kconfig | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/gcov/Kconfig b/kernel/gcov/Kconfig
index 04f4ebdc3cf5..11c377019d01 100644
--- a/kernel/gcov/Kconfig
+++ b/kernel/gcov/Kconfig
@@ -42,6 +42,9 @@ config GCOV_PROFILE_ALL
depends on !COMPILE_TEST
depends on GCOV_KERNEL
depends on ARCH_HAS_GCOV_PROFILE_ALL
+ # Clang 20 & 21 miscompute __builtin_object_size() under -fprofile-arcs
+ # on 32-bit UML, causing spurious compile-time errors in check_copy_size().
+ depends on !(UML && !64BIT && CC_IS_CLANG && CLANG_VERSION >= 200000 && CLANG_VERSION <= 220100)
default n
help
This options activates profiling for the entire kernel.
--
2.34.1