This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Figuring out start and end of sections
- From: Felipe Balbi <me at felipebalbi dot com>
- To: Felipe Balbi <me at felipebalbi dot com>
- Cc: gcc-help at gcc dot gnu dot org, iant at google dot com
- Date: Wed, 14 Apr 2010 09:47:51 +0300
- Subject: Re: Figuring out start and end of sections
- References: <20100414062234.GB4285@gandalf> <20100414063043.GC4285@gandalf>
- Reply-to: me at felipebalbi dot com
Hi,
On Wed, Apr 14, 2010 at 09:30:43AM +0300, Felipe Balbi wrote:
> I commented the for loop just to get the thing compiling and nm doesn't
> show any __start_ symbols:
now I got it working:
#include <stdio.h>
typedef int (*initcall_t)(void);
extern initcall_t __start__initcall[];
extern initcall_t __stop__initcall[];
static int my_init(void)
{
printf("hello world from _init\n");
}
static initcall_t __my_initcall_my_init
__attribute__((__used__))
__attribute__((section("_initcall"))) = my_init;
static void call_initcall(initcall_t fn)
{
fn();
}
int main(int argc, char *argv[])
{
initcall_t *fn;
for (fn = __start__initcall; fn
< __stop__initcall; fn++)
call_initcall(*fn);
return
0;
}
thanks a lot Ian and Andrew.
--
balbi