Browse Source

* fix of Erroneous reading of the value of the StackLength variable at program start based on issue report by Sergey Larin, resolves #40211

florian 2 years ago
parent
commit
3e3b96e088
4 changed files with 24 additions and 2 deletions
  1. 3 2
      rtl/linux/x86_64/si_c.inc
  2. 1 0
      rtl/linux/x86_64/si_g.inc
  3. 1 0
      rtl/linux/x86_64/si_prc.inc
  4. 19 0
      tests/webtbs/tw40211.pp

+ 3 - 2
rtl/linux/x86_64/si_c.inc

@@ -88,8 +88,9 @@ procedure main_stub; assembler; nostackframe;
     movq    %rsp,TEntryInformation.OS.stkptr(%rdi)
     movq    %rsp,TEntryInformation.OS.stkptr(%rdi)
 
 
     { store stack length }
     { store stack length }
-    movq StackLength@GOTPCREL(%rip),%rax
-    movq %rax,TEntryInformation.OS.stklen(%rdi)
+    movq    StackLength@GOTPCREL(%rip),%rax
+    movq    (%rax),%rax
+    movq    %rax,TEntryInformation.OS.stklen(%rdi)
 
 
     { store pointer to haltproc }
     { store pointer to haltproc }
     movq    _FPC_libc_haltproc@GOTPCREL(%rip),%rax
     movq    _FPC_libc_haltproc@GOTPCREL(%rip),%rax

+ 1 - 0
rtl/linux/x86_64/si_g.inc

@@ -85,6 +85,7 @@ procedure main_stub; assembler; nostackframe;
 
 
     { store stack length }
     { store stack length }
     movq    StackLength@GOTPCREL(%rip),%rax
     movq    StackLength@GOTPCREL(%rip),%rax
+    movq    (%rax),%rax
     movq    %rax,TEntryInformation.OS.stklen(%rdi)
     movq    %rax,TEntryInformation.OS.stklen(%rdi)
 
 
     { store pointer to haltproc }
     { store pointer to haltproc }

+ 1 - 0
rtl/linux/x86_64/si_prc.inc

@@ -66,6 +66,7 @@ procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
 
 
     { store stack length }
     { store stack length }
     movq    StackLength@GOTPCREL(%rip),%rax
     movq    StackLength@GOTPCREL(%rip),%rax
+    movq    (%rax),%rax
     movq    %rax,TEntryInformation.OS.stklen(%r10)
     movq    %rax,TEntryInformation.OS.stklen(%r10)
 
 
     { store pointer to haltproc }
     { store pointer to haltproc }

+ 19 - 0
tests/webtbs/tw40211.pp

@@ -0,0 +1,19 @@
+{ %opt=-Ct -Cs7340032 }
+{ %target=win32,win64,linux,freebsd,darwin,openbsd }
+program project1;
+
+{$mode objfpc}
+
+function BigStack: Integer;
+var
+  buf: array[0..6*1024*1014] of Byte;
+begin
+  buf[0] := 1;
+  buf[High(buf)] := 2;
+  Result := buf[0] + buf[High(buf)];
+end;
+
+begin
+  if BigStack <> 3 then
+    Halt(1);
+end.