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: Figurig out start and end of sections


Hi Andrew,

for some reason I didn't receive your reply.

>On 04/13/2010 06:40 PM, Felipe Balbi wrote:
>> is there any way to figure out where a section starts and ends ?
>> 
>> I added a specific section to my program using
>> __attribute__((section "<section name>")) and now I want to figure out
>> where that section starts so I can iterate over it and call the
>> function
>> pointers I'm adding to it.
>
>Terminate the list with a null pointer; AFAIK that's what everyone else
>does.  To get the start address, you just need to define a global
>variable
>in that section.  Of course this means you have to link everything in
>the
>correct order.

I think you're talking about something like:

void (*func_ptr)(void)[] __attribute__((section ".my_section")) = {
	func1,
	func2,
	func3,
	NULL,
};

is that right ? (the code above isn't really correct).

I don't really have an array. I'm trying to mimic what the kernel does
with the modules, but then again, the kernel declares the constants for
the start and end of initcalls in constants within the ld script.

So what I have right now is:

main.c:

[..]

int __attribute__((section(".init"))) register_struct(struct my_struct *ptr)
{
	[..]
}

[..]

static int call_initcalls(void)
{
	initcall_t	*fn;

	for (fn = __start_initcall; fn; fn++)
		fn();

	return 0;
}

then on another source code, I define an initcall_t.

initcall.c:

[..]

static int __attribute__((section(".init"))) init(void)
{
	return register_struct(ptr);
}

static initcall_t initcall_t_init __attribute__((section(".my.init")))
	__attribute__((__used__)) = init;

then several little "plugins" would define that and all those pointers
are going to the right section. Now how to fetch them and call them ??
currently I'm getting segfault. :-p

-- 
balbi


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