On 2015-06-17 01:19, bitwise wrote:

Heh... trying ;)

Here, there seems to be a function to put things in ctors/dtors, but it
looks like it was copy pasted from the Elf code:
https://github.com/D-Programming-Language/dmd/blob/c718790165c3124c61e510d8352b9cb9d8ae0198/src/backend/machobj.c#L1532


I've rewritten the first line as follows, but still working on what I
need to do to actually put the function in there.
IDXSEC seg = s->Sseg = MachObj::getsegment("__mod_init_func", "__DATA",
2, S_MOD_INIT_FUNC_POINTERS);

I think the S_COALESCED flag could be added to the above to allow a
definition in every obj file like Martin's approach, but I would rather
have an explicit DllMain and put the init code in that one obj file. It
seems more intuitive to me.

So if I get Obj::staticctor and Obj::staticdtor working on osx, that's
half the problem solved... I think.

Obj::staticctor does not seem to be used for setting up the runtime. This is the code that generates the runtime initialization [1], I believe, at least it calls "_d_dso_registry". There's a lot more code there than I first hoped.

[1] https://github.com/D-Programming-Language/dmd/blob/c718790165c3124c61e510d8352b9cb9d8ae0198/src/backend/elfobj.c#L3183

--
/Jacob Carlborg

Reply via email to