From 88a736c95a59fa301a39e1b2876c2927d85ca417 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 15 Jul 2016 14:34:11 +0000 Subject: [PATCH] * moved the code generated for library init/fini to the al_pure_assembler list, so that the assembler directives generated for Darwin are emitted correctly for LLVM o extracted the library init code generation from hlcgobj to pmodules so we don't add things to another list than what's passed to gen_proc_symbol_end(), and so it's done where we generate the init routine for libraries (rather then checking for every routine whether it's the init routine for a library) o removed the llvm-specific gen_proc_symbol_end() because the regular one now does the same git-svn-id: trunk@34134 - --- compiler/hlcgobj.pas | 17 ----------------- compiler/llvm/hlcgllvm.pas | 8 -------- compiler/pmodules.pas | 19 +++++++++++++++++-- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/compiler/hlcgobj.pas b/compiler/hlcgobj.pas index ca9059f2d8..272a7603c9 100644 --- a/compiler/hlcgobj.pas +++ b/compiler/hlcgobj.pas @@ -4479,26 +4479,9 @@ implementation end; procedure thlcgobj.gen_proc_symbol_end(list: TAsmList); - var - initname : tsymstr; begin list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname)); - current_procinfo.procdef.procendtai:=tai(list.last); - - if (current_module.islibrary) then - if (current_procinfo.procdef.proctypeoption = potype_proginit) then - 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; end; diff --git a/compiler/llvm/hlcgllvm.pas b/compiler/llvm/hlcgllvm.pas index 04083f5a55..bc0431cce9 100644 --- a/compiler/llvm/hlcgllvm.pas +++ b/compiler/llvm/hlcgllvm.pas @@ -96,7 +96,6 @@ uses procedure a_loadfpu_reg_reg(list: TAsmList; fromsize, tosize: tdef; reg1, reg2: tregister); override; procedure gen_proc_symbol(list: TAsmList); override; - procedure gen_proc_symbol_end(list: TAsmList); override; procedure handle_external_proc(list: TAsmList; pd: tprocdef; const importname: TSymStr); override; procedure g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean); override; procedure g_proc_exit(list : TAsmList;parasize:longint;nostackframe:boolean); override; @@ -1247,13 +1246,6 @@ implementation end; - procedure thlcgllvm.gen_proc_symbol_end(list: TAsmList); - begin - list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname)); - { todo: darwin main proc, or handle in other way? } - end; - - procedure thlcgllvm.handle_external_proc(list: TAsmList; pd: tprocdef; const importname: TSymStr); begin { don't do anything, because at this point we can't know yet for certain diff --git a/compiler/pmodules.pas b/compiler/pmodules.pas index e6b7f69fa5..b9f2e3e5e2 100644 --- a/compiler/pmodules.pas +++ b/compiler/pmodules.pas @@ -1808,6 +1808,7 @@ type main_procinfo : tcgprocinfo; force_init_final : boolean; resources_used : boolean; + initname, program_name : ansistring; consume_semicolon_after_uses : boolean; ps : tprogramparasym; @@ -2023,7 +2024,19 @@ type if not(target_info.system in (systems_darwin+systems_aix)) then main_procinfo.procdef.aliasnames.insert('PASCALMAIN') else - main_procinfo.procdef.aliasnames.insert(target_info.Cprefix+'PASCALMAIN') + main_procinfo.procdef.aliasnames.insert(target_info.Cprefix+'PASCALMAIN'); + + { 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 + -- add to pure assembler section, so in case of special directives + they are directly added to the assembler output by llvm } + exportlib.setinitname(current_asmdata.AsmLists[al_pure_assembler],initname); end else if (target_info.system in ([system_i386_netware,system_i386_netwlibc,system_powerpc_macos]+systems_darwin+systems_aix)) then begin @@ -2087,8 +2100,10 @@ type { the finalization routine of libraries is generic (and all libraries need to } { be finalized, so they can finalize any units they use } + { Place in "pure assembler" list so that the llvm assembler writer + directly emits the generated directives } if (islibrary) then - exportlib.setfininame(current_asmdata.asmlists[al_procedures],'FPC_LIB_EXIT'); + exportlib.setfininame(current_asmdata.asmlists[al_pure_assembler],'FPC_LIB_EXIT'); { all labels must be defined before generating code } if Errorcount=0 then