[fpc-pascal] Shared libraries and threadvars
pascaldragon at googlemail.com
Wed Jun 27 07:25:50 CEST 2012
Am 26.06.2012 20:09 schrieb "Mark Morgan Lloyd" <
markMLl.fpc-pascal at telemetry.co.uk>:
> One final question if I may: noting Ludo's example elsewhere:
> > In the project.lpr add the following code:
> > Procedure qt_startup_hook;export;
> > Begin
> > End;
> > Exports qt_startup_hook;
> Can such an alternative entry point in the main unit be called by a
shared library, i.e. either resolved at load time or with the main binary
reopened like a library? Or is the only way to pass a main-program entry
point to a shared library by using it as a parameter to a procedure?
> I've used such things in a Windows-style .exe so a loader/binder would
know how to generate absolute code for an embedded system, but have never
tried exploiting it with a "real" OS.
I can't tell you for *nix systems as I'm not experienced enough regarding
their dynamic linkers, but I can tell you for Windows systems:
If you export functions from a executable (not a DLL) you can get access to
these methods from within a library the same way you'd do with a DLL
(though I don't know what happens if you load a unrelated executable). As
your executable is already loaded no further "instance" of it will be
There is also the possibility that you link to the executable at link time
(in Pascal using the "procedure bla; external 'your.exe' name 'bla'"
mechanism). I don't know whether you can build a circle here (in the sense
of having the exe depend on that DLL as well) as I have not tested that
that mechanism yet. Also there is only one case that I definitely know of
that uses this link time variant: drivers on NT based systems (which are
simply DLLs) link to ntoskrnl.exe and the kernel loads them dynamically.
You can see this if you look into the ndk.pas unit of my Native NT port
where the constant NTDLL is set to 'ntoskrnl.exe' instead of 'ntdll.dll' if
it is compiled with KMODE defined.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal