From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5A11E2063D756 for ; Sun, 20 May 2018 17:51:59 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 May 2018 17:51:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,425,1520924400"; d="scan'208";a="230154969" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga005.fm.intel.com with ESMTP; 20 May 2018 17:51:58 -0700 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 20 May 2018 17:51:58 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx109.amr.corp.intel.com (10.18.116.9) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 20 May 2018 17:51:58 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.240]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.210]) with mapi id 14.03.0319.002; Mon, 21 May 2018 08:51:56 +0800 From: "Gao, Liming" To: Andrew Fish , Tim Lewis CC: "edk2-devel@lists.01.org" Thread-Topic: [edk2] Does __attribute__ ((selectany)) make sense now for GCC? Thread-Index: AdPu9mNaq0U5HhCQSYSVpekIn2LMEv//fwaAgAABPACAAAbBAP/8Of0w Date: Mon, 21 May 2018 00:51:54 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E22C7CD@SHSMSX104.ccr.corp.intel.com> References: <03b101d3eef6$a5f4dd90$f1de98b0$@insyde.com> <01146E3B-6B4F-4C58-B753-63BFD5ADF3E4@apple.com> <040701d3eef9$95563a80$c002af80$@insyde.com> <0E83E7B9-AA12-4921-A7A2-ABA9DBD8D2AA@apple.com> In-Reply-To: <0E83E7B9-AA12-4921-A7A2-ABA9DBD8D2AA@apple.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.200.100 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: Does __attribute__ ((selectany)) make sense now for GCC? 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: Mon, 21 May 2018 00:51:59 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Andrew: VS has added /Gw option to Optimize Global Data since VS2013. With /Gw op= tion, __declspec(selectany) is not used any more. Now, __declspec(selectany= ) is kept for old VS tool chain. So, I suggest GCC uses its native optimiza= tion option instead of it.=20 Thanks Liming > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of An= drew Fish > Sent: Saturday, May 19, 2018 7:07 AM > To: Tim Lewis > Cc: edk2-devel@lists.01.org > Subject: Re: [edk2] Does __attribute__ ((selectany)) make sense now for G= CC? >=20 > Tim, >=20 > VC++ is a strange beast. See C99 support. VC++ seems to do strange thing= s to support non standard hackyness of years past. So the > only reason I can think of that __attribute__ ((selectany)) is associate= d with dead stripping, is doing it correctly broke some chunk of > code that was required for compatibility. From looking on the VC++ site i= t seems like COMDAT folding may be required for dead code > removal, but again this not required to make it work, but to not break ol= d crufty stuff. >=20 > I guess on Windows GCC they could trying to "copy exact" VC++ behavior, b= ut it is most definitely going to be ignored on the > non-Windows versions. >=20 > The answer from Microsoft on C99 is to use clang :) >=20 > Thanks, >=20 > Andrew Fish >=20 > > On May 18, 2018, at 3:43 PM, Tim Lewis wrote: > > > > Andrew - > > > > > > > > I know for Visual Studio it does the same thing for data that /Gy does = for > > code. > > > > > > > > That is, if the data is unreferenced, then it doesn't get brought it. > > > > > > > > Maybe link-time code generation has the same effect. That's what I'm cu= rious > > about. > > > > > > > > Tim > > > > > > > > From: afish@apple.com > > > Sent: Friday, May 18, 2018 3:39 PM > > To: Tim Lewis > > > Cc: edk2-devel@lists.01.org > > Subject: Re: [edk2] Does __attribute__ ((selectany)) make sense now for= GCC? > > > > > > > > Tim, > > > > > > > > Looks like that is only available on Windows versions of GCC, and is mo= re > > about compatible behavior. > > > > > > > > selectany > > > > The selectany attribute causes an initialized global variable to have > > link-once semantics. When multiple definitions of the variable are > > encountered by the linker, the first is selected and the remainder are > > discarded. Following usage by the Microsoft compiler, the linker is tol= d not > > to warn about size or content differences of the multiple definitions. > > > > Although the primary usage of this attribute is for POD types, the attr= ibute > > can also be applied to global C++ objects that are initialized by a > > constructor. In this case, the static initialization and destruction co= de > > for the object is emitted in each translation defining the object, but = the > > calls to the constructor and destructor are protected by a link-once gu= ard > > variable. > > > > The selectany attribute is only available on Microsoft Windows targets.= You > > can use __declspec (selectany) as a synonym for __attribute__ ((selecta= ny)) > > for compatibility with other compilers. > > > > > > > > What I've noticed with clang/LLVM is the unreferenced globals get remov= ed > > when you enable link time optimizations. > > > > > > > > I'd actually ask the opposite question. Does __declspec(selectany) impa= ct > > dead code removal on current versions of VC++? > > > > > > > > Thanks, > > > > > > > > Andrew Fish > > > > > > > > > > > > On May 18, 2018, at 3:22 PM, Tim Lewis > > > wrote: > > > > > > > > In Visual Studio we have __declspec(selectany) to limit the impact of u= nused > > data. > > > > > > > > I see that GCC for Windows has __attribute__ ((selectany)). > > > > > > > > Should we me using this for GLOBAL_REMOVE_IF_UNREFERENCED in > > MdePkg\Include\Base.h? > > > > > > > > Tim > > > > _______________________________________________ > > edk2-devel mailing list > > > edk2-= devel@lists.01.org > > > > > https://lists.01.org/mailman/listinfo/edk2-devel > > > > > > > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel