@@ -442,8 +442,6 @@ export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
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.
@@ -514,6 +512,12 @@ ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/cc-can-link.sh $(CC)), y)
514
512
export CC_CAN_LINK
515
513
endif
516
514
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
+
517
521
ifeq ($(config-targets ) ,1)
518
522
# ===========================================================================
519
523
# *config targets only - make sure prerequisites are updated, and descend
@@ -523,7 +527,7 @@ ifeq ($(config-targets),1)
523
527
# KBUILD_DEFCONFIG may point out an alternative default configuration
524
528
# used for 'make defconfig'
525
529
include arch/$(SRCARCH ) /Makefile
526
- export KBUILD_DEFCONFIG KBUILD_KCONFIG
530
+ export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
527
531
528
532
config : scripts_basic outputmakefile FORCE
529
533
$(Q )$(MAKE ) $(build ) =scripts/kconfig $@
@@ -585,12 +589,32 @@ virt-y := virt/
585
589
endif # KBUILD_EXTMOD
586
590
587
591
ifeq ($(dot-config ) ,1)
588
- # Read in config
589
592
-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
590
605
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)
591
614
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.
594
618
-include include/config/auto.conf.cmd
595
619
596
620
# To avoid any implicit rule to kick in, define an empty command
@@ -622,24 +646,6 @@ else
622
646
include/config/auto.conf : ;
623
647
endif # $(dot-config)
624
648
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
-
643
649
KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,)
644
650
KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
645
651
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
@@ -680,55 +686,11 @@ ifneq ($(CONFIG_FRAME_WARN),0)
680
686
KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
681
687
endif
682
688
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 )
732
694
733
695
ifeq ($(cc-name ) ,clang)
734
696
KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
@@ -1112,7 +1074,7 @@ endif
1112
1074
# prepare2 creates a makefile if using a separate output directory.
1113
1075
# From this point forward, .config has been reprocessed, so any rules
1114
1076
# 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
1116
1078
1117
1079
prepare1 : prepare2 $(version_h ) $(autoksyms_h ) include/generated/utsrelease.h \
1118
1080
include /config/auto.conf
@@ -1138,43 +1100,6 @@ uapi-asm-generic:
1138
1100
PHONY += prepare-objtool
1139
1101
prepare-objtool : $(objtool_target )
1140
1102
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
-
1178
1103
# Generate some files
1179
1104
# ---------------------------------------------------------------------------
1180
1105
0 commit comments