From 380d53c45ff21f66870ee965b62613137f9d010d Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Mon, 21 Jun 2021 16:18:20 -0700 Subject: compiler_attributes.h: define __no_profile, add to noinstr noinstr implies that we would like the compiler to avoid instrumenting a function. Add support for the compiler attribute no_profile_instrument_function to compiler_attributes.h, then add __no_profile to the definition of noinstr. Link: https://lore.kernel.org/lkml/20210614162018.GD68749@worktop.programming.kicks-ass.net/ Link: https://reviews.llvm.org/D104257 Link: https://reviews.llvm.org/D104475 Link: https://reviews.llvm.org/D104658 Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80223 Reviewed-by: Fangrui Song Reviewed-by: Miguel Ojeda Suggested-by: Peter Zijlstra Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Acked-by: Peter Zijlstra (Intel) Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20210621231822.2848305-2-ndesaulniers@google.com --- include/linux/compiler_attributes.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include/linux/compiler_attributes.h') diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index c043b8d2b17b..225511b17223 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -33,6 +33,7 @@ # define __GCC4_has_attribute___externally_visible__ 1 # define __GCC4_has_attribute___no_caller_saved_registers__ 0 # define __GCC4_has_attribute___noclone__ 1 +# define __GCC4_has_attribute___no_profile_instrument_function__ 0 # define __GCC4_has_attribute___nonstring__ 0 # define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) # define __GCC4_has_attribute___no_sanitize_undefined__ (__GNUC_MINOR__ >= 9) @@ -237,6 +238,18 @@ # define __nonstring #endif +/* + * Optional: only supported since GCC >= 7.1, clang >= 13.0. + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fprofile_005finstrument_005ffunction-function-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#no-profile-instrument-function + */ +#if __has_attribute(__no_profile_instrument_function__) +# define __no_profile __attribute__((__no_profile_instrument_function__)) +#else +# define __no_profile +#endif + /* * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute * clang: https://clang.llvm.org/docs/AttributeReference.html#noreturn -- cgit From ae4d682dfd3350d9836dafeed1fc5aa1e27c4963 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Mon, 21 Jun 2021 16:18:21 -0700 Subject: compiler_attributes.h: cleanups for GCC 4.9+ Since commit 6ec4476ac825 ("Raise gcc version requirement to 4.9") we no longer support building the kernel with GCC 4.8; drop the preprocess checks for __GNUC_MINOR__ version. It's implied that if __GNUC_MAJOR__ is 4, then the only supported version of __GNUC_MINOR__ left is 9. Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Acked-by: Peter Zijlstra (Intel) Reviewed-by: Miguel Ojeda Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20210621231822.2848305-3-ndesaulniers@google.com --- include/linux/compiler_attributes.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/linux/compiler_attributes.h') diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index 225511b17223..84b1c970acb3 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -27,7 +27,7 @@ */ #ifndef __has_attribute # define __has_attribute(x) __GCC4_has_attribute_##x -# define __GCC4_has_attribute___assume_aligned__ (__GNUC_MINOR__ >= 9) +# define __GCC4_has_attribute___assume_aligned__ 1 # define __GCC4_has_attribute___copy__ 0 # define __GCC4_has_attribute___designated_init__ 0 # define __GCC4_has_attribute___externally_visible__ 1 @@ -35,8 +35,8 @@ # define __GCC4_has_attribute___noclone__ 1 # define __GCC4_has_attribute___no_profile_instrument_function__ 0 # define __GCC4_has_attribute___nonstring__ 0 -# define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) -# define __GCC4_has_attribute___no_sanitize_undefined__ (__GNUC_MINOR__ >= 9) +# define __GCC4_has_attribute___no_sanitize_address__ 1 +# define __GCC4_has_attribute___no_sanitize_undefined__ 1 # define __GCC4_has_attribute___fallthrough__ 0 #endif -- cgit