Avoid -fwhole-program on broken gcc instead of stopping build.
[seabios.git] / tools / test-gcc.sh
1 #!/bin/sh
2 # Script to test if gcc "-fwhole-program" works properly.
3
4 mkdir -p out
5 TMPFILE1=out/tmp_testcompile1.c
6 TMPFILE1o=out/tmp_testcompile1.o
7 TMPFILE2=out/tmp_testcompile2.c
8 TMPFILE2o=out/tmp_testcompile2.o
9 TMPFILE3o=out/tmp_testcompile3.o
10
11 # Test for "-fwhole-program"
12 $CC -fwhole-program -S -o /dev/null -xc /dev/null > /dev/null 2>&1
13 if [ $? -ne 0 ]; then
14     echo "  Working around no -fwhole-program" > /dev/fd/2
15     echo 2
16     exit 0
17 fi
18
19 # Test if "visible" variables and functions are marked global.
20 cat - > $TMPFILE1 <<EOF
21 void __attribute__((externally_visible)) t1() { }
22 unsigned char v1 __attribute__((section(".data16.foo.19"))) __attribute__((externally_visible));
23 EOF
24 $CC -Os -c -fwhole-program $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
25 cat - > $TMPFILE2 <<EOF
26 void t1();
27 extern unsigned char v1;
28 int __attribute__((externally_visible)) main() { t1(); return v1; }
29 EOF
30 $CC -Os -c -fwhole-program $TMPFILE2 -o $TMPFILE2o > /dev/null 2>&1
31 $CC -nostdlib -Os $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1
32 if [ $? -ne 0 ]; then
33     echo "  Working around non-functional -fwhole-program" > /dev/fd/2
34     echo 2
35     exit 0
36 fi
37
38 # Test if "-combine" works
39 mkdir -p out
40 cat - > $TMPFILE1 <<EOF
41 struct ts { union { int u1; struct { int u2; }; }; };
42 void t1(struct ts *r);
43 EOF
44 $CC -c -fwhole-program -combine $TMPFILE1 $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
45 if [ $? -eq 0 ]; then
46     #echo "  Setting AVOIDCOMBINE=0" > /dev/fd/2
47     echo 0
48 else
49     echo "  Enabling AVOIDCOMBINE=1" > /dev/fd/2
50     echo 1
51 fi
52
53 rm -f $TMPFILE1 $TMPFILE1o $TMPFILE2 $TMPFILE2o $TMPFILE3o