2020-10-27 00:07:01

by Arnd Bergmann

[permalink] [raw]
Subject: [PATCH 1/2] Makefile.extrawarn: move -Wcast-align to W=3

From: Arnd Bergmann <[email protected]>

This warning behaves differently depending on the architecture
and compiler. Using x86 gcc, we get no output at all because
gcc knows the architecture can handle unaligned accesses.

Using x86 clang, or gcc on an architecture that needs to
manually deal with unaligned accesses, the build log is
completely flooded with these warnings, as they are commonly
invoked by inline functions of networking headers, e.g.

include/linux/skbuff.h:1426:26: warning: cast increases required alignment of target type [-Wcast-align]

The compiler is correct to point this out, as we are dealing
with undefined behavior that does cause problems in practice,
but there is also no good way to rewrite the code in commonly
included headers to a safer method.

Signed-off-by: Arnd Bergmann <[email protected]>
---
scripts/Makefile.extrawarn | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 95e4cdb94fe9..6baee1200615 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -60,7 +60,6 @@ endif
#
ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)

-KBUILD_CFLAGS += -Wcast-align
KBUILD_CFLAGS += -Wdisabled-optimization
KBUILD_CFLAGS += -Wnested-externs
KBUILD_CFLAGS += -Wshadow
@@ -80,6 +79,7 @@ endif
ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)

KBUILD_CFLAGS += -Wbad-function-cast
+KBUILD_CFLAGS += -Wcast-align
KBUILD_CFLAGS += -Wcast-qual
KBUILD_CFLAGS += -Wconversion
KBUILD_CFLAGS += -Wpacked
--
2.27.0


2020-10-27 19:49:46

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH 1/2] Makefile.extrawarn: move -Wcast-align to W=3

On Mon, Oct 26, 2020 at 11:03:13PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <[email protected]>
>
> This warning behaves differently depending on the architecture
> and compiler. Using x86 gcc, we get no output at all because
> gcc knows the architecture can handle unaligned accesses.
>
> Using x86 clang, or gcc on an architecture that needs to
> manually deal with unaligned accesses, the build log is
> completely flooded with these warnings, as they are commonly
> invoked by inline functions of networking headers, e.g.
>
> include/linux/skbuff.h:1426:26: warning: cast increases required alignment of target type [-Wcast-align]
>
> The compiler is correct to point this out, as we are dealing
> with undefined behavior that does cause problems in practice,
> but there is also no good way to rewrite the code in commonly
> included headers to a safer method.
>
> Signed-off-by: Arnd Bergmann <[email protected]>

Always sad to see a warning move further down the list but noisy headers
are rough to deal with. This seems okay.

Reviewed-by: Nathan Chancellor <[email protected]>

> ---
> scripts/Makefile.extrawarn | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 95e4cdb94fe9..6baee1200615 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -60,7 +60,6 @@ endif
> #
> ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
>
> -KBUILD_CFLAGS += -Wcast-align
> KBUILD_CFLAGS += -Wdisabled-optimization
> KBUILD_CFLAGS += -Wnested-externs
> KBUILD_CFLAGS += -Wshadow
> @@ -80,6 +79,7 @@ endif
> ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
>
> KBUILD_CFLAGS += -Wbad-function-cast
> +KBUILD_CFLAGS += -Wcast-align
> KBUILD_CFLAGS += -Wcast-qual
> KBUILD_CFLAGS += -Wconversion
> KBUILD_CFLAGS += -Wpacked
> --
> 2.27.0
>

2020-11-23 11:22:16

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH 1/2] Makefile.extrawarn: move -Wcast-align to W=3

On Tue, Oct 27, 2020 at 10:42 AM Nathan Chancellor
<[email protected]> wrote:
>
> On Mon, Oct 26, 2020 at 11:03:13PM +0100, Arnd Bergmann wrote:
> > From: Arnd Bergmann <[email protected]>
> >
> > This warning behaves differently depending on the architecture
> > and compiler. Using x86 gcc, we get no output at all because
> > gcc knows the architecture can handle unaligned accesses.
> >
> > Using x86 clang, or gcc on an architecture that needs to
> > manually deal with unaligned accesses, the build log is
> > completely flooded with these warnings, as they are commonly
> > invoked by inline functions of networking headers, e.g.
> >
> > include/linux/skbuff.h:1426:26: warning: cast increases required alignment of target type [-Wcast-align]
> >
> > The compiler is correct to point this out, as we are dealing
> > with undefined behavior that does cause problems in practice,
> > but there is also no good way to rewrite the code in commonly
> > included headers to a safer method.
> >
> > Signed-off-by: Arnd Bergmann <[email protected]>
>
> Always sad to see a warning move further down the list but noisy headers
> are rough to deal with. This seems okay.
>
> Reviewed-by: Nathan Chancellor <[email protected]>
>
> > ---
> > scripts/Makefile.extrawarn | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> > index 95e4cdb94fe9..6baee1200615 100644
> > --- a/scripts/Makefile.extrawarn
> > +++ b/scripts/Makefile.extrawarn
> > @@ -60,7 +60,6 @@ endif
> > #
> > ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
> >
> > -KBUILD_CFLAGS += -Wcast-align
> > KBUILD_CFLAGS += -Wdisabled-optimization
> > KBUILD_CFLAGS += -Wnested-externs
> > KBUILD_CFLAGS += -Wshadow
> > @@ -80,6 +79,7 @@ endif
> > ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
> >
> > KBUILD_CFLAGS += -Wbad-function-cast
> > +KBUILD_CFLAGS += -Wcast-align
> > KBUILD_CFLAGS += -Wcast-qual
> > KBUILD_CFLAGS += -Wconversion
> > KBUILD_CFLAGS += -Wpacked
> > --
> > 2.27.0
> >


Applied to linux-kbuild. Thanks.

But, I think people already tend to ignore W=2 warnings.


--
Best Regards
Masahiro Yamada

2020-11-24 15:47:32

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 1/2] Makefile.extrawarn: move -Wcast-align to W=3

On Mon, Nov 23, 2020 at 12:18 PM Masahiro Yamada <[email protected]> wrote:
>
> Applied to linux-kbuild. Thanks.
>
> But, I think people already tend to ignore W=2 warnings.

Yes, this is what I was trying to change with this series and a couple of other
patches I sent. When all the warnings from commonly included headers are
gone, W=2 actually becomes somewhat useful.

Arnd