This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Figuring out start and end of sections


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]