History

stackprotector: update make rules

Impact: no default -fno-stack-protector if stackp is enabled, cleanup Stackprotector make rules had the following problems. * cc support test and warning are scattered across makefile and kernel/panic.c. * -fno-stack-protector was always added regardless of configuration. Update such that cc support test and warning are contained in makefile and -fno-stack-protector is added iff stackp is turned off. While at it, prepare for 32bit support.

Tejun Heo committed 17 years ago

Commit 5d707e91 parent 76397f74 files · +15 −13Browse files

Unified · Split

4 files
  1. Makefile +2 −1
  2. arch/x86/Makefile +10 −7
  3. kernel/panic.c +0 −4
  4. scripts/gcc-x86_64-has-stack-protector.sh +3 −1
Makefile+2−1
@@ -532,8 +532,9 @@ KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN}) · 531 unmodified lines
532532 endif
533533
534534 # Force gcc to behave correct even for buggy distributions
535−# Arch Makefiles may override this setting
535+ifndef CONFIG_CC_STACKPROTECTOR
536536 KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector)
537+endif
537538
538539 ifdef CONFIG_FRAME_POINTER
539540 KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
arch/x86/Makefile+10−7
@@ -70,14 +70,17 @@ else · 69 unmodified lines
7070 # this works around some issues with generating unwind tables in older gccs
7171 # newer gccs do it by default
7272 KBUILD_CFLAGS += -maccumulate-outgoing-args
73+endif
7374
74− stackp := $(CONFIG_SHELL) $(srctree)/scripts/gcc-x86_64-has-stack-protector.sh
75− stackp-$(CONFIG_CC_STACKPROTECTOR) := $(shell $(stackp) \
76− "$(CC)" "-fstack-protector -DGCC_HAS_SP" )
77− stackp-$(CONFIG_CC_STACKPROTECTOR_ALL) += $(shell $(stackp) \
78− "$(CC)" -fstack-protector-all )
79−
80− KBUILD_CFLAGS += $(stackp-y)
75+ifdef CONFIG_CC_STACKPROTECTOR
76+ cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
77+ ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC)),y)
78+ stackp-y := -fstack-protector
79+ stackp-$(CONFIG_CC_STACKPROTECTOR_ALL) += -fstack-protector-all
80+ KBUILD_CFLAGS += $(stackp-y)
81+ else
82+ $(warning stack protector enabled but no compiler support)
83+ endif
8184 endif
8285
8386 # Stackpointer is addressed different for 32 bit and 64 bit x86
kernel/panic.c+0−4
@@ -359,10 +359,6 @@ EXPORT_SYMBOL(warn_slowpath); · 358 unmodified lines
359359
360360 #ifdef CONFIG_CC_STACKPROTECTOR
361361
362−#ifndef GCC_HAS_SP
363−#warning You have selected the CONFIG_CC_STACKPROTECTOR option, but the gcc used does not support this.
364−#endif
365−
366362 /*
367363 * Called when gcc's -fstack-protector feature is used, and
368364 * gcc detects corruption of the on-stack canary value
scripts/gcc-x86_64-has-stack-protector.sh+3−1
@@ -2,5 +2,7 @@ · 1 unmodified line
22
33 echo "int foo(void) { char X[200]; return 3; }" | $1 -S -xc -c -O0 -mcmodel=kernel -fstack-protector - -o - 2> /dev/null | grep -q "%gs"
44 if [ "$?" -eq "0" ] ; then
5− echo $2
5+ echo y
6+else
7+ echo n
68 fi

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t