Skip to content

Commit

Permalink
compiler-gcc: Suppress -Wmissing-prototypes warning for all supported…
Browse files Browse the repository at this point in the history
… GCC

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. "#pragma GCC diagnostic push" is supported as
of GCC 4.6, and both "-Wmissing-prototypes" and "-Wmissing-declarations"
are supported for all the GCC versions that we currently support.
Therefore, it is reasonable to suppress these warnings for all supported
GCC versions.

With this adjustment, it's important to note that after implementing
"__diag_ignore_all", it will effectively suppress warnings for all the
supported GCC versions.

In the future, if you wish to suppress warnings that are only supported on
higher GCC versions, it is advisable to explicitly use "__diag_ignore" to
specify the GCC version you are targeting.

Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Suggested-by: Arnd Bergmann <[email protected]>
Signed-off-by: Yafang Shao <[email protected]>
Cc: Kumar Kartikeya Dwivedi <[email protected]>
Cc: Arnd Bergmann <[email protected]>
  • Loading branch information
laoar authored and d-e-s-o committed Nov 9, 2023
1 parent b7b6ef0 commit a1538b4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/linux/compiler-gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
#endif

#define __diag_ignore_all(option, comment) \
__diag_GCC(8, ignore, option)
__diag(__diag_GCC_ignore option)

/*
* Prior to 9.1, -Wno-alloc-size-larger-than (and therefore the "alloc_size"
Expand Down

0 comments on commit a1538b4

Please sign in to comment.