Skip to content

Commit c8248fa

Browse files
committed
Compiler Attributes: counted_by: Adjust name and identifier expansion
GCC and Clang's current RFCs name this attribute "counted_by", and have moved away from using a string for the member name. Update the kernel's macros to match. Additionally provide a UAPI no-op macro for UAPI structs that will gain annotations. Cc: Miguel Ojeda <[email protected]> Cc: Nick Desaulniers <[email protected]> Fixes: dd06e72 ("Compiler Attributes: Add __counted_by macro") Acked-by: Miguel Ojeda <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent be8dffa commit c8248fa

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

include/linux/compiler_attributes.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@
9494
# define __copy(symbol)
9595
#endif
9696

97+
/*
98+
* Optional: only supported since gcc >= 14
99+
* Optional: only supported since clang >= 18
100+
*
101+
* gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896
102+
* clang: https://reviews.llvm.org/D148381
103+
*/
104+
#if __has_attribute(__counted_by__)
105+
# define __counted_by(member) __attribute__((__counted_by__(member)))
106+
#else
107+
# define __counted_by(member)
108+
#endif
109+
97110
/*
98111
* Optional: not supported by gcc
99112
* Optional: only supported since clang >= 14.0
@@ -129,19 +142,6 @@
129142
# define __designated_init
130143
#endif
131144

132-
/*
133-
* Optional: only supported since gcc >= 14
134-
* Optional: only supported since clang >= 17
135-
*
136-
* gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896
137-
* clang: https://reviews.llvm.org/D148381
138-
*/
139-
#if __has_attribute(__element_count__)
140-
# define __counted_by(member) __attribute__((__element_count__(#member)))
141-
#else
142-
# define __counted_by(member)
143-
#endif
144-
145145
/*
146146
* Optional: only supported since clang >= 14.0
147147
*

include/uapi/linux/stddef.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@
4545
TYPE NAME[]; \
4646
}
4747
#endif
48+
49+
#ifndef __counted_by
50+
#define __counted_by(m)
51+
#endif

0 commit comments

Comments
 (0)