Skip to contentSkip to conversation

kernel/kcsan/core.c:829:1: warning: no previous prototype for function '__tsan_volatile_read1'

PATCH kernel test robot 4 participants 6 messages Jun 5, 2020 – Jun 8, 2020

lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   af30725c132e2e5c5369b60369ff0771fde7d4ff
commit: 4e23395b9e97562d12b87a330a2fca3bf10c8663 [10774/15793] kcsan: Support distinguishing volatile accesses
config: x86_64-randconfig-r013-20200605 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 6dd738e2f0609f7d3313b574a1d471263d2d3ba1)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
git checkout 4e23395b9e97562d12b87a330a2fca3bf10c8663
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

DEFINE_TSAN_READ_WRITE(4);
^
kernel/kcsan/core.c:757:7: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
<scratch space>:92:1: note: expanded from here
__tsan_read4
^
kernel/kcsan/core.c:776:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_READ_WRITE(4);
^
static
kernel/kcsan/core.c:757:2: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
kernel/kcsan/core.c:776:1: warning: no previous prototype for function '__tsan_write4' [-Wmissing-prototypes] DEFINE_TSAN_READ_WRITE(4);
^
kernel/kcsan/core.c:765:7: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_write##size(void *ptr) ^
<scratch space>:126:1: note: expanded from here
__tsan_write4
^
kernel/kcsan/core.c:776:1: note: declare 'static' if the function is not intended to be used outside of this translation unit kernel/kcsan/core.c:765:2: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_write##size(void *ptr) ^
kernel/kcsan/core.c:777:1: warning: no previous prototype for function '__tsan_read8' [-Wmissing-prototypes] DEFINE_TSAN_READ_WRITE(8);
^
kernel/kcsan/core.c:757:7: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
<scratch space>:160:1: note: expanded from here
__tsan_read8
^
kernel/kcsan/core.c:777:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_READ_WRITE(8);
^
static
kernel/kcsan/core.c:757:2: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
kernel/kcsan/core.c:777:1: warning: no previous prototype for function '__tsan_write8' [-Wmissing-prototypes] DEFINE_TSAN_READ_WRITE(8);
^
kernel/kcsan/core.c:765:7: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_write##size(void *ptr) ^
<scratch space>:15:1: note: expanded from here
__tsan_write8
^
kernel/kcsan/core.c:777:1: note: declare 'static' if the function is not intended to be used outside of this translation unit kernel/kcsan/core.c:765:2: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_write##size(void *ptr) ^
kernel/kcsan/core.c:778:1: warning: no previous prototype for function '__tsan_read16' [-Wmissing-prototypes] DEFINE_TSAN_READ_WRITE(16);
^
kernel/kcsan/core.c:757:7: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
<scratch space>:49:1: note: expanded from here
__tsan_read16
^
kernel/kcsan/core.c:778:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_READ_WRITE(16);
^
static
kernel/kcsan/core.c:757:2: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
kernel/kcsan/core.c:778:1: warning: no previous prototype for function '__tsan_write16' [-Wmissing-prototypes] DEFINE_TSAN_READ_WRITE(16);
^
kernel/kcsan/core.c:765:7: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_write##size(void *ptr) ^
<scratch space>:83:1: note: expanded from here
__tsan_write16
^
kernel/kcsan/core.c:778:1: note: declare 'static' if the function is not intended to be used outside of this translation unit kernel/kcsan/core.c:765:2: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_write##size(void *ptr) ^
kernel/kcsan/core.c:780:6: warning: no previous prototype for function '__tsan_read_range' [-Wmissing-prototypes] void __tsan_read_range(void *ptr, size_t size)
^
kernel/kcsan/core.c:780:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void __tsan_read_range(void *ptr, size_t size)
^
static
kernel/kcsan/core.c:786:6: warning: no previous prototype for function '__tsan_write_range' [-Wmissing-prototypes] void __tsan_write_range(void *ptr, size_t size)
^
kernel/kcsan/core.c:786:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void __tsan_write_range(void *ptr, size_t size)
^
static

>> kernel/kcsan/core.c:829:1: warning: no previous prototype for function '__tsan_volatile_read1' [-Wmissing-prototypes]

DEFINE_TSAN_VOLATILE_READ_WRITE(1);
^
kernel/kcsan/core.c:802:7: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_read##size(void *ptr) ^
<scratch space>:145:1: note: expanded from here
__tsan_volatile_read1
^
kernel/kcsan/core.c:829:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_VOLATILE_READ_WRITE(1);
^
static
kernel/kcsan/core.c:802:2: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_read##size(void *ptr) ^

>> kernel/kcsan/core.c:829:1: warning: no previous prototype for function '__tsan_volatile_write1' [-Wmissing-prototypes]

DEFINE_TSAN_VOLATILE_READ_WRITE(1);
^
kernel/kcsan/core.c:814:7: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_write##size(void *ptr) ^
<scratch space>:18:1: note: expanded from here
__tsan_volatile_write1
^
kernel/kcsan/core.c:829:1: note: declare 'static' if the function is not intended to be used outside of this translation unit kernel/kcsan/core.c:814:2: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_write##size(void *ptr) ^

>> kernel/kcsan/core.c:830:1: warning: no previous prototype for function '__tsan_volatile_read2' [-Wmissing-prototypes]

DEFINE_TSAN_VOLATILE_READ_WRITE(2);
^
kernel/kcsan/core.c:802:7: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_read##size(void *ptr) ^
<scratch space>:56:1: note: expanded from here
__tsan_volatile_read2
^
kernel/kcsan/core.c:830:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_VOLATILE_READ_WRITE(2);
^
static
kernel/kcsan/core.c:802:2: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_read##size(void *ptr) ^

>> kernel/kcsan/core.c:830:1: warning: no previous prototype for function '__tsan_volatile_write2' [-Wmissing-prototypes]

DEFINE_TSAN_VOLATILE_READ_WRITE(2);
^
kernel/kcsan/core.c:814:7: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_write##size(void *ptr) ^
<scratch space>:94:1: note: expanded from here
__tsan_volatile_write2
^
kernel/kcsan/core.c:830:1: note: declare 'static' if the function is not intended to be used outside of this translation unit kernel/kcsan/core.c:814:2: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_write##size(void *ptr) ^

>> kernel/kcsan/core.c:831:1: warning: no previous prototype for function '__tsan_volatile_read4' [-Wmissing-prototypes]

DEFINE_TSAN_VOLATILE_READ_WRITE(4);
^
kernel/kcsan/core.c:802:7: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_read##size(void *ptr) ^
<scratch space>:6:1: note: expanded from here
__tsan_volatile_read4
^
kernel/kcsan/core.c:831:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_VOLATILE_READ_WRITE(4);
^
static
kernel/kcsan/core.c:802:2: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_read##size(void *ptr) ^

>> kernel/kcsan/core.c:831:1: warning: no previous prototype for function '__tsan_volatile_write4' [-Wmissing-prototypes]

DEFINE_TSAN_VOLATILE_READ_WRITE(4);
^
kernel/kcsan/core.c:814:7: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_write##size(void *ptr) ^
<scratch space>:44:1: note: expanded from here
__tsan_volatile_write4
^
kernel/kcsan/core.c:831:1: note: declare 'static' if the function is not intended to be used outside of this translation unit kernel/kcsan/core.c:814:2: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_write##size(void *ptr) ^

>> kernel/kcsan/core.c:832:1: warning: no previous prototype for function '__tsan_volatile_read8' [-Wmissing-prototypes]

DEFINE_TSAN_VOLATILE_READ_WRITE(8);
^
kernel/kcsan/core.c:802:7: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_read##size(void *ptr) ^
<scratch space>:82:1: note: expanded from here
__tsan_volatile_read8
^
kernel/kcsan/core.c:832:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_VOLATILE_READ_WRITE(8);
^
static
kernel/kcsan/core.c:802:2: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_read##size(void *ptr) ^

>> kernel/kcsan/core.c:832:1: warning: no previous prototype for function '__tsan_volatile_write8' [-Wmissing-prototypes]

DEFINE_TSAN_VOLATILE_READ_WRITE(8);
^
kernel/kcsan/core.c:814:7: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_write##size(void *ptr) ^
<scratch space>:120:1: note: expanded from here
__tsan_volatile_write8
^
kernel/kcsan/core.c:832:1: note: declare 'static' if the function is not intended to be used outside of this translation unit kernel/kcsan/core.c:814:2: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_write##size(void *ptr) ^

>> kernel/kcsan/core.c:833:1: warning: no previous prototype for function '__tsan_volatile_read16' [-Wmissing-prototypes]

DEFINE_TSAN_VOLATILE_READ_WRITE(16);
^
kernel/kcsan/core.c:802:7: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_read##size(void *ptr) ^
<scratch space>:30:1: note: expanded from here
__tsan_volatile_read16
^
kernel/kcsan/core.c:833:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_VOLATILE_READ_WRITE(16);
^
static
kernel/kcsan/core.c:802:2: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_read##size(void *ptr) ^

>> kernel/kcsan/core.c:833:1: warning: no previous prototype for function '__tsan_volatile_write16' [-Wmissing-prototypes]

DEFINE_TSAN_VOLATILE_READ_WRITE(16);
^
kernel/kcsan/core.c:814:7: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_write##size(void *ptr) ^
<scratch space>:68:1: note: expanded from here
__tsan_volatile_write16
^
kernel/kcsan/core.c:833:1: note: declare 'static' if the function is not intended to be used outside of this translation unit kernel/kcsan/core.c:814:2: note: expanded from macro 'DEFINE_TSAN_VOLATILE_READ_WRITE'
void __tsan_volatile_write##size(void *ptr) ^
kernel/kcsan/core.c:839:6: warning: no previous prototype for function '__tsan_func_entry' [-Wmissing-prototypes] void __tsan_func_entry(void *call_pc)
^
kernel/kcsan/core.c:839:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void __tsan_func_entry(void *call_pc)
^
static
kernel/kcsan/core.c:843:6: warning: no previous prototype for function '__tsan_func_exit' [-Wmissing-prototypes] void __tsan_func_exit(void)
^
kernel/kcsan/core.c:843:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void __tsan_func_exit(void)
^
static
kernel/kcsan/core.c:847:6: warning: no previous prototype for function '__tsan_init' [-Wmissing-prototypes] void __tsan_init(void)
^
kernel/kcsan/core.c:847:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void __tsan_init(void)
^
static
25 warnings generated.

vim +/__tsan_volatile_read1 +829 kernel/kcsan/core.c

791
792 /*
793 * Use of explicit volatile is generally disallowed [1], however, volatile is
794 * still used in various concurrent context, whether in low-level
795 * synchronization primitives or for legacy reasons.
796 * [1] https://lwn.net/Articles/233479/
797 *
798 * We only consider volatile accesses atomic if they are aligned and would pass
799 * the size-check of compiletime_assert_rwonce_type().
800 */
801 #define DEFINE_TSAN_VOLATILE_READ_WRITE(size) \
802 void __tsan_volatile_read##size(void *ptr) \
803 { \
804 const bool is_atomic = size <= sizeof(long long) && \
805 IS_ALIGNED((unsigned long)ptr, size); \
806 if (IS_ENABLED(CONFIG_KCSAN_IGNORE_ATOMICS) && is_atomic) \
807 return; \
808 check_access(ptr, size, is_atomic ? KCSAN_ACCESS_ATOMIC : 0); \

   809		}                                                                      \
   810		EXPORT_SYMBOL(__tsan_volatile_read##size);                             \
   811		void __tsan_unaligned_volatile_read##size(void *ptr)                   \
   812			__alias(__tsan_volatile_read##size);                           \
   813		EXPORT_SYMBOL(__tsan_unaligned_volatile_read##size);                   \
   814		void __tsan_volatile_write##size(void *ptr)                            \
   815		{                                                                      \
   816			const bool is_atomic = size <= sizeof(long long) &&            \
   817					       IS_ALIGNED((unsigned long)ptr, size);   \
   818			if (IS_ENABLED(CONFIG_KCSAN_IGNORE_ATOMICS) && is_atomic)      \
   819				return;                                                \
   820			check_access(ptr, size,                                        \
   821				     KCSAN_ACCESS_WRITE |                              \
   822					     (is_atomic ? KCSAN_ACCESS_ATOMIC : 0));   \
   823		}                                                                      \
   824		EXPORT_SYMBOL(__tsan_volatile_write##size);                            \
   825		void __tsan_unaligned_volatile_write##size(void *ptr)                  \
   826			__alias(__tsan_volatile_write##size);                          \
   827		EXPORT_SYMBOL(__tsan_unaligned_volatile_write##size)
   828	
 > 829	DEFINE_TSAN_VOLATILE_READ_WRITE(1);
 > 830	DEFINE_TSAN_VOLATILE_READ_WRITE(2);
 > 831	DEFINE_TSAN_VOLATILE_READ_WRITE(4);
 > 832	DEFINE_TSAN_VOLATILE_READ_WRITE(8);
 > 833	DEFINE_TSAN_VOLATILE_READ_WRITE(16);

834

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#1 lore raw
Quoted 20 lines · kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   af30725c132e2e5c5369b60369ff0771fde7d4ff
commit: 4e23395b9e97562d12b87a330a2fca3bf10c8663 [10774/15793] kcsan: Support distinguishing volatile accesses
config: x86_64-randconfig-r013-20200605 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 6dd738e2f0609f7d3313b574a1d471263d2d3ba1)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
git checkout 4e23395b9e97562d12b87a330a2fca3bf10c8663
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

Quoted 16 lines

DEFINE_TSAN_READ_WRITE(4);
^
kernel/kcsan/core.c:757:7: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
<scratch space>:92:1: note: expanded from here
__tsan_read4
^
kernel/kcsan/core.c:776:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_READ_WRITE(4);
^
static
kernel/kcsan/core.c:757:2: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
kernel/kcsan/core.c:776:1: warning: no previous prototype for function '__tsan_write4' [-Wmissing-prototypes] DEFINE_TSAN_READ_WRITE(4);
^

[...]

In the case here (and for all other *SAN or compiler-based instrumentation), it's clearly fine since the compiler is the one emitting calls to them.

How is one meant to act on W=1 reports like this? The kernel seems to be full of these. It seems wrong, just to shut up W=1, to start adding -Wno-missing-prototypes everywhere.

Thanks,
-- Marco

#2 lore raw
Quoted 40 lines · Marco Elver' via Clang Built Linux
Quoted 36 lines · kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   af30725c132e2e5c5369b60369ff0771fde7d4ff
commit: 4e23395b9e97562d12b87a330a2fca3bf10c8663 [10774/15793] kcsan: Support distinguishing volatile accesses
config: x86_64-randconfig-r013-20200605 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 6dd738e2f0609f7d3313b574a1d471263d2d3ba1)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
git checkout 4e23395b9e97562d12b87a330a2fca3bf10c8663
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

DEFINE_TSAN_READ_WRITE(4);
^
kernel/kcsan/core.c:757:7: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
<scratch space>:92:1: note: expanded from here
__tsan_read4
^
kernel/kcsan/core.c:776:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_READ_WRITE(4);
^
static
kernel/kcsan/core.c:757:2: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
kernel/kcsan/core.c:776:1: warning: no previous prototype for function '__tsan_write4' [-Wmissing-prototypes] DEFINE_TSAN_READ_WRITE(4);
^

[...]

Quoted 7 lines

In the case here (and for all other *SAN or compiler-based instrumentation), it's clearly fine since the compiler is the one emitting calls to them.

How is one meant to act on W=1 reports like this? The kernel seems to be full of these. It seems wrong, just to shut up W=1, to start adding -Wno-missing-prototypes everywhere.

+ Philip, because the team is probably getting asked this a lot, and should link to this response.

make W=1 enabled -Wmissing-prototypes via scripts/Makfile.extrawarn.

Both GCC and Clang will warn for -Wmissing-prototypes when you define a function without a previous declaration of it, for non-static functions. If the linkage is extern, and there was no previous declaration, then callers may have the wrong signature. Mostly, this isn't a bug, which is why it's not an error. But sometimes the signature has changed but the callers have not been updated, which is an ABI breakage resulting in a bug. Mostly this is not an issue due to -Wimplicit-function-declaration being on by default, which also helps in this case.

See: https://godbolt.org/z/aYrYfS

Functions with external linkage should have a forward declaration, or be marked static if in a .c file, or be marked static inline if in a header file.

For this specific case, it looks like kcsan.h should forward declare the functions defined by DEFINE_TSAN_READ_WRITE, to avoid any ABI mismatch due to different call signatures between callers and callee. Though I can't see where the callees are; if they're only within kernel/kcsan/core.c, then defining them as static qualified may be better. (Probably not, since they're exported via EXPORT_SYMBOL).

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw
Quoted 41 lines · Nick Desaulniers
Quoted 38 lines · Marco Elver' via Clang Built Linux
Quoted 36 lines · kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   af30725c132e2e5c5369b60369ff0771fde7d4ff
commit: 4e23395b9e97562d12b87a330a2fca3bf10c8663 [10774/15793] kcsan: Support distinguishing volatile accesses
config: x86_64-randconfig-r013-20200605 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 6dd738e2f0609f7d3313b574a1d471263d2d3ba1)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
git checkout 4e23395b9e97562d12b87a330a2fca3bf10c8663
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

DEFINE_TSAN_READ_WRITE(4);
^
kernel/kcsan/core.c:757:7: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
<scratch space>:92:1: note: expanded from here
__tsan_read4
^
kernel/kcsan/core.c:776:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_READ_WRITE(4);
^
static
kernel/kcsan/core.c:757:2: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
kernel/kcsan/core.c:776:1: warning: no previous prototype for function '__tsan_write4' [-Wmissing-prototypes] DEFINE_TSAN_READ_WRITE(4);
^

Quoted 5 lines
Quoted 5 lines

[...]

In the case here (and for all other *SAN or compiler-based instrumentation), it's clearly fine since the compiler is the one emitting calls to them.

I should have probably said "the compiler is the one emitting calls due to sanitizer instrumentation" to be clearer.

Quoted 25 lines
Quoted 3 lines

How is one meant to act on W=1 reports like this? The kernel seems to be full of these. It seems wrong, just to shut up W=1, to start adding -Wno-missing-prototypes everywhere.

+ Philip, because the team is probably getting asked this a lot, and should link to this response.

make W=1 enabled -Wmissing-prototypes via scripts/Makfile.extrawarn.

Both GCC and Clang will warn for -Wmissing-prototypes when you define a function without a previous declaration of it, for non-static functions. If the linkage is extern, and there was no previous declaration, then callers may have the wrong signature. Mostly, this isn't a bug, which is why it's not an error. But sometimes the signature has changed but the callers have not been updated, which is an ABI breakage resulting in a bug. Mostly this is not an issue due to -Wimplicit-function-declaration being on by default, which also helps in this case.

See: https://godbolt.org/z/aYrYfS

Functions with external linkage should have a forward declaration, or be marked static if in a .c file, or be marked static inline if in a header file.

Quoted 6 lines

For this specific case, it looks like kcsan.h should forward declare the functions defined by DEFINE_TSAN_READ_WRITE, to avoid any ABI mismatch due to different call signatures between callers and callee. Though I can't see where the callees are; if they're only within kernel/kcsan/core.c, then defining them as static qualified may be better. (Probably not, since they're exported via EXPORT_SYMBOL).

Thanks for the explanation. And I agree in the general case this is a fine warning.

However, the functions here should not be forward declared anywhere, as they should *only* be emitted by the compiler due to sanitizer instrumentation. In the case here it's "-fsanitize=thread". Same thing for KASAN with "-fsanitize=kernel-address". Or UBSAN. None of them should be forward declared for access by other parts of the kernel explicitly. Forward declaring these also doesn't help prevent ABI breakage, since it's the compiler generating the calls.

Let me rephrase my question: what is the idiomatic way to deal with the warnings for the sanitizers, where the functions are runtime functions only emitted by the compiler due to instrumentation? We can add forward declarations 1 line above where they are defined, just for the sake of shutting up the warning specifically for these functions. I can send a patch if that's what we want.

Thanks,
-- Marco

#4 lore raw
Quoted 7 lines · Marco Elver

Let me rephrase my question: what is the idiomatic way to deal with the warnings for the sanitizers, where the functions are runtime functions only emitted by the compiler due to instrumentation? We can add forward declarations 1 line above where they are defined, just for the sake of shutting up the warning specifically for these functions. I can send a patch if that's what we want.

I don't know that's there's an idiomatic way for the specific case of compiler emitted calls, but your suggestion sounds fine. You can test it with make W=1 or manually setting -Wmissing-prototypes for KBUILD_CFLAGS. (I think you can even set that variable to that string in a make command line arg, ie. make KBUILD_CFLAGS="-Wmissing-prototypes (untested).

Signature · 2 lines
Thanks,
~Nick Desaulniers
#5 lore raw
In reply to Nick Desaulniers
Quoted 46 lines · Nick Desaulniers
Quoted 44 lines · Marco Elver' via Clang Built Linux
Quoted 20 lines · kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   af30725c132e2e5c5369b60369ff0771fde7d4ff
commit: 4e23395b9e97562d12b87a330a2fca3bf10c8663 [10774/15793] kcsan: Support distinguishing volatile accesses
config: x86_64-randconfig-r013-20200605 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 6dd738e2f0609f7d3313b574a1d471263d2d3ba1)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
git checkout 4e23395b9e97562d12b87a330a2fca3bf10c8663
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

Quoted 16 lines

DEFINE_TSAN_READ_WRITE(4);
^
kernel/kcsan/core.c:757:7: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
<scratch space>:92:1: note: expanded from here
__tsan_read4
^
kernel/kcsan/core.c:776:1: note: declare 'static' if the function is not intended to be used outside of this translation unit DEFINE_TSAN_READ_WRITE(4);
^
static
kernel/kcsan/core.c:757:2: note: expanded from macro 'DEFINE_TSAN_READ_WRITE'
void __tsan_read##size(void *ptr) ^
kernel/kcsan/core.c:776:1: warning: no previous prototype for function '__tsan_write4' [-Wmissing-prototypes] DEFINE_TSAN_READ_WRITE(4);
^

[...]

In the case here (and for all other *SAN or compiler-based instrumentation), it's clearly fine since the compiler is the one emitting calls to them.

Quoted 6 lines
Quoted 3 lines

How is one meant to act on W=1 reports like this? The kernel seems to be full of these. It seems wrong, just to shut up W=1, to start adding -Wno-missing-prototypes everywhere.

+ Philip, because the team is probably getting asked this a lot, and should link to this response.

thanks a lot, i had added your response at https://github.com/intel/lkp-tests/wiki/LKP-FAQ
which is very helpful to explain this.

Quoted 28 lines

make W=1 enabled -Wmissing-prototypes via scripts/Makfile.extrawarn.

Both GCC and Clang will warn for -Wmissing-prototypes when you define a function without a previous declaration of it, for non-static functions. If the linkage is extern, and there was no previous declaration, then callers may have the wrong signature. Mostly, this isn't a bug, which is why it's not an error. But sometimes the signature has changed but the callers have not been updated, which is an ABI breakage resulting in a bug. Mostly this is not an issue due to -Wimplicit-function-declaration being on by default, which also helps in this case.

See: https://godbolt.org/z/aYrYfS

Functions with external linkage should have a forward declaration, or be marked static if in a .c file, or be marked static inline if in a header file.

For this specific case, it looks like kcsan.h should forward declare the functions defined by DEFINE_TSAN_READ_WRITE, to avoid any ABI mismatch due to different call signatures between callers and callee. Though I can't see where the callees are; if they're only within kernel/kcsan/core.c, then defining them as static qualified may be better. (Probably not, since they're exported via EXPORT_SYMBOL).

Signature · 2 lines
Thanks,
~Nick Desaulniers