public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* used vs retain attribute
@ 2021-07-04 17:31 NightStrike
  2021-07-07 10:51 ` Kewen.Lin
  0 siblings, 1 reply; 2+ messages in thread
From: NightStrike @ 2021-07-04 17:31 UTC (permalink / raw)
  To: gcc-help

Which of these is correct?

1) The manual states:

used

This attribute, attached to a variable with static storage, means that
the variable must be emitted even if it appears that the variable is
not referenced.

When applied to a static data member of a C++ class template, the
attribute also means that the member is instantiated if the class
itself is instantiated.

retain

For ELF targets that support the GNU or FreeBSD OSABIs, this attribute
will save the variable from linker garbage collection. To support this
behavior, variables that have not been placed in specific sections
(e.g. by the section attribute, or the -fdata-sections option), will
be placed in new, unique sections.

This additional functionality requires Binutils version 2.36 or later.




2) The gcc 11 changes website (https://gcc.gnu.org/gcc-11/changes.html) states:

For ELF targets that support the GNU or FreeBSD OSABIs, the used
attribute will now save the symbol declaration it is applied to from
linker garbage collection.

To support this behavior, used symbols that have not been placed in
specific sections (e.g. with the section attribute, or the
-f{function,data}-sections options) will be placed in new, unique
sections.

This functionality requires Binutils version 2.36 or later.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: used vs retain attribute
  2021-07-04 17:31 used vs retain attribute NightStrike
@ 2021-07-07 10:51 ` Kewen.Lin
  0 siblings, 0 replies; 2+ messages in thread
From: Kewen.Lin @ 2021-07-07 10:51 UTC (permalink / raw)
  To: NightStrike; +Cc: gcc-help, jozef.l

Hi,

on 2021/7/5 上午1:31, NightStrike via Gcc-help wrote:
> Which of these is correct?
> 

IIUC the quoted content in gcc-11 changes is stale and wrong.
Good catch!

> 1) The manual states:
> 
> used
> 
> This attribute, attached to a variable with static storage, means that
> the variable must be emitted even if it appears that the variable is
> not referenced.
> 
> When applied to a static data member of a C++ class template, the
> attribute also means that the member is instantiated if the class
> itself is instantiated.
> 
> retain
> 
> For ELF targets that support the GNU or FreeBSD OSABIs, this attribute
> will save the variable from linker garbage collection. To support this
> behavior, variables that have not been placed in specific sections
> (e.g. by the section attribute, or the -fdata-sections option), will
> be placed in new, unique sections.
> 
> This additional functionality requires Binutils version 2.36 or later.
> 
> 
> 
> 
> 2) The gcc 11 changes website (https://gcc.gnu.org/gcc-11/changes.html) states:
> 
> For ELF targets that support the GNU or FreeBSD OSABIs, the used
> attribute will now save the symbol declaration it is applied to from
> linker garbage collection.
> 
> To support this behavior, used symbols that have not been placed in
> specific sections (e.g. with the section attribute, or the
> -f{function,data}-sections options) will be placed in new, unique
> sections.
> 
> This functionality requires Binutils version 2.36 or later.
> 

The above note was meant for the change introduced by commit [1].
But later commit [2] introduced attribute "retain" and recovered the
behavior of attribute "used".  So I'm afraid that the above note
has to be removed to avoid any confusions.

CC Jozef.

BR,
Kewen

[1] https://gcc.gnu.org/git/gcc.git/6fbec038f7a7ddf29f074943611b53210d17c40c
[2] https://gcc.gnu.org/git/gcc.git/6347f4a0904fce17eedf5c071be6f3c118680290

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-07 10:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-04 17:31 used vs retain attribute NightStrike
2021-07-07 10:51 ` Kewen.Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).