[haiku-development] Re: complex constructors in kernel (following #4782)

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 27 Oct 2009 12:28:04 +0800

On 2009-10-27 at 01:57:58 [+0800], Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> 
wrote:
> > > Replying to [comment:20 bonefish]:
> > > > > Hm, I would prefer a more clear/descriptive mechanism, like
> > > > > putting
> > > > >  them into a different ELF section, and then skip them when
> > > > > calling the
> > > > >  constructors.
> > > > What "them" do you mean? I thought we're talking about
> > > > constructors,
> > > > but then your sentence doesn't make sense.
> > > It did to me ;-) When we move constructors into a separate segment,
> > > the
> > > constructor calling code could ignore them, giving you the
> > > opportunity to
> > > initialize them manually.
> > The constructor calling code -- I assume you mean crtbegin.o, which
> > we
> > don't even link against ATM -- shall ignore the constructors, so we
> > can
> > invoke them manually? Sorry, I'm still at a loss.
> 
> What I meant is something like this:
> static class Object sObject __attribute__ ((section ("complex.init")));

I'd say something like this would put the variable into the respective 
section, which is probably not what you mean. AFAIK static constructors 
live in a separate section anyway (".ctors" I'd guess).

> Since we have to call the constructors manually anyway at some point
> (we're already doing that in the boot loader, see src/system/boot/
> platform/bios_ia32/start.c),

Or link against crtbegin.o and call the init function instead.

> we can as well check their section before
> doing so.

It slowly dawns on me, what you're trying to say. You want to introduce 
some means to mark certain static constructors so that they aren't invoked 
automatically. I find that unnecessarily complicated, though. I would 
rather call all constructors and adjust the code that has constructors that 
shouldn't be called that early. Either by moving code from the constructor 
to an explicit Init() method or by constructing the object explicitly in a 
static buffer like:

        static char sObjectBuffer[sizeof(Foo)];
        static Foo* sObject;
        ...
        sObject = new(sObjectBuffer) Foo;

CU, Ingo

Other related posts: