From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 76A4F21CFA600 for ; Tue, 22 Aug 2017 07:13:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB4331F570; Tue, 22 Aug 2017 14:15:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AB4331F570 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=pbonzini@redhat.com Received: from [10.36.116.244] (ovpn-116-244.ams2.redhat.com [10.36.116.244]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2BA4486E85; Tue, 22 Aug 2017 14:15:51 +0000 (UTC) To: Ard Biesheuvel Cc: Laszlo Ersek , "Shi, Steven" , edk2-devel-01 , Alex Williamson , "Justen, Jordan L" , "Gao, Liming" , "Kinney, Michael D" References: <20170811003426.2332-1-lersek@redhat.com> <20170811003426.2332-2-lersek@redhat.com> <06C8AB66E78EE34A949939824ABE2B313B560EB2@shsmsx102.ccr.corp.intel.com> <787f4528-980e-8c71-2804-0e8be2c935aa@redhat.com> <06C8AB66E78EE34A949939824ABE2B313B56176B@shsmsx102.ccr.corp.intel.com> <092446e6-0900-7eb3-d071-b88abcdadfa9@redhat.com> <06C8AB66E78EE34A949939824ABE2B313B5673A1@shsmsx102.ccr.corp.intel.com> <3c593a67-bffc-45db-e65c-8d0242ddada4@redhat.com> From: Paolo Bonzini Message-ID: Date: Tue, 22 Aug 2017 16:15:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 22 Aug 2017 14:15:56 +0000 (UTC) Subject: Re: [PATCH 1/1] BaseTools/tools_def.template: revert to large code model for X64/GCC5/LTO X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Aug 2017 14:13:24 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 22/08/2017 16:03, Ard Biesheuvel wrote: > On 22 August 2017 at 14:27, Paolo Bonzini wrote: >> On 22/08/2017 13:59, Laszlo Ersek wrote: >>> This seems to suggest that "-pie" is the *master* switch (used only when >>> linking), and "-fpie" is a *prerequisite* for it (to be used both when >>> linking and compiling). Is this right? >>> >>> If so, then I think this is a gcc usability bug. We don't generally >>> start our thinking from the linker side. The above implies that the >>> simple (hosted) command line: >>> >>> $ gcc -o example -fpie source1.c source2.c >>> >>> could also result in miscompilation, because "-pie" is not given, only >>> "-fpie". >> >> No, GCC should add -pie on its own. >> > > I disagree. PIE linking and PIE code generation are two completely > different things. What I'm saying is that GCC should add -pie on its own if you add -fpie to the linker command line. But that would require changes to the compiler driver. That said, the extra "-Wl," in "-Wl,-pie" is not necessary; the compiler driver knows "-pie" and swallows it when compiling (and passes it to the linker). Paolo > PIE linking (in the absence of LTO) only involves emitting the > sections containing the metadata required by the loader at runtime. > Because dynamic ELF relocations are more restricted than static ones, > and only operate on native pointer sized quantities, this imposes > constraints on the code generation, which is why we need the -fpic or > -fpie compiler switch. On ARM, this means you should not emit absolute > symbol references where the address is encoded in the immediate field > of a sequence of movw/movt/movz/movk instructions. I'm sure there are > similar restrictions on other architectures. Note that the arm64 KASLR > kernel does use PIE linking but omits -fpic/-fpie simply because the > default small code model never uses such instructions, but always uses > relative references (and statically initialized function pointers etc > are guaranteed to be dynamically relocatable) > > IIRC, PIE linking predates the availability of the -fpie GCC flag, and > so -fpic objects were used to create PIE binaries, because they > happened to fulfil these requirements, given that they apply to shared > libraries as well. However, -fpic is geared towards ELF symbol > preemption and other restrictions that do apply to shared libraries > but not to PIE executables, and so the -fpie switch was introduced as > an alternative, which generates code that may not be suitable for a > shared library but can be used in a PIE or ordinary executable. > > None of this really applies to bare metal binaries, which is why we > need the visibility tweaks when using -fpic/-fpie, in which case the > compiler will relative references over absolute ones. Such objects > could be combined in different ways, and PIE linking is only one of > them. >