| @@ -680,6 +680,10 @@ endif · 679 unmodified lines |
| 680 | 680 | # This selects the stack protector compiler flag. Testing it is delayed |
| 681 | 681 | # until after .config has been reprocessed, in the prepare-compiler-check |
| 682 | 682 | # target. |
| 683 | +ifdef CONFIG_CC_STACKPROTECTOR_AUTO |
| 684 | + stackp-flag := $(call cc-option,-fstack-protector-strong,$(call cc-option,-fstack-protector)) |
| 685 | + stackp-name := AUTO |
| 686 | +else |
| 683 | 687 | ifdef CONFIG_CC_STACKPROTECTOR_REGULAR |
| 684 | 688 | stackp-flag := -fstack-protector |
| 685 | 689 | stackp-name := REGULAR |
| @@ -688,12 +692,18 @@ ifdef CONFIG_CC_STACKPROTECTOR_STRONG · 2 unmodified lines |
| 688 | 692 | stackp-flag := -fstack-protector-strong |
| 689 | 693 | stackp-name := STRONG |
| 690 | 694 | else |
| 695 | + # If either there is no stack protector for this architecture or |
| 696 | + # CONFIG_CC_STACKPROTECTOR_NONE is selected, we're done, and $(stackp-name) |
| 697 | + # is empty, skipping all remaining stack protector tests. |
| 698 | + # |
| 691 | 699 | # Force off for distro compilers that enable stack protector by default. |
| 692 | | − stackp-flag := $(call cc-option, -fno-stack-protector) |
| 700 | + KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector) |
| 701 | +endif |
| 693 | 702 | endif |
| 694 | 703 | endif |
| 695 | 704 | # Find arch-specific stack protector compiler sanity-checking script. |
| 696 | 705 | ifdef stackp-name |
| 706 | +ifneq ($(stackp-flag),) |
| 697 | 707 | stackp-path := $(srctree)/scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh |
| 698 | 708 | stackp-check := $(wildcard $(stackp-path)) |
| 699 | 709 | # If the wildcard test matches a test script, run it to check functionality. |
| @@ -705,9 +715,17 @@ ifdef stackp-name · 5 unmodified lines |
| 705 | 715 | ifndef stackp-broken |
| 706 | 716 | # If the stack protector is functional, enable code that depends on it. |
| 707 | 717 | KBUILD_CPPFLAGS += -DCONFIG_CC_STACKPROTECTOR |
| 718 | + # Either we've already detected the flag (for AUTO) or we'll fail the |
| 719 | + # build in the prepare-compiler-check rule (for specific flag). |
| 720 | + KBUILD_CFLAGS += $(stackp-flag) |
| 721 | + else |
| 722 | + # We have to make sure stack protector is unconditionally disabled if |
| 723 | + # the compiler is broken (in case we're going to continue the build in |
| 724 | + # AUTO mode). |
| 725 | + KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector) |
| 708 | 726 | endif |
| 709 | 727 | endif |
| 710 | | −KBUILD_CFLAGS += $(stackp-flag) |
| 728 | +endif |
| 711 | 729 | |
| 712 | 730 | ifeq ($(cc-name),clang) |
| 713 | 731 | KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) |
| @@ -1102,15 +1120,28 @@ PHONY += prepare-compiler-check · 388 unmodified lines |
| 1102 | 1120 | prepare-compiler-check: FORCE |
| 1103 | 1121 | # Make sure compiler supports requested stack protector flag. |
| 1104 | 1122 | ifdef stackp-name |
| 1123 | + # Warn about CONFIG_CC_STACKPROTECTOR_AUTO having found no option. |
| 1124 | + ifeq ($(stackp-flag),) |
| 1125 | + @echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ |
| 1126 | + Compiler does not support any known stack-protector >&2 |
| 1127 | + else |
| 1128 | + # Fail if specifically requested stack protector is missing. |
| 1105 | 1129 | ifeq ($(call cc-option, $(stackp-flag)),) |
| 1106 | 1130 | @echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ |
| 1107 | 1131 | $(stackp-flag) not supported by compiler >&2 && exit 1 |
| 1108 | 1132 | endif |
| 1133 | + endif |
| 1109 | 1134 | endif |
| 1110 | | −# Make sure compiler does not have buggy stack-protector support. |
| 1135 | +# Make sure compiler does not have buggy stack-protector support. If a |
| 1136 | +# specific stack-protector was requested, fail the build, otherwise warn. |
| 1111 | 1137 | ifdef stackp-broken |
| 1138 | + ifeq ($(stackp-name),AUTO) |
| 1139 | + @echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ |
| 1140 | + $(stackp-flag) available but compiler is broken: disabling >&2 |
| 1141 | + else |
| 1112 | 1142 | @echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ |
| 1113 | 1143 | $(stackp-flag) available but compiler is broken >&2 && exit 1 |
| 1144 | + endif |
| 1114 | 1145 | endif |
| 1115 | 1146 | @: |
| 1116 | 1147 | |