Skip to content

Commit 433dc2e

Browse files
committed
kbuild: do not call cc-option before KBUILD_CFLAGS initialization
Some $(call cc-option,...) are invoked very early, even before KBUILD_CFLAGS, etc. are initialized. The returned string from $(call cc-option,...) depends on KBUILD_CPPFLAGS, KBUILD_CFLAGS, and GCC_PLUGINS_CFLAGS. Since they are exported, they are not empty when the top Makefile is recursively invoked. The recursion occurs in several places. For example, the top Makefile invokes itself for silentoldconfig. "make tinyconfig", "make rpm-pkg" are the cases, too. In those cases, the second call of cc-option from the same line runs a different shell command due to non-pristine KBUILD_CFLAGS. To get the same result all the time, KBUILD_* and GCC_PLUGINS_CFLAGS must be initialized before any call of cc-option. This avoids garbage data in the .cache.mk file. Move all calls of cc-option below the config targets because target compiler flags are unnecessary for Kconfig. Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Douglas Anderson <[email protected]>
1 parent 4e56207 commit 433dc2e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Makefile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,6 @@ LDFLAGS_MODULE =
392392
CFLAGS_KERNEL =
393393
AFLAGS_KERNEL =
394394
LDFLAGS_vmlinux =
395-
CFLAGS_GCOV := -fprofile-arcs -ftest-coverage -fno-tree-loop-im $(call cc-disable-warning,maybe-uninitialized,)
396-
CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,)
397-
398395

399396
# Use USERINCLUDE when you must reference the UAPI directories only.
400397
USERINCLUDE := \
@@ -413,29 +410,27 @@ LINUXINCLUDE := \
413410
-I$(objtree)/include \
414411
$(USERINCLUDE)
415412

416-
KBUILD_CPPFLAGS := -D__KERNEL__
417-
413+
KBUILD_AFLAGS := -D__ASSEMBLY__
418414
KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
419415
-fno-strict-aliasing -fno-common -fshort-wchar \
420416
-Werror-implicit-function-declaration \
421417
-Wno-format-security \
422-
-std=gnu89 $(call cc-option,-fno-PIE)
423-
424-
418+
-std=gnu89
419+
KBUILD_CPPFLAGS := -D__KERNEL__
425420
KBUILD_AFLAGS_KERNEL :=
426421
KBUILD_CFLAGS_KERNEL :=
427-
KBUILD_AFLAGS := -D__ASSEMBLY__ $(call cc-option,-fno-PIE)
428422
KBUILD_AFLAGS_MODULE := -DMODULE
429423
KBUILD_CFLAGS_MODULE := -DMODULE
430424
KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
425+
GCC_PLUGINS_CFLAGS :=
431426

432427
export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
433428
export CPP AR NM STRIP OBJCOPY OBJDUMP HOSTLDFLAGS HOST_LOADLIBES
434429
export MAKE AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE
435430
export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
436431

437432
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
438-
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV CFLAGS_KCOV CFLAGS_KASAN CFLAGS_UBSAN
433+
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_KASAN CFLAGS_UBSAN
439434
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
440435
export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
441436
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
@@ -607,6 +602,12 @@ endif
607602
# Defaults to vmlinux, but the arch makefile usually adds further targets
608603
all: vmlinux
609604

605+
KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
606+
KBUILD_AFLAGS += $(call cc-option,-fno-PIE)
607+
CFLAGS_GCOV := -fprofile-arcs -ftest-coverage -fno-tree-loop-im $(call cc-disable-warning,maybe-uninitialized,)
608+
CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,)
609+
export CFLAGS_GCOV CFLAGS_KCOV
610+
610611
# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
611612
# values of the respective KBUILD_* variables
612613
ARCH_CPPFLAGS :=

0 commit comments

Comments
 (0)