[PATCH v2 25/63] compiler_types.h: Remove __compiletime_object_size()

Kees Cook keescook at chromium.org
Wed Aug 18 06:04:55 UTC 2021


Since all compilers support __builtin_object_size(), and there is only
one user of __compiletime_object_size, remove it to avoid the needless
indirection. This lets Clang reason about check_copy_size() correctly.

Link: https://github.com/ClangBuiltLinux/linux/issues/1179
Suggested-by: Nick Desaulniers <ndesaulniers at google.com>
Cc: Nathan Chancellor <nathan at kernel.org>
Cc: Nick Desaulniers <ndesaulniers at google.com>
Cc: Miguel Ojeda <ojeda at kernel.org>
Cc: Sedat Dilek <sedat.dilek at gmail.com>
Cc: Will Deacon <will at kernel.org>
Cc: Marco Elver <elver at google.com>
Cc: Arvind Sankar <nivedita at alum.mit.edu>
Cc: Masahiro Yamada <masahiroy at kernel.org>
Cc: Luc Van Oostenryck <luc.vanoostenryck at gmail.com>
Cc: Andrew Morton <akpm at linux-foundation.org>
Cc: Sami Tolvanen <samitolvanen at google.com>
Cc: Thomas Gleixner <tglx at linutronix.de>
Cc: Gabriel Krisman Bertazi <krisman at collabora.com>
Cc: Andy Lutomirski <luto at kernel.org>
Cc: Oleg Nesterov <oleg at redhat.com>
Signed-off-by: Kees Cook <keescook at chromium.org>
---
 include/linux/compiler-gcc.h   | 2 --
 include/linux/compiler_types.h | 4 ----
 include/linux/thread_info.h    | 2 +-
 3 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index cb9217fc60af..01985821944b 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -41,8 +41,6 @@
 
 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
 
-#define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
-
 #define __compiletime_warning(message) __attribute__((__warning__(message)))
 #define __compiletime_error(message) __attribute__((__error__(message)))
 
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index e4ea86fc584d..c43308b0a9a9 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -290,10 +290,6 @@ struct ftrace_likely_data {
 	(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
 	 sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
 
-/* Compile time object size, -1 for unknown */
-#ifndef __compiletime_object_size
-# define __compiletime_object_size(obj) -1
-#endif
 #ifndef __compiletime_warning
 # define __compiletime_warning(message)
 #endif
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index 0999f6317978..ad0c4e041030 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -203,7 +203,7 @@ static inline void copy_overflow(int size, unsigned long count)
 static __always_inline __must_check bool
 check_copy_size(const void *addr, size_t bytes, bool is_source)
 {
-	int sz = __compiletime_object_size(addr);
+	int sz = __builtin_object_size(addr, 0);
 	if (unlikely(sz >= 0 && sz < bytes)) {
 		if (!__builtin_constant_p(bytes))
 			copy_overflow(sz, bytes);
-- 
2.30.2



More information about the dri-devel mailing list