From patchwork Fri Sep 4 12:28:06 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 32982 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 5AB49B7080 for ; Fri, 4 Sep 2009 19:33:02 +1000 (EST) Received: from localhost ([127.0.0.1]:59809 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MjVA7-0006yh-NE for incoming@patchwork.ozlabs.org; Fri, 04 Sep 2009 05:32:55 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MjV5n-0005Em-9K for qemu-devel@nongnu.org; Fri, 04 Sep 2009 05:28:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MjV5i-0005BI-Gm for qemu-devel@nongnu.org; Fri, 04 Sep 2009 05:28:26 -0400 Received: from [199.232.76.173] (port=37611 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MjV5h-0005B9-WB for qemu-devel@nongnu.org; Fri, 04 Sep 2009 05:28:22 -0400 Received: from mx20.gnu.org ([199.232.41.8]:29289) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MjV5g-0001KV-Q7 for qemu-devel@nongnu.org; Fri, 04 Sep 2009 05:28:21 -0400 Received: from mail-bw0-f227.google.com ([209.85.218.227]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MjV5f-00061R-Qm for qemu-devel@nongnu.org; Fri, 04 Sep 2009 05:28:20 -0400 Received: by mail-bw0-f227.google.com with SMTP id 27so510222bwz.34 for ; Fri, 04 Sep 2009 02:28:19 -0700 (PDT) Received: by 10.103.85.28 with SMTP id n28mr4670672mul.66.1252056499379; Fri, 04 Sep 2009 02:28:19 -0700 (PDT) Received: from localhost.localdomain (viktor.cosmicparrot.net [217.152.255.14]) by mx.google.com with ESMTPS id y37sm2227142mug.41.2009.09.04.02.28.17 (version=SSLv3 cipher=RC4-MD5); Fri, 04 Sep 2009 02:28:18 -0700 (PDT) From: "Kirill A. Shutemov" To: qemu-devel@nongnu.org Date: Fri, 4 Sep 2009 15:28:06 +0300 Message-Id: <1252067286-21758-2-git-send-email-kirill@shutemov.name> X-Mailer: git-send-email 1.6.4.2 In-Reply-To: <1252067286-21758-1-git-send-email-kirill@shutemov.name> References: <1252067286-21758-1-git-send-email-kirill@shutemov.name> X-Detected-Operating-System: by mx20.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Paolo Bonzini , Riku Voipio , Juan Quintela , "Kirill A. Shutemov" , Arnaud Patard , Paul Brook Subject: [Qemu-devel] [PATCH v4 2/2] Build usermode targets as PIE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Signed-off-by: Kirill A. Shutemov --- Makefile | 10 +--------- Makefile.target | 19 +++++++++++++++---- configure | 49 ++++++++++++++++++++++++++++++++++++++----------- linux-user/main.c | 26 -------------------------- 4 files changed, 54 insertions(+), 50 deletions(-) diff --git a/Makefile b/Makefile index bdac9b3..634ea81 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 @@ -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 diff --git a/Makefile.target b/Makefile.target index f7d1919..f738617 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 0d0162a..4a6a9fb 100755 --- a/configure +++ b/configure @@ -221,6 +221,7 @@ kerneldir="" aix="no" blobs="yes" pkgversion="" +user_pie="" # OS specific if check_define __linux__ ; then @@ -498,6 +499,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=*) @@ -672,6 +677,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" @@ -1538,6 +1545,29 @@ elif compile_prog "" "-lrt" ; then LIBS="-lrt $LIBS" fi +########################################## +# Can toolchain generate proper PIE +cat > $TMPC < 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 */