Skip to contentSkip to conversation

Qemu 32-bit i386, gcc >= 3.4 spill error fix

Qemu-devel Ben Taylor 3 participants 5 messages May 4, 2008 – May 5, 2008 Kbuild

lore
Share & tools
lore

Ben Taylor

author
#0 lore raw

This patch applies some additional flags to op.c and helper.c for compiling on i386 32-bit systems with gcc >= 3.4.

This has been tested on both ubuntu 7.10/32-bit and Solaris SXCE/32-bit with both gcc-3.3 and gcc-3.4 and the behavior is consistent between both.

This is just a short term fix til the SSE ops are converted to TCG.

Ben

diff -r qemu.ORIG/configure qemu/configure
1201a1202,1208

Quoted 7 lines
    gcc3minver=`$cc --version 2> /dev/null| fgrep "(GCC) 3." | awk '{ print $3 }' | cut -f2 -d.`
    if test -n "$gcc3minver" -a $gcc3minver -gt 3
    then
      echo "HAVE_GT_GCC_3_3=true" >> $config_mak
    else
      echo "HAVE_GT_GCC_3_3=false" >> $config_mak
    fi

diff -r qemu.ORIG/Makefile.target qemu/Makefile.target 98a99,104

Quoted 6 lines

# OP_CFLAGS needs this on 32-bit x86 system to avoid

# a compiler spill error. This can probably go away
# once the SSE ops have been converted to TCG
ifeq ($(HAVE_GT_GCC_3_3), true)
MTUNE_CFLAGS=-march=i486 -mtune=i686
endif

312c318
< $(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $<
---

Quoted 1 line
	$(CC) $(OP_CFLAGS) $(CPPFLAGS) $(MTUNE_CFLAGS) -c -o $@ $<

319a326,339

Quoted 5 lines
  # if current host is i386 and gcc >= -3.4, CFLAGS requires some
  # handling as helper.c generates a compiler spill error if 
  # -march=i686 and -mtune=i686. We set 
  # MTUNE_CFLAGS="-march=i486 -mtune=i686" here
  # Once SSE ops are converted to TCG, this can go away
Quoted 9 lines
  HCFLAGS=$(CFLAGS)
  ifeq ($(ARCH), i386)
    ifeq ($(HAVE_GT_GCC_3_3), true)
      # if CFLAGS has -march=i686, remove it so helper.o
      # can compile on 32-bit intel systems
      HCFLAGS=`echo $(CFLAGS) | sed 's,-march=i686,,'`
    endif
  endif

322c342
< $(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
---

Quoted 1 line
	$(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(MTUNE_CFLAGS) $(HCFLAGS) -c -o $@ $<
author
#1 lore raw
Quoted 10 lines · Ben Taylor

This patch applies some additional flags to op.c and helper.c
for compiling on i386 32-bit systems with gcc >= 3.4.

This has been tested on both ubuntu 7.10/32-bit and Solaris SXCE/32-bit with both gcc-3.3 and gcc-3.4 and the behavior is consistent between both.

This is just a short term fix til the SSE ops are converted to TCG.

I updated the patch to take care of -mtune options that might be set by --extra-cflags, as well as the -march flags. I added support for athlon-xp, as someone mentioned it in #qemu with the exact error that helper.c sees in this context, so I fixed it as I have an athlon-xp.

Ben

configure +7 -0
diff -ruN qemu.ORIG/configure qemu/configure
@@ -1199,6 +1199,13 @@
     then
       echo "#define USE_KQEMU 1" >> $config_h
     fi
+    gcc3minver=`$cc --version 2> /dev/null| fgrep "(GCC) 3." | awk '{ print $3 }' | cut -f2 -d.`
+    if test -n "$gcc3minver" -a $gcc3minver -gt 3
+    then
+      echo "HAVE_GT_GCC_3_3=true" >> $config_mak
+    else
+      echo "HAVE_GT_GCC_3_3=false" >> $config_mak
+    fi
   ;;
   x86_64)
     echo "TARGET_ARCH=x86_64" >> $config_mak
Makefile.target +23 -2
diff -ruN qemu.ORIG/Makefile.target qemu/Makefile.target
@@ -96,6 +96,12 @@
 ifeq ($(ARCH),i386)
 HELPER_CFLAGS+=-fomit-frame-pointer
 OP_CFLAGS+=-mpreferred-stack-boundary=2 -fomit-frame-pointer
+# OP_CFLAGS needs this on 32-bit x86 system to avoid
+# a compiler spill error. This can probably go away
+# once the SSE ops have been converted to TCG
+ifeq ($(HAVE_GT_GCC_3_3), true)
+MTUNE_CFLAGS=-march=i486 -mtune=i686
+endif
 endif
 
 ifeq ($(ARCH),ppc)
@@ -309,7 +315,7 @@
 	$(DYNGEN) -g -o $@ $<
 
 op.o: op.c
-	$(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $<
+	$(CC) $(OP_CFLAGS) $(CPPFLAGS) $(MTUNE_CFLAGS) -c -o $@ $<
 
 machine.o: machine.c
 	$(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $<
@@ -317,9 +323,24 @@
 # HELPER_CFLAGS is used for all the code compiled with static register
 # variables
 ifeq ($(TARGET_BASE_ARCH), i386)
+  # if current host is i386 and gcc >= -3.4, CFLAGS requires some
+  # handling as helper.c generates a compiler spill error if 
+  # "-march=i686 -mtune=i686" or -"march=athlon-xp -mtune=athlon-xp"
+  # We set MTUNE_CFLAGS="-march=i486 -mtune=i686" here
+  # Once SSE ops are converted to TCG, this can go away
+  HCFLAGS=$(CFLAGS)
+  ifeq ($(ARCH), i386)
+    ifeq ($(HAVE_GT_GCC_3_3), true)
+      # if CFLAGS has -march=i686, remove it so helper.o
+      # can compile on 32-bit intel systems
+      HCFLAGS=`echo $(CFLAGS) | sed 's,-march=i686,,' | sed 's,-mtune=i686,,' \
+        | sed 's,-march=athlon-xp,,' |  sed 's,-mtune=athlon-xp,,'`
+    endif
+  endif
+
 # XXX: rename helper.c to op_helper.c
 helper.o: helper.c
-	$(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+	$(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(MTUNE_CFLAGS) $(HCFLAGS) -c -o $@ $<
 else
 op_helper.o: op_helper.c
 	$(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
#2 lore raw
Quoted 41 lines · Ben Taylor
Quoted 10 lines · Ben Taylor

This patch applies some additional flags to op.c and helper.c
for compiling on i386 32-bit systems with gcc >= 3.4.

This has been tested on both ubuntu 7.10/32-bit and Solaris SXCE/32-bit with both gcc-3.3 and gcc-3.4 and the behavior is consistent between both.

This is just a short term fix til the SSE ops are converted to TCG.

I updated the patch to take care of -mtune options that might be set by --extra-cflags, as well as the -march flags. I added support for athlon-xp, as someone mentioned it in #qemu with the exact error that helper.c sees in this context, so I fixed it as I have an athlon-xp.

Ben

diff -ruN qemu.ORIG/configure qemu/configure

configure +7 -0
@@ -1199,6 +1199,13 @@
     then
       echo "#define USE_KQEMU 1" >> $config_h
     fi
+    gcc3minver=`$cc --version 2> /dev/null| fgrep "(GCC) 3." | awk '{ print $3 }' | cut -f2 -d.`
+    if test -n "$gcc3minver" -a $gcc3minver -gt 3
+    then
+      echo "HAVE_GT_GCC_3_3=true" >> $config_mak
+    else
+      echo "HAVE_GT_GCC_3_3=false" >> $config_mak
+    fi
   ;;
   x86_64)
     echo "TARGET_ARCH=x86_64" >> $config_mak

diff -ruN qemu.ORIG/Makefile.target qemu/Makefile.target

Makefile.target line 103

Quoted 8 lines
Makefile.target +5 -0
@@ -96,6 +96,12 @@
 ifeq ($(ARCH),i386)
 HELPER_CFLAGS+=-fomit-frame-pointer
 OP_CFLAGS+=-mpreferred-stack-boundary=2 -fomit-frame-pointer
+# OP_CFLAGS needs this on 32-bit x86 system to avoid
+# a compiler spill error. This can probably go away
+# once the SSE ops have been converted to TCG
+ifeq ($(HAVE_GT_GCC_3_3), true)
+MTUNE_CFLAGS=-march=i486 -mtune=i686

MTUNE is not really a good name, given it overrides both -mtune and -march. What about I386_CFLAGS?

Quoted 22 lines
Makefile.target +7 -1
+endif
 endif
 
 ifeq ($(ARCH),ppc)
@@ -309,7 +315,7 @@
 	$(DYNGEN) -g -o $@ $<
 
 op.o: op.c
-	$(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $<
+	$(CC) $(OP_CFLAGS) $(CPPFLAGS) $(MTUNE_CFLAGS) -c -o $@ $<
 
 machine.o: machine.c
 	$(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $<
@@ -317,9 +323,24 @@
 # HELPER_CFLAGS is used for all the code compiled with static register
 # variables
 ifeq ($(TARGET_BASE_ARCH), i386)
+  # if current host is i386 and gcc >= -3.4, CFLAGS requires some
+  # handling as helper.c generates a compiler spill error if 
+  # "-march=i686 -mtune=i686" or -"march=athlon-xp -mtune=athlon-xp"
+  # We set MTUNE_CFLAGS="-march=i486 -mtune=i686" here
+  # Once SSE ops are converted to TCG, this can go away

Makefile.target line 340

Quoted 10 lines
Makefile.target +10 -0
+  HCFLAGS=$(CFLAGS)
+  ifeq ($(ARCH), i386)
+    ifeq ($(HAVE_GT_GCC_3_3), true)
+      # if CFLAGS has -march=i686, remove it so helper.o
+      # can compile on 32-bit intel systems
+      HCFLAGS=`echo $(CFLAGS) | sed 's,-march=i686,,' | sed 's,-mtune=i686,,' \
+        | sed 's,-march=athlon-xp,,' |  sed 's,-mtune=athlon-xp,,'`
+    endif
+  endif
+

This part looks overcomplicated, and probably doesn't handle all cases. What's the point of trying to remove options from CFLAGS? Multiple -march or -mtune should be harmless, gcc should use the latest provided one. So just make sure MTUNE_CFLAGS or I386_CFLAGS is after CFLAGS.

Quoted 7 lines
Makefile.target +1 -1
 # XXX: rename helper.c to op_helper.c
 helper.o: helper.c
-	$(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+	$(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(MTUNE_CFLAGS) $(HCFLAGS) -c -o $@ $<
 else
 op_helper.o: op_helper.c
 	$(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net
author
#3 lore raw
Quoted 22 lines · Aurelien Jarno
Quoted 20 lines · Ben Taylor
Quoted 10 lines · Ben Taylor

This patch applies some additional flags to op.c and helper.c
for compiling on i386 32-bit systems with gcc >= 3.4.

This has been tested on both ubuntu 7.10/32-bit and Solaris SXCE/32-bit with both gcc-3.3 and gcc-3.4 and the behavior is consistent between both.

This is just a short term fix til the SSE ops are converted to TCG.

I updated the patch to take care of -mtune options that might be set by --extra-cflags, as well as the -march flags. I added support for athlon-xp, as someone mentioned it in #qemu with the exact error that helper.c sees in this context, so I fixed it as I have an athlon-xp.

Ben

Quoted 15 lines

Makefile.target 2008-05-04 20:58:47.000000000 -0400 line 103

Quoted 12 lines

diff -ruN qemu.ORIG/Makefile.target qemu/Makefile.target

Makefile.target 2008-05-04 20:58:47.000000000 -0400 renamed from Makefile.target 2008-05-04 17:21:08.000000000 -0400 +5 -0
@@ -96,6 +96,12 @@
 ifeq ($(ARCH),i386)
 HELPER_CFLAGS+=-fomit-frame-pointer
 OP_CFLAGS+=-mpreferred-stack-boundary=2 -fomit-frame-pointer
+# OP_CFLAGS needs this on 32-bit x86 system to avoid
+# a compiler spill error. This can probably go away
+# once the SSE ops have been converted to TCG
+ifeq ($(HAVE_GT_GCC_3_3), true)
+MTUNE_CFLAGS=-march=i486 -mtune=i686

MTUNE is not really a good name, given it overrides both -mtune and -march. What about I386_CFLAGS?

Done.

Quoted 25 lines
Quoted 25 lines
Makefile.target 2008-05-04 20:58:47.000000000 -0400 renamed from Makefile.target 2008-05-04 17:21:08.000000000 -0400 +13 -1
@@ -309,7 +315,7 @@
      $(DYNGEN) -g -o $@ $<
 
 op.o: op.c
-     $(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $<
+     $(CC) $(OP_CFLAGS) $(CPPFLAGS) $(MTUNE_CFLAGS) -c -o $@ $<
 
 machine.o: machine.c
      $(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $<
@@ -317,9 +323,24 @@
 # HELPER_CFLAGS is used for all the code compiled with static register
 # variables
 ifeq ($(TARGET_BASE_ARCH), i386)
+  # if current host is i386 and gcc >= -3.4, CFLAGS requires some
+  # handling as helper.c generates a compiler spill error if
+  # "-march=i686 -mtune=i686" or -"march=athlon-xp -mtune=athlon-xp"
+  # We set MTUNE_CFLAGS="-march=i486 -mtune=i686" here
+  # Once SSE ops are converted to TCG, this can go away
+  HCFLAGS=$(CFLAGS)
+  ifeq ($(ARCH), i386)
+    ifeq ($(HAVE_GT_GCC_3_3), true)
+      # if CFLAGS has -march=i686, remove it so helper.o
+      # can compile on 32-bit intel systems
+      HCFLAGS=`echo $(CFLAGS) | sed 's,-march=i686,,' | sed 's,-mtune=i686,,' \
+        | sed 's,-march=athlon-xp,,' |  sed 's,-mtune=athlon-xp,,'`
Quoted 8 lines

Makefile.target 2008-05-04 20:58:47.000000000 -0400 line 340

Quoted 3 lines
Makefile.target 2008-05-04 20:58:47.000000000 -0400 renamed from Makefile.target 2008-05-04 17:21:08.000000000 -0400 +3 -0
+    endif
+  endif
+

This part looks overcomplicated, and probably doesn't handle all cases. What's the point of trying to remove options from CFLAGS? Multiple -march or -mtune should be harmless, gcc should use the latest provided one. So just make sure MTUNE_CFLAGS or I386_CFLAGS is after CFLAGS.

Done. Because I had put the flags forward, they were getting over-riden by CFLAGS. Now it is much simpler and we don't care what the user puts in --extra-cflags.

Ben

configure +7 -0
diff -ruN qemu.ORIG/configure qemu/configure
@@ -1199,6 +1199,13 @@
     then
       echo "#define USE_KQEMU 1" >> $config_h
     fi
+    gcc3minver=`$cc --version 2> /dev/null| fgrep "(GCC) 3." | awk '{ print $3 }' | cut -f2 -d.`
+    if test -n "$gcc3minver" -a $gcc3minver -gt 3
+    then
+      echo "HAVE_GT_GCC_3_3=true" >> $config_mak
+    else
+      echo "HAVE_GT_GCC_3_3=false" >> $config_mak
+    fi
   ;;
   x86_64)
     echo "TARGET_ARCH=x86_64" >> $config_mak
Makefile.target +8 -2
diff -ruN qemu.ORIG/Makefile.target qemu/Makefile.target
@@ -96,6 +96,12 @@
 ifeq ($(ARCH),i386)
 HELPER_CFLAGS+=-fomit-frame-pointer
 OP_CFLAGS+=-mpreferred-stack-boundary=2 -fomit-frame-pointer
+# op.c and helper.c need this on 32-bit x86 system to avoid
+# a compiler spill error. This can probably go away
+# once the SSE ops have been converted to TCG
+ifeq ($(HAVE_GT_GCC_3_3), true)
+I386_CFLAGS=-march=i486 -mtune=i686
+endif
 endif
 
 ifeq ($(ARCH),ppc)
@@ -309,7 +315,7 @@
 	$(DYNGEN) -g -o $@ $<
 
 op.o: op.c
-	$(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $<
+	$(CC) $(OP_CFLAGS) $(CPPFLAGS) $(I386_CFLAGS) -c -o $@ $<
 
 machine.o: machine.c
 	$(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $<
@@ -319,7 +325,7 @@
 ifeq ($(TARGET_BASE_ARCH), i386)
 # XXX: rename helper.c to op_helper.c
 helper.o: helper.c
-	$(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+	$(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) $(I386_CFLAGS) -c -o $@ $<
 else
 op_helper.o: op_helper.c
 	$(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
#4 lore raw
In reply to Ben Taylor
Quoted 6 lines · Ben Taylor

This patch applies some additional flags to op.c and helper.c for compiling on i386 32-bit systems with gcc >= 3.4.

This has been tested on both ubuntu 7.10/32-bit and Solaris SXCE/32-bit with both gcc-3.3 and gcc-3.4 and the behavior is consistent between both.

These hacks are sufficient fickle, and gcc versions sufficiently meaningless[1], that I don't think we should do this. If you really want to fix this, do it properly and finish the TCG conversion.

Paul

[1] As with most open source software a version number does not uniquely identify a binary. In my experience pretty much noone uses unpatched FSF releases directly.