diff mbox series

[bpf-next] compiler-gcc: Ignore -Wmissing-prototypes warning for older GCC

Message ID 20231105062227.4190-1-laoar.shao@gmail.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next] compiler-gcc: Ignore -Wmissing-prototypes warning for older GCC | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 16002 this patch: 14665
netdev/cc_maintainers warning 4 maintainers not CCed: nathan@kernel.org akpm@linux-foundation.org elver@google.com ojeda@kernel.org
netdev/build_clang success Errors and warnings before: 1378 this patch: 1378
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 17265 this patch: 15774
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-3 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-16 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-llvm-16 / build / build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-llvm-16 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-llvm-16 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-16 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-16 / veristat
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-16 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc

Commit Message

Yafang Shao Nov. 5, 2023, 6:22 a.m. UTC
The kernel supports a minimum GCC version of 5.1.0 for building. However,
the "__diag_ignore_all" directive only suppresses the
"-Wmissing-prototypes" warning for GCC versions >= 8.0.0. As a result, when
building the kernel with older GCC versions, warnings may be triggered. The
example below illustrates the warnings reported by the kernel test robot
using GCC 7.5.0:

  compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
  All warnings (new ones prefixed by >>):

   kernel/bpf/helpers.c:1893:19: warning: no previous prototype for 'bpf_obj_new_impl' [-Wmissing-prototypes]
    __bpf_kfunc void *bpf_obj_new_impl(u64 local_type_id__k, void *meta__ign)
                      ^~~~~~~~~~~~~~~~
   kernel/bpf/helpers.c:1907:19: warning: no previous prototype for 'bpf_percpu_obj_new_impl' [-Wmissing-prototypes]
    __bpf_kfunc void *bpf_percpu_obj_new_impl(u64 local_type_id__k, void *meta__ign)
   [...]

To address this, we should also suppress the "-Wmissing-prototypes" warning
for older GCC versions. Since "#pragma GCC diagnostic push" is supported as
of GCC 4.6, it is acceptable to ignore these warnings for GCC >= 5.1.0.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202311031651.A7crZEur-lkp@intel.com/
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
---
 include/linux/compiler-gcc.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Arnd Bergmann Nov. 5, 2023, 8:24 a.m. UTC | #1
On Sun, Nov 5, 2023, at 07:22, Yafang Shao wrote:
> The kernel supports a minimum GCC version of 5.1.0 for building. However,
> the "__diag_ignore_all" directive only suppresses the
> "-Wmissing-prototypes" warning for GCC versions >= 8.0.0. As a result, when
> building the kernel with older GCC versions, warnings may be triggered. The
> example below illustrates the warnings reported by the kernel test robot
> using GCC 7.5.0:
>
>   compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
>   All warnings (new ones prefixed by >>):
>
>    kernel/bpf/helpers.c:1893:19: warning: no previous prototype for 
> 'bpf_obj_new_impl' [-Wmissing-prototypes]
>     __bpf_kfunc void *bpf_obj_new_impl(u64 local_type_id__k, void 
> *meta__ign)
>                       ^~~~~~~~~~~~~~~~
>    kernel/bpf/helpers.c:1907:19: warning: no previous prototype for 
> 'bpf_percpu_obj_new_impl' [-Wmissing-prototypes]
>     __bpf_kfunc void *bpf_percpu_obj_new_impl(u64 local_type_id__k, 
> void *meta__ign)
>    [...]
>
> To address this, we should also suppress the "-Wmissing-prototypes" warning
> for older GCC versions. Since "#pragma GCC diagnostic push" is supported as
> of GCC 4.6, it is acceptable to ignore these warnings for GCC >= 5.1.0.

Not sure why these need to be suppressed like this at all,
can't you just add the prototype somewhere?

> @@ -131,14 +131,14 @@
>  #define __diag_str(s)		__diag_str1(s)
>  #define __diag(s)		_Pragma(__diag_str(GCC diagnostic s))
> 
> -#if GCC_VERSION >= 80000
> -#define __diag_GCC_8(s)		__diag(s)
> +#if GCC_VERSION >= 50100
> +#define __diag_GCC_5(s)		__diag(s)
>  #else
> -#define __diag_GCC_8(s)
> +#define __diag_GCC_5(s)
>  #endif
> 

This breaks all uses of __diag_ignore that specify
version 8 directly. Just add the macros for each version
from 5 to 14 here.

     Arnd
Yafang Shao Nov. 5, 2023, 11:54 a.m. UTC | #2
On Sun, Nov 5, 2023 at 4:24 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Sun, Nov 5, 2023, at 07:22, Yafang Shao wrote:
> > The kernel supports a minimum GCC version of 5.1.0 for building. However,
> > the "__diag_ignore_all" directive only suppresses the
> > "-Wmissing-prototypes" warning for GCC versions >= 8.0.0. As a result, when
> > building the kernel with older GCC versions, warnings may be triggered. The
> > example below illustrates the warnings reported by the kernel test robot
> > using GCC 7.5.0:
> >
> >   compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
> >   All warnings (new ones prefixed by >>):
> >
> >    kernel/bpf/helpers.c:1893:19: warning: no previous prototype for
> > 'bpf_obj_new_impl' [-Wmissing-prototypes]
> >     __bpf_kfunc void *bpf_obj_new_impl(u64 local_type_id__k, void
> > *meta__ign)
> >                       ^~~~~~~~~~~~~~~~
> >    kernel/bpf/helpers.c:1907:19: warning: no previous prototype for
> > 'bpf_percpu_obj_new_impl' [-Wmissing-prototypes]
> >     __bpf_kfunc void *bpf_percpu_obj_new_impl(u64 local_type_id__k,
> > void *meta__ign)
> >    [...]
> >
> > To address this, we should also suppress the "-Wmissing-prototypes" warning
> > for older GCC versions. Since "#pragma GCC diagnostic push" is supported as
> > of GCC 4.6, it is acceptable to ignore these warnings for GCC >= 5.1.0.
>
> Not sure why these need to be suppressed like this at all,
> can't you just add the prototype somewhere?

BPF kfuncs are intended for use within BPF programs, and they should
not be called from other parts of the kernel. Consequently, it is not
appropriate to include their prototypes in a kernel header file.

>
> > @@ -131,14 +131,14 @@
> >  #define __diag_str(s)                __diag_str1(s)
> >  #define __diag(s)            _Pragma(__diag_str(GCC diagnostic s))
> >
> > -#if GCC_VERSION >= 80000
> > -#define __diag_GCC_8(s)              __diag(s)
> > +#if GCC_VERSION >= 50100
> > +#define __diag_GCC_5(s)              __diag(s)
> >  #else
> > -#define __diag_GCC_8(s)
> > +#define __diag_GCC_5(s)
> >  #endif
> >
>
> This breaks all uses of __diag_ignore that specify
> version 8 directly. Just add the macros for each version
> from 5 to 14 here.

It seems that __diag_GCC_8() or __diag_GCC() are not directly used
anywhere in the kernel, right?
Therefore it won't break anything if we just replace __diag_GCC_8()
with __diag_GCC_5().
It may be cumbersome to add the macrocs for every GCC version if they
aren't actively used.

--
Regards
Yafang
Arnd Bergmann Nov. 5, 2023, 1:01 p.m. UTC | #3
On Sun, Nov 5, 2023, at 12:54, Yafang Shao wrote:
> On Sun, Nov 5, 2023 at 4:24 PM Arnd Bergmann <arnd@arndb.de> wrote:
>> On Sun, Nov 5, 2023, at 07:22, Yafang Shao wrote:
>> > To address this, we should also suppress the "-Wmissing-prototypes" warning
>> > for older GCC versions. Since "#pragma GCC diagnostic push" is supported as
>> > of GCC 4.6, it is acceptable to ignore these warnings for GCC >= 5.1.0.
>>
>> Not sure why these need to be suppressed like this at all,
>> can't you just add the prototype somewhere?
>
> BPF kfuncs are intended for use within BPF programs, and they should
> not be called from other parts of the kernel. Consequently, it is not
> appropriate to include their prototypes in a kernel header file.

How does the caller in the BPF program get the prototype?

>> > @@ -131,14 +131,14 @@
>> >  #define __diag_str(s)                __diag_str1(s)
>> >  #define __diag(s)            _Pragma(__diag_str(GCC diagnostic s))
>> >
>> > -#if GCC_VERSION >= 80000
>> > -#define __diag_GCC_8(s)              __diag(s)
>> > +#if GCC_VERSION >= 50100
>> > +#define __diag_GCC_5(s)              __diag(s)
>> >  #else
>> > -#define __diag_GCC_8(s)
>> > +#define __diag_GCC_5(s)
>> >  #endif
>> >
>>
>> This breaks all uses of __diag_ignore that specify
>> version 8 directly. Just add the macros for each version
>> from 5 to 14 here.
>
> It seems that __diag_GCC_8() or __diag_GCC() are not directly used
> anywhere in the kernel, right?

I see three instances:

drivers/net/ethernet/renesas/sh_eth.c:__diag_ignore(GCC, 8, "-Woverride-init",
include/linux/compat.h:     __diag_ignore(GCC, 8, "-Wattribute-alias",                              include/linux/syscalls.h:   __diag_ignore(GCC, 8, "-Wattribute-alias",                      

The override-init one should probably use version 5 as well,
but I think the -Wattribute-alias ones require GCC 8 and otherwise
cause a warning about an unknown warning option.

__diag_ignore_all() would also be wrong for the override-init
because the option has a different name in clang
(-Winitializer-overrides).

> Therefore it won't break anything if we just replace __diag_GCC_8()
> with __diag_GCC_5().
> It may be cumbersome to add the macrocs for every GCC version if they
> aren't actively used.

For the _all variant, I would prefer to completely remove
the version logic and just use __diag() directly. I think the
entire point of this is that it is used on all supported
versions.

      Arnd
Yafang Shao Nov. 5, 2023, 1:50 p.m. UTC | #4
On Sun, Nov 5, 2023 at 9:01 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Sun, Nov 5, 2023, at 12:54, Yafang Shao wrote:
> > On Sun, Nov 5, 2023 at 4:24 PM Arnd Bergmann <arnd@arndb.de> wrote:
> >> On Sun, Nov 5, 2023, at 07:22, Yafang Shao wrote:
> >> > To address this, we should also suppress the "-Wmissing-prototypes" warning
> >> > for older GCC versions. Since "#pragma GCC diagnostic push" is supported as
> >> > of GCC 4.6, it is acceptable to ignore these warnings for GCC >= 5.1.0.
> >>
> >> Not sure why these need to be suppressed like this at all,
> >> can't you just add the prototype somewhere?
> >
> > BPF kfuncs are intended for use within BPF programs, and they should
> > not be called from other parts of the kernel. Consequently, it is not
> > appropriate to include their prototypes in a kernel header file.
>
> How does the caller in the BPF program get the prototype?

BPF programs will get the prototype directly from BTF, for example,
see also the prototypes declared using "__ksym"  in
tools/testing/selftests/bpf/progs/ for examples.

>
> >> > @@ -131,14 +131,14 @@
> >> >  #define __diag_str(s)                __diag_str1(s)
> >> >  #define __diag(s)            _Pragma(__diag_str(GCC diagnostic s))
> >> >
> >> > -#if GCC_VERSION >= 80000
> >> > -#define __diag_GCC_8(s)              __diag(s)
> >> > +#if GCC_VERSION >= 50100
> >> > +#define __diag_GCC_5(s)              __diag(s)
> >> >  #else
> >> > -#define __diag_GCC_8(s)
> >> > +#define __diag_GCC_5(s)
> >> >  #endif
> >> >
> >>
> >> This breaks all uses of __diag_ignore that specify
> >> version 8 directly. Just add the macros for each version
> >> from 5 to 14 here.
> >
> > It seems that __diag_GCC_8() or __diag_GCC() are not directly used
> > anywhere in the kernel, right?
>
> I see three instances:
>
> drivers/net/ethernet/renesas/sh_eth.c:__diag_ignore(GCC, 8, "-Woverride-init",
> include/linux/compat.h:     __diag_ignore(GCC, 8, "-Wattribute-alias",                              include/linux/syscalls.h:   __diag_ignore(GCC, 8, "-Wattribute-alias",

Thanks for pointing them out.

>
> The override-init one should probably use version 5 as well,
> but I think the -Wattribute-alias ones require GCC 8 and otherwise
> cause a warning about an unknown warning option.

Right. -Wattribute-alias requires GCC 8.

>
> __diag_ignore_all() would also be wrong for the override-init
> because the option has a different name in clang
> (-Winitializer-overrides).
>
> > Therefore it won't break anything if we just replace __diag_GCC_8()
> > with __diag_GCC_5().
> > It may be cumbersome to add the macrocs for every GCC version if they
> > aren't actively used.
>
> For the _all variant, I would prefer to completely remove
> the version logic and just use __diag() directly. I think the
> entire point of this is that it is used on all supported
> versions.

Good suggestion.
will do it.
diff mbox series

Patch

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 7af9e34..a5cfcad 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -131,14 +131,14 @@ 
 #define __diag_str(s)		__diag_str1(s)
 #define __diag(s)		_Pragma(__diag_str(GCC diagnostic s))
 
-#if GCC_VERSION >= 80000
-#define __diag_GCC_8(s)		__diag(s)
+#if GCC_VERSION >= 50100
+#define __diag_GCC_5(s)		__diag(s)
 #else
-#define __diag_GCC_8(s)
+#define __diag_GCC_5(s)
 #endif
 
 #define __diag_ignore_all(option, comment) \
-	__diag_GCC(8, ignore, option)
+	__diag_GCC(5, ignore, option)
 
 /*
  * Prior to 9.1, -Wno-alloc-size-larger-than (and therefore the "alloc_size"