[PATCH 4/8] section-select: Completely rebuild matches

Alan Modra amodra@gmail.com
Tue Nov 29 12:22:17 GMT 2022


On Mon, Nov 28, 2022 at 02:24:30PM +0000, Michael Matz wrote:
> Hello,
> 
> On Mon, 28 Nov 2022, Alan Modra wrote:
> 
> > On Fri, Nov 25, 2022 at 04:55:12PM +0000, Michael Matz via Binutils wrote:
> > > this resets all section matches before updating for newly created
> > > sections (i.e. completely rebuilds the matches).  This fixes powerpc
> > > "TOC opt" tests that shows a difference in section order: originally
> > > .got of "linker stubs" comes before .toc (both placed into the same
> > > .got output section due to ".got {*(.got .toc)}".  But .got of linker
> > > stubs is created later, and in the second run of resolve_wilds is
> > > appended to the list, hence is then coming after .toc (which was added
> > > already in the earlier resolve_wilds run).  So order swapped ->
> > > test fails.
> > 
> > That's a problem.  The got header is created in the .got of "linker
> > stubs", and code setting the value of .TOC. assumes that the header
> > will be located first in the .got output section.  This ties in with
> > where ld.so expects to find the header too.
> 
> I see.  But then why is the testcase (and linker script?) not using
> 
>   .got { *(.got) *(.toc) }
> 
> ?  The way it's written right now means "for each file, first its .got 
> then its .toc, intermixed", i.e. file1.got, file1.toc, file2.got, 
> file2.toc ...

Yes.  That's the way we want it.  When linking small model code with a
total GOT/TOC of over 64k, the linker splits the TOC into multiple
pieces with r2 adjusting stubs inserted on calls between files that
use different pieces of the TOC.  That scheme wouldn't work if a
file's .got entries were placed in a different piece of the TOC to the
file's .toc entries.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list