From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 595 invoked by alias); 10 Feb 2011 09:47:50 -0000 Received: (qmail 586 invoked by uid 22791); 10 Feb 2011 09:47:49 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from metis.ext.pengutronix.de (HELO metis.ext.pengutronix.de) (92.198.50.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 10 Feb 2011 09:47:43 +0000 Received: from octopus.hi.pengutronix.de ([2001:6f8:1178:2:215:17ff:fe12:23b0]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1PnT7l-00031d-3F for gcc-help@gcc.gnu.org; Thu, 10 Feb 2011 10:47:41 +0100 Received: from ukl by octopus.hi.pengutronix.de with local (Exim 4.69) (envelope-from ) id 1PnT7k-0001Jw-O6 for gcc-help@gcc.gnu.org; Thu, 10 Feb 2011 10:47:40 +0100 Date: Thu, 10 Feb 2011 13:27:00 -0000 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: gcc-help@gcc.gnu.org Subject: Re: about function attributes for functions returning a pointer Message-ID: <20110210094740.GX27982@pengutronix.de> References: <20101004090407.GA11737@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-SA-Exim-Connect-IP: 2001:6f8:1178:2:215:17ff:fe12:23b0 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: gcc-help@gcc.gnu.org Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg00174.txt.bz2 Hello Ian, On Mon, Oct 04, 2010 at 11:23:45AM -0700, Ian Lance Taylor wrote: > Uwe Kleine-König writes: > > > in the linux kernel I defined a function as follows: > > > > static struct platform_device *__init __maybe_unused imx_add_imx_dma(void) > > { > > ... > > } > > > > and the only used was #ifdefed out. > > > > With the following defines: > > > > #define __section(S) __attribute__ ((__section__(#S))) > > #define __cold __attribute__((__cold__)) > > #define notrace __attribute__((no_instrument_function)) > > #define __init __section(.init.text) __cold notrace > > #define __maybe_unused __attribute__((unused)) > > > > this still generated the "defined but unused" warning. > > > > Then after changing the definition to > > > > static struct platform_device __init __maybe_unused *imx_add_imx_dma(void) > > > > (i.e. move the * after the attribute stuff) the warning is gone. In > > both cases (and when the function was used) it is put in the > > ".init.text" section though. That is in the first case __init worked, > > but __maybe_unused did not. Is this intended? Do I something wrong? > > What is the most correct position for function attributes for functions > > returning a pointer? > > > > (I'm using gcc 4.3.2 for arm, OSELAS.Toolchain-1.99.3.6 here. Could not > > reproduce with Debian's gcc 4.4.5 for x86 using a minimal example.) > > This message is not appropriate for the mailing list gcc@gcc.gnu.org. > It would be appropriate for gcc-help@gcc.gnu.org. Please take any > followups to gcc-help. Thanks. oops, ok, sorry. > The syntax for attributes is documented at > http://gcc.gnu.org/onlinedocs/gcc-4.5.1/gcc/Attribute-Syntax.html . This is heavy reading. And though I'd claim not to be a novice C programmer I don't understand it. For me static struct platform_device *__init __maybe_unused imx_add_imx_dma(void) makes most sense, because the * belongs to struct platform_device and it's imx_add_imx_dma() that is unused and should live in .init.text, not *imx_add_imx_dma(). > I think the differences you are seeing are because some attributes can > apply to types and some can only apply to declarations. Moving the > location of the __attribute__ affects which type it applies to. In > particular __attribute__ ((unused)) may be used with a type, but > __attribute__ ((section (...))) may only be used with a declaration. As far as I got it both section() and unused are variable/function attributes and not type attributes. So I think this explanation doesn't match, does it? Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |