diff mbox series

Makefile: use -Wno-main in the full kernel tree

Message ID 20210813224131.25803-1-rdunlap@infradead.org (mailing list archive)
State New, archived
Headers show
Series Makefile: use -Wno-main in the full kernel tree | expand

Commit Message

Randy Dunlap Aug. 13, 2021, 10:41 p.m. UTC
When using gcc (SUSE Linux) 7.5.0 (on openSUSE 15.3), I see a
build warning:

../kernel/trace/trace_osnoise.c: In function 'start_kthread':
../kernel/trace/trace_osnoise.c:1461:8: warning: 'main' is usually a function [-Wmain]
  void *main = osnoise_main;
        ^~~~

Quieten that warning by using "-Wno-main". It's OK to use "main" as a
declaration name in the kernel.

Build-tested on most ARCHes.

Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Daniel Bristot de Oliveira <bristot@kernel.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michal Marek <michal.lkml@markovi.net>
Cc: linux-kbuild@vger.kernel.org
---
 Makefile |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Linus Torvalds Aug. 14, 2021, 12:01 a.m. UTC | #1
On Fri, Aug 13, 2021 at 12:41 PM Randy Dunlap <rdunlap@infradead.org> wrote:
>
> Build-tested on most ARCHes.

How about old versions of gcc? Or clang?

From a quick google, it seems like '-Wmain' means something else for
clang. But it is probably ok.

                 Linus
Randy Dunlap Aug. 14, 2021, 12:29 a.m. UTC | #2
On 8/13/21 5:01 PM, Linus Torvalds wrote:
> On Fri, Aug 13, 2021 at 12:41 PM Randy Dunlap <rdunlap@infradead.org> wrote:
>>
>> Build-tested on most ARCHes.
> 
> How about old versions of gcc? Or clang?
> 
>  From a quick google, it seems like '-Wmain' means something else for
> clang. But it is probably ok.

Dunno. Let's just let it ride in linux-next for a bit to see what it hits.
Steven Rostedt Aug. 16, 2021, 3:08 p.m. UTC | #3
On Fri, 13 Aug 2021 15:41:31 -0700
Randy Dunlap <rdunlap@infradead.org> wrote:

> When using gcc (SUSE Linux) 7.5.0 (on openSUSE 15.3), I see a
> build warning:
> 
> ../kernel/trace/trace_osnoise.c: In function 'start_kthread':
> ../kernel/trace/trace_osnoise.c:1461:8: warning: 'main' is usually a function [-Wmain]
>   void *main = osnoise_main;
>         ^~~~
> 
> Quieten that warning by using "-Wno-main". It's OK to use "main" as a
> declaration name in the kernel.
> 
> Build-tested on most ARCHes.
> 
> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> Suggested-by: Steven Rostedt <rostedt@goodmis.org>
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Daniel Bristot de Oliveira <bristot@kernel.org>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: Michal Marek <michal.lkml@markovi.net>
> Cc: linux-kbuild@vger.kernel.org
> ---
>  Makefile |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- linux-next-20210812.orig/Makefile
> +++ linux-next-20210812/Makefile
> @@ -522,7 +522,7 @@ KBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-P
>  KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
>  		   -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
>  		   -Werror=implicit-function-declaration -Werror=implicit-int \
> -		   -Werror=return-type -Wno-format-security \
> +		   -Werror=return-type -Wno-format-security -Wno-main \

Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

>  		   -std=gnu89
>  KBUILD_CPPFLAGS := -D__KERNEL__
>  KBUILD_RUST_TARGET := $(srctree)/arch/$(SRCARCH)/rust/target.json
Linus Torvalds Aug. 17, 2021, 12:33 a.m. UTC | #4
On Fri, Aug 13, 2021 at 2:01 PM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> From a quick google, it seems like '-Wmain' means something else for
> clang. But it is probably ok.

So the warnings that clang gives with -Wmain seem to be much more reasonable.

Which makes me think that the '-Wno-main' thing would likely be better
as a gcc-only thing.

Maybe something like this instead?

              Linus
Linus Torvalds Aug. 17, 2021, 12:38 a.m. UTC | #5
On Mon, Aug 16, 2021 at 2:33 PM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> So the warnings that clang gives with -Wmain seem to be much more reasonable.

In fact, I can't recreate the warning even with gcc and -Wmain.

I get the feeling that this was a temporary misake in gcc, and perhaps
only warns in a few very specific versions, and the gcc people already
fixed this long ago.

Oh well.

              Linus
Randy Dunlap Aug. 17, 2021, 1:01 a.m. UTC | #6
On 8/16/21 5:38 PM, Linus Torvalds wrote:
> On Mon, Aug 16, 2021 at 2:33 PM Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
>>
>> So the warnings that clang gives with -Wmain seem to be much more reasonable.
> 
> In fact, I can't recreate the warning even with gcc and -Wmain.
> 
> I get the feeling that this was a temporary misake in gcc, and perhaps
> only warns in a few very specific versions, and the gcc people already
> fixed this long ago.
> 
> Oh well.

That sounds likely. We can just ignore this if you had rather go that way.
Linus Torvalds Aug. 17, 2021, 1:31 a.m. UTC | #7
On Mon, Aug 16, 2021 at 3:01 PM Randy Dunlap <rdunlap@infradead.org> wrote:
>
> That sounds likely. We can just ignore this if you had rather go that way.

I'm happy doing it, I don't think the Wmain warnings buy anything for
the kernel. My main worry is just that some compiler version might not
support it at all or similar, and it would cause problems that way.

Which is really the only reason why I'd like to narrow it down as much
as (trivially) possible.

It doesn't sound worth trying to pinpoint exact gcc version, but
making it gcc-only would at least narrow it down a _bit_.

                  Linus
Steven Rostedt Aug. 17, 2021, 2:05 a.m. UTC | #8
On Mon, 16 Aug 2021 15:31:33 -1000
Linus Torvalds <torvalds@linux-foundation.org> wrote:

> On Mon, Aug 16, 2021 at 3:01 PM Randy Dunlap <rdunlap@infradead.org> wrote:
> >
> > That sounds likely. We can just ignore this if you had rather go that way.  
> 
> I'm happy doing it, I don't think the Wmain warnings buy anything for
> the kernel. My main worry is just that some compiler version might not
> support it at all or similar, and it would cause problems that way.
> 
> Which is really the only reason why I'd like to narrow it down as much
> as (trivially) possible.
> 
> It doesn't sound worth trying to pinpoint exact gcc version, but
> making it gcc-only would at least narrow it down a _bit_.

Looks to me that -Wmain and -Wno-main have been in gcc for a long time.
If we limit it to just gcc, I believe it will not be an issue for any
compiler version the kernel supports.

  https://gcc.gnu.org/onlinedocs/gcc/Option-Index.html

And perhaps you are correct, as this is not a new option (it's in all
the gcc versions I have (tested back to 4.2.4)), and it didn't trigger
for me, I too believe this was a bug in a particular version that Randy
used.

-- Steve
Randy Dunlap Aug. 21, 2021, 11:26 p.m. UTC | #9
On 8/16/21 5:33 PM, Linus Torvalds wrote:
> On Fri, Aug 13, 2021 at 2:01 PM Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
>>
>>  From a quick google, it seems like '-Wmain' means something else for
>> clang. But it is probably ok.
> 
> So the warnings that clang gives with -Wmain seem to be much more reasonable.
> 
> Which makes me think that the '-Wno-main' thing would likely be better
> as a gcc-only thing.
> 
> Maybe something like this instead?
> 
>                Linus

Tested-by: Randy Dunlap <rdunlap@infradead.org>

Should I resend the full patch?

Thanks.
Randy Dunlap Sept. 7, 2021, 10:42 p.m. UTC | #10
On 8/16/21 5:33 PM, Linus Torvalds wrote:
> On Fri, Aug 13, 2021 at 2:01 PM Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
>>
>>  From a quick google, it seems like '-Wmain' means something else for
>> clang. But it is probably ok.
> 
> So the warnings that clang gives with -Wmain seem to be much more reasonable.
> 
> Which makes me think that the '-Wno-main' thing would likely be better
> as a gcc-only thing.
> 
> Maybe something like this instead?
> 
>                Linus
> 

Linus,

Can we get your version of this patch merged?


Tested-by: Randy Dunlap <rdunlap@infradead.org>

Should I resend the full patch?

---
  Makefile | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/Makefile b/Makefile
index c19d1638da25..a33fba083df7 100644
--- a/Makefile
+++ b/Makefile
@@ -803,6 +803,8 @@ else
  # Disabled for clang while comment to attribute conversion happens and
  # https://github.com/ClangBuiltLinux/linux/issues/636 is discussed.
  KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=5,)
+# gcc inanely warns about local variables called 'main'
+KBUILD_CFLAGS += -Wno-main
  endif
  
  # These warnings generated too much noise in a regular build.
diff mbox series

Patch

--- linux-next-20210812.orig/Makefile
+++ linux-next-20210812/Makefile
@@ -522,7 +522,7 @@  KBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-P
 KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
 		   -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
 		   -Werror=implicit-function-declaration -Werror=implicit-int \
-		   -Werror=return-type -Wno-format-security \
+		   -Werror=return-type -Wno-format-security -Wno-main \
 		   -std=gnu89
 KBUILD_CPPFLAGS := -D__KERNEL__
 KBUILD_RUST_TARGET := $(srctree)/arch/$(SRCARCH)/rust/target.json