0

I'm compiling some code with Clang 3.3 using -pg on the ARM architecture, and I see that an empty C function:

void do_nothing() {
}

Now looks like:

    .section    .text.do_nothing,"ax",%progbits
    .globl  do_nothing
    .align  2
    .type   do_nothing,%function
    .code   16
    .thumb_func
do_nothing:
    .fnstart
.Leh_func_begin1:
.Lfunc_begin1:
    .loc    2 17 0
    .save   {r7, lr}
    push    {r7, lr}
    .setfp  r7, sp
    mov r7, sp
    bl  mcount(PLT)
    .loc    2 17 0 prologue_end
.Ltmp3:
    pop {r7, pc}
.Ltmp4:
.Ltmp5:
    .size   do_nothing, .Ltmp5-do_nothing
.Lfunc_end1:
.Leh_func_end1:
    .fnend

Now I understand that r7 is used as a frame counter, and that I can walk backwards through it for the stack and lr of the caller of the current call up the stack if -ffunction-section and -no-omit-frame-pointer is specified. However, when I try to write the code that will do this, it doesn't work:

mcount:
        push {r7, lr} @ Save off where to return and current link
        push {r0-r4} @ Save off arguments
        ldr r0, [r7, #4]
        mov r1, lr
        bl MyMCount
        pop {r0-r4}
        pop {r7, pc} @ Restore link and new PC

r0 is definitely wrong here in trying to be the lr of the callee, and I believe r1 is as well since I used mov and so I don't have the full 32 bits that's in lr.

Can anyone point out what I'm doing wrong?

Doug-W
  • 1,318
  • 12
  • 14
  • 1
    What makes you think that `mov r1,lr` isn't copying the full 32 bits? Some thumb instructions can only access the lower 8 registers, but they'll still use the full _contents_ of those registers. – Michael Aug 19 '13 at 05:57
  • It turns out that was a red herring, once I looked into it further. – Doug-W Aug 21 '13 at 16:57

0 Answers0