Skip to contentSkip to conversation

compiler_types: Identify compiler versions for __builtin_dynamic_object_size

PATCH Applied Kees Cook 2 participants 3 messages Apr 16, 2025

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 compiler_types: Identify compiler versions for __builtin_dynamic_object_size

Clarify when __builtin_dynamic_object_size() is available. All our supported Clang versions support it. GCC 12 and later support it. Link to documentation for both.

---
Cc: Miguel Ojeda <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Nick Desaulniers <[email protected]>
Cc: Bill Wendling <[email protected]>
Cc: Justin Stitt <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Marco Elver <[email protected]>
Cc: Przemek Kitszel <[email protected]>
Cc: [email protected]

---
 include/linux/compiler_types.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/compiler_types.h +5 -0
index 501cffddc2f4..20881cc761fa 100644
@@ -449,6 +449,11 @@ struct ftrace_likely_data {
 /*
  * When the size of an allocated object is needed, use the best available
  * mechanism to find it. (For cases where sizeof() cannot be used.)
+ *
+ * Optional: only supported since gcc >= 12
+ *
+ *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
+ * clang: https://clang.llvm.org/docs/LanguageExtensions.html#evaluating-object-size
  */
 #if __has_builtin(__builtin_dynamic_object_size)
 #define __struct_size(p)	__builtin_dynamic_object_size(p, 0)
Signature · 1 line
2.34.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Kees Cook

Clarify when __builtin_dynamic_object_size() is available. All our supported Clang versions support it. GCC 12 and later support it. Link to documentation for both.

Looks good to me, thanks!

If you/someone is taking it through their tree:

Cheers,
Miguel

author Applied
#2 lore raw
In reply to Kees Cook
Quoted 5 lines · Kees Cook

Clarify when __builtin_dynamic_object_size() is available. All our supported Clang versions support it. GCC 12 and later support it. Link to documentation for both.

Applied to for-next/hardening, thanks!

[1/1] compiler_types: Identify compiler versions for __builtin_dynamic_object_size

      https://git.kernel.org/kees/c/833dd6a6a1b1

Take care,

Signature · 1 line
Kees Cook