diff mbox

[PULL,00/31] Misc changes for 2016-05-27

Message ID 20160527133858.GR1683@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Richard W.M. Jones May 27, 2016, 1:38 p.m. UTC
On Fri, May 27, 2016 at 02:04:52PM +0100, Peter Maydell wrote:
> With V=1:
> 
> i686-w64-mingw32-ld -m i386pe -Ttext 0 -e _start -s -o
> linuxboot_dma.img linuxboot_dma.o
> linuxboot_dma.o:linuxboot_dma.c:(.text+0x57): undefined reference to
> `load_kernel'
> 
> Building an image for the target using our host compiler seems like
> an odd choice,

Which compiler should I be using?

> but the makefile obviously intends to support it
> since it has specific ifdef CONFIG_WIN32 code to adjust the linker
> command line.
>
> I suspect this is a mismatch between the symbol the native asm is
> using and the one that the C compiler wants:
> 
> $ nm build/w32-new/pc-bios/optionrom/linuxboot_dma.o |grep load_kernel
> 000005dd T _load_kernel
>          U load_kernel
> 
> since name mangling rules are different for Linux and Windows ABIs.

One way to solve this (which works for me) is as below.  There are
some other approaches, eg. using -fno-leading-underscore, or using a
conditional macro to mangle the name.  However I have no idea if there
is some preferred way.

Rich.

Comments

Peter Maydell May 27, 2016, 2:04 p.m. UTC | #1
On 27 May 2016 at 14:38, Richard W.M. Jones <rjones@redhat.com> wrote:
> On Fri, May 27, 2016 at 02:04:52PM +0100, Peter Maydell wrote:
>> With V=1:
>>
>> i686-w64-mingw32-ld -m i386pe -Ttext 0 -e _start -s -o
>> linuxboot_dma.img linuxboot_dma.o
>> linuxboot_dma.o:linuxboot_dma.c:(.text+0x57): undefined reference to
>> `load_kernel'
>>
>> Building an image for the target using our host compiler seems like
>> an odd choice,
>
> Which compiler should I be using?

I would have expected that how we build a guest image ought to
be the same regardless of how we're building QEMU itself.
(You wouldn't try to build an i386 image with $(CC) if you're
on an ARM host, for instance.)
However, given that the makefile already works this way, better
to go with the flow...

thanks
-- PMM
Paolo Bonzini May 27, 2016, 2:07 p.m. UTC | #2
On 27/05/2016 16:04, Peter Maydell wrote:
> > > i686-w64-mingw32-ld -m i386pe -Ttext 0 -e _start -s -o
> > > linuxboot_dma.img linuxboot_dma.o
> > > linuxboot_dma.o:linuxboot_dma.c:(.text+0x57): undefined reference to
> > > `load_kernel'
> > >
> > > Building an image for the target using our host compiler seems like
> > > an odd choice,
> >
> > Which compiler should I be using?
>
> I would have expected that how we build a guest image ought to
> be the same regardless of how we're building QEMU itself.
> (You wouldn't try to build an i386 image with $(CC) if you're
> on an ARM host, for instance.)
> However, given that the makefile already works this way, better
> to go with the flow...

Yeah, however currently the ROMs are only built if you are not doing a
cross build.

Thanks,

Paolo
Richard W.M. Jones May 27, 2016, 2:11 p.m. UTC | #3
On Fri, May 27, 2016 at 04:06:07PM +0200, Paolo Bonzini wrote:
> 
> 
> On 27/05/2016 15:38, Richard W.M. Jones wrote:
> > One way to solve this (which works for me) is as below.  There are
> > some other approaches, eg. using -fno-leading-underscore, or using a
> > conditional macro to mangle the name.  However I have no idea if there
> > is some preferred way.
> > 
> > Rich.
> > 
> > diff --git a/pc-bios/optionrom/linuxboot_dma.c b/pc-bios/optionrom/linuxboot_dma.c
> > index 86ef1ce..8509b28 100644
> > --- a/pc-bios/optionrom/linuxboot_dma.c
> > +++ b/pc-bios/optionrom/linuxboot_dma.c
> > @@ -213,6 +213,9 @@ static uint32_t get_e801_addr(void)
> >      return ret;
> >  }
> >  
> > +/* Force the asm name without leading underscore, even on Win32. */
> > +extern void load_kernel(void) asm("load_kernel");
> > +
> >  void load_kernel(void)
> >  {
> >      void *setup_addr;
> 
> Yes, that's what I wanted to do.  I also need
> 
> diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
> index 2b11cd3..14e7f71 100644
> --- a/pc-bios/optionrom/Makefile
> +++ b/pc-bios/optionrom/Makefile
> @@ -31,6 +31,7 @@ build-all: multiboot.bin linuxboot.bin
> linuxboot_dma.bin kvmvapic.bin
> 
>  ifdef CONFIG_WIN32
>  LD_EMULATION = i386pe
> +CFLAGS += -Wa,-32
>  else
>  LD_EMULATION = elf_i386
>  endif
> 
> to work around what is likely a GCC bug.

OK I don't need that with mingw32-gcc-6.1.0-1.fc24.x86_64, but on the
other hand it doesn't negatively affect builds for me either.  Next
version coming up soon.

Rich.
diff mbox

Patch

diff --git a/pc-bios/optionrom/linuxboot_dma.c b/pc-bios/optionrom/linuxboot_dma.c
index 86ef1ce..8509b28 100644
--- a/pc-bios/optionrom/linuxboot_dma.c
+++ b/pc-bios/optionrom/linuxboot_dma.c
@@ -213,6 +213,9 @@  static uint32_t get_e801_addr(void)
     return ret;
 }
 
+/* Force the asm name without leading underscore, even on Win32. */
+extern void load_kernel(void) asm("load_kernel");
+
 void load_kernel(void)
 {
     void *setup_addr;