18

I am analyzing a linux exception code. By the way I can't understand gnu assembly syntax.

    svc_preempt:
    mov r8, lr
1:  bl  preempt_schedule_irq        @ irq en/disable is done inside
    ldr r0, [tsk, #TI_FLAGS]        @ get new tasks TI_FLAGS
    tst r0, #_TIF_NEED_RESCHED
    moveq   pc, r8              @ go again
    b   1b

In this code, I can see "b 1b", but I can't find "1b" label anywhere.

And,

#ifdef CONFIG_NEON
    adr r6, .LCneon_thumb_opcodes
    b   2f
#endif
call_fpe:
#ifdef CONFIG_NEON
    adr r6, .LCneon_arm_opcodes
2:
    ldr r7, [r6], #4            @ mask value
    cmp r7, #0              @ end mask?
    beq 1f
    and r8, r0, r7
    ldr r7, [r6], #4            @ opcode bits matching in mask
    cmp r8, r7              @ NEON instruction?
    bne 2b
    get_thread_info r10
    mov r7, #1
    strb    r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
    strb    r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
    b   do_vfp              @ let VFP handler handle this
1:

I can't find "2f" and "1f" label.

So, I wonder the meaning of "1b", "1f", "2f" and so on.

artless noise
  • 21,212
  • 6
  • 68
  • 105
user3247643
  • 283
  • 1
  • 4
  • 7

2 Answers2

40

Labels "xb" and "xf", where "x" is a number are a smart extension to the GNU assembly. It branches to the first found label "x" searching "forward" for "f" or "backward" for "b".

That means that in your first listing using "1b" as a target will search for "1" BEFORE the instruction that uses it. In the second listing "2f" will search for "2" AFTER the instruction that uses it, the "2b" at the end of this listing will then branch to the same "2", because it is BEFORE the instruction.

There may be multiple labels with numbers in your code.

See here - https://sourceware.org/binutils/docs-2.24/as/Symbol-Names.html#Symbol-Names - chapter "Local labels".

Freddie Chopin
  • 8,440
  • 2
  • 28
  • 58
0

These are relative branches (so many bytes forwards or backwards relative to the current position) so they don't really have a label. However, when visualizing code it is easier to actually have some kind of visualization of where it goes to - hence the "not-label" of 1 and the backwards and forwards jumps.

I had to work with the alternative on the IBM370 mainframe - believe me, that's not fun!

Mike
  • 2,721
  • 1
  • 15
  • 20
  • No, they don't and I didn't say they were. The numbers here are a pseudo-label. The bytes are part of the assembler instruction (eg branch 27 bytes forwards). If there weren't the pseudo-label of 1 or 2, you would have to calculate the size of each instruction, including operands, before figuring out where you were going. – Mike Dec 08 '14 at 08:18