- 论坛徽章:
- 0
|
1. Add to .init section, be called in .init before __do_global_ctors_aux
CODE:
int oinit(void)
{
__asm__ (".section .init \n"
"bl oinit
\n\t" /* for arm, or "call oinit \n\t" for x86
".section .text"); /* you can also put this out of the function */
printf("In o init by insert to .init section");
}
2. Add to .ctors section, will be called by function __do_global_ctors_aux
CODE:
static void *__libinit __attribute__((section(".ctors"))) = libinit;
int libinit(void)
{
......
}
3. Use constructor attribute(alost added to .ctors section as method 2):
void func(void) __attribute__((constructor));
void func(void)
{
printf("In lib's Constructor.\n");
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/15482/showart_90614.html |
|