Преглед на файлове

+ added separate startup code for libraries, that declares _initialize, instead of _start

Nikolay Nikolov преди 3 години
родител
ревизия
590c878690
променени са 4 файла, в които са добавени 64 реда и са изтрити 3 реда
  1. 4 1
      compiler/systems/t_wasi.pas
  2. 3 1
      rtl/wasi/Makefile
  3. 4 1
      rtl/wasi/Makefile.fpc
  4. 53 0
      rtl/wasi/si_dll.pp

+ 4 - 1
compiler/systems/t_wasi.pas

@@ -103,7 +103,10 @@ end;
 
 procedure tlinkerwasi.InitSysInitUnitName;
 begin
-  sysinitunit:='si_prc';
+  if current_module.islibrary then
+    sysinitunit:='si_dll'
+  else
+    sysinitunit:='si_prc';
 end;
 
 function tlinkerwasi.MakeExecutable:boolean;

+ 3 - 1
rtl/wasi/Makefile

@@ -359,7 +359,7 @@ COMMON=$(RTL)/common
 PROCINC=../$(CPU_TARGET)
 UNITPREFIX=rtl
 SYSTEMUNIT=system
-SYSINIT_UNITS=si_prc
+SYSINIT_UNITS=si_prc si_dll
 OBJPASDIR=$(RTL)/objpas
 ifdef EXCEPTIONS_IN_SYSTEM
 override FPCOPT+=-dEXCEPTIONS_IN_SYSTEM
@@ -2699,6 +2699,8 @@ extpas$(PPUEXT) : $(INC)/extpas.pp dos$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
 si_prc$(PPUEXT) : si_prc.pp $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
+si_dll$(PPUEXT) : si_dll.pp $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
 wasiapi$(PPUEXT) : wasiapi.pp wasiinc/wasitypes.inc wasiinc/wasiprocs.inc $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $< -Fiwasiinc
 wasiutil$(PPUEXT) : wasiutil.pp wasiapi$(PPUEXT) objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)

+ 4 - 1
rtl/wasi/Makefile.fpc

@@ -28,7 +28,7 @@ COMMON=$(RTL)/common
 PROCINC=../$(CPU_TARGET)
 UNITPREFIX=rtl
 SYSTEMUNIT=system
-SYSINIT_UNITS=si_prc
+SYSINIT_UNITS=si_prc si_dll
 
 # Paths
 OBJPASDIR=$(RTL)/objpas
@@ -83,6 +83,9 @@ extpas$(PPUEXT) : $(INC)/extpas.pp dos$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 si_prc$(PPUEXT) : si_prc.pp $(SYSTEMUNIT)$(PPUEXT)
         $(COMPILER) $<
 
+si_dll$(PPUEXT) : si_dll.pp $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
 #
 # Other $(SYSTEMUNIT)-dependent RTL Units
 #

+ 53 - 0
rtl/wasi/si_dll.pp

@@ -0,0 +1,53 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2021, 2022 by Free Pascal development team
+
+    This file implements the startup code for WebAssembly programs that
+    don't link to the C library.
+
+    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.
+
+ **********************************************************************}
+
+
+unit si_dll;
+
+{$if defined(FPC_WASM_BRANCHFUL_EXCEPTIONS) or defined(FPC_WASM_NATIVE_EXCEPTIONS)}
+  {$MODESWITCH EXCEPTIONS}
+{$endif}
+
+interface
+
+procedure _initialize;
+
+implementation
+
+procedure PASCALMAIN; external 'PASCALMAIN';
+
+{$if defined(FPC_WASM_BRANCHFUL_EXCEPTIONS) or defined(FPC_WASM_NATIVE_EXCEPTIONS)}
+Procedure DoUnHandledException; external name 'FPC_DOUNHANDLEDEXCEPTION';
+
+procedure _initialize;
+begin
+  try
+    PASCALMAIN;
+  except
+    DoUnhandledException;
+  end;
+end;
+{$else}
+procedure _initialize;
+begin
+  PASCALMAIN;
+end;
+{$endif}
+
+exports
+  _initialize;
+
+end.