[rtems-users] C++ Virtual Functions

Smith, Gene gene.smith at siemens.com
Wed Feb 2 17:12:37 UTC 2005


Joel Sherrill <joel at OARcorp.com> wrote, On 2/1/2005 4:07 PM:

> gregory.menke at gsfc.nasa.gov wrote:
> 
>>Smith, Gene 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.
>> > 
>> > Tks,
>> > -gene
>>
>>This is generally caused by problem with the linkscript where the
>>various tables are set up incorrectly.  The motorola_shared bsp link
>>script works, so you might compare them for discrepancies.  It might
>>also be related to your gcc- but I'd check the linkscript first.

Are you referring to the powerpc/motorola_powerpc/startup/linkcmds when 
you say "motorola_shared"? I appears similar to the psim version in cvs.

> 
> 
> psim on the CVS head and post 4.6.2 on the 4.6 branch is also supposed
> to work for C++.
> 
> Look at the bsp_specs as well for crt*.
> 
> If you have a simple example, you want tried on another BSP, post it.

Don't have a simple example.

Thanks for responses. The vtable addresses look ok when dumped with nm.
I see crt* in bsp_spec which is unchanged from helas and ppc40x bsp's.
However 4.6.1 psim is some different (crt in *startfile instead of
*lib). No idea what this means.

However, I think I see basically how things are going wrong. The derived
class containing the virtual function implementation is instantiated as
a global variable. I never actually see its constructor being called
(and it should occur before main I think I have read). It is showing up
in section .bss according to objdump. Therefore, it is getting zeroed
out at startup, including the _vptr value. At least I think that is
happening.

When I look at the psim head linkcmd file in CVS I see differences
regarding placement of CTOR and DTOR stuff. I probably need to tailor my
linkcmds file to be more like the head (1.18.2.4) psim version. Does
this sound reasonable? Or can someone point out to me what might be
wrong in my current linkcmds file, attached.

Thanks for the help.
-gene

P/S: The attached linkcmds actually just builds a image that runs from
ram with no rom yet involved. I load it to ram with a jtag debugger.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: linkcmds
URL: <http://lists.rtems.org/pipermail/users/attachments/20050202/3f6b6e25/attachment.ksh>


More information about the users mailing list