Do not link usermode targets with libhw*.a
PATCH v4 1/2 Do not link usermode targets with libhw*.a
Usermode targets are hardware-independed.
--- configure | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
configure +2 -2
@@ -2173,15 +2173,15 @@ case "$target_arch2" in echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak fi esac -echo "HWLIB=../libhw$target_phys_bits/libqemuhw$target_phys_bits.a" >> $config_mak echo "TARGET_PHYS_ADDR_BITS=$target_phys_bits" >> $config_mak -echo "subdir-$target: subdir-libhw$target_phys_bits" >> $config_host_mak if test "$target_bigendian" = "yes" ; then echo "TARGET_WORDS_BIGENDIAN=y" >> $config_mak fi if test "$target_softmmu" = "yes" ; then echo "CONFIG_SOFTMMU=y" >> $config_mak echo "LIBS+=$libs_softmmu" >> $config_mak + echo "HWLIB=../libhw$target_phys_bits/libqemuhw$target_phys_bits.a" >> $config_mak + echo "subdir-$target: subdir-libhw$target_phys_bits" >> $config_host_mak fi if test "$target_user_only" = "yes" ; then echo "CONFIG_USER_ONLY=y" >> $config_mak
Signature · 1 line
1.6.4.2
PATCH v4 2/2 Build usermode targets as PIE
Long since, qemu on i386 has a linking hack which produces an executable which looks like PIE, but it always has text relocations since all object files compiled without -fpie.
The best was to solve the issue is to build a true PIE.
v4:
- Add test for toolchain if it has proper PIE support
v3:
- One more pice of the hack was removed
- Description updated
v2:
- Add configure options do enable/disable PIE for usermode targets. Disabling can be useful if you build uswing toolchain which has broken PIE support. PIE for usermode targets enabled by default.
--- Makefile | 10 +--------- Makefile.target | 19 +++++++++++++++---- configure | 49 ++++++++++++++++++++++++++++++++++++++----------- linux-user/main.c | 26 -------------------------- 4 files changed, 54 insertions(+), 50 deletions(-)
Makefile +1 -9
@@ -39,8 +39,6 @@ subdir-%: $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" TARGET_DIR="$*/" all,) $(filter %-softmmu,$(SUBDIR_RULES)): libqemu_common.a -$(filter %-user,$(SUBDIR_RULES)): libqemu_user.a - ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) romsubdir-%:
@@ -74,7 +72,7 @@ block-obj-y += $(addprefix block/, $(block-nested-y)) # CPUs and machines. obj-y = $(block-obj-y) -obj-y += readline.o console.o host-utils.o +obj-y += readline.o console.o obj-y += irq.o ptimer.o obj-y += i2c.o smbus.o smbus_eeprom.o max7310.o max111x.o wm8750.o
@@ -161,12 +159,6 @@ bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS) libqemu_common.a: $(obj-y) -####################################################################### -# user-obj-y is code used by qemu userspace emulation -user-obj-y = cutils.o cache-utils.o path.o envlist.o host-utils.o - -libqemu_user.a: $(user-obj-y) - ###################################################################### qemu-img.o: qemu-img-cmds.h
Makefile.target +15 -4
@@ -31,7 +31,7 @@ all: $(PROGS) ######################################################### # cpu emulator library -libobj-y = exec.o translate-all.o cpu-exec.o translate.o +libobj-y = exec.o translate-all.o cpu-exec.o translate.o host-utils.o libobj-y += tcg/tcg.o tcg/tcg-runtime.o libobj-$(CONFIG_SOFTFLOAT) += fpu/softfloat.o libobj-$(CONFIG_NOSOFTFLOAT) += fpu/softfloat-native.o
@@ -80,9 +80,9 @@ ifdef CONFIG_LINUX_USER VPATH+=:$(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) - obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \ elfload.o linuxload.o uaccess.o gdbstub.o gdbstub-xml.o +obj-y += envlist.o path.o obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_HAS_ELFLOAD32) += elfload32.o
@@ -98,7 +98,7 @@ obj-arm-y += arm-semi.o obj-m68k-y += m68k-sim.o m68k-semi.o -ARLIBS=../libqemu_user.a libqemu.a +ARLIBS=libqemu.a endif #CONFIG_LINUX_USER #########################################################
@@ -116,6 +116,7 @@ LIBS+=-lmx obj-y = main.o commpage.o machload.o mmap.o signal.o syscall.o thunk.o \ gdbstub.o gdbstub-xml.o +obj-y += envlist.o path.o obj-i386-y += ioport-user.o
@@ -133,13 +134,23 @@ QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ARCH) obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ gdbstub.o gdbstub-xml.o uaccess.o +obj-y += envlist.o path.o obj-i386-y += ioport-user.o -ARLIBS=libqemu.a ../libqemu_user.a +ARLIBS=libqemu.a endif #CONFIG_BSD_USER +ifdef CONFIG_USER_ONLY +# hack to compile with -fpie for *-user targets +obj-y += cutils-user.o cache-utils-user.o +cutils-user.c cache-utils-user.c: + @echo " LN $(TARGET_DIR)$@" + @ln -s $(SRC_PATH)/$(@:%-user.c=%.c) $@ +endif + + ######################################################### # System emulator target ifdef CONFIG_SOFTMMU
configure +38 -11
97 lines not on this page · raw message
linux-user/main.c +0 -26
@@ -48,32 +48,6 @@ int have_guest_base;static const char *interp_prefix =CONFIG_QEMU_PREFIX ;const char *qemu_uname_release =CONFIG_UNAME_RELEASE ; -#if defined(__i386__) && !defined(CONFIG_STATIC ) -/* Force usage of an ELF interpreter even if it is an ELF shared -object ! */ -const char interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2"; -#endif - -/* for recent libc, we add these dummy symbols which are not declared -when generating a linked object (bug in ld ?) */ -#if (__GLIBC__ >2 || (__GLIBC__ ==2 && __GLIBC_MINOR__ >=3 )) && !defined(CONFIG_STATIC ) -asm(".globl __preinit_array_start\n" -".globl __preinit_array_end\n" -".globl __init_array_start\n" -".globl __init_array_end\n" -".globl __fini_array_start\n" -".globl __fini_array_end\n" -".section \".rodata\"\n" -"__preinit_array_start:\n" -"__preinit_array_end:\n" -"__init_array_start:\n" -"__init_array_end:\n" -"__fini_array_start:\n" -"__fini_array_end:\n" -".long 0\n" -".previous\n" ); -#endif -/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example by remapping the process stack directly at the right place */
Signature · 1 line
1.6.4.2
Re: [Qemu-devel] [PATCH v4 2/2] Build usermode targets as PIE
"Kirill A. Shutemov" <[email protected]> writes:
Hi,
[...]
Quoted 10 lines
configure +10
-0+cat > $TMPC <<EOF +int main() { + static __thread int i = 0; + i++; + return 0; +} +EOF + +if test "$user_pie" != "no" ; then + if compile_prog "-fpie" "-pie -Wl,--fatal-warnings -Wl,--warn-shared-textrel"; then
configure elif compile_prog "" "-lrt" ; then · line 1569
Quoted 10 lines
configure +10
-0+ user_pie="yes" + else + if test "$user_pie" = "yes"; then + echo "Toolchain has no proper PIE support" + exit 1 + else + user_pie="no" + fi + fi +fi
Unfortunately, the broken mips toolchain pass this test. When you compile, you're getting no warning at all. Moreover, the failure is triggered at run-time (and this test doesn't trigger it). See
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=526961 if you want something which segfault with pie.
I don't know if there are some other non-mips toolchains with broken pie and what's their behaviour. I hope it's crashing too...
Arnaud
Re: [Qemu-devel] [PATCH v4 2/2] Build usermode targets as PIE
Quoted 27 lines · Arnaud Patard
"Kirill A. Shutemov" <[email protected]> writes:
Hi,
[...]
Quoted 10 lines
configure +10
-0+cat > $TMPC <<EOF +int main() { + static __thread int i = 0; + i++; + return 0; +} +EOF + +if test "$user_pie" != "no" ; then + if compile_prog "-fpie" "-pie -Wl,--fatal-warnings -Wl,--warn-shared-textrel"; thenconfigure elif compile_prog "" "-lrt" ; then · line 1569
Quoted 10 lines
configure +10
-0+ user_pie="yes" + else + if test "$user_pie" = "yes"; then + echo "Toolchain has no proper PIE support" + exit 1 + else + user_pie="no" + fi + fi +fi
Quoted 7 lines
Unfortunately, the broken mips toolchain pass this test. When you compile, you're getting no warning at all. Moreover, the failure is triggered at run-time (and this test doesn't trigger it). See
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=526961 if you want something which segfault with pie.
I don't know if there are some other non-mips toolchains with broken pie and what's their behaviour. I hope it's crashing too...
Where can I get a mips cross-compiler with this issue to play?
Re: [Qemu-devel] [PATCH v4 2/2] Build usermode targets as PIE
"Kirill A. Shutemov" <[email protected]> writes:
Hi,
Quoted 9 lines
Quoted 7 lines
Unfortunately, the broken mips toolchain pass this test. When you compile, you're getting no warning at all. Moreover, the failure is triggered at run-time (and this test doesn't trigger it). See
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=526961 if you want something which segfault with pie.
I don't know if there are some other non-mips toolchains with broken pie and what's their behaviour. I hope it's crashing too...Where can I get a mips cross-compiler with this issue to play?
No, sorry. I'm building mips stuff only natively. Fortunately, this is a toolchain bug so this should be reproductible if you use qemu to emulate a mips box running debian for mipsel.
Arnaud