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

This commit is contained in:
Nikolay Nikolov 2022-02-16 05:24:41 +02:00
parent 5f66de624d
commit 590c878690
4 changed files with 64 additions and 3 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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
rtl/wasi/si_dll.pp Normal file
View File

@ -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.