From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from 3.mo1.mail-out.ovh.net ([46.105.60.232] helo=mo1.mail-out.ovh.net) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TtHOb-0002Nh-4b for barebox@lists.infradead.org; Thu, 10 Jan 2013 12:38:10 +0000 Received: from mail615.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo1.mail-out.ovh.net (Postfix) with SMTP id B08CEFF8772 for ; Thu, 10 Jan 2013 13:51:45 +0100 (CET) Date: Thu, 10 Jan 2013 13:36:34 +0100 From: Jean-Christophe PLAGNIOL-VILLARD Message-ID: <20130110123634.GB22953@game.jcrosoft.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: barebox-bounces@lists.infradead.org Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: Re: GCC question To: Franck Jullien Cc: barebox On 10:02 Wed 09 Jan , Franck Jullien wrote: > Hi, > > I have a question not directly related to Barebox but I think I can > find some answer here: ) > > I would like to use initcalls in a Linux user's land program on a x86 target. > > I'm doing something like this: > > #ifndef _INIT_H > #define _INIT_H > > typedef int (*initcall_t)(void); > > extern initcall_t __start_target, __stop_target; > > #define target_initcall(fn) static initcall_t _##fn \ > __attribute__((used)) \ > __attribute__ ((section("target"))) = fn > > #endif > > then: > > initcall_t *initcall; > > for (initcall = &__start_target; > initcall < &__stop_target; initcall++) { > printf("initcall-> %p\n", *initcall); > ret = (*initcall)(); > if (ret) > printf("initcall %p failed: %d\n", *initcall, ret); > } > > Everything looks fine except the linker removes the function > "initcalled" because it is not > referenced anywhere and this is normal. > > I have not modified the linker script (I'm using the default one). I'm > using auto generated > __start_target and __stop_target symbols generated by the linker. > > My question is: why does it work in barebox ? For example, in > nios2/generic.c we have only > static function and initcalls. So why the linker does optimize out > those functions ? Is it > because we have initcall corresponding sections in the linker script ? on userspace you can use directly the contructor Best Regards, J. _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox