From a90e3b3e1db7d30fb48b74d46a3cab98126adf42 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 10 Mar 2006 23:45:37 +0000 Subject: [PATCH] * fixed argc/argv/envp catching for darwin/x86 (not really nice, but works) git-svn-id: trunk@2848 - --- compiler/ncgutil.pas | 17 ++++++++++------- compiler/options.pas | 1 + compiler/pmodules.pas | 3 +-- rtl/bsd/system.pp | 12 ++++++++---- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/compiler/ncgutil.pas b/compiler/ncgutil.pas index a484107a74..6c3d0827de 100644 --- a/compiler/ncgutil.pas +++ b/compiler/ncgutil.pas @@ -1689,13 +1689,6 @@ implementation { call startup helpers from main program } if (current_procinfo.procdef.proctypeoption=potype_proginit) then begin - if (target_info.system in [system_powerpc_darwin,system_i386_darwin,system_powerpc_macos]) and - not(current_module.islibrary) then - begin - { the parameters are already in the right registers } - cg.a_call_name(list,target_info.cprefix+'FPC_SYSTEMMAIN'); - end; - { initialize units } cg.allocallcpuregisters(list); cg.a_call_name(list,'FPC_INITIALIZEUNITS'); @@ -1787,6 +1780,16 @@ implementation if (current_procinfo.procdef.proctypeoption=potype_proginit) then begin + if (target_info.system in [system_powerpc_darwin,system_i386_darwin,system_powerpc_macos]) and + not(current_module.islibrary) then + begin + list.concat(tai_section.create(sec_code,'',4)); + list.concat(tai_symbol.createname_global( + target_info.cprefix+mainaliasname,AT_FUNCTION,0)); + { keep argc, argv and envp properly on the stack } + cg.a_jmp_name(list,target_info.cprefix+'FPC_SYSTEMMAIN'); + end; + { Reference all DEBUGINFO sections from the main .text section } if (cs_debuginfo in aktmoduleswitches) then debuginfo.referencesections(list); diff --git a/compiler/options.pas b/compiler/options.pas index f37acc00f0..e7b21f1487 100644 --- a/compiler/options.pas +++ b/compiler/options.pas @@ -1795,6 +1795,7 @@ begin { Temporary defines, until things settle down } { "main" symbol is generated in the main program, and left out of the system unit } def_system_macro('FPC_DARWIN_PASCALMAIN'); + def_system_macro('FPC_DARWIN_JMP_MAIN'); def_system_macro('COMPPROCINLINEFIXED'); def_system_macro('PARAOUTFILE'); diff --git a/compiler/pmodules.pas b/compiler/pmodules.pas index e6b70d41c1..272ffb00c6 100644 --- a/compiler/pmodules.pas +++ b/compiler/pmodules.pas @@ -1293,8 +1293,7 @@ implementation if not(target_info.system in [system_powerpc_darwin,system_i386_darwin]) then pd.aliasnames.insert('PASCALMAIN'); end - else if (target_info.system = system_i386_netware) or - (target_info.system = system_i386_netwlibc) then + else if (target_info.system in [system_i386_netware,system_i386_netwlibc,system_powerpc_macos,system_powerpc_darwin,system_i386_darwin]) then begin pd:=create_main_proc('PASCALMAIN',potype_proginit,current_module.localsymtable); end diff --git a/rtl/bsd/system.pp b/rtl/bsd/system.pp index aec799d6e8..22d69cfc20 100644 --- a/rtl/bsd/system.pp +++ b/rtl/bsd/system.pp @@ -218,11 +218,15 @@ end; {$ifdef Darwin} {$ifndef FPC_DARWIN_PASCALMAIN} -procedure pascalmain; external name '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} + +{$ifdef FPC_DARWIN_JMP_MAIN} +procedure pascalmain;cdecl;external name 'PASCALMAIN'; +{$endif} procedure FPC_SYSTEMMAIN(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public]; {$endif FPC_DARWIN_PASCALMAIN} @@ -230,9 +234,9 @@ begin argc:= argcparam; argv:= argvparam; envp:= envpparam; -{$ifndef FPC_DARWIN_PASCALMAIN} +{$if not defined(FPC_DARWIN_PASCALMAIN) or defined(FPC_DARWIN_JMP_MAIN)} pascalmain; {run the pascal main program} -{$endif FPC_DARWIN_PASCALMAIN} +{$endif} end; {$endif Darwin} {$endif FPC_USE_LIBC}