Closed Bug 491367 Opened 15 years ago Closed 11 years ago

Get stack walking working on ARM

Categories

(Developer Infrastructure :: Source Code Analysis, defect)

ARM
All
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 810526

People

(Reporter: cjones, Unassigned)

References

Details

Supposedly walking the stack is hard on ARM.  If this is true, then it is a problem of instrumentation to make it easier.
I should note that broken stack walking on ARM is probably why oprofile won't produce callgraphs on maemo.
I wanted to implement a prototype, looks like I won't be able to do this work.  I learned a couple of important things:

  (1) gcc uses r11 (or was it r12) for the frame pointer.  The symbolic name in gcc assembly is "fp."  If -fno-omit-frame-pointer is passed to gcc, and the system libraries are recompiled this was too (may be already for debug), then walking the stack is no harder than walking it on x86.  From what I could tell, the link register (return address) was being pushed at |$fp - 2words|.

  (2) libc provides a |dladdr(addr)| function that returns the function pointer with the highest address less than |addr|, if |addr| points to a location in a code page.  This gives us a hacky and somewhat expensive solution to walking the stack when we can't rely on -fno-omit-frame-pointer.  Examine every word on the stack, and try to resolve it using dladdr() information.  If it's resolved, assume it's a link register that's been pushed on the stack and count it as part of the backtrace.  This can falsely add functions to the backtrace, but will never miss one.  One situation when it could be wrong is when an actual function pointer in C has been declared locally.

If you want to get fancier, after resolving an address, you can also verify that it points just in front of a |bl| instruction (branch and link).  This is another sanity check that the resolved address is a pushed link register, but it can still be wrong.  However, it does work for the stack-allocated function pointer case above.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → DUPLICATE
Product: Core → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.