[Bug c/92172] ARM Thumb2 frame pointers inconsistent with clang

wilco at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Oct 23 17:54:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92172

--- Comment #6 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to Seth LaForge from comment #5)

> GCC 8:
>         push    {r7, lr}
>         sub     sp, sp, #8
>         add     r7, sp, #0
>         str     r0, [r7, #4]
>         ...
> 
> Clang 9:
>         push    {r7, lr}
>         mov     r7, sp
>         sub     sp, #8
>         str     r0, [sp, #4]
>         ...

Crazy yes, but it's due to historical reasons. Originally GCC could only emit
code using a frame pointer. Later the frame pointer could be switched off
(hence -fomit-frame-pointer), but you still needed it for debug tables. Then
there was Dwarf which didn't need a frame pointer anymore. And today the frame
pointer is off by default globally in GCC.

> - GCC ARM and Clang ARM use R11 for frame pointer, pointing to the stacked R11. Useful.

Well Clang does this:

       push    {r4, r10, r11, lr}
       add     r11, sp, #8

but GCC does something different:

        push    {r4, r5, fp, lr}
        add     fp, sp, #12

Ie. FP points to saved LR with GCC but saved FP with Clang, so it's not
possible for a generic unwinder to follow the chain, even ignoring Arm/Thumb
interworking (which is a real issue when an application is Thumb-2 but various
library functions use Arm assembly).


More information about the Gcc-bugs mailing list