Explorar o código

* integrate loaders in system unit

git-svn-id: trunk@2695 -
peter %!s(int64=19) %!d(string=hai) anos
pai
achega
4c56a87d59

+ 32 - 17
compiler/systems/t_win.pas

@@ -898,15 +898,15 @@ begin
      {$else ARM}
      {$else ARM}
        targetopts:='-b pe-i386 -m i386pe';
        targetopts:='-b pe-i386 -m i386pe';
      {$endif ARM}
      {$endif ARM}
-     ExeCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $STRIP $APPTYPE $IMAGEBASE $RELOC -o $EXE $RES';
-     DllCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $STRIP --dll $APPTYPE $IMAGEBASE $RELOC -o $EXE $RES';
+     ExeCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $STRIP $APPTYPE $ENTRY  $IMAGEBASE $RELOC -o $EXE $RES';
+     DllCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $STRIP --dll $APPTYPE $ENTRY  $IMAGEBASE $RELOC -o $EXE $RES';
      { ExeCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF';
      { ExeCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF';
        use short forms to avoid 128 char limitation problem }
        use short forms to avoid 128 char limitation problem }
      ExeCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
      ExeCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
-     ExeCmd[3]:='ld '+targetopts+' $OPT $STRIP $APPTYPE $IMAGEBASE -o $EXE $RES exp.$$$';
+     ExeCmd[3]:='ld '+targetopts+' $OPT $STRIP $APPTYPE $ENTRY $IMAGEBASE -o $EXE $RES exp.$$$';
      { DllCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF'; }
      { DllCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF'; }
      DllCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
      DllCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
-     DllCmd[3]:='ld '+targetopts+' $OPT $STRIP --dll $APPTYPE $IMAGEBASE -o $EXE $RES exp.$$$';
+     DllCmd[3]:='ld '+targetopts+' $OPT $STRIP --dll $APPTYPE $ENTRY  $IMAGEBASE -o $EXE $RES exp.$$$';
    end;
    end;
 end;
 end;
 
 
@@ -951,6 +951,7 @@ begin
   { add objectfiles, start with prt0 always                  }
   { add objectfiles, start with prt0 always                  }
   { profiling of shared libraries is currently not supported }
   { profiling of shared libraries is currently not supported }
   LinkRes.Add('INPUT(');
   LinkRes.Add('INPUT(');
+(*
   if isdll then
   if isdll then
    LinkRes.AddFileName(MaybeQuoted(FindObjectFile('wdllprt0','',false)))
    LinkRes.AddFileName(MaybeQuoted(FindObjectFile('wdllprt0','',false)))
   else
   else
@@ -963,6 +964,7 @@ begin
      else
      else
       LinkRes.AddFileName(MaybeQuoted(FindObjectFile('wprt0','',false)));
       LinkRes.AddFileName(MaybeQuoted(FindObjectFile('wprt0','',false)));
    end;
    end;
+*)
 
 
   while not ObjectFiles.Empty do
   while not ObjectFiles.Empty do
    begin
    begin
@@ -1040,6 +1042,7 @@ var
   StripStr,
   StripStr,
   RelocStr,
   RelocStr,
   AppTypeStr,
   AppTypeStr,
+  EntryStr,
   ImageBaseStr : string[40];
   ImageBaseStr : string[40];
 begin
 begin
   if not(cs_link_extern in aktglobalswitches) then
   if not(cs_link_extern in aktglobalswitches) then
@@ -1048,27 +1051,30 @@ begin
 { Create some replacements }
 { Create some replacements }
   RelocStr:='';
   RelocStr:='';
   AppTypeStr:='';
   AppTypeStr:='';
+  EntryStr:='';
   ImageBaseStr:='';
   ImageBaseStr:='';
   StripStr:='';
   StripStr:='';
   GCSectionsStr:='';
   GCSectionsStr:='';
   AsBinStr:=FindUtil(utilsprefix+'as');
   AsBinStr:=FindUtil(utilsprefix+'as');
   if RelocSection then
   if RelocSection then
-   RelocStr:='--base-file base.$$$';
+    RelocStr:='--base-file base.$$$';
   if use_smartlink_section then
   if use_smartlink_section then
-   GCSectionsStr:='--gc-sections';
+    GCSectionsStr:='--gc-sections';
   if target_info.system in [system_arm_wince,system_i386_wince] then
   if target_info.system in [system_arm_wince,system_i386_wince] then
+    AppTypeStr:='--subsystem wince'
+  else
     begin
     begin
-      AppTypeStr:='--subsystem wince';
-      if apptype <> app_gui then
-        AppTypeStr:=AppTypeStr + ' --entry=mainCRTStartup';
-    end
+      if apptype=app_gui then
+        AppTypeStr:='--subsystem windows';
+    end;
+  if apptype=app_gui then
+    EntryStr:='--entry=_WinMainCRTStartup'
   else
   else
-    if apptype=app_gui then
-     AppTypeStr:='--subsystem windows';
+    EntryStr:='--entry=_mainCRTStartup';
   if assigned(DLLImageBase) then
   if assigned(DLLImageBase) then
-   ImageBaseStr:='--image-base=0x'+DLLImageBase^;
+    ImageBaseStr:='--image-base=0x'+DLLImageBase^;
   if (cs_link_strip in aktglobalswitches) then
   if (cs_link_strip in aktglobalswitches) then
-   StripStr:='-s';
+    StripStr:='-s';
 
 
 { Write used files and libraries }
 { Write used files and libraries }
   WriteResponseFile(false);
   WriteResponseFile(false);
@@ -1088,6 +1094,7 @@ begin
         Replace(cmdstr,'$OPT',Info.ExtraOptions);
         Replace(cmdstr,'$OPT',Info.ExtraOptions);
         Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
         Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
         Replace(cmdstr,'$APPTYPE',AppTypeStr);
         Replace(cmdstr,'$APPTYPE',AppTypeStr);
+        Replace(cmdstr,'$ENTRY',EntryStr);
         Replace(cmdstr,'$ASBIN',AsbinStr);
         Replace(cmdstr,'$ASBIN',AsbinStr);
         Replace(cmdstr,'$RELOC',RelocStr);
         Replace(cmdstr,'$RELOC',RelocStr);
         Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);
         Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);
@@ -1135,6 +1142,7 @@ var
   GCSectionsStr,
   GCSectionsStr,
   RelocStr,
   RelocStr,
   AppTypeStr,
   AppTypeStr,
+  EntryStr,
   ImageBaseStr : string[40];
   ImageBaseStr : string[40];
 begin
 begin
   MakeSharedLibrary:=false;
   MakeSharedLibrary:=false;
@@ -1144,6 +1152,7 @@ begin
 { Create some replacements }
 { Create some replacements }
   RelocStr:='';
   RelocStr:='';
   AppTypeStr:='';
   AppTypeStr:='';
+  EntryStr:='';
   ImageBaseStr:='';
   ImageBaseStr:='';
   StripStr:='';
   StripStr:='';
   GCSectionsStr:='';
   GCSectionsStr:='';
@@ -1153,11 +1162,16 @@ begin
   if use_smartlink_section then
   if use_smartlink_section then
    GCSectionsStr:='--gc-sections';
    GCSectionsStr:='--gc-sections';
   if apptype=app_gui then
   if apptype=app_gui then
-   AppTypeStr:='--subsystem windows';
+    begin
+      AppTypeStr:='--subsystem windows';
+      EntryStr:='--entry _DLLWinMainCRTStartup@12'
+    end
+  else
+    EntryStr:='--entry _DLLMainCRTStartup@12';
   if assigned(DLLImageBase) then
   if assigned(DLLImageBase) then
-   ImageBaseStr:='--image-base=0x'+DLLImageBase^;
+    ImageBaseStr:='--image-base=0x'+DLLImageBase^;
   if (cs_link_strip in aktglobalswitches) then
   if (cs_link_strip in aktglobalswitches) then
-   StripStr:='-s';
+    StripStr:='-s';
 
 
 { Write used files and libraries }
 { Write used files and libraries }
   WriteResponseFile(true);
   WriteResponseFile(true);
@@ -1177,6 +1191,7 @@ begin
         Replace(cmdstr,'$OPT',Info.ExtraOptions);
         Replace(cmdstr,'$OPT',Info.ExtraOptions);
         Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
         Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
         Replace(cmdstr,'$APPTYPE',AppTypeStr);
         Replace(cmdstr,'$APPTYPE',AppTypeStr);
+        Replace(cmdstr,'$ENTRY',EntryStr);
         Replace(cmdstr,'$ASBIN',AsbinStr);
         Replace(cmdstr,'$ASBIN',AsbinStr);
         Replace(cmdstr,'$RELOC',RelocStr);
         Replace(cmdstr,'$RELOC',RelocStr);
         Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);
         Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);

+ 1 - 1
rtl/inc/heaptrc.pp

@@ -802,7 +802,7 @@ begin
 {$ifdef windows}
 {$ifdef windows}
   { inside stack ? }
   { inside stack ? }
   if (ptruint(p)>ptruint(get_frame)) and
   if (ptruint(p)>ptruint(get_frame)) and
-     (ptruint(p)<Win32StackTop) then
+     (p<StackTop) then
     goto _exit;
     goto _exit;
   { inside data ? }
   { inside data ? }
   if (ptruint(p)>=ptruint(@sdata)) and (ptruint(p)<ptruint(@edata)) then
   if (ptruint(p)>=ptruint(@sdata)) and (ptruint(p)<ptruint(@edata)) then

+ 0 - 1
rtl/inc/system.inc

@@ -44,7 +44,6 @@ const
 var
 var
   emptychar : char;public name 'FPC_EMPTYCHAR';
   emptychar : char;public name 'FPC_EMPTYCHAR';
   initialstklen : SizeUint;external name '__stklen';
   initialstklen : SizeUint;external name '__stklen';
-  initialstkptr : Pointer;external name '__stkptr';
 
 
 { checks whether the given suggested size for the stack of the current
 { checks whether the given suggested size for the stack of the current
  thread is acceptable. If this is the case, returns it unaltered.
  thread is acceptable. If this is the case, returns it unaltered.

+ 2 - 1
rtl/inc/systemh.inc

@@ -1,6 +1,6 @@
 {
 {
     This file contains the OS independent declarations of the system unit
     This file contains the OS independent declarations of the system unit
-    
+
     This file is part of the Free Pascal Run time library.
     This file is part of the Free Pascal Run time library.
     Copyright (c) 1999-2005 by the Free Pascal development team
     Copyright (c) 1999-2005 by the Free Pascal development team
 
 
@@ -349,6 +349,7 @@ ThreadVar
   StdErr      : Text;
   StdErr      : Text;
   InOutRes    : Word;
   InOutRes    : Word;
   { Stack checking }
   { Stack checking }
+  StackTop,
   StackBottom : Pointer;
   StackBottom : Pointer;
   StackLength : SizeUInt;
   StackLength : SizeUInt;
 
 

+ 3 - 0
rtl/linux/system.pp

@@ -249,6 +249,9 @@ begin
     result := stklen;
     result := stklen;
 end;
 end;
 
 
+
+var
+  initialstkptr : Pointer;external name '__stkptr';
 Begin
 Begin
   SysResetFPU;
   SysResetFPU;
   IsConsole := TRUE;
   IsConsole := TRUE;

+ 62 - 42
rtl/win32/Makefile

@@ -1,8 +1,8 @@
 #
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2006/02/04]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2006/02/20]
 #
 #
 default: all
 default: all
-MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-emx i386-watcom i386-netwlibc i386-wince m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos powerpc-linux powerpc-netbsd powerpc-macos powerpc-darwin powerpc-morphos sparc-linux sparc-netbsd sparc-solaris x86_64-linux x86_64-freebsd x86_64-win64 arm-linux arm-palmos arm-wince powerpc64-linux
+MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos powerpc-linux powerpc-netbsd powerpc-macos powerpc-darwin powerpc-morphos sparc-linux sparc-netbsd sparc-solaris x86_64-linux x86_64-freebsd x86_64-win64 arm-linux arm-palmos arm-wince powerpc64-linux
 BSDs = freebsd netbsd openbsd darwin
 BSDs = freebsd netbsd openbsd darwin
 UNIXs = linux $(BSDs) solaris qnx
 UNIXs = linux $(BSDs) solaris qnx
 LIMIT83fs = go32v2 os2 emx watcom
 LIMIT83fs = go32v2 os2 emx watcom
@@ -239,8 +239,8 @@ COMMON=$(RTL)/common
 PROCINC=$(RTL)/$(CPU_TARGET)
 PROCINC=$(RTL)/$(CPU_TARGET)
 WININC=wininc
 WININC=wininc
 UNITPREFIX=rtl
 UNITPREFIX=rtl
-ifdef RELEASE
-override FPCOPT+=-Ur
+ifneq ($(findstring 2.0.,$(FPC_VERSION)),)
+LOADERS=wprt0 wdllprt0 gprt0 wcygprt0
 endif
 endif
 OBJPASDIR=$(RTL)/objpas
 OBJPASDIR=$(RTL)/objpas
 include $(WININC)/makefile.inc
 include $(WININC)/makefile.inc
@@ -281,6 +281,9 @@ endif
 ifeq ($(FULL_TARGET),i386-wdosx)
 ifeq ($(FULL_TARGET),i386-wdosx)
 override TARGET_UNITS+=system ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 override TARGET_UNITS+=system ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 endif
+ifeq ($(FULL_TARGET),i386-darwin)
+override TARGET_UNITS+=system ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+endif
 ifeq ($(FULL_TARGET),i386-emx)
 ifeq ($(FULL_TARGET),i386-emx)
 override TARGET_UNITS+=system ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 override TARGET_UNITS+=system ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 endif
@@ -360,118 +363,121 @@ ifeq ($(FULL_TARGET),powerpc64-linux)
 override TARGET_UNITS+=system ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 override TARGET_UNITS+=system ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 endif
 ifeq ($(FULL_TARGET),i386-linux)
 ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
 ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-win32)
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-os2)
 ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
 ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-beos)
 ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-netbsd)
 ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-solaris)
 ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-qnx)
 ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-netware)
 ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-openbsd)
 ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-wdosx)
 ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
+endif
+ifeq ($(FULL_TARGET),i386-darwin)
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-emx)
 ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-watcom)
 ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-netwlibc)
 ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-wince)
 ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
 ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
 ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-amiga)
 ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-atari)
 ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-openbsd)
 ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-palmos)
 ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
 ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
 ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-macos)
 ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
 ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
 ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
 ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),sparc-solaris)
 ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
 ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
 ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),arm-linux)
 ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
 ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),arm-wince)
 ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+override TARGET_LOADERS+=$(LOADERS)
 endif
 endif
 ifeq ($(FULL_TARGET),i386-linux)
 ifeq ($(FULL_TARGET),i386-linux)
 override TARGET_RSTS+=math varutils typinfo variants classes dateutils sysconst fpmkunit
 override TARGET_RSTS+=math varutils typinfo variants classes dateutils sysconst fpmkunit
@@ -509,6 +515,9 @@ endif
 ifeq ($(FULL_TARGET),i386-wdosx)
 ifeq ($(FULL_TARGET),i386-wdosx)
 override TARGET_RSTS+=math varutils typinfo variants classes dateutils sysconst fpmkunit
 override TARGET_RSTS+=math varutils typinfo variants classes dateutils sysconst fpmkunit
 endif
 endif
+ifeq ($(FULL_TARGET),i386-darwin)
+override TARGET_RSTS+=math varutils typinfo variants classes dateutils sysconst fpmkunit
+endif
 ifeq ($(FULL_TARGET),i386-emx)
 ifeq ($(FULL_TARGET),i386-emx)
 override TARGET_RSTS+=math varutils typinfo variants classes dateutils sysconst fpmkunit
 override TARGET_RSTS+=math varutils typinfo variants classes dateutils sysconst fpmkunit
 endif
 endif
@@ -624,6 +633,9 @@ endif
 ifeq ($(FULL_TARGET),i386-wdosx)
 ifeq ($(FULL_TARGET),i386-wdosx)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 endif
 endif
+ifeq ($(FULL_TARGET),i386-darwin)
+override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
+endif
 ifeq ($(FULL_TARGET),i386-emx)
 ifeq ($(FULL_TARGET),i386-emx)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 endif
 endif
@@ -738,6 +750,9 @@ endif
 ifeq ($(FULL_TARGET),i386-wdosx)
 ifeq ($(FULL_TARGET),i386-wdosx)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 endif
 endif
+ifeq ($(FULL_TARGET),i386-darwin)
+override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
+endif
 ifeq ($(FULL_TARGET),i386-emx)
 ifeq ($(FULL_TARGET),i386-emx)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 endif
 endif
@@ -1456,12 +1471,17 @@ endif
 endif
 endif
 export ZIPPROG
 export ZIPPROG
 ifndef TARPROG
 ifndef TARPROG
+TARPROG:=$(strip $(wildcard $(addsuffix /gtar$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(TARPROG),)
 TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
 TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
 ifeq ($(TARPROG),)
 ifeq ($(TARPROG),)
 TARPROG= __missing_command_TARPROG
 TARPROG= __missing_command_TARPROG
 else
 else
 TARPROG:=$(firstword $(TARPROG))
 TARPROG:=$(firstword $(TARPROG))
 endif
 endif
+else
+TARPROG:=$(firstword $(TARPROG))
+endif
 endif
 endif
 export TARPROG
 export TARPROG
 ASNAME=$(BINUTILSPREFIX)as
 ASNAME=$(BINUTILSPREFIX)as

+ 3 - 6
rtl/win32/Makefile.fpc

@@ -6,7 +6,7 @@
 main=rtl
 main=rtl
 
 
 [target]
 [target]
-loaders=wprt0 wdllprt0 gprt0 wcygprt0
+loaders=$(LOADERS)
 units=system ctypes objpas macpas strings \
 units=system ctypes objpas macpas strings \
       lineinfo heaptrc matrix \
       lineinfo heaptrc matrix \
       windows winsock initc cmem dynlibs signals \
       windows winsock initc cmem dynlibs signals \
@@ -44,11 +44,8 @@ WININC=wininc
 
 
 UNITPREFIX=rtl
 UNITPREFIX=rtl
 
 
-# Use new feature from 1.0.5 version
-# that generates release PPU files
-# which will not be recompiled
-ifdef RELEASE
-override FPCOPT+=-Ur
+ifneq ($(findstring 2.0.,$(FPC_VERSION)),)
+LOADERS=wprt0 wdllprt0 gprt0 wcygprt0
 endif
 endif
 
 
 # Paths
 # Paths

+ 46 - 8
rtl/win32/system.pp

@@ -93,8 +93,6 @@ var
   MainInstance,
   MainInstance,
   cmdshow     : longint;
   cmdshow     : longint;
   DLLreason,DLLparam:longint;
   DLLreason,DLLparam:longint;
-  Win32StackTop : Dword;
-
 type
 type
   TDLL_Process_Entry_Hook = function (dllparam : longint) : longbool;
   TDLL_Process_Entry_Hook = function (dllparam : longint) : longbool;
   TDLL_Entry_Hook = procedure (dllparam : longint);
   TDLL_Entry_Hook = procedure (dllparam : longint);
@@ -365,7 +363,6 @@ procedure remove_exception_handlers;forward;
 procedure PascalMain;stdcall;external name 'PASCALMAIN';
 procedure PascalMain;stdcall;external name 'PASCALMAIN';
 procedure fpc_do_exit;stdcall;external name 'FPC_DO_EXIT';
 procedure fpc_do_exit;stdcall;external name 'FPC_DO_EXIT';
 Procedure ExitDLL(Exitcode : longint); forward;
 Procedure ExitDLL(Exitcode : longint); forward;
-procedure asm_exit(Exitcode : longint);external name 'asm_exit';
 
 
 Procedure system_exit;
 Procedure system_exit;
 begin
 begin
@@ -383,7 +380,7 @@ begin
   remove_exception_handlers;
   remove_exception_handlers;
 
 
   { call exitprocess, with cleanup as required }
   { call exitprocess, with cleanup as required }
-  asm_exit(exitcode);
+  ExitProcess(exitcode);
 end;
 end;
 
 
 var
 var
@@ -391,7 +388,7 @@ var
     to check if the call stack can be written on exceptions }
     to check if the call stack can be written on exceptions }
   _SS : Cardinal;
   _SS : Cardinal;
 
 
-procedure Exe_entry;[public, alias : '_FPC_EXE_Entry'];
+procedure Exe_entry;[public,alias:'_FPC_EXE_Entry'];
   begin
   begin
      IsLibrary:=false;
      IsLibrary:=false;
      { install the handlers for exe only ?
      { install the handlers for exe only ?
@@ -412,7 +409,7 @@ procedure Exe_entry;[public, alias : '_FPC_EXE_Entry'];
         pushl %ebp
         pushl %ebp
         xorl %ebp,%ebp
         xorl %ebp,%ebp
         movl %esp,%eax
         movl %esp,%eax
-        movl %eax,Win32StackTop
+        movl %eax,StackTop
         movw %ss,%bp
         movw %ss,%bp
         movl %ebp,_SS
         movl %ebp,_SS
         call SysResetFPU
         call SysResetFPU
@@ -424,6 +421,7 @@ procedure Exe_entry;[public, alias : '_FPC_EXE_Entry'];
      system_exit;
      system_exit;
   end;
   end;
 
 
+
 Const
 Const
   { DllEntryPoint  }
   { DllEntryPoint  }
      DLL_PROCESS_ATTACH = 1;
      DLL_PROCESS_ATTACH = 1;
@@ -435,7 +433,7 @@ Var
 Const
 Const
      DLLExitOK : boolean = true;
      DLLExitOK : boolean = true;
 
 
-function Dll_entry : longbool;[public, alias : '_FPC_DLL_Entry'];
+function Dll_entry : longbool;
 var
 var
   res : longbool;
   res : longbool;
 
 
@@ -494,6 +492,44 @@ begin
     LongJmp(DLLBuf,1);
     LongJmp(DLLBuf,1);
 end;
 end;
 
 
+{$ifndef VER2_0}
+
+procedure _FPC_mainCRTStartup;stdcall;public name '_mainCRTStartup';
+begin
+  IsConsole:=true;
+  Exe_entry;
+end;
+
+
+procedure _FPC_WinMainCRTStartup;stdcall;public name '_WinMainCRTStartup';
+begin
+  IsConsole:=false;
+  Exe_entry;
+end;
+
+
+procedure _FPC_DLLMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLMainCRTStartup@12';
+begin
+  IsConsole:=true;
+  sysinstance:=_hinstance;
+  dllreason:=_dllreason;
+  dllparam:=_dllparam;
+  DLL_Entry;
+end;
+
+
+procedure _FPC_DLLWinMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLWinMainCRTStartup@12';
+begin
+  IsConsole:=false;
+  sysinstance:=_hinstance;
+  dllreason:=_dllreason;
+  dllparam:=_dllparam;
+  DLL_Entry;
+end;
+
+{$endif VER2_0}
+
+
 function GetCurrentProcess : dword;
 function GetCurrentProcess : dword;
  stdcall;external 'kernel32' name 'GetCurrentProcess';
  stdcall;external 'kernel32' name 'GetCurrentProcess';
 
 
@@ -1160,13 +1196,15 @@ begin
   result := stklen;
   result := stklen;
 end;
 end;
 
 
+{
 const
 const
    Exe_entry_code : pointer = @Exe_entry;
    Exe_entry_code : pointer = @Exe_entry;
    Dll_entry_code : pointer = @Dll_entry;
    Dll_entry_code : pointer = @Dll_entry;
+}
 
 
 begin
 begin
   StackLength := CheckInitialStkLen(InitialStkLen);
   StackLength := CheckInitialStkLen(InitialStkLen);
-  StackBottom := initialstkptr - StackLength;
+  StackBottom := StackTop - StackLength;
   { get some helpful informations }
   { get some helpful informations }
   GetStartupInfo(@startupinfo);
   GetStartupInfo(@startupinfo);
   { some misc Win32 stuff }
   { some misc Win32 stuff }