RFC: ld: Add --text-section-ordering-file (version 2)
Nick Clifton
nickc@redhat.com
Thu Apr 25 13:01:01 GMT 2024
Hi Guys,
Attached is a patch to add a --section-ordering-file option to the BFD
linker. It is based upon H.J.'s original patch, but extended so that
it will work with multiple output sections.
There are a couple of points that I feel I should highlight:
* The option only works in conjunction with a modified linker script.
In particular the script must have: "INCLUDE section-ordering-file"
statements in it, wherever it wants section ordering to be allowed.
This statement can appear multiple times in a linker script,
although it would not make sense to have it appear more than once in
any given output section. Here is an example:
SECTIONS
{
.text : {
INCLUDE section-ordering-file
*(.text)
}
.data : {
INCLUDE section-ordering-file
*(.data)
}
}
* H.J's original version allowed for linker script like
"filename(section)" syntax to be used to name sections, eg:
"*(.text.*)", as well as a simpler "section name regexp", eg
".text.*", to be used. This version only supports the latter
format.
In addition H.J.'s syntax allowed for abbreviated section names to
match. So ".t*t" would match any section starting with ".t" and
ending with "t" and would put it into the .text section. In this
version however the output section is selected based upon matching
the fixed part at the start of the pattern with the output section.
So ".t*t" would only work if the output section was called ".t".
To help compensate for this, and to allow arbitrary input sections
to be mapped to specific output sections, the output section name
can be provided as if it were a filename. So .foo(.bar) would map
all sections called .bar to the output section .foo, but only if the
linker script has an output section called .foo, and only if that
output section declaration includes a INCLUDE section-ordering-file
statement.
Perhaps an example will make things clearer. If the above linker
script is used and the section ordering file contains:
# A comment - this will be ignored.
.text.hot .text.cold .text.warm
.data.big
.data(.bar)
.text.foo*
.ignore(.me)
This is roughly equivalent to a linker script that looks like this:
SECTIONS
{
.text : {
*(.text.hot)
*(.text.cold)
*(.text.warm)
*(.text.foo*)
*(.text)
}
.data : {
*(.data.big)
*(.bar)
*(.data)
}
}
Note - the linker will not warn about entries in the section
ordering file that do not match an output section name. So in the
above example the ".ignore(.me)" entry will not generate a warning
about it not being used.
Thoughts, comments, etc ?
Cheers
Nick
-------------- next part --------------
A non-text attachment was scrubbed...
Name: section-ordering-file.patch
Type: text/x-patch
Size: 47828 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20240425/3e9a37ce/attachment-0001.bin>
More information about the Binutils
mailing list