Expand gcc tests.
authorKevin O'Connor <kevin@koconnor.net>
Fri, 27 Mar 2009 00:45:36 +0000 (20:45 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Fri, 27 Mar 2009 00:45:36 +0000 (20:45 -0400)
Verify -fwhole-program works at make startup.
Warn when gcc marks global functions as local.

Makefile
tools/test-combine.sh [deleted file]
tools/test-gcc.sh [new file with mode: 0755]

index 34a7535432b3477362c1977fbf5519d18b3b651f..7d7dbebe5fb91dd0de49b7942acf68c4fe4ea9a3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
 
 # Default compiler flags
 COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \
-               -mpreferred-stack-boundary=2 -mrtd \
+               -mpreferred-stack-boundary=2 -mrtd -freg-struct-return \
                -ffreestanding -fwhole-program -fomit-frame-pointer \
                -fno-delete-null-pointer-checks -Wno-strict-aliasing
 COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
@@ -54,8 +54,13 @@ vpath %.S src
 
 ################ Build rules
 
+TESTGCC:=$(shell CC=$(CC) tools/test-gcc.sh)
+ifeq "$(TESTGCC)" "-1"
+$(error "Please upgrade GCC")
+endif
+
 ifndef AVOIDCOMBINE
-AVOIDCOMBINE=$(shell CC=$(CC) tools/test-combine.sh)
+AVOIDCOMBINE=$(TESTGCC)
 endif
 
 # Do a whole file compile - two methods are supported.  The first
diff --git a/tools/test-combine.sh b/tools/test-combine.sh
deleted file mode 100755 (executable)
index 6d17fd0..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh
-# Script to test if gcc's -combine option works properly.
-
-TMPFILE1=out/tmp_testcompile1.c
-TMPFILE2=out/tmp_testcompile.o
-
-mkdir -p out
-cat - > $TMPFILE1 <<EOF
-struct ts { union { int u1; struct { int u2; }; }; };
-void t1(struct ts *r);
-EOF
-
-$CC -c -fwhole-program -combine $TMPFILE1 $TMPFILE1 -o $TMPFILE2 > /dev/null 2>&1
-
-if [ $? -eq 0 ]; then
-    #echo "  Setting AVOIDCOMBINE=0" > /dev/fd/2
-    echo 0
-else
-    echo "  Enabling AVOIDCOMBINE=1" > /dev/fd/2
-    echo 1
-fi
-
-rm -f $TMPFILE1 $TMPFILE2
diff --git a/tools/test-gcc.sh b/tools/test-gcc.sh
new file mode 100755 (executable)
index 0000000..1dce450
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/sh
+# Script to test if gcc's -combine option works properly.
+
+mkdir -p out
+TMPFILE1=out/tmp_testcompile1.c
+TMPFILE1o=out/tmp_testcompile1.o
+TMPFILE2=out/tmp_testcompile2.c
+TMPFILE2o=out/tmp_testcompile2.o
+TMPFILE3o=out/tmp_testcompile3.o
+
+# Test for "-fwhole-program"
+gcc -fwhole-program -S -o /dev/null -xc /dev/null > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+    echo "This version of gcc does not support -fwhole-program." > /dev/fd/2
+    echo "Please upgrade to gcc v4.1 or later" > /dev/fd/2
+    echo -1
+    exit -1
+fi
+
+# Test if "visible" functions are marked global.
+cat - > $TMPFILE1 <<EOF
+void __attribute__((externally_visible)) t1() { }
+EOF
+$CC -c -fwhole-program $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
+cat - > $TMPFILE2 <<EOF
+void t1();
+void __attribute__((externally_visible)) main() { t1(); }
+EOF
+$CC -c -fwhole-program $TMPFILE2 -o $TMPFILE2o > /dev/null 2>&1
+$CC $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+    echo "  Working around non-global functions in -fwhole-program" > /dev/fd/2
+fi
+
+# Test if "-combine" works
+mkdir -p out
+cat - > $TMPFILE1 <<EOF
+struct ts { union { int u1; struct { int u2; }; }; };
+void t1(struct ts *r);
+EOF
+$CC -c -fwhole-program -combine $TMPFILE1 $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
+if [ $? -eq 0 ]; then
+    #echo "  Setting AVOIDCOMBINE=0" > /dev/fd/2
+    echo 0
+else
+    echo "  Enabling AVOIDCOMBINE=1" > /dev/fd/2
+    echo 1
+fi
+
+rm -f $TMPFILE1 $TMPFILE1o $TMPFILE2 $TMPFILE2o $TMPFILE3o