Browse Source

Merge remote-tracking branch 'origin/main' into wasm_js_promise_integration

Nikolay Nikolov 2 years ago
parent
commit
315166fccc

+ 3 - 0
packages/fpmkunit/src/fpmkunit.pp

@@ -3076,6 +3076,9 @@ var
     GccExecutable := ExeSearch(AddProgramExtension(CrossPrefix+'gcc', OS),Sysutils.GetEnvironmentVariable('PATH'));
     GccExecutable := ExeSearch(AddProgramExtension(CrossPrefix+'gcc', OS),Sysutils.GetEnvironmentVariable('PATH'));
     if not(FileExists(GccExecutable)) then
     if not(FileExists(GccExecutable)) then
       GccExecutable := ExeSearch(AddProgramExtension(CrossPrefix+'gnu-gcc', OS),Sysutils.GetEnvironmentVariable('PATH'));
       GccExecutable := ExeSearch(AddProgramExtension(CrossPrefix+'gnu-gcc', OS),Sysutils.GetEnvironmentVariable('PATH'));
+    { ugly hack to find gcc on newer linuxes }
+    if not(FileExists(GccExecutable)) and (CrossPrefix='i386-linux-') then
+      GccExecutable := ExeSearch(AddProgramExtension('i686-linux-gnu-gcc', OS),Sysutils.GetEnvironmentVariable('PATH'));
     if FileExists(GccExecutable) then
     if FileExists(GccExecutable) then
       begin
       begin
 {$ifdef HAS_UNIT_PROCESS}
 {$ifdef HAS_UNIT_PROCESS}

+ 3 - 0
packages/pastojs/src/pas2jsfiler.pp

@@ -3350,6 +3350,7 @@ function TPCUWriter.IsExternalEl(El: TPasElement): boolean;
 var
 var
   C: TClass;
   C: TClass;
 begin
 begin
+  Result:=false;
   while El<>nil do
   while El<>nil do
     begin
     begin
     C:=El.ClassType;
     C:=El.ClassType;
@@ -3477,6 +3478,8 @@ begin
     ParentRef:=WriteExternalReference(SpecItem.GenericEl,aContext)
     ParentRef:=WriteExternalReference(SpecItem.GenericEl,aContext)
   else if IsExternalEl(Parent) then
   else if IsExternalEl(Parent) then
     ParentRef:=WriteExternalReference(Parent,aContext)
     ParentRef:=WriteExternalReference(Parent,aContext)
+  else if Parent=nil then
+    ParentRef:=nil
   else
   else
     begin
     begin
     // El is external, Parent is not
     // El is external, Parent is not

+ 2 - 0
rtl/inc/system.inc

@@ -48,6 +48,8 @@ const
   STACK_MARGIN_MAX = 64;    { Stack size margin for stack checking }
   STACK_MARGIN_MAX = 64;    { Stack size margin for stack checking }
 {$elseif defined(CPUZ80)}
 {$elseif defined(CPUZ80)}
   STACK_MARGIN_MAX = 64;    { Stack size margin for stack checking }
   STACK_MARGIN_MAX = 64;    { Stack size margin for stack checking }
+{$elseif defined(CPULOONGARCH64)}
+  STACK_MARGIN_MAX = 65536;    { Stack size margin for stack checking }
 {$else}
 {$else}
   STACK_MARGIN_MAX = 16384;    { Stack size margin for stack checking }
   STACK_MARGIN_MAX = 16384;    { Stack size margin for stack checking }
 {$endif}
 {$endif}

+ 36 - 0
rtl/linux/loongarch64/cp_new_stat.inc

@@ -0,0 +1,36 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by Jonas Maebe, (c) 2005 Thomas Schatzl,
+    members of the Free Pascal development team.
+
+    Contains the transformation from struct stat to struct statx.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+  procedure cp_new_stat(nbuf: pstatx64; buf: pstat);
+
+  begin
+    buf^.st_dev:=makedev(nbuf^.stx_dev_major,nbuf^.stx_dev_minor);
+    buf^.st_rdev:=makedev(nbuf^.stx_rdev_major,nbuf^.stx_rdev_minor);
+    buf^.st_ino:=nbuf^.stx_ino;
+    buf^.st_mode:=nbuf^.stx_mode;
+    buf^.st_nlink:=nbuf^.stx_nlink;
+    buf^.st_uid:=nbuf^.stx_uid;
+    buf^.st_gid:=nbuf^.stx_gid;
+    buf^.st_size:=nbuf^.stx_size;
+    buf^.st_blksize:=nbuf^.stx_blksize;
+    buf^.st_blocks:=nbuf^.stx_blocks;
+    buf^.st_atime:=nbuf^.stx_atime.tv_sec;
+    buf^.st_atime_nsec:=nbuf^.stx_atime.tv_nsec;
+    buf^.st_mtime:=nbuf^.stx_mtime.tv_sec;
+    buf^.st_mtime_nsec:=nbuf^.stx_mtime.tv_nsec;
+    buf^.st_ctime:=nbuf^.stx_ctime.tv_sec;
+    buf^.st_ctime_nsec:=nbuf^.stx_ctime.tv_nsec;
+  end;

+ 1 - 0
rtl/linux/loongarch64/si_c.inc

@@ -78,6 +78,7 @@ procedure main_stub; assembler; nostackframe;
     la.got, $t0, SysInitEntryInformation
     la.got, $t0, SysInitEntryInformation
     st.d $sp, $t0, TEntryInformation.OS.stkptr
     st.d $sp, $t0, TEntryInformation.OS.stkptr
     la.got $t1, StackLength
     la.got $t1, StackLength
+    ld.d $t1, $t1, 0
     st.d $t1, $t0, TEntryInformation.OS.stklen
     st.d $t1, $t0, TEntryInformation.OS.stklen
     la.got $t2, _FPC_libc_haltproc
     la.got $t2, _FPC_libc_haltproc
     st.d $t2, $t0, TEntryInformation.OS.haltproc
     st.d $t2, $t0, TEntryInformation.OS.haltproc

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

@@ -77,6 +77,7 @@ procedure main_stub; assembler; nostackframe;
     la.got, $t0, SysInitEntryInformation
     la.got, $t0, SysInitEntryInformation
     st.d $sp, $t0, TEntryInformation.OS.stkptr
     st.d $sp, $t0, TEntryInformation.OS.stkptr
     la.got $t1, StackLength
     la.got $t1, StackLength
+    ld.d $t1, $t1, 0
     st.d $t1, $t0, TEntryInformation.OS.stklen
     st.d $t1, $t0, TEntryInformation.OS.stklen
     la.got $t2, _FPC_libc_haltproc
     la.got $t2, _FPC_libc_haltproc
     st.d $t2, $t0, TEntryInformation.OS.haltproc
     st.d $t2, $t0, TEntryInformation.OS.haltproc

+ 6 - 5
rtl/linux/loongarch64/si_prc.inc

@@ -50,6 +50,7 @@ procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
 
 
     st.d $sp, $t1, TEntryInformation.OS.stkptr
     st.d $sp, $t1, TEntryInformation.OS.stkptr
     la.got $t0, StackLength
     la.got $t0, StackLength
+    ld.d $t0, $t0, 0
     st.d $t0, $t1, TEntryInformation.OS.stklen
     st.d $t0, $t1, TEntryInformation.OS.stklen
     la.got $t2, _FPC_proc_haltproc
     la.got $t2, _FPC_proc_haltproc
     st.d $t2, $t1, TEntryInformation.OS.haltproc
     st.d $t2, $t1, TEntryInformation.OS.haltproc
@@ -85,13 +86,13 @@ procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
     la.got $t0, initialstkptr
     la.got $t0, initialstkptr
     st.d $sp, $t0, 0
     st.d $sp, $t0, 0
 
 
-{$if defined(FPC_USE_LIBC)}
-    { call PascalMain }
-    bl PASCALMAIN
-{$else}
+{$if not defined(FPC_USE_LIBC)}
     bl InitTLS
     bl InitTLS
 {$endif}
 {$endif}
-{$endif}
+
+    { call PascalMain }
+    bl PASCALMAIN
+{$endif}    
     break 1
     break 1
   end;
   end;
 
 

+ 2 - 0
rtl/linux/osdefs.inc

@@ -125,5 +125,7 @@
 
 
 {$ifdef cpuloongarch64}
 {$ifdef cpuloongarch64}
   {$define generic_linux_syscalls}
   {$define generic_linux_syscalls}
+  {$define use_statx_syscall}
+  {$define use_prlimit64}
   {$undef usestime}
   {$undef usestime}
 {$endif cpuloongarch64}
 {$endif cpuloongarch64}

+ 56 - 2
rtl/linux/ossysc.inc

@@ -110,6 +110,28 @@ begin
 {$endif}
 {$endif}
 end;
 end;
 
 
+{$if defined(use_statx_syscall)}
+function makedev(major,minor: cuint32): cuint32;
+
+begin
+  makedev:=(minor and $ff) or (major shl 8) or ((minor and $fffffff00) shl 12);
+end;
+
+{$i cp_new_stat.inc}
+
+function Fpstat(path: pchar; var buf: stat):cint; [public, alias : 'FPC_SYSC_STAT'];
+
+var
+  nbuf:tstatx64;
+
+begin
+  Fpstat:=do_syscall(syscall_nr_statx,AT_FDCWD,TSysParam(path),AT_NO_AUTOMOUNT,STATX_BASIC_STATS,TSysParam(@nbuf));
+  if Fpstat=0 then
+    cp_new_stat(@nbuf,@buf);
+end;
+
+{$else defined(use_statx_syscall)}
+
 function Fpstat(path: pchar; var buf: stat):cint; [public, alias : 'FPC_SYSC_STAT'];
 function Fpstat(path: pchar; var buf: stat):cint; [public, alias : 'FPC_SYSC_STAT'];
 
 
 begin
 begin
@@ -124,6 +146,7 @@ begin
   Fpstat:=do_syscall(syscall_nr_stat64,TSysParam(path),TSysParam(@buf));
   Fpstat:=do_syscall(syscall_nr_stat64,TSysParam(path),TSysParam(@buf));
 {$endif}
 {$endif}
 end;
 end;
+{$endif defined(use_statx_syscall)}
 
 
 {*****************************************************************************
 {*****************************************************************************
                --- Directory:Directory related calls ---
                --- Directory:Directory related calls ---
@@ -403,6 +426,20 @@ end;
 
 
 {$undef FPC_ALIGN_DUMMY}
 {$undef FPC_ALIGN_DUMMY}
 
 
+{$if defined(use_statx_syscall)}
+function Fpfstat(fd : cint; var sb : stat): cint;  [public, alias : 'FPC_SYSC_FSTAT'];
+
+var
+  nbuf:tstatx64;
+  nonestr:char=#0;
+
+begin
+  Fpfstat:=do_syscall(syscall_nr_statx,fd,TSysParam(@nonestr),AT_EMPTY_PATH,STATX_BASIC_STATS,TSysParam(@nbuf));
+  if Fpfstat=0 then
+    cp_new_stat(@nbuf,@sb);
+end;
+
+{$else defined(use_statx_syscall)}
 function Fpfstat(fd : cint; var sb : stat): cint;  [public, alias : 'FPC_SYSC_FSTAT'];
 function Fpfstat(fd : cint; var sb : stat): cint;  [public, alias : 'FPC_SYSC_FSTAT'];
 
 
 begin
 begin
@@ -416,6 +453,7 @@ begin
   FpFStat:=do_SysCall(syscall_nr_fstat64,TSysParam(fd),TSysParam(@sb));
   FpFStat:=do_SysCall(syscall_nr_fstat64,TSysParam(fd),TSysParam(@sb));
 {$endif}
 {$endif}
 end;
 end;
+{$endif defined(use_statx_syscall)}
 
 
 
 
 {$ifndef FPC_SYSTEM_HAS_FPFORK}
 {$ifndef FPC_SYSTEM_HAS_FPFORK}
@@ -699,11 +737,23 @@ begin
 end;
 end;
 
 
 
 
+{$ifdef USE_PRLIMIT64}
+function FpPRlimit64(pid : pid_t; resource : cInt; nrlim, orlim : PRLimit) : cInt;
+begin
+  FpPRlimit64 := do_syscall(syscall_nr_prlimit64, TSysParam(pid),
+    TSysParam(resource), TSysParam(nrlim), TSysParam(orlim));
+end;
+{$endif}
+
 function FpGetRLimit(resource : cInt; rlim : PRLimit) : cInt; [public, alias : 'FPC_SYSC_GETRLIMIT'];
 function FpGetRLimit(resource : cInt; rlim : PRLimit) : cInt; [public, alias : 'FPC_SYSC_GETRLIMIT'];
 begin
 begin
 {$ifndef NO_SYSCALL_GETRLIMIT}
 {$ifndef NO_SYSCALL_GETRLIMIT}
-  FpGetRLimit := do_syscall(syscall_nr_getrlimit,
-    TSysParam(resource), TSysParam(rlim));
+  {$ifndef USE_PRLIMIT64}
+    FpGetRLimit := do_syscall(syscall_nr_getrlimit,
+      TSysParam(resource), TSysParam(rlim));
+  {$else}
+    FpGetRLimit := FpPRlimit64(0, RLIMIT_STACK, PRLimit(0), rlim);
+  {$endif}
 {$else}
 {$else}
   FpGetRLimit := do_syscall(syscall_nr_ugetrlimit,
   FpGetRLimit := do_syscall(syscall_nr_ugetrlimit,
     TSysParam(resource), TSysParam(rlim));
     TSysParam(resource), TSysParam(rlim));
@@ -729,7 +779,11 @@ end;
 
 
 function FpSetRLimit(Resource:cint;rlim:PRLimit):cint; [public, alias : 'FPC_SYSC_SETRLIMIT'];
 function FpSetRLimit(Resource:cint;rlim:PRLimit):cint; [public, alias : 'FPC_SYSC_SETRLIMIT'];
 begin
 begin
+{$ifndef USE_PRLIMIT64}
   fpsetrlimit:=do_syscall(syscall_nr_setrlimit,TSysParam(Resource),TSysParam(rlim));
   fpsetrlimit:=do_syscall(syscall_nr_setrlimit,TSysParam(Resource),TSysParam(rlim));
+{$else}
+  fpsetrlimit:=FpPRlimit64(0, RLIMIT_STACK, rlim, PRLimit(0));
+{$endif USE_PRLIMIT64}
 end;
 end;
 
 
 function FpSchedGetAffinity(pid : pid_t;cpusetsize : size_t;mask : pcpu_set_t) : cint;
 function FpSchedGetAffinity(pid : pid_t;cpusetsize : size_t;mask : pcpu_set_t) : cint;

+ 37 - 0
rtl/linux/ostypes.inc

@@ -90,6 +90,10 @@ const
 {$endif}
 {$endif}
   _STAT_VER = _STAT_VER_LINUX;
   _STAT_VER = _STAT_VER_LINUX;
 
 
+{$if defined(use_statx_syscall)}
+  STATX_BASIC_STATS=$000007ff;
+{$endif}
+
 type
 type
 
 
 {$i stat.inc}
 {$i stat.inc}
@@ -97,6 +101,39 @@ type
   TStat      = Stat;
   TStat      = Stat;
   PStat      = ^Stat;
   PStat      = ^Stat;
 
 
+  { Referred to rtl/linux/linux.pp }
+  statx64_timestamp = record
+    tv_sec : cint64;
+    tv_nsec : cuint32;
+    __reserved : cint32;
+  end;
+  pstatx64_timestamp = ^statx64_timestamp;
+
+  tstatx64 = record
+    stx_mask : cuint32;
+    stx_blksize : cuint32;
+    stx_attributes : cuint64;
+    stx_nlink : cuint32;
+    stx_uid : cuint32;
+    stx_gid : cuint32;
+    stx_mode : word;
+    __spare0 : array[0..0] of word;
+    stx_ino : cuint64;
+    stx_size : cuint64;
+    stx_blocks : cuint64;
+    stx_attributes_mask : cuint64;
+    stx_atime : statx64_timestamp;
+    stx_btime : statx64_timestamp;
+    stx_ctime : statx64_timestamp;
+    stx_mtime : statx64_timestamp;
+    stx_rdev_major : cuint32;
+    stx_rdev_minor : cuint32;
+    stx_dev_major : cuint32;
+    stx_dev_minor : cuint32;
+    __spare2 : array[0..13] of cuint64;
+  end;
+  pstatx64 = ^tstatx64;
+
   { directory services }
   { directory services }
   { the Dirent type for getdents64 is no longer declared as ending with
   { the Dirent type for getdents64 is no longer declared as ending with
     an array 0..255, but as ending with a variable-sized array. While the
     an array 0..255, but as ending with a variable-sized array. While the

+ 2 - 10
rtl/loongarch64/loongarch64.inc

@@ -139,7 +139,7 @@ procedure SysInitFPU;
   begin
   begin
     setrm(0);
     setrm(0);
     setcause(0);
     setcause(0);
-    setenables(fpu_z or fpu_v);
+    setenables(fpu_z or fpu_v or fpu_o);
     softfloat_exception_mask:=[exPrecision,exUnderflow];
     softfloat_exception_mask:=[exPrecision,exUnderflow];
     softfloat_exception_flags:=[];
     softfloat_exception_flags:=[];
   end;
   end;
@@ -509,18 +509,10 @@ procedure Move(const source;var dest;count:SizeInt);[public, alias: 'FPC_MOVE'];
 
 
 {$define FPC_SYSTEM_HAS_SYSRESETFPU}
 {$define FPC_SYSTEM_HAS_SYSRESETFPU}
 procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
 procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
-{$ifdef FPUFD}
-var
-  cw: TNativeFPUControlWord;
-{$endif}
 begin
 begin
   softfloat_exception_flags:=[];
   softfloat_exception_flags:=[];
   softfloat_exception_mask:=[exPrecision,exUnderflow];
   softfloat_exception_mask:=[exPrecision,exUnderflow];
 {$ifdef FPUFD}
 {$ifdef FPUFD}
-  cw:=GetNativeFPUControlWord;
-  cw.cw:=0;
-  { round to nearest }
-  cw.rndmode:=0;
-  SetNativeFPUControlWord(cw);
+  SetNativeFPUControlWord(DefaultFPUControlWord);
 {$endif}
 {$endif}
 end;
 end;

+ 1 - 1
utils/fpcm/revision.inc

@@ -1 +1 @@
-'2023-03-27 hash 327aac7f24'
+'2023-06-19 hash 193550945c'