Yay! You have no idea how happy I am to push this patch up. No more -fno-stack-protector hacks (at least for v3).
Jordan
[PATCH][v3] Add automatic detection for -fno-stack-protector
This borrows the cc-option call from the kernel to check if -fno-stack-protector is supported by the compiler, and if it is, then enable it.
Signed-off-by: Jordan Crouse jordan.crouse@amd.com
Index: LinuxBIOSv3/Makefile =================================================================== --- LinuxBIOSv3.orig/Makefile 2007-07-02 17:21:19.000000000 -0600 +++ LinuxBIOSv3/Makefile 2007-07-02 17:26:32.000000000 -0600 @@ -32,6 +32,19 @@ obj := $(shell pwd)/build export src obj
+# These functions are called by the kernel - we use these below +# to check for -fno-stack-protector + +try-run= $(shell set -e; \ + TMP=".$$$$.tmp"; \ + if ($(1)) > /dev/null 2>&1; \ + then echo "$(2)"; \ + else echo "$(3)"; \ + fi; rm -rf "$$TMP") + +cc-option=$(call try-run,\ + $(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2)) + # Do not print "Entering directory ...". MAKEFLAGS += --no-print-directory
@@ -42,6 +55,11 @@ -mpreferred-stack-boundary=2 -mregparm=3 -pipe # FIXME: Does stack boundary or regparm break the code on real hardware?
+# Add in automagic detection for -fno-stack-protector +# This is borrowed from the kernel 2.6 scripts + +CFLAGS += $(call cc-option, -fno-stack-protector,) + HOSTCC := gcc HOSTCXX := g++ HOSTCFLAGS := -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
On 02/07/07 17:38 -0600, Jordan Crouse wrote:
Yay! You have no idea how happy I am to push this patch up. No more -fno-stack-protector hacks (at least for v3).
Jordan
Hmm - whoever checks this in, please change "called by the kernel" to "from the kernel" in the first blob. The way it reads now is stupid. :)
Jordan
* Jordan Crouse jordan.crouse@amd.com [070703 01:38]:
Yay! You have no idea how happy I am to push this patch up. No more -fno-stack-protector hacks (at least for v3).
Jordan
Hi Jordan,
is there some way we can include this in util/xcompile/xcompile instead?
That script was meant to be an abstraction for stuff like this at some point.
Comments/flames/ideas of course welcome!
[PATCH][v3] Add automatic detection for -fno-stack-protector
This borrows the cc-option call from the kernel to check if -fno-stack-protector is supported by the compiler, and if it is, then enable it.
Signed-off-by: Jordan Crouse jordan.crouse@amd.com
Index: LinuxBIOSv3/Makefile
--- LinuxBIOSv3.orig/Makefile 2007-07-02 17:21:19.000000000 -0600 +++ LinuxBIOSv3/Makefile 2007-07-02 17:26:32.000000000 -0600 @@ -32,6 +32,19 @@ obj := $(shell pwd)/build export src obj
+# These functions are called by the kernel - we use these below +# to check for -fno-stack-protector
+try-run= $(shell set -e; \
- TMP=".$$$$.tmp"; \
- if ($(1)) > /dev/null 2>&1; \
- then echo "$(2)"; \
- else echo "$(3)"; \
- fi; rm -rf "$$TMP")
+cc-option=$(call try-run,\
- $(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2))
# Do not print "Entering directory ...". MAKEFLAGS += --no-print-directory
@@ -42,6 +55,11 @@ -mpreferred-stack-boundary=2 -mregparm=3 -pipe # FIXME: Does stack boundary or regparm break the code on real hardware?
+# Add in automagic detection for -fno-stack-protector +# This is borrowed from the kernel 2.6 scripts
+CFLAGS += $(call cc-option, -fno-stack-protector,)
HOSTCC := gcc HOSTCXX := g++ HOSTCFLAGS := -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
-- linuxbios mailing list linuxbios@linuxbios.org http://www.linuxbios.org/mailman/listinfo/linuxbios
On Tue, Jul 03, 2007 at 05:01:43AM +0200, Stefan Reinauer wrote:
is there some way we can include this in util/xcompile/xcompile instead?
That script was meant to be an abstraction for stuff like this at some point.
Ack, would be better in xcompile. Could somebody please test this on non-Linux platforms, too? E.g. Solaris, FreeBSD, OpenBSD etc. etc.
Uwe.
On 04/07/07 00:06 +0200, Uwe Hermann wrote:
On Tue, Jul 03, 2007 at 05:01:43AM +0200, Stefan Reinauer wrote:
is there some way we can include this in util/xcompile/xcompile instead?
That script was meant to be an abstraction for stuff like this at some point.
Ack, would be better in xcompile. Could somebody please test this on non-Linux platforms, too? E.g. Solaris, FreeBSD, OpenBSD etc. etc.
Alright - xcompile it is. i'll do the patch.
Uwe.
http://www.hermann-uwe.de | http://www.holsham-traders.de http://www.crazy-hacks.org | http://www.unmaintained-free-software.org
-- linuxbios mailing list linuxbios@linuxbios.org http://www.linuxbios.org/mailman/listinfo/linuxbios
On 04/07/07 00:06 +0200, Uwe Hermann wrote:
On Tue, Jul 03, 2007 at 05:01:43AM +0200, Stefan Reinauer wrote:
is there some way we can include this in util/xcompile/xcompile instead?
That script was meant to be an abstraction for stuff like this at some point.
Ack, would be better in xcompile. Could somebody please test this on non-Linux platforms, too? E.g. Solaris, FreeBSD, OpenBSD etc. etc.
Okay then - here goes. Please test extensively.....
Jordan
[PATCH][v3] Add testcc() function to xcompile to check for -fno-stack-protector
enable xcompile to check for various compiler flags and set them in the CFLAGS variable if they are located.
Signed-off-by: Jordan Crouse jordan.crouse@amd.com
Index: LinuxBIOSv3/Makefile =================================================================== --- LinuxBIOSv3.orig/Makefile 2007-07-03 16:29:49.000000000 -0600 +++ LinuxBIOSv3/Makefile 2007-07-03 16:32:01.000000000 -0600 @@ -96,6 +96,7 @@ AS := $(AS_$(ARCH)) LD := $(LD_$(ARCH)) OBJCOPY := $(OBJCOPY_$(ARCH)) +CFLAGS += $(CFLAGS_$(ARCH))
CPPFLAGS := $(LINUXBIOSINCLUDE) CFLAGS += $(LINUXBIOSINCLUDE) Index: LinuxBIOSv3/util/xcompile/xcompile =================================================================== --- LinuxBIOSv3.orig/util/xcompile/xcompile 2007-07-03 16:32:16.000000000 -0600 +++ LinuxBIOSv3/util/xcompile/xcompile 2007-07-03 16:32:20.000000000 -0600 @@ -25,6 +25,15 @@ -e s/s390x/s390/ -e s/parisc64/parisc/ \ -e s/ppc.*/powerpc/ -e s/mips.*/mips/`
+testcc() +{ + TMP=".$$$$.tmp" + $1 $2 -S -xc /dev/null -o $TMP > /dev/null 2>&1 + ret=$? + rm -rf $TMP + return $ret +} + searchgnu() { # $1 short name @@ -45,18 +54,23 @@ case "$ARCH" in "x86_64") echo "CC_x86 := gcc -m32" + CC="gcc -m32" + searchgnu as >/dev/null && echo "AS_x86 := $(searchgnu as) --32" searchgnu ld >/dev/null && echo "LD_x86 := $(searchgnu ld) -b elf32-i386 -melf_i386" searchgnu objcopy >/dev/null && echo "OBJCOPY_x86 := $(searchgnu objcopy)" ;; "x86") echo "CC_x86 := gcc" + CC="gcc" + searchgnu as >/dev/null && echo "AS_x86 := $(searchgnu as)" searchgnu ld >/dev/null && echo "LD_x86 := $(searchgnu ld)" searchgnu objcopy >/dev/null && echo "OBJCOPY_x86 := $(searchgnu objcopy)" ;; *) # FIXME: This should be detected. + CC="i386-linux-gcc" echo "CC_x86 := i386-linux-gcc" echo "AS_x86 := i386-linux-as" echo "LD_x86 := i386-linux-ld" @@ -64,6 +78,13 @@ ;; esac
+# This is where we test for various flags and other things + +CFLAGS="" +testcc "$CC" "-fno-stack-protector" && CFLAGS="$CFLAGS-fno-stack-protector " + +echo "CFLAGS_x86 := $CFLAGS" + # TODO: The same as above for PowerPC, and other architectures # as soon as they are supported by LinuxBIOSv3.
On Tue, Jul 03, 2007 at 04:36:03PM -0600, Jordan Crouse wrote:
[PATCH][v3] Add testcc() function to xcompile to check for -fno-stack-protector
enable xcompile to check for various compiler flags and set them in the CFLAGS variable if they are located.
Signed-off-by: Jordan Crouse jordan.crouse@amd.com
Looks good, and works for me (but I cannot test the case where -fno-stack-protector is actually needed, my setup doesn't require it).
Acked-by: Uwe Hermann uwe@hermann-uwe.de
Uwe.
Uwe Hermann wrote:
On Tue, Jul 03, 2007 at 04:36:03PM -0600, Jordan Crouse wrote:
[PATCH][v3] Add testcc() function to xcompile to check for -fno-stack-protector
enable xcompile to check for various compiler flags and set them in the CFLAGS variable if they are located.
Signed-off-by: Jordan Crouse jordan.crouse@amd.com
Looks good, and works for me (but I cannot test the case where -fno-stack-protector is actually needed, my setup doesn't require it).
Acked-by: Uwe Hermann uwe@hermann-uwe.de
Uwe.
Acked-by: Marc Jones marc.jones@amd.com
r434
Thanks, Marc