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 DAA472095DCBE for ; Wed, 23 Aug 2017 03:24:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1430E81E01; Wed, 23 Aug 2017 10:26:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1430E81E01 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-43.phx2.redhat.com [10.3.116.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BDD66048A; Wed, 23 Aug 2017 10:26:48 +0000 (UTC) To: Liming Gao References: <1503475444-6116-1-git-send-email-liming.gao@intel.com> From: Laszlo Ersek Cc: edk2-devel@lists.01.org, "Shi, Steven" , Paolo Bonzini , Ard Biesheuvel , "Jordan Justen (Intel address)" , Michael Kinney Message-ID: <29a70849-7b3e-77ae-5dbc-1f64e4ea8696@redhat.com> Date: Wed, 23 Aug 2017 12:26:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1503475444-6116-1-git-send-email-liming.gao@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 23 Aug 2017 10:26:51 +0000 (UTC) Subject: Re: [Patch] BaseTools: Add the missing -pie link option in GCC tool chain 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: Wed, 23 Aug 2017 10:24:18 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Hi Liming, On 08/23/17 10:04, Liming Gao wrote: > GCC tool chain uses -fpie in CC_FLAGS. So, add -pie in DLINK_FLAGS. > > More discussion in > https://lists.01.org/pipermail/edk2-devel/2017-August/013508.html > > 3.13 Options for Linking > ======================== > '-pie' > Produce a position independent executable on targets that support > it. For predictable results, you must also specify the same set > of options used for compilation ('-fpie', '-fPIE', or model > suboptions) when you specify this linker option. > > 3.18 Options for Code Generation Conventions > ============================================ > '-fpie' > '-fPIE' > These options are similar to '-fpic' and '-fPIC', but generated > position independent code can be only linked into executables. > Usually these options are used when '-pie' GCC option is used > during linking. > '-fpie' and '-fPIE' both define the macros '__pie__' and > '__PIE__'. The macros have the value 1 for '-fpie' and 2 for > '-fPIE'. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Liming Gao > --- > BaseTools/Conf/tools_def.template | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template > index 6076a69..aff0cbd 100755 > --- a/BaseTools/Conf/tools_def.template > +++ b/BaseTools/Conf/tools_def.template > @@ -4502,7 +4502,7 @@ DEFINE GCC44_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z comm > DEFINE GCC44_IA32_X64_ASLDLINK_FLAGS = DEF(GCC44_IA32_X64_DLINK_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable > DEFINE GCC44_IA32_X64_DLINK_FLAGS = DEF(GCC44_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map > DEFINE GCC44_IA32_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220 DEF(GCC_DLINK2_FLAGS_COMMON) > -DEFINE GCC44_X64_DLINK_FLAGS = DEF(GCC44_IA32_X64_DLINK_FLAGS) -Wl,-melf_x86_64,--oformat=elf64-x86-64 > +DEFINE GCC44_X64_DLINK_FLAGS = DEF(GCC44_IA32_X64_DLINK_FLAGS) -Wl,-melf_x86_64,--oformat=elf64-x86-64,-pie > DEFINE GCC44_X64_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x228 DEF(GCC_DLINK2_FLAGS_COMMON) > DEFINE GCC44_ASM_FLAGS = DEF(GCC_ASM_FLAGS) > > @@ -4582,7 +4582,7 @@ DEFINE GCC49_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z comm > DEFINE GCC49_IA32_X64_ASLDLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable > DEFINE GCC49_IA32_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map > DEFINE GCC49_IA32_DLINK2_FLAGS = DEF(GCC48_IA32_DLINK2_FLAGS) > -DEFINE GCC49_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_FLAGS) -Wl,-melf_x86_64,--oformat=elf64-x86-64 > +DEFINE GCC49_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_FLAGS) -Wl,-melf_x86_64,--oformat=elf64-x86-64,-pie > DEFINE GCC49_X64_DLINK2_FLAGS = DEF(GCC48_X64_DLINK2_FLAGS) > DEFINE GCC49_ASM_FLAGS = DEF(GCC48_ASM_FLAGS) > DEFINE GCC49_ARM_ASM_FLAGS = DEF(GCC48_ARM_ASM_FLAGS) > (1) you forgot to CC the participants of the previous thread :) (2) Please add a reference to to the commit message. (3) I tested the GCC49_X64_DLINK_FLAGS change with the following commands, on Fedora 26 (the gcc version is "7.1.1 20170622 (Red Hat 7.1.1-3)"): $ git clean -fdx $ git reset --hard $ . edksetup.sh --reconfig $ make -C "$EDK_TOOLS_PATH" $ build -a X64 -p OvmfPkg/OvmfPkgX64.dsc -t GCC5 -n 6 -b DEBUG $ qemu-system-x86_64 \ -m 5120 \ -smp 8 \ -pflash Build/OvmfX64/DEBUG_GCC5/FV/OVMF.fd \ -enable-kvm \ -global isa-debugcon.iobase=0x402 \ -debugcon file:debug-gcc5-64.fd.log \ -net none The resultant OVMF binary works fine. (The UEFI shell is reached OK.) (4) I regression-tested the GCC44_X64_DLINK_FLAGS change on RHEL-7.4, using "gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)". No regressions were found. Tested-by: Laszlo Ersek Reviewed-by: Laszlo Ersek (5) When you push the patch (possibly after receiving comments from others), please send a reminder for me to revert commit ca56256d5e0b ("OvmfPkg/build.sh: select the GCC49 toolchain settings for gcc-7.*", 2017-08-15). Thanks! Laszlo