Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Apr 2026 21:08:56 +0000
From:      Bjoern A. Zeeb <bz@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 70cc86a2c8c0 - stable/15 - LinuxKPI: conditionally add __flex_counter()
Message-ID:  <69e938e8.30b01.5822fc32@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/15 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=70cc86a2c8c042e48162b891e53f1d4ad74e8bb6

commit 70cc86a2c8c042e48162b891e53f1d4ad74e8bb6
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2026-04-14 15:06:56 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-04-22 20:57:08 +0000

    LinuxKPI: conditionally add __flex_counter()
    
    __flex_counter() is used by overflow.h and needed for "flex allocations".
    It is either a void * typed 0 (NULL) (like this for _Generic checks),
    or uses __builtin_counted_by_ref.
    
    The latter was added to gcc and llvm fairly recently and while for gcc
    the __has_builtin() check suffices, clang had parts broken until recently
    so needs an extra check for the next major version.  The fixed hash is
    currently not part of any tag to use, so we play it save (and hope 23
    will have it).  It will be a while until we will see the builting to be
    used but at least we will be prepared for it.  See inline comments for
    the commit hashes and versions which added the feature.
    
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    dumbbell
    Differential Revision: https://reviews.freebsd.org/D56393
    
    (cherry picked from commit 524df650a92f648e19ba27d6727bdc79c8efdbbb)
---
 sys/compat/linuxkpi/common/include/linux/compiler_types.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/compiler_types.h b/sys/compat/linuxkpi/common/include/linux/compiler_types.h
index 7151c03de690..25e69f5afd8e 100644
--- a/sys/compat/linuxkpi/common/include/linux/compiler_types.h
+++ b/sys/compat/linuxkpi/common/include/linux/compiler_types.h
@@ -42,4 +42,17 @@
 
 #define	__same_type(a, b)	__builtin_types_compatible_p(typeof(a), typeof(b))
 
+/*
+ * __builtin_counted_by_ref was introduced to
+ * - gcc in e7380688fa59 with a first release tag of gcc-15.1.0,
+ * - llvm in 7475156d49406 with a first release tag of llvmorg-20.1.0-rc1
+ *   but cannot be used before 23 (22.x.y possibly) (see 09a3d830a888).
+ */
+#if (__has_builtin(__builtin_counted_by_ref)) && \
+    (!defined(__clang__) || (__clang_major__ >= 23))
+#define	__flex_counter(_field)		__builtin_counted_by_ref(_field)
+#else
+#define	__flex_counter(_field)		((void *)NULL)
+#endif
+
 #endif


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69e938e8.30b01.5822fc32>