ELF without .init section
Tzu-Chien Chiu
tzuchien.chiu@gmail.com
Fri May 5 19:00:00 GMT 2006
Hello, everyone:
How to make the constructors and destructors of global C++ objects be
called without using the .init and .fini sections in ELF?
I'm building a cross gcc. We used a very simple RTOS which doesn't
support an ELF loader (there is no loader at all), so the .init and
.fini section cannot be used to call ctors and dtors. After reading
the GCC Internals, I decided to #defined/#undefined the symbols in
gcc/config/or32/or32.h (the "_machine_.h"):
#definde INVOKE__main 1
#undef HAS_INIT_SECTION
#undef INIT_SECTION_ASM_OP
I disassembled the resulted libgcc.a, but I didn't find symbol
__do_global_ctors. It seems the processor symbol HAS_INIT_SECTION is
_not_ #undef'ed. Why? Did I insert the #define/#undef in the wrong
place?
FILE: libgcc2.c
...
#ifndef HAS_INIT_SECTION
/* Run all the global constructors on entry to the program. */
void
__do_global_ctors (void)
{
#ifdef EH_FRAME_SECTION_NAME
{
static struct object object;
__register_frame_info (__EH_FRAME_BEGIN__, &object);
}
#endif
DO_GLOBAL_CTORS_BODY;
atexit (__do_global_dtors);
}
#endif /* no HAS_INIT_SECTION */
--
Tzu-Chien Chiu - SMedia Technology Corp.
URL: http://www.csie.nctu.edu.tw/~jwchiu/
More information about the Gcc-help
mailing list