blob: 738cf64051ac1b7f055b06144513b5f8f9c99c2d [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
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040015 echo 2
Kevin O'Connor942d4952009-06-10 22:44:06 -040016 exit 0
Kevin O'Connor03f630e2009-03-26 20:45:36 -040017fi
18
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040019# Test if "visible" variables and functions are marked global.
Kevin O'Connor03f630e2009-03-26 20:45:36 -040020cat - > $TMPFILE1 <<EOF
21void __attribute__((externally_visible)) t1() { }
Kevin O'Connora68287f2009-06-26 18:55:50 -040022extern unsigned char v1;
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040023unsigned char v1 __attribute__((section(".data16.foo.19"))) __attribute__((externally_visible));
Kevin O'Connor03f630e2009-03-26 20:45:36 -040024EOF
Kevin O'Connor84452f12009-03-27 00:07:07 -040025$CC -Os -c -fwhole-program $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040026cat - > $TMPFILE2 <<EOF
27void t1();
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040028extern unsigned char v1;
29int __attribute__((externally_visible)) main() { t1(); return v1; }
Kevin O'Connor03f630e2009-03-26 20:45:36 -040030EOF
Kevin O'Connor84452f12009-03-27 00:07:07 -040031$CC -Os -c -fwhole-program $TMPFILE2 -o $TMPFILE2o > /dev/null 2>&1
Kevin O'Connorff82b242009-04-19 21:30:48 -040032$CC -nostdlib -Os $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040033if [ $? -ne 0 ]; then
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040034 echo " Working around non-functional -fwhole-program" > /dev/fd/2
35 echo 2
36 exit 0
Kevin O'Connor03f630e2009-03-26 20:45:36 -040037fi
38
39# Test if "-combine" works
40mkdir -p out
41cat - > $TMPFILE1 <<EOF
42struct ts { union { int u1; struct { int u2; }; }; };
43void t1(struct ts *r);
44EOF
45$CC -c -fwhole-program -combine $TMPFILE1 $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
46if [ $? -eq 0 ]; then
Kevin O'Connor03f630e2009-03-26 20:45:36 -040047 echo 0
48else
Kevin O'Connor4d863fe2009-06-15 22:45:00 -040049 echo " Working around non-functional -combine" > /dev/fd/2
Kevin O'Connor03f630e2009-03-26 20:45:36 -040050 echo 1
51fi
52
53rm -f $TMPFILE1 $TMPFILE1o $TMPFILE2 $TMPFILE2o $TMPFILE3o