ARM Assembly walking the frame pointer with clang -
i'm compiling code clang 3.3 using -pg on arm architecture, , see 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 understand r7 used frame counter, , can walk backwards through stack , lr of caller of current call stack if -ffunction-section , -no-omit-frame-pointer specified. however, when try write code this, doesn't work:
mcount: push {r7, lr} @ save off return , 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 , new pc
r0 wrong here in trying lr of callee, , believe r1 since used mov , don't have full 32 bits that's in lr.
can point out i'm doing wrong?