From: "Tim Lewis" <tim.lewis@insyde.com>
To: <afish@apple.com>
Cc: <edk2-devel@lists.01.org>
Subject: Re: Does __attribute__ ((selectany)) make sense now for GCC?
Date: Fri, 18 May 2018 15:43:00 -0700 [thread overview]
Message-ID: <040701d3eef9$95563a80$c002af80$@insyde.com> (raw)
In-Reply-To: <01146E3B-6B4F-4C58-B753-63BFD5ADF3E4@apple.com>
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 curious
about.
Tim
From: afish@apple.com <afish@apple.com>
Sent: Friday, May 18, 2018 3:39 PM
To: Tim Lewis <tim.lewis@insyde.com>
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 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
<mailto: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
<mailto:edk2-devel@lists.01.org> edk2-devel@lists.01.org
<https://lists.01.org/mailman/listinfo/edk2-devel>
https://lists.01.org/mailman/listinfo/edk2-devel
next prev parent reply other threads:[~2018-05-18 22:43 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
2018-05-18 22:43 ` Tim Lewis [this message]
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='040701d3eef9$95563a80$c002af80$@insyde.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