gdc so files
Kirk McDonald
kirklin.mcdonald at gmail.com
Fri Jan 12 13:33:06 PST 2007
sclytrack wrote:
> Kirk McDonald wrote:
>>The -nostartfiles point is important: gcc has default versions of these
>>functions that it will want to link in. If you end up using both this
>>and GCC's version, it gets very confused. -nostartfiles tells it to not
>>use the defaults, so these can be used instead.
>>
>>These days, _init and _fini are deprecated in favor of some built-in GCC
>>macros. These are obviously not available in D. Their use in Pyd is
>
>
> 1) More Information
>
> I wish there was some more information about
> shared libraries for linux on "some" place.
>
> Maybe with linking with a C file, for the
> __attribute__((constructor))
>
> Since gcc is readily available on linux
>
This is certainly possible. I did not go this route in Pyd, as sticking
with D for everything makes compilation that much simpler.
>
> 2) Shared Library _minit() and _moduleCtors()
>
> I don't find the _minit() routine, in what file is it located?
> What does _moduleCtor() do exactly, does anybody know?
>
You may find the following file in your DMD distribution useful:
dmd/src/phobos/internal/dmain2.d
When a D program is started, the actual entry point is the extern(C)
main function in that file, which in turn calls the one you define in
your program. That is where the calls to gc_init and all the rest are
made for regular executables. (It also does some other things, like run
main() inside an exception-safe environment, and convert int argc,
char** argv to char[][] args.)
> These two routines are called in the windows DLL version.
>
> The two routines above don't appear to be called
> in the PyD (linux) project. (nice project by the way, and thanks
> the reference to _init() and _fini() )
>
Correct: Pyd does not call _init and _fini. Linux (or perhaps Python)
calls them when an extension using Pyd is loaded. Pyd (or, more
properly, CeleriD, which is Pyd's build utility) merely makes sure they
are linked in to the .so.
> I've linked it with the so file and the static this()
> and ~this() appear to be called of the from the module in the shared library. Automatically. Without me telling to do so.
>
> Just wondering whether the _moduleCtor() calls these static this()
> or not. For me it segfaults
> on that routine, but I don't have the _minit().
>
The dmain2.d file leads me to believe that _minit() is only available on
Windows. I haven't played with this stuff on Linux since I wrote that
Linux boilerplate file, so I forget the details of what is called and
what isn't.
--
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org
More information about the Digitalmars-d-learn
mailing list