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 |
Kevin O'Connor | 942d495 | 2009-06-10 22:44:06 -0400 | [diff] [blame] | 14 | echo " Working around no -fwhole-program" > /dev/fd/2 |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 15 | echo 2 |
Kevin O'Connor | 942d495 | 2009-06-10 22:44:06 -0400 | [diff] [blame] | 16 | exit 0 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 17 | fi |
| 18 | |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 19 | # Test if "visible" variables and functions are marked global. |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 20 | cat - > $TMPFILE1 <<EOF |
| 21 | void __attribute__((externally_visible)) t1() { } |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 22 | unsigned char v1 __attribute__((section(".data16.foo.19"))) __attribute__((externally_visible)); |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 23 | EOF |
Kevin O'Connor | 84452f1 | 2009-03-27 00:07:07 -0400 | [diff] [blame] | 24 | $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] | 25 | cat - > $TMPFILE2 <<EOF |
| 26 | void t1(); |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 27 | extern unsigned char v1; |
| 28 | int __attribute__((externally_visible)) main() { t1(); return v1; } |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 29 | EOF |
Kevin O'Connor | 84452f1 | 2009-03-27 00:07:07 -0400 | [diff] [blame] | 30 | $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] | 31 | $CC -nostdlib -Os $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 32 | if [ $? -ne 0 ]; then |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 33 | echo " Working around non-functional -fwhole-program" > /dev/fd/2 |
| 34 | echo 2 |
| 35 | exit 0 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 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 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 46 | echo 0 |
| 47 | else |
Kevin O'Connor | 4d863fe | 2009-06-15 22:45:00 -0400 | [diff] [blame^] | 48 | echo " Working around non-functional -combine" > /dev/fd/2 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 49 | echo 1 |
| 50 | fi |
| 51 | |
| 52 | rm -f $TMPFILE1 $TMPFILE1o $TMPFILE2 $TMPFILE2o $TMPFILE3o |