Compiler Attributes: counted_by: Adjust name and identifier expansion
PATCH 1/1 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.
--- include/linux/compiler_attributes.h | 26 +++++++++++++------------- include/uapi/linux/stddef.h | 4 ++++ 2 files changed, 17 insertions(+), 13 deletions(-)
include/linux/compiler_attributes.h +13 -13
@@ -94,6 +94,19 @@# define __copy (symbol)#endif +/* +* Optional: only supported since gcc >= 14 +* Optional: only supported since clang >= 17 +* +* gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 +* clang: https://reviews.llvm.org/D148381 +*/ +#if __has_attribute (__counted_by__) +# define __counted_by (member) __attribute__((__counted_by__(member))) +#else +# define __counted_by (member) +#endif +/* * Optional: not supported by gcc * Optional: only supported since clang >= 14.0
@@ -129,19 +142,6 @@# define __designated_init#endif -/* -* Optional: only supported since gcc >= 14 -* Optional: only supported since clang >= 17 -* -* gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 -* clang: https://reviews.llvm.org/D148381 -*/ -#if __has_attribute (__element_count__) -# define __counted_by (member) __attribute__((__element_count__(#member))) -#else -# define __counted_by (member) -#endif -/* * Optional: only supported since clang >= 14.0 *
include/uapi/linux/stddef.h +4 -0
@@ -45,3 +45,7 @@ TYPE NAME[]; \ }#endif + +#ifndef __counted_by +#define __counted_by (m) +#endif
Signature · 1 line
2.34.1
Quoted 9 lines · Kees Cook
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 dd06e72e68bc ("Compiler Attributes: Add __counted_by macro")Signed-off-by Kees Cook <[email protected]>
One comment below.
Quoted 10 lines
--- include/linux/compiler_attributes.h | 26 +++++++++++++------------- include/uapi/linux/stddef.h | 4 ++++ 2 files changed, 17 insertions(+), 13 deletions(-)include/linux/compiler_attributes.h +0
-0
include/linux/compiler_attributes.h line 99
Quoted 6 lines
include/linux/compiler_attributes.h +3
-0@@ -94,6 +94,19 @@# define __copy (symbol)#endif +/* +* Optional: only supported since gcc >= 14 +* Optional: only supported since clang >= 17
Since you are in the area, should the supported clang version be optimistically updated to '18'? 17.x has already branched and I suspect it would be too late in the release cycle to cherry-pick that change from main if it were landed today (which seems pretty unlikely, given there do not appear to be many reviews from high profile clang folks yet).
Quoted 48 lines
include/linux/compiler_attributes.h +10
-13+* +* gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 +* clang: https://reviews.llvm.org/D148381 +*/ +#if __has_attribute (__counted_by__) +# define __counted_by (member) __attribute__((__counted_by__(member))) +#else +# define __counted_by (member) +#endif +/* * Optional: not supported by gcc * Optional: only supported since clang >= 14.0 @@ -129,19 +142,6 @@# define __designated_init#endif -/* -* Optional: only supported since gcc >= 14 -* Optional: only supported since clang >= 17 -* -* gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 -* clang: https://reviews.llvm.org/D148381 -*/ -#if __has_attribute (__element_count__) -# define __counted_by (member) __attribute__((__element_count__(#member))) -#else -# define __counted_by (member) -#endif -/* * Optional: only supported since clang >= 14.0 * include/uapi/linux/stddef.h +4
-0@@ -45,3 +45,7 @@ TYPE NAME[]; \ }#endif + +#ifndef __counted_by +#define __counted_by (m) +#endif Signature · 1 line
2.34.1
Quoted 28 lines · Nathan Chancellor
Quoted 9 lines · Kees Cook
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 dd06e72e68bc ("Compiler Attributes: Add __counted_by macro")Signed-off-by Kees Cook <[email protected]>Reviewed-by Nathan Chancellor <[email protected]>One comment below.
Quoted 13 lines
--- include/linux/compiler_attributes.h | 26 +++++++++++++------------- include/uapi/linux/stddef.h | 4 ++++ 2 files changed, 17 insertions(+), 13 deletions(-)include/linux/compiler_attributes.h +0
-0@@ -94,6 +94,19 @@# define __copy (symbol)#endif
Quoted 10 lines
include/linux/compiler_attributes.h line 99
Quoted 3 lines
include/linux/compiler_attributes.h +3
-0+/* +* Optional: only supported since gcc >= 14 +* Optional: only supported since clang >= 17 Since you are in the area, should the supported clang version be optimistically updated to '18'? 17.x has already branched and I suspect it would be too late in the release cycle to cherry-pick that change from main if it were landed today (which seems pretty unlikely, given there do not appear to be many reviews from high profile clang folks yet).
Oops, yes. Excellent point. I'll bump this to 18.
-Kees
Quoted 49 lines
Quoted 49 lines
include/linux/compiler_attributes.h +10
-13+* +* gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 +* clang: https://reviews.llvm.org/D148381 +*/ +#if __has_attribute (__counted_by__) +# define __counted_by (member) __attribute__((__counted_by__(member))) +#else +# define __counted_by (member) +#endif +/* * Optional: not supported by gcc * Optional: only supported since clang >= 14.0 @@ -129,19 +142,6 @@# define __designated_init#endif -/* -* Optional: only supported since gcc >= 14 -* Optional: only supported since clang >= 17 -* -* gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 -* clang: https://reviews.llvm.org/D148381 -*/ -#if __has_attribute (__element_count__) -# define __counted_by (member) __attribute__((__element_count__(#member))) -#else -# define __counted_by (member) -#endif -/* * Optional: only supported since clang >= 14.0 * include/uapi/linux/stddef.h +4
-0@@ -45,3 +45,7 @@ TYPE NAME[]; \ }#endif + +#ifndef __counted_by +#define __counted_by (m) +#endif Signature · 1 line
2.34.1
Signature · 1 line
Kees Cook
Quoted 10 lines · Kees Cook
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 dd06e72e68bc ("Compiler Attributes: Add __counted_by macro")Signed-off-by Kees Cook <[email protected]>
Looks good to me, thanks. Perhaps we should split the UAPI bit into a second patch.
I can take it into my tree; otherwise if you need this elsewhere:
Cheers,
Miguel
Quoted 7 lines · Miguel Ojeda
Quoted 6 lines · Kees Cook
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.
Quoted 7 lines
Quoted 4 lines
Cc Miguel Ojeda <[email protected]>Cc Nick Desaulniers <[email protected]>Fixes dd06e72e68bc ("Compiler Attributes: Add __counted_by macro")Signed-off-by Kees Cook <[email protected]>Looks good to me, thanks. Perhaps we should split the UAPI bit into a second patch.
I'd like to keep the UAPI part -- that was an oversight when I first added it.
Quoted 3 lines
I can take it into my tree; otherwise if you need this elsewhere:
Acked-by Miguel Ojeda <[email protected]>
Thanks! It'd be slightly easier for me if it was is my tree, so I'll grab your Ack. :) Let me know if you'd prefer it otherwise.
-Kees
Signature · 1 line
Kees Cook
Quoted 9 lines · Kees Cook
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 dd06e72e68bc ("Compiler Attributes: Add __counted_by macro")Signed-off-by Kees Cook <[email protected]>
Thanks
Signature · 1 line
Gustavo
Quoted 61 lines
--- include/linux/compiler_attributes.h | 26 +++++++++++++------------- include/uapi/linux/stddef.h | 4 ++++ 2 files changed, 17 insertions(+), 13 deletions(-)include/linux/compiler_attributes.h +13
-13@@ -94,6 +94,19 @@# define __copy (symbol)#endif +/* +* Optional: only supported since gcc >= 14 +* Optional: only supported since clang >= 17 +* +* gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 +* clang: https://reviews.llvm.org/D148381 +*/ +#if __has_attribute (__counted_by__) +# define __counted_by (member) __attribute__((__counted_by__(member))) +#else +# define __counted_by (member) +#endif +/* * Optional: not supported by gcc * Optional: only supported since clang >= 14.0 @@ -129,19 +142,6 @@# define __designated_init#endif -/* -* Optional: only supported since gcc >= 14 -* Optional: only supported since clang >= 17 -* -* gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 -* clang: https://reviews.llvm.org/D148381 -*/ -#if __has_attribute (__element_count__) -# define __counted_by (member) __attribute__((__element_count__(#member))) -#else -# define __counted_by (member) -#endif -/* * Optional: only supported since clang >= 14.0 * include/uapi/linux/stddef.h +4
-0@@ -45,3 +45,7 @@ TYPE NAME[]; \ }#endif + +#ifndef __counted_by +#define __counted_by (m) +#endif
Kees Cook
AppliedQuoted 4 lines · Kees Cook
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.
Applied to for-next/hardening, thanks!
[1/1] Compiler Attributes: counted_by: Adjust name and identifier expansion
https://git.kernel.org/kees/c/c8248faf3ca2
Take care,
Signature · 1 line
Kees Cook