Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 1 | #!/bin/sh |
Kevin O'Connor | 84452f1 | 2009-03-27 00:07:07 -0400 | [diff] [blame] | 2 | # Script to test if gcc "-fwhole-program" works properly. |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 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" |
Kevin O'Connor | 2787680 | 2009-03-27 00:12:00 -0400 | [diff] [blame] | 12 | $CC -fwhole-program -S -o /dev/null -xc /dev/null > /dev/null 2>&1 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 13 | if [ $? -ne 0 ]; then |
| 14 | echo "This version of gcc does not support -fwhole-program." > /dev/fd/2 |
| 15 | echo "Please upgrade to gcc v4.1 or later" > /dev/fd/2 |
| 16 | echo -1 |
Kevin O'Connor | ff82b24 | 2009-04-19 21:30:48 -0400 | [diff] [blame] | 17 | exit 1 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 18 | fi |
| 19 | |
Kevin O'Connor | 84452f1 | 2009-03-27 00:07:07 -0400 | [diff] [blame] | 20 | # Test if "visible" variables are marked global. |
| 21 | cat - > $TMPFILE1 <<EOF |
| 22 | unsigned char t1 __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 | extern unsigned char t1; |
| 27 | int __attribute__((externally_visible)) main() { return t1; } |
| 28 | EOF |
| 29 | $CC -Os -c -fwhole-program $TMPFILE2 -o $TMPFILE2o > /dev/null 2>&1 |
Kevin O'Connor | ff82b24 | 2009-04-19 21:30:48 -0400 | [diff] [blame] | 30 | $CC -nostdlib -Os $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1 |
Kevin O'Connor | 84452f1 | 2009-03-27 00:07:07 -0400 | [diff] [blame] | 31 | if [ $? -ne 0 ]; then |
| 32 | echo "This version of gcc does not properly handle" > /dev/fd/2 |
| 33 | echo " global variables in -fwhole-program mode." > /dev/fd/2 |
| 34 | echo "Please upgrade to a newer gcc (eg, v4.3 or later)" > /dev/fd/2 |
| 35 | echo -1 |
Kevin O'Connor | ff82b24 | 2009-04-19 21:30:48 -0400 | [diff] [blame] | 36 | exit 1 |
Kevin O'Connor | 84452f1 | 2009-03-27 00:07:07 -0400 | [diff] [blame] | 37 | fi |
| 38 | |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 39 | # Test if "visible" functions are marked global. |
| 40 | cat - > $TMPFILE1 <<EOF |
| 41 | void __attribute__((externally_visible)) t1() { } |
| 42 | EOF |
Kevin O'Connor | 84452f1 | 2009-03-27 00:07:07 -0400 | [diff] [blame] | 43 | $CC -Os -c -fwhole-program $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 44 | cat - > $TMPFILE2 <<EOF |
| 45 | void t1(); |
| 46 | void __attribute__((externally_visible)) main() { t1(); } |
| 47 | EOF |
Kevin O'Connor | 84452f1 | 2009-03-27 00:07:07 -0400 | [diff] [blame] | 48 | $CC -Os -c -fwhole-program $TMPFILE2 -o $TMPFILE2o > /dev/null 2>&1 |
Kevin O'Connor | ff82b24 | 2009-04-19 21:30:48 -0400 | [diff] [blame] | 49 | $CC -nostdlib -Os $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 50 | if [ $? -ne 0 ]; then |
| 51 | echo " Working around non-global functions in -fwhole-program" > /dev/fd/2 |
| 52 | fi |
| 53 | |
| 54 | # Test if "-combine" works |
| 55 | mkdir -p out |
| 56 | cat - > $TMPFILE1 <<EOF |
| 57 | struct ts { union { int u1; struct { int u2; }; }; }; |
| 58 | void t1(struct ts *r); |
| 59 | EOF |
| 60 | $CC -c -fwhole-program -combine $TMPFILE1 $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1 |
| 61 | if [ $? -eq 0 ]; then |
| 62 | #echo " Setting AVOIDCOMBINE=0" > /dev/fd/2 |
| 63 | echo 0 |
| 64 | else |
| 65 | echo " Enabling AVOIDCOMBINE=1" > /dev/fd/2 |
| 66 | echo 1 |
| 67 | fi |
| 68 | |
| 69 | rm -f $TMPFILE1 $TMPFILE1o $TMPFILE2 $TMPFILE2o $TMPFILE3o |