Skip to contentSkip to conversation

MINGW: Unable to link multiboot.img + strnlen missing

Qemu-devel In review Bartlomiej Celary 5 participants 9 messages Jul 1, 2009 – Jul 10, 2009

lore
Share & tools
lore
#0 lore raw

Hi,
I have recently updated my git snapshot and had 2 problems:

1. There is no strnlen function in MINGW (not sure if it has been added recently as I might be using an outdated version...)

2. I was not able to link multiboot.bin using mingw:

for d in pc-bios/optionrom; do \
make -C $d || exit 1 ; \
done
make[1]: Entering directory `/home/abc024/work/qemu/pc-bios/optionrom' gcc -o signrom -g -Wall signrom.c
gcc -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin -I/home/abc024/work/qemu -o multiboot.o -c multiboot.S ld --oformat binary -Ttext 0 -o multiboot.img multiboot.o D:\mingw\bin\ld.exe: cannot perform PE operations on non PE output file 'multiboot.img'.
make[1]: *** [multiboot.img] Error 1
rm multiboot.o
make[1]: Leaving directory `/home/abc024/work/qemu/pc-bios/optionrom'
make: *** [roms] Error 1

And it looks that this workaround did the trick:

pc-bios/optionrom/Makefile +5 -2
old mode 100644
new mode 100755
index c4a6f42..f414eba
@@ -34,8 +34,14 @@ build-all: multiboot.bin
 %.o: %.S
        $(CC) $(CFLAGS) -o $@ -c $<
 
-%.img: %.o
-       $(LD) --oformat binary -Ttext 0 -o $@ $<
+%.img: %.out
+       $(OBJCOPY) -O binary -j .text $< $@
+
+%.out: %.o
+       $(LD) -Ttext 0 -e _start -s -o $@ $<
 
 %.bin: %.img signrom
        ./signrom $< $@

Obviously objcopy needs to be defined in the config.mak file.

Regards,
Bartek Celary

#1 lore raw
Quoted 3 lines · Bartlomiej Celary

Hi,
I have recently updated my git snapshot and had 2 problems:

Thanks for the report.

Quoted 3 lines

1. There is no strnlen function in MINGW (not sure if it has been added recently as I might be using an outdated version...)

That should be easy enough to fix. Can you send a patch?

Quoted 40 lines

2. I was not able to link multiboot.bin using mingw:

for d in pc-bios/optionrom; do \
make -C $d || exit 1 ; \
done
make[1]: Entering directory `/home/abc024/work/qemu/pc-bios/optionrom' gcc -o signrom -g -Wall signrom.c
gcc -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin -I/home/abc024/work/qemu -o multiboot.o -c multiboot.S ld --oformat binary -Ttext 0 -o multiboot.img multiboot.o D:\mingw\bin\ld.exe: cannot perform PE operations on non PE output file 'multiboot.img'.
make[1]: *** [multiboot.img] Error 1
rm multiboot.o
make[1]: Leaving directory `/home/abc024/work/qemu/pc-bios/optionrom'
make: *** [roms] Error 1

And it looks that this workaround did the trick:

pc-bios/optionrom/Makefile +5 -2
old mode 100644
new mode 100755
index c4a6f42..f414eba
@@ -34,8 +34,14 @@ build-all: multiboot.bin
 %.o: %.S
        $(CC) $(CFLAGS) -o $@ -c $<
 
-%.img: %.o
-       $(LD) --oformat binary -Ttext 0 -o $@ $<
+%.img: %.out
+       $(OBJCOPY) -O binary -j .text $< $@
+
+%.out: %.o
+       $(LD) -Ttext 0 -e _start -s -o $@ $<
 
 %.bin: %.img signrom
        ./signrom $< $@
Quoted 2 lines

Obviously objcopy needs to be defined in the config.mak file.

I'm not sure I understand why this works, but if you resubmit the patch with a Signed-off-by, we can apply it.

It's unfortunate that we need to do the signrom step now that I think about it as it's bad for cross-compilation. Maybe we should sign anything without a checksum when doing option rom loading. What do you think Alex?

Regards,

Anthony Liguori

Quoted 5 lines

Regards,
Bartek Celary

#2 lore raw
Quoted 53 lines · Anthony Liguori
Quoted 3 lines · Bartlomiej Celary

Hi,
I have recently updated my git snapshot and had 2 problems:

Thanks for the report.

Quoted 3 lines

1. There is no strnlen function in MINGW (not sure if it has been added recently as I might be using an outdated version...)

That should be easy enough to fix. Can you send a patch?

Quoted 40 lines

2. I was not able to link multiboot.bin using mingw:

for d in pc-bios/optionrom; do \
make -C $d || exit 1 ; \
done
make[1]: Entering directory `/home/abc024/work/qemu/pc-bios/optionrom' gcc -o signrom -g -Wall signrom.c
gcc -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin -I/home/abc024/work/qemu -o multiboot.o -c multiboot.S ld --oformat binary -Ttext 0 -o multiboot.img multiboot.o D:\mingw\bin\ld.exe: cannot perform PE operations on non PE output file 'multiboot.img'.
make[1]: *** [multiboot.img] Error 1
rm multiboot.o
make[1]: Leaving directory `/home/abc024/work/qemu/pc-bios/optionrom'
make: *** [roms] Error 1

And it looks that this workaround did the trick:

pc-bios/optionrom/Makefile +0 -0
old mode 100644
new mode 100755
index c4a6f42..f414eba
@@ -34,8 +34,14 @@ build-all: multiboot.bin

%.o: %.S

       $(CC) $(CFLAGS) -o $@ -c $<

-%.img: %.o

pc-bios/optionrom/Makefile +5 -1
-       $(LD) --oformat binary -Ttext 0 -o $@ $<
+%.img: %.out
+       $(OBJCOPY) -O binary -j .text $< $@
+
+%.out: %.o
+       $(LD) -Ttext 0 -e _start -s -o $@ $<

%.bin: %.img signrom

       ./signrom $< $@
Quoted 6 lines
Quoted 2 lines

Obviously objcopy needs to be defined in the config.mak file.

I'm not sure I understand why this works, but if you resubmit the patch with a Signed-off-by, we can apply it.

It's unfortunate that we need to do the signrom step now that I think about it as it's bad for cross-compilation. Maybe we should sign anything without a checksum when doing option rom loading. What do you think Alex?

Why can't we just exclude mingw from building option roms? Let's just treat it like any non-x86 platform, so it takes the binary blobs.

Alex

#3 lore raw
Quoted 1 line · Alexander Graf

Why can't we just exclude mingw from building option roms? Let's just treat it like any non-x86 platform, so it takes the binary blobs.

The signrom problem is independent on mingw32. This makefile is doing something that the rest of the build system is careful not to do: compile a binary and run it as part of the build process.

That's why hxtool is not written in C.

Regards,

Anthony Liguori

Quoted 2 lines

Alex

#4 lore raw
Quoted 6 lines · Anthony Liguori
Quoted 1 line · Alexander Graf

Why can't we just exclude mingw from building option roms? Let's just treat it like any non-x86 platform, so it takes the binary blobs.

The signrom problem is independent on mingw32. This makefile is doing something that the rest of the build system is careful not to do: compile a binary and run it as part of the build process.

That's why hxtool is not written in C.

Well, the optionrom directory is a first of its kind: Full source to a binary blob. So would you prefer to have signrom be in sh? :-)

Maybe I could come up with a version in brainfuck though ... hum

Alex

#5 lore raw

Hi,
Just tried latest pull from git and noticed the "cannot perform PE operations on non PE output file 'multiboot.img'." error.

Is there any agreement on how to fix the linker issue under mingw?

Thanks,
Bartek Celary

2009/7/1 Alexander Graf <[email protected]>:

Quoted 23 lines · Anthony Liguori
Quoted 11 lines
Quoted 3 lines · Alexander Graf

Why can't we just exclude mingw from building option roms? Let's just treat it like any non-x86 platform, so it takes the binary blobs.

The signrom problem is independent on mingw32.  This makefile is doing something that the rest of the build system is careful not to do: compile a binary and run it as part of the build process.

That's why hxtool is not written in C.

Well, the optionrom directory is a first of its kind: Full source to a binary blob.
So would you prefer to have signrom be in sh? :-)

Maybe I could come up with a version in brainfuck though ... hum

Alex

#6 lore raw
Quoted 4 lines · Bartlomiej Celary

Hi,
Just tried latest pull from git and noticed the "cannot perform PE operations on non PE output file 'multiboot.img'." error.

Someone posted a snippet in a thread but I can't find it. If someone posts a top level patch, I'll apply it.

Regards,

Anthony Liguori

Quoted 31 lines

Is there any agreement on how to fix the linker issue under mingw?

Thanks,
Bartek Celary

2009/7/1 Alexander Graf <[email protected]>:

Quoted 24 lines · Anthony Liguori
Quoted 4 lines

Alexander Graf wrote:

Quoted 9 lines
Quoted 3 lines

Why can't we just exclude mingw from building option roms? Let's just treat it like any non-x86 platform, so it takes the binary blobs.

The signrom problem is independent on mingw32. This makefile is doing something that the rest of the build system is careful not to do: compile a binary and run it as part of the build process.

That's why hxtool is not written in C.

Well, the optionrom directory is a first of its kind: Full source to a binary blob.
So would you prefer to have signrom be in sh? :-)

Maybe I could come up with a version in brainfuck though ... hum

Alex

#7 lore raw

PATCH 1/1 Win32: Fix build (no strnlen)

In reply to Anthony Liguori

strnlen is a GNU extension which is missing in mingw32 and perhaps other build environments.

So we should avoid it and replace it by standard functions.

---
 block.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
block.c +6 -1
index c66c031..79b3313 100644
@@ -225,9 +225,14 @@ static BlockDriver *find_protocol(const char *filename)
 {
     BlockDriver *drv1;
     char protocol[128];
-    int len = strnlen(filename, 127)+1;
+    int len;
     const char *p;
 
+    len = strlen(filename) + 1;
+    if (len > sizeof(protocol)) {
+      len = sizeof(protocol);
+    }
+
 #ifdef _WIN32
     if (is_windows_drive(filename) ||
         is_windows_drive_prefix(filename))
Signature · 1 line
1.5.6.5
#8 lore raw

[Qemu-devel] Re: [PATCH] Win32: Fix build (no strnlen)

Quoted 20 lines · Stefan Weil

strnlen is a GNU extension which is missing in mingw32 and perhaps other build environments.

So we should avoid it and replace it by standard functions.

---
 block.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
block.c +1 -1
index c66c031..79b3313 100644
@@ -225,9 +225,14 @@ static BlockDriver *find_protocol(const char *filename)
 {
     BlockDriver *drv1;
     char protocol[128];
-    int len = strnlen(filename, 127)+1;
+    int len;

block.c static BlockDriver *find_protocol(const char *filename) · line 238

Quoted 10 lines
block.c +5 -0
     const char *p;
 
+    len = strlen(filename) + 1;
+    if (len > sizeof(protocol)) {
+      len = sizeof(protocol);
+    }
+
 #ifdef _WIN32
     if (is_windows_drive(filename) ||
         is_windows_drive_prefix(filename))

Or something like this?
#ifdef __MINGW32__
size_t strnlen (const char *string, size_t maxlen) {
const char *end = memchr (string, '\0', maxlen); return end ? (size_t) (end - string) : maxlen;
};
#endif