From nobody Fri May 3 11:10:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1573882164; cv=none; d=zoho.com; s=zohoarc; b=UYwM85l0FHoN4tJ1sXF/CpT18cp9hGvtATgNfsLCpQ/gdLPQUbFAMW8rgWk40Y/0lgZ5kPstmEIRjqVAoq+XzWqguoUw5TcbB71Sc5CVe0AGAUxJSJSKbXllTpC0SIPDaFIYiBRniZDRoa3u7uSnB373UmetLp8cbobGpaZKP8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573882164; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=r3g7HUON5sc/j7shXGegavmfWXmQJz6lr0xbcS0w7No=; b=OoZGIV4xxR5U07AMgpJkfOSjpTbn8a+tdfA7g9WJOwiWMWVWf8sPvo23sGWMAIh3DM+8b+EMXdoWxuBcr0PQ2HF8BqfJCeJZVVcss5AWQKGcCaGb/lTaDoTsSWiV9hCm1GTKIqeJ5c1PEJEYINYvB7p8CzvEI3FEd8xepI1dsyE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1573882164027249.2550350787136; Fri, 15 Nov 2019 21:29:24 -0800 (PST) Received: from localhost ([::1]:46488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVqe4-0002YP-Un for importer@patchew.org; Sat, 16 Nov 2019 00:29:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42536) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVqdA-00026z-Ar for qemu-devel@nongnu.org; Sat, 16 Nov 2019 00:28:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iVqd8-000625-VN for qemu-devel@nongnu.org; Sat, 16 Nov 2019 00:28:20 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:44266) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iVqd8-00061q-Pa for qemu-devel@nongnu.org; Sat, 16 Nov 2019 00:28:18 -0500 Received: by mail-pf1-f194.google.com with SMTP id q26so7642472pfn.11 for ; Fri, 15 Nov 2019 21:28:18 -0800 (PST) Received: from localhost (c-71-204-169-238.hsd1.ca.comcast.net. [71.204.169.238]) by smtp.gmail.com with ESMTPSA id c13sm11617304pfo.5.2019.11.15.21.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 21:28:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=r3g7HUON5sc/j7shXGegavmfWXmQJz6lr0xbcS0w7No=; b=onFC+fV/L21/nwu3zAAfoRgbyh+RBawGgoVYJAj438BNc7I+nU8sehka+gxGjgNxdt bpUM1inJHOpTzBZeuz8plucegf7YRfyq2U4+XKw80Mer/+dStGEmsUTBv224M4uwucp4 SKQilBcRMyyStyYkvnLOB4rW9EEIdd4P9qmstCSedK5jF5mSC42r6OqthlEPrlMqDI0v s1BKEHvwBBpD9VxMQ70knII83NkqnSUK98cJ0ZC41iTBrfOkgFWgSL+dTXUiJi7uQcS4 fQeBtjSF1fub28LS/iLqYlj8ma4z4HGvFQ5InphM6dX4y2Awv06WfEi+6k0H0Qz1UUQP 2MTA== X-Gm-Message-State: APjAAAW40NPxneAAKxcF/28LKXCwBQbghC6hSmtUyj08jrZM1o9rl7Lt 49H+WRY+5HIahf7iW3/+OJx3ayWV3Rs= X-Google-Smtp-Source: APXvYqx1vpRXpoP5ceS9dc2V3atK0DN+/GqoWZDgAHWyGkZ02bYXCm5iSeD4i1s7y5wkT7SiC/4zWw== X-Received: by 2002:a63:f006:: with SMTP id k6mr20159903pgh.380.1573882097284; Fri, 15 Nov 2019 21:28:17 -0800 (PST) Date: Fri, 15 Nov 2019 21:28:15 -0800 From: Fangrui Song To: qemu-devel@nongnu.org Subject: [PATCH] configure: Use lld --image-base for --disable-pie user mode binaries Message-ID: <20191116052815.nop3xkmd4umqsdsb@google.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20180223-112-0c5bf3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.210.194 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For lld, --image-base is the preferred way to set the base address. lld does not actually implement -Ttext-segment, but treats it as an alias f= or -Ttext. -Ttext-segment=3D0x60000000 combined with --no-rosegment can create a 1.6GB executable. Fix the problem by using --image-base for lld. GNU ld and gold will still get -Ttext-segment. Also delete the ld --verbose fallback introduced in 2013, which is no longer relevant or correct (the default linker script has changed). Signed-off-by: Fangrui Song --- configure | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/configure b/configure index 6099be1d84..2d45af0d09 100755 --- a/configure +++ b/configure @@ -6336,43 +6336,34 @@ fi =20 # Probe for the need for relocating the user-only binary. if ( [ "$linux_user" =3D yes ] || [ "$bsd_user" =3D yes ] ) && [ "$pie" = =3D no ]; then - textseg_addr=3D + image_base=3D case "$cpu" in arm | i386 | ppc* | s390* | sparc* | x86_64 | x32) - # ??? Rationale for choosing this address - textseg_addr=3D0x60000000 + # An arbitrary address that makes it unlikely to collide with user + # programs. + image_base=3D0x60000000 ;; mips) # A 256M aligned address, high in the address space, with enough # room for the code_gen_buffer above it before the stack. - textseg_addr=3D0x60000000 + image_base=3D0x60000000 ;; esac - if [ -n "$textseg_addr" ]; then + if [ -n "$image_base" ]; then cat > $TMPC </dev/null 2>&1; then + image_base_ldflags=3D"-Wl,--image-base=3D$image_base" + if ! compile_prog "" "$image_base_ldflags"; then + image_base_ldflags=3D"-Wl,-Ttext-segment=3D$image_base" + if ! compile_prog "" "$image_base_ldflags"; then error_exit \ "We need to link the QEMU user mode binaries at a" \ "specific text address. Unfortunately your linker" \ - "doesn't support either the -Ttext-segment option or" \ - "printing the default linker script with --verbose." \ + "supports neither --image-base nor -Ttext-segment. " \ "If you don't want the user mode binaries, pass the" \ "--disable-user option to configure." fi - - $ld --verbose | sed \ - -e '1,/=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D/d' \ - -e '/=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D/,$d' \ - -e "s/[.] =3D [0-9a-fx]* [+] SIZEOF_HEADERS/. =3D $textseg_addr + = SIZEOF_HEADERS/" \ - -e "s/__executable_start =3D [0-9a-fx]*/__executable_start =3D $te= xtseg_addr/" > config-host.ld - textseg_ldflags=3D"-Wl,-T../config-host.ld" fi fi fi @@ -7945,7 +7936,7 @@ if test "$gprof" =3D "yes" ; then fi =20 if test "$target_linux_user" =3D "yes" || test "$target_bsd_user" =3D "ye= s" ; then - ldflags=3D"$ldflags $textseg_ldflags" + ldflags=3D"$ldflags $image_base_ldflags" fi =20 # Newer kernels on s390 check for an S390_PGSTE program header and --=20 2.24.0