Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C Disassembly to ARMv6: Meaning of Dot (.) Before a Label

Tags:

c

assembly

arm

I disassembled a C program to see how structs were created and I have a question. This is on a Raspberry PI using

gcc -S -o source.s mystruct.c

To get the source.

Questions:

I noticed in all the programs I disassemble, there are labels .Lxx. What's the difference between a label with a . in front and a label without one? I guess I'm confused because directives have a '.', like .data.

Code

typedef struct {
    int x;
    int y;
} point;

int main( int argc, char *argv[] ){
    point p = { 1, 2 };

    p.x = 2;
    p.x = p.x - p.y;

    return p.x;
}

Disassemble to

        .arch armv6
        .eabi_attribute 27, 3
        .eabi_attribute 28, 1
        .fpu vfp
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 2
        .eabi_attribute 30, 6
        .eabi_attribute 34, 1
        .eabi_attribute 18, 4
        .file   "struct.c"
        .section        .rodata
        .align  2
.LC0:
        .word   1
        .word   2
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        @ link register save eliminated.
        str     fp, [sp, #-4]!
        add     fp, sp, #0
        sub     sp, sp, #20
        str     r0, [fp, #-16]
        str     r1, [fp, #-20]
        ldr     r2, .L3
        sub     r3, fp, #12
        ldmia   r2, {r0, r1}
        stmia   r3, {r0, r1}
        mov     r3, #3
        str     r3, [fp, #-12]
        mov     r3, #0
        mov     r0, r3
        add     sp, fp, #0
        ldmfd   sp!, {fp}
        bx      lr
.L4:
        .align  2
.L3:
        .word   .LC0
        .size   main, .-main
        .ident  "GCC: (Debian 4.7.2-5+rpi1) 4.7.2"
        .section        .note.GNU-stack,"",%progbits
like image 329
Jerinaw Avatar asked May 05 '15 18:05

Jerinaw


1 Answers

The .L prefix denotes a local symbol, which is a symbol visible only in that source file (these symbol are not exported to the .o file unless you specify a special option to the assembler).

You can tell they are labels because the line ends with :; directives do not.

For more information, see the GCC Symbol Names documentation:

A local symbol is any symbol beginning with certain local label prefixes. By default, the local label prefix is .L for ELF systems or L for traditional a.out systems, but each target may have its own set of local label prefixes. On the HPPA local symbols begin with L$.

like image 119
nneonneo Avatar answered Oct 13 '22 06:10

nneonneo