blob: 25cc2f20ef85da4e9fb0d7c6aedd3290a86c5b60 [file] [log] [blame]
Kevin O'Connor03f630e2009-03-26 20:45:36 -04001#!/bin/sh
Kevin O'Connor51d6ba32012-05-30 21:31:42 -04002# Script to test if the build works properly.
3
Kevin O'Connor23219122013-02-17 10:56:10 -05004mkdir -p ${OUT}
5TMPFILE1=${OUT}/tmp_testcompile1.c
6TMPFILE1o=${OUT}/tmp_testcompile1.o
7TMPFILE1_ld=${OUT}/tmp_testcompile1.lds
8TMPFILE2=${OUT}/tmp_testcompile2.c
9TMPFILE2o=${OUT}/tmp_testcompile2.o
10TMPFILE3o=${OUT}/tmp_testcompile3.o
Kevin O'Connor03f630e2009-03-26 20:45:36 -040011
Kevin O'Connor626416e2011-05-21 21:05:04 -040012# Test if ld's alignment handling is correct. This is a known problem
13# with the linker that ships with Ubuntu 11.04.
14cat - > $TMPFILE1 <<EOF
15const char v1[] __attribute__((section(".text.v1"))) = "0123456789";
16const char v2[] __attribute__((section(".text.v2"))) = "0123456789";
17EOF
18cat - > $TMPFILE1_ld <<EOF
19SECTIONS
20{
21 .mysection 0x88f0 : {
22. = 0x10 ;
23*(.text.v1)
24. = 0x20 ;
25*(.text.v2)
26. = 0x30 ;
27 }
28}
29EOF
30$CC -O -g -c $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
Kevin O'Connorbb0808a2013-02-18 10:28:55 -050031if [ $? -ne 0 ]; then
32 echo "Unable to execute the C compiler ($CC)." >&2
33 echo "" >&2
34 echo "Please install a working compiler and retry." >&2
35 echo -1
36 exit 0
37fi
Kevin O'Connor626416e2011-05-21 21:05:04 -040038$LD -T $TMPFILE1_ld $TMPFILE1o -o $TMPFILE2o > /dev/null 2>&1
39if [ $? -ne 0 ]; then
Kevin O'Connorbb0808a2013-02-18 10:28:55 -050040 echo "The version of LD on this system ($LD) does not properly handle" >&2
Ian Campbell57929d82012-03-22 15:25:24 +000041 echo "alignments. As a result, this project can not be built." >&2
42 echo "" >&2
43 echo "The problem may be the result of this LD bug report:" >&2
44 echo " http://sourceware.org/bugzilla/show_bug.cgi?id=12726" >&2
45 echo "" >&2
46 echo "Please update to a working version of binutils and retry." >&2
Kevin O'Connor626416e2011-05-21 21:05:04 -040047 echo -1
48 exit 0
49fi
50
Kevin O'Connorab233da2009-06-30 21:13:44 -040051# Test for "-fwhole-program". Older versions of gcc (pre v4.1) don't
52# support the whole-program optimization - detect that.
Kevin O'Connor27876802009-03-27 00:12:00 -040053$CC -fwhole-program -S -o /dev/null -xc /dev/null > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040054if [ $? -ne 0 ]; then
Ian Campbell57929d82012-03-22 15:25:24 +000055 echo " Working around no -fwhole-program" >&2
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040056 echo 2
Kevin O'Connor942d4952009-06-10 22:44:06 -040057 exit 0
Kevin O'Connor03f630e2009-03-26 20:45:36 -040058fi
59
Kevin O'Connorab233da2009-06-30 21:13:44 -040060# Test if "visible" variables and functions are marked global. On
61# OpenSuse 10.3 "visible" variables declared with "extern" first
62# aren't marked as global in the resulting assembler. On Ubuntu 7.10
63# "visible" functions aren't marked as global in the resulting
64# assembler.
Kevin O'Connor03f630e2009-03-26 20:45:36 -040065cat - > $TMPFILE1 <<EOF
66void __attribute__((externally_visible)) t1() { }
Kevin O'Connora68287f2009-06-26 18:55:50 -040067extern unsigned char v1;
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040068unsigned char v1 __attribute__((section(".data16.foo.19"))) __attribute__((externally_visible));
Kevin O'Connor03f630e2009-03-26 20:45:36 -040069EOF
Kevin O'Connor84452f12009-03-27 00:07:07 -040070$CC -Os -c -fwhole-program $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040071cat - > $TMPFILE2 <<EOF
72void t1();
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040073extern unsigned char v1;
74int __attribute__((externally_visible)) main() { t1(); return v1; }
Kevin O'Connor03f630e2009-03-26 20:45:36 -040075EOF
Kevin O'Connor84452f12009-03-27 00:07:07 -040076$CC -Os -c -fwhole-program $TMPFILE2 -o $TMPFILE2o > /dev/null 2>&1
Kevin O'Connorff82b242009-04-19 21:30:48 -040077$CC -nostdlib -Os $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1
Kevin O'Connor03f630e2009-03-26 20:45:36 -040078if [ $? -ne 0 ]; then
Ian Campbell57929d82012-03-22 15:25:24 +000079 echo " Working around non-functional -fwhole-program" >&2
Kevin O'Connor0942e7f2009-06-15 22:27:01 -040080 echo 2
81 exit 0
Kevin O'Connor03f630e2009-03-26 20:45:36 -040082fi
83
Kevin O'Connorfa2eacb2012-12-11 21:59:45 -050084echo 0
Kevin O'Connor3133e382009-11-20 09:19:28 -050085
Kevin O'Connorab233da2009-06-30 21:13:44 -040086# Also, the Ubuntu 8.04 compiler has a bug causing corruption when the
87# "ebp" register is clobberred in an "asm" statement. The code has
88# been modified to not clobber "ebp" - no test is available yet.
89
Kevin O'Connor626416e2011-05-21 21:05:04 -040090rm -f $TMPFILE1 $TMPFILE1o $TMPFILE1_ld $TMPFILE2 $TMPFILE2o $TMPFILE3o