[PATCH] Stack corruption in naked functions.

Richard Guenther richard.guenther@gmail.com
Fri May 23 10:40:00 GMT 2008


On Fri, May 23, 2008 at 3:18 AM, Carlos O'Donell
<carlos@codesourcery.com> wrote:
> The patch below fixes a stack corruption bug in __attribute__((naked))
> functions.
>
> Mark Mitchell's comments here:
> http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00592.html
> have been incorporated into this patch.
>
> On supported targets this attribute can be used to suppress the normal
> function prologue/epilogue. This allows a function to be implemented in
> assembly without requiring the user to put everything in a separate .S file.
>
> The problem is that at -O0 the compiler assigns all decls to a local stack
> slot and the value will be copied to this slot even if not used. This is
> undesirable in naked function because we don't allocate a stack frame.
>
> The best solution we could come up with is to suppress stack slot allocation
> for these functions.
>
> The user documentation is enhanced to clarify the intended use of
> __attribute__((naked)).
>
> Tested on arm-none-eabi and i686-pc-linux-gnu.
>
> OK to checkin to mainline?

I wonder if you start to get ICEs all over the place if you use naked
on a function with addressable local variables or with BLKmode
parameters?  IMHO it would be better to sorry () as soon as a
stack slot is allocated for such a function.

Richard.



More information about the Gcc-patches mailing list