gas: Multiple default version .file directives

Fangrui Song i@maskray.me
Tue Feb 9 22:39:35 GMT 2021


On 2021-02-09, Alan Modra wrote:
>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.

Thanks.

If we consider .file as real separators for files (pseudo relocatable
link), file "1" should not reference a local symbol in file "2",
then this behavior makes a lot of sense.

I've changed LLVM integrated assembler to behave similarly.
I have special cased implicit sections like (.text/.data) to make them
follow the first .file emitted STT_FILE.

>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