소스 검색

Switch Mac OS X to indirect entry information.

compiler/systems/t_bsd.pas, TLinkerBSD:
  + implement InitSysInitUnitName
compiler/system.pas:
  * systems_internal_sysinit: add Darwin systems
compiler/hlcgobj.pas, thlcgobj:
  * gen_proc_symbol_end: for Darwin systems don't directly call PascalMain for libraries, but FPC_LIBMAIN instead
rtl/darwin:
  + add sysinit.pas unit which contains the executable and library entry points for Darwin
rtl/darwin/Makefile.fpc:
  * add sysinit unit
rtl/bsd/sysosh.inc:
  + add a Darwin specific TPlatformEntryInformation (could probably be used for all Unix systems...)
rtl/bsd/system.pp:
  * define FPC_HAS_INDIRECT_MAIN_INFORMATION for Darwin systems once we're no longer bootstrapping with 2.6.x
  + add EntryInformation variable (this could maybe moved to system.inc...)
  + add new procedure SysEntry that is called from the entrypoint and which sets up necessary information required by other parts of the RTL
  * the old FPC_SYSTEMMAIN is still in place for bootstrapping
rtl/inc/systemh.inc, TEntryInformation:
  * PascalMain is cdecl on non-Windows systems (ToDo: really?)
rtl/inc/system.inc:
  * initialstklen is provided by the indirect entry information, so no external here

git-svn-id: branches/svenbarth/packages@31929 -
svenbarth 10 년 전
부모
커밋
1a68af9a74
10개의 변경된 파일148개의 추가작업 그리고 7개의 파일을 삭제
  1. 1 0
      .gitattributes
  2. 13 3
      compiler/hlcgobj.pas
  3. 1 1
      compiler/systems.pas
  4. 10 0
      compiler/systems/t_bsd.pas
  5. 12 0
      rtl/bsd/sysosh.inc
  6. 33 0
      rtl/bsd/system.pp
  7. 1 1
      rtl/darwin/Makefile.fpc
  8. 75 0
      rtl/darwin/sysinit.pas
  9. 1 1
      rtl/inc/system.inc
  10. 1 1
      rtl/inc/systemh.inc

+ 1 - 0
.gitattributes

@@ -7965,6 +7965,7 @@ rtl/darwin/ptypes.inc svneol=native#text/plain
 rtl/darwin/rtldefs.inc svneol=native#text/plain
 rtl/darwin/signal.inc svneol=native#text/plain
 rtl/darwin/sysctlh.inc svneol=native#text/plain
+rtl/darwin/sysinit.pas svneol=native#text/pascal
 rtl/darwin/termio.pp svneol=native#text/plain
 rtl/darwin/termios.inc svneol=native#text/plain
 rtl/darwin/termiosproc.inc svneol=native#text/plain

+ 13 - 3
compiler/hlcgobj.pas

@@ -4162,6 +4162,8 @@ implementation
     end;
 
   procedure thlcgobj.gen_proc_symbol_end(list: TAsmList);
+    var
+      initname : tsymstr;
     begin
       list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
 
@@ -4169,9 +4171,17 @@ implementation
 
       if (current_module.islibrary) then
         if (current_procinfo.procdef.proctypeoption = potype_proginit) then
-          { setinitname may generate a new section -> don't add to the
-            current list, because we assume this remains a text section }
-          exportlib.setinitname(current_asmdata.AsmLists[al_exports],current_procinfo.procdef.mangledname);
+          begin
+            { ToDo: systems that use indirect entry info, but check back with Windows! }
+            if target_info.system in systems_darwin then
+              { we need to call FPC_LIBMAIN in sysinit which in turn will call PascalMain }
+              initname:=target_info.cprefix+'FPC_LIBMAIN'
+            else
+              initname:=current_procinfo.procdef.mangledname;
+            { setinitname may generate a new section -> don't add to the
+              current list, because we assume this remains a text section }
+            exportlib.setinitname(current_asmdata.AsmLists[al_exports],initname);
+          end;
 
       if (current_procinfo.procdef.proctypeoption=potype_proginit) then
         begin

+ 1 - 1
compiler/systems.pas

@@ -304,7 +304,7 @@ interface
        { all systems for which weak linking has been tested/is supported }
        systems_weak_linking = systems_darwin + systems_solaris + systems_linux + systems_android;
 
-       systems_internal_sysinit = [system_i386_linux,system_i386_win32];
+       systems_internal_sysinit = [system_i386_linux,system_i386_win32]+systems_darwin;
 
        { all systems that use garbage collection for reference-counted types }
        systems_garbage_collected_managed_types = [

+ 10 - 0
compiler/systems/t_bsd.pas

@@ -69,6 +69,7 @@ implementation
       function  MakeExecutable:boolean;override;
       function  MakeSharedLibrary:boolean;override;
       procedure LoadPredefinedLibraryOrder; override;
+      procedure InitSysInitUnitName; override;
     end;
 
 
@@ -224,6 +225,15 @@ else
 End;
 
 
+procedure TLinkerBSD.InitSysInitUnitName;
+begin
+  if target_info.system in systems_darwin then
+    SysInitUnit:='sysinit'
+  else
+    inherited InitSysInitUnitName;
+end;
+
+
 function TLinkerBSD.GetDarwinCrt1ObjName(isdll: boolean): TCmdStr;
 begin
   if not isdll then

+ 12 - 0
rtl/bsd/sysosh.inc

@@ -26,6 +26,18 @@ type
   PRTLCriticalSection = ^TRTLCriticalSection;
   TRTLCriticalSection = {$i pmutext.inc}
 
+{$ifdef darwin}
+{$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
+{$define HAS_ENTRYINFORMATION_PLATFORM}
+  TPlatformEntryInformation = record
+    argc: longint;
+    argv: ppchar;
+    envp: ppchar;
+    stklen: sizeuint;
+  end;
+{$endif}
+{$endif}
+
 {$if defined(darwin) and defined(powerpc)}
   { for profiling support }
   procedure mcount(p: pointer); compilerproc; cdecl; external;

+ 33 - 0
rtl/bsd/system.pp

@@ -32,6 +32,10 @@ Interface
 {$define FPC_USE_SYSCALL}
 {$endif}
 
+{$if defined(darwin) and not defined(ver2_6)}
+{$define FPC_HAS_INDIRECT_MAIN_INFORMATION}
+{$endif}
+
 
 {$define FPC_IS_SYSTEM}
 
@@ -77,6 +81,11 @@ Implementation
 {$endif defined(CPUARM) or defined(CPUM68K)}
 
 
+{$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
+var
+  EntryInformation: TEntryInformation;
+{$endif FPC_HAS_INDIRECT_MAIN_INFORMATION}
+
 {$I system.inc}
 
 {*****************************************************************************
@@ -292,6 +301,29 @@ end;
 
 {$ifdef Darwin}
 
+{$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
+
+var
+  FPCResStrInitTables : Pointer;public name '_FPC_ResStrInitTables';
+  FPCResourceStringTables : Pointer;public name '_FPC_ResourceStringTables';
+
+procedure SysEntry(constref info: TEntryInformation);[public,alias:'FPC_SysEntry'];
+begin
+  EntryInformation := info;
+  argc := EntryInformation.Platform.argc;
+  argv := EntryInformation.Platform.argv;
+  envp := EntryInformation.Platform.envp;
+  initialstklen := EntryInformation.Platform.stklen;
+  FPCResStrInitTables := EntryInformation.ResStrInitTables;
+  FPCResourceStringTables := EntryInformation.ResourceStringTables;
+{$ifdef cpui386}
+  Set8087CW(Default8087CW);
+{$endif cpui386}
+  EntryInformation.PascalMain();
+end;
+
+{$else FPC_HAS_INDIRECT_MAIN_INFORMATION}
+
 procedure pascalmain;cdecl;external name 'PASCALMAIN';
 
 procedure FPC_SYSTEMMAIN(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public];
@@ -305,6 +337,7 @@ begin
 {$endif cpui386}
   pascalmain;  {run the pascal main program}
 end;
+{$endif FPC_HAS_INDIRECT_MAIN_INFORMATION}
 {$endif Darwin}
 {$endif FPC_USE_LIBC}
 

+ 1 - 1
rtl/darwin/Makefile.fpc

@@ -8,7 +8,7 @@ main=rtl
 # disabled units: serial
 [target]
 loaders=
-units=$(SYSTEMUNIT) uuchar unixtype ctypes objpas macpas iso7185 \
+units=$(SYSTEMUNIT) sysinit uuchar unixtype ctypes objpas macpas iso7185 \
       strings sysctl baseunix unixutil \
       unix initc cmem dynlibs $(CPU_UNITS) \
       dos dl \

+ 75 - 0
rtl/darwin/sysinit.pas

@@ -0,0 +1,75 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by the Free Pascal development team
+
+    Implements indirect entry point for executables and libaries
+
+    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 sysinit;
+
+interface
+
+implementation
+
+procedure PascalMain; cdecl; external name 'PASCALMAIN';
+procedure SysEntry(constref info: TEntryInformation); external name 'FPC_SysEntry';
+
+var
+  InitFinalTable : record end; external name 'INITFINAL';
+  ThreadvarTablesTable : record end; external name 'FPC_THREADVARTABLES';
+  {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
+  WideInitTables : record end; external name 'FPC_WIDEINITTABLES';
+  {$endif}
+  {$ifdef FPC_HAS_RESSTRINITS}
+  ResStrInitTables : record end; external name 'FPC_RESSTRINITTABLES';
+  {$endif}
+  ResourceStringTables : record end; external name 'FPC_RESOURCESTRINGTABLES';
+  StkLen: SizeUInt; external name '__stklen';
+
+const
+  SysInitEntryInformation : TEntryInformation = (
+    InitFinalTable : @InitFinalTable;
+    ThreadvarTablesTable : @ThreadvarTablesTable;
+    ResourceStringTables : @ResourceStringTables;
+{$ifdef FPC_HAS_RESSTRINITS}
+    ResStrInitTables : @ResStrInitTables;
+{$else}
+    ResStrInitTables : nil;
+{$endif}
+{$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
+    WideInitTables : @WideInitTables;
+{$endif}
+    asm_exit : nil;
+    PascalMain : @PascalMain;
+    valgrind_used : false;
+    Platform: (
+        argc: 0;
+        argv: nil;
+        envp: nil;
+        stklen: 0;
+      );
+    );
+
+
+procedure FPC_SYSTEMMAIN(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public];
+begin
+  SysInitEntryInformation.Platform.argc := argcparam;
+  SysInitEntryInformation.Platform.argv := argvparam;
+  SysInitEntryInformation.Platform.envp := envpparam;
+  SysInitEntryInformation.Platform.stklen := StkLen;
+  SysEntry(SysInitEntryInformation);
+end;
+
+procedure FPC_LIBMAIN; cdecl; [public];
+begin
+  SysEntry(SysInitEntryInformation);
+end;
+
+end.

+ 1 - 1
rtl/inc/system.inc

@@ -102,7 +102,7 @@ var
 {$ifndef FPC_NO_GENERIC_STACK_CHECK}
   { if the OS does the stack checking, we don't need any stklen from the
     main program }
-  initialstklen : SizeUint;external name '__stklen';
+  initialstklen : SizeUint;{$ifndef FPC_HAS_INDIRECT_MAIN_INFORMATION}external name '__stklen';{$endif FPC_HAS_INDIRECT_MAIN_INFORMATION}
 {$endif FPC_NO_GENERIC_STACK_CHECK}
 
 { checks whether the given suggested size for the stack of the current

+ 1 - 1
rtl/inc/systemh.inc

@@ -563,7 +563,7 @@ type
     WideInitTables : Pointer;
 {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
     asm_exit : Procedure;stdcall;
-    PascalMain : Procedure;stdcall;
+    PascalMain : Procedure;{$ifndef windows}cdecl;{$else}stdcall;{$endif}
     valgrind_used : boolean;
 {$ifdef HAS_ENTRYINFORMATION_PLATFORM}
     platform: TPlatformEntryInformation;