Re: [PATCH] kasan: add declarations for internal functions

From: Dmitry Vyukov
Date: Fri Jan 05 2018 - 16:38:36 EST


On Fri, Jan 5, 2018 at 10:40 AM, Arnd Bergmann <arnd@xxxxxxxx> wrote:
> A patch got merged that made newly added functions static, leading
> to a warning about unused functions as well as a link error when
> they are actually used:
>
> mm/kasan/kasan.c:780:7: error: '__asan_set_shadow_f8' defined but not used [-Werror=unused-function]
> mm/kasan/kasan.c:791:8: note: in expansion of macro 'DEFINE_ASAN_SET_SHADOW'
> mm/kasan/kasan.c:780:7: error: '__asan_set_shadow_f5' defined but not used [-Werror=unused-function]
>
> It turns out the underlying problem is that a lot of the internal
> interfaces of the kasan implementation are only ever called from
> code generated by the compiler. These don't need any declarations
> to work fine, but cause warnings both with sparse and with 'make W=1':
>
> mm/kasan/kasan.c:695:1: warning: symbol '__asan_load1' was not declared. Should it be static?
> mm/kasan/kasan.c:695:1: warning: symbol '__asan_store1' was not declared. Should it be static?
> mm/kasan/kasan.c:696:1: warning: symbol '__asan_load2' was not declared. Should it be static?
> mm/kasan/kasan.c:696:1: warning: symbol '__asan_store2' was not declared. Should it be static?
> mm/kasan/kasan.c:697:1: warning: symbol '__asan_load4' was not declared. Should it be static?
>
> This removes the bogus 'static' annotation and adds declarations
> for all affected interfaces.
>
> Fixes: mmotm ("kasan: __asan_set_shadow_00 can be static")
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> mm/kasan/kasan.c | 12 ++++++------
> mm/kasan/kasan.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 50 insertions(+), 6 deletions(-)
>
> diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c
> index 83a11e7e3700..3fb497d4fbf8 100644
> --- a/mm/kasan/kasan.c
> +++ b/mm/kasan/kasan.c
> @@ -783,12 +783,12 @@ EXPORT_SYMBOL(__asan_allocas_unpoison);
> } \
> EXPORT_SYMBOL(__asan_set_shadow_##byte)
>
> -static DEFINE_ASAN_SET_SHADOW(00);
> -static DEFINE_ASAN_SET_SHADOW(f1);
> -static DEFINE_ASAN_SET_SHADOW(f2);
> -static DEFINE_ASAN_SET_SHADOW(f3);
> -static DEFINE_ASAN_SET_SHADOW(f5);
> -static DEFINE_ASAN_SET_SHADOW(f8);
> +DEFINE_ASAN_SET_SHADOW(00);
> +DEFINE_ASAN_SET_SHADOW(f1);
> +DEFINE_ASAN_SET_SHADOW(f2);
> +DEFINE_ASAN_SET_SHADOW(f3);
> +DEFINE_ASAN_SET_SHADOW(f5);
> +DEFINE_ASAN_SET_SHADOW(f8);
>
> #ifdef CONFIG_MEMORY_HOTPLUG
> static int __meminit kasan_mem_notifier(struct notifier_block *nb,
> diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
> index 2792de927fcd..c12dcfde2ebd 100644
> --- a/mm/kasan/kasan.h
> +++ b/mm/kasan/kasan.h
> @@ -120,4 +120,48 @@ static inline void quarantine_reduce(void) { }
> static inline void quarantine_remove_cache(struct kmem_cache *cache) { }
> #endif
>
> +/*
> + * Exported functions for interfaces called from assembly or from generated
> + * code. Declarations here to avoid warning about missing declarations.
> + */
> +asmlinkage void kasan_unpoison_task_stack_below(const void *watermark);
> +void __asan_register_globals(struct kasan_global *globals, size_t size);
> +void __asan_unregister_globals(struct kasan_global *globals, size_t size);
> +void __asan_loadN(unsigned long addr, size_t size);
> +void __asan_storeN(unsigned long addr, size_t size);
> +void __asan_handle_no_return(void);
> +void __asan_poison_stack_memory(const void *addr, size_t size);
> +void __asan_unpoison_stack_memory(const void *addr, size_t size);
> +void __asan_alloca_poison(unsigned long addr, size_t size);
> +void __asan_allocas_unpoison(const void *stack_top, const void *stack_bottom);
> +
> +void __asan_load1(unsigned long addr);
> +void __asan_store1(unsigned long addr);
> +void __asan_load2(unsigned long addr);
> +void __asan_store2(unsigned long addr);
> +void __asan_load4(unsigned long addr);
> +void __asan_store4(unsigned long addr);
> +void __asan_load8(unsigned long addr);
> +void __asan_store8(unsigned long addr);
> +void __asan_load16(unsigned long addr);
> +void __asan_store16(unsigned long addr);
> +
> +void __asan_load1_noabort(unsigned long addr);
> +void __asan_store1_noabort(unsigned long addr);
> +void __asan_load2_noabort(unsigned long addr);
> +void __asan_store2_noabort(unsigned long addr);
> +void __asan_load4_noabort(unsigned long addr);
> +void __asan_store4_noabort(unsigned long addr);
> +void __asan_load8_noabort(unsigned long addr);
> +void __asan_store8_noabort(unsigned long addr);
> +void __asan_load16_noabort(unsigned long addr);
> +void __asan_store16_noabort(unsigned long addr);
> +
> +void __asan_set_shadow_00(const void *addr, size_t size);
> +void __asan_set_shadow_f1(const void *addr, size_t size);
> +void __asan_set_shadow_f2(const void *addr, size_t size);
> +void __asan_set_shadow_f3(const void *addr, size_t size);
> +void __asan_set_shadow_f5(const void *addr, size_t size);
> +void __asan_set_shadow_f8(const void *addr, size_t size);
> +
> #endif


Acked-by: Dmitry Vyukov <dvyukov@xxxxxxxxxx>