Skip to contentSkip to conversation

Fix QEMU build on OpenBSD on x86 archs

PATCH Superseded Brad Smith 2 participants 7 messages Dec 10, 2013 – Dec 11, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Brad Smith

author
#0 lore raw

PATCH v2 1/1 Fix QEMU build on OpenBSD on x86 archs

This resolves the build issue with building the ROMs on OpenBSD on x86 archs. As of OpenBSD 5.3 the compiler builds PIE binaries by default and thus the whole OS/packages and so forth. The ROMs need to have PIE disabled. This is my initial attempt at trying to get somehting upstream so that QEMU both builds out of the box and to resolve the build issue with the buildbots that has been around for awhile. We have a patch in our ports tree but it is just the flags hardcoded into the Makefile which obviously is not appropriate for upstream.

Quoted 1 line

From the OpenBSD buildbots..

Building optionrom/multiboot.img
ld: multiboot.o: relocation R_X86_64_16 can not be used when making a shared object; recompile with -fPIC

Signed-off by: Brad Smith <[email protected]>
---

Changes in v2:
* Fix '==' is not portable syntax.

configure +6 -0
index 508f6a5..6d84885 100755
@@ -1342,6 +1342,10 @@ EOF
   if compile_prog "-fPIE -DPIE" "-pie"; then
     QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
     LDFLAGS="-pie $LDFLAGS"
+    if test "$targetos" = OpenBSD; then
+      CC_NOPIE="-fno-pie"
+      LD_NOPIE="-nopie"
+    fi
     pie="yes"
     if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
       LDFLAGS="-Wl,-z,relro -Wl,-z,now $LDFLAGS"
@@ -4307,6 +4311,8 @@ if test "$gcov" = "yes" ; then
   echo "CONFIG_GCOV=y" >> $config_host_mak
   echo "GCOV=$gcov_tool" >> $config_host_mak
 fi
+echo "CC_NOPIE=$CC_NOPIE" >> $config_host_mak
+echo "LD_NOPIE=$LD_NOPIE" >> $config_host_mak
 
 # use included Linux headers
 if test "$linux" = "yes" ; then
pc-bios/optionrom/Makefile +2 -1
index 57d8bd0..0b35000 100644
@@ -12,6 +12,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
 CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin
 CFLAGS += -I$(SRC_PATH)
 CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
+CFLAGS += $(CC_NOPIE)
 QEMU_CFLAGS = $(CFLAGS)
 
 build-all: multiboot.bin linuxboot.bin kvmvapic.bin
@@ -20,7 +21,7 @@ build-all: multiboot.bin linuxboot.bin kvmvapic.bin
 .SECONDARY:
 
 %.img: %.o
-	$(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
+	$(call quiet-command,$(LD) $(LD_NOPIE) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
 
 %.raw: %.img
 	$(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"  Building $(TARGET_DIR)$@")
Signature · 3 lines
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
#1 lore raw

Am 10.12.2013 02:26, schrieb Brad Smith:

Quoted 50 lines

This resolves the build issue with building the ROMs on OpenBSD on x86 archs. As of OpenBSD 5.3 the compiler builds PIE binaries by default and thus the whole OS/packages and so forth. The ROMs need to have PIE disabled. This is my initial attempt at trying to get somehting upstream so that QEMU both builds out of the box and to resolve the build issue with the buildbots that has been around for awhile. We have a patch in our ports tree but it is just the flags hardcoded into the Makefile which obviously is not appropriate for upstream.

From the OpenBSD buildbots..
Building optionrom/multiboot.img
ld: multiboot.o: relocation R_X86_64_16 can not be used when making a shared object; recompile with -fPIC

Signed-off by: Brad Smith <[email protected]>
---

Changes in v2:
* Fix '==' is not portable syntax.

configure +6 -0
index 508f6a5..6d84885 100755
@@ -1342,6 +1342,10 @@ EOF
   if compile_prog "-fPIE -DPIE" "-pie"; then
     QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
     LDFLAGS="-pie $LDFLAGS"
+    if test "$targetos" = OpenBSD; then
+      CC_NOPIE="-fno-pie"
+      LD_NOPIE="-nopie"
+    fi
     pie="yes"
     if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
       LDFLAGS="-Wl,-z,relro -Wl,-z,now $LDFLAGS"
@@ -4307,6 +4311,8 @@ if test "$gcov" = "yes" ; then
   echo "CONFIG_GCOV=y" >> $config_host_mak
   echo "GCOV=$gcov_tool" >> $config_host_mak
 fi
+echo "CC_NOPIE=$CC_NOPIE" >> $config_host_mak
+echo "LD_NOPIE=$LD_NOPIE" >> $config_host_mak
 
 # use included Linux headers
 if test "$linux" = "yes" ; then
pc-bios/optionrom/Makefile +0 -0
index 57d8bd0..0b35000 100644

pc-bios/optionrom/Makefile $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom) · line 15

Quoted 4 lines
pc-bios/optionrom/Makefile +1 -0
@@ -12,6 +12,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
 CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin
 CFLAGS += -I$(SRC_PATH)
 CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
+CFLAGS += $(CC_NOPIE)

Would it be possible to add -fno-pie unconditionally here ...

pc-bios/optionrom/Makefile build-all: multiboot.bin linuxboot.bin kvmvapic.bin · line 25

Quoted 10 lines
pc-bios/optionrom/Makefile +1 -1
 QEMU_CFLAGS = $(CFLAGS)
 
 build-all: multiboot.bin linuxboot.bin kvmvapic.bin
@@ -20,7 +21,7 @@ build-all: multiboot.bin linuxboot.bin kvmvapic.bin
 .SECONDARY:
 
 %.img: %.o
-	$(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
+	$(call quiet-command,$(LD) $(LD_NOPIE) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
 

... and use -nopie here? I tried it in my Linux build environment, and it seems to work.

Then no changes to file configure are needed.

Stefan

author
#2 lore raw
Quoted 74 lines · Stefan Weil

Am 10.12.2013 02:26, schrieb Brad Smith:

Quoted 50 lines

This resolves the build issue with building the ROMs on OpenBSD on x86 archs. As of OpenBSD 5.3 the compiler builds PIE binaries by default and thus the whole OS/packages and so forth. The ROMs need to have PIE disabled. This is my initial attempt at trying to get somehting upstream so that QEMU both builds out of the box and to resolve the build issue with the buildbots that has been around for awhile. We have a patch in our ports tree but it is just the flags hardcoded into the Makefile which obviously is not appropriate for upstream.

From the OpenBSD buildbots..
Building optionrom/multiboot.img
ld: multiboot.o: relocation R_X86_64_16 can not be used when making a shared object; recompile with -fPIC

Signed-off by: Brad Smith <[email protected]>
---

Changes in v2:
* Fix '==' is not portable syntax.

configure +6 -0
index 508f6a5..6d84885 100755
@@ -1342,6 +1342,10 @@ EOF
    if compile_prog "-fPIE -DPIE" "-pie"; then
      QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
      LDFLAGS="-pie $LDFLAGS"
+    if test "$targetos" = OpenBSD; then
+      CC_NOPIE="-fno-pie"
+      LD_NOPIE="-nopie"
+    fi
      pie="yes"
      if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
        LDFLAGS="-Wl,-z,relro -Wl,-z,now $LDFLAGS"
@@ -4307,6 +4311,8 @@ if test "$gcov" = "yes" ; then
    echo "CONFIG_GCOV=y" >> $config_host_mak
    echo "GCOV=$gcov_tool" >> $config_host_mak
  fi
+echo "CC_NOPIE=$CC_NOPIE" >> $config_host_mak
+echo "LD_NOPIE=$LD_NOPIE" >> $config_host_mak
 
  # use included Linux headers
  if test "$linux" = "yes" ; then
pc-bios/optionrom/Makefile +0 -0
index 57d8bd0..0b35000 100644

pc-bios/optionrom/Makefile $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom) · line 15

Quoted 4 lines
pc-bios/optionrom/Makefile +1 -0
@@ -12,6 +12,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
  CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin
  CFLAGS += -I$(SRC_PATH)
  CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
+CFLAGS += $(CC_NOPIE)

Would it be possible to add -fno-pie unconditionally here ...

pc-bios/optionrom/Makefile build-all: multiboot.bin linuxboot.bin kvmvapic.bin · line 25

Quoted 10 lines
pc-bios/optionrom/Makefile +1 -1
  QEMU_CFLAGS = $(CFLAGS)
 
  build-all: multiboot.bin linuxboot.bin kvmvapic.bin
@@ -20,7 +21,7 @@ build-all: multiboot.bin linuxboot.bin kvmvapic.bin
  .SECONDARY:
 
  %.img: %.o
-	$(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
+	$(call quiet-command,$(LD) $(LD_NOPIE) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
 

... and use -nopie here? I tried it in my Linux build environment, and it seems to work.

Quoted 1 line

Then no changes to file configure are needed.

The linker flag definitely does not exist everywhere so that would break the build on other OS/toolchain combinations; for example stock binutils does not have this flag. I would not have bothered going this route if I didn't see having the flags hard coded as causing a problem.

Signature · 3 lines
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Reviewed-by
#3 lore raw

Am 10.12.2013 08:48, schrieb Brad Smith:

Quoted 83 lines · Stefan Weil
Quoted 82 lines

Am 10.12.2013 02:26, schrieb Brad Smith:

Quoted 55 lines

This resolves the build issue with building the ROMs on OpenBSD on x86 archs.
As of OpenBSD 5.3 the compiler builds PIE binaries by default and thus the
whole OS/packages and so forth. The ROMs need to have PIE disabled. This
is my initial attempt at trying to get somehting upstream so that QEMU both builds out of the box and to resolve the build issue with the buildbots that has been around for awhile. We have a patch in our ports tree but it is just the flags hardcoded into the Makefile which obviously
is not appropriate for upstream.

From the OpenBSD buildbots..
Building optionrom/multiboot.img
ld: multiboot.o: relocation R_X86_64_16 can not be used when making a shared object; recompile with -fPIC

Signed-off by: Brad Smith <[email protected]>
---

Changes in v2:
* Fix '==' is not portable syntax.

configure +6 -0
index 508f6a5..6d84885 100755
@@ -1342,6 +1342,10 @@ EOF
    if compile_prog "-fPIE -DPIE" "-pie"; then
      QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
      LDFLAGS="-pie $LDFLAGS"
+    if test "$targetos" = OpenBSD; then
+      CC_NOPIE="-fno-pie"
+      LD_NOPIE="-nopie"
+    fi
      pie="yes"
      if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
        LDFLAGS="-Wl,-z,relro -Wl,-z,now $LDFLAGS"
@@ -4307,6 +4311,8 @@ if test "$gcov" = "yes" ; then
    echo "CONFIG_GCOV=y" >> $config_host_mak
    echo "GCOV=$gcov_tool" >> $config_host_mak
  fi
+echo "CC_NOPIE=$CC_NOPIE" >> $config_host_mak
+echo "LD_NOPIE=$LD_NOPIE" >> $config_host_mak
 
  # use included Linux headers
  if test "$linux" = "yes" ; then
pc-bios/optionrom/Makefile +0 -0
index 57d8bd0..0b35000 100644

pc-bios/optionrom/Makefile $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom) · line 15

Quoted 5 lines
pc-bios/optionrom/Makefile +1 -1
@@ -12,6 +12,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
  CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer
-fno-builtin
  CFLAGS += -I$(SRC_PATH)
  CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
+CFLAGS += $(CC_NOPIE)

Would it be possible to add -fno-pie unconditionally here ...

pc-bios/optionrom/Makefile build-all: multiboot.bin linuxboot.bin kvmvapic.bin · line 27

Quoted 12 lines
pc-bios/optionrom/Makefile +1 -1
  QEMU_CFLAGS = $(CFLAGS)
 
  build-all: multiboot.bin linuxboot.bin kvmvapic.bin
@@ -20,7 +21,7 @@ build-all: multiboot.bin linuxboot.bin kvmvapic.bin
  .SECONDARY:
 
  %.img: %.o
-    $(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<," 
 Building $(TARGET_DIR)$@")
+    $(call quiet-command,$(LD) $(LD_NOPIE) -Ttext 0 -e _start -s -o
 $@ $<,"  Building $(TARGET_DIR)$@")
 

... and use -nopie here? I tried it in my Linux build environment, and it seems to work.

Quoted 7 lines
Quoted 1 line

Then no changes to file configure are needed.

The linker flag definitely does not exist everywhere so that would break the build on other OS/toolchain combinations; for example stock binutils does not have this flag. I would not have bothered going this route if I didn't see having the flags hard coded as causing a problem.

Thank you for your explanation. I cc your patch to qemu-stable because fixing QEMU 1.7 for OpenBSD might be a good idea, too.

If other hosts beside OpenBSD will need thismodification in the future, I suggest modified code like this:

if compile_prog "-fPIE -DPIE" "-pie"; then
QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
LDFLAGS="-pie $LDFLAGS"
# [...]
fi

if compile_prog "-fno-pie" "-nopie"; then
CFLAGS_NOPIE="-fno-pie"
LDFLAGS_NOPIE="-nopie"
fi

(separate if blocks in configure and use CFLAGS_NOPIE, LDFLAGS_NOPIE instead of CC_NOPIE, LD_NOPIE, this also needs a modified Makefile).

Regards,
Stefan

#4 lore raw

... now with qemu-stable addressed - I had pressed "send" to early.

Stefan

Am 10.12.2013 19:42, schrieb Stefan Weil:

Quoted 115 lines

Am 10.12.2013 08:48, schrieb Brad Smith:

Quoted 81 lines · Stefan Weil
Quoted 80 lines

Am 10.12.2013 02:26, schrieb Brad Smith:

Quoted 55 lines

This resolves the build issue with building the ROMs on OpenBSD on x86 archs.
As of OpenBSD 5.3 the compiler builds PIE binaries by default and thus the
whole OS/packages and so forth. The ROMs need to have PIE disabled. This
is my initial attempt at trying to get somehting upstream so that QEMU both builds out of the box and to resolve the build issue with the buildbots that has been around for awhile. We have a patch in our ports tree but it is just the flags hardcoded into the Makefile which obviously
is not appropriate for upstream.

From the OpenBSD buildbots..
Building optionrom/multiboot.img
ld: multiboot.o: relocation R_X86_64_16 can not be used when making a shared object; recompile with -fPIC

Signed-off by: Brad Smith <[email protected]>
---

Changes in v2:
* Fix '==' is not portable syntax.

configure +6 -0
index 508f6a5..6d84885 100755
@@ -1342,6 +1342,10 @@ EOF
    if compile_prog "-fPIE -DPIE" "-pie"; then
      QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
      LDFLAGS="-pie $LDFLAGS"
+    if test "$targetos" = OpenBSD; then
+      CC_NOPIE="-fno-pie"
+      LD_NOPIE="-nopie"
+    fi
      pie="yes"
      if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
        LDFLAGS="-Wl,-z,relro -Wl,-z,now $LDFLAGS"
@@ -4307,6 +4311,8 @@ if test "$gcov" = "yes" ; then
    echo "CONFIG_GCOV=y" >> $config_host_mak
    echo "GCOV=$gcov_tool" >> $config_host_mak
  fi
+echo "CC_NOPIE=$CC_NOPIE" >> $config_host_mak
+echo "LD_NOPIE=$LD_NOPIE" >> $config_host_mak
 
  # use included Linux headers
  if test "$linux" = "yes" ; then
pc-bios/optionrom/Makefile +0 -0
index 57d8bd0..0b35000 100644

pc-bios/optionrom/Makefile $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom) · line 15

Quoted 5 lines
pc-bios/optionrom/Makefile +1 -1
@@ -12,6 +12,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
  CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer
-fno-builtin
  CFLAGS += -I$(SRC_PATH)
  CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
+CFLAGS += $(CC_NOPIE)

Would it be possible to add -fno-pie unconditionally here ...

pc-bios/optionrom/Makefile build-all: multiboot.bin linuxboot.bin kvmvapic.bin · line 27

Quoted 12 lines
pc-bios/optionrom/Makefile +1 -1
  QEMU_CFLAGS = $(CFLAGS)
 
  build-all: multiboot.bin linuxboot.bin kvmvapic.bin
@@ -20,7 +21,7 @@ build-all: multiboot.bin linuxboot.bin kvmvapic.bin
  .SECONDARY:
 
  %.img: %.o
-    $(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<," 
 Building $(TARGET_DIR)$@")
+    $(call quiet-command,$(LD) $(LD_NOPIE) -Ttext 0 -e _start -s -o
 $@ $<,"  Building $(TARGET_DIR)$@")
 

... and use -nopie here? I tried it in my Linux build environment, and it seems to work.

Quoted 6 lines
Quoted 1 line

Then no changes to file configure are needed.

The linker flag definitely does not exist everywhere so that would break the build on other OS/toolchain combinations; for example stock binutils does not have this flag. I would not have bothered going this route if I didn't see having the flags hard coded as causing a problem.

Thank you for your explanation. I cc your patch to qemu-stable because fixing QEMU 1.7 for OpenBSD might be a good idea, too.

If other hosts beside OpenBSD will need thismodification in the future, I suggest modified code like this:

if compile_prog "-fPIE -DPIE" "-pie"; then
QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
LDFLAGS="-pie $LDFLAGS"
# [...]
fi

if compile_prog "-fno-pie" "-nopie"; then
CFLAGS_NOPIE="-fno-pie"
LDFLAGS_NOPIE="-nopie"
fi

(separate if blocks in configure and use CFLAGS_NOPIE, LDFLAGS_NOPIE instead of CC_NOPIE, LD_NOPIE, this also needs a modified Makefile).

Regards,
Stefan

author
#5 lore raw
Quoted 117 lines · Stefan Weil

... now with qemu-stable addressed - I had pressed "send" to early.

Stefan

Am 10.12.2013 19:42, schrieb Stefan Weil:

Quoted 111 lines

Am 10.12.2013 08:48, schrieb Brad Smith:

Quoted 81 lines · Stefan Weil
Quoted 80 lines

Am 10.12.2013 02:26, schrieb Brad Smith:

Quoted 55 lines

This resolves the build issue with building the ROMs on OpenBSD on x86 archs.
As of OpenBSD 5.3 the compiler builds PIE binaries by default and thus the
whole OS/packages and so forth. The ROMs need to have PIE disabled. This
is my initial attempt at trying to get somehting upstream so that QEMU both builds out of the box and to resolve the build issue with the buildbots that has been around for awhile. We have a patch in our ports tree but it is just the flags hardcoded into the Makefile which obviously
is not appropriate for upstream.

From the OpenBSD buildbots..
Building optionrom/multiboot.img
ld: multiboot.o: relocation R_X86_64_16 can not be used when making a shared object; recompile with -fPIC

Signed-off by: Brad Smith <[email protected]>
---

Changes in v2:
* Fix '==' is not portable syntax.

configure +6 -0
index 508f6a5..6d84885 100755
@@ -1342,6 +1342,10 @@ EOF
     if compile_prog "-fPIE -DPIE" "-pie"; then
       QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
       LDFLAGS="-pie $LDFLAGS"
+    if test "$targetos" = OpenBSD; then
+      CC_NOPIE="-fno-pie"
+      LD_NOPIE="-nopie"
+    fi
       pie="yes"
       if compile_prog "" "-Wl,-z,relro -Wl,-z,now" ; then
         LDFLAGS="-Wl,-z,relro -Wl,-z,now $LDFLAGS"
@@ -4307,6 +4311,8 @@ if test "$gcov" = "yes" ; then
     echo "CONFIG_GCOV=y" >> $config_host_mak
     echo "GCOV=$gcov_tool" >> $config_host_mak
   fi
+echo "CC_NOPIE=$CC_NOPIE" >> $config_host_mak
+echo "LD_NOPIE=$LD_NOPIE" >> $config_host_mak
 
   # use included Linux headers
   if test "$linux" = "yes" ; then
pc-bios/optionrom/Makefile +0 -0
index 57d8bd0..0b35000 100644

pc-bios/optionrom/Makefile $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom) · line 15

Quoted 5 lines
pc-bios/optionrom/Makefile +1 -1
@@ -12,6 +12,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
   CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer
-fno-builtin
   CFLAGS += -I$(SRC_PATH)
   CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
+CFLAGS += $(CC_NOPIE)

Would it be possible to add -fno-pie unconditionally here ...

pc-bios/optionrom/Makefile build-all: multiboot.bin linuxboot.bin kvmvapic.bin · line 27

Quoted 12 lines
pc-bios/optionrom/Makefile +1 -1
   QEMU_CFLAGS = $(CFLAGS)
 
   build-all: multiboot.bin linuxboot.bin kvmvapic.bin
@@ -20,7 +21,7 @@ build-all: multiboot.bin linuxboot.bin kvmvapic.bin
   .SECONDARY:
 
   %.img: %.o
-    $(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<,"
 Building $(TARGET_DIR)$@")
+    $(call quiet-command,$(LD) $(LD_NOPIE) -Ttext 0 -e _start -s -o
 $@ $<,"  Building $(TARGET_DIR)$@")
 

... and use -nopie here? I tried it in my Linux build environment, and it seems to work.

Quoted 6 lines
Quoted 1 line

Then no changes to file configure are needed.

The linker flag definitely does not exist everywhere so that would break the build on other OS/toolchain combinations; for example stock binutils does not have this flag. I would not have bothered going this route if I didn't see having the flags hard coded as causing a problem.

Thank you for your explanation. I cc your patch to qemu-stable because fixing QEMU 1.7 for OpenBSD might be a good idea, too.

If other hosts beside OpenBSD will need thismodification in the future, I suggest modified code like this:

if compile_prog "-fPIE -DPIE" "-pie"; then
QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS"
LDFLAGS="-pie $LDFLAGS"
# [...]
fi

if compile_prog "-fno-pie" "-nopie"; then
CFLAGS_NOPIE="-fno-pie"
LDFLAGS_NOPIE="-nopie"
fi

(separate if blocks in configure and use CFLAGS_NOPIE, LDFLAGS_NOPIE instead of CC_NOPIE, LD_NOPIE, this also needs a modified Makefile).

Well if you want to use CFLAGS_NOPIE and LDFLAGS_NOPIE now I can do so. The variable names are not set in stone and I was just trying to come up with an idea of how to do this and see how it goes through review.

Signature · 3 lines
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
author
#6 lore raw
In reply to Stefan Weil
Quoted 1 line · Stefan Weil

... now with qemu-stable addressed - I had pressed "send" to early.

Ah, I usually send such requests separately with a commit hash after it has been commited to master.

Signature · 3 lines
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.