From: "Gao, Liming" <liming.gao@intel.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
"Shi, Steven" <steven.shi@intel.com>,
"Zhu, Yonghong" <yonghong.zhu@intel.com>,
"Justen, Jordan L" <jordan.l.justen@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [PATCH v2] BaseTools X64: fold PLT relocations into simple relative references
Date: Mon, 8 Aug 2016 03:05:34 +0000 [thread overview]
Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A1155E6144@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <1470407750-28589-1-git-send-email-ard.biesheuvel@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Ard Biesheuvel
> Sent: Friday, August 05, 2016 10:36 PM
> To: Shi, Steven <steven.shi@intel.com>; Zhu, Yonghong
> <yonghong.zhu@intel.com>; Gao, Liming <liming.gao@intel.com>; Justen,
> Jordan L <jordan.l.justen@intel.com>; edk2-devel@lists.01.org
> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Subject: [edk2] [PATCH v2] BaseTools X64: fold PLT relocations into simple
> relative references
>
> For X64/GCC, we use position independent code with hidden visibility
> to inform the compiler that symbols references are never resolved at
> runtime, which removes the need for PLTs and GOTs. However, in some
> cases GCC has been reported to still emit PLT based relocations, which
> we need to handle in the ELF to PE/COFF perform by GenFw.
>
> Unlike GOT based relocations, which are non-trivial to handle since the
> indirections in the code can not be fixed up easily (although relocation
> types exist for X64 that annotate relocation targets as suitable for
> relaxation), PLT relocations simply point to jump targets, and we can
> relax such relocations by resolving them using the symbol directly rather
> than via a PLT entry that does nothing more than tail call the function
> we already know it is going to call (since all symbol references are
> resolved in the same module).
>
> So handle R_X86_64_PLT32 as a R_X86_64_PC32 relocation.
>
> Suggested-by: Steven Shi <steven.shi@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> BaseTools/Source/C/GenFw/Elf64Convert.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c
> b/BaseTools/Source/C/GenFw/Elf64Convert.c
> index 944c94b8f8b4..708c1a1d91a7 100644
> --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
> +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
> @@ -785,6 +785,17 @@ WriteSections64 (
> *(INT32 *)Targ = (INT32)((INT64)(*(INT32 *)Targ) - SymShdr->sh_addr
> + mCoffSectionsOffset[Sym->st_shndx]);
> VerboseMsg ("Relocation: 0x%08X", *(UINT32*)Targ);
> break;
> +
> + case R_X86_64_PLT32:
> + //
> + // Treat R_X86_64_PLT32 relocations as R_X86_64_PC32: this is
> + // possible since we know all code symbol references resolve to
> + // definitions in the same module (UEFI has no shared libraries),
> + // and so there is never a reason to jump via a PLT entry,
> + // allowing us to resolve the reference using the symbol directly.
> + //
> + VerboseMsg ("Treating R_X86_64_PLT32 as R_X86_64_PC32 ...");
> + /* fall through */
> case R_X86_64_PC32:
> //
> // Relative relocation: Symbol - Ip + Addend
> @@ -935,6 +946,7 @@ WriteRelocations64 (
> switch (ELF_R_TYPE(Rel->r_info)) {
> case R_X86_64_NONE:
> case R_X86_64_PC32:
> + case R_X86_64_PLT32:
> break;
> case R_X86_64_64:
> VerboseMsg ("EFI_IMAGE_REL_BASED_DIR64 Offset: 0x%08X",
> --
> 2.7.4
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
prev parent reply other threads:[~2016-08-08 3:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-05 14:35 [PATCH v2] BaseTools X64: fold PLT relocations into simple relative references Ard Biesheuvel
2016-08-08 3:05 ` Gao, Liming [this message]
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=4A89E2EF3DFEDB4C8BFDE51014F606A1155E6144@shsmsx102.ccr.corp.intel.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