From 34005a0060c176b3025a9e7c5d064615a9f80325 Mon Sep 17 00:00:00 2001 From: "Kirill A. Shutemov" Date: Sat, 12 Sep 2009 02:17:55 +0300 Subject: Add configure option to compile user targets as PIE Build uset targers as true PIE if user want to keep qemu self-virtualizable. v5: - Split into to patches: drop link hack and add PIE support - do not build PIE by default and drop toolchain check 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. Signed-off-by: Kirill A. Shutemov Signed-off-by: Blue Swirl --- Makefile | 10 +--------- Makefile.target | 19 +++++++++++++++---- configure | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index cb2614b0c6..b1de39a090 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -162,12 +160,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 diff --git a/Makefile.target b/Makefile.target index 0fe8b6ac38..6314e0e78b 100644 --- a/Makefile.target +++ b/Makefile.target @@ -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 diff --git a/configure b/configure index cb1c29f5be..494e9ced7b 100755 --- a/configure +++ b/configure @@ -222,6 +222,7 @@ aix="no" blobs="yes" pkgversion="" check_utests="no" +user_pie="no" # OS specific if check_define __linux__ ; then @@ -503,6 +504,10 @@ for opt do ;; --disable-guest-base) guest_base="no" ;; + --enable-user-pie) user_pie="yes" + ;; + --disable-user-pie) user_pie="no" + ;; --enable-uname-release=*) uname_release="$optarg" ;; --sparc_cpu=*) @@ -683,6 +688,8 @@ echo " --disable-bsd-user disable all BSD usermode emulation targets" echo " --enable-guest-base enable GUEST_BASE support for usermode" echo " emulation targets" echo " --disable-guest-base disable GUEST_BASE support" +echo " --enable-user-pie build usermode emulation targets as PIE" +echo " --disable-user-pie do not build usermode emulation targets as PIE" echo " --fmod-lib path to FMOD library" echo " --fmod-inc path to FMOD includes" echo " --oss-lib path to OSS library" @@ -1723,6 +1730,7 @@ echo "Documentation $docs" echo "uname -r $uname_release" echo "NPTL support $nptl" echo "GUEST_BASE $guest_base" +echo "PIE user targets $user_pie" echo "vde support $vde" echo "IO thread $io_thread" echo "Linux AIO support $linux_aio" @@ -2355,6 +2363,12 @@ if test "$target_softmmu" = "yes" ; then esac fi +if test "$target_user_only" = "yes" -a "$static" = "no" -a \ + "$user_pie" = "yes" ; then + cflags="-fpie $cflags" + ldflags="-pie $ldflags" +fi + if test "$target_softmmu" = "yes" -a \( \ "$TARGET_ARCH" = "microblaze" -o \ "$TARGET_ARCH" = "cris" \) ; then -- cgit v1.2.3