C++ static constructor problem

gregory.menke at gsfc.nasa.gov gregory.menke at gsfc.nasa.gov
Tue Nov 26 16:27:03 UTC 2002

Till Straumann writes:

 > > 
 > > In my application, there are some C++ static constructors which are
 > > supposed to run on application startup.  However, it did not happen at
 > > all. It seems that  __do_global_ctors was not  in the gcc library.
 > > My question is that is the C++ static constructors implemented
 > > in the gcc-3.2 cross compiler  for powerpc or maybe it is just my local
 > > building error ?

This is probably a linker script and/or specs problem.  The default
specs in the last few snapshots does not handle the crtbegin/crtend
stuff correctly, so some of the objects never get included in the
link- leading to the ctor/dtors not even being present in the

In a C app, some of the ctor/dtor stuff is still there, but the
constructors are effectively no-ops and it only amounts to a couple
hundred bytes of overhead.

Below is my bsp_specs, it does seem to invoke static constructors
properly using gcc 3.2 on the mcp750 and mtx603e.  I'll submit it to
Joel fairly soon, but I've other fixes that need to go in for our
Mongoose BSP that I have to complete.

%rename cpp old_cpp
%rename lib old_lib
%rename endfile old_endfile
%rename startfile old_startfile
%rename link old_link

%(old_cpp) %{qrtems: -D__embedded__ -DUSE_ENHANCED_INTR_API} -Asystem(embedded)

%{!qrtems: %(old_lib)} %{!nostdlib: %{qrtems: --start-group \
%{!qrtems_debug: -lrtemsbsp -lrtemscpu} %{qrtems_debug: -lrtemsbsp_g -lrtemscpu_g} \
-lc -lgcc --end-group  \
%{!qnolinkcmds: -T linkcmds%s}}}

%{!qrtems: %(old_startfile)} %{!nostdlib: %{qrtems:  ecrti.o%s  crtbegin.o%s  \
%{!qrtems_debug: start.o%s} \
%{qrtems_debug: start_g.o%s}}}

%{!qrtems: %(old_link)} %{qrtems: -Qy -dp -Bstatic -e __rtems_entry_point -u __vectors}

%{!qrtems: %(old_endfile)} %{qrtems: crtend.o%s ecrtn.o%s}


More information about the users mailing list