From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.163.190.148; helo=sonic315-22.consmr.mail.ne1.yahoo.com; envelope-from=zenith432@users.sourceforge.net; receiver=edk2-devel@lists.01.org Received: from sonic315-22.consmr.mail.ne1.yahoo.com (sonic315-22.consmr.mail.ne1.yahoo.com [66.163.190.148]) (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 D09F2210DA7A9 for ; Wed, 6 Jun 2018 23:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1528351476; bh=Rn4xXGTr9GF8PUUDF63d43V+Ikzun1BbQkceHO+C0eY=; h=Date:From:Reply-To:To:Cc:Subject:References:From:Subject; b=Fpuif23TQPsZ0lpNsBAURmQ7BrPvA68R5KpaipzBMuBnksTenEyBpZt/G/Rcd1YkW4KY+mfRCWMdCjIRzAtodEircGDEilZuUC/txyC3o211ObwhM2O1tX1ceTpU6ouhTPp5p4ZKNOPTh9izGugIMYOaAudxQslqDpW/eFMgSrTPmVmi4E+GENaD4r+ImrT7C9tiJgTtlAJOp+jXRlxh5ZT3our4MBeUJnQ1KVjE/EA0wKrtmcf+J4j289x8Z0VdJE45FPjWV6wJhVzb2+h+v+8NsyD5SHRVngGS2ZvG09cN7TwzXYTQOrQeWOvoAG7JaVIZ32XdhiLjRrAUln2qQg== X-YMail-OSG: O9uFUmoVM1lmmgsH0NreQXfHtnj23fcGvlLfSBH1nA7ItgBdlZ9vljNXVtjX88c qC_gMq1worRgeN4ZoPDze8K5KLiPkImmiH.pOjRep8OCdHj_UHlbojwFD.CmABBirSMVKPhDv_5M rUVWioHpSVUlvf8sQ9RWFMoZqY.zuxO8SSqn1uf4fty9vHVVjNTh226AiZ9gc9O1mCSjebL2uXhy hRIqxlP.sjMaVKY4H2CN2RGXUHtvpMmzgsFunx1RPsmzWg1HyFBlIbjxmJJNbAqleDX7RRWrxWiA zUgr7Ezj0dCPEDPZIZc7oZAJcjuNrmYpewYma3V7oweRmEx6.XxqhvRD6n359PhqfT_EGLEPeScd UBcO1nwmgW8cf3_lBYI5sxkt3uVqcLyGYp.ebKsHPROLURYqFbW_A1IFNtbMGU.SxV7VpuyETR2E DhpmdrHEhdUVghAD0Qai0yD.B35eyRRK8AuH.XesXfSIXhiFJZX9cAye4FB6AGDQ6UuPtpMH6X64 j9TK3UlXOPIPXT2s6nsdMHgVGLCSnEHsZnpXerwIz5uCi3.XMCb898.chV04F0M7UUPRnmdK2ItW 5NS3XjmQdFr75DmNwiKzPyqVfvK5ZP0j4c8G2ZdeVun6linz_cYJyD2YH9Z1u9CBwRQjo1tFJKK7 t6._EIdRtfVb5ib9N5zyZzvBSf.I_9_6Z9fKWVR.VqL6Z8tXClZ2N9p8H05ICFkQaFwfX7UhdS3x 2MC9Hkezbybo0cmKk.4YrJtpbif0f4Km8qjMdVznYYhtgYwGOBiJQc.O.aFrAoKF_VOdzZbMbEmQ Js7B0FpFoh_p7k4P_E6uqTnXKAHMr_PGlAp_mB4iqjuPS8dWuUthrHiUEtwdNATeLAtEni1A2Ksl UDSEn8fzNCfxoPdzd3eqfogrS8YDYQXXOGabR0TnZEGeioddyBTkU4BqeFNR_6c2S0RdCmWEDjlC 39g-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.ne1.yahoo.com with HTTP; Thu, 7 Jun 2018 06:04:36 +0000 Date: Thu, 7 Jun 2018 06:04:33 +0000 (UTC) From: Zenith432 Reply-To: Zenith432 To: LimingGao Cc: StevenShi , YonghongZhu , "edk2-devel@lists.01.org" Message-ID: <1501305711.1573406.1528351473858@mail.yahoo.com> MIME-Version: 1.0 References: <1501305711.1573406.1528351473858.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] 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: Thu, 07 Jun 2018 06:04:37 -0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit This issue only applies to GCC/ELF target. When using -fpie ("small pie" model which is GCC extension to SYSV ABI) - eliminates nearly all emission of GOTPCREL in object code (= loading addresses from the GOT.) However, when optimizing for size (-Os), sometimes emitted code only needs to compute address of external symbol, not access data under it. For example, when doing pointer arithmetic or passing address as an argument - the code generator concludes that loading the address from GOT is beneficial to reduced code size (since address can be loaded from GOT using push or add instructions, not just mov instruction.) It then occasionally emits GOTPCREL. The emission of GOTPCREL is completely suppressed by putting __attribute__((visibility("hidden")) on declaration of external symbol, or using #pragma GCC push visibility("hidden") to achieve this on all exernal symbols. This is included in MdePkg/Include/X64/ProcessorBind.h - however only turned on for non-LTO builds. When using "-flto -DUSING_LTO" - GCC can sometimes emit GOTPCREL for pointer arithmetic on external symbols. I have instance of this which is not part of EDK2 (the GOTPCREL is emitted when "-flto -DUSING_LTO" is enabled.) There is also an instance of emitted PCREL occuring when building OvmfX64.dsc if using "-fno-lto -DUSING_LTO" (i.e. no LTO, but suppress the #pragma). Adding GOTPCREL support to GenFw can handle a few occasional cases if this relocation is emitted by GCC. I no longer ask that "#pragma GCC push visibility("hidden")" be removed for non-LTO builds, although it's a sweeping solution because if affects all symbols. It is enough to put __attribute__((visibility("hidden")) on affected symbols. Additionally, maybe scope be reduced with "#if defined(__GNUC__) && !defined(__clang__) && defined(__ELF__)" instead of "#if defined(__GNUC__)" so pragma affects only GCC/ELF. I don't have any standalone samples that are not part of a large build. If you want standalone test cases - I only have time next week to construct some. As for the code itself - I did test of course on the cases that occur in the build. - Patch is constructed so that if no GOTPCREL are found in ELF binary - there's no effect on today's function of GenFw other then testing for NULL in a couple of places in function WriteLocation64. In this sense the patch is safe - does not affect function of GenFw on previously suppoted ELF binaries that already works. For ELF binaries with GOTPCREL today GenFw breaks with an error. - ELF with multiple text or data sections is supported. However, the order of events in the added code the patch makes to WriteSection64 depends on text sections being processed first and GOT being emitted in one of the text sections. This is the case today (ld script emits GOT in .text). I don't believe this is likely to change, however, if it's important to elminate this minor order dependence - I can do so. - I hope someone reviews the code carefully :) - I see other patches to Elf64Convert.c were posted so this patch probably needs merging before commit. Regards -------------------------------------------- On Thu, 6/7/18, Gao, Liming wrote: Subject: RE: [PATCH] BaseTools/GenFw: Add X64 GOTPCREL Support to GenFw To: "Zenith432" , "edk2-devel@lists.01.org" Cc: "Shi, Steven" , "Zhu, Yonghong" Date: Thursday, June 7, 2018, 4:32 AM What's purpose to support GOTPCREL in GenFw? Could you introduce your usage model?