Browse Source

Merged revisions 503,513,541,1077 via svnmerge from
/trunk

git-svn-id: branches/fixes_2_0@1129 -

peter 20 năm trước cách đây
mục cha
commit
00a5bcb0bc

+ 4 - 0
compiler/globals.pas

@@ -288,6 +288,10 @@ interface
        syscall_convention : string = 'LEGACY';
 {$endif powerpc}
 
+       { default name of the C-style "main" procedure of the library/program }
+       { (this will be prefixed with the target_info.cprefix)                }
+       mainaliasname : string = 'main';
+
     procedure abstract;
 
     function bstoslash(const s : string) : string;

+ 2 - 0
compiler/msg/errore.msg

@@ -2374,6 +2374,8 @@ P*2WT_Specify tool type application (MPW tool, MacOS only)
 **2Xc_pass --shared to the linker (Unix only)
 **2Xd_don't use standard library search path (needed for cross compile)
 **2XD_try to link units dynamic          (defines FPC_LINK_DYNAMIC)
+**2Xm_generate link map
+**2XM<x>_set the name of the 'main' program routine (default is 'main')
 **2XP<x>_prepend the binutils names with the prefix <x>
 **2Xr<x>_set library search path to <x> (needed for cross compile)
 **2Xs_strip all symbols from executable

+ 1 - 1
compiler/msgidx.inc

@@ -660,7 +660,7 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 38842;
+  MsgTxtSize = 38938;
 
   MsgIdxMax : array[1..20] of longint=(
     19,73,215,59,59,47,100,20,135,60,

+ 8 - 5
compiler/msgtxt.inc

@@ -1,7 +1,7 @@
 {$ifdef Delphi}
-const msgtxt : array[0..000161] of string[240]=(
+const msgtxt : array[0..000162] of string[240]=(
 {$else Delphi}
-const msgtxt : array[0..000161,1..240] of char=(
+const msgtxt : array[0..000162,1..240] of char=(
 {$endif Delphi}
   '01000_T_Compiler: $1'#000+
   '01001_D_Compiler OS: $1'#000+
@@ -935,13 +935,16 @@ const msgtxt : array[0..000161,1..240] of char=(
   '**2Xd_don'#039't use standard library search path (needed for cross com'+
   'pile)'#010+
   '**2XD_try to link units dynamic          (defines',' FPC_LINK_DYNAMIC)'#010+
+  '**2Xm_generate link map'#010+
+  '**2XM<x>_set the name of the '#039'main'#039' program routine (default i'+
+  's '#039'main'#039')'#010+
   '**2XP<x>_prepend the binutils names with the prefix <x>'#010+
   '**2Xr<x>_set library search path to <x> (needed for cross compile)'#010+
-  '**2Xs_strip all symbols from executable'#010+
-  '**2XS_try to link units static (default) (defines FPC_LINK','_STATIC)'#010+
+  '**','2Xs_strip all symbols from executable'#010+
+  '**2XS_try to link units static (default) (defines FPC_LINK_STATIC)'#010+
   '**2Xt_link with static libraries (-static is passed to linker)'#010+
   '**2XX_try to link units smart            (defines FPC_LINK_SMART)'#010+
-  '**1*_'#010+
+  '**1*_'#010,
   '**1?_shows this help'#010+
   '**1h_shows this help without waiting'#000
 );

+ 9 - 1
compiler/ncgutil.pas

@@ -1554,7 +1554,8 @@ implementation
       var
         href : treference;
         paraloc1,
-        paraloc2 : tcgpara;
+        paraloc2,
+        paraloc3 : tcgpara;
         hp   : tused_unit;
       begin
         paraloc1.init;
@@ -1580,6 +1581,13 @@ implementation
         { call startup helpers from main program }
         if (current_procinfo.procdef.proctypeoption=potype_proginit) then
          begin
+           if (target_info.system = system_powerpc_darwin) or
+              (target_info.system = system_powerpc_macos) then
+             begin
+              { the parameters are already in the right registers }
+              cg.a_call_name(list,target_info.cprefix+'FPC_SYSTEMMAIN');
+             end;
+           
            { initialize units }
            cg.alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
            cg.a_call_name(list,'FPC_INITIALIZEUNITS');

+ 8 - 1
compiler/options.pas

@@ -606,7 +606,7 @@ begin
                begin
                  l:=Pos(':=',more);
                  if l>0 then
-                   set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))                  
+                   set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))
                  else
                    def_system_macro(more);
                end;
@@ -1213,6 +1213,11 @@ begin
                         exclude(initglobalswitches,cs_link_shared);
                         LinkTypeSetExplicitly:=true;
                       end;
+                    'M' :
+                      begin
+                        mainaliasname:=Copy(more,2,length(More)-1);
+                        More:='';
+                      end;
                     '-' :
                       begin
                         exclude(initglobalswitches,cs_link_staticflag);
@@ -1775,6 +1780,8 @@ begin
 
 { Temporary defines, until things settle down }
   def_system_macro('COMPPROCINLINEFIXED');
+  { "main" symbol is generated in the main program, and left out of the system unit }
+  def_system_macro('FPC_DARWIN_PASCALMAIN');
 
   if pocall_default = pocall_register then
     def_system_macro('REGCALL');

+ 2 - 0
compiler/parser.pas

@@ -35,7 +35,9 @@ interface
 implementation
 
     uses
+{$IFNDEF MACOS_USE_FAKE_SYSUTILS}
       sysutils,
+{$ENDIF MACOS_USE_FAKE_SYSUTILS}
       cutils,cclasses,
       globtype,version,tokens,systems,globals,verbose,
       symbase,symtable,symsym,

+ 13 - 15
compiler/pmodules.pas

@@ -1498,26 +1498,24 @@ implementation
 
          { The program intialization needs an alias, so it can be called
            from the bootstrap code.}
-         if islibrary or
-            (target_info.system in [system_powerpc_macos,system_powerpc_darwin]) then
+         
+         if islibrary then
           begin
-            pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'main'),potype_proginit,st);
+            pd:=create_main_proc(make_mangledname('',current_module.localsymtable,mainaliasname),potype_proginit,st);
             { Win32 startup code needs a single name }
 //            if (target_info.system in [system_i386_win32,system_i386_wdosx]) then
             pd.aliasnames.insert('PASCALMAIN');
           end
-         else
-          begin
-            if (target_info.system = system_i386_netware) or
-               (target_info.system = system_i386_netwlibc) then
-            begin
-              pd:=create_main_proc('PASCALMAIN',potype_proginit,st); { main is need by the netware rtl }
-            end else
-            begin
-              pd:=create_main_proc('main',potype_proginit,st);
-              pd.aliasnames.insert('PASCALMAIN');
-            end;
-          end;
+         else if (target_info.system = system_i386_netware) or
+                 (target_info.system = system_i386_netwlibc) then
+           begin
+             pd:=create_main_proc('PASCALMAIN',potype_proginit,st); { main is need by the netware rtl }
+           end
+         else 
+           begin
+             pd:=create_main_proc(mainaliasname,potype_proginit,st);
+             pd.aliasnames.insert('PASCALMAIN');
+           end;
          tcgprocinfo(current_procinfo).parse_body;
          tcgprocinfo(current_procinfo).generate_code;
          tcgprocinfo(current_procinfo).resetprocdef;

+ 7 - 0
rtl/bsd/system.pp

@@ -216,16 +216,23 @@ end;
 { can also be used with other BSD's if they use the system's crtX instead of prtX }
 
 {$ifdef Darwin}
+
+{$ifndef FPC_DARWIN_PASCALMAIN}
 procedure pascalmain; external name 'PASCALMAIN';
 
 { Main entry point in C style, needed to capture program parameters. }
 procedure main(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public];
+{$else FPC_DARWIN_PASCALMAIN}
+procedure FPC_SYSTEMMAIN(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public];
+{$endif FPC_DARWIN_PASCALMAIN}
 
 begin
   argc:= argcparam;
   argv:= argvparam;
   envp:= envpparam;
+{$ifndef FPC_DARWIN_PASCALMAIN}
   pascalmain;  {run the pascal main program}
+{$endif FPC_DARWIN_PASCALMAIN}
 end;
 {$endif Darwin}
 {$endif FPC_USE_LIBC}

+ 6 - 0
rtl/macos/system.pp

@@ -213,18 +213,24 @@ end;
                          SystemUnit Initialization
 *****************************************************************************}
 
+{$ifndef FPC_DARWIN_PASCALMAIN}
 procedure pascalmain; external name 'PASCALMAIN';
 
 {Main entry point in C style, needed to capture program parameters.
  For this to work, the system unit must be before the main program
  in the linking order.}
 procedure main(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public];
+{$else FPC_DARWIN_PASCALMAIN}
+procedure FPC_SYSTEMMAIN(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public];
+{$endif FPC_DARWIN_PASCALMAIN}
 
 begin
   argc:= argcparam;
   argv:= argvparam;
   envp:= envpparam;
+{$ifndef FPC_DARWIN_PASCALMAIN}
   pascalmain;  {run the pascal main program}
+{$endif FPC_DARWIN_PASCALMAIN}
 end;
 
 procedure setup_arguments;