Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit 490173c

Browse files
authored
kernel-cflags-finder: Set CONFIG_CC_IS_CLANG=y (#227)
Some of the things in the kernel's Makefile check whether `${CC} --version` is clang, which is affected by setting CC. Some look at CONFIG_CC_IS_CLANG, which was set at configuration time when our kernel was built. We need to override the latter to get clang-compatible flags. This causes the kernel to no longer set -W / -Wno flags that aren't valid for clang, so we can get rid of `-Wno-unknown-warning-option`. One problem with the previous approach is that the kernel's Makefile does feature detection to see what options are accepted by the current compiler, and it doesn't accept custom CFLAGS early enough for them to take effect during feature detection. Because the kernel sets `-Werror=unknown-warning-option` for clang (by checking the version of `${CC}`, unfortunately), all attempts at feature detection would fail with an unrelated error. This causes Makefile to wrongly conclude that the compiler doesn't support `-mfentry` and use mcount instead even if the compiled kernel expects fentry - i.e., this commit fixes #174. We might eventually need to set CONFIG_CLANG_VERSION and perhaps unset CONFIG_CC_IS_GCC, but this seems to work well enough for now.
1 parent 59110dc commit 490173c

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

kernel-cflags-finder/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
ifneq ($(KERNELRELEASE),)
22
obj-m += dummy.o
33
clean-files := dummy.c
4-
ccflags-y += -Wno-unknown-warning-option
54

65
# Some systems for installing kernel headers (e.g. Debian's) happen to
76
# trigger the out-of-tree build code because the kernel headers directly
@@ -30,7 +29,7 @@ else
3029
KDIR ?= /lib/modules/$(shell uname -r)/build
3130
CLANG ?= clang
3231
all:
33-
$(MAKE) -C $(KDIR) M=$(CURDIR) CC=$(CLANG)
32+
$(MAKE) -C $(KDIR) M=$(CURDIR) CC=$(CLANG) CONFIG_CC_IS_CLANG=y
3433
clean:
3534
$(MAKE) -C $(KDIR) M=$(CURDIR) clean
3635
endif

0 commit comments

Comments
 (0)