From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: Franck Jullien <franck.jullien@gmail.com>
Cc: barebox <barebox@lists.infradead.org>
Subject: Re: GCC question
Date: Thu, 10 Jan 2013 13:36:34 +0100 [thread overview]
Message-ID: <20130110123634.GB22953@game.jcrosoft.org> (raw)
In-Reply-To: <CAJfOKBzoXNvQu38qXXu9w9fyBuWqC_kAmHUqw2Z5B=8d9ymejg@mail.gmail.com>
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
next prev parent reply other threads:[~2013-01-10 12:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-09 9:02 Franck Jullien
2013-01-09 9:09 ` Sascha Hauer
2013-01-09 9:13 ` Franck Jullien
2013-01-09 9:28 ` Sascha Hauer
2013-01-10 12:36 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-01-10 12:52 ` Franck Jullien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130110123634.GB22953@game.jcrosoft.org \
--to=plagnioj@jcrosoft.com \
--cc=barebox@lists.infradead.org \
--cc=franck.jullien@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox