[rtems-users] C++ Virtual Functions

Phil Torre ptorre at zetron.com
Thu Feb 3 18:45:52 UTC 2005


On Thu, Feb 03, 2005 at 09:07:44AM -0500, Smith, Gene wrote:
> 
> I went back a read everything I could find on this list regarding this
> and several people have reported this problem. The only one who reported
> a resolution did like you and wrote their own initializer (Phil Torre).
> However there was a lot of discussion about "eabi" that got into the
> ctor init and pointed out that it occurs in a call to _init() in
> _Thread_Handler when __USE_INIT_FINI__ is defined. The _init() call
> occurs on my system as described which in turn calls etext and
> eventually __do_global_ctors_aux__ but I never see any constructors
> actually called before _init() returns. I assume it is supposed to call
> the constructors for any globally or statically defined c++ objects
> somewhere inside the _init() call?  Also, are these c++ objects supposed
> to be in the .bss section?
> -gene

Someone subsequently pointed out to me that this was the wrong thing
to do, so these days I have added crtbegin.o and crtend.o to our 
bsp_specs file, like so:

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

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

(I'm guity of cargo-cult programming here, as I don't actually understand
why this works.  It does the trick, though, and without requiring me to
explicitly call my own initializer function.)

-Phil
-- 

=====================================================================
Phil Torre                               phone: 425-820-6363 x234
Design Engineer                          email: ptorre at zetron.com
Switching Systems Group                    fax: 425-820-7031
Zetron, Inc.                               web: http://www.zetron.com



More information about the users mailing list