linker script, /DISCARD/ section and SHT_GROUP

Nick Clifton nickc@redhat.com
Thu Nov 14 12:30:00 GMT 2019


Hi Serge,

> I find this behavior relatively strange with respect to group semantic: we end
> up with a group with one of its member stripped, and the others happily living
> around.
> 
> Surely, the /DISCARD/ section is incomplete, but I would have expected a
> warning, if not an error, in that case.
> 
> Is my understanding correct or am I missing something?

No this is a bug, or possibly a feature.  Either the linker documentation
needs to be updated to say that the /DISCARD/ section is allowed to break
ELF section group semantics (a bad idea imho), or else we need to fix the
linker to generate either an error or a warning.

My feeling is that the correct behaviour would be to discard the entire
group, but to also generate a warning indicating that only part of the
group was covered by the /DISCARD/ section.

But there is another complication.  What should happen if one or more
of the sections are explicitly kept ?  Ie:

  % cat b.script
  SECTIONS 
  { 
    /DISCARD/   : { *(.myanote.foo) }
    .mytext.foo : { KEEP (*(.mytext.foo)) }
    .mynote.foo : { *(.mynote.foo) }
  }

  % ld -T b.script a.o

Now we have one section in the group that is deliberately discarded,
one that is deliberately kept, one that can be discarded if it is not
referenced, and one that is an orphan.  What is the poor linker to do ?

Complain to the user and say that the script cannot be honoured would
be my suggestion, but what do you think ?

Cheers
  Nick



More information about the Binutils mailing list