I'm building something like in the question How to collect data from different .a files into one array? How to keep sections in .a files with ld script?, i.e. arrays composed during link-time out of elements from different object files.
In my case, there are several arrays, each one going into its own section, .ld_comp_array_*, where * matches the name of the array. Then I take the default linker script using ld --verbose and modify it by putting all these sections (sorted, so that elements of different arrays don't get mixed) into an output section:
KEEP (*(SORT_BY_NAME(.ld_comp_array*)))
and everything works fine.
Then things get a tiny bit more complicated, because application(s) using this feature may be built for various platforms - so far, I've successfully tried AVR Xmega as target platform, as well as Windows 32-bit and Linux 32- and 64-bit for unit testing, and the list is open (new platforms are likely to be added in near future).
However, for each particular platform the default linker scripts is different than on other platforms, and currently I insert the .ld_comp_array* sections manually - would it be possible to do it somehow automatically? The only solution I thought of was parsing the default script and pasting the above input section description, but this seems way too heavy.
I could keep it done manually if there's no relatively simple solution, but I'm not sure if the default scripts obtained from a local version of ld may break on different version of binutils. Can anyone clarify whether this is safe or not?
In case it can be done automatically, is it ok to "inject" the input section specification always directly into .text section, assuming arrays are supposed to be "immutable"?