From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ml01.01.org (Postfix) with ESMTP id 068561A1E0F for ; Sun, 7 Aug 2016 20:05:36 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 07 Aug 2016 20:05:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,487,1464678000"; d="scan'208";a="745573472" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by FMSMGA003.fm.intel.com with ESMTP; 07 Aug 2016 20:05:36 -0700 Received: from fmsmsx102.amr.corp.intel.com (10.18.124.200) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 7 Aug 2016 20:05:36 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX102.amr.corp.intel.com (10.18.124.200) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 7 Aug 2016 20:05:36 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.147]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.181]) with mapi id 14.03.0248.002; Mon, 8 Aug 2016 11:05:34 +0800 From: "Gao, Liming" To: Ard Biesheuvel , "Shi, Steven" , "Zhu, Yonghong" , "Justen, Jordan L" , "edk2-devel@lists.01.org" Thread-Topic: [edk2] [PATCH v2] BaseTools X64: fold PLT relocations into simple relative references Thread-Index: AQHR7ybAypqQQYtvnEeQICTB0y7xwKA+ZRvQ Date: Mon, 8 Aug 2016 03:05:34 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A1155E6144@shsmsx102.ccr.corp.intel.com> References: <1470407750-28589-1-git-send-email-ard.biesheuvel@linaro.org> In-Reply-To: <1470407750-28589-1-git-send-email-ard.biesheuvel@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2] BaseTools X64: fold PLT relocations into simple relative references X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Aug 2016 03:05:37 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----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 ; Zhu, Yonghong > ; Gao, Liming ; Justen, > Jordan L ; edk2-devel@lists.01.org > Cc: Ard Biesheuvel > Subject: [edk2] [PATCH v2] BaseTools X64: fold PLT relocations into simpl= e > relative references >=20 > 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. >=20 > 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). >=20 > So handle R_X86_64_PLT32 as a R_X86_64_PC32 relocation. >=20 > Suggested-by: Steven Shi > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ard Biesheuvel > --- > BaseTools/Source/C/GenFw/Elf64Convert.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) >=20 > 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 =3D (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 i= s > + // possible since we know all code symbol references resolve= to > + // definitions in the same module (UEFI has no shared librar= ies), > + // and so there is never a reason to jump via a PLT entry, > + // allowing us to resolve the reference using the symbol dir= ectly. > + // > + 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 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel