From patchwork Tue Oct 16 07:30:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 191747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 124CF2C009A for ; Tue, 16 Oct 2012 18:31:05 +1100 (EST) Received: from localhost ([::1]:49238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TO1cF-000443-40 for incoming@patchwork.ozlabs.org; Tue, 16 Oct 2012 03:31:03 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TO1bu-0003f4-Aj for qemu-devel@nongnu.org; Tue, 16 Oct 2012 03:30:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TO1bp-0001pr-Pd for qemu-devel@nongnu.org; Tue, 16 Oct 2012 03:30:42 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:51531) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TO1bp-0001pC-JN for qemu-devel@nongnu.org; Tue, 16 Oct 2012 03:30:37 -0400 Received: by mail-pa0-f45.google.com with SMTP id fb10so5591558pad.4 for ; Tue, 16 Oct 2012 00:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=EbDxP1OowjR0AxDJuxOXudz94S+9smDH8fiPZQlZqLY=; b=Ua9as1hj2avYGv23VBVE9q/OeE2+xH2Jphf0+8MsB+cZcPYDxq4dp6hr6ZghZFJXAB R/oNB4mgGLDxRE6thbxaodsQCrCmD4JL+H13ZRa1q08cWRyIt69buJDGlGvoXayVM8ww nB1hBSX2zRIASRoalKIcc7vsMb+QdQKugUJE68w3j5gOaqQj/7p7OUrXb3LvwsDCToYR 3i8OaOP2JIhn1OP0DmCMsl23WPpRlPGqGKrBSmWne2v8QsLH63/C3CrZ9TLbOXYX0CsW tLgLSkg8E2V5qVOa4HmYqiR2i86WPcKwmxiBDz6J8mmFG7hmW6H+AERhUe0ZOHdSkokK 2iSQ== Received: by 10.68.229.194 with SMTP id ss2mr44732630pbc.17.1350372637170; Tue, 16 Oct 2012 00:30:37 -0700 (PDT) Received: from pebble.twiddle.home ([1.141.46.32]) by mx.google.com with ESMTPS id jw14sm10364647pbb.36.2012.10.16.00.30.34 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 16 Oct 2012 00:30:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 16 Oct 2012 17:30:12 +1000 Message-Id: <1350372614-30041-4-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1350372614-30041-1-git-send-email-rth@twiddle.net> References: <1350372614-30041-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.220.45 Cc: blauwirbel@gmail.com Subject: [Qemu-devel] [PATCH 3/5] exec: Do not use absolute address hints for code_gen_buffer with -fpie X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The hard-coded addresses inside alloc_code_gen_buffer only make sense if we're building an executable that will actually run at the address we've put into the linker scripts. When we're building with -fpie, the executable will run at some random location chosen by the kernel. We get better placement for the code_gen_buffer if we allow the kernel to place the memory, as it will tend to to place it near the executable, based on the PROT_EXEC bit. Since code_gen_prologue is always inside the executable, this effect is easily seen at the end of most TB, with the exit_tb opcode, and with any calls to helper functions. Signed-off-by: Richard Henderson --- exec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 6c0b2d7..5e33a3d 100644 --- a/exec.c +++ b/exec.c @@ -578,7 +578,12 @@ static inline void *alloc_code_gen_buffer(void) /* Constrain the position of the buffer based on the host cpu. Note that these addresses are chosen in concert with the addresses assigned in the relevant linker script file. */ -# if defined(__x86_64__) && defined(MAP_32BIT) +# if defined(__PIE__) || defined(__PIC__) + /* Don't bother setting a preferred location if we're building + a position-independent executable. We're more likely to get + an address near the main executable if we let the kernel + choose the address. */ +# elif defined(__x86_64__) && defined(MAP_32BIT) /* Force the memory down into low memory with the executable. Leave the choice of exact location with the kernel. */ flags |= MAP_32BIT;