From e56b58c2b05124558bc3c0d18ef1d1c48e9b6d01 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sun, 7 Jul 2019 21:33:47 +0000 Subject: [PATCH] * factored out checks whether a procdef's symbol needs to be global, and the generation of the procdef's asmsymbols o also removed unnecessary definition of procdef alias symbols for Darwin (they are already defined in ncgutil.alloc_proc_symbol) git-svn-id: trunk@42341 - --- compiler/aasmdata.pas | 17 +++++++++++++++++ compiler/hlcgobj.pas | 12 +----------- compiler/ncgutil.pas | 18 ++++-------------- compiler/psub.pas | 10 +--------- compiler/symdef.pas | 14 ++++++++++++++ 5 files changed, 37 insertions(+), 34 deletions(-) diff --git a/compiler/aasmdata.pas b/compiler/aasmdata.pas index 7b4eeb1fdd..b6018d652a 100644 --- a/compiler/aasmdata.pas +++ b/compiler/aasmdata.pas @@ -198,6 +198,7 @@ interface { asmsymbol } function DefineAsmSymbolByClass(symclass: TAsmSymbolClass; const s : TSymStr;_bind:TAsmSymBind;_typ:Tasmsymtype; def: tdef) : TAsmSymbol; virtual; function DefineAsmSymbol(const s : TSymStr;_bind:TAsmSymBind;_typ:Tasmsymtype; def: tdef) : TAsmSymbol; + function DefineProcAsmSymbol(pd: tdef; const s: TSymStr; global: boolean): TAsmSymbol; function WeakRefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype) : TAsmSymbol; function RefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype;indirect:boolean=false) : TAsmSymbol; function GetAsmSymbol(const s : TSymStr) : TAsmSymbol; @@ -248,6 +249,7 @@ implementation uses verbose, + globals, symconst, aasmtai; @@ -572,6 +574,21 @@ implementation end; + function TAsmData.DefineProcAsmSymbol(pd: tdef; const s: TSymStr; global: boolean): TAsmSymbol; + begin + { The condition to use global or local symbol must match + the code written in hlcg.gen_proc_symbol to + avoid change from AB_LOCAL to AB_GLOBAL, which generates + erroneous code (at least for targets using GOT) } + if global or + (cs_profile in current_settings.moduleswitches) then + result:=DefineAsmSymbol(s,AB_GLOBAL,AT_FUNCTION,pd) + else if tf_supports_hidden_symbols in target_info.flags then + result:=DefineAsmSymbol(s,AB_PRIVATE_EXTERN,AT_FUNCTION,pd) + else + result:=DefineAsmSymbol(s,AB_LOCAL,AT_FUNCTION,pd); + end; + function TAsmData.RefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype;indirect:boolean) : TAsmSymbol; var namestr : TSymStr; diff --git a/compiler/hlcgobj.pas b/compiler/hlcgobj.pas index ee1e7ae063..f3d834cc2f 100644 --- a/compiler/hlcgobj.pas +++ b/compiler/hlcgobj.pas @@ -4590,14 +4590,7 @@ implementation begin item:=TCmdStrListItem(current_procinfo.procdef.aliasnames.first); firstitem:=item; - global:= - (cs_profile in current_settings.moduleswitches) or - { smart linking using a library requires to promote - all non-nested procedures to AB_GLOBAL - otherwise you get undefined symbol error at linking - for msdos target with -CX option for instance } - (create_smartlink_library and not is_nested_pd(current_procinfo.procdef)) or - (po_global in current_procinfo.procdef.procoptions); + global:=current_procinfo.procdef.needsglobalasmsym; while assigned(item) do begin {$ifdef arm} @@ -4614,13 +4607,10 @@ implementation if global then begin list.concat(tai_symbolpair.create(spk_set_global,item.str,firstitem.str)); - { needed for generating the tai_symbol_end } - current_asmdata.DefineAsmSymbol(item.str,AB_GLOBAL,AT_FUNCTION,current_procinfo.procdef); end else begin list.concat(tai_symbolpair.create(spk_set,item.str,firstitem.str)); - current_asmdata.DefineAsmSymbol(item.str,AB_PRIVATE_EXTERN,AT_FUNCTION,current_procinfo.procdef); end; end else diff --git a/compiler/ncgutil.pas b/compiler/ncgutil.pas index 276c49fa9d..5330702be8 100644 --- a/compiler/ncgutil.pas +++ b/compiler/ncgutil.pas @@ -687,23 +687,13 @@ implementation procedure alloc_proc_symbol(pd: tprocdef); var - item : TCmdStrListItem; + item: TCmdStrListItem; begin - item := TCmdStrListItem(pd.aliasnames.first); + item:=TCmdStrListItem(pd.aliasnames.first); while assigned(item) do begin - { The condition to use global or local symbol must match - the code written in hlcg.gen_proc_symbol to - avoid change from AB_LOCAL to AB_GLOBAL, which generates - erroneous code (at least for targets using GOT) } - if (cs_profile in current_settings.moduleswitches) or - (po_global in current_procinfo.procdef.procoptions) then - current_asmdata.DefineAsmSymbol(item.str,AB_GLOBAL,AT_FUNCTION,pd) - else if tf_supports_hidden_symbols in target_info.flags then - current_asmdata.DefineAsmSymbol(item.str,AB_PRIVATE_EXTERN,AT_FUNCTION,pd) - else - current_asmdata.DefineAsmSymbol(item.str,AB_LOCAL,AT_FUNCTION,pd); - item := TCmdStrListItem(item.next); + current_asmdata.DefineProcAsmSymbol(pd,item.str,pd.needsglobalasmsym); + item:=TCmdStrListItem(item.next); end; end; diff --git a/compiler/psub.pas b/compiler/psub.pas index b7c905ba5d..6184f6bd83 100644 --- a/compiler/psub.pas +++ b/compiler/psub.pas @@ -2583,15 +2583,7 @@ implementation { make sure we don't change the binding of real external symbols } if (([po_external,po_weakexternal]*pd.procoptions)=[]) and (pocall_internproc<>pd.proccalloption) then - begin - if (po_global in pd.procoptions) or - (cs_profile in current_settings.moduleswitches) then - current_asmdata.DefineAsmSymbol(pd.mangledname,AB_GLOBAL,AT_FUNCTION,pd) - else if tf_supports_hidden_symbols in target_info.flags then - current_asmdata.DefineAsmSymbol(pd.mangledname,AB_PRIVATE_EXTERN,AT_FUNCTION,pd) - else - current_asmdata.DefineAsmSymbol(pd.mangledname,AB_LOCAL,AT_FUNCTION,pd); - end; + current_asmdata.DefineProcAsmSymbol(pd,pd.mangledname,pd.needsglobalasmsym); current_structdef:=old_current_structdef; current_genericdef:=old_current_genericdef; diff --git a/compiler/symdef.pas b/compiler/symdef.pas index 43b5ee5947..89619e5c74 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -820,6 +820,7 @@ interface function GetTypeName : string;override; function mangledname : TSymStr; virtual; procedure setmangledname(const s : TSymStr); + function needsglobalasmsym: boolean; procedure setcompilerprocname; function fullprocname(showhidden:boolean):string; function customprocname(pno: tprocnameoptions):ansistring; @@ -1254,6 +1255,7 @@ implementation { module } fmodule, { other } + aasmbase, gendef, fpccrc, entfile @@ -6556,6 +6558,18 @@ implementation include(procoptions,po_has_mangledname); end; + function tprocdef.needsglobalasmsym: boolean; + begin + result:= + (cs_profile in current_settings.moduleswitches) or + { smart linking using a library requires to promote + all non-nested procedures to AB_GLOBAL + otherwise you get undefined symbol error at linking + for msdos target with -CX option for instance } + (create_smartlink_library and not is_nested_pd(self)) or + (po_global in procoptions); + end; + procedure tprocdef.setcompilerprocname; begin