Skip to contentSkip to conversation

pc-bios/optionrom: Fix OpenBSD build with better detection of linker emulation

PATCH In review Peter Maydell 4 participants 10 messages Aug 8, 2016 – Aug 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pc-bios/optionrom: Fix OpenBSD build with better detection of linker emulation

The various host OSes are irritatingly variable about the name of the linker emulation we need to pass to ld's -m option to build the i386 option ROMs. Instead of doing this via a CONFIG ifdef, check in configure whether any of the emulation names we know about will work and pass the right answer through to the makefile. If we can't find one, we fall back to not trying to build the option ROMs, in the same way we would for a non-x86 host platform.

This is in particular necessary to unbreak the build on OpenBSD, since it wants a different answer to FreeBSD and we don't have an existing CONFIG_ variable that distinguishes the two.

---
This works for Linux and for the Windows builds; I don't have any BSD systems to test it on. Brad and Sean, can I ask you to test this on OpenBSD and FreeBSD, please?

(I think this is going to miss -rc2. Sorry about that; we'll get OpenBSD builds fixed for -rc3.)

 configure                  | 12 +++++++++++-
 pc-bios/optionrom/Makefile | 12 +-----------
 2 files changed, 12 insertions(+), 12 deletions(-)
configure +11 -1
index f57fcc6..7c744ad 100755
@@ -4699,7 +4699,16 @@ roms=
 if test \( "$cpu" = "i386" -o "$cpu" = "x86_64" \) -a \
         "$targetos" != "Darwin" -a "$targetos" != "SunOS" -a \
         "$softmmu" = yes ; then
-  roms="optionrom"
+    # Different host OS linkers have different ideas about the name of the ELF
+    # emulation. Linux and OpenBSD use 'elf_i386'; FreeBSD uses the _fbsd
+    # variant; and Windows uses i386pe.
+    for emu in elf_i386 elf_i386_fbsd i386pe; do
+        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
+            ld_i386_emulation="$emu"
+            roms="optionrom"
+            break
+        fi
+    done
 fi
 if test "$cpu" = "ppc64" -a "$targetos" != "Darwin" ; then
   roms="$roms spapr-rtas"
@@ -5539,6 +5548,7 @@ fi
 echo "LDFLAGS=$LDFLAGS" >> $config_host_mak
 echo "LDFLAGS_NOPIE=$LDFLAGS_NOPIE" >> $config_host_mak
 echo "LD_REL_FLAGS=$LD_REL_FLAGS" >> $config_host_mak
+echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
 echo "LIBS+=$LIBS" >> $config_host_mak
 echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
 echo "PTHREAD_LIB=$PTHREAD_LIB" >> $config_host_mak
pc-bios/optionrom/Makefile +1 -11
index 24e175e..5bbe233 100644
@@ -41,18 +41,8 @@ build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin
 %.o: %.S
 	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"  AS    $(TARGET_DIR)$@")
 
-ifdef CONFIG_WIN32
-LD_EMULATION = i386pe
-else
-ifdef CONFIG_BSD
-LD_EMULATION = elf_i386_fbsd
-else
-LD_EMULATION = elf_i386
-endif
-endif
-
 %.img: %.o
-	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_EMULATION) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
+	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_I386_EMULATION) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
 
 %.raw: %.img
 	$(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"  Building $(TARGET_DIR)$@")
Signature · 1 line
2.7.4
#1 lore raw
Quoted 13 lines · Peter Maydell

The various host OSes are irritatingly variable about the name of the linker emulation we need to pass to ld's -m option to build the i386 option ROMs. Instead of doing this via a CONFIG ifdef, check in configure whether any of the emulation names we know about will work and pass the right answer through to the makefile. If we can't find one, we fall back to not trying to build the option ROMs, in the same way we would for a non-x86 host platform.

This is in particular necessary to unbreak the build on OpenBSD, since it wants a different answer to FreeBSD and we don't have an existing CONFIG_ variable that distinguishes the two.

Quoted 8 lines

---
This works for Linux and for the Windows builds; I don't have any BSD systems to test it on. Brad and Sean, can I ask you to test this on OpenBSD and FreeBSD, please?

(I think this is going to miss -rc2. Sorry about that; we'll get OpenBSD builds fixed for -rc3.)

PS: if you would like your BSD flavour promoted to "we don't merge changes that break the build on it" I would need to have ssh access to a machine I can run builds and tests on. (Unfortunately the only BSD in the gcc compile farm is an ancient NetBSD.)

thanks
-- PMM

#2 lore raw
Quoted 5 lines · Peter Maydell

PS: if you would like your BSD flavour promoted to "we don't merge changes that break the build on it" I would need to have ssh access to a machine I can run builds and tests on. (Unfortunately the only BSD in the gcc compile farm is an ancient NetBSD.)

For the purpose of "not breaking the build", having a docker image for a cross compiler would also be enough.

Paolo

#3 lore raw
Quoted 9 lines · Paolo Bonzini
Quoted 5 lines · Peter Maydell

PS: if you would like your BSD flavour promoted to "we don't merge changes that break the build on it" I would need to have ssh access to a machine I can run builds and tests on. (Unfortunately the only BSD in the gcc compile farm is an ancient NetBSD.)

For the purpose of "not breaking the build", having a docker image for a cross compiler would also be enough.

My requirement here is largely that I personally don't have to expend any effort on admining and maintaining BSD related build setups. I also think that setups that let you run "make check" are much more valuable than cross-compile setups that don't.

thanks
-- PMM

Reviewed-by on v1 1/1
#4 lore raw
In reply to Peter Maydell
Quoted 9 lines · Peter Maydell

The various host OSes are irritatingly variable about the name of the linker emulation we need to pass to ld's -m option to build the i386 option ROMs. Instead of doing this via a CONFIG ifdef, check in configure whether any of the emulation names we know about will work and pass the right answer through to the makefile. If we can't find one, we fall back to not trying to build the option ROMs, in the same way we would for a non-x86 host platform.

Quoted 4 lines

This is in particular necessary to unbreak the build on OpenBSD, since it wants a different answer to FreeBSD and we don't have an existing CONFIG_ variable that distinguishes the two.

For impact to FreeBSD only.

Quoted 68 lines

---
This works for Linux and for the Windows builds; I don't have any BSD systems to test it on. Brad and Sean, can I ask you to test this on OpenBSD and FreeBSD, please?

(I think this is going to miss -rc2. Sorry about that; we'll get OpenBSD builds fixed for -rc3.)

 configure                  | 12 +++++++++++-
 pc-bios/optionrom/Makefile | 12 +-----------
 2 files changed, 12 insertions(+), 12 deletions(-)
configure +11 -1
index f57fcc6..7c744ad 100755
@@ -4699,7 +4699,16 @@ roms=
 if test \( "$cpu" = "i386" -o "$cpu" = "x86_64" \) -a \
         "$targetos" != "Darwin" -a "$targetos" != "SunOS" -a \
         "$softmmu" = yes ; then
-  roms="optionrom"
+    # Different host OS linkers have different ideas about the name of the ELF
+    # emulation. Linux and OpenBSD use 'elf_i386'; FreeBSD uses the _fbsd
+    # variant; and Windows uses i386pe.
+    for emu in elf_i386 elf_i386_fbsd i386pe; do
+        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
+            ld_i386_emulation="$emu"
+            roms="optionrom"
+            break
+        fi
+    done
 fi
 if test "$cpu" = "ppc64" -a "$targetos" != "Darwin" ; then
   roms="$roms spapr-rtas"
@@ -5539,6 +5548,7 @@ fi
 echo "LDFLAGS=$LDFLAGS" >> $config_host_mak
 echo "LDFLAGS_NOPIE=$LDFLAGS_NOPIE" >> $config_host_mak
 echo "LD_REL_FLAGS=$LD_REL_FLAGS" >> $config_host_mak
+echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
 echo "LIBS+=$LIBS" >> $config_host_mak
 echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
 echo "PTHREAD_LIB=$PTHREAD_LIB" >> $config_host_mak
pc-bios/optionrom/Makefile +1 -11
index 24e175e..5bbe233 100644
@@ -41,18 +41,8 @@ build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin
 %.o: %.S
 	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"  AS    $(TARGET_DIR)$@")
 
-ifdef CONFIG_WIN32
-LD_EMULATION = i386pe
-else
-ifdef CONFIG_BSD
-LD_EMULATION = elf_i386_fbsd
-else
-LD_EMULATION = elf_i386
-endif
-endif
-
 %.img: %.o
-	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_EMULATION) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
+	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_I386_EMULATION) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
 
 %.raw: %.img
 	$(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"  Building $(TARGET_DIR)$@")
#5 lore raw
In reply to Peter Maydell
Quoted 9 lines · Peter Maydell

The various host OSes are irritatingly variable about the name of the linker emulation we need to pass to ld's -m option to build the i386 option ROMs. Instead of doing this via a CONFIG ifdef, check in configure whether any of the emulation names we know about will work and pass the right answer through to the makefile. If we can't find one, we fall back to not trying to build the option ROMs, in the same way we would for a non-x86 host platform.

Quoted 3 lines

This is in particular necessary to unbreak the build on OpenBSD, since it wants a different answer to FreeBSD and we don't have an existing CONFIG_ variable that distinguishes the two.

To add to this.. amd64 uses "elf_i386". Looking at i386 it uses elf_i386_obsd and that is the only emulation supported.

So change the list of emulations to try to

elf_i386 elf_i386_fbsd elf_i386_obsd i386pe

Someone needs to take a look at what NetBSD / DragonFly are using.

Quoted 68 lines

---
This works for Linux and for the Windows builds; I don't have any BSD systems to test it on. Brad and Sean, can I ask you to test this on OpenBSD and FreeBSD, please?

(I think this is going to miss -rc2. Sorry about that; we'll get OpenBSD builds fixed for -rc3.)

 configure                  | 12 +++++++++++-
 pc-bios/optionrom/Makefile | 12 +-----------
 2 files changed, 12 insertions(+), 12 deletions(-)
configure +11 -1
index f57fcc6..7c744ad 100755
@@ -4699,7 +4699,16 @@ roms=
 if test \( "$cpu" = "i386" -o "$cpu" = "x86_64" \) -a \
         "$targetos" != "Darwin" -a "$targetos" != "SunOS" -a \
         "$softmmu" = yes ; then
-  roms="optionrom"
+    # Different host OS linkers have different ideas about the name of the ELF
+    # emulation. Linux and OpenBSD use 'elf_i386'; FreeBSD uses the _fbsd
+    # variant; and Windows uses i386pe.
+    for emu in elf_i386 elf_i386_fbsd i386pe; do
+        if "$ld" -verbose 2>&1 | grep -q "^[[:space:]]*$emu[[:space:]]*$"; then
+            ld_i386_emulation="$emu"
+            roms="optionrom"
+            break
+        fi
+    done
 fi
 if test "$cpu" = "ppc64" -a "$targetos" != "Darwin" ; then
   roms="$roms spapr-rtas"
@@ -5539,6 +5548,7 @@ fi
 echo "LDFLAGS=$LDFLAGS" >> $config_host_mak
 echo "LDFLAGS_NOPIE=$LDFLAGS_NOPIE" >> $config_host_mak
 echo "LD_REL_FLAGS=$LD_REL_FLAGS" >> $config_host_mak
+echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
 echo "LIBS+=$LIBS" >> $config_host_mak
 echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
 echo "PTHREAD_LIB=$PTHREAD_LIB" >> $config_host_mak
pc-bios/optionrom/Makefile +1 -11
index 24e175e..5bbe233 100644
@@ -41,18 +41,8 @@ build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin
 %.o: %.S
 	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"  AS    $(TARGET_DIR)$@")
 
-ifdef CONFIG_WIN32
-LD_EMULATION = i386pe
-else
-ifdef CONFIG_BSD
-LD_EMULATION = elf_i386_fbsd
-else
-LD_EMULATION = elf_i386
-endif
-endif
-
 %.img: %.o
-	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_EMULATION) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
+	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_I386_EMULATION) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
 
 %.raw: %.img
 	$(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"  Building $(TARGET_DIR)$@")
#6 lore raw
Quoted 19 lines · Brad Smith
Quoted 10 lines · Peter Maydell

The various host OSes are irritatingly variable about the name of the linker emulation we need to pass to ld's -m option to build the i386 option ROMs. Instead of doing this via a CONFIG ifdef, check in configure whether any of the emulation names we know about will work and pass the right answer through to the makefile. If we can't find one, we fall back to not trying to build the option ROMs, in the same way we would for a non-x86 host platform.

Quoted 3 lines

This is in particular necessary to unbreak the build on OpenBSD, since it wants a different answer to FreeBSD and we don't have an existing CONFIG_ variable that distinguishes the two.

To add to this.. amd64 uses "elf_i386". Looking at i386 it uses elf_i386_obsd and that is the only emulation supported.

Quoted 7 lines

So change the list of emulations to try to

elf_i386 elf_i386_fbsd elf_i386_obsd i386pe

Someone needs to take a look at what NetBSD / DragonFly are using.

My NetBSD 6.1.4 amd64 VM uses elf_i386. Building should still work on an OS which doesn't support an emulation in the list in configure -- we'll just fall back to not building the option ROMs, which is the same position any non-x86 host architecture is in.

thanks
-- PMM

#7 lore raw
In reply to Peter Maydell
Quoted 13 lines · Peter Maydell

The various host OSes are irritatingly variable about the name of the linker emulation we need to pass to ld's -m option to build the i386 option ROMs. Instead of doing this via a CONFIG ifdef, check in configure whether any of the emulation names we know about will work and pass the right answer through to the makefile. If we can't find one, we fall back to not trying to build the option ROMs, in the same way we would for a non-x86 host platform.

This is in particular necessary to unbreak the build on OpenBSD, since it wants a different answer to FreeBSD and we don't have an existing CONFIG_ variable that distinguishes the two.

Quoted 8 lines

---
This works for Linux and for the Windows builds; I don't have any BSD systems to test it on. Brad and Sean, can I ask you to test this on OpenBSD and FreeBSD, please?

(I think this is going to miss -rc2. Sorry about that; we'll get OpenBSD builds fixed for -rc3.)

Tested on OpenBSD/amd64 and it builds. Need to get my i386 VM going and test on i386.

#8 lore raw
In reply to Peter Maydell
Quoted 13 lines · Peter Maydell

The various host OSes are irritatingly variable about the name of the linker emulation we need to pass to ld's -m option to build the i386 option ROMs. Instead of doing this via a CONFIG ifdef, check in configure whether any of the emulation names we know about will work and pass the right answer through to the makefile. If we can't find one, we fall back to not trying to build the option ROMs, in the same way we would for a non-x86 host platform.

This is in particular necessary to unbreak the build on OpenBSD, since it wants a different answer to FreeBSD and we don't have an existing CONFIG_ variable that distinguishes the two.

Quoted 8 lines

---
This works for Linux and for the Windows builds; I don't have any BSD systems to test it on. Brad and Sean, can I ask you to test this on OpenBSD and FreeBSD, please?

(I think this is going to miss -rc2. Sorry about that; we'll get OpenBSD builds fixed for -rc3.)

Applied to master (as-is, in the absence of a build check for i386 OpenBSD; we can always add the elf_i386_obsd entry to the list as a later patch, and if not then i386 is no worse off than other non-x86-64 OpenBSD hosts: it just won't build the option roms from source).

thanks
-- PMM

#9 lore raw
Quoted 22 lines · Peter Maydell
Quoted 13 lines · Peter Maydell

The various host OSes are irritatingly variable about the name of the linker emulation we need to pass to ld's -m option to build the i386 option ROMs. Instead of doing this via a CONFIG ifdef, check in configure whether any of the emulation names we know about will work and pass the right answer through to the makefile. If we can't find one, we fall back to not trying to build the option ROMs, in the same way we would for a non-x86 host platform.

This is in particular necessary to unbreak the build on OpenBSD, since it wants a different answer to FreeBSD and we don't have an existing CONFIG_ variable that distinguishes the two.

Quoted 8 lines

---
This works for Linux and for the Windows builds; I don't have any BSD systems to test it on. Brad and Sean, can I ask you to test this on OpenBSD and FreeBSD, please?

(I think this is going to miss -rc2. Sorry about that; we'll get OpenBSD builds fixed for -rc3.)

Quoted 8 lines

Applied to master (as-is, in the absence of a build check for i386 OpenBSD; we can always add the elf_i386_obsd entry to the list as a later patch, and if not then i386 is no worse off than other non-x86-64 OpenBSD hosts: it just won't build the option roms from source).

thanks
-- PMM

I am fine with that. Thank you.