Skip to content

Commit

Permalink
BACKPORT: compiler_types.h: Remove __compiletime_object_size()
Browse files Browse the repository at this point in the history
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: ClangBuiltLinux/linux#1179
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Sedat Dilek <sedat.dilek@gmail.com>
Cc: Will Deacon <will@kernel.org>
Cc: Marco Elver <elver@google.com>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Gabriel Krisman Bertazi <krisman@collabora.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
Change-Id: Iaa0e99edc8a081aa31cc32d7684644e5833d9864
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
  • Loading branch information
kees authored and bemerguy committed Feb 18, 2024
1 parent 2ea02fd commit 47c050b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 7 deletions.
2 changes: 0 additions & 2 deletions include/linux/compiler-gcc.h
Expand Up @@ -60,8 +60,6 @@

#define __optimize(level) __attribute__((__optimize__(level)))

#define __compiletime_object_size(obj) __builtin_object_size(obj, 0)

#ifndef __CHECKER__
#define __compiletime_warning(message) __attribute__((warning(message)))
#define __compiletime_error(message) __attribute__((error(message)))
Expand Down
4 changes: 0 additions & 4 deletions include/linux/compiler.h
Expand Up @@ -328,10 +328,6 @@ static inline void *offset_to_ptr(const int *off)
#define __noreorder
#endif

/* 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
Expand Down
2 changes: 1 addition & 1 deletion include/linux/thread_info.h
Expand Up @@ -137,7 +137,7 @@ static inline void copy_overflow(int size, unsigned long count)
static __always_inline 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);
Expand Down

0 comments on commit 47c050b

Please sign in to comment.