Skip to contentSkip to conversation

Some OpenBSD/amd64 build fixes

Qemu-devel In review Laurence Tratt 3 participants 5 messages Sep 23, 2009 – Oct 14, 2009

lore
Share & tools
lore
#0 lore raw

Dear all,

I've been trying to get the qemu in git to build on OpenBSD/amd64. It's not there yet, but I have made some progress. The first problem encountered is that x86_64.ld fails:

  $ gmake
    LINK  i386-bsd-user/qemu-i386
  /usr/bin/ld:/tmp/qemu/x86_64.ld:61: syntax error
  collect2: ld returned 1 exit status
  gmake[1]: *** [qemu-i386] Error 1
  gmake: *** [subdir-i386-bsd-user] Error 2
  $

One of the patches at the end of this e-mail fixes that by removing the ONLY_IF_RO parts that make it choke [thanks to [email protected] for the hint]. I don't honestly know the precise semantic effect ONLY_IF_RO has, but I'm assuming it's not critical.

Another problem I've patched is with signrom.sh which uses the -A option which isn't found in OpenBSD's od. I've hacked around that (inelegantly, I admit) in a way which I think should still preserve correct operation on other platforms (it works OK under Linux, at least).

Unfortunately there are still a couple of places that I'm stuck. Any help would be much appreciated, and I can provide an OpenBSD/amd64 account for anyone who's interested in playing further.

First, if I do a plain "./configure", the build dies as follows:

...

    AR    i386-bsd-user/libqemu.a
    LINK  i386-bsd-user/qemu-i386

libqemu.a(i386-dis.o)(.text+0x19af): In function `oappend':
/home/ltratt/qemu/i386-dis.c:4656: warning: strcpy() is almost always misused, please use strlcpy() main.o(.text+0x5fc): In function `main':
/home/ltratt/qemu/bsd-user/main.c:911: undefined reference to guest_base' main.o(.text+0x740):/home/ltratt/qemu/bsd-user/main.c:941: undefined reference to guest_base' bsdload.o(.text+0x31): In function `memcpy_to_target':
/home/ltratt/qemu/bsd-user/qemu.h:331: undefined reference to guest_base' bsdload.o(.text+0x230): In function loader_build_argptr':
/home/ltratt/qemu/bsd-user/qemu.h:331: undefined reference to guest_base' bsdload.o(.text+0x262):/home/ltratt/qemu/bsd-user/qemu.h:331: undefined reference to guest_base' bsdload.o(.text+0x2a1):/home/ltratt/qemu/bsd-user/qemu.h:331: more undefined references to `guest_base' follow
collect2: ld returned 1 exit status
gmake[1]: *** [qemu-i386] Error 1
gmake: *** [subdir-i386-bsd-user] Error 2
$

I haven't yet investigated this in depth. If I do "./configure -disable-guest", then the above error doesn't occur, but pc-bios/optionrom/multiboot.S dies as follows:

$
AS optionrom/multiboot.o
multiboot.S: Assembler messages:
multiboot.S:116: Error: `%es:-4(%edi)' is not a valid 16 bit base/index
expression
$

What little Intel assembler I ever knew has long since departed from my brain, so I don't know why that error occurs, nor what a fix might be.

Laurie

Signature · 4 lines
http://tratt.net/laurie/ -- Personal
http://fetegeo.org/      -- Free text geocoding
http://convergepl.org/   -- The Converge programming language
http://www.model-transformation.org/ICMT2010/ -- ICMT 2010
x86_64.ld +4 -4
index 24ea77d..aeb0bce 100644
@@ -58,8 +58,8 @@ SECTIONS
   .rodata         : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
   .rodata1        : { *(.rodata1) }
   .eh_frame_hdr : { *(.eh_frame_hdr) }
-  .eh_frame       : ONLY_IF_RO { KEEP (*(.eh_frame)) }
-  .gcc_except_table   : ONLY_IF_RO { *(.gcc_except_table) }
+  .eh_frame       : { KEEP (*(.eh_frame)) }
+  .gcc_except_table   : { *(.gcc_except_table) }
   /* Adjust the address for the data segment.  We want to adjust up to
      the same address within the page on the next page up.  */
   . = ALIGN (0x100000) - ((0x100000 - .) & (0x100000 - 1)); . = DATA_SEGMENT_ALIGN (0x100000, 0x1000);
@@ -85,8 +85,8 @@ SECTIONS
   .data1          : { *(.data1) }
   .tdata	  : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
   .tbss		  : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
-  .eh_frame       : ONLY_IF_RW { KEEP (*(.eh_frame)) }
-  .gcc_except_table   : ONLY_IF_RW { *(.gcc_except_table) }
+  .eh_frame       : { KEEP (*(.eh_frame)) }
+  .gcc_except_table   : { *(.gcc_except_table) }
   .dynamic        : { *(.dynamic) }
   .ctors          :
   {
pc-bios/optionrom/signrom.sh +6 -2
@@ -26,12 +26,16 @@ test "$1" -a "$2" || exit 1
 sum=0
 
 # find out the file size
-x=`dd if="$1" bs=1 count=1 skip=2 2>/dev/null | od -t u1 -A n`
+tmp=`mktemp`
+dd if="$1" bs=1 count=1 skip=2 2>/dev/null > $tmp
+x=`od -v -t u1 $tmp | head -n 1 | cut -d " " -f 2- | sed "s/ //g" | sed "s/^0*//g"`
+rm $tmp
 #size=`expr $x \* 512 - 1`
 size=$(( $x * 512 - 1 ))
 
 # now get the checksum
-nums=`od -A n -t u1 -v "$1"`
+num_lines=`od -v -t u1 "$1" | wc -l`
+nums=`od -v -t u1 "$1" | head -n $(( num_lines - 1 ))  | cut -d " " -f 2-`
 for i in ${nums}; do
     # add each byte's value to sum
     sum=`expr $sum + $i`
x86_64.ld +0 -0
index 24ea77d..aeb0bce 100644
#1 lore raw
Quoted 14 lines · Laurence Tratt

Dear all,

I've been trying to get the qemu in git to build on OpenBSD/amd64. It's not there yet, but I have made some progress. The first problem encountered is that x86_64.ld fails:

  $ gmake
    LINK  i386-bsd-user/qemu-i386
  /usr/bin/ld:/tmp/qemu/x86_64.ld:61: syntax error
  collect2: ld returned 1 exit status
  gmake[1]: *** [qemu-i386] Error 1
  gmake: *** [subdir-i386-bsd-user] Error 2
  $
Quoted 5 lines

One of the patches at the end of this e-mail fixes that by removing the ONLY_IF_RO parts that make it choke [thanks to [email protected] for the hint]. I don't honestly know the precise semantic effect ONLY_IF_RO has, but I'm assuming it's not critical.

Yup, I've had this on FreeBSD as well (and came up with practically the same workaround.)

Quoted 31 lines

Another problem I've patched is with signrom.sh which uses the -A option which isn't found in OpenBSD's od. I've hacked around that (inelegantly, I admit) in a way which I think should still preserve correct operation on other platforms (it works OK under Linux, at least).

Unfortunately there are still a couple of places that I'm stuck. Any help would be much appreciated, and I can provide an OpenBSD/amd64 account for anyone who's interested in playing further.

First, if I do a plain "./configure", the build dies as follows:

...

    AR    i386-bsd-user/libqemu.a
    LINK  i386-bsd-user/qemu-i386

libqemu.a(i386-dis.o)(.text+0x19af): In function `oappend':
/home/ltratt/qemu/i386-dis.c:4656: warning: strcpy() is almost always misused, please use strlcpy() main.o(.text+0x5fc): In function `main':
/home/ltratt/qemu/bsd-user/main.c:911: undefined reference to guest_base' main.o(.text+0x740):/home/ltratt/qemu/bsd-user/main.c:941: undefined reference to guest_base' bsdload.o(.text+0x31): In function `memcpy_to_target':
/home/ltratt/qemu/bsd-user/qemu.h:331: undefined reference to guest_base' bsdload.o(.text+0x230): In function loader_build_argptr':
/home/ltratt/qemu/bsd-user/qemu.h:331: undefined reference to guest_base' bsdload.o(.text+0x262):/home/ltratt/qemu/bsd-user/qemu.h:331: undefined reference to guest_base' bsdload.o(.text+0x2a1):/home/ltratt/qemu/bsd-user/qemu.h:331: more undefined references to `guest_base' follow
collect2: ld returned 1 exit status
gmake[1]: *** [qemu-i386] Error 1
gmake: *** [subdir-i386-bsd-user] Error 2
$

Quoted 2 lines

I haven't yet investigated this in depth. If I do "./configure -disable-guest",

You mean --disable-bsd-user?

Quoted 10 lines

then the above error doesn't occur, but
pc-bios/optionrom/multiboot.S dies as follows:

$
AS optionrom/multiboot.o
multiboot.S: Assembler messages:
multiboot.S:116: Error: `%es:-4(%edi)' is not a valid 16 bit base/index
expression
$

Quoted 3 lines

What little Intel assembler I ever knew has long since departed from my brain, so I don't know why that error occurs, nor what a fix might be.

It occurs because of too old binutils (as(1) in this case), on FreeBSD
we now have a port for newer ones,
http://www.freshports.org/devel/binutils
so I depend on that and have the optionrom Makefile use the new as like this: (the first change wrt CFLAGS is unrelated and has probably been fixed in the meantime; it caused gmake to complain about recursive use of CFLAGS.)

Index: qemu/pc-bios/optionrom/Makefile
@@ -9,10 +9,13 @@

CFLAGS = -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin CFLAGS += -I$(SRC_PATH)
-CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector,"") +CFLAGS := $(CFLAGS) $(call cc-option, $(CFLAGS), -fno-stack-protector,"")

build-all: multiboot.bin

+%.o: %.S
+ $(CC) -E $(CFLAGS) -o - -c $< |${LOCALBASE}/bin/as -V -Qy -o $@
+
%.img: %.o
$(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<," Building $(TARGET_DIR)$@")

HTH,
Juergen

#2 lore raw

PATCH 1/1 multiboot.S patch for old as(1) (was: Re: [Qemu-devel] Some OpenBSD/amd64 build fixes)

Quoted 29 lines · Juergen Lock

On Wed, Sep 23, 2009 at 09:31:16PM +0100, Laurence Tratt wrote:
[...]

Quoted 10 lines

then the above error doesn't occur, but
pc-bios/optionrom/multiboot.S dies as follows:

$
AS optionrom/multiboot.o
multiboot.S: Assembler messages:
multiboot.S:116: Error: `%es:-4(%edi)' is not a valid 16 bit base/index
expression
$

Quoted 3 lines

What little Intel assembler I ever knew has long since departed from my brain, so I don't know why that error occurs, nor what a fix might be.

It occurs because of too old binutils (as(1) in this case), on FreeBSD
we now have a port for newer ones,
http://www.freshports.org/devel/binutils
so I depend on that and have the optionrom Makefile use the new as like this: (the first change wrt CFLAGS is unrelated and has probably been fixed in the meantime; it caused gmake to complain about recursive use of CFLAGS.)

Index: qemu/pc-bios/optionrom/Makefile

(quoted diff) +0 -1
@@ -9,10 +9,13 @@
 
 CFLAGS = -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin
 CFLAGS += -I$(SRC_PATH)
-CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector,"")

Review line 21

Quoted 10 lines
(quoted diff) +4 -0
+CFLAGS := $(CFLAGS) $(call cc-option, $(CFLAGS), -fno-stack-protector,"")
 
 build-all: multiboot.bin
 
+%.o: %.S
+	$(CC) -E $(CFLAGS) -o - -c $< |${LOCALBASE}/bin/as -V -Qy -o $@
+
 %.img: %.o
 	$(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
 

That patch didn't seem to help on OpenBSD so I now finally got around making another one that just emits the bytes of the offending insn instead so people can keep using old assemblers:

pc-bios/optionrom/multiboot.S +3 -0
@@ -113,7 +113,10 @@ mmap_loop:
 	/* entry size (mmap struct) & max buffer size (int15) */
 	movl		$20, %ecx
 	/* store entry size */
+	/* old as(1) doesn't like this insn so emit the bytes instead:
 	movl		%ecx, %es:-4(%edi)
+	*/
+	.dc.b		0x26,0x67,0x66,0x89,0x4f,0xfc
 	/* e820 */
 	movl		$0x0000e820, %eax
 	/* 'SMAP' magic */
#3 lore raw

[Qemu-devel] Re: [PATCH] multiboot.S patch for old as(1)

pc-bios/optionrom/multiboot.S mmap_loop: · line 119

Quoted 1 line · Juergen Lock
pc-bios/optionrom/multiboot.S +1 -0
+	.dc.b		0x26,0x67,0x66,0x89,0x4f,0xfc

If anything, this would be easier to read:

	.dc.b		0x26		/* %es: prefix for old as(1) */
	movl		%ecx, -4(%edi)

Paolo

#4 lore raw

[Qemu-devel] Re: [PATCH] multiboot.S patch for old as(1)

Quoted 8 lines · Paolo Bonzini

pc-bios/optionrom/multiboot.S mmap_loop: · line 119

Quoted 1 line · Juergen Lock
pc-bios/optionrom/multiboot.S +1 -0
+	.dc.b		0x26,0x67,0x66,0x89,0x4f,0xfc

If anything, this would be easier to read:

	.dc.b		0x26		/* %es: prefix for old as(1) */
	movl		%ecx, -4(%edi)

I like the idea, but unfortunately old as (2.15) doesnt, it still says:
Error: `-4(%edi)' is not a valid 16 bit base/index expression

:(,
Juergen