[PATCH 2/2] compiler: check for __SANITIZE_ADDRESS__ instead of CONFIG_KASAN
Ahmad Fatoum
a.fatoum at barebox.org
Wed May 28 04:30:50 PDT 2025
The current Linux definition for __no_kasan_or_inline adds a notrace
attribute and checks __SANITIZE_ADDRESS__ instead of CONFIG_KASAN.
Checking __SANITIZE_ADDRESS__ is better because it also applies to
CONFIG_ASAN, so import the Linux version into <linux/compiler_types.h>,
which is the same location it's defined at in Linux.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
include/linux/compiler.h | 12 ------------
include/linux/compiler_types.h | 20 ++++++++++++++++++++
2 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index e7dc9ba0a590..4953121711ba 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -168,18 +168,6 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
#include <linux/types.h>
-#ifdef CONFIG_KASAN
-/*
- * We can't declare function 'inline' because __no_sanitize_address confilcts
- * with inlining. Attempt to inline it may cause a build failure.
- * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
- * '__maybe_unused' allows us to avoid defined-but-not-used warnings.
- */
-# define __no_kasan_or_inline __no_sanitize_address __maybe_unused
-#else
-# define __no_kasan_or_inline __always_inline
-#endif
-
#endif /* __KERNEL__ */
/**
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index cd618e7dece1..87ab117aca13 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -378,6 +378,26 @@ struct ftrace_likely_data {
*/
#define noinline_for_stack noinline
+/*
+ * Sanitizer helper attributes: Because using __always_inline and
+ * __no_sanitize_* conflict, provide helper attributes that will either expand
+ * to __no_sanitize_* in compilation units where instrumentation is enabled
+ * (__SANITIZE_*__), or __always_inline in compilation units without
+ * instrumentation (__SANITIZE_*__ undefined).
+ */
+#ifdef __SANITIZE_ADDRESS__
+/*
+ * We can't declare function 'inline' because __no_sanitize_address conflicts
+ * with inlining. Attempt to inline it may cause a build failure.
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
+ * '__maybe_unused' allows us to avoid defined-but-not-used warnings.
+ */
+# define __no_kasan_or_inline __no_sanitize_address notrace __maybe_unused
+# define __no_sanitize_or_inline __no_kasan_or_inline
+#else
+# define __no_kasan_or_inline __always_inline
+#endif
+
#ifndef __no_sanitize_or_inline
#define __no_sanitize_or_inline __always_inline
#endif
--
2.39.5
More information about the barebox
mailing list