lnkscript .ctors/.dtors; Must be in RAM or can be in ROM?
William A. Gatliff
bgat@saturn.billgatliff.com
Mon Jul 30 18:51:00 GMT 2001
Jeff:
.ctor and .dtor are function pointer tables.
To see how they work, compile any C++ module that has global object
instantiations in it, and look at the assembly language. In general,
what happens is (at least for the PPC EABI target) the compiler
generates a function that contains a "this" pointer for the global
object, and a call to the object's constructor.
.ctor and .dtor are lists of pointers to these functions. For the
EABI target, putting them in ROM is ok.
Here's a snipped from some of my ppc-eabi startup code, that you may
find illustrative:
/* a symbol created by the linker, resides at the start of .ctor. */
extern void (*__CTOR_LIST__[])(void);
/* the end of .ctor */
extern void (*__CTOR_END__[])(void);
/*
Invokes constructors by walking through
all the function pointers in the .ctor section.
*/
void __eabi_ctors ( void )
{
int wctor;
int nctor = __CTOR_END__ - __CTOR_LIST__;
for( wctor = 0; wctor < nctor; wctor++ )
(*(__CTOR_LIST__[wctor]))();
return;
}
HTH,
b.g.
On Mon, Jul 30, 2001 at 06:13:17PM -0500, Jeff Frohwein wrote:
> A friend of mine has a link script which includes the following sections
> for embedded c++ support. I have spent the last 8 hours searching these
> archives & doing web searches to figure out if it is reasonable to put
> these sections in ROM.
>
> I have found several posts that mention they should be in RAM. However,
> they did not state their reasoning for this.
>
> My friend suggests that he has had no problems with his code by putting
> then in ROM.
>
> Can anyone guide me towards a definitive answer or direct me to where I
> can locate such?
>
> Thanks,
>
> Jeff
> ---------------
> .ctors :
> {
> KEEP (*crtbegin.o(.ctors))
> KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
> KEEP (*(SORT(.ctors.*)))
> KEEP (*(.ctors))
> . = ALIGN(4);
> } >ROM =0
>
> .dtors :
> {
> KEEP (*crtbegin.o(.dtors))
>
> KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
> KEEP (*(SORT(.dtors.*)))
> KEEP (*(.dtors))
> . = ALIGN(4);
> } >ROM =0
>
> ------
> Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
> Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
>
--
Bill Gatliff
bgat@billgatliff.com
------
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
More information about the crossgcc
mailing list