This patch should work on top of D8156 because it needs linker script
expression evaluation.
This patch implements the behaviour of the SECTIONS linker script directive,
used to define a custom mapping between input and output sections. Not all
sections constructs are currently supported, but only the ones that do not
use special sort orders. I added two LIT test as practical examples of which
sections directives are currently supported.
In terms of high-level changes, I created a new class "script::Sema" that owns
all linker script ASTs and the logic for linker script semantics as well.
ELFLinkingContext owns a single copy of Sema, which will be used throughout
the object file reading process (to assign rule ids to atoms) and writing
process (to layout sections as proposed by the linker script).
Other high-level change is that the writer no longer uses a "const" copy of
the linking context. This happens because linker script expressions must be
calculated *while* calculating final virtual addresses, which is a very late
step in object file writing. While calculating these expressions, we need to
update the linker script symbol table (inside the semantics object), and, thus,
we are "modifying our context" as we prepare to write the file.
The difference D7915 is that I implemented several suggestions from Rui and
Shankar:
- there is no exposed "id". Clients always ask how to order a section, and whether we use "ids" to sort or not is internal to the Sema class implementation. (suggestion from Rui)
- improved the input sections ordering and addressed the test case mentioned by Shankar (second LIT test case in this patch) (suggestion from Shankar)
- refactored the code in DefaultLayout to live in ScriptLayout (suggestion from Shankar)
I also took the opportunity to improve the code and implement simple
SORT directives and wildcard matching.
Could you represent all the different kinds of functions that can operate on the input sections as Functions instead of InputSectionKinds ?