From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.163.191.147; helo=sonic304-21.consmr.mail.ne1.yahoo.com; envelope-from=zenith432@users.sourceforge.net; receiver=edk2-devel@lists.01.org Received: from sonic304-21.consmr.mail.ne1.yahoo.com (sonic304-21.consmr.mail.ne1.yahoo.com [66.163.191.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6124D2112A295 for ; Fri, 8 Jun 2018 04:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1528455979; bh=l8ktEhkhBLl49nTKJwliWlcsqEa5cUINMtJrZL51mi8=; h=Date:From:Reply-To:To:Cc:Subject:References:From:Subject; b=L1Qv0TzCEEO7k1630ELEV2J8RmzrV0ZZJSvl2X87tMi25lnnfQ12vTkoFijO1s3Eb1poIQ/xb5pnqMf0pvh1kmRVf+w+e4IIonka3UtKiTD4okNagB6wDYsMUakY0FvUxtH61BA6EHdMEbvuOHnbEYS/L/xcA69/c3M9axvj4omr8K5orkMNCT++Myc1H/OStvkWHhifK++Non0ICAii8SI+IVIWoQ9YBez9mkW9anwPH5NYg7+BHeWAFSGMNxBRyPjqQEkRKujWPekKcfKpNufy8MMQ6pf+3m77bAuLC6VAJyCbKvGnpMOVy/+TPMFETx6fIyvv0BAq6DQvDIqaPQ== X-YMail-OSG: nrlAo0EVM1kZMlP4D.RMuXj43LjPnSMmYZV0dzvvv_8Ep3E2cxOypbH4x9GZ62e hYbVHyXIqHAhUrxDzIi9m8eJf3NkIYN_i0U0SUN.3I4Wg62AY8.oK9MY3N2mVrK_codYFWGWTUed soeDHOlq8qXEssYUb7DU_KfGmd8Ef3fsnNTw16rdHT6q2uI_PmueK25.zuM0Yo4BY7_NnGOL2O6C hA1gPhxSnI_YWOq9m9GS4ugJg2Gs4gW.D3X9WzTnF006Aj8pQFP6MbAwIxg5QpnfPslhui5VtexR o.PQvLKf0wIlA_FxA8jlc_g1WK2.SzHP9tSf4s_isEl8cjkz0Cm8GtlGZMutW1WzV.MMIf6D6sHQ wtWApJTkdqHVH1iV.GvtZJvzxoEGuGyIG5AnLwKQGB0fLfefkXKFLKsRnrLc2ksS.1wBE1kCiie1 Tro8ProVSLIBBLmvcjDfeeUT4HDM7XtWsr_CkfC8i0vrJgIhhJFreZ3_bJoXgm3YuXa_QRxpQiLB 9b9j4Qqqw.mNOjuBfeEUiwdTyydYumSjPjyxYVTGTU0QJn_b0uzEIcvBImVhJnPMOcQQDqXlvw6d 9f3bOft1zAhdA3Sw7U6LNlcCHVcTVBTiN8AV7BdYNncxcUlowfI1nK1D.Rhu2XA6Wy2qkg3X0XBY whanaCr6lfKbcCZsl5HXPag6QWrInUzxSGtb9PMv3tLYXnnGwYApQzo6P4SqT21nR2Ub5PFwsywS Q.MBZNhUi1L7iuaQcZVV5M0eFIHB324VIDYg_TWDSZPw26xajsO.vUXn2MyPEOC56xWZRxXNffB7 ItYugWyrL6GVQWfV.ChsV3tANQdX.CEf_uKQVLMc5mpic43bAzgpSuLvs7Zqij7.jKD1r7V2QgkY R5TnKP3E6dV8PN9S6fQ5Tzwvpe4hRZVGmk4WAhrsaozwd4kgkYg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Fri, 8 Jun 2018 11:06:19 +0000 Date: Fri, 8 Jun 2018 11:06:16 +0000 (UTC) From: Zenith432 Reply-To: Zenith432 To: Andrew Fish Cc: "edk2-devel@lists.01.org" , LimingGao Message-ID: <1761571963.2244772.1528455976855@mail.yahoo.com> MIME-Version: 1.0 References: <1761571963.2244772.1528455976855.ref@mail.yahoo.com> X-Mailer: WebService/1.1.11950 YahooMailBasic Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0 Subject: Re: [PATCH v2] BaseTools/GenFw: Add X64 GOTPCREL Support to GenFw X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jun 2018 11:06:21 -0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit It's a byproduct of aggressive GCC optimization for size -Os GCC's code generator loads extern symbol addresses from the GOT when they produce smaller code. 1) When passing a pointer to an extern function as a non-register argument to another function it uses pushq instruction pushq function@GOTPCREL(%rip) This is shorter code than computing the address of function in register using leaq instruction, then pushing register. It also saves the use of a register. There are 5 instances of this construct in MdeModulePkg when building OvmgPkgX64.dsc, but I don't have my notes to list them here. 2) When doing pointer arithmetic on extern symbols using addq, subq, cmpq with operand stored in the GOT. This code in MdeModulePkg/Core/Pei/PeiMain/PeiMain.c - ShadowPeiCore return (PEICORE_FUNCTION_POINTER)((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint); emits a subq from the GOT entry for _ModuleEntryPoint. The way things stand today is that when doing non-LTO GCC build, #pragma GCC push visibility("hidden") tells the compiler not to assume the existence of GOT entries for extern symbols and eliminates all GOT loads. For the LTO build, it was found that this breaks the build. So the pragma is active only for non-LTO build. For LTO build it was found that all above instances of GOT loads in MdeModulePkg disappear due to different code generation selected by LTO. However, LTO build (without the pragma) can still emit GOT loads to carry out pointer arithmetic done on extern symbols. I have sample of this which is not in EDK2 codebase, and I hope to make a standalone test case of it. My reasoning for adding this capability to GenFw is similar to the reasoning here https://bugzilla.tianocore.org/show_bug.cgi?id=955 which is that if the latter build stage (GenFw) can handle anything GCC + binutils-ld throw it then it's not necessary to find the right compiler tweak to suppress the generation of unhandled product anymore. As a side note, I tested that my patch to GenFw works right on all the GOTPCRELs emitted in build of OvmfPkgX64.dsc. -------------------------------------------- On Fri, 6/8/18, Andrew Fish wrote: Subject: Re: [edk2] [PATCH v2] BaseTools/GenFw: Add X64 GOTPCREL Support to GenFw To: "Zenith432" Cc: "edk2-devel@lists.01.org" , "LimingGao" Date: Friday, June 8, 2018, 7:02 AM Zenith, Stupid question, I'm not trying to derail the code review..... In a static lib world like EFI, I can't figure out why we need support for GOT PC REL addressing modes? I say that as I would think they would be relocation entries in object files, and then the final link would happen and these relocation types would not be required in the final executable? Seems like the linker, at link time, would know the relative offset for all the static libraries that got linked together (edk2 build) and there is no need for a relocation. So I want to make sure this is not an issue caused by the wrong linker flags (emitting relocation for dynamic libs that is not supported in EF)? I'll freely admit there could be some circumstances I don't understand that require this support, but I just want to make sure we understand why we need to do it. Or maybe I'm missing something fundamental?