Assembly label prefixes


Assembly label prefixes



Can somebody explain the difference between these labels in assembly?


Lfoo:

.Lfoo:

foo:

.foo:



There's some documentation but it is a bit unclear. I tried this with an ELF system:


$ cat foo.S
Laaa:
jmp Laaa

.Lbbb:
jmp .Lbbb

aaa:
jmp aaa

.bbb:
jmp .bbb

$ clang -c foo.S -o foo.o
$ objdump -D foo.o

foo.o: file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <Laaa>:
0: eb fe jmp 0 <Laaa>
2: eb fe jmp 2 <Laaa+0x2>

0000000000000004 <aaa>:
4: eb fe jmp 4 <aaa>

0000000000000006 <.bbb>:
6: eb fe jmp 6 <.bbb>



And that seems to confirm that .L is a local symbol for ELF, however the symbols clearly don't have to start with . or _. I know _ is used for name mangling in C, but what is the point of the .?


.L


.


_


_


.




1 Answer
1



The name mangling scheme and the prefix to make a local symbol (i.e. symbol that does not appear in the symbol table) depend on your platform and assembler. There is no single combination that works everywhere. The following two conventions seem to be common:



On targets following the traditional UNIX conventions (e.g. aout, Mach-O, and COFF targets), C symbols are decorated with a leading underscore _ and local labels begin with an L.


_


L



On ELF targets, C symbols are not decorated and local labels begin with .L.


.L



Some assemblers (e.g. nasm) deviate from these conventions for local labels. For example, on NASM, local labels begin with a single period . independently of what target you are on.


.



I don't know what the convention outside UNIX is (Windows is UNIX-like in that it is a COFF target).





Ah I thought the _ was added everywhere but it seems you are right and they aren't on ELF.
– Timmmm
Jul 3 at 9:33


_





So if you're not using NASM, there's really no point having a label .foo rather than just foo?
– Timmmm
Jul 3 at 9:34


.foo


foo





@Timmmm On NASM, .foo has the same behaviour as .Lfoo has on the GNU assembler. It's just a label that doesn't appear in the symbol table. That's really all there is to it.
– fuz
Jul 3 at 9:48


.foo


.Lfoo





@fuz: no, NASM local labels are not like GAS .L labels. NASM .foo: is "local" to the previous non-dot label, and does show up in the object file (if you enable debug symbols) it You can have a .loop: label in each of multiple functions in the same file. The actual symbol name is func1.loop, func2.loop, i.e. just tacked on to the previous non-dot symbol name. See nasm.us/doc/nasmdoc3.html#section-3.9. They're handing if you're playing with different versions of the same function: you can copy/paste it and just change the non-dot label.
– Peter Cordes
Jul 3 at 10:08



.L


.foo:


.loop:


func1.loop


func2.loop





@PeterCordes Seems like I misunderstood this! Thank you for the clarification.
– fuz
Jul 3 at 10:18






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

JMeter fails on beanshell imports

Why in node-red my HTTP POST no receive payload from inject?

PHP contact form sending but not receiving emails