Skip to content

Commit be779f0

Browse files
committed
Merge tag 'kbuild-v4.18-2' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild
Pull more Kbuild updates from Masahiro Yamada: - fix some bugs introduced by the recent Kconfig syntax extension - add some symbols about compiler information in Kconfig, such as CC_IS_GCC, CC_IS_CLANG, GCC_VERSION, etc. - test compiler capability for the stack protector in Kconfig, and clean-up Makefile - test compiler capability for GCC-plugins in Kconfig, and clean-up Makefile - allow to enable GCC-plugins for COMPILE_TEST - test compiler capability for KCOV in Kconfig and correct dependency - remove auto-detect mode of the GCOV format, which is now more nicely handled in Kconfig - test compiler capability for mprofile-kernel on PowerPC, and clean-up Makefile - misc cleanups * tag 'kbuild-v4.18-2' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: linux/linkage.h: replace VMLINUX_SYMBOL_STR() with __stringify() kconfig: fix localmodconfig sh: remove no-op macro VMLINUX_SYMBOL() powerpc/kbuild: move -mprofile-kernel check to Kconfig Documentation: kconfig: add recommended way to describe compiler support gcc-plugins: disable GCC_PLUGIN_STRUCTLEAK_BYREF_ALL for COMPILE_TEST gcc-plugins: allow to enable GCC_PLUGINS for COMPILE_TEST gcc-plugins: test plugin support in Kconfig and clean up Makefile gcc-plugins: move GCC version check for PowerPC to Kconfig kcov: test compiler capability in Kconfig and correct dependency gcov: remove CONFIG_GCOV_FORMAT_AUTODETECT arm64: move GCC version check for ARCH_SUPPORTS_INT128 to Kconfig kconfig: add CC_IS_CLANG and CLANG_VERSION kconfig: add CC_IS_GCC and GCC_VERSION stack-protector: test compiler capability in Kconfig and drop AUTO mode kbuild: fix endless syncconfig in case arch Makefile sets CROSS_COMPILE
2 parents d290ef9 + 00979ce commit be779f0

File tree

26 files changed

+173
-308
lines changed

26 files changed

+173
-308
lines changed

Documentation/kbuild/kconfig-language.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,24 @@ config option to 'y' no matter the dependencies.
473473
The dependencies are moved to the symbol GENERIC_IOMAP and we avoid the
474474
situation where select forces a symbol equals to 'y'.
475475

476+
Adding features that need compiler support
477+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
478+
479+
There are several features that need compiler support. The recommended way
480+
to describe the dependency on the compiler feature is to use "depends on"
481+
followed by a test macro.
482+
483+
config CC_STACKPROTECTOR
484+
bool "Stack Protector buffer overflow detection"
485+
depends on $(cc-option,-fstack-protector)
486+
...
487+
488+
If you need to expose a compiler capability to makefiles and/or C source files,
489+
CC_HAS_ is the recommended prefix for the config option.
490+
491+
config CC_HAS_STACKPROTECTOR_NONE
492+
def_bool $(cc-option,-fno-stack-protector)
493+
476494
Build as module only
477495
~~~~~~~~~~~~~~~~~~~~
478496
To restrict a component build to module-only, qualify its config symbol

Makefile

Lines changed: 36 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,6 @@ export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
442442
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
443443
export KBUILD_ARFLAGS
444444

445-
export CC_VERSION_TEXT := $(shell $(CC) --version | head -n 1)
446-
447445
# When compiling out-of-tree modules, put MODVERDIR in the module
448446
# tree rather than in the kernel tree. The kernel tree might
449447
# even be read-only.
@@ -514,6 +512,12 @@ ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/cc-can-link.sh $(CC)), y)
514512
export CC_CAN_LINK
515513
endif
516514

515+
# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
516+
# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
517+
# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
518+
# and from include/config/auto.conf.cmd to detect the compiler upgrade.
519+
CC_VERSION_TEXT = $(shell $(CC) --version | head -n 1)
520+
517521
ifeq ($(config-targets),1)
518522
# ===========================================================================
519523
# *config targets only - make sure prerequisites are updated, and descend
@@ -523,7 +527,7 @@ ifeq ($(config-targets),1)
523527
# KBUILD_DEFCONFIG may point out an alternative default configuration
524528
# used for 'make defconfig'
525529
include arch/$(SRCARCH)/Makefile
526-
export KBUILD_DEFCONFIG KBUILD_KCONFIG
530+
export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
527531

528532
config: scripts_basic outputmakefile FORCE
529533
$(Q)$(MAKE) $(build)=scripts/kconfig $@
@@ -585,12 +589,32 @@ virt-y := virt/
585589
endif # KBUILD_EXTMOD
586590

587591
ifeq ($(dot-config),1)
588-
# Read in config
589592
-include include/config/auto.conf
593+
endif
594+
595+
# The all: target is the default when no target is given on the
596+
# command line.
597+
# This allow a user to issue only 'make' to build a kernel including modules
598+
# Defaults to vmlinux, but the arch makefile usually adds further targets
599+
all: vmlinux
600+
601+
CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
602+
$(call cc-option,-fno-tree-loop-im) \
603+
$(call cc-disable-warning,maybe-uninitialized,)
604+
export CFLAGS_GCOV
590605

606+
# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
607+
# values of the respective KBUILD_* variables
608+
ARCH_CPPFLAGS :=
609+
ARCH_AFLAGS :=
610+
ARCH_CFLAGS :=
611+
include arch/$(SRCARCH)/Makefile
612+
613+
ifeq ($(dot-config),1)
591614
ifeq ($(KBUILD_EXTMOD),)
592-
# Read in dependencies to all Kconfig* files, make sure to run
593-
# oldconfig if changes are detected.
615+
# Read in dependencies to all Kconfig* files, make sure to run syncconfig if
616+
# changes are detected. This should be included after arch/$(SRCARCH)/Makefile
617+
# because some architectures define CROSS_COMPILE there.
594618
-include include/config/auto.conf.cmd
595619

596620
# To avoid any implicit rule to kick in, define an empty command
@@ -622,24 +646,6 @@ else
622646
include/config/auto.conf: ;
623647
endif # $(dot-config)
624648

625-
# The all: target is the default when no target is given on the
626-
# command line.
627-
# This allow a user to issue only 'make' to build a kernel including modules
628-
# Defaults to vmlinux, but the arch makefile usually adds further targets
629-
all: vmlinux
630-
631-
CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
632-
$(call cc-option,-fno-tree-loop-im) \
633-
$(call cc-disable-warning,maybe-uninitialized,)
634-
export CFLAGS_GCOV CFLAGS_KCOV
635-
636-
# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
637-
# values of the respective KBUILD_* variables
638-
ARCH_CPPFLAGS :=
639-
ARCH_AFLAGS :=
640-
ARCH_CFLAGS :=
641-
include arch/$(SRCARCH)/Makefile
642-
643649
KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,)
644650
KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
645651
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
@@ -680,55 +686,11 @@ ifneq ($(CONFIG_FRAME_WARN),0)
680686
KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
681687
endif
682688

683-
# This selects the stack protector compiler flag. Testing it is delayed
684-
# until after .config has been reprocessed, in the prepare-compiler-check
685-
# target.
686-
ifdef CONFIG_CC_STACKPROTECTOR_AUTO
687-
stackp-flag := $(call cc-option,-fstack-protector-strong,$(call cc-option,-fstack-protector))
688-
stackp-name := AUTO
689-
else
690-
ifdef CONFIG_CC_STACKPROTECTOR_REGULAR
691-
stackp-flag := -fstack-protector
692-
stackp-name := REGULAR
693-
else
694-
ifdef CONFIG_CC_STACKPROTECTOR_STRONG
695-
stackp-flag := -fstack-protector-strong
696-
stackp-name := STRONG
697-
else
698-
# If either there is no stack protector for this architecture or
699-
# CONFIG_CC_STACKPROTECTOR_NONE is selected, we're done, and $(stackp-name)
700-
# is empty, skipping all remaining stack protector tests.
701-
#
702-
# Force off for distro compilers that enable stack protector by default.
703-
KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector)
704-
endif
705-
endif
706-
endif
707-
# Find arch-specific stack protector compiler sanity-checking script.
708-
ifdef stackp-name
709-
ifneq ($(stackp-flag),)
710-
stackp-path := $(srctree)/scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh
711-
stackp-check := $(wildcard $(stackp-path))
712-
# If the wildcard test matches a test script, run it to check functionality.
713-
ifdef stackp-check
714-
ifneq ($(shell $(CONFIG_SHELL) $(stackp-check) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
715-
stackp-broken := y
716-
endif
717-
endif
718-
ifndef stackp-broken
719-
# If the stack protector is functional, enable code that depends on it.
720-
KBUILD_CPPFLAGS += -DCONFIG_CC_STACKPROTECTOR
721-
# Either we've already detected the flag (for AUTO) or we'll fail the
722-
# build in the prepare-compiler-check rule (for specific flag).
723-
KBUILD_CFLAGS += $(stackp-flag)
724-
else
725-
# We have to make sure stack protector is unconditionally disabled if
726-
# the compiler is broken (in case we're going to continue the build in
727-
# AUTO mode).
728-
KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector)
729-
endif
730-
endif
731-
endif
689+
stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector
690+
stackp-flags-$(CONFIG_CC_STACKPROTECTOR) := -fstack-protector
691+
stackp-flags-$(CONFIG_CC_STACKPROTECTOR_STRONG) := -fstack-protector-strong
692+
693+
KBUILD_CFLAGS += $(stackp-flags-y)
732694

733695
ifeq ($(cc-name),clang)
734696
KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
@@ -1112,7 +1074,7 @@ endif
11121074
# prepare2 creates a makefile if using a separate output directory.
11131075
# From this point forward, .config has been reprocessed, so any rules
11141076
# that need to depend on updated CONFIG_* values can be checked here.
1115-
prepare2: prepare3 prepare-compiler-check outputmakefile asm-generic
1077+
prepare2: prepare3 outputmakefile asm-generic
11161078

11171079
prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h \
11181080
include/config/auto.conf
@@ -1138,43 +1100,6 @@ uapi-asm-generic:
11381100
PHONY += prepare-objtool
11391101
prepare-objtool: $(objtool_target)
11401102

1141-
# Check for CONFIG flags that require compiler support. Abort the build
1142-
# after .config has been processed, but before the kernel build starts.
1143-
#
1144-
# For security-sensitive CONFIG options, we don't want to fallback and/or
1145-
# silently change which compiler flags will be used, since that leads to
1146-
# producing kernels with different security feature characteristics
1147-
# depending on the compiler used. (For example, "But I selected
1148-
# CC_STACKPROTECTOR_STRONG! Why did it build with _REGULAR?!")
1149-
PHONY += prepare-compiler-check
1150-
prepare-compiler-check: FORCE
1151-
# Make sure compiler supports requested stack protector flag.
1152-
ifdef stackp-name
1153-
# Warn about CONFIG_CC_STACKPROTECTOR_AUTO having found no option.
1154-
ifeq ($(stackp-flag),)
1155-
@echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \
1156-
Compiler does not support any known stack-protector >&2
1157-
else
1158-
# Fail if specifically requested stack protector is missing.
1159-
ifeq ($(call cc-option, $(stackp-flag)),)
1160-
@echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \
1161-
$(stackp-flag) not supported by compiler >&2 && exit 1
1162-
endif
1163-
endif
1164-
endif
1165-
# Make sure compiler does not have buggy stack-protector support. If a
1166-
# specific stack-protector was requested, fail the build, otherwise warn.
1167-
ifdef stackp-broken
1168-
ifeq ($(stackp-name),AUTO)
1169-
@echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \
1170-
$(stackp-flag) available but compiler is broken: disabling >&2
1171-
else
1172-
@echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \
1173-
$(stackp-flag) available but compiler is broken >&2 && exit 1
1174-
endif
1175-
endif
1176-
@:
1177-
11781103
# Generate some files
11791104
# ---------------------------------------------------------------------------
11801105

arch/Kconfig

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,15 @@ config SECCOMP_FILTER
405405

406406
See Documentation/prctl/seccomp_filter.txt for details.
407407

408+
preferred-plugin-hostcc := $(if-success,[ $(gcc-version) -ge 40800 ],$(HOSTCXX),$(HOSTCC))
409+
410+
config PLUGIN_HOSTCC
411+
string
412+
default "$(shell,$(srctree)/scripts/gcc-plugin.sh "$(preferred-plugin-hostcc)" "$(HOSTCXX)" "$(CC)")"
413+
help
414+
Host compiler used to build GCC plugins. This can be $(HOSTCXX),
415+
$(HOSTCC), or a null string if GCC plugin is unsupported.
416+
408417
config HAVE_GCC_PLUGINS
409418
bool
410419
help
@@ -414,7 +423,7 @@ config HAVE_GCC_PLUGINS
414423
menuconfig GCC_PLUGINS
415424
bool "GCC plugins"
416425
depends on HAVE_GCC_PLUGINS
417-
depends on !COMPILE_TEST
426+
depends on PLUGIN_HOSTCC != ""
418427
help
419428
GCC plugins are loadable modules that provide extra features to the
420429
compiler. They are useful for runtime instrumentation and static analysis.
@@ -424,7 +433,7 @@ menuconfig GCC_PLUGINS
424433
config GCC_PLUGIN_CYC_COMPLEXITY
425434
bool "Compute the cyclomatic complexity of a function" if EXPERT
426435
depends on GCC_PLUGINS
427-
depends on !COMPILE_TEST
436+
depends on !COMPILE_TEST # too noisy
428437
help
429438
The complexity M of a function's control flow graph is defined as:
430439
M = E - N + 2P
@@ -484,14 +493,15 @@ config GCC_PLUGIN_STRUCTLEAK
484493
config GCC_PLUGIN_STRUCTLEAK_BYREF_ALL
485494
bool "Force initialize all struct type variables passed by reference"
486495
depends on GCC_PLUGIN_STRUCTLEAK
496+
depends on !COMPILE_TEST
487497
help
488498
Zero initialize any struct type local variable that may be passed by
489499
reference without having been initialized.
490500

491501
config GCC_PLUGIN_STRUCTLEAK_VERBOSE
492502
bool "Report forcefully initialized variables"
493503
depends on GCC_PLUGIN_STRUCTLEAK
494-
depends on !COMPILE_TEST
504+
depends on !COMPILE_TEST # too noisy
495505
help
496506
This option will cause a warning to be printed each time the
497507
structleak plugin finds a variable it thinks needs to be
@@ -531,7 +541,7 @@ config GCC_PLUGIN_RANDSTRUCT
531541
config GCC_PLUGIN_RANDSTRUCT_PERFORMANCE
532542
bool "Use cacheline-aware structure randomization"
533543
depends on GCC_PLUGIN_RANDSTRUCT
534-
depends on !COMPILE_TEST
544+
depends on !COMPILE_TEST # do not reduce test coverage
535545
help
536546
If you say Y here, the RANDSTRUCT randomization will make a
537547
best effort at restricting randomization to cacheline-sized
@@ -543,13 +553,16 @@ config HAVE_CC_STACKPROTECTOR
543553
bool
544554
help
545555
An arch should select this symbol if:
546-
- its compiler supports the -fstack-protector option
547556
- it has implemented a stack canary (e.g. __stack_chk_guard)
548557

549-
choice
550-
prompt "Stack Protector buffer overflow detection"
558+
config CC_HAS_STACKPROTECTOR_NONE
559+
def_bool $(cc-option,-fno-stack-protector)
560+
561+
config CC_STACKPROTECTOR
562+
bool "Stack Protector buffer overflow detection"
551563
depends on HAVE_CC_STACKPROTECTOR
552-
default CC_STACKPROTECTOR_AUTO
564+
depends on $(cc-option,-fstack-protector)
565+
default y
553566
help
554567
This option turns on the "stack-protector" GCC feature. This
555568
feature puts, at the beginning of functions, a canary value on
@@ -559,14 +572,6 @@ choice
559572
overwrite the canary, which gets detected and the attack is then
560573
neutralized via a kernel panic.
561574

562-
config CC_STACKPROTECTOR_NONE
563-
bool "None"
564-
help
565-
Disable "stack-protector" GCC feature.
566-
567-
config CC_STACKPROTECTOR_REGULAR
568-
bool "Regular"
569-
help
570575
Functions will have the stack-protector canary logic added if they
571576
have an 8-byte or larger character array on the stack.
572577

@@ -578,7 +583,10 @@ config CC_STACKPROTECTOR_REGULAR
578583
by about 0.3%.
579584

580585
config CC_STACKPROTECTOR_STRONG
581-
bool "Strong"
586+
bool "Strong Stack Protector"
587+
depends on CC_STACKPROTECTOR
588+
depends on $(cc-option,-fstack-protector-strong)
589+
default y
582590
help
583591
Functions will have the stack-protector canary logic added in any
584592
of the following conditions:
@@ -596,14 +604,6 @@ config CC_STACKPROTECTOR_STRONG
596604
about 20% of all kernel functions, which increases the kernel code
597605
size by about 2%.
598606

599-
config CC_STACKPROTECTOR_AUTO
600-
bool "Automatic"
601-
help
602-
If the compiler supports it, the best available stack-protector
603-
option will be chosen.
604-
605-
endchoice
606-
607607
config HAVE_ARCH_WITHIN_STACK_FRAMES
608608
bool
609609
help

arch/arm64/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ config ARM64
4646
select ARCH_USE_QUEUED_RWLOCKS
4747
select ARCH_SUPPORTS_MEMORY_FAILURE
4848
select ARCH_SUPPORTS_ATOMIC_RMW
49+
select ARCH_SUPPORTS_INT128 if GCC_VERSION >= 50000 || CC_IS_CLANG
4950
select ARCH_SUPPORTS_NUMA_BALANCING
5051
select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
5152
select ARCH_WANT_FRAME_POINTERS

arch/arm64/Makefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ KBUILD_AFLAGS += $(lseinstr) $(brokengasinst)
5656
KBUILD_CFLAGS += $(call cc-option,-mabi=lp64)
5757
KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
5858

59-
ifeq ($(cc-name),clang)
60-
KBUILD_CFLAGS += -DCONFIG_ARCH_SUPPORTS_INT128
61-
else
62-
KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0500, -DCONFIG_ARCH_SUPPORTS_INT128)
63-
endif
64-
6559
ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
6660
KBUILD_CPPFLAGS += -mbig-endian
6761
CHECKFLAGS += -D__AARCH64EB__

0 commit comments

Comments
 (0)