linker script, /DISCARD/ section and SHT_GROUP

Alan Modra amodra@gmail.com
Wed Nov 20 01:05:00 GMT 2019


On Tue, Nov 19, 2019 at 01:49:22PM +0000, Nick Clifton wrote:
> Hi Guys,
> 
> > I don't see anything particularly strange.  A section group typically
> > is used to package up code, data and debug info for a function.  You
> > normally want to include or exclude the whole group, but in some cases
> > you might want to exclude all sections of a particular type.  An
> > obvious example is when stripping debug info.  Other abnormal cases
> > surely exist, allowed for by /DISCARD/.
> 
> The problem is that discarding sections in this way breaks the semantics 
> of the ELF section group, so at the very least we ought to document this
> behaviour.

I disagree, and I think the ELF spec is wrong to say "such groups must
be included or omitted from the linked object as a unit".  Or at
least, interpreting the wording strictly is wrong.  The example I gave
of a linker omitting all debug sections is an obvious exception to the
rule.  It would make no sense *at all* for debug info in groups to be
kept when other debug info was dropped.

> Attached however is a proposed patch to change the linker's behaviour so
> that it would behave in the following way:
> 
>   * If a /DISCARD/ed section is not part of an ELF group, then always
>     discard it, just like before.
> 
>   * Otherwise if any of the other sections in the group are the subject
>     of a KEEP directive, then treat the section as an orphan.  (I did not
>     want to reparse the linker script to see if the section matched some
>     other section directive).  This will usually mean that the section will
>     be retained, unless orphans are being discarded.

I think this is a horrible complication that serves no useful
purpose, and would probably break things that now work.  I'm sorry
that being away I didn't see the original email earlier to try to
dissuade you from writing the patch.

>   * Otherwise discard the section as normal.
> 
>   * If the --verbose linker option is in effect then generate information
>     messages when then /DISCARD/ section interacts with an ELF group.

/DISCARD/ is dangerous.  It's for people who know what they're doing.
Why single out groups for a nanny message?

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list