kbuild: fix kernel/bounds.c 'W=1' warning

Message ID 20181005083313.2088252-1-arnd@arndb.de
State Accepted
Commit 6a32c2469c3fbfee8f25bcd20af647326650a6cf
Headers show
Series
  • kbuild: fix kernel/bounds.c 'W=1' warning
Related show

Commit Message

Arnd Bergmann Oct. 5, 2018, 8:33 a.m.
Building any configuration with 'make W=1' produces a warning:

kernel/bounds.c:16:6: warnign: no previous prototype for 'foo' [-Wmissing-prototypes]

When also passing -Werror, this prevents us from building any
other files. Nobody ever calls the function, but we can't make
it 'static' either since we want the compiler output.

Calling it 'main' instead however avoids the warning, because gcc
does not insist on having a declaration for main.

Reported-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Cc: stable@vger.kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

---
I have run into this problem several times before, and thought I had
sent a fix at some point. Looking in the archives, I came across
the suggested fix from Kieran, so I'm following up on that here.
---
 kernel/bounds.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

-- 
2.18.0

Comments

Kieran Bingham Oct. 5, 2018, 8:47 a.m. | #1
Hi Arnd,

On 05/10/18 09:33, Arnd Bergmann wrote:
> Building any configuration with 'make W=1' produces a warning:

> 

> kernel/bounds.c:16:6: warnign: no previous prototype for 'foo' [-Wmissing-prototypes]

> 


s/warnign/warning/ but I don't think that's too important :D

> When also passing -Werror, this prevents us from building any

> other files. Nobody ever calls the function, but we can't make

> it 'static' either since we want the compiler output.

> 

> Calling it 'main' instead however avoids the warning, because gcc

> does not insist on having a declaration for main.


Aha - even better! (and annoyingly fairly obvious, from the
Why-didn't-I-think-of-that department).

> Reported-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>

> Cc: stable@vger.kernel.org

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>


Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>


> ---

> I have run into this problem several times before, and thought I had

> sent a fix at some point. Looking in the archives, I came across

> the suggested fix from Kieran, so I'm following up on that here.

> ---

>  kernel/bounds.c | 4 +++-

>  1 file changed, 3 insertions(+), 1 deletion(-)

> 

> diff --git a/kernel/bounds.c b/kernel/bounds.c

> index c373e887c066..9795d75b09b2 100644

> --- a/kernel/bounds.c

> +++ b/kernel/bounds.c

> @@ -13,7 +13,7 @@

>  #include <linux/log2.h>

>  #include <linux/spinlock_types.h>

>  

> -void foo(void)

> +int main(void)

>  {

>  	/* The enum constants to put into include/generated/bounds.h */

>  	DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);

> @@ -23,4 +23,6 @@ void foo(void)

>  #endif

>  	DEFINE(SPINLOCK_SIZE, sizeof(spinlock_t));

>  	/* End of constants */

> +

> +	return 0;

>  }

>
Arnd Bergmann Oct. 5, 2018, 9:07 a.m. | #2
On Fri, Oct 5, 2018 at 10:52 AM David Laight <David.Laight@aculab.com> wrote:
>

> From: Arnd Bergmann

> > Sent: 05 October 2018 09:33

> >

> > Building any configuration with 'make W=1' produces a warning:

> >

> > kernel/bounds.c:16:6: warnign: no previous prototype for 'foo' [-Wmissing-prototypes]

> >

> > When also passing -Werror, this prevents us from building any

> > other files. Nobody ever calls the function, but we can't make

> > it 'static' either since we want the compiler output.

> >

> > Calling it 'main' instead however avoids the warning, because gcc

> > does not insist on having a declaration for main.

>

> Ugg.

> main() might be special in other ways too.

> It wouldn't surprise me if some linkers don't do special stuff for it.

>

> What is wrong with just putting and extra "void foo(void);" before

> the function?


Greg objected to that on the basis that we don't want declarations
in .c files -- they should be in a shared header:

https://lkml.org/lkml/2018/9/21/735

I don't see what could go wrong here with calling it main(), after
all we are just interested in the assembler output, not even
creating an object file.

      Arnd
Kieran Bingham Oct. 5, 2018, 9:27 a.m. | #3
On 05/10/18 10:07, Arnd Bergmann wrote:
> On Fri, Oct 5, 2018 at 10:52 AM David Laight <David.Laight@aculab.com> wrote:

>>

>> From: Arnd Bergmann

>>> Sent: 05 October 2018 09:33

>>>

>>> Building any configuration with 'make W=1' produces a warning:

>>>

>>> kernel/bounds.c:16:6: warnign: no previous prototype for 'foo' [-Wmissing-prototypes]

>>>

>>> When also passing -Werror, this prevents us from building any

>>> other files. Nobody ever calls the function, but we can't make

>>> it 'static' either since we want the compiler output.

>>>

>>> Calling it 'main' instead however avoids the warning, because gcc

>>> does not insist on having a declaration for main.

>>

>> Ugg.

>> main() might be special in other ways too.

>> It wouldn't surprise me if some linkers don't do special stuff for it.


I worried about this but didn't think it would be too much of an issue.
But perhaps we should check...

<compile bounds.s in both configurations> as bounds.s.foo and bounds.s.main:


 diff -Nurp bounds.s.*
--- bounds.s.foo        2018-10-05 10:20:53.269941404 +0100
+++ bounds.s.main       2018-10-05 10:20:31.375891260 +0100
@@ -108,11 +108,12 @@

        .global _mcount
 #NO_APP
+       .section        .text.startup,"ax",@progbits
        .align  2
        .p2align 3,,7
-       .global foo
-       .type   foo, %function
-foo:
+       .global main
+       .type   main, %function
+main:
        stp     x29, x30, [sp, -16]!    //,,,
        add     x29, sp, 0      //,,
 // /home/linuxembedded/iob/renesas/vsp1/sources/linux/kernel/bounds.c:17: {
@@ -139,10 +140,11 @@ foo:

 .ascii "->SPINLOCK_SIZE 56 sizeof(spinlock_t)" //
 // 0 "" 2
-// /home/linuxembedded/iob/renesas/vsp1/sources/linux/kernel/bounds.c:26: }
+// /home/linuxembedded/iob/renesas/vsp1/sources/linux/kernel/bounds.c:28: }
 #NO_APP
+       mov     w0, 0   //,
        ldp     x29, x30, [sp], 16      //,,,
        ret
-       .size   foo, .-foo
+       .size   main, .-main
        .ident  "GCC: (Ubuntu/Linaro 7.3.0-16ubuntu3) 7.3.0"
        .section        .note.GNU-stack,"",@progbits



compiled with aarch64-linux-gnu-gcc, and with no debug enabled.

Other than the entry point rename (and section name) and the return
value being added, I can't see anything problematic here.

And as far as I know - this file gets processed after to extract
definitions which should be independent. This file is not executed or
further compiled as far as I am aware.

--
Kieran



>>

>> What is wrong with just putting and extra "void foo(void);" before

>> the function?

> 

> Greg objected to that on the basis that we don't want declarations

> in .c files -- they should be in a shared header:

> 

> https://lkml.org/lkml/2018/9/21/735

> 

> I don't see what could go wrong here with calling it main(), after

> all we are just interested in the assembler output, not even

> creating an object file.

> 

>       Arnd

>
Masahiro Yamada Oct. 6, 2018, 8:31 p.m. | #4
On Fri, Oct 5, 2018 at 5:34 PM Arnd Bergmann <arnd@arndb.de> wrote:
>

> Building any configuration with 'make W=1' produces a warning:

>

> kernel/bounds.c:16:6: warnign: no previous prototype for 'foo' [-Wmissing-prototypes]

>

> When also passing -Werror, this prevents us from building any

> other files. Nobody ever calls the function, but we can't make

> it 'static' either since we want the compiler output.

>

> Calling it 'main' instead however avoids the warning, because gcc

> does not insist on having a declaration for main.

>

> Reported-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>

> Cc: stable@vger.kernel.org

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

> ---



Applied to kbuild/fixes
with 's/warnign/warning/'

Thanks!




> I have run into this problem several times before, and thought I had

> sent a fix at some point. Looking in the archives, I came across

> the suggested fix from Kieran, so I'm following up on that here.

> ---

>  kernel/bounds.c | 4 +++-

>  1 file changed, 3 insertions(+), 1 deletion(-)

>

> diff --git a/kernel/bounds.c b/kernel/bounds.c

> index c373e887c066..9795d75b09b2 100644

> --- a/kernel/bounds.c

> +++ b/kernel/bounds.c

> @@ -13,7 +13,7 @@

>  #include <linux/log2.h>

>  #include <linux/spinlock_types.h>

>

> -void foo(void)

> +int main(void)

>  {

>         /* The enum constants to put into include/generated/bounds.h */

>         DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);

> @@ -23,4 +23,6 @@ void foo(void)

>  #endif

>         DEFINE(SPINLOCK_SIZE, sizeof(spinlock_t));

>         /* End of constants */

> +

> +       return 0;

>  }

> --

> 2.18.0

>



-- 
Best Regards
Masahiro Yamada
Masahiro Yamada Oct. 6, 2018, 9:58 p.m. | #5
Hi Miguel,


On Sun, Oct 7, 2018 at 6:18 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>

> On Fri, Oct 5, 2018 at 10:35 AM Arnd Bergmann <arnd@arndb.de> wrote:

> >

> > Building any configuration with 'make W=1' produces a warning:

> >

> > kernel/bounds.c:16:6: warnign: no previous prototype for 'foo' [-Wmissing-prototypes]

> >

> > When also passing -Werror, this prevents us from building any

> > other files. Nobody ever calls the function, but we can't make

> > it 'static' either since we want the compiler output.

> >

> > Calling it 'main' instead however avoids the warning, because gcc

> > does not insist on having a declaration for main.

>

> I think marking the function as static __used should do the trick and

> would be less confusing.





I tried __used, but I still see the warning.


masahiro@grover:~/ref/linux$ git diff
diff --git a/kernel/bounds.c b/kernel/bounds.c
index c373e88..aee0101 100644
--- a/kernel/bounds.c
+++ b/kernel/bounds.c
@@ -13,7 +13,7 @@
 #include <linux/log2.h>
 #include <linux/spinlock_types.h>

-void foo(void)
+void __used foo(void)
 {
        /* The enum constants to put into include/generated/bounds.h */
        DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);
masahiro@grover:~/ref/linux$ make W=1  prepare
  CC      kernel/bounds.s
kernel/bounds.c:16:13: warning: no previous prototype for ‘foo’
[-Wmissing-prototypes]
 void __used foo(void)
             ^
  CC      arch/x86/kernel/asm-offsets.s





-- 
Best Regards
Masahiro Yamada
Masahiro Yamada Oct. 6, 2018, 10:06 p.m. | #6
On Sun, Oct 7, 2018 at 6:58 AM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
>

> Hi Miguel,

>

>

> On Sun, Oct 7, 2018 at 6:18 AM Miguel Ojeda

> <miguel.ojeda.sandonis@gmail.com> wrote:

> >

> > On Fri, Oct 5, 2018 at 10:35 AM Arnd Bergmann <arnd@arndb.de> wrote:

> > >

> > > Building any configuration with 'make W=1' produces a warning:

> > >

> > > kernel/bounds.c:16:6: warnign: no previous prototype for 'foo' [-Wmissing-prototypes]

> > >

> > > When also passing -Werror, this prevents us from building any

> > > other files. Nobody ever calls the function, but we can't make

> > > it 'static' either since we want the compiler output.

> > >

> > > Calling it 'main' instead however avoids the warning, because gcc

> > > does not insist on having a declaration for main.

> >

> > I think marking the function as static __used should do the trick and

> > would be less confusing.

>

>

>

>

> I tried __used, but I still see the warning.

>

>

> masahiro@grover:~/ref/linux$ git diff

> diff --git a/kernel/bounds.c b/kernel/bounds.c

> index c373e88..aee0101 100644

> --- a/kernel/bounds.c

> +++ b/kernel/bounds.c

> @@ -13,7 +13,7 @@

>  #include <linux/log2.h>

>  #include <linux/spinlock_types.h>

>

> -void foo(void)

> +void __used foo(void)

>  {

>         /* The enum constants to put into include/generated/bounds.h */

>         DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);

> masahiro@grover:~/ref/linux$ make W=1  prepare

>   CC      kernel/bounds.s

> kernel/bounds.c:16:13: warning: no previous prototype for ‘foo’

> [-Wmissing-prototypes]

>  void __used foo(void)

>              ^

>   CC      arch/x86/kernel/asm-offsets.s




Sorry, I forgot to add 'static'.

Adding both static and __used worked for me,
and I like the idea.



-- 
Best Regards
Masahiro Yamada
Masahiro Yamada Oct. 8, 2018, 2:32 p.m. | #7
On Mon, Oct 8, 2018 at 7:01 PM Kieran Bingham
<kieran.bingham+renesas@ideasonboard.com> wrote:
>

> On 06/10/18 23:06, Masahiro Yamada wrote:

> > On Sun, Oct 7, 2018 at 6:58 AM Masahiro Yamada

> > <yamada.masahiro@socionext.com> wrote:

> >>

> >> Hi Miguel,

> >>

> >>

> >> On Sun, Oct 7, 2018 at 6:18 AM Miguel Ojeda

> >> <miguel.ojeda.sandonis@gmail.com> wrote:

> >>>

> >>> On Fri, Oct 5, 2018 at 10:35 AM Arnd Bergmann <arnd@arndb.de> wrote:

> >>>>

> >>>> Building any configuration with 'make W=1' produces a warning:

> >>>>

> >>>> kernel/bounds.c:16:6: warnign: no previous prototype for 'foo' [-Wmissing-prototypes]

> >>>>

> >>>> When also passing -Werror, this prevents us from building any

> >>>> other files. Nobody ever calls the function, but we can't make

> >>>> it 'static' either since we want the compiler output.

> >>>>

> >>>> Calling it 'main' instead however avoids the warning, because gcc

> >>>> does not insist on having a declaration for main.

> >>>

> >>> I think marking the function as static __used should do the trick and

> >>> would be less confusing.

> >>

> >>

> >>

> >>

> >> I tried __used, but I still see the warning.

> >>

> >>

> >> masahiro@grover:~/ref/linux$ git diff

> >> diff --git a/kernel/bounds.c b/kernel/bounds.c

> >> index c373e88..aee0101 100644

> >> --- a/kernel/bounds.c

> >> +++ b/kernel/bounds.c

> >> @@ -13,7 +13,7 @@

> >>  #include <linux/log2.h>

> >>  #include <linux/spinlock_types.h>

> >>

> >> -void foo(void)

> >> +void __used foo(void)

> >>  {

> >>         /* The enum constants to put into include/generated/bounds.h */

> >>         DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);

> >> masahiro@grover:~/ref/linux$ make W=1  prepare

> >>   CC      kernel/bounds.s

> >> kernel/bounds.c:16:13: warning: no previous prototype for ‘foo’

> >> [-Wmissing-prototypes]

> >>  void __used foo(void)

> >>              ^

> >>   CC      arch/x86/kernel/asm-offsets.s

> >

> >

> >

> > Sorry, I forgot to add 'static'.

> >

> > Adding both static and __used worked for me,

> > and I like the idea.

> >

>

> Aha - I'd also tried converting to static in my earlier attempts, but

> didn't realise we had __used!

>

> updating as "static __used" causes the following diff:

>

> diff -Nurp bounds.s.foo bounds.s.static-used

> --- bounds.s.foo        2018-10-05 10:20:53.269941404 +0100

> +++ bounds.s.static-used        2018-10-08 10:51:18.079309049 +0100

> @@ -110,7 +110,6 @@

>  #NO_APP

>         .align  2

>         .p2align 3,,7

> -       .global foo

>         .type   foo, %function

>  foo:

>         stp     x29, x30, [sp, -16]!    //,,,

>

>

> I'd say this is a pretty good alternative fix - however I see Arnd's

> version is already on it's way though akpm's tree...

>

> https://ozlabs.org/~akpm/mmots/broken-out/kbuild-fix-kernel-boundsc-w%3D1-warning.patch

>

> Anyway, as long as one of the variants gets there I'll be happy :)



I will leave it to Arnd.


When we fix arch/{mips,sparc}/kernel/asm-offsets.c,
'static __used' is just additions.

The 'main(void)' solution would require a little bit restructuring.



FWIW, with my quick analysis, the following should be fixed as well:

arch/alpha/kernel/asm-offsets.c
arch/c6x/kernel/asm-offsets.c
arch/ia64/kernel/asm-offsets.c
arch/ia64/kernel/nr-irqs.c
arch/mips/kernel/asm-offsets.c
arch/riscv/kernel/asm-offsets.c
arch/sparc/kernel/asm-offsets.c
arch/x86/kernel/asm-offsets.c
arch/x86/um/shared/sysdep/kernel-offsets.h
samples/bpf/syscall_nrs.c






-- 
Best Regards
Masahiro Yamada
Geert Uytterhoeven Oct. 8, 2018, 2:41 p.m. | #8
On Mon, Oct 8, 2018 at 4:33 PM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> On Mon, Oct 8, 2018 at 7:01 PM Kieran Bingham

> <kieran.bingham+renesas@ideasonboard.com> wrote:

> > On 06/10/18 23:06, Masahiro Yamada wrote:

> > > On Sun, Oct 7, 2018 at 6:58 AM Masahiro Yamada

> > > <yamada.masahiro@socionext.com> wrote:

> > >>

> > >> Hi Miguel,

> > >>

> > >>

> > >> On Sun, Oct 7, 2018 at 6:18 AM Miguel Ojeda

> > >> <miguel.ojeda.sandonis@gmail.com> wrote:

> > >>>

> > >>> On Fri, Oct 5, 2018 at 10:35 AM Arnd Bergmann <arnd@arndb.de> wrote:

> > >>>>

> > >>>> Building any configuration with 'make W=1' produces a warning:

> > >>>>

> > >>>> kernel/bounds.c:16:6: warnign: no previous prototype for 'foo' [-Wmissing-prototypes]

> > >>>>

> > >>>> When also passing -Werror, this prevents us from building any

> > >>>> other files. Nobody ever calls the function, but we can't make

> > >>>> it 'static' either since we want the compiler output.

> > >>>>

> > >>>> Calling it 'main' instead however avoids the warning, because gcc

> > >>>> does not insist on having a declaration for main.

> > >>>

> > >>> I think marking the function as static __used should do the trick and

> > >>> would be less confusing.

> > >>

> > >>

> > >>

> > >>

> > >> I tried __used, but I still see the warning.

> > >>

> > >>

> > >> masahiro@grover:~/ref/linux$ git diff

> > >> diff --git a/kernel/bounds.c b/kernel/bounds.c

> > >> index c373e88..aee0101 100644

> > >> --- a/kernel/bounds.c

> > >> +++ b/kernel/bounds.c

> > >> @@ -13,7 +13,7 @@

> > >>  #include <linux/log2.h>

> > >>  #include <linux/spinlock_types.h>

> > >>

> > >> -void foo(void)

> > >> +void __used foo(void)

> > >>  {

> > >>         /* The enum constants to put into include/generated/bounds.h */

> > >>         DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);

> > >> masahiro@grover:~/ref/linux$ make W=1  prepare

> > >>   CC      kernel/bounds.s

> > >> kernel/bounds.c:16:13: warning: no previous prototype for ‘foo’

> > >> [-Wmissing-prototypes]

> > >>  void __used foo(void)

> > >>              ^

> > >>   CC      arch/x86/kernel/asm-offsets.s

> > >

> > >

> > >

> > > Sorry, I forgot to add 'static'.

> > >

> > > Adding both static and __used worked for me,

> > > and I like the idea.

> > >

> >

> > Aha - I'd also tried converting to static in my earlier attempts, but

> > didn't realise we had __used!

> >

> > updating as "static __used" causes the following diff:

> >

> > diff -Nurp bounds.s.foo bounds.s.static-used

> > --- bounds.s.foo        2018-10-05 10:20:53.269941404 +0100

> > +++ bounds.s.static-used        2018-10-08 10:51:18.079309049 +0100

> > @@ -110,7 +110,6 @@

> >  #NO_APP

> >         .align  2

> >         .p2align 3,,7

> > -       .global foo

> >         .type   foo, %function

> >  foo:

> >         stp     x29, x30, [sp, -16]!    //,,,

> >

> >

> > I'd say this is a pretty good alternative fix - however I see Arnd's

> > version is already on it's way though akpm's tree...

> >

> > https://ozlabs.org/~akpm/mmots/broken-out/kbuild-fix-kernel-boundsc-w%3D1-warning.patch

> >

> > Anyway, as long as one of the variants gets there I'll be happy :)

>

>

> I will leave it to Arnd.

>

>

> When we fix arch/{mips,sparc}/kernel/asm-offsets.c,

> 'static __used' is just additions.

>

> The 'main(void)' solution would require a little bit restructuring.

>

>

>

> FWIW, with my quick analysis, the following should be fixed as well:

>

> arch/alpha/kernel/asm-offsets.c

> arch/c6x/kernel/asm-offsets.c

> arch/ia64/kernel/asm-offsets.c

> arch/ia64/kernel/nr-irqs.c

> arch/mips/kernel/asm-offsets.c

> arch/riscv/kernel/asm-offsets.c

> arch/sparc/kernel/asm-offsets.c

> arch/x86/kernel/asm-offsets.c

> arch/x86/um/shared/sysdep/kernel-offsets.h

> samples/bpf/syscall_nrs.c


All the other asm-offsets.c files already use "int main(void)" ;-)

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Patch

diff --git a/kernel/bounds.c b/kernel/bounds.c
index c373e887c066..9795d75b09b2 100644
--- a/kernel/bounds.c
+++ b/kernel/bounds.c
@@ -13,7 +13,7 @@ 
 #include <linux/log2.h>
 #include <linux/spinlock_types.h>
 
-void foo(void)
+int main(void)
 {
 	/* The enum constants to put into include/generated/bounds.h */
 	DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);
@@ -23,4 +23,6 @@  void foo(void)
 #endif
 	DEFINE(SPINLOCK_SIZE, sizeof(spinlock_t));
 	/* End of constants */
+
+	return 0;
 }