linker script, /DISCARD/ section and SHT_GROUP

Nick Clifton nickc@redhat.com
Tue Nov 19 13:49:00 GMT 2019


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.

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.

  * 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.

So new behaviour would only happen when /DISCARD/ and KEEP intersect, and
then only if orphans are being retained in the output.

What do you think, would this work ?

Cheers
  Nick


-------------- next part --------------
A non-text attachment was scrubbed...
Name: ld.discard.patch
Type: text/x-patch
Size: 19587 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20191119/9f18bca8/attachment.bin>


More information about the Binutils mailing list