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

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Sep 17 16:20:16 CEST 2009


On 17 Sep 2009, at 16:16, Lukas Zeller wrote:

>> Which FPC version are you using? I fixed shared library  
>> initialisation/finalisation for Mac OS X and Linux in FPC 2.2.4.
>
> I am using FPC 2.2.4 on Mac OS X and the problem happens there.

On which version of Mac OS X?

> 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.

> 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.


Jonas



More information about the fpc-devel mailing list