Re: [arm-gnu] some questions about gcc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [arm-gnu] some questions about gcc



On Tue, Jun 02, 2009 at 01:52:37PM +0200, yann.poupet@xxxxxxx wrote:
> Consider the following C code:
> 
> int a(int b)
> {
>   int c = c;
>   return c + b;
> }

This is a GNU C extension to suppress uninitialized variable warnings.
Take a look at the -Winit-self option in the compiler manual.

> This one compiles fine and does what I want, which is return r0 + r4.
> However, objdump shows r4 is saved then restored from the stack :
> 
>    0:   e52d4004        push    {r4}            ; (str r4, [sp, #-4]!)
>    4:   e0800004        add     r0, r0, r4
>    8:   e8bd0010        pop     {r4}
>    c:   e12fff1e        bx      lr
> 
> which is useless since r4 is not modified. Is there a reason ?

The compiler does not support what you're trying to do, sorry.  You
might have better luck with a global register variable.  However,
you'll have to put this function in its own file then; a global
register variable completely reserves the listed register.

Or, use the "naked" attribute and write the body of the function in
assembly.

__attribute__((naked)) int foo(int x)
{
  asm ("add r0, r0, r4\nbx lr");
}

[This will generate a -Wall warning; I don't know how to suppress that
except by turning off the warning.]

-- 
Daniel Jacobowitz
CodeSourcery