[fpc-devel] Memory leak on BeginThread() when RTL compiled with -O2

Yuriy Sydorov jura at cp-lab.com
Mon May 24 12:18:34 CEST 2021


Hello,

You have not read closely what I wrote before:

"When compiling RTL you should disable reading of options from fpc.cfg using the -n switch.
When compiling the system unit use the -Us switch.
Additionally specify only CPU/Target and optimization options -O<x>.
No other options are required for Windows RTL."

sysinitpas.pp is the part of the RTL. So in your example it is needed to be compiled as:

"%FPC_BINARY%" -Fu"%UNITS_DIR%" -FU"%SCRIPT_DIR%units" -n -O2 "sysinitpas.pp"

-n ensures the default state of the compiler settings. This is the intended state for compiling the RTL.

RTL must be compiled in the FPC mode. No other modes must be specified in the command line or fpc.cfg. You can't first 
pass the -Mdelphi switch and then override it with -Mfpc. -Mdelphi implicitly enables lot of other compiler options 
which are not reverted by -Mfpc.


Yuriy Sydorov,
jura at cp-lab.com

On 24.05.2021 12:00, NetSpirit via fpc-devel wrote:
> Unfortunately I tried it and this doesn't work.
> Problem only with 'sysinitpas.pp' unit.
> He is not depends on other RTL units, but linked into final executable by
> compiler.
> I suppose, compiler itself depends on internal layout of this unit.
> And a solution is to compile 'sysinitpas.pp' with the same options as
> 'ppc386.exe' was compiled, not RTL.
> 
> See my previuos demo: http://dl.free.fr/ePtkQwgJJ
> 
>> When compiling RTL you should disable reading of options from fpc.cfg
> using the -n switch.
>> When compiling the system unit use the -Us switch.
>> Additionally specify only CPU/Target and optimization options -O. > No
> other options are required for Windows RTL.
>>
>> When RTL is properly compiled, even with -O2, your test program works
> without memory leaks.
>>
>> Yuriy Sydorov,
>> jura at cp-lab.com
>>
> 
> 
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
> 


More information about the fpc-devel mailing list