linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Makefile: use -Wno-main in the full kernel tree
@ 2021-08-13 22:41 Randy Dunlap
  2021-08-14  0:01 ` Linus Torvalds
  2021-08-16 15:08 ` Steven Rostedt
  0 siblings, 2 replies; 11+ messages in thread
From: Randy Dunlap @ 2021-08-13 22:41 UTC (permalink / raw)
  To: linux-kernel
  Cc: Randy Dunlap, Steven Rostedt, Linus Torvalds,
	Daniel Bristot de Oliveira, Masahiro Yamada, Michal Marek,
	linux-kbuild

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 \
 		   -std=gnu89
 KBUILD_CPPFLAGS := -D__KERNEL__
 KBUILD_RUST_TARGET := $(srctree)/arch/$(SRCARCH)/rust/target.json

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Makefile: use -Wno-main in the full kernel tree
  2021-08-13 22:41 [PATCH] Makefile: use -Wno-main in the full kernel tree Randy Dunlap
@ 2021-08-14  0:01 ` Linus Torvalds
  2021-08-14  0:29   ` Randy Dunlap
  2021-08-17  0:33   ` Linus Torvalds
  2021-08-16 15:08 ` Steven Rostedt
  1 sibling, 2 replies; 11+ messages in thread
From: Linus Torvalds @ 2021-08-14  0:01 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Linux Kernel Mailing List, Steven Rostedt,
	Daniel Bristot de Oliveira, Masahiro Yamada, Michal Marek,
	Linux Kbuild mailing list

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Makefile: use -Wno-main in the full kernel tree
  2021-08-14  0:01 ` Linus Torvalds
@ 2021-08-14  0:29   ` Randy Dunlap
  2021-08-17  0:33   ` Linus Torvalds
  1 sibling, 0 replies; 11+ messages in thread
From: Randy Dunlap @ 2021-08-14  0:29 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Linux Kernel Mailing List, Steven Rostedt,
	Daniel Bristot de Oliveira, Masahiro Yamada, Michal Marek,
	Linux Kbuild mailing list

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.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Makefile: use -Wno-main in the full kernel tree
  2021-08-13 22:41 [PATCH] Makefile: use -Wno-main in the full kernel tree Randy Dunlap
  2021-08-14  0:01 ` Linus Torvalds
@ 2021-08-16 15:08 ` Steven Rostedt
  1 sibling, 0 replies; 11+ messages in thread
From: Steven Rostedt @ 2021-08-16 15:08 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: linux-kernel, Linus Torvalds, Daniel Bristot de Oliveira,
	Masahiro Yamada, Michal Marek, linux-kbuild

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Makefile: use -Wno-main in the full kernel tree
  2021-08-14  0:01 ` Linus Torvalds
  2021-08-14  0:29   ` Randy Dunlap
@ 2021-08-17  0:33   ` Linus Torvalds
  2021-08-17  0:38     ` Linus Torvalds
                       ` (2 more replies)
  1 sibling, 3 replies; 11+ messages in thread
From: Linus Torvalds @ 2021-08-17  0:33 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Linux Kernel Mailing List, Steven Rostedt,
	Daniel Bristot de Oliveira, Masahiro Yamada, Michal Marek,
	Linux Kbuild mailing list

[-- Attachment #1: Type: text/plain, Size: 420 bytes --]

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

[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 539 bytes --]

 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.

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] Makefile: use -Wno-main in the full kernel tree
  2021-08-17  0:33   ` Linus Torvalds
@ 2021-08-17  0:38     ` Linus Torvalds
  2021-08-17  1:01       ` Randy Dunlap
  2021-08-21 23:26     ` Randy Dunlap
  2021-09-07 22:42     ` Randy Dunlap
  2 siblings, 1 reply; 11+ messages in thread
From: Linus Torvalds @ 2021-08-17  0:38 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Linux Kernel Mailing List, Steven Rostedt,
	Daniel Bristot de Oliveira, Masahiro Yamada, Michal Marek,
	Linux Kbuild mailing list

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Makefile: use -Wno-main in the full kernel tree
  2021-08-17  0:38     ` Linus Torvalds
@ 2021-08-17  1:01       ` Randy Dunlap
  2021-08-17  1:31         ` Linus Torvalds
  0 siblings, 1 reply; 11+ messages in thread
From: Randy Dunlap @ 2021-08-17  1:01 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Linux Kernel Mailing List, Steven Rostedt,
	Daniel Bristot de Oliveira, Masahiro Yamada, Michal Marek,
	Linux Kbuild mailing list

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.

-- 
~Randy


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Makefile: use -Wno-main in the full kernel tree
  2021-08-17  1:01       ` Randy Dunlap
@ 2021-08-17  1:31         ` Linus Torvalds
  2021-08-17  2:05           ` Steven Rostedt
  0 siblings, 1 reply; 11+ messages in thread
From: Linus Torvalds @ 2021-08-17  1:31 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Linux Kernel Mailing List, Steven Rostedt,
	Daniel Bristot de Oliveira, Masahiro Yamada, Michal Marek,
	Linux Kbuild mailing list

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Makefile: use -Wno-main in the full kernel tree
  2021-08-17  1:31         ` Linus Torvalds
@ 2021-08-17  2:05           ` Steven Rostedt
  0 siblings, 0 replies; 11+ messages in thread
From: Steven Rostedt @ 2021-08-17  2:05 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Randy Dunlap, Linux Kernel Mailing List,
	Daniel Bristot de Oliveira, Masahiro Yamada, Michal Marek,
	Linux Kbuild mailing list

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Makefile: use -Wno-main in the full kernel tree
  2021-08-17  0:33   ` Linus Torvalds
  2021-08-17  0:38     ` Linus Torvalds
@ 2021-08-21 23:26     ` Randy Dunlap
  2021-09-07 22:42     ` Randy Dunlap
  2 siblings, 0 replies; 11+ messages in thread
From: Randy Dunlap @ 2021-08-21 23:26 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Linux Kernel Mailing List, Steven Rostedt,
	Daniel Bristot de Oliveira, Masahiro Yamada, Michal Marek,
	Linux Kbuild mailing list

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Makefile: use -Wno-main in the full kernel tree
  2021-08-17  0:33   ` Linus Torvalds
  2021-08-17  0:38     ` Linus Torvalds
  2021-08-21 23:26     ` Randy Dunlap
@ 2021-09-07 22:42     ` Randy Dunlap
  2 siblings, 0 replies; 11+ messages in thread
From: Randy Dunlap @ 2021-09-07 22:42 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Linux Kernel Mailing List, Steven Rostedt,
	Daniel Bristot de Oliveira, Masahiro Yamada, Michal Marek,
	Linux Kbuild mailing list, Alexander Viro

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.


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-09-07 22:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-13 22:41 [PATCH] Makefile: use -Wno-main in the full kernel tree Randy Dunlap
2021-08-14  0:01 ` Linus Torvalds
2021-08-14  0:29   ` Randy Dunlap
2021-08-17  0:33   ` Linus Torvalds
2021-08-17  0:38     ` Linus Torvalds
2021-08-17  1:01       ` Randy Dunlap
2021-08-17  1:31         ` Linus Torvalds
2021-08-17  2:05           ` Steven Rostedt
2021-08-21 23:26     ` Randy Dunlap
2021-09-07 22:42     ` Randy Dunlap
2021-08-16 15:08 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).