On Wednesday 25 February 2009, Andrew Haley wrote: > Uwe Kleine-König wrote: > > currently[1] __builtin_return_address for ARM only works with level == 0. > > > > For ftrace in the linux kernel it would be great to implement that for > > level > 0 (provided that framepointers or unwind information are > > available of course). On the linux-arm-kernel ML Mikael Pettersson[2] > > said that "__builtin_return_address(N) where N>0 should never have been > > introduced into gcc.". Is that the general view for > > __builtin_return_address or would a patch be accepted? > > The old APCS, if I recall correctly, required a frame pointer, so > __builtin_return_address(N) was easy.
One minor exception: Thumb code generally doesn't have a frame pointer chain either, even on old-abi targets. In general it's impossible to make __builtin_return_address(N) to work for N>0. > > Up to now I only had a quick glance at gcc sources and after that I'm > > not sure if I even find the place where to put an implementation, so any > > help is welcome. > > In userland ARM EABI doesn't have a frame pointer chain, so what you > suggest isn't possible. However, we do need to unwind the stack so > we use the unwinder info. For this you have to call _Unwind_Backtrace > directly. > > As I understand it, the ARM kernel can now do something similar. So, > the only use for a __builtin_return_address(N) that used the frame > pointer chain would be if the code were compiled with nonstandard > options. Correct. The short story is that on modern ARM targets[1] there is no standard frame layout. It is not possible to do backtraces without using additional unwind tables. Current arm-linux kernels use a special set of options to allow this under most circumstances. However this often incurs a significant performance and code size hit, and isn't supported at all when you switch to Thumb mode. Paul [1] I believe the same is also true for some other targets, e.g. MIPS.