For the Mips LA25 Thunks we want the Thunks to precede the target section. The existing code merges these thunks into OutputSections::Sections. This is not sufficient when linker scripts are used as the order of sections and the addresses assigned to them are determined by the InputSectionDescription in the LinkerScript, and thunks are generated after the InputSectionDescription contents have been generated.
This change merges the LA25 Thunks into the InputSectionDescription as well as the OutputSections so that the ordering of the Thunks is maintained. To do this we need to ask the script to calculate the offsets of the OutputSection as all the offsets for script controlled OutputSections are 0 at thunk creation time. We need to ask the script to calculate the offsets as there may be multiple InputSectionDescriptions with location expressions in between them.
The state is cleared at the start of the Linker Script address assignment as we will be running this function twice when Thunks are created.
I've gone for an implementation that merges the result of the createThunks() function into the InputSectionDescription. An alternative is to rewrite createThunks to work on ranges of InputSectionData and have createThunks ask the script for the InputSectionDescription ranges. I'm open to suggestions on how best to work out how scripts and thunks interact as range extension thunks will need to deal with location expressions.
I've based this on top of D30637.