This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: linker script, /DISCARD/ section and SHT_GROUP


On Thu, Nov 14, 2019 at 12:30:00PM +0000, Nick Clifton wrote:
> 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.

That's my feeling too. Or an error and suggest to discard the group?

> 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 ?

Yeah, an error looks like the way to go.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]