kbuild: clang: remove crufty HOSTCFLAGS
PATCH 1/1 kbuild: clang: remove crufty HOSTCFLAGS
When compiling with make CC=clang HOSTCC=clang, I was seeing warnings that clang did not recognize -fno-delete-null-pointer-checks for HOSTCC targets. These were added in commit 61163efae020 ("kbuild: LLVMLinux:
Add Kbuild support for building kernel with Clang"). That patch wraps that flag in cc-option for KBUILD_CFLAGS, but not hostcc-option for HOSTCFLAGS. Either hostcc-option did not exist, or the author was not setting HOSTCC to clang as well as CC when authored.
It's not clear why the other warnings were disabled, and just for HOSTCFLAGS, but I can remove them, add -Werror to HOSTCFLAGS and compile with clang just fine.
---
* It may also be worthwhile keep the old flags, and simply wrap everything in hostcc-option.
Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
Makefile +1 -5
@@ -301,16 +301,12 @@ HOST_LFS_LIBS := $(shell getconf LFS_LIBS) HOSTCC = gcc HOSTCXX = g++ HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \ + $(call hostcc-option,-fno-delete-null-pointer-checks) \ -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) HOST_LOADLIBES := $(HOST_LFS_LIBS) -ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1) -HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ - -Wno-missing-field-initializers -fno-delete-null-pointer-checks -endif - # Decide whether to build built-in, modular, or both. # Normally, just do built-in.
Signature · 1 line
2.11.0
Hi Nick,
2017-09-26 11:28 GMT+09:00 Nick Desaulniers <[email protected]>:
Quoted 25 lines
When compiling with
make CC=clang HOSTCC=clang, I was seeing warnings that clang did not recognize -fno-delete-null-pointer-checks for HOSTCC targets. These were added in commit61163efae020("kbuild: LLVMLinux:
AddKbuildsupport for building kernel with Clang"). That patch wraps that flag in cc-option forKBUILD_CFLAGS, but not hostcc-option for HOSTCFLAGS. Either hostcc-option did not exist, or the author was not setting HOSTCC to clang as well as CC when authored.It's not clear why the other warnings were disabled, and just for HOSTCFLAGS, but I can remove them, add -Werror to HOSTCFLAGS and compile with clang just fine.
Signed-off-by Nick Desaulniers <[email protected]>---
* It may also be worthwhile keep the old flags, and simply wrap everything in hostcc-option.Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)Makefile +0
-0
Makefile HOST_LFS_LIBS := $(shell getconf LFS_LIBS) · line 305
Quoted 5 lines
Makefile +1
-0@@ -301,16 +301,12 @@ HOST_LFS_LIBS := $(shell getconf LFS_LIBS) HOSTCC = gcc HOSTCXX = g++ HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \ + $(call hostcc-option,-fno-delete-null-pointer-checks) \ -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS)
You call hostcc-option
before Kbuild.include is included around line 341.
So, $(call hostcc-option, ...) returns always an empty string here whether the compiler supports the option or not.
Makefile HOST_LFS_LIBS := $(shell getconf LFS_LIBS) · line 313
Quoted 9 lines
Makefile +0
-5HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) HOST_LOADLIBES := $(HOST_LFS_LIBS) -ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1) -HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ - -Wno-missing-field-initializers -fno-delete-null-pointer-checks -endif -
The logic is very strange in the first place.
Even very old GCC supports -fno-delete-null-pointer-checks, but clang does not.
Here, -fno-delete-null-pointer-checks is added only when we are using clang for HOSTCC. This is opposite.
I guess we can remove all of them
unless somebody can explain the rationale.
Quoted 3 lines
Makefile +0
-0# Decide whether to build built-in, modular, or both. # Normally, just do built-in.
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 10 lines · Masahiro Yamada
2017-09-26 11:28 GMT+09:00 Nick Desaulniers <[email protected]>:
Quoted 3 lines
HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
+ $(call hostcc-option,-fno-delete-null-pointer-checks) \ -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS)You call hostcc-option
before Kbuild.include is included around line 341.So, $(call hostcc-option, ...) returns always an empty string here whether the compiler supports the option or not.
So calling a yet-to-be defined variable results in an empty string rather than a loud failure? Chalk that up there with language features no one ever asked for. That kind of implicit conversion gets languages like JavaScript (with its loose type system, not that C is without its own implicit type conversions/promotions) in a lot of hot water.
If that's the case, why are includes not at the top of Makefiles, if silent failure is a possibility? Is there a reason the include is so far into the Makefile?
Is your sugguestion to raise the include or lower the HOSTCFLAGS definition?
Quoted 7 lines
Makefile HOST_LFS_LIBS := $(shell getconf LFS_LIBS) · line 312
Quoted 4 lines
Makefile +0
-4-ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1) -HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ - -Wno-missing-field-initializers -fno-delete-null-pointer-checks -endifThe logic is very strange in the first place.
Quoted 8 lines
Even very old GCC supports -fno-delete-null-pointer-checks, but clang does not.
Here, -fno-delete-null-pointer-checks is added only when we are using clang for HOSTCC. This is opposite.
I guess we can remove all of them
unless somebody can explain the rationale.
+llvm-linux
I suppose maybe different ARCH's have different host binaries made during the build? I tested x86_64 and arm64. The commit message that added them missed any context or justification.
Quoted 9 lines · Nick Desaulniers
Quoted 8 lines · Masahiro Yamada
2017-09-26 11:28 GMT+09:00 Nick Desaulniers <[email protected]>:
Quoted 3 lines
HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
+ $(call hostcc-option,-fno-delete-null-pointer-checks) \ -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS)You call hostcc-option
before Kbuild.include is included around line 341.
Quoted 8 lines
Quoted 2 lines
So, $(call hostcc-option, ...) returns always an empty string here whether the compiler supports the option or not.
So calling a yet-to-be defined variable results in an empty string rather than a loud failure? Chalk that up there with language features no one ever asked for. That kind of implicit conversion gets languages like JavaScript (with its loose type system, not that C is without its own implicit type conversions/promotions) in a lot of hot water.
make --warn-undefined-variables
(and it warns all over the place during a kernel build -- having undefined variables expand to the empty string is a useful feature, too, not just a trap for the unwary).
Segher
Hi Nick.
2017-10-01 8:14 GMT+09:00 Nick Desaulniers <[email protected]>:
Quoted 18 lines · Masahiro Yamada
Quoted 10 lines
2017-09-26 11:28 GMT+09:00 Nick Desaulniers <[email protected]>:
Quoted 3 lines
HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
+ $(call hostcc-option,-fno-delete-null-pointer-checks) \ -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS)You call hostcc-option
before Kbuild.include is included around line 341.So, $(call hostcc-option, ...) returns always an empty string here whether the compiler supports the option or not.
So calling a yet-to-be defined variable results in an empty string rather than a loud failure? Chalk that up there with language features no one ever asked for. That kind of implicit conversion gets languages like JavaScript (with its loose type system, not that C is without its own implicit type conversions/promotions) in a lot of hot water.
Quoted 3 lines
If that's the case, why are includes not at the top of Makefiles, if silent failure is a possibility? Is there a reason the include is so far into the
Makefile?
Kbuild.include depends on some other variables. You can not include it at the top of the Makefile.
Quoted 2 lines
Is your sugguestion to raise the include or lower the HOSTCFLAGS definition?
In this case, you do not need to move any of them.
-fno-delete-null-pointer-checks has never enabled
for host-tools before.
Just remove it to keep the current behavior.
Quoted 13 lines
Quoted 13 lines
Makefile HOST_LFS_LIBS := $(shell getconf LFS_LIBS) · line 312
Quoted 4 lines
Makefile +0
-4-ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1) -HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ - -Wno-missing-field-initializers -fno-delete-null-pointer-checks -endifThe logic is very strange in the first place.
Even very old GCC supports -fno-delete-null-pointer-checks, but clang does not.
Here, -fno-delete-null-pointer-checks is added only when we are using clang for HOSTCC. This is opposite.
Quoted 8 lines
Quoted 2 lines
I guess we can remove all of them
unless somebody can explain the rationale.+llvm-linux
I suppose maybe different ARCH's have different host binaries made during the build? I tested
x86_64and arm64. The commit message that added them missed any context or justification.
According to
http://llvm.linuxfoundation.org/index.php/Main_Page
llvm-linux was only successful for x86, arm(64)
at that time.
If you tested x86_64 and arm64, and saw no problem, it is fine.
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH v2 1/1 kbuild: clang: remove crufty HOSTCFLAGS
When compiling with make CC=clang HOSTCC=clang, I was seeing warnings that clang did not recognize -fno-delete-null-pointer-checks for HOSTCC targets. These were added in commit 61163efae020 ("kbuild: LLVMLinux:
Add Kbuild support for building kernel with Clang").
Clang does not support -fno-delete-null-pointer-checks, so adding it to HOSTCFLAGS if HOSTCC is clang does not make sense.
It's not clear why the other warnings were disabled, and just for HOSTCFLAGS, but I can remove them, add -Werror to HOSTCFLAGS and compile with clang just fine.
--- Makefile | 5 ----- 1 file changed, 5 deletions(-)
Makefile +0 -5
@@ -306,11 +306,6 @@ HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) HOST_LOADLIBES := $(HOST_LFS_LIBS) -ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1) -HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ - -Wno-missing-field-initializers -fno-delete-null-pointer-checks -endif - # Decide whether to build built-in, modular, or both. # Normally, just do built-in.
Signature · 1 line
2.11.0
Sorry, I forgot to note the changes in v2:
* Dont add back -fno-delete-null-pointer-checks wrapped in hostcc-option, just remove all flags.
* Update wording of commit message.
2017-10-08 5:23 GMT+09:00 Nick Desaulniers <[email protected]>:
Quoted 23 lines
When compiling with
make CC=clang HOSTCC=clang, I was seeing warnings that clang did not recognize -fno-delete-null-pointer-checks for HOSTCC targets. These were added in commit61163efae020("kbuild: LLVMLinux:
AddKbuildsupport for building kernel with Clang").Clang does not support -fno-delete-null-pointer-checks, so adding it to HOSTCFLAGS if HOSTCC is clang does not make sense.
It's not clear why the other warnings were disabled, and just for HOSTCFLAGS, but I can remove them, add -Werror to HOSTCFLAGS and compile with clang just fine.
Suggested-by Masahiro Yamada <[email protected]>Signed-off-by Nick Desaulniers <[email protected]>--- Makefile | 5 ----- 1 file changed, 5 deletions(-)Makefile +0
-0
Makefile HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) · line 312
Quoted 7 lines
Makefile +0
-4@@ -306,11 +306,6 @@ HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) HOST_LOADLIBES := $(HOST_LFS_LIBS) -ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1) -HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \ - -Wno-missing-field-initializers -fno-delete-null-pointer-checks -endif
Applied to linux-kbuild/kbuild. Thanks.
Signature · 2 lines
Best Regards Masahiro Yamada