diff mbox

Some OpenBSD/amd64 build fixes

Message ID 20090923203116.GF4859@overdrive.home.tratt.net
State Superseded
Headers show

Commit Message

Laurence Tratt Sept. 23, 2009, 8:31 p.m. UTC
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 blauwirbel@gmail.com 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

Comments

Juergen Lock Sept. 23, 2009, 8:55 p.m. UTC | #1
On Wed, Sep 23, 2009 at 09:31:16PM +0100, Laurence Tratt wrote:
> 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 blauwirbel@gmail.com 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.)

> 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",

 You mean --disable-bsd-user?

>  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.
> 
 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
diff mbox

Patch

diff --git a/x86_64.ld b/x86_64.ld
index 24ea77d..aeb0bce 100644
--- a/x86_64.ld
+++ b/x86_64.ld
@@ -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          :
   {
--- a/pc-bios/optionrom/signrom.sh
+++ b/pc-bios/optionrom/signrom.sh
@@ -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`