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 | |
Kevin O'Connor | ab233da | 2009-06-30 21:13:44 -0400 | [diff] [blame] | 11 | # Test for "-fwhole-program". Older versions of gcc (pre v4.1) don't |
| 12 | # support the whole-program optimization - detect that. |
Kevin O'Connor | 2787680 | 2009-03-27 00:12:00 -0400 | [diff] [blame] | 13 | $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] | 14 | if [ $? -ne 0 ]; then |
Kevin O'Connor | 942d495 | 2009-06-10 22:44:06 -0400 | [diff] [blame] | 15 | echo " Working around no -fwhole-program" > /dev/fd/2 |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 16 | echo 2 |
Kevin O'Connor | 942d495 | 2009-06-10 22:44:06 -0400 | [diff] [blame] | 17 | exit 0 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 18 | fi |
| 19 | |
Kevin O'Connor | ab233da | 2009-06-30 21:13:44 -0400 | [diff] [blame] | 20 | # Test if "visible" variables and functions are marked global. On |
| 21 | # OpenSuse 10.3 "visible" variables declared with "extern" first |
| 22 | # aren't marked as global in the resulting assembler. On Ubuntu 7.10 |
| 23 | # "visible" functions aren't marked as global in the resulting |
| 24 | # assembler. |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 25 | cat - > $TMPFILE1 <<EOF |
| 26 | void __attribute__((externally_visible)) t1() { } |
Kevin O'Connor | a68287f | 2009-06-26 18:55:50 -0400 | [diff] [blame] | 27 | extern unsigned char v1; |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 28 | unsigned char v1 __attribute__((section(".data16.foo.19"))) __attribute__((externally_visible)); |
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 $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 31 | cat - > $TMPFILE2 <<EOF |
| 32 | void t1(); |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 33 | extern unsigned char v1; |
| 34 | int __attribute__((externally_visible)) main() { t1(); return v1; } |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 35 | EOF |
Kevin O'Connor | 84452f1 | 2009-03-27 00:07:07 -0400 | [diff] [blame] | 36 | $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] | 37 | $CC -nostdlib -Os $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 38 | if [ $? -ne 0 ]; then |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 39 | echo " Working around non-functional -fwhole-program" > /dev/fd/2 |
| 40 | echo 2 |
| 41 | exit 0 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 42 | fi |
| 43 | |
Kevin O'Connor | ab233da | 2009-06-30 21:13:44 -0400 | [diff] [blame] | 44 | # Test if "-combine" works. On Ubuntu 8.04 the compiler doesn't work |
| 45 | # correctly with combine and the "struct bregs" register due to the |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 46 | # anonymous unions and structs. On Fedora Core 12 the compiler throws |
| 47 | # an internal compiler error when multiple files access global |
| 48 | # variables with debugging enabled. |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 49 | cat - > $TMPFILE1 <<EOF |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 50 | // Look for anonymous union/struct failure |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 51 | struct ts { union { int u1; struct { int u2; }; }; }; |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 52 | void func1(struct ts *r); |
| 53 | |
| 54 | // Look for global variable failure. |
| 55 | struct s1_s { int v; } g1; |
| 56 | void __attribute__((externally_visible)) func2() { |
| 57 | struct s1_s *l1 = &g1; |
Kevin O'Connor | 8918989 | 2010-01-03 15:12:00 -0500 | [diff] [blame] | 58 | l1->v=0; |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 59 | } |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 60 | EOF |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 61 | cat - > $TMPFILE2 <<EOF |
| 62 | struct ts { union { int u1; struct { int u2; }; }; }; |
| 63 | void func1(struct ts *r); |
| 64 | |
| 65 | extern struct s1_s g1; |
| 66 | void func3() { |
| 67 | &g1; |
| 68 | } |
| 69 | EOF |
| 70 | $CC -O -g -fwhole-program -combine -c $TMPFILE1 $TMPFILE2 -o $TMPFILE1o > /dev/null 2>&1 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 71 | if [ $? -eq 0 ]; then |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 72 | echo 0 |
| 73 | else |
Kevin O'Connor | 4d863fe | 2009-06-15 22:45:00 -0400 | [diff] [blame] | 74 | echo " Working around non-functional -combine" > /dev/fd/2 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 75 | echo 1 |
| 76 | fi |
| 77 | |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 78 | # Also, on several compilers, -combine fails if code is emitted with a |
| 79 | # reference to an extern variable that is later found to be externally |
| 80 | # visible - the compiler does not mark those variables as global. |
| 81 | # This is being worked around by ordering the compile objects to avoid |
| 82 | # this case. |
| 83 | |
Kevin O'Connor | ab233da | 2009-06-30 21:13:44 -0400 | [diff] [blame] | 84 | # Also, the Ubuntu 8.04 compiler has a bug causing corruption when the |
| 85 | # "ebp" register is clobberred in an "asm" statement. The code has |
| 86 | # been modified to not clobber "ebp" - no test is available yet. |
| 87 | |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 88 | rm -f $TMPFILE1 $TMPFILE1o $TMPFILE2 $TMPFILE2o $TMPFILE3o |