View Issue Details

IDProjectCategoryView StatusLast Update
0033565FPCCompilerpublic2019-11-03 18:14
ReporterFiliuta VitaliAssigned ToFlorian 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformi386OSWindowsOS Version10
Product Version3.1.1Product Buildr38673 
Target VersionFixed in Version3.3.1 
Summary0033565: Wrong register used for fpc_check_object in compilers asm code, that cause EAccessViolation.
DescriptionTroublemaker code and asm file attached.

execute result:

An unhandled exception occurred at $00402B27:
EAccessViolation: Access violation
  $00402B27
  $0040174D SETMEMORY, line 12 of app_test_core.pas
  $00401813 main, line 27 of app_test_core.pas

error here:

  procedure SetMemory(Stream: TStream; var P: Pointer; var PSize: Integer);
  begin
    PSize := Stream.Size;
    GetMem(P, PSize);
    Stream.Position := 0;
    Stream.Read(P^, PSize); // <-- Line 12, error here
  end;

asm of "Stream.Read(P^, PSize);":

# -8(%ebp) - @P
# -4(%ebp) - @PSize
# -16(%ebp) - Stream

# [12] Stream.Read(P^, PSize);
    movl -8(%ebp),%eax
    movl (%eax),%edx <-------------- %edx = P ; %eax = @P
    movl %edx,-12(%ebp)
    movl -4(%ebp),%eax
    movl (%eax),%edi <-------------- %edi = PSize ; %eax = @PSize
    movl -16(%ebp),%esi <----------- %esi = Stream
# Var Stream located in register eax
    movl %eax,%ebx <---------------- from here %eax = @PSize used to check Stream object
    testl %ebx,%ebx
    jne .Lj16
    call fpc_objecterror
    .balign 4,0x90
.Lj16:
    movl (%ebx),%ebx
    movl %ebx,%eax
    call fpc_check_object
    movl %esi,%eax
    movl %edi,%ecx
    movl -12(%ebp),%edx
    call *128(%ebx)
    .stabn 68,0,13,.Ll6 - P$APP_TEST_CORE_$$_SETMEMORY$TSTREAM$POINTER$LONGINT
.Ll6:
# [13] end;

TagsNo tags attached.
Fixed in Revision43384
FPCOldBugId
FPCTarget-
Attached Files

Activities

Filiuta Vitali

2018-04-05 01:19

reporter  

eaccess.zip (6,875 bytes)

Pierre Muller

2018-04-05 11:28

developer   ~0107628

 Hello,

  I just tried your source with -CRiot option
with a recent win32 ppc386.exe (commit 38689) and did not experience the crash
you describe in this report.

  Could you please give a full set of compilation options using -n option
that generates the same problem.

-n prevents loading of configuration files,
thus you will need to add explicit location of your RTL with
-FuX:\full\path\to\your\rtl\units\i386-win32

Thanks in advance,

Pierre Muller

Filiuta Vitali

2018-04-05 14:47

reporter   ~0107635

Hi,

my release of fpc is r38673;

here are the commands and shell log:

f:\units_new\anvil_core\test>del .\out\app_test_core.exe

f:\units_new\anvil_core\test>f:\compilers/fpc/bin/i386-win32/fpc.exe app_test_core.pas -n -O3 -v0wnh -Mobjfpc -gl -Crtoi -dDEBUG -FUF:\compilers\fpc\units\i386-win32\rtl -FE./out

f:\units_new\anvil_core\test>.\out\app_test_core.exe
An unhandled exception occurred at $00402B27:
EAccessViolation: Access violation
  $00402B27
  $0040174D SETMEMORY, line 12 of app_test_core.pas
  $00401813 main, line 27 of app_test_core.pas

Kind regards,
Vitali

Filiuta Vitali

2018-04-05 14:49

reporter   ~0107636

That error is very sensitive to compiling options, content of the SETMEMORY procedure, remove from or add to instructions, will make it OK.

Pierre Muller

2018-04-05 17:03

developer   ~0107638

I was able to reduce the number of command line options:

fpc.exe app_test_core.pas -n -O- -OoREGVAR -Oolevel1 -Cr -Fue:\pas\fpc-3.1.1\units\i386-win32\rtl -FE. -Mobjfpc -al -gl -Oopeephole

objfpc mode is required,
regvar, peephole and level1 optimizations need to be on.
(peephole and level1 are equivalent to -O1 option)

Issue History

Date Modified Username Field Change
2018-04-05 01:19 Filiuta Vitali New Issue
2018-04-05 01:19 Filiuta Vitali File Added: eaccess.zip
2018-04-05 11:28 Pierre Muller Note Added: 0107628
2018-04-05 11:28 Pierre Muller Assigned To => Pierre Muller
2018-04-05 11:28 Pierre Muller Status new => feedback
2018-04-05 14:47 Filiuta Vitali Note Added: 0107635
2018-04-05 14:47 Filiuta Vitali Status feedback => assigned
2018-04-05 14:49 Filiuta Vitali Note Added: 0107636
2018-04-05 17:03 Pierre Muller Note Added: 0107638
2018-04-05 17:03 Pierre Muller Status assigned => confirmed
2018-04-05 17:03 Pierre Muller Assigned To Pierre Muller => Florian Klämpfl
2018-04-05 17:03 Pierre Muller Status confirmed => assigned
2018-04-05 23:09 Florian Assigned To Florian Klämpfl => Florian
2019-11-03 18:14 Florian Status assigned => resolved
2019-11-03 18:14 Florian Resolution open => fixed
2019-11-03 18:14 Florian Fixed in Version => 3.3.1
2019-11-03 18:14 Florian Fixed in Revision => 43384
2019-11-03 18:14 Florian FPCTarget => -