C++ problems with sh4

Joel Sherrill joel.sherrill at OARcorp.com
Thu Nov 8 12:50:46 UTC 2001


Alexandra Kossovsky wrote:
> 
> On Mon, Nov 05, 2001 at 07:06:42AM -0600, Joel Sherrill wrote:
> >
> > Alexandra Kossovsky wrote:
> > >
> > > Hi!
> > >
> > > I have gensh4 bsp, and I need C++ to work.
> > > It worked perfectly with ss-20010816
> > >
> > > Now, in ss-20011017 (or ss-20011025) it does not work.
> > > The problem is with global constructors -- they are not called.
> > >
> > > gcc does not define __USE_INIT_FINI__ for sh4.
> > > In 'gcc-2.95.3/gcc/config/sh/elf.h' there is:
> > > ---------
> > > /* Arrange to call __main, rather than using crtbegin.o and crtend.o
> > >    and relying on .init and .fini being executed at appropriate times.  */
> > > ---------
> > >
> > > In ss-20010816 gcc calls '__do_global_ctors' on the begining of 'main()',
> > > and all is OK. In ss-20011025 where are no 'main()'.
> > >
> > > What can I do?
> > > Should I patch gcc to do all this things through init & fini ?
> > > Or something else?
> >
> > We did this because making main() available in user space is generally
> > a good thing.
> >
> > Hmm... I see two possibilities.  As an experiment, change the name of
> > the first task to main() and verify things work.
> 
> OK, it works.
> 
> > If that does in fact work, then we might want make the toolset
> > define __USE__MAIN__ and have an alternative next to the
> > __USE_INIT_FINI__.
> > That presupposes that this won't result in the global ctors being
> > called twice if someone uses main().
> 
> It would be fine. Can I help with this work?

I don't think there is much you can do except provide some
information.  I will need to patch the file gcc/config/sh/rtems.h,
generate a new gcc patch, and crank RPMs.  Some questions:

  + If we call __main like __init and there is a user main(),
    is it safe to call __main twice?  
  + What about global destructors when using __main?  How do
    they get invoked?
  + (less important) what other RTEMS tool configurations use 
    __main?

> --
> 
> Alexandra Kossovsky
> OKTET Ltd.
> 1 Ulianovskaya st., Petergof, St.Petersburg, 198904 Russia
> Phones: +7(812)428-43-84(work) +7(812)184-52-58(home) +7(812)956-42-86(mobile)
> e-mail: sasha at oktet.ru (or sasha at gate.ort.spb.ru)

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985



More information about the users mailing list