section-select: Lazily resolve section matches
and remember the results. Before this the order of section matching
is basically:
foreach script-wild-stmt S
foreach pattern P of S
foreach inputfile I
foreach section S of I
match S against P
if match: do action for S
And this process is done three or four times: for each top-level call to
walk_wild() or wild(), that is: check_input_sections, lang_gc_sections,
lang_find_relro_sections and of course map_input_to_output_sections.
So we iterate over all sections of all files many many times (for each
glob). Reality is a bit more complicated (some special glob types don't
need the full iteration over all sections, only over all files), but
that's the gist of it.
For future work this shuffles the whole ordering a bit by lazily doing
the matching process and memoizing results, trading a little memory for
a 75% speedup of the overall section selection process.
This lazy resolution introduces a problem with sections added late
that's corrected in the next patch.