kbuild: Add -Werror=unknown-warning-option to CLANG_FLAGS
PATCH 1/1 kbuild: Add -Werror=unknown-warning-option to CLANG_FLAGS
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
--- Makefile | 1 + 1 file changed, 1 insertion(+)
Makefile +1 -0
@@ -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
Signature · 1 line
2.22.0
Quoted 2 lines · Nathan Chancellor
Suggested-by Peter Smith <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>
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:
Quoted 1 line
error: unknown warning option '-Wno-psabi' [-Werror,-Wunknown-warning-option]
Quoted 19 lines
--- Makefile | 1 + 1 file changed, 1 insertion(+)Makefile +1
-1@@ -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
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 28 lines · Nathan Chancellor
In commit
ebcc5928c5d9("arm64: Silence gcc warnings about arch ABI drift"), the arm64Makefileadded -Wno-psabi toKBUILD_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 toKBUILD_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.
Quoted 8 lines
[1]: https://godbolt.org/z/7F7rm3
[2]: https://releases.llvm.org/4.0.0/tools/clang/docs/DiagnosticsReference.html#wunknown-warning-optionSuggested-by Peter Smith <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>---
Applied to linux-kbuild.
Thanks!
Signature · 2 lines
Best Regards Masahiro Yamada