Skip to content

Commit d39a1d7

Browse files
committed
compiler_types: Disable __builtin_counted_by_ref for Clang
Unfortunately, there is a corner case of __builtin_counted_by_ref() usage that crashes[1] Clang since support was introduced in Clang 19. Disable it prior to Clang 22. Found while tested kmalloc_obj treewide refactoring (via kmalloc_flex() usage). Link: llvm/llvm-project#182575 [1] Signed-off-by: Kees Cook <kees@kernel.org>
1 parent d79526b commit d39a1d7

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

include/linux/compiler_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ struct ftrace_likely_data {
552552
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005fcounted_005fby_005fref
553553
* clang: https://clang.llvm.org/docs/LanguageExtensions.html#builtin-counted-by-ref
554554
*/
555-
#if __has_builtin(__builtin_counted_by_ref)
555+
#if __has_builtin(__builtin_counted_by_ref) && \
556+
!defined(CONFIG_CC_HAS_BROKEN_COUNTED_BY_REF)
556557
/**
557558
* __flex_counter() - Get pointer to counter member for the given
558559
* flexible array, if it was annotated with __counted_by()

init/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ config CC_HAS_COUNTED_BY_PTR
150150
# supported since gcc 16.0.0
151151
default y if CC_IS_GCC && GCC_VERSION >= 160000
152152

153+
config CC_HAS_BROKEN_COUNTED_BY_REF
154+
bool
155+
# https://github.com/llvm/llvm-project/issues/182575
156+
default y if CC_IS_CLANG && CLANG_VERSION < 220000
157+
153158
config CC_HAS_MULTIDIMENSIONAL_NONSTRING
154159
def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror)
155160

0 commit comments

Comments
 (0)