Skip to content

Commit 380d53c

Browse files
nickdesaulnierskees
authored andcommitted
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/[email protected]/ 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 <[email protected]> Reviewed-by: Miguel Ojeda <[email protected]> Suggested-by: Peter Zijlstra <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 583bfd4 commit 380d53c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

include/linux/compiler_attributes.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# define __GCC4_has_attribute___externally_visible__ 1
3434
# define __GCC4_has_attribute___no_caller_saved_registers__ 0
3535
# define __GCC4_has_attribute___noclone__ 1
36+
# define __GCC4_has_attribute___no_profile_instrument_function__ 0
3637
# define __GCC4_has_attribute___nonstring__ 0
3738
# define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8)
3839
# define __GCC4_has_attribute___no_sanitize_undefined__ (__GNUC_MINOR__ >= 9)
@@ -237,6 +238,18 @@
237238
# define __nonstring
238239
#endif
239240

241+
/*
242+
* Optional: only supported since GCC >= 7.1, clang >= 13.0.
243+
*
244+
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fprofile_005finstrument_005ffunction-function-attribute
245+
* clang: https://clang.llvm.org/docs/AttributeReference.html#no-profile-instrument-function
246+
*/
247+
#if __has_attribute(__no_profile_instrument_function__)
248+
# define __no_profile __attribute__((__no_profile_instrument_function__))
249+
#else
250+
# define __no_profile
251+
#endif
252+
240253
/*
241254
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute
242255
* clang: https://clang.llvm.org/docs/AttributeReference.html#noreturn

include/linux/compiler_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ struct ftrace_likely_data {
210210
/* Section for code which can't be instrumented at all */
211211
#define noinstr \
212212
noinline notrace __attribute((__section__(".noinstr.text"))) \
213-
__no_kcsan __no_sanitize_address
213+
__no_kcsan __no_sanitize_address __no_profile
214214

215215
#endif /* __KERNEL__ */
216216

0 commit comments

Comments
 (0)