3
votes

I am relatively inexperienced with ARM assembly, and need help understanding a few lines. I have used Godbolt to compile C++ 11 code with the ARM gcc 8.2 compiler and got these lines of assembly:

.L10:
        .word   .LANCHOR0

I read that .LANCHOR0 are section anchors, but what does that mean?

I understand that .word and .data can be used together to declare variables and assign values to memory spaces like this:

        .data           ! start a group of variable declarations
x:      .word   23      ! int x = 23;

But, what does

.L10:
        .word   .LANCHOR0

do? There is no label preceding .word here.

Secondly, what does it mean when a block of .word lines are proceeded by another block of assembly instructions like this?

.L7:
        .word   131586
        .word   .LANCHOR0
_GLOBAL__sub_I_unsigned int atlantic_line_ns::getSimInstAddr<atlantic_line_ns::Cr>():
        mov     r2, #0
        ldr     r3, .L10
        str     r2, [r3]
        str     r2, [r3, #4]
        bx      lr

Thanks in advance.

UPDATE

After reading the ARM documentation a bit more, I understand that

.L7:
        .word   131586
        .word   .LANCHOR0

Allocates 2 memory locations, storing values, 131586 and the value at .LANCHOR0, there. Are these memory locations next to each other? Also, what does .LANCHR0 mean?

1
There is no label preceding .word here. Did you not see the .L10: on the previous line? Anyway, look for where GCC puts the .LANCHOR0: label: IIRC, it uses it as a common reference point for referencing multiple items of static data. (After loading the .LANCHOR0 address from a literal pool near the code.) - Peter Cordes
Understand that assembly language is defined by the tool not architecture. It likely resembles arms documentation which is geared toward the assembly language of arms tools, but the language does not have to conform, esp with respect to how data items are declared. - old_timer
.LANCHOR0 is likely just some compiler generated label. - old_timer
Godbolt.. You may want to play with the settings there to get more detailed listing, chances are you'll see what this .LANCHOR0 is. - tum_
Yep, in Godbolt you can remove the tick from .text tab and you'll see the line .set .LANCHOR0,. + 0 somewhere in the listing. On the purpose of 'section anchors' read this if you haven't already. - tum_

1 Answers

3
votes

The following line

.L10:
  .word   .LANCHOR0

instructs assembler to allocate 4 bytes to hold the address of code/data at .LANCHOR0 label. The address itself is located at label .L10. Note that both .LANCHOR0 and .L10 are ordinary local labels (suffix simply denotes that compiler used them for different purposes).

As you noted, it's possible to intermix code and readonly data in assembly as e.g. in

.L7:
  .word   131586
  .word   .LANCHOR0
  mov     r2, #0
  ldr     r3, .L10

Compiler frequently does this to declare local function data (literal pool, static variables, etc.). Data from .word lines next to each other will also be consecutive in object code.