Calls to __asan_before_dynamic_init() and __asan_after_dynamic_init()
are inserted by Clang when building with coverage guards.
These functions can be used to detect initialization order fiasco bugs
in the userspace, but it is fine for them to be no-ops in the kernel.
Signed-off-by: Alexander Potapenko <glider@google.com>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
---
v3:
- add Reviewed-by: Dmitry Vyukov
v2:
- Address comments by Dmitry Vyukov:
- rename CONFIG_KCOV_ENABLE_GUARDS to CONFIG_KCOV_UNIQUE
- Move this patch before the one introducing CONFIG_KCOV_UNIQUE,
per Marco Elver's request.
Change-Id: I7f8eb690a3d96f7d122205e8f1cba8039f6a68eb
---
mm/kasan/generic.c | 18 ++++++++++++++++++
mm/kasan/kasan.h | 2 ++
2 files changed, 20 insertions(+)
diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c
index d54e89f8c3e76..b0b7781524348 100644
--- a/mm/kasan/generic.c
+++ b/mm/kasan/generic.c
@@ -238,6 +238,24 @@ void __asan_unregister_globals(void *ptr, ssize_t size)
}
EXPORT_SYMBOL(__asan_unregister_globals);
+#if defined(CONFIG_KCOV_UNIQUE)
+/*
+ * __asan_before_dynamic_init() and __asan_after_dynamic_init() are inserted
+ * when the user requests building with coverage guards. In the userspace, these
+ * two functions can be used to detect initialization order fiasco bugs, but in
+ * the kernel they can be no-ops.
+ */
+void __asan_before_dynamic_init(const char *module_name)
+{
+}
+EXPORT_SYMBOL(__asan_before_dynamic_init);
+
+void __asan_after_dynamic_init(void)
+{
+}
+EXPORT_SYMBOL(__asan_after_dynamic_init);
+#endif
+
#define DEFINE_ASAN_LOAD_STORE(size) \
void __asan_load##size(void *addr) \
{ \
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index 129178be5e649..c817c46b4fcd2 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -582,6 +582,8 @@ void kasan_restore_multi_shot(bool enabled);
void __asan_register_globals(void *globals, ssize_t size);
void __asan_unregister_globals(void *globals, ssize_t size);
+void __asan_before_dynamic_init(const char *module_name);
+void __asan_after_dynamic_init(void);
void __asan_handle_no_return(void);
void __asan_alloca_poison(void *, ssize_t size);
void __asan_allocas_unpoison(void *stack_top, ssize_t stack_bottom);
--
2.50.1.470.g6ba607880d-goog
Hi Alexander, kernel test robot noticed the following build warnings: [auto build test WARNING on tip/x86/core] [also build test WARNING on akpm-mm/mm-everything shuah-kselftest/next shuah-kselftest/fixes linus/master v6.16 next-20250729] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Alexander-Potapenko/x86-kcov-disable-instrumentation-of-arch-x86-kernel-tsc-c/20250728-232935 base: tip/x86/core patch link: https://lore.kernel.org/r/20250728152548.3969143-5-glider%40google.com patch subject: [PATCH v3 04/10] mm/kasan: define __asan_before_dynamic_init, __asan_after_dynamic_init config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20250729/202507291913.UMbUQv95-lkp@intel.com/config) compiler: powerpc64-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250729/202507291913.UMbUQv95-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202507291913.UMbUQv95-lkp@intel.com/ All warnings (new ones prefixed by >>): In file included from mm/kasan/kasan_test_c.c:32: >> mm/kasan/kasan.h:585:6: warning: conflicting types for built-in function '__asan_before_dynamic_init'; expected 'void(const void *)' [-Wbuiltin-declaration-mismatch] 585 | void __asan_before_dynamic_init(const char *module_name); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ vim +585 mm/kasan/kasan.h 577 578 /* 579 * Exported functions for interfaces called from assembly or from generated 580 * code. Declared here to avoid warnings about missing declarations. 581 */ 582 583 void __asan_register_globals(void *globals, ssize_t size); 584 void __asan_unregister_globals(void *globals, ssize_t size); > 585 void __asan_before_dynamic_init(const char *module_name); 586 void __asan_after_dynamic_init(void); 587 void __asan_handle_no_return(void); 588 void __asan_alloca_poison(void *, ssize_t size); 589 void __asan_allocas_unpoison(void *stack_top, ssize_t stack_bottom); 590 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
On Tue, Jul 29, 2025 at 1:44 PM kernel test robot <lkp@intel.com> wrote: > > Hi Alexander, > > kernel test robot noticed the following build warnings: > > [auto build test WARNING on tip/x86/core] > [also build test WARNING on akpm-mm/mm-everything shuah-kselftest/next shuah-kselftest/fixes linus/master v6.16 next-20250729] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch#_base_tree_information] > > url: https://github.com/intel-lab-lkp/linux/commits/Alexander-Potapenko/x86-kcov-disable-instrumentation-of-arch-x86-kernel-tsc-c/20250728-232935 > base: tip/x86/core > patch link: https://lore.kernel.org/r/20250728152548.3969143-5-glider%40google.com > patch subject: [PATCH v3 04/10] mm/kasan: define __asan_before_dynamic_init, __asan_after_dynamic_init > config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20250729/202507291913.UMbUQv95-lkp@intel.com/config) > compiler: powerpc64-linux-gcc (GCC) 15.1.0 > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250729/202507291913.UMbUQv95-lkp@intel.com/reproduce) > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > the same patch/commit), kindly add following tags > | Reported-by: kernel test robot <lkp@intel.com> > | Closes: https://lore.kernel.org/oe-kbuild-all/202507291913.UMbUQv95-lkp@intel.com/ > > All warnings (new ones prefixed by >>): > > In file included from mm/kasan/kasan_test_c.c:32: > >> mm/kasan/kasan.h:585:6: warning: conflicting types for built-in function '__asan_before_dynamic_init'; expected 'void(const void *)' [-Wbuiltin-declaration-mismatch] > 585 | void __asan_before_dynamic_init(const char *module_name); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~ > For some reason GCC declares this function as a `void(const void *)`, whereas LLVM goes with `void @__asan_before_dynamic_init(i64)` (not to mention that ASan userspace runtime expects a const char * parameter). I'll change the prototype to match that from GCC, because Clang does not care much.
© 2016 - 2025 Red Hat, Inc.