[rtems-users] C++ Virtual Functions

Smith, Gene gene.smith at siemens.com
Wed Feb 2 20:24:10 UTC 2005


Sergei Organov wrote, On 2/2/2005 12:10 PM:

> "Smith, Gene" <Gene.Smith at siemens.com> writes:
> 
>>I am having some problems running code containing C++ virtual functions in
>>rtems. When the code tries to branch to a virtual function address using
>>"bctrl" instruction, the address (in ctr) is way out of range and results in
>>a machine check exception.
>>
>>Is there anything I need to do special in rtems for virtual functions to
>>work? Is anyone using virtual functions, pure or impure, in rtems? I am
>>still using rtems 4.6.1 and my ppc40x-derived bsp.
> 
> 
> Besides what others have already suggested to check for, it could be the
> case that you call a virtual member function of a static or global
> object for which constructor hasn't been invoked (yet). In this case
> virtual table pointer in the object isn't initialized. Global
> constructors are invoked by special startup code so you need to check if
> this code is linked in and executed. Check for .ctors section in the
> executable as well.

Yes, that is what I just concluded in my previous post to this thread. I 
could see *no* .ctors or .dtors sections in my original output file. The 
.ctors and .dtors sections were supposedly placed into the .text section 
(see the attached linkcmds on previous msg). I then moved them out of 
.text into their own sections following .got2 (as shown in referenced 
example linkcmds, psim and motorola) and now I do see the sections 
.c(d)tors in the output following .got2. However, I still don't seem to 
see any initialization (construction) of the global object in question 
(its constructor is never hit when a breakpoint is put on it).

-gene








More information about the users mailing list