This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


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

Re: __CTORS__


>>>>> "Rafael" == Rafael Rodríguez Velilla <rrv@tid.es> writes:

Rafael> void cyg_invoque_constructors(void) { pfunc *p; for
Rafael> (p=&__CTOR_END__[-1];p >= __CTOR_LIST__;p--) (*p) (); }

Rafael>   I have search what these extern symbols are (__CTOR_LIST__
Rafael> and __CTOR_END__). I found it at the linker script arm.ld.
Rafael> Can anybody explain me which constructors are referenced at
Rafael> __CTOR__LIST__ and what does it means when you reference it
Rafael> with brackets? The symbol at arm.ld is just __CTOR_END__, but
Rafael> at this routine is called with __CTOR_END__[-1].

The two symbols are the limits of an array of pointers to
constructors. The pointers in this array get sorted (see linker
script) according to their priority. We add the brackets in the C code
to make the compiler treat the symbols as array references -- type
information only exists in the compiler; in the linker a symbols is
just named entity associated with an address.

The code above iterates through the array from the top to the bottom
(end-1 to start), calling each constructor in turn.

Hope that helps.

Jesper

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