diff mbox series

kbuild: Add -Werror=unknown-warning-option to CLANG_FLAGS

Message ID 20190611184331.44242-1-natechancellor@gmail.com (mailing list archive)
State New, archived
Headers show
Series kbuild: Add -Werror=unknown-warning-option to CLANG_FLAGS | expand

Commit Message

Nathan Chancellor June 11, 2019, 6:43 p.m. UTC
In commit ebcc5928c5d9 ("arm64: Silence gcc warnings about arch ABI
drift"), the arm64 Makefile added -Wno-psabi to KBUILD_CFLAGS, which is
a GCC only option so clang rightfully complains:

warning: unknown warning option '-Wno-psabi' [-Wunknown-warning-option]

https://clang.llvm.org/docs/DiagnosticsReference.html#wunknown-warning-option

However, by default, this is merely a warning so the build happily goes
on with a slew of these warnings in the process.

Commit c3f0d0bc5b01 ("kbuild, LLVMLinux: Add -Werror to cc-option to
support clang") worked around this behavior in cc-option by adding
-Werror so that unknown flags cause an error. However, this all happens
silently and when an unknown flag is added to the build unconditionally
like -Wno-psabi, cc-option will always fail because there is always an
unknown flag in the list of flags. This manifested as link time failures
in the arm64 libstub because -fno-stack-protector didn't get added to
KBUILD_CFLAGS.

To avoid these weird cryptic failures in the future, make clang behave
like gcc and immediately error when it encounters an unknown flag by
adding -Werror=unknown-warning-option to CLANG_FLAGS. This can be added
unconditionally for clang because it is supported by at least 3.0.0,
according to godbolt [1] and 4.0.0, according to its documentation [2],
which is far earlier than we typically support.

[1]: https://godbolt.org/z/7F7rm3
[2]: https://releases.llvm.org/4.0.0/tools/clang/docs/DiagnosticsReference.html#wunknown-warning-option

Link: https://github.com/ClangBuiltLinux/linux/issues/511
Link: https://github.com/ClangBuiltLinux/linux/issues/517
Suggested-by: Peter Smith <peter.smith@linaro.org>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 Makefile | 1 +
 1 file changed, 1 insertion(+)

Comments

Nick Desaulniers June 11, 2019, 7:37 p.m. UTC | #1
On Tue, Jun 11, 2019 at 11:43 AM Nathan Chancellor
<natechancellor@gmail.com> wrote:
> Suggested-by: Peter Smith <peter.smith@linaro.org>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

I verified this has no negative effect with -Qunused-arguments and the
relative position of the two flags.  The build failure is much more
explicit with this patch:
> error: unknown warning option '-Wno-psabi' [-Werror,-Wunknown-warning-option]

Tested-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  Makefile | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/Makefile b/Makefile
> index b81e17261250..5f9d09bd2252 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -528,6 +528,7 @@ ifneq ($(GCC_TOOLCHAIN),)
>  CLANG_FLAGS    += --gcc-toolchain=$(GCC_TOOLCHAIN)
>  endif
>  CLANG_FLAGS    += -no-integrated-as
> +CLANG_FLAGS    += -Werror=unknown-warning-option
>  KBUILD_CFLAGS  += $(CLANG_FLAGS)
>  KBUILD_AFLAGS  += $(CLANG_FLAGS)
>  export CLANG_FLAGS
> --
> 2.22.0
>
Masahiro Yamada June 20, 2019, 2:23 p.m. UTC | #2
On Wed, Jun 12, 2019 at 3:43 AM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> In commit ebcc5928c5d9 ("arm64: Silence gcc warnings about arch ABI
> drift"), the arm64 Makefile added -Wno-psabi to KBUILD_CFLAGS, which is
> a GCC only option so clang rightfully complains:
>
> warning: unknown warning option '-Wno-psabi' [-Wunknown-warning-option]
>
> https://clang.llvm.org/docs/DiagnosticsReference.html#wunknown-warning-option
>
> However, by default, this is merely a warning so the build happily goes
> on with a slew of these warnings in the process.
>
> Commit c3f0d0bc5b01 ("kbuild, LLVMLinux: Add -Werror to cc-option to
> support clang") worked around this behavior in cc-option by adding
> -Werror so that unknown flags cause an error. However, this all happens
> silently and when an unknown flag is added to the build unconditionally
> like -Wno-psabi, cc-option will always fail because there is always an
> unknown flag in the list of flags. This manifested as link time failures
> in the arm64 libstub because -fno-stack-protector didn't get added to
> KBUILD_CFLAGS.
>
> To avoid these weird cryptic failures in the future, make clang behave
> like gcc and immediately error when it encounters an unknown flag by
> adding -Werror=unknown-warning-option to CLANG_FLAGS. This can be added
> unconditionally for clang because it is supported by at least 3.0.0,
> according to godbolt [1] and 4.0.0, according to its documentation [2],
> which is far earlier than we typically support.
>
> [1]: https://godbolt.org/z/7F7rm3
> [2]: https://releases.llvm.org/4.0.0/tools/clang/docs/DiagnosticsReference.html#wunknown-warning-option
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/511
> Link: https://github.com/ClangBuiltLinux/linux/issues/517
> Suggested-by: Peter Smith <peter.smith@linaro.org>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---

Applied to linux-kbuild.
Thanks!
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index b81e17261250..5f9d09bd2252 100644
--- a/Makefile
+++ b/Makefile
@@ -528,6 +528,7 @@  ifneq ($(GCC_TOOLCHAIN),)
 CLANG_FLAGS	+= --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 CLANG_FLAGS	+= -no-integrated-as
+CLANG_FLAGS	+= -Werror=unknown-warning-option
 KBUILD_CFLAGS	+= $(CLANG_FLAGS)
 KBUILD_AFLAGS	+= $(CLANG_FLAGS)
 export CLANG_FLAGS