public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Liming Gao <liming.gao@intel.com>
Cc: edk2-devel@lists.01.org, "Shi, Steven" <steven.shi@intel.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	"Jordan Justen (Intel address)" <jordan.l.justen@intel.com>,
	Michael Kinney <michael.d.kinney@intel.com>
Subject: Re: [Patch] BaseTools: Add the missing -pie link option in GCC tool chain
Date: Wed, 23 Aug 2017 12:26:47 +0200	[thread overview]
Message-ID: <29a70849-7b3e-77ae-5dbc-1f64e4ea8696@redhat.com> (raw)
In-Reply-To: <1503475444-6116-1-git-send-email-liming.gao@intel.com>

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 <liming.gao@intel.com>
> ---
>  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
<https://bugzilla.tianocore.org/show_bug.cgi?id=671> 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 <lersek@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>

(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


  reply	other threads:[~2017-08-23 10:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23  8:04 [Patch] BaseTools: Add the missing -pie link option in GCC tool chain Liming Gao
2017-08-23 10:26 ` Laszlo Ersek [this message]
2017-08-23 14:06   ` Gao, Liming
2017-08-24 13:25 ` Zhu, Yonghong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=29a70849-7b3e-77ae-5dbc-1f64e4ea8696@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox