[fpc-devel] FPC shared lib called from C shared lib called from C main program crashes

Lukas Zeller luz_info at synthesis.ch
Thu Sep 17 17:28:51 CEST 2009


Hi Jonas,

On Sep 17, 2009, at 16:20 , Jonas Maebe wrote:

>> I am using FPC 2.2.4 on Mac OS X and the problem happens there.
>
> On which version of Mac OS X?

Now Snow Leopard 10.6.1, but we have a parallel installation on  
Leopard 10.5.latest that also shows the problem.

>
>> And in fact it was - while re-testing everything for writing this  
>> email, by accident I found the following:
>>
>> The Write in the library initialisation is required if any other  
>> part of the library wants to write to stdout later as part of the  
>> normally called library functions. As soon as there is no single  
>> Write or WriteLn called anywhere in the library, it works.
>
> That is strange.
>
>> So for practical purposes of our project, the problem is solved (we  
>> don't want any stdout from the library anyway, the ones that caused  
>> the crash were quick hacks inserted for debugging).
>>
>> For technical curiosity however I still wonder what interals of the  
>> runtime a Write or WriteLn in the library init code initializes  
>> correctly while the same Write called later in a normal library  
>> function makes the program crash.
>
> The RTL initialisation code is run before any code in the  
> initialisation section is executed.

Ok. I assume the RTL initialisation and the library initialisation  
block are BOTH run as part of the system level shared lib  
initialisation (DLL main entry point), in that order, correct?

>> More precisely, I think in the later call to Write it still tries  
>> to initialize something, but then has side effects on other data  
>> structures in the runtime, which for example make memory  
>> allocations crash - note that the Write/WriteLn themselves WORK,  
>> i.e. show on the console, but make the program crash shortly  
>> afterwards (as said, my observation was during allocation of a  
>> TObject, although the debugging situation was a bit difficult so I  
>> could be mistaken here).
>
> If you can create a test that reproduces the problem, please submit  
> a bug report.

I could. Actually it also happens without the in-between C shlib. A C  
main with a FPC shlib is sufficient.

I have a 10 lines sample program that shows the effect nicely. As a  
FPC community newbie - where should I post the sample and the bug  
report to? Not to this list, I assume...

Lukas



More information about the fpc-devel mailing list