gas: Multiple default version .file directives
Alan Modra
amodra@gmail.com
Tue Feb 9 07:42:18 GMT 2021
On Thu, Feb 04, 2021 at 11:58:50PM -0800, Fangrui Song wrote:
> For ELF, the default version .file directive can be specified multiple
> times to create multiple STT_FILE symbols. It looks like that in the
> symbol table, local symbols (including section symbols) are ordered
> after their preceding .file directives.
This happens because symbols are output in the same order that gas
creates them, mostly, subject of course to locals first for ELF.
> So is this a guaranteed behavior?
There is no guarantee. And it is certainly not in the order of their
definitions. A simple example:
.file "1"
.data
.l1:
.dc.a .l2
.file "2"
.text
.l2:
will emit "1", ".text", ".data", ".l1", ".l2", "2" in that order.
This ordering may be explained by the fact that section symbols for
.text, .data and .bss are created at the start of assembly (.bss not
being emitted as it is unused), the first .file symbol being forced to
the start of symbols, .l1 being created when it was defined, .l2 being
created when it was referenced, then the final .file symbol being
created.
Remember that section symbols may be reordered by ld -r too.
> (https://sourceware.org/binutils/docs/as/File.html#File does
> not document this)
>
> .file "2.cc"
> l2:
>
> .file "1.cc"
> l1:
> .section .xxx,"a"
> .long .xxx
>
> .file "0.cc"
> l0:
> .section .yyy,"a"
> .long .yyy
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list