--- Begin Message ---
- From: Felipe Balbi <me at felipebalbi dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Date: Wed, 14 Apr 2010 09:17:33 +0300
- Subject: Re: Figuring out start and end of sections
- Reply-to: me at felipebalbi dot com
Hi Ian,
I guess my mailer is fishy, didn't get your mail either
Ian Taylor <iant@google.com> writes:
>> 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.
>>
>> Do I need a specific linker script to achieve that or does the default
>> scripts give me possibility to find that out ?
>
> If you are using the GNU linker, or gold, and you make the section
> name a valid C identifier, then the linker will automatically define
> symbols __start_SECNAME and __stop_SECNAME which you can use.
so you're saying that something if I name my section _init then I should
have __start__init and __stop__init identifiers ??
The following isn't compiling:
#include <stdio.h>
typedef int (*initcall_t)(void);
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;
int main(int argc, char *argv[])
{
initcall_t *fn;
for (fn = __start__initcall; fn <
__stop__initcall; fn++)
(void) fn();
return 0;
}
do I need to pass any particular option to gcc/ld to get that working ??
--
balbi
--- End Message ---