From patchwork Sun Oct 7 19:20:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 189863 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 52DA82C0269 for ; Mon, 8 Oct 2012 06:20:46 +1100 (EST) Received: from localhost ([::1]:58833 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TKwP6-0004qZ-CM for incoming@patchwork.ozlabs.org; Sun, 07 Oct 2012 15:20:44 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TKwOt-0004ep-L9 for qemu-devel@nongnu.org; Sun, 07 Oct 2012 15:20:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TKwOq-0000Pt-I8 for qemu-devel@nongnu.org; Sun, 07 Oct 2012 15:20:30 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:59830) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TKwOq-0000PF-89 for qemu-devel@nongnu.org; Sun, 07 Oct 2012 15:20:28 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp2so3450551pbb.4 for ; Sun, 07 Oct 2012 12:20:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; bh=x3M3DmFztWxw9OKk0zPHW8k9d2HKoGL1HhdluNi/9mQ=; b=iCAvBY6kSjvBWI69i1DyRhacbiZNBzVQ7hjfUovnOPM29P4pkBvU4DYldjA9Iopm8p 1/cUda85yGzyvHAuR84eA+BXYkQGqaH01gaqN23jfncI+YjjsD8HWJAv53Km3ACjPq9W WqArqdNj8o+Mct/NmoEGhu2dOPYixdkFW6vgMOnqpF31MU68ToO4Iokp4EsiUjnGMSsN sCOxd0ySuPC0paPeed9Lx9nSLPHdPd81PlvEct80RYN7EKk3iFpQ0qIiOfKieyYy0Yj+ SXLCp9P/L153OLB/3dv0oqEQLBfnHkzvFM8h7QquUEDIM96dNWWiIqP6MTHoJyXh6wGW XbAg== Received: by 10.68.203.195 with SMTP id ks3mr47453601pbc.79.1349637627338; Sun, 07 Oct 2012 12:20:27 -0700 (PDT) Received: from anchor.twiddle.home (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPS id w4sm9570917pav.27.2012.10.07.12.20.26 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 07 Oct 2012 12:20:26 -0700 (PDT) Message-ID: <5071D5F9.4010106@twiddle.net> Date: Sun, 07 Oct 2012 12:20:25 -0700 From: Richard Henderson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1 MIME-Version: 1.0 To: Blue Swirl References: <1349386306-24764-1-git-send-email-rth@twiddle.net> In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH] exec: Don't request an address for code_gen_buffer if -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 On 10/07/2012 09:34 AM, Blue Swirl wrote: >> > +#ifdef USE_MMAP >> > + code_gen_buffer = mmap((void *)start, code_gen_buffer_size, >> > + PROT_WRITE | PROT_READ | PROT_EXEC, >> > + flags, -1, 0); >> > + if (code_gen_buffer == MAP_FAILED) { >> > + fprintf(stderr, "Could not allocate dynamic translator buffer\n"); >> > + exit(1); >> > } >> > #else >> > code_gen_buffer = g_malloc(code_gen_buffer_size); >> > map_exec(code_gen_buffer, code_gen_buffer_size); > In this branch (e.g. mingw32), 'start' is unused: > /src/qemu/exec.c: In function 'code_gen_alloc': > /src/qemu/exec.c:531: warning: unused variable 'start' Well, I've rearranged the code to handle this, and it does avoid the warning. But I'm not sure I like the two separate blocks. Especially for the x86_64 MAP32 case. Perhaps we're better off with an __attribute__((unused)) there? r~ diff --git a/exec.c b/exec.c index 8f3bc74..704426c 100644 --- a/exec.c +++ b/exec.c @@ -527,15 +527,14 @@ static void code_gen_alloc(unsigned long tb_size) #else #ifdef USE_MMAP int flags = MAP_PRIVATE | MAP_ANONYMOUS; + uintptr_t start = 0; #endif - uintptr_t max_buf = -1, start = 0; + size_t max_buf = ~(size_t)0; - /* Constrain the size and position of the buffer based on the host cpu. */ + /* Constrain the size of the buffer based on the host cpu. */ #if defined(__x86_64__) -# if !defined(__PIE__) && !defined(__PIC__) && 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; +# if !defined(__PIE__) && !defined(__PIC__) \ + && defined(USE_MMAP) && defined(MAP_32BIT) /* Cannot expect to map more than 800MB in low memory. */ max_buf = 800 * 1024 * 1024; # else @@ -545,22 +544,12 @@ static void code_gen_alloc(unsigned long tb_size) #elif defined(__sparc__) && HOST_LONG_BITS == 64 /* Maximum range of direct branches between TB (via "call"). */ max_buf = 2ul * 1024 * 1024 * 1024; - start = 0x40000000ul; #elif defined(__arm__) /* Keep the buffer no bigger than 16MB to branch between blocks */ max_buf = 16 * 1024 * 1024; #elif defined(__s390x__) - /* Map the buffer so that we can use direct calls and branches. */ /* We have a +- 4GB range on the branches; leave some slop. */ max_buf = 3ul * 1024 * 1024 * 1024; - start = 0x90000000ul; -#endif -#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. */ - start = 0; #endif /* Size the buffer. */ @@ -581,6 +570,23 @@ static void code_gen_alloc(unsigned long tb_size) } #ifdef USE_MMAP + /* 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(__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; +# elif defined(__sparc__) && HOST_LONG_BITS == 64 + start = 0x40000000ul; +# elif defined(__s390x__) + start = 0x90000000ul; +# endif code_gen_buffer = mmap((void *)start, code_gen_buffer_size, PROT_WRITE | PROT_READ | PROT_EXEC, flags, -1, 0);