[fpc-pascal] Reproducible code: DLL calling Firebird crashes

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Tue Sep 30 11:27:10 CEST 2014


Reinier Olislagers wrote:
> On 29/09/2014 19:30, Reinier Olislagers wrote:
>> Re bug report: agreed. I'll raise it.

Jonas has already closed it, noting

"http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583%28v=vs.85%29.aspx

"***
The entry-point function should perform only simple initialization or 
termination tasks. It must not call the LoadLibrary or LoadLibraryEx 
function (or a function that calls these functions), because this may 
create dependency loops in the DLL load order. This can result in a DLL 
being used before the system has executed its initialization code.
***

"I.e., what you are doing is unsupported ("must not call the LoadLibrary 
or LoadLibraryEx function"). I think that on most unix platforms, trying 
to load libraries from other the init function of other libraries is not 
supported either."

However I'd precede that by a thought based on what Jose said. In your 
example, you're opening the database in the initialisation block of 
businesslayer.pas, which is invoked at an arbitrary position in the init 
sequence of the DLL/so. If that operation were moved instead to the 
initialisation block of testdbdll.lpr, which in the context of the 
DLL/so is analogous to a program's main block, it might work.

If having the open operation in testdbdll.lpr works but having it in 
businesslayer.pas doesn't, then it's fair to ask why in the context of 
FPC (hence my suggestion of a bug report). If neither works, then it's 
presumably explained by Jonas's note i.e. it's a "feature" in the 
context of the library loader.

In practice, I still think it's best for the main program to tell the 
database when and how to initialise, since there's things that it might 
know about the user's intentions or environment that aren't known by the 
dynamically-loaded libraries (crude example: you might want to know the 
compile-time name of the project of which the main program was a part).

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list