Compiler fail lazarus / 13-General ---------------------------------------------------------------------- anna · 2012-08-31 08:41 Compiler converts same slices of asm-code by different ways. See this message: http://www.lazarus.freepascal.org/index.php/topic,17968.msg101124.html #msg101124 As you can see binary data of executable differs (OllyDBG debugger was used). Why it was happened? ---------------------------------------------------------------------- theo · 2012-08-31 10:04 I would ask in fpc-devel  http://freepascal.org/maillist.var ---------------------------------------------------------------------- ludob · 2012-08-31 10:11 The difference is that cheaten uses delphi mode and your testprogram probably objfpc mode. Delphi mode doesn't generate stackframes anymore for pure assembler functions. The missingCode: [Select]PUSH EBP  MOV EBP,ESP ... LEAVE is the stackframe code. See http://wiki.freepascal.org/User_Changes_2.2.0#Pure_assembler_routi nes_in_Delphi_mode. Edit: I tried adding {$W+} to force stackframes but that doesn't work for pure assembler functions. Edit: but adding {$MODE objfpc} at the top of BigInt18 does work ---------------------------------------------------------------------- anna · 2012-08-31 12:28 Quote from: ludob on August 31, 2012, 12:11:32 pmThe difference is that cheaten uses delphi mode and your testprogram probably objfpc mode. Delphi mode doesn't generate stackframes anymore for pure assembler functions. The missingCode: [Select]PUSH EBP  MOV EBP,ESP ... LEAVE is the stackframe code. See http://wiki.freepascal.org/User_Changes_2.2.0#Pure_assembler_routi nes_in_Delphi_mode. Edit: I tried adding {$W+} to force stackframes but that doesn't work for pure assembler functions. Edit: but adding {$MODE objfpc} at the top of BigInt18 does work Thank you very much . But for what purpose developers made different processing asm-code in delfi and objfpc? ---------------------------------------------------------------------- ludob · 2012-08-31 13:21 Delphi added a compiler optimisation at one stage breaking iirc TP behavior. Since Delphi mode is supposed to be compatible with Delphi, fpc had to implement 2 different behaviors. ---------------------------------------------------------------------- taazz · 2012-08-31 13:28 Quote from: ludob on August 31, 2012, 03:21:54 pmDelphi added a compiler optimisation at one stage breaking iirc TP behavior. Since Delphi mode is supposed to be compatible with Delphi, fpc had to implement 2 different behaviors. err, Delphi compatibility in what level? Is it really needed an asm compatibility and for what reason? I am under the impression that compatability is on the source code level aka the parser and I don't understand why should it have asm compatibility as well. ---------------------------------------------------------------------- ludob · 2012-08-31 13:46 QuoteIs it really needed an asm compatibility and for what reason?If you want to run delphi code that uses assembler functions the compiler would better generate the same function prologue.  When a stackframe is used, pushed parameters and local variables on win32 are relative to EBP. When no stackframe is used, they are relative to ESP. This is just the same as any other calling convention fpc is trying to be compatible with. The compiler has to set up all registers as defined in the convention. Nothing says that this has to be done in this case with Code: [Select]PUSH EBP  MOV EBP,ESP ... LEAVEbut why re-invent the wheel when these instructions are used everywhere to obtain the expected result? ---------------------------------------------------------------------- anna · 2012-09-01 08:17 Quote from: ludob on August 31, 2012, 03:46:24 pmQuoteIs it really needed an asm compatibility and for what reason?If you want to run delphi code that uses assembler functions the compiler would better generate the same function prologue.  When a stackframe is used, pushed parameters and local variables on win32 are relative to EBP. When no stackframe is used, they are relative to ESP. Stack is always pointed by ESP. ---------------------------------------------------------------------- ludob · 2012-09-01 08:40 QuoteStack is always pointed by ESP.Yes, but when a stackframe is used the procedure will reference pushed parameters and local variables relative to ebp instead of esp. That is why your assembler procedures crashed without a stackframe. They referenced a EBP that is not set up correctly. For more info see fe. http://en.wikibooks.org/wiki/X86_Disassembly/Fun ctions_and_Stack_Frames or http://www.guidogybels.eu/asmch3.html