This implements https://sourceware.org/bugzilla/show_bug.cgi?id=26404#c6
--overwrite-section-script specifies a scripAn `OVERWRITE_SECTIONS` command is a `SECTIONS` variant which contains several `SECTIONS`
commands. Each `SECTIONS` specifies exactly one output section descriptions. The initial syntax is intentionally narrow to
initial syntax is intentionally narrow to facilitate backward compatiblefacilitate backward compatible extensions in the future. Symbol assignments
extensions in the future. Symbol assignments cannot be used. Not supporting
multiple output section descriptions in one `SECTIONS` makes it clear the
sections don't have order guaranteecannot be used.
The semantics are similar to `INSERT [BEFORE|AFTER]` in thatOVERWRITE_SECTIONS does not specify a section order. Similar to
`INSERT [BEFORE|AFTER]`, `LinkerScript::hasSectionsCommand` is not set, so default linker script rulesso the
still apply. In the absence of a main built-in rules (see `docs/ELF/linker _script, --overwrite-script can be.rst`) still apply.
`OVERWRITE_SECTIONS` can be more convenient than `INSERT` because --overwrite-scripit does not need a random
need an anchor section used by `INSERT`.
This feature is versatile. To list a few usage:
* Use `section : { KEEP(...) }` to retain input sections under GC
* Define encapsulation symbols (start/end) for an output section
* Use `section : ALIGN(...) : { ... }` to overalign an output section (similar to ld64 `-sectalign`)
When an output section is specified by both `--overwrite-section-script`OVERWRITE_SECTIONS` and
`INSERT`, `INSERT` is processed after overwrite sections. To make this work,
this patch changes `InsertCommand` to use name based matching instead of pointer
based matching. This causes a difference when `INSERT` moves one output section
more than once. This should not be used in practice (seems that in GNU ld the
output sections may just disappear)
A linker script can be used without -T/--script. This feature does not suppress
orphan section placement so a wrong rule can make it easy to shoot oneself in
the foot. The traditional `SECTIONS` commands are concatenated so a wrong rule
can be more noticeable.