Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 1 | #!/bin/sh |
Kevin O'Connor | 51d6ba3 | 2012-05-30 21:31:42 -0400 | [diff] [blame] | 2 | # Script to test if the build works properly. |
| 3 | |
| 4 | # Test IASL is installed. |
| 5 | $IASL -h > /dev/null 2>&1 |
| 6 | if [ $? -ne 0 ]; then |
| 7 | echo "The SeaBIOS project requires the 'iasl' package be installed." >&2 |
| 8 | echo "Many Linux distributions have this package." >&2 |
| 9 | echo "Try: sudo yum install iasl" >&2 |
| 10 | echo "Or: sudo apt-get install iasl" >&2 |
| 11 | echo "" >&2 |
| 12 | echo "Please install iasl and retry." >&2 |
| 13 | echo -1 |
| 14 | exit 0 |
| 15 | fi |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 16 | |
| 17 | mkdir -p out |
| 18 | TMPFILE1=out/tmp_testcompile1.c |
| 19 | TMPFILE1o=out/tmp_testcompile1.o |
Kevin O'Connor | 626416e | 2011-05-21 21:05:04 -0400 | [diff] [blame] | 20 | TMPFILE1_ld=out/tmp_testcompile1.lds |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 21 | TMPFILE2=out/tmp_testcompile2.c |
| 22 | TMPFILE2o=out/tmp_testcompile2.o |
| 23 | TMPFILE3o=out/tmp_testcompile3.o |
| 24 | |
Kevin O'Connor | 626416e | 2011-05-21 21:05:04 -0400 | [diff] [blame] | 25 | # Test if ld's alignment handling is correct. This is a known problem |
| 26 | # with the linker that ships with Ubuntu 11.04. |
| 27 | cat - > $TMPFILE1 <<EOF |
| 28 | const char v1[] __attribute__((section(".text.v1"))) = "0123456789"; |
| 29 | const char v2[] __attribute__((section(".text.v2"))) = "0123456789"; |
| 30 | EOF |
| 31 | cat - > $TMPFILE1_ld <<EOF |
| 32 | SECTIONS |
| 33 | { |
| 34 | .mysection 0x88f0 : { |
| 35 | . = 0x10 ; |
| 36 | *(.text.v1) |
| 37 | . = 0x20 ; |
| 38 | *(.text.v2) |
| 39 | . = 0x30 ; |
| 40 | } |
| 41 | } |
| 42 | EOF |
| 43 | $CC -O -g -c $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1 |
| 44 | $LD -T $TMPFILE1_ld $TMPFILE1o -o $TMPFILE2o > /dev/null 2>&1 |
| 45 | if [ $? -ne 0 ]; then |
Ian Campbell | 57929d8 | 2012-03-22 15:25:24 +0000 | [diff] [blame] | 46 | echo "The version of LD on this system does not properly handle" >&2 |
| 47 | echo "alignments. As a result, this project can not be built." >&2 |
| 48 | echo "" >&2 |
| 49 | echo "The problem may be the result of this LD bug report:" >&2 |
| 50 | echo " http://sourceware.org/bugzilla/show_bug.cgi?id=12726" >&2 |
| 51 | echo "" >&2 |
| 52 | echo "Please update to a working version of binutils and retry." >&2 |
Kevin O'Connor | 626416e | 2011-05-21 21:05:04 -0400 | [diff] [blame] | 53 | echo -1 |
| 54 | exit 0 |
| 55 | fi |
| 56 | |
Kevin O'Connor | ab233da | 2009-06-30 21:13:44 -0400 | [diff] [blame] | 57 | # Test for "-fwhole-program". Older versions of gcc (pre v4.1) don't |
| 58 | # support the whole-program optimization - detect that. |
Kevin O'Connor | 2787680 | 2009-03-27 00:12:00 -0400 | [diff] [blame] | 59 | $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] | 60 | if [ $? -ne 0 ]; then |
Ian Campbell | 57929d8 | 2012-03-22 15:25:24 +0000 | [diff] [blame] | 61 | echo " Working around no -fwhole-program" >&2 |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 62 | echo 2 |
Kevin O'Connor | 942d495 | 2009-06-10 22:44:06 -0400 | [diff] [blame] | 63 | exit 0 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 64 | fi |
| 65 | |
Kevin O'Connor | ab233da | 2009-06-30 21:13:44 -0400 | [diff] [blame] | 66 | # Test if "visible" variables and functions are marked global. On |
| 67 | # OpenSuse 10.3 "visible" variables declared with "extern" first |
| 68 | # aren't marked as global in the resulting assembler. On Ubuntu 7.10 |
| 69 | # "visible" functions aren't marked as global in the resulting |
| 70 | # assembler. |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 71 | cat - > $TMPFILE1 <<EOF |
| 72 | void __attribute__((externally_visible)) t1() { } |
Kevin O'Connor | a68287f | 2009-06-26 18:55:50 -0400 | [diff] [blame] | 73 | extern unsigned char v1; |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 74 | unsigned char v1 __attribute__((section(".data16.foo.19"))) __attribute__((externally_visible)); |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 75 | EOF |
Kevin O'Connor | 84452f1 | 2009-03-27 00:07:07 -0400 | [diff] [blame] | 76 | $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] | 77 | cat - > $TMPFILE2 <<EOF |
| 78 | void t1(); |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 79 | extern unsigned char v1; |
| 80 | int __attribute__((externally_visible)) main() { t1(); return v1; } |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 81 | EOF |
Kevin O'Connor | 84452f1 | 2009-03-27 00:07:07 -0400 | [diff] [blame] | 82 | $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] | 83 | $CC -nostdlib -Os $TMPFILE1o $TMPFILE2o -o $TMPFILE3o > /dev/null 2>&1 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 84 | if [ $? -ne 0 ]; then |
Ian Campbell | 57929d8 | 2012-03-22 15:25:24 +0000 | [diff] [blame] | 85 | echo " Working around non-functional -fwhole-program" >&2 |
Kevin O'Connor | 0942e7f | 2009-06-15 22:27:01 -0400 | [diff] [blame] | 86 | echo 2 |
| 87 | exit 0 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 88 | fi |
| 89 | |
Kevin O'Connor | ab233da | 2009-06-30 21:13:44 -0400 | [diff] [blame] | 90 | # Test if "-combine" works. On Ubuntu 8.04 the compiler doesn't work |
| 91 | # correctly with combine and the "struct bregs" register due to the |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 92 | # anonymous unions and structs. On Fedora Core 12 the compiler throws |
| 93 | # an internal compiler error when multiple files access global |
| 94 | # variables with debugging enabled. |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 95 | cat - > $TMPFILE1 <<EOF |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 96 | // Look for anonymous union/struct failure |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 97 | struct ts { union { int u1; struct { int u2; }; }; }; |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 98 | void func1(struct ts *r); |
| 99 | |
| 100 | // Look for global variable failure. |
| 101 | struct s1_s { int v; } g1; |
| 102 | void __attribute__((externally_visible)) func2() { |
| 103 | struct s1_s *l1 = &g1; |
Kevin O'Connor | 8918989 | 2010-01-03 15:12:00 -0500 | [diff] [blame] | 104 | l1->v=0; |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 105 | } |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 106 | EOF |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 107 | cat - > $TMPFILE2 <<EOF |
| 108 | struct ts { union { int u1; struct { int u2; }; }; }; |
| 109 | void func1(struct ts *r); |
| 110 | |
| 111 | extern struct s1_s g1; |
| 112 | void func3() { |
| 113 | &g1; |
| 114 | } |
| 115 | EOF |
| 116 | $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] | 117 | if [ $? -eq 0 ]; then |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 118 | echo 0 |
| 119 | else |
Ian Campbell | 57929d8 | 2012-03-22 15:25:24 +0000 | [diff] [blame] | 120 | echo " Working around non-functional -combine" >&2 |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 121 | echo 1 |
| 122 | fi |
| 123 | |
Kevin O'Connor | 3133e38 | 2009-11-20 09:19:28 -0500 | [diff] [blame] | 124 | # Also, on several compilers, -combine fails if code is emitted with a |
| 125 | # reference to an extern variable that is later found to be externally |
| 126 | # visible - the compiler does not mark those variables as global. |
| 127 | # This is being worked around by ordering the compile objects to avoid |
| 128 | # this case. |
| 129 | |
Kevin O'Connor | ab233da | 2009-06-30 21:13:44 -0400 | [diff] [blame] | 130 | # Also, the Ubuntu 8.04 compiler has a bug causing corruption when the |
| 131 | # "ebp" register is clobberred in an "asm" statement. The code has |
| 132 | # been modified to not clobber "ebp" - no test is available yet. |
| 133 | |
Kevin O'Connor | 626416e | 2011-05-21 21:05:04 -0400 | [diff] [blame] | 134 | rm -f $TMPFILE1 $TMPFILE1o $TMPFILE1_ld $TMPFILE2 $TMPFILE2o $TMPFILE3o |