Recent

Author Topic: [SOLVED] Strange AV in asm proc  (Read 1678 times)

guest58172

  • Guest
[SOLVED] Strange AV in asm proc
« on: November 05, 2017, 02:32:23 pm »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$Mode objfpc}
  4. {$AsmMode intel}
  5.  
  6. type TProc = function(): PtrInt;
  7.  
  8. function AllInOne(): PtrInt; assembler;
  9. asm
  10.   mov rax, 1 // 9 bytes
  11.   ret        // 1
  12.   nop        // + 6
  13.   nop
  14.   nop
  15.   nop
  16.   nop
  17.   nop
  18.   mov rax, 2 // this EIP is then aligned to 8...
  19.   ret
  20. end;
  21.  
  22. var
  23.   proc1, proc2: TProc;
  24.  
  25. begin
  26.   proc1 := @AllInOne;
  27.   proc2 := TProc(pointer(proc1) + 16);
  28.   writeln(proc1());
  29.   writeln(proc2());
  30. end.

The call to proc2 is okay but not the one to proc1. The idea is to generate the code for several function in one and then to play with code offsets. There no temporaries, no stack frame... why does this AV occurs then ?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12838
  • FPC developer.
Re: Strange AV in asm proc
« Reply #1 on: November 05, 2017, 03:52:48 pm »
Check the assembler generated? I don't see a nostackframe modifier.

guest58172

  • Guest
Re: Strange AV in asm proc
« Reply #2 on: November 05, 2017, 04:18:30 pm »
Aw yeah it works with the`nostackframe;` attribute. I thought there was no stack frame because the prologue and the epilogue were not generated.

 

TinyPortal © 2005-2018