[PATCH] Support SHF_GNU_RETAIN ELF section flag

Michael Matz matz@suse.de
Wed Sep 23 13:51:56 GMT 2020


Hello,

On Wed, 23 Sep 2020, H.J. Lu via Binutils wrote:

> > I think that:
> >
> > >  .section .text,"ax"
> > >    ...
> > >  foo:
> > >    ...
> > >  .retain
> > >  retained_fn:
> > >    ...
> >
> > is some nice syntactic sugar compared to:
> >
> > >  .section .text,"ax"
> > >    ...
> > >  foo:
> > >    ...
> > >  .section .text,"axR"
> > >  retained_fn:
> > >    ...
> >
> > It's also partly for convenience; we have other directives which are
> > synonyms or short-hand for each other.
> >
> 
> You don't need to keep the whole section when only one symbol should
> be kept.  Please drop the .retain directive.  GCC, as and ld should do the
> right thing with
> 
> .section .text,"ax"
>    ...
> foo:
>   ...
>  .section .text,"axR"
> 
>  retained_fn:
> 
> where foo can be dropped and retained_fn will be kept.

This is not what we discussed at the ABI list, the flag is per section, so 
either the whole section is retained or not.  What you describe is 
something else that would work on a per symbol basis, which would have to 
be specified in a different way and might or might not be a good idea.  
But let's not conflate these two.

About the .retain syntactic sugar: I also think it's not necessary, the 
.section directive with R flag merging is good enough IMHO.


Ciao,
Michael.


More information about the Binutils mailing list