Annotation of qemu/roms/seabios/tools/test-gcc.sh, revision 1.1.1.3

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.