Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC return address of calling function in ARM architecture

Tags:

c

stack

gcc

arm

I'm curious why __builtin_return_address() doesn't supports other arguments than 0 in ARM ? It's a problem that somehow you can't deduce calling function address from the stack of ARM ? Or something else ?

Thanks

like image 987
Agnius Vasiliauskas Avatar asked Feb 10 '12 14:02

Agnius Vasiliauskas


People also ask

Where is the return address of a function call stored?

The function return address is placed on the stack by the x86 CALL instruction, which stores the current value of the EIP register. Then, the frame pointer that is the previous value of the EBP register is placed on the stack.

What is __ Builtin_frame_address?

__builtin_frame_address, __builtin_return_addressReturns the address of the stack frame, or return address, of the current function, or of one of its callers.

What is return address Assembly?

In assembly language, the call instruction handles passing the return address for you, and ret handles using that address to return back to where you called the function from. return value. The return value is the main method of transferring data back to the main program.


1 Answers

According to this post <http://codingrelic.geekhold.com/2009/05/pre-mortem-backtracing.html>,

Also on some architectures, including my beloved MIPS, only __builtin_return_address(0) works. MIPS has no frame pointer, making it difficult to walk back up the stack. Frame 0 can use the return address register directly. If ARM also does not have a frame pointer, this would explain the limitation.

See also http://gcc.gnu.org/onlinedocs/gcc/Return-Address.html.

like image 166
J. C. Salomon Avatar answered Dec 02 '22 02:12

J. C. Salomon