Browse Source

* 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 -

Jonas Maebe 6 years ago
parent
commit
e56b58c2b0
5 changed files with 37 additions and 34 deletions
  1. 17 0
      compiler/aasmdata.pas
  2. 1 11
      compiler/hlcgobj.pas
  3. 4 14
      compiler/ncgutil.pas
  4. 1 9
      compiler/psub.pas
  5. 14 0
      compiler/symdef.pas

+ 17 - 0
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;

+ 1 - 11
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

+ 4 - 14
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;
 

+ 1 - 9
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;

+ 14 - 0
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