blob: 55f359faccd61657a712b8e8a5a81bd5af4bb4d9 [file] [log] [blame]
Kevin O'Connor03f630e2009-03-26 20:45:36 -04001#!/bin/sh
Kevin O'Connor84452f12009-03-27 00:07:07 -04002# Script to test if gcc "-fwhole-program" works properly.
Kevin O'Connor03f630e2009-03-26 20:45:36 -04003
4mkdir -p out
5TMPFILE1=out/tmp_testcompile1.c
6TMPFILE1o=out/tmp_testcompile1.o
7TMPFILE2=out/tmp_testcompile2.c
8TMPFILE2o=out/tmp_testcompile2.o
9TMPFILE3o=out/tmp_testcompile3.o
10
11# Test for "-fwhole-program"
Kevin O'Connor27876802009-03-27 00:12:00 -040012$CC -fwhole-program -S -o /dev/null -xc /dev/null > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040013if [ $? -ne 0 ]; then
Kevin O'Connor942d4952009-06-10 22:44:06 -040014 echo " Working around no -fwhole-program" > /dev/fd/2
15 echo 1
16 exit 0
Kevin O'Connor03f630e2009-03-26 20:45:36 -040017fi
18
Kevin O'Connor84452f12009-03-27 00:07:07 -040019# Test if "visible" variables are marked global.
20cat - > $TMPFILE1 <<EOF
21unsigned char t1 __attribute__((section(".data16.foo.19"))) __attribute__((externally_visible));
22EOF
23$CC -Os -c -fwhole-program $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
24cat - > $TMPFILE2 <<EOF
25extern unsigned char t1;
26int __attribute__((externally_visible)) main() { return t1; }
27EOF
28$CC -Os -c -fwhole-program $TMPFILE2 -o $TMPFILE2o > /dev/null 2>&1
Kevin O'Connorff82b242009-04-19 21:30:48 -040029$CC -nostdlib -Os $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1
Kevin O'Connor84452f12009-03-27 00:07:07 -040030if [ $? -ne 0 ]; then
31 echo "This version of gcc does not properly handle" > /dev/fd/2
32 echo " global variables in -fwhole-program mode." > /dev/fd/2
33 echo "Please upgrade to a newer gcc (eg, v4.3 or later)" > /dev/fd/2
34 echo -1
Kevin O'Connorff82b242009-04-19 21:30:48 -040035 exit 1
Kevin O'Connor84452f12009-03-27 00:07:07 -040036fi
37
Kevin O'Connor03f630e2009-03-26 20:45:36 -040038# Test if "visible" functions are marked global.
39cat - > $TMPFILE1 <<EOF
40void __attribute__((externally_visible)) t1() { }
41EOF
Kevin O'Connor84452f12009-03-27 00:07:07 -040042$CC -Os -c -fwhole-program $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040043cat - > $TMPFILE2 <<EOF
44void t1();
45void __attribute__((externally_visible)) main() { t1(); }
46EOF
Kevin O'Connor84452f12009-03-27 00:07:07 -040047$CC -Os -c -fwhole-program $TMPFILE2 -o $TMPFILE2o > /dev/null 2>&1
Kevin O'Connorff82b242009-04-19 21:30:48 -040048$CC -nostdlib -Os $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040049if [ $? -ne 0 ]; then
50 echo " Working around non-global functions in -fwhole-program" > /dev/fd/2
51fi
52
53# Test if "-combine" works
54mkdir -p out
55cat - > $TMPFILE1 <<EOF
56struct ts { union { int u1; struct { int u2; }; }; };
57void t1(struct ts *r);
58EOF
59$CC -c -fwhole-program -combine $TMPFILE1 $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
60if [ $? -eq 0 ]; then
61 #echo " Setting AVOIDCOMBINE=0" > /dev/fd/2
62 echo 0
63else
64 echo " Enabling AVOIDCOMBINE=1" > /dev/fd/2
65 echo 1
66fi
67
68rm -f $TMPFILE1 $TMPFILE1o $TMPFILE2 $TMPFILE2o $TMPFILE3o