public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Andrew Fish <afish@apple.com>
To: Tim Lewis <tim.lewis@insyde.com>
Cc: edk2-devel@lists.01.org
Subject: Re: Does __attribute__ ((selectany)) make sense now for GCC?
Date: Fri, 18 May 2018 15:38:35 -0700	[thread overview]
Message-ID: <01146E3B-6B4F-4C58-B753-63BFD5ADF3E4@apple.com> (raw)
In-Reply-To: <03b101d3eef6$a5f4dd90$f1de98b0$@insyde.com>

Tim,

Looks like that is only available on Windows versions of GCC, and is more 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 told not to warn about size or content differences of the multiple definitions.
Although the primary usage of this attribute is for POD types, the attribute can also be applied to global C++ objects that are initialized by a constructor. In this case, the static initialization and destruction code 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 guard variable.

The selectany attribute is only available on Microsoft Windows targets. You can use __declspec (selectany) as a synonym for __attribute__ ((selectany)) for compatibility with other compilers.


What I've noticed with clang/LLVM is the unreferenced globals get removed when you enable link time optimizations. 

I'd actually ask the opposite question. Does __declspec(selectany) impact dead code removal on current versions of VC++? 

Thanks,

Andrew Fish

> On May 18, 2018, at 3:22 PM, Tim Lewis <tim.lewis@insyde.com> wrote:
> 
> In Visual Studio we have __declspec(selectany) to limit the impact of unused
> 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 <mailto:edk2-devel@lists.01.org>
> https://lists.01.org/mailman/listinfo/edk2-devel <https://lists.01.org/mailman/listinfo/edk2-devel>


  reply	other threads:[~2018-05-18 22:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-18 22:22 Does __attribute__ ((selectany)) make sense now for GCC? Tim Lewis
2018-05-18 22:38 ` Andrew Fish [this message]
2018-05-18 22:43   ` Tim Lewis
2018-05-18 23:07     ` Andrew Fish
2018-05-21  0:51       ` Gao, Liming

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=01146E3B-6B4F-4C58-B753-63BFD5ADF3E4@apple.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