From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10250 invoked by alias); 23 May 2008 09:17:49 -0000 Received: (qmail 10239 invoked by uid 22791); 23 May 2008 09:17:49 -0000 X-Spam-Check-By: sourceware.org Received: from wf-out-1314.google.com (HELO wf-out-1314.google.com) (209.85.200.169) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 23 May 2008 09:17:21 +0000 Received: by wf-out-1314.google.com with SMTP id 25so434210wfc.14 for ; Fri, 23 May 2008 02:17:20 -0700 (PDT) Received: by 10.142.162.5 with SMTP id k5mr506782wfe.53.1211534239966; Fri, 23 May 2008 02:17:19 -0700 (PDT) Received: by 10.143.162.1 with HTTP; Fri, 23 May 2008 02:17:19 -0700 (PDT) Message-ID: <84fc9c000805230217s5ba6c53bp8efa870ad292df5c@mail.gmail.com> Date: Fri, 23 May 2008 10:40:00 -0000 From: "Richard Guenther" To: "Carlos O'Donell" Subject: Re: [PATCH] Stack corruption in naked functions. Cc: "Mark Mitchell" , gcc-patches@gcc.gnu.org, "Paul Brook" In-Reply-To: <48361B73.5020705@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <48361B73.5020705@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2008-05/txt/msg01457.txt.bz2 On Fri, May 23, 2008 at 3:18 AM, Carlos O'Donell 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.