Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+177 -312
+18
Documentation/kbuild/kconfig-language.txt
··· 473 473 The dependencies are moved to the symbol GENERIC_IOMAP and we avoid the 474 474 situation where select forces a symbol equals to 'y'. 475 475 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 + 476 494 Build as module only 477 495 ~~~~~~~~~~~~~~~~~~~~ 478 496 To restrict a component build to module-only, qualify its config symbol
+36 -111
Makefile
··· 442 442 export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL 443 443 export KBUILD_ARFLAGS 444 444 445 - export CC_VERSION_TEXT := $(shell $(CC) --version | head -n 1) 446 - 447 445 # When compiling out-of-tree modules, put MODVERDIR in the module 448 446 # tree rather than in the kernel tree. The kernel tree might 449 447 # even be read-only. ··· 512 514 export CC_CAN_LINK 513 515 endif 514 516 517 + # The expansion should be delayed until arch/$(SRCARCH)/Makefile is included. 518 + # Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile. 519 + # CC_VERSION_TEXT is referenced from Kconfig (so it needs export), 520 + # and from include/config/auto.conf.cmd to detect the compiler upgrade. 521 + CC_VERSION_TEXT = $(shell $(CC) --version | head -n 1) 522 + 515 523 ifeq ($(config-targets),1) 516 524 # =========================================================================== 517 525 # *config targets only - make sure prerequisites are updated, and descend ··· 527 523 # KBUILD_DEFCONFIG may point out an alternative default configuration 528 524 # used for 'make defconfig' 529 525 include arch/$(SRCARCH)/Makefile 530 - export KBUILD_DEFCONFIG KBUILD_KCONFIG 526 + export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT 531 527 532 528 config: scripts_basic outputmakefile FORCE 533 529 $(Q)$(MAKE) $(build)=scripts/kconfig $@ ··· 589 585 endif # KBUILD_EXTMOD 590 586 591 587 ifeq ($(dot-config),1) 592 - # Read in config 593 588 -include include/config/auto.conf 589 + endif 594 590 591 + # The all: target is the default when no target is given on the 592 + # command line. 593 + # This allow a user to issue only 'make' to build a kernel including modules 594 + # Defaults to vmlinux, but the arch makefile usually adds further targets 595 + all: vmlinux 596 + 597 + CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \ 598 + $(call cc-option,-fno-tree-loop-im) \ 599 + $(call cc-disable-warning,maybe-uninitialized,) 600 + export CFLAGS_GCOV 601 + 602 + # The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default 603 + # values of the respective KBUILD_* variables 604 + ARCH_CPPFLAGS := 605 + ARCH_AFLAGS := 606 + ARCH_CFLAGS := 607 + include arch/$(SRCARCH)/Makefile 608 + 609 + ifeq ($(dot-config),1) 595 610 ifeq ($(KBUILD_EXTMOD),) 596 - # Read in dependencies to all Kconfig* files, make sure to run 597 - # oldconfig if changes are detected. 611 + # Read in dependencies to all Kconfig* files, make sure to run syncconfig if 612 + # changes are detected. This should be included after arch/$(SRCARCH)/Makefile 613 + # because some architectures define CROSS_COMPILE there. 598 614 -include include/config/auto.conf.cmd 599 615 600 616 # To avoid any implicit rule to kick in, define an empty command ··· 645 621 # Dummy target needed, because used as prerequisite 646 622 include/config/auto.conf: ; 647 623 endif # $(dot-config) 648 - 649 - # The all: target is the default when no target is given on the 650 - # command line. 651 - # This allow a user to issue only 'make' to build a kernel including modules 652 - # Defaults to vmlinux, but the arch makefile usually adds further targets 653 - all: vmlinux 654 - 655 - CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \ 656 - $(call cc-option,-fno-tree-loop-im) \ 657 - $(call cc-disable-warning,maybe-uninitialized,) 658 - export CFLAGS_GCOV CFLAGS_KCOV 659 - 660 - # The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default 661 - # values of the respective KBUILD_* variables 662 - ARCH_CPPFLAGS := 663 - ARCH_AFLAGS := 664 - ARCH_CFLAGS := 665 - include arch/$(SRCARCH)/Makefile 666 624 667 625 KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) 668 626 KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) ··· 686 680 KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN}) 687 681 endif 688 682 689 - # This selects the stack protector compiler flag. Testing it is delayed 690 - # until after .config has been reprocessed, in the prepare-compiler-check 691 - # target. 692 - ifdef CONFIG_CC_STACKPROTECTOR_AUTO 693 - stackp-flag := $(call cc-option,-fstack-protector-strong,$(call cc-option,-fstack-protector)) 694 - stackp-name := AUTO 695 - else 696 - ifdef CONFIG_CC_STACKPROTECTOR_REGULAR 697 - stackp-flag := -fstack-protector 698 - stackp-name := REGULAR 699 - else 700 - ifdef CONFIG_CC_STACKPROTECTOR_STRONG 701 - stackp-flag := -fstack-protector-strong 702 - stackp-name := STRONG 703 - else 704 - # If either there is no stack protector for this architecture or 705 - # CONFIG_CC_STACKPROTECTOR_NONE is selected, we're done, and $(stackp-name) 706 - # is empty, skipping all remaining stack protector tests. 707 - # 708 - # Force off for distro compilers that enable stack protector by default. 709 - KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector) 710 - endif 711 - endif 712 - endif 713 - # Find arch-specific stack protector compiler sanity-checking script. 714 - ifdef stackp-name 715 - ifneq ($(stackp-flag),) 716 - stackp-path := $(srctree)/scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh 717 - stackp-check := $(wildcard $(stackp-path)) 718 - # If the wildcard test matches a test script, run it to check functionality. 719 - ifdef stackp-check 720 - ifneq ($(shell $(CONFIG_SHELL) $(stackp-check) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y) 721 - stackp-broken := y 722 - endif 723 - endif 724 - ifndef stackp-broken 725 - # If the stack protector is functional, enable code that depends on it. 726 - KBUILD_CPPFLAGS += -DCONFIG_CC_STACKPROTECTOR 727 - # Either we've already detected the flag (for AUTO) or we'll fail the 728 - # build in the prepare-compiler-check rule (for specific flag). 729 - KBUILD_CFLAGS += $(stackp-flag) 730 - else 731 - # We have to make sure stack protector is unconditionally disabled if 732 - # the compiler is broken (in case we're going to continue the build in 733 - # AUTO mode). 734 - KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector) 735 - endif 736 - endif 737 - endif 683 + stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector 684 + stackp-flags-$(CONFIG_CC_STACKPROTECTOR) := -fstack-protector 685 + stackp-flags-$(CONFIG_CC_STACKPROTECTOR_STRONG) := -fstack-protector-strong 686 + 687 + KBUILD_CFLAGS += $(stackp-flags-y) 738 688 739 689 ifeq ($(cc-name),clang) 740 690 KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) ··· 1074 1112 # prepare2 creates a makefile if using a separate output directory. 1075 1113 # From this point forward, .config has been reprocessed, so any rules 1076 1114 # that need to depend on updated CONFIG_* values can be checked here. 1077 - prepare2: prepare3 prepare-compiler-check outputmakefile asm-generic 1115 + prepare2: prepare3 outputmakefile asm-generic 1078 1116 1079 1117 prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h \ 1080 1118 include/config/auto.conf ··· 1099 1137 1100 1138 PHONY += prepare-objtool 1101 1139 prepare-objtool: $(objtool_target) 1102 - 1103 - # Check for CONFIG flags that require compiler support. Abort the build 1104 - # after .config has been processed, but before the kernel build starts. 1105 - # 1106 - # For security-sensitive CONFIG options, we don't want to fallback and/or 1107 - # silently change which compiler flags will be used, since that leads to 1108 - # producing kernels with different security feature characteristics 1109 - # depending on the compiler used. (For example, "But I selected 1110 - # CC_STACKPROTECTOR_STRONG! Why did it build with _REGULAR?!") 1111 - PHONY += prepare-compiler-check 1112 - prepare-compiler-check: FORCE 1113 - # Make sure compiler supports requested stack protector flag. 1114 - ifdef stackp-name 1115 - # Warn about CONFIG_CC_STACKPROTECTOR_AUTO having found no option. 1116 - ifeq ($(stackp-flag),) 1117 - @echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ 1118 - Compiler does not support any known stack-protector >&2 1119 - else 1120 - # Fail if specifically requested stack protector is missing. 1121 - ifeq ($(call cc-option, $(stackp-flag)),) 1122 - @echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ 1123 - $(stackp-flag) not supported by compiler >&2 && exit 1 1124 - endif 1125 - endif 1126 - endif 1127 - # Make sure compiler does not have buggy stack-protector support. If a 1128 - # specific stack-protector was requested, fail the build, otherwise warn. 1129 - ifdef stackp-broken 1130 - ifeq ($(stackp-name),AUTO) 1131 - @echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ 1132 - $(stackp-flag) available but compiler is broken: disabling >&2 1133 - else 1134 - @echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ 1135 - $(stackp-flag) available but compiler is broken >&2 && exit 1 1136 - endif 1137 - endif 1138 - @: 1139 1140 1140 1141 # Generate some files 1141 1142 # ---------------------------------------------------------------------------
+25 -25
arch/Kconfig
··· 405 405 406 406 See Documentation/prctl/seccomp_filter.txt for details. 407 407 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 + 408 417 config HAVE_GCC_PLUGINS 409 418 bool 410 419 help ··· 423 414 menuconfig GCC_PLUGINS 424 415 bool "GCC plugins" 425 416 depends on HAVE_GCC_PLUGINS 426 - depends on !COMPILE_TEST 417 + depends on PLUGIN_HOSTCC != "" 427 418 help 428 419 GCC plugins are loadable modules that provide extra features to the 429 420 compiler. They are useful for runtime instrumentation and static analysis. ··· 433 424 config GCC_PLUGIN_CYC_COMPLEXITY 434 425 bool "Compute the cyclomatic complexity of a function" if EXPERT 435 426 depends on GCC_PLUGINS 436 - depends on !COMPILE_TEST 427 + depends on !COMPILE_TEST # too noisy 437 428 help 438 429 The complexity M of a function's control flow graph is defined as: 439 430 M = E - N + 2P ··· 493 484 config GCC_PLUGIN_STRUCTLEAK_BYREF_ALL 494 485 bool "Force initialize all struct type variables passed by reference" 495 486 depends on GCC_PLUGIN_STRUCTLEAK 487 + depends on !COMPILE_TEST 496 488 help 497 489 Zero initialize any struct type local variable that may be passed by 498 490 reference without having been initialized. ··· 501 491 config GCC_PLUGIN_STRUCTLEAK_VERBOSE 502 492 bool "Report forcefully initialized variables" 503 493 depends on GCC_PLUGIN_STRUCTLEAK 504 - depends on !COMPILE_TEST 494 + depends on !COMPILE_TEST # too noisy 505 495 help 506 496 This option will cause a warning to be printed each time the 507 497 structleak plugin finds a variable it thinks needs to be ··· 541 531 config GCC_PLUGIN_RANDSTRUCT_PERFORMANCE 542 532 bool "Use cacheline-aware structure randomization" 543 533 depends on GCC_PLUGIN_RANDSTRUCT 544 - depends on !COMPILE_TEST 534 + depends on !COMPILE_TEST # do not reduce test coverage 545 535 help 546 536 If you say Y here, the RANDSTRUCT randomization will make a 547 537 best effort at restricting randomization to cacheline-sized ··· 553 543 bool 554 544 help 555 545 An arch should select this symbol if: 556 - - its compiler supports the -fstack-protector option 557 546 - it has implemented a stack canary (e.g. __stack_chk_guard) 558 547 559 - choice 560 - prompt "Stack Protector buffer overflow detection" 548 + config CC_HAS_STACKPROTECTOR_NONE 549 + def_bool $(cc-option,-fno-stack-protector) 550 + 551 + config CC_STACKPROTECTOR 552 + bool "Stack Protector buffer overflow detection" 561 553 depends on HAVE_CC_STACKPROTECTOR 562 - default CC_STACKPROTECTOR_AUTO 554 + depends on $(cc-option,-fstack-protector) 555 + default y 563 556 help 564 557 This option turns on the "stack-protector" GCC feature. This 565 558 feature puts, at the beginning of functions, a canary value on ··· 572 559 overwrite the canary, which gets detected and the attack is then 573 560 neutralized via a kernel panic. 574 561 575 - config CC_STACKPROTECTOR_NONE 576 - bool "None" 577 - help 578 - Disable "stack-protector" GCC feature. 579 - 580 - config CC_STACKPROTECTOR_REGULAR 581 - bool "Regular" 582 - help 583 562 Functions will have the stack-protector canary logic added if they 584 563 have an 8-byte or larger character array on the stack. 585 564 ··· 583 578 by about 0.3%. 584 579 585 580 config CC_STACKPROTECTOR_STRONG 586 - bool "Strong" 581 + bool "Strong Stack Protector" 582 + depends on CC_STACKPROTECTOR 583 + depends on $(cc-option,-fstack-protector-strong) 584 + default y 587 585 help 588 586 Functions will have the stack-protector canary logic added in any 589 587 of the following conditions: ··· 603 595 On an x86 "defconfig" build, this feature adds canary checks to 604 596 about 20% of all kernel functions, which increases the kernel code 605 597 size by about 2%. 606 - 607 - config CC_STACKPROTECTOR_AUTO 608 - bool "Automatic" 609 - help 610 - If the compiler supports it, the best available stack-protector 611 - option will be chosen. 612 - 613 - endchoice 614 598 615 599 config HAVE_ARCH_WITHIN_STACK_FRAMES 616 600 bool
+1
arch/arm64/Kconfig
··· 46 46 select ARCH_USE_QUEUED_RWLOCKS 47 47 select ARCH_SUPPORTS_MEMORY_FAILURE 48 48 select ARCH_SUPPORTS_ATOMIC_RMW 49 + select ARCH_SUPPORTS_INT128 if GCC_VERSION >= 50000 || CC_IS_CLANG 49 50 select ARCH_SUPPORTS_NUMA_BALANCING 50 51 select ARCH_WANT_COMPAT_IPC_PARSE_VERSION 51 52 select ARCH_WANT_FRAME_POINTERS
-6
arch/arm64/Makefile
··· 56 56 KBUILD_CFLAGS += $(call cc-option,-mabi=lp64) 57 57 KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) 58 58 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 - 65 59 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y) 66 60 KBUILD_CPPFLAGS += -mbig-endian 67 61 CHECKFLAGS += -D__AARCH64EB__
+2 -16
arch/powerpc/Kconfig
··· 190 190 select HAVE_FTRACE_MCOUNT_RECORD 191 191 select HAVE_FUNCTION_GRAPH_TRACER 192 192 select HAVE_FUNCTION_TRACER 193 - select HAVE_GCC_PLUGINS 193 + select HAVE_GCC_PLUGINS if GCC_VERSION >= 50200 # plugin support on gcc <= 5.1 is buggy on PPC 194 194 select HAVE_GENERIC_GUP 195 195 select HAVE_HW_BREAKPOINT if PERF_EVENTS && (PPC_BOOK3S || PPC_8xx) 196 196 select HAVE_IDE ··· 461 461 462 462 If unsure, say "N". 463 463 464 - config DISABLE_MPROFILE_KERNEL 465 - bool "Disable use of mprofile-kernel for kernel tracing" 466 - depends on PPC64 && CPU_LITTLE_ENDIAN 467 - default y 468 - help 469 - Selecting this options disables use of the mprofile-kernel ABI for 470 - kernel tracing. That will cause options such as live patching 471 - (CONFIG_LIVEPATCH) which depend on CONFIG_DYNAMIC_FTRACE_WITH_REGS to 472 - be disabled also. 473 - 474 - If you have a toolchain which supports mprofile-kernel, then you can 475 - disable this. Otherwise leave it enabled. If you're not sure, say 476 - "Y". 477 - 478 464 config MPROFILE_KERNEL 479 465 depends on PPC64 && CPU_LITTLE_ENDIAN 480 - def_bool !DISABLE_MPROFILE_KERNEL 466 + def_bool $(success,$(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -I$(srctree)/include -D__KERNEL__) 481 467 482 468 config HOTPLUG_CPU 483 469 bool "Support for enabling/disabling CPUs"
+1 -12
arch/powerpc/Makefile
··· 161 161 endif 162 162 163 163 ifdef CONFIG_MPROFILE_KERNEL 164 - ifeq ($(shell $(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -I$(srctree)/include -D__KERNEL__),OK) 165 - CC_FLAGS_FTRACE := -pg -mprofile-kernel 166 - KBUILD_CPPFLAGS += -DCC_USING_MPROFILE_KERNEL 167 - else 168 - # If the user asked for mprofile-kernel but the toolchain doesn't 169 - # support it, emit a warning and deliberately break the build later 170 - # with mprofile-kernel-not-supported. We would prefer to make this an 171 - # error right here, but then the user would never be able to run 172 - # oldconfig to change their configuration. 173 - $(warning Compiler does not support mprofile-kernel, set CONFIG_DISABLE_MPROFILE_KERNEL) 174 - CC_FLAGS_FTRACE := -mprofile-kernel-not-supported 175 - endif 164 + CC_FLAGS_FTRACE := -pg -mprofile-kernel 176 165 endif 177 166 178 167 CFLAGS-$(CONFIG_CELL_CPU) += $(call cc-option,-mcpu=cell)
+1 -1
arch/powerpc/include/asm/module.h
··· 14 14 #include <asm-generic/module.h> 15 15 16 16 17 - #ifdef CC_USING_MPROFILE_KERNEL 17 + #ifdef CONFIG_MPROFILE_KERNEL 18 18 #define MODULE_ARCH_VERMAGIC_FTRACE "mprofile-kernel " 19 19 #else 20 20 #define MODULE_ARCH_VERMAGIC_FTRACE ""
+2 -2
arch/powerpc/kernel/module_64.c
··· 466 466 return (unsigned long)&stubs[i]; 467 467 } 468 468 469 - #ifdef CC_USING_MPROFILE_KERNEL 469 + #ifdef CONFIG_MPROFILE_KERNEL 470 470 static bool is_mprofile_mcount_callsite(const char *name, u32 *instruction) 471 471 { 472 472 if (strcmp("_mcount", name)) ··· 753 753 754 754 #ifdef CONFIG_DYNAMIC_FTRACE 755 755 756 - #ifdef CC_USING_MPROFILE_KERNEL 756 + #ifdef CONFIG_MPROFILE_KERNEL 757 757 758 758 #define PACATOC offsetof(struct paca_struct, kernel_toc) 759 759
+3 -3
arch/powerpc/kernel/trace/ftrace.c
··· 144 144 return -EINVAL; 145 145 } 146 146 147 - #ifdef CC_USING_MPROFILE_KERNEL 147 + #ifdef CONFIG_MPROFILE_KERNEL 148 148 /* When using -mkernel_profile there is no load to jump over */ 149 149 pop = PPC_INST_NOP; 150 150 ··· 188 188 pr_err("Expected %08x found %08x\n", PPC_INST_LD_TOC, op); 189 189 return -EINVAL; 190 190 } 191 - #endif /* CC_USING_MPROFILE_KERNEL */ 191 + #endif /* CONFIG_MPROFILE_KERNEL */ 192 192 193 193 if (patch_instruction((unsigned int *)ip, pop)) { 194 194 pr_err("Patching NOP failed.\n"); ··· 324 324 * They should effectively be a NOP, and follow formal constraints, 325 325 * depending on the ABI. Return false if they don't. 326 326 */ 327 - #ifndef CC_USING_MPROFILE_KERNEL 327 + #ifndef CONFIG_MPROFILE_KERNEL 328 328 static int 329 329 expected_nop_sequence(void *ip, unsigned int op0, unsigned int op1) 330 330 {
-1
arch/powerpc/tools/gcc-check-mprofile-kernel.sh
··· 24 24 2> /dev/null | grep -q "_mcount" && \ 25 25 exit 1 26 26 27 - echo "OK" 28 27 exit 0
+2 -2
arch/sh/include/asm/vmlinux.lds.h
··· 7 7 #ifdef CONFIG_DWARF_UNWINDER 8 8 #define DWARF_EH_FRAME \ 9 9 .eh_frame : AT(ADDR(.eh_frame) - LOAD_OFFSET) { \ 10 - VMLINUX_SYMBOL(__start_eh_frame) = .; \ 10 + __start_eh_frame = .; \ 11 11 *(.eh_frame) \ 12 - VMLINUX_SYMBOL(__stop_eh_frame) = .; \ 12 + __stop_eh_frame = .; \ 13 13 } 14 14 #else 15 15 #define DWARF_EH_FRAME
+10 -1
arch/x86/Kconfig
··· 130 130 select HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD if X86_64 131 131 select HAVE_ARCH_VMAP_STACK if X86_64 132 132 select HAVE_ARCH_WITHIN_STACK_FRAMES 133 - select HAVE_CC_STACKPROTECTOR 133 + select HAVE_CC_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR 134 134 select HAVE_CMPXCHG_DOUBLE 135 135 select HAVE_CMPXCHG_LOCAL 136 136 select HAVE_CONTEXT_TRACKING if X86_64 ··· 346 346 default 2 347 347 348 348 source "init/Kconfig" 349 + 350 + config CC_HAS_SANE_STACKPROTECTOR 351 + bool 352 + default $(success,$(srctree)/scripts/gcc-x86_64-has-stack-protector.sh $(CC)) if 64BIT 353 + default $(success,$(srctree)/scripts/gcc-x86_32-has-stack-protector.sh $(CC)) 354 + help 355 + We have to make sure stack protector is unconditionally disabled if 356 + the compiler produces broken code. 357 + 349 358 source "kernel/Kconfig.freezer" 350 359 351 360 menu "Processor type and features"
+6 -6
include/linux/linkage.h
··· 24 24 25 25 #ifndef cond_syscall 26 26 #define cond_syscall(x) asm( \ 27 - ".weak " VMLINUX_SYMBOL_STR(x) "\n\t" \ 28 - ".set " VMLINUX_SYMBOL_STR(x) "," \ 29 - VMLINUX_SYMBOL_STR(sys_ni_syscall)) 27 + ".weak " __stringify(x) "\n\t" \ 28 + ".set " __stringify(x) "," \ 29 + __stringify(sys_ni_syscall)) 30 30 #endif 31 31 32 32 #ifndef SYSCALL_ALIAS 33 33 #define SYSCALL_ALIAS(alias, name) asm( \ 34 - ".globl " VMLINUX_SYMBOL_STR(alias) "\n\t" \ 35 - ".set " VMLINUX_SYMBOL_STR(alias) "," \ 36 - VMLINUX_SYMBOL_STR(name)) 34 + ".globl " __stringify(alias) "\n\t" \ 35 + ".set " __stringify(alias) "," \ 36 + __stringify(name)) 37 37 #endif 38 38 39 39 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
+15
init/Kconfig
··· 8 8 default ARCH_DEFCONFIG 9 9 default "arch/$(ARCH)/defconfig" 10 10 11 + config CC_IS_GCC 12 + def_bool $(success,$(CC) --version | head -n 1 | grep -q gcc) 13 + 14 + config GCC_VERSION 15 + int 16 + default $(shell,$(srctree)/scripts/gcc-version.sh -p $(CC) | sed 's/^0*//') if CC_IS_GCC 17 + default 0 18 + 19 + config CC_IS_CLANG 20 + def_bool $(success,$(CC) --version | head -n 1 | grep -q clang) 21 + 22 + config CLANG_VERSION 23 + int 24 + default $(shell,$(srctree)/scripts/clang-version.sh $(CC)) 25 + 11 26 config CONSTRUCTORS 12 27 bool 13 28 depends on !UML
+5 -12
kernel/gcov/Kconfig
··· 53 53 choice 54 54 prompt "Specify GCOV format" 55 55 depends on GCOV_KERNEL 56 - default GCOV_FORMAT_AUTODETECT 57 56 ---help--- 58 - The gcov format is usually determined by the GCC version, but there are 57 + The gcov format is usually determined by the GCC version, and the 58 + default is chosen according to your GCC version. However, there are 59 59 exceptions where format changes are integrated in lower-version GCCs. 60 - In such a case use this option to adjust the format used in the kernel 61 - accordingly. 62 - 63 - If unsure, choose "Autodetect". 64 - 65 - config GCOV_FORMAT_AUTODETECT 66 - bool "Autodetect" 67 - ---help--- 68 - Select this option to use the format that corresponds to your GCC 69 - version. 60 + In such a case, change this option to adjust the format used in the 61 + kernel accordingly. 70 62 71 63 config GCOV_FORMAT_3_4 72 64 bool "GCC 3.4 format" 65 + depends on CC_IS_GCC && GCC_VERSION < 40700 73 66 ---help--- 74 67 Select this option to use the format defined by GCC 3.4. 75 68
-2
kernel/gcov/Makefile
··· 4 4 obj-y := base.o fs.o 5 5 obj-$(CONFIG_GCOV_FORMAT_3_4) += gcc_3_4.o 6 6 obj-$(CONFIG_GCOV_FORMAT_4_7) += gcc_4_7.o 7 - obj-$(CONFIG_GCOV_FORMAT_AUTODETECT) += $(call cc-ifversion, -lt, 0407, \ 8 - gcc_3_4.o, gcc_4_7.o)
+7 -4
lib/Kconfig.debug
··· 736 736 only for x86_64. KCOV requires testing on other archs, and most likely 737 737 disabling of instrumentation for some early boot code. 738 738 739 + config CC_HAS_SANCOV_TRACE_PC 740 + def_bool $(cc-option,-fsanitize-coverage=trace-pc) 741 + 739 742 config KCOV 740 743 bool "Code coverage for fuzzing" 741 744 depends on ARCH_HAS_KCOV 745 + depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS 742 746 select DEBUG_FS 743 - select GCC_PLUGINS if !COMPILE_TEST 744 - select GCC_PLUGIN_SANCOV if !COMPILE_TEST 747 + select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC 745 748 help 746 749 KCOV exposes kernel code coverage information in a form suitable 747 750 for coverage-guided fuzzing (randomized testing). ··· 758 755 config KCOV_ENABLE_COMPARISONS 759 756 bool "Enable comparison operands collection by KCOV" 760 757 depends on KCOV 761 - default n 758 + depends on $(cc-option,-fsanitize-coverage=trace-cmp) 762 759 help 763 760 KCOV also exposes operands of every comparison in the instrumented 764 761 code along with operand sizes and PCs of the comparison instructions. ··· 768 765 config KCOV_INSTRUMENT_ALL 769 766 bool "Instrument all code by default" 770 767 depends on KCOV 771 - default y if KCOV 768 + default y 772 769 help 773 770 If you are doing generic system call fuzzing (like e.g. syzkaller), 774 771 then you will want to instrument the whole kernel and you should
+3
scripts/Kconfig.include
··· 25 25 # $(ld-option,<flag>) 26 26 # Return y if the linker supports <flag>, n otherwise 27 27 ld-option = $(success,$(LD) -v $(1)) 28 + 29 + # gcc version including patch level 30 + gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh -p $(CC) | sed 's/^0*//')
+26 -73
scripts/Makefile.gcc-plugins
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - ifdef CONFIG_GCC_PLUGINS 3 - __PLUGINCC := $(call cc-ifversion, -ge, 0408, $(HOSTCXX), $(HOSTCC)) 4 - PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)") 2 + gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so 5 3 6 - SANCOV_PLUGIN := -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so 7 - 8 - gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so 9 - 10 - gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so 11 - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += -DLATENT_ENTROPY_PLUGIN 12 - ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY 4 + gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so 5 + gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += -DLATENT_ENTROPY_PLUGIN 6 + ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY 13 7 DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable 14 - endif 15 - 16 - ifdef CONFIG_GCC_PLUGIN_SANCOV 17 - ifeq ($(strip $(CFLAGS_KCOV)),) 18 - # It is needed because of the gcc-plugin.sh and gcc version checks. 19 - gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so 20 - 21 - ifneq ($(PLUGINCC),) 22 - CFLAGS_KCOV := $(SANCOV_PLUGIN) 23 - else 24 - $(warning warning: cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler) 25 - endif 26 - endif 27 - endif 28 - 29 - gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += structleak_plugin.so 30 - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE) += -fplugin-arg-structleak_plugin-verbose 31 - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL) += -fplugin-arg-structleak_plugin-byref-all 32 - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += -DSTRUCTLEAK_PLUGIN 33 - 34 - gcc-plugin-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += randomize_layout_plugin.so 35 - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += -DRANDSTRUCT_PLUGIN 36 - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) += -fplugin-arg-randomize_layout_plugin-performance-mode 37 - 38 - GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) 39 - 40 - export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR 41 - export SANCOV_PLUGIN DISABLE_LATENT_ENTROPY_PLUGIN 42 - 43 - ifneq ($(PLUGINCC),) 44 - # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication. 45 - GCC_PLUGINS_CFLAGS := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGINS_CFLAGS)) 46 - endif 47 - 48 - KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) 49 - GCC_PLUGIN := $(gcc-plugin-y) 50 - GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y) 51 8 endif 52 9 53 - # If plugins aren't supported, abort the build before hard-to-read compiler 54 - # errors start getting spewed by the main build. 55 - PHONY += gcc-plugins-check 56 - gcc-plugins-check: FORCE 57 - ifdef CONFIG_GCC_PLUGINS 58 - ifeq ($(PLUGINCC),) 59 - ifneq ($(GCC_PLUGINS_CFLAGS),) 60 - # Various gccs between 4.5 and 5.1 have bugs on powerpc due to missing 61 - # header files. gcc <= 4.6 doesn't work at all, gccs from 4.8 to 5.1 have 62 - # issues with 64-bit targets. 63 - ifeq ($(ARCH),powerpc) 64 - ifeq ($(call cc-ifversion, -le, 0501, y), y) 65 - @echo "Cannot use CONFIG_GCC_PLUGINS: plugin support on gcc <= 5.1 is buggy on powerpc, please upgrade to gcc 5.2 or newer" >&2 && exit 1 66 - endif 67 - endif 68 - ifeq ($(call cc-ifversion, -ge, 0405, y), y) 69 - $(Q)$(srctree)/scripts/gcc-plugin.sh --show-error "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)" || true 70 - @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc installation does not support plugins, perhaps the necessary headers are missing?" >&2 && exit 1 71 - else 72 - @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc version does not support plugins, you should upgrade it to at least gcc 4.5" >&2 && exit 1 73 - endif 74 - endif 75 - endif 76 - endif 77 - @: 10 + gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so 11 + gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += structleak_plugin.so 12 + gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE) += -fplugin-arg-structleak_plugin-verbose 13 + gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL) += -fplugin-arg-structleak_plugin-byref-all 14 + gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += -DSTRUCTLEAK_PLUGIN 15 + 16 + gcc-plugin-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += randomize_layout_plugin.so 17 + gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += -DRANDSTRUCT_PLUGIN 18 + gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) += -fplugin-arg-randomize_layout_plugin-performance-mode 19 + 20 + GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) 21 + 22 + export GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR 23 + export DISABLE_LATENT_ENTROPY_PLUGIN 24 + 25 + # sancov_plugin.so can be only in CFLAGS_KCOV because avoid duplication. 26 + GCC_PLUGINS_CFLAGS := $(filter-out %/sancov_plugin.so, $(GCC_PLUGINS_CFLAGS)) 27 + 28 + KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) 29 + GCC_PLUGIN := $(gcc-plugin-y) 30 + GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y) 78 31 79 32 # Actually do the build, if requested. 80 33 PHONY += gcc-plugins 81 - gcc-plugins: scripts_basic gcc-plugins-check 34 + gcc-plugins: scripts_basic 82 35 ifdef CONFIG_GCC_PLUGINS 83 36 $(Q)$(MAKE) $(build)=scripts/gcc-plugins 84 37 endif
+6 -4
scripts/Makefile.kcov
··· 1 1 ifdef CONFIG_KCOV 2 - CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,) 3 - ifeq ($(CONFIG_KCOV_ENABLE_COMPARISONS),y) 4 - CFLAGS_KCOV += $(call cc-option,-fsanitize-coverage=trace-cmp,) 5 - endif 2 + 3 + kcov-flags-$(CONFIG_CC_HAS_SANCOV_TRACE_PC) += -fsanitize-coverage=trace-pc 4 + kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) += -fsanitize-coverage=trace-cmp 5 + kcov-flags-$(CONFIG_GCC_PLUGIN_SANCOV) += -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so 6 + 7 + export CFLAGS_KCOV := $(kcov-flags-y) 6 8 7 9 endif
+4 -14
scripts/clang-version.sh
··· 10 10 # clang-5.0.1 etc. 11 11 # 12 12 13 - if [ "$1" = "-p" ] ; then 14 - with_patchlevel=1; 15 - shift; 16 - fi 17 - 18 13 compiler="$*" 19 14 20 - if [ ${#compiler} -eq 0 ]; then 21 - echo "Error: No compiler specified." 22 - printf "Usage:\n\t$0 <clang-command>\n" 15 + if !( $compiler --version | grep -q clang) ; then 16 + echo 0 23 17 exit 1 24 18 fi 25 19 26 20 MAJOR=$(echo __clang_major__ | $compiler -E -x c - | tail -n 1) 27 21 MINOR=$(echo __clang_minor__ | $compiler -E -x c - | tail -n 1) 28 - if [ "x$with_patchlevel" != "x" ] ; then 29 - PATCHLEVEL=$(echo __clang_patchlevel__ | $compiler -E -x c - | tail -n 1) 30 - printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL 31 - else 32 - printf "%02d%02d\\n" $MAJOR $MINOR 33 - fi 22 + PATCHLEVEL=$(echo __clang_patchlevel__ | $compiler -E -x c - | tail -n 1) 23 + printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL
+1 -4
scripts/gcc-plugins/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 + PLUGINCC := $(CONFIG_PLUGIN_HOSTCC:"%"=%) 2 3 GCC_PLUGINS_DIR := $(shell $(CC) -print-file-name=plugin) 3 4 4 5 ifeq ($(PLUGINCC),$(HOSTCC)) ··· 12 11 HOST_EXTRACXXFLAGS += -fno-exceptions -fasynchronous-unwind-tables -ggdb 13 12 HOST_EXTRACXXFLAGS += -Wno-narrowing -Wno-unused-variable 14 13 export HOST_EXTRACXXFLAGS 15 - endif 16 - 17 - ifneq ($(CFLAGS_KCOV), $(SANCOV_PLUGIN)) 18 - GCC_PLUGIN := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGIN)) 19 14 endif 20 15 21 16 export HOSTLIBS
+1 -6
scripts/gcc-x86_32-has-stack-protector.sh
··· 1 1 #!/bin/sh 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 - echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -O0 -fstack-protector - -o - 2> /dev/null | grep -q "%gs" 5 - if [ "$?" -eq "0" ] ; then 6 - echo y 7 - else 8 - echo n 9 - fi 4 + echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -m32 -O0 -fstack-protector - -o - 2> /dev/null | grep -q "%gs"
-5
scripts/gcc-x86_64-has-stack-protector.sh
··· 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 4 echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -O0 -mcmodel=kernel -fno-PIE -fstack-protector - -o - 2> /dev/null | grep -q "%gs" 5 - if [ "$?" -eq "0" ] ; then 6 - echo y 7 - else 8 - echo n 9 - fi
+2 -2
scripts/kconfig/streamline_config.pl
··· 165 165 my $last_source = ""; 166 166 167 167 # Check for any environment variables used 168 - while ($source =~ /\$(\w+)/ && $last_source ne $source) { 168 + while ($source =~ /\$\((\w+)\)/ && $last_source ne $source) { 169 169 my $env = $1; 170 170 $last_source = $source; 171 - $source =~ s/\$$env/$ENV{$env}/; 171 + $source =~ s/\$\($env\)/$ENV{$env}/; 172 172 } 173 173 174 174 open(my $kinfile, '<', $source) || die "Can't open $kconfig";