2
0
Эх сурвалжийг харах

* Add unit name to unit init table

Michaël Van Canneyt 1 долоо хоног өмнө
parent
commit
91eb56bdfa

+ 15 - 0
compiler/ngenutil.pas

@@ -1148,6 +1148,9 @@ implementation
       nameinit,namefini : TSymStr;
       tabledef: tdef;
       entry : pinitfinalentry;
+      unitnametcb : ttai_typedconstbuilder;
+      unitnamedef : tdef;
+      unitnamelbl : tasmlabel;
 
       procedure add_initfinal_import(symtable:tsymtable);
         var
@@ -1245,6 +1248,18 @@ implementation
               if entry^.module<>current_module then
                 add_initfinal_import(entry^.module.localsymtable);
             end;
+          { Add pointer to unit name }
+          if assigned(entry^.module.realmodulename) then
+            begin
+              { Create string constant and emit pointer to it }
+              unitinits.start_internal_data_builder(current_asmdata.asmlists[al_globals],sec_rodata,'',unitnametcb,unitnamelbl);
+              unitnamedef:=unitnametcb.emit_shortstring_const(entry^.module.realmodulename^);
+              unitinits.finish_internal_data_builder(unitnametcb,unitnamelbl,unitnamedef,sizeof(pint));
+              unitinits.queue_init(charpointertype);
+              unitinits.queue_emit_asmsym(unitnamelbl,unitnamedef);
+            end
+          else
+            unitinits.emit_tai(Tai_const.Create_nil_dataptr,charpointertype);
         end;
 
       { Add to data segment }

+ 1 - 0
compiler/options.pas

@@ -4952,6 +4952,7 @@ begin
   def_system_macro('FPC_HAS_MEMBAR');
   def_system_macro('FPC_SETBASE_USED');
   def_system_macro('FPC_ALIGNED_THREADVARTABLES');
+  def_system_macro('FPC_INITFINAL_HASUNITNAME');
 
   { don't remove this, it's also for fpdoc necessary (FK) }
   def_system_macro('FPC_HAS_FEATURE_SUPPORT');

+ 3 - 0
rtl/inc/system.inc

@@ -1132,6 +1132,9 @@ type
   TInitFinalRec=record
     InitProc,
     FinalProc : TProcedure;
+    {$IFDEF FPC_INITFINAL_HASUNITNAME}
+    unitname : ^shortstring;
+    {$ENDIF}
   end;
   TInitFinalTable = record
     TableCount,