Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Keith Walker <kwalker <at> arm.com>
Subject: Why do LLVM and GCC differ in the position of the frame pointer for ARM?
Newsgroups: gmane.comp.compilers.llvm.devel
Date: Thursday 16th January 2014 11:02:45 UTC (over 3 years ago)
I have been looking at the function prologue code for ARM which uses frame
pointers and comparing the code that LLVM generates with that produced by
GCC.    In the examples below the frame pointer register is R11.

I used this simple C code (frame.c):

    extern int func2(int i);
    int func(int i) {
	return func2(i);
    }

If I compile (clang -c -target armv7-arm-none-eabi frame.c) this source
LLVM
produced the following code in the function prologue to set up the frame
pointer:

    PUSH     {r11,lr}
    MOV      r11,sp

However compiling the same source with GCC (arm-none-eabi-gcc -c -O0
--no-omit-frame-pointer frame.c) produced the following code:

    PUSH     {r11,lr}
    ADD      r11,sp,#4

So the LLVM code results in the frame pointer pointing to just after the
pushed R11 register on the stack, while the GCC code results in the frame
pointer pointing to just after the pushed LR register on the stack.

So my question is whether there a reason for this difference in where the
frame pointer points between code generated by LLVM and GCC, or have I
missed something obvious?

This difference will make it difficult, without additional information, for
a generic stack walker to use the frame pointer to walk up the stack that
can handle both GCC and LLVM compiled code.

Keith
 
CD: 2ms