On Thu, Feb 18, 2021 at 01:08:54PM +0100, Jakub Jelinek via Gcc-patches wrote:
> On Thu, Feb 18, 2021 at 12:00:59PM +0000, Jozef Lawrynowicz wrote:
> > If we can add ".retain <symbol_name>" to GAS, then I agree, current GCC
> > SHF_GNU_RETAIN behavior should be removed. For GCC 12 we leverage
> > .retain to implement the functionality where "used" saves symbols form
> > linker garbage collection, without modifying section names or the
> > structure of the object file.
> 
> Even in that case I think it is a bad idea to change the "used" attribute
> behavior, not everyone using "used" attribute needs or wants that behavior,
> so it should be a functionality provided by a separate new attribute.

I think it is a enhancement, and true to the spirit of the attribute,
for "used" to save a symbol from linker garbage collection.

Why should "used" mean:
  Save this symbol from compiler optimization, but allow the linker to
  remove it.

I can't currently think of a use case where a "used" symbol should be
kept by the compiler but removed by the linker.

Often we see KEEP directives in linker scripts accompanying
"used" in the source code. libgcc/crtstuff.c is a good example. GNU
linker scripts need many specific KEEP directives to handle all the
"used" symbols.

If a developer marks a symbol as "used" in the source code, I think the
intuitive thing is for that symbol to be present in the linked output
file.

Jozef

Reply via email to