[cfe-dev] Clarification for __cxx_global_var_initN and _GLOBAL__I_a

salvatore benedetto salvatore.benedetto at gmail.com
Wed Sep 12 11:01:42 PDT 2012


On Tue, Sep 11, 2012 at 11:35 PM, salvatore benedetto
<salvatore.benedetto at gmail.com> wrote:
> Hi there,
>
> I'm using clang to cross compile my firmware for an ARM based cpu.
>
> I need to set up the C++ environment myself, which means I have
> to call the constructors of all static objects.
>
> After a bit of searching on the matter I saw that GCC have a
> specific ELF section for this (.ctors*), where constructors address are
> laid out in an array etc... so I was looking for the same on clang.
>
> By looking at the generated ELF I found not such section, and
> by looking at the disassembled code I instead noticed the __cxx_global_var_initN
> symbols, and a quick grep on clang source code brought me to
> CreateGlobalInitOrDestructFunction which seems to generate the calls themselves.
>
> Still by looking at the dissambled I noticed the _GLOBAL__I_a routine where
> all the calls to the various __cxx_global_var_initN are placed. So far so good.
>
> Unfortunately though I get more than one _GLOBAL__I_a symbol in the
> final binary,
> and a simple call to _GLOBAL__I_a in my startup code does not work.
> Are they placed in a particular section?
>
> Now, I could keep digging in the clang and libcxxabi code base until eventually
> (hopefully) I find the answer :-) but I would really appreciate if
> someone can point me
> to a document that explain how this process works and what I need to
> get it done?
>
> Thanks,
> Salvatore

Never mind. My fault.

I was looking for the wrong section.
.init_array did the job.

Sorry for the noise.

Regards,
Salvatore



More information about the cfe-dev mailing list