Check for broken LD that ships with Ubuntu 11.04.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 22 May 2011 01:05:04 +0000 (21:05 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 22 May 2011 01:05:04 +0000 (21:05 -0400)
Add a build test to ensure that LD can properly align sections.

Makefile
tools/test-gcc.sh

index 9affb398b8980a7c86e6088e488eae211ea787ef..d17f85ae032609c8b68c8c2cbc8ba87ed7de3e2b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -70,9 +70,9 @@ vpath %.S src vgasrc
 ################ Build rules
 
 # Verify the gcc configuration and test if -fwhole-program works.
-TESTGCC:=$(shell CC="$(CC)" tools/test-gcc.sh)
+TESTGCC:=$(shell CC="$(CC)" LD="$(LD)" tools/test-gcc.sh)
 ifeq "$(TESTGCC)" "-1"
-$(error "Please upgrade GCC")
+$(error "Please upgrade GCC and/or binutils")
 endif
 
 ifndef COMPSTRAT
index ce3497b0d3f0a262920ed57fc3c6df2ed75b0ac1..935f211b0a2f6899846cfdb2a875c7f13534d6f0 100755 (executable)
@@ -4,10 +4,43 @@
 mkdir -p out
 TMPFILE1=out/tmp_testcompile1.c
 TMPFILE1o=out/tmp_testcompile1.o
+TMPFILE1_ld=out/tmp_testcompile1.lds
 TMPFILE2=out/tmp_testcompile2.c
 TMPFILE2o=out/tmp_testcompile2.o
 TMPFILE3o=out/tmp_testcompile3.o
 
+# Test if ld's alignment handling is correct.  This is a known problem
+# with the linker that ships with Ubuntu 11.04.
+cat - > $TMPFILE1 <<EOF
+const char v1[] __attribute__((section(".text.v1"))) = "0123456789";
+const char v2[] __attribute__((section(".text.v2"))) = "0123456789";
+EOF
+cat - > $TMPFILE1_ld <<EOF
+SECTIONS
+{
+     .mysection 0x88f0 : {
+. = 0x10 ;
+*(.text.v1)
+. = 0x20 ;
+*(.text.v2)
+. = 0x30 ;
+     }
+}
+EOF
+$CC -O -g -c $TMPFILE1 -o $TMPFILE1o > /dev/null 2>&1
+$LD -T $TMPFILE1_ld $TMPFILE1o -o $TMPFILE2o > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+    echo "The version of LD on this system does not properly handle" > /dev/fd/2
+    echo "alignments.  As a result, this project can not be built." > /dev/fd/2
+    echo "" > /dev/fd/2
+    echo "The problem may be the result of this LD bug report:" > /dev/fd/2
+    echo " http://sourceware.org/bugzilla/show_bug.cgi?id=12726" > /dev/fd/2
+    echo "" > /dev/fd/2
+    echo "Please update to a working version of binutils and retry." > /dev/fd/2
+    echo -1
+    exit 0
+fi
+
 # Test for "-fwhole-program".  Older versions of gcc (pre v4.1) don't
 # support the whole-program optimization - detect that.
 $CC -fwhole-program -S -o /dev/null -xc /dev/null > /dev/null 2>&1
@@ -85,4 +118,4 @@ fi
 # "ebp" register is clobberred in an "asm" statement.  The code has
 # been modified to not clobber "ebp" - no test is available yet.
 
-rm -f $TMPFILE1 $TMPFILE1o $TMPFILE2 $TMPFILE2o $TMPFILE3o
+rm -f $TMPFILE1 $TMPFILE1o $TMPFILE1_ld $TMPFILE2 $TMPFILE2o $TMPFILE3o