On Wed, Oct 29, 2008 at 10:00:16AM -0400, Chris Dukes wrote:
> Package: kqemu-source
> Version: 1.4.0~pre1-1
> Followup-For: Bug #494479
> 
> I ran into this last night attempting to build on a system
> using i386 as the architecture for packages, but an amd64 kernel.
> 
> There are two problems.
> 1) kqemu/common/Makefile incorrectly assumes in the %.o: %.S rule
> that gcc will automatically invoke use the correct -m## for $(ARCH)
> 2) kqemu/configure incorrectly assumes that ARCH should come from
> uname -m instead of the $(KSRC)/.config
> 
> I'll attempt to cobble together a patch later today and send it in.

And after too much kludgery I've given up for the day and forwarded
it off to the qemu developers.

Here's the improvement :-).
And attached is the kludge patch for anyone that wants to try to get further.

./configure --kernel-path=/lib/modules/2.6.26-1-amd64/build --cc=gcc-4.1 
--host-cc=gcc-4.1
CONFIG_X86_64=y
Source path       /usr/src/modules/kqemu
C compiler        gcc-4.1
Host C compiler   gcc-4.1
make              make
host CPU          x86_64

kernel sources    /lib/modules/2.6.26-1-amd64/build
kbuild type       2.6
/usr/bin/make
make[2]: Entering directory `/usr/src/modules/kqemu'
make -C common all
make[3]: Entering directory `/usr/src/modules/kqemu/common'
gcc -Wall -O2 -Werror -g -D__KERNEL__ -I.. -o genoffsets genoffsets.c
./genoffsets > monitor_def.h
gcc -m64 -march=k8 -D__KERNEL__ -nostdinc -iwithprefix include -I. -I.. 
-D__ASSEMBLY__ -c -o x86_64/nexus_asm.o x86_64/nexus_asm.S
gcc -m64 -march=k8 -D__KERNEL__ -nostdinc -iwithprefix include -I. -I.. 
-D__ASSEMBLY__ -c -o x86_64/monitor_asm.o x86_64/monitor_asm.S
gcc -m64 -march=k8 -Wall -O2 -fomit-frame-pointer -fno-strict-aliasing -Werror  
-mno-red-zone -fno-stack-protector    -fpic  -D__KERNEL__ -nostdinc 
-iwithprefix include -I. -I.. -c -o monitor.o monitor.c
gcc -m64 -march=k8 -Wall -O2 -fomit-frame-pointer -fno-strict-aliasing -Werror  
-mno-red-zone -fno-stack-protector    -fpic  -D__KERNEL__ -nostdinc 
-iwithprefix include -I. -I.. -c -o monitor-utils.o monitor-utils.c
gcc -m64 -march=k8 -Wall -O2 -fomit-frame-pointer -fno-strict-aliasing -Werror  
-mno-red-zone -fno-stack-protector    -fpic  -D__KERNEL__ -nostdinc 
-iwithprefix include -I. -I.. -c -o interp.o interp.c
ld -m elf_x86_64 -T x86_64/monitor.ld -o monitor-image.out x86_64/nexus_asm.o 
x86_64/monitor_asm.o monitor.o monitor-utils.o interp.o
x86_64/monitor_asm.o: In function `__monitor_exception':
(.text+0x68d): undefined reference to `KQEMU_STATE_monitor_ss_null_sel'
x86_64/monitor_asm.o: In function `exception_return':
(.text+0x6d3): undefined reference to `KQEMU_STATE_monitor_ss_null_sel'
x86_64/monitor_asm.o: In function `exception_return16':
(.text+0x776): undefined reference to `KQEMU_STATE_monitor_cs32_sel'
x86_64/monitor_asm.o: In function `__monitor_interrupt':
(.text+0x81c): undefined reference to `KQEMU_STATE_monitor_ss_null_sel'
make[3]: *** [monitor-image.out] Error 1
make[3]: Leaving directory `/usr/src/modules/kqemu/common'
make[2]: *** [kqemu.ko] Error 2
make[2]: Leaving directory `/usr/src/modules/kqemu'
make[1]: *** [binary-modules] Error 2
make[1]: Leaving directory `/usr/src/modules/kqemu'
make: *** [kdist_build] Error 2
diff -urwp kqemu.orig/common/Makefile kqemu/common/Makefile
--- kqemu.orig/common/Makefile	2008-09-14 09:40:51.000000000 -0400
+++ kqemu/common/Makefile	2008-10-29 11:32:38.000000000 -0400
@@ -28,8 +28,8 @@ cc-option = $(shell if test -z "`$(1) $(
               /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi  ;) 
 
 HOST_CC=gcc
-MON_CC=gcc
-MON_LD=ld
+MON_CC=$(CC)
+MON_LD=ld -m elf_$(ARCH)
 ifdef CONFIG_WIN32
 TARGET=../kqemu-mod-$(ARCH)-win32.o
 CC=i386-mingw32-gcc
@@ -116,10 +116,10 @@ genmon: genmon.c
 	$(HOST_CC) $(TOOLS_CFLAGS) -o $@ $<
 
 %.o: %.c
-	$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c -o $@ $<
+	$(CC) $(ASMMFLAG) $(CFLAGS) $(DEFINES) $(INCLUDES) -c -o $@ $<
 
 %.o: %.S
-	$(CC) $(DEFINES) $(INCLUDES) -D__ASSEMBLY__ -c -o $@ $<
+	$(CC) $(ASMMFLAG) $(DEFINES) $(INCLUDES) -D__ASSEMBLY__ -c -o $@ $<
 
 clean:
 	rm -f *.o *~ monitor-image.h genoffsets genmon monitor_def.h \
diff -urwp kqemu.orig/config-host.mak kqemu/config-host.mak
--- kqemu.orig/config-host.mak	2008-10-29 09:23:04.000000000 -0400
+++ kqemu/config-host.mak	2008-10-29 10:17:30.000000000 -0400
@@ -13,6 +13,7 @@ CFLAGS=-O2
 LDFLAGS=
 EXESUF=
 ARCH=i386
+ASMMFLAG=-m32
 KERNEL_PATH=/lib/modules/2.6.26-1-686/build
 CONFIG_KBUILD26=yes
 SRC_PATH=/usr/src/modules/kqemu
diff -urwp kqemu.orig/configure kqemu/configure
--- kqemu.orig/configure	2008-09-14 09:40:51.000000000 -0400
+++ kqemu/configure	2008-10-29 11:18:08.000000000 -0400
@@ -275,6 +275,19 @@ if test '!' -f "$kernel_path/Makefile" ;
     kqemu="no"
 fi
 
+if test "$kqemu" = "yes" ; then
+    if grep '^CONFIG_X86_64=y$' $kernel_path/.config; then
+        ARCH=x86_64
+        ASMMFLAG="-m64 -march=k8"
+    elif grep '^CONFIG_X86_32=y$' $kernel_path/.config; then
+        ARCH=i386
+        ASMMFLAG="-m32 -march=generic"
+    else
+        echo "This kernel lacks CONFIG_X86_64 and CONFIG_X86_32 - kqemu cannot be built"
+        kqemu="no"
+    fi
+fi
+
 # find build system (2.6 or legacy)
 kbuild26="yes"
 if grep -q "PATCHLEVEL = 4" $kernel_path/Makefile ; then
@@ -325,14 +338,16 @@ echo "STRIP=$strip -s -R .comment -R .no
 echo "CFLAGS=$CFLAGS" >> $config_mak
 echo "LDFLAGS=$LDFLAGS" >> $config_mak
 echo "EXESUF=$EXESUF" >> $config_mak
-if test "$cpu" = "i386" ; then
-  echo "ARCH=i386" >> $config_mak
-elif test "$cpu" = "x86_64" ; then
-  echo "ARCH=x86_64" >> $config_mak
-else
-  echo "Unsupported CPU"
-  exit 1
-fi
+#if test "$cpu" = "i386" ; then
+#  echo "ARCH=i386" >> $config_mak
+#elif test "$cpu" = "x86_64" ; then
+#  echo "ARCH=x86_64" >> $config_mak
+#else
+#  echo "Unsupported CPU"
+#  exit 1
+#fi
+echo "ARCH=$ARCH" >> $config_mak
+echo "ASMMFLAG=$ASMMFLAG" >> $config_mak
 if test "$bigendian" = "yes" ; then
   echo "WORDS_BIGENDIAN=yes" >> $config_mak
 fi
diff -urwp kqemu.orig/debian/rules kqemu/debian/rules
--- kqemu.orig/debian/rules	2008-09-14 09:40:53.000000000 -0400
+++ kqemu/debian/rules	2008-10-29 11:28:53.000000000 -0400
@@ -63,7 +63,7 @@ binary-modules: prep-deb-files
 	dh_clean -k
 
 	# Build the module
-	./configure --kernel-path=$(KSRC)
+	./configure --kernel-path=$(KSRC) --cc=$(CC) --host-cc=$(CC)
 	$(MAKE)
 
 	# Install the module

Reply via email to