blob: 3bb91e97d7d1d2cba1a27cbc6283dfb007296596 [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
Kevin O'Connorab233da2009-06-30 21:13:44 -040011# Test for "-fwhole-program". Older versions of gcc (pre v4.1) don't
12# support the whole-program optimization - detect that.
Kevin O'Connor27876802009-03-27 00:12:00 -040013$CC -fwhole-program -S -o /dev/null -xc /dev/null > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040014if [ $? -ne 0 ]; then
Kevin O'Connor942d4952009-06-10 22:44:06 -040015 echo " Working around no -fwhole-program" > /dev/fd/2
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040016 echo 2
Kevin O'Connor942d4952009-06-10 22:44:06 -040017 exit 0
Kevin O'Connor03f630e2009-03-26 20:45:36 -040018fi
19
Kevin O'Connorab233da2009-06-30 21:13:44 -040020# 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'Connor03f630e2009-03-26 20:45:36 -040025cat - > $TMPFILE1 <<EOF
26void __attribute__((externally_visible)) t1() { }
Kevin O'Connora68287f2009-06-26 18:55:50 -040027extern unsigned char v1;
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040028unsigned char v1 __attribute__((section(".data16.foo.19"))) __attribute__((externally_visible));
Kevin O'Connor03f630e2009-03-26 20:45:36 -040029EOF
Kevin O'Connor84452f12009-03-27 00:07:07 -040030$CC -Os -c -fwhole-program $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040031cat - > $TMPFILE2 <<EOF
32void t1();
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040033extern unsigned char v1;
34int __attribute__((externally_visible)) main() { t1(); return v1; }
Kevin O'Connor03f630e2009-03-26 20:45:36 -040035EOF
Kevin O'Connor84452f12009-03-27 00:07:07 -040036$CC -Os -c -fwhole-program $TMPFILE2 -o $TMPFILE2o > /dev/null 2>&1
Kevin O'Connorff82b242009-04-19 21:30:48 -040037$CC -nostdlib -Os $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040038if [ $? -ne 0 ]; then
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040039 echo " Working around non-functional -fwhole-program" > /dev/fd/2
40 echo 2
41 exit 0
Kevin O'Connor03f630e2009-03-26 20:45:36 -040042fi
43
Kevin O'Connorab233da2009-06-30 21:13:44 -040044# 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'Connor3133e382009-11-20 09:19:28 -050046# 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'Connor03f630e2009-03-26 20:45:36 -040049cat - > $TMPFILE1 <<EOF
Kevin O'Connor3133e382009-11-20 09:19:28 -050050// Look for anonymous union/struct failure
Kevin O'Connor03f630e2009-03-26 20:45:36 -040051struct ts { union { int u1; struct { int u2; }; }; };
Kevin O'Connor3133e382009-11-20 09:19:28 -050052void func1(struct ts *r);
53
54// Look for global variable failure.
55struct s1_s { int v; } g1;
56void __attribute__((externally_visible)) func2() {
57 struct s1_s *l1 = &g1;
58}
Kevin O'Connor03f630e2009-03-26 20:45:36 -040059EOF
Kevin O'Connor3133e382009-11-20 09:19:28 -050060cat - > $TMPFILE2 <<EOF
61struct ts { union { int u1; struct { int u2; }; }; };
62void func1(struct ts *r);
63
64extern struct s1_s g1;
65void func3() {
66 &g1;
67}
68EOF
69$CC -O -g -fwhole-program -combine -c $TMPFILE1 $TMPFILE2 -o $TMPFILE1o > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040070if [ $? -eq 0 ]; then
Kevin O'Connor03f630e2009-03-26 20:45:36 -040071 echo 0
72else
Kevin O'Connor4d863fe2009-06-15 22:45:00 -040073 echo " Working around non-functional -combine" > /dev/fd/2
Kevin O'Connor03f630e2009-03-26 20:45:36 -040074 echo 1
75fi
76
Kevin O'Connor3133e382009-11-20 09:19:28 -050077# Also, on several compilers, -combine fails if code is emitted with a
78# reference to an extern variable that is later found to be externally
79# visible - the compiler does not mark those variables as global.
80# This is being worked around by ordering the compile objects to avoid
81# this case.
82
Kevin O'Connorab233da2009-06-30 21:13:44 -040083# Also, the Ubuntu 8.04 compiler has a bug causing corruption when the
84# "ebp" register is clobberred in an "asm" statement. The code has
85# been modified to not clobber "ebp" - no test is available yet.
86
Kevin O'Connor03f630e2009-03-26 20:45:36 -040087rm -f $TMPFILE1 $TMPFILE1o $TMPFILE2 $TMPFILE2o $TMPFILE3o