Ver código fonte

Omit FPC_INIT_FUNC_TABLE generation if no unit initialization is registered for current project.

ccrause 2 anos atrás
pai
commit
fc76d9fac2
2 arquivos alterados com 27 adições e 1 exclusões
  1. 6 1
      compiler/hlcgobj.pas
  2. 21 0
      compiler/ngenutil.pas

+ 6 - 1
compiler/hlcgobj.pas

@@ -715,6 +715,7 @@ implementation
        nbas,ncon,nld,nmem,
        ncgrtti,pass_2,
        cgobj,cutils,procinfo,
+       ngenutil,
 {$ifdef x86}
        cgx86,
 {$endif x86}
@@ -4949,7 +4950,11 @@ implementation
          if not(current_module.islibrary) then
            begin
              if tf_init_final_units_by_calls in target_info.flags then
-               cg.a_call_name(list,'FPC_INIT_FUNC_TABLE',false)
+               begin
+                 { Only insert call if there are init functions }
+                 if cnodeutils.has_init_list then
+                   cg.a_call_name(list,'FPC_INIT_FUNC_TABLE',false);
+               end
              else
                g_call_system_proc(list,'fpc_initializeunits',[],nil).resetiftemp;
            end

+ 21 - 0
compiler/ngenutil.pas

@@ -134,6 +134,9 @@ interface
 
       class procedure InsertMemorySizes; virtual;
 
+      { Call this to check if init code is required }
+      class function has_init_list: boolean;
+
       { called right before an object is assembled, can be used to insert
         global information into the assembler list (used by LLVM to insert type
         info) }
@@ -1228,6 +1231,24 @@ implementation
       unitinits.free;
     end;
 
+  class function tnodeutils.has_init_list: boolean;
+    var
+      hp : tused_unit;
+    begin
+      Result:=false;
+      { Check used units }
+      hp:=tused_unit(usedunits.first);
+      while assigned(hp) and (Result=false) do
+        begin
+          if mf_init in hp.u.moduleflags then
+            Result:=true;
+          hp:=tused_unit(hp.next);
+        end;
+
+      { Check current module }
+      Result:=Result or (mf_init in current_module.moduleflags);
+    end;
+
 
   class procedure tnodeutils.InsertThreadvarTablesTable;
     var