Browse Source

tnodeuitls: merge GenerateObjCImageInfo into InsertObjectInfo

LLVM needs to insert the Objective-C image info into the general object info
metadata. This way we don't need to store a reference to that metadata so
as to add extra data to it later (tnodeutils is never instantiated, it only
contains class methods)
Jonas Maebe 3 years ago
parent
commit
229eb93e72
3 changed files with 99 additions and 109 deletions
  1. 81 84
      compiler/llvm/nllvmutil.pas
  2. 18 23
      compiler/ngenutil.pas
  3. 0 2
      compiler/objcgutl.pas

+ 81 - 84
compiler/llvm/nllvmutil.pas

@@ -40,7 +40,6 @@ interface
      public
      public
       class procedure InsertObjectInfo; override;
       class procedure InsertObjectInfo; override;
       class procedure RegisterUsedAsmSym(sym: TAsmSymbol; def: tdef; compileronly: boolean); override;
       class procedure RegisterUsedAsmSym(sym: TAsmSymbol; def: tdef; compileronly: boolean); override;
-      class procedure GenerateObjCImageInfo; override;
       class procedure RegisterModuleInitFunction(pd: tprocdef); override;
       class procedure RegisterModuleInitFunction(pd: tprocdef); override;
       class procedure RegisterModuleFiniFunction(pd: tprocdef); override;
       class procedure RegisterModuleFiniFunction(pd: tprocdef); override;
     end;
     end;
@@ -205,11 +204,89 @@ implementation
 
 
 
 
   class procedure tllvmnodeutils.InsertObjectInfo;
   class procedure tllvmnodeutils.InsertObjectInfo;
+    var
+      llvmmoduleflags,
+      objcmoduleflag,
+      dwarfversionflag: tai_llvmbasemetadatanode;
+      objcabiversion: longint;
     begin
     begin
-      inherited;
+      llvmmoduleflags:=tai_llvmnamedmetadatanode.create('llvm.module.flags');
+      current_asmdata.AsmLists[al_rotypedconsts].Concat(llvmmoduleflags);
+
+      if (m_objectivec1 in current_settings.modeswitches) then
+        begin
+          { Objective-C ABI version }
+          if not(target_info.system in [system_powerpc_darwin,system_powerpc64_darwin,system_i386_darwin,system_x86_64_darwin]) or
+             (CompareVersionStrings(MacOSXVersionMin,'10.5')>=0) then
+            objcabiversion:=2
+          else
+            objcabiversion:=1;
+          objcmoduleflag:=tai_llvmunnamedmetadatanode.create;
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(1)));
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Objective-C Version')));
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(objcabiversion)));
+          llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(objcmoduleflag));
+          current_asmdata.AsmLists[al_rotypedconsts].Concat(objcmoduleflag);
+
+          { image info version }
+          objcmoduleflag:=tai_llvmunnamedmetadatanode.create;
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(1)));
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Objective-C Image Info Version')));
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(0)));
+          llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(objcmoduleflag));
+          current_asmdata.AsmLists[al_rotypedconsts].Concat(objcmoduleflag);
+
+          { image info section }
+          objcmoduleflag:=tai_llvmunnamedmetadatanode.create;
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(1)));
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Objective-C Image Info Section')));
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create(objc_section_name(sec_objc_image_info))));
+          llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(objcmoduleflag));
+          current_asmdata.AsmLists[al_rotypedconsts].Concat(objcmoduleflag);
+
+          { garbage collection }
+          objcmoduleflag:=tai_llvmunnamedmetadatanode.create;
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(1)));
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Objective-C Garbage Collection')));
+          objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(0)));
+          llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(objcmoduleflag));
+          current_asmdata.AsmLists[al_rotypedconsts].Concat(objcmoduleflag);
+
+          { insert newly created defs in the implementation rather than interface symtable
+          (the interface symtable is sealed at this point) }
+        end;
+
+      { debug information }
+      if (([cs_debuginfo,cs_lineinfo]*current_settings.moduleswitches)<>[]) and
+         (target_dbg.id in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4]) then
+        begin
+          { the debug info version is the version of the debug info metadata
+            format }
+          dwarfversionflag:=tai_llvmunnamedmetadatanode.create;
+          dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(2)));
+          dwarfversionflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Debug Info Version')));
+          dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(llvm_debuginfo_metadata_format[current_settings.llvmversion])));
+          llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(dwarfversionflag));
+          current_asmdata.AsmLists[al_rotypedconsts].Concat(dwarfversionflag);
+
+          { dwarf version }
+          dwarfversionflag:=tai_llvmunnamedmetadatanode.create;
+          dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(2)));
+          dwarfversionflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Dwarf Version')));
+          case target_dbg.id of
+            dbg_dwarf2:
+              dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(2)));
+            dbg_dwarf3:
+              dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(3)));
+            dbg_dwarf4:
+              dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(4)));
+            else
+              internalerror(2022022012);
+          end;
+          llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(dwarfversionflag));
+          current_asmdata.AsmLists[al_rotypedconsts].Concat(dwarfversionflag);
+        end;
 
 
-      { insert newly created defs in the implementation rather than interface symtable
-        (the interface symtable is sealed at this point) }
       symtablestack.push(current_module.localsymtable);
       symtablestack.push(current_module.localsymtable);
 
 
       { add the llvm.compiler.used array }
       { add the llvm.compiler.used array }
@@ -254,86 +331,6 @@ implementation
     end;
     end;
 
 
 
 
-  class procedure tllvmnodeutils.GenerateObjCImageInfo;
-    var
-      llvmmoduleflags,
-      objcmoduleflag,
-      dwarfversionflag: tai_llvmbasemetadatanode;
-      objcabiversion: longint;
-    begin
-      llvmmoduleflags:=tai_llvmnamedmetadatanode.create('llvm.module.flags');
-      current_asmdata.AsmLists[al_rotypedconsts].Concat(llvmmoduleflags);
-
-      { Objective-C ABI version }
-      if not(target_info.system in [system_powerpc_darwin,system_powerpc64_darwin,system_i386_darwin,system_x86_64_darwin]) or
-         (CompareVersionStrings(MacOSXVersionMin,'10.5')>=0) then
-        objcabiversion:=2
-      else
-        objcabiversion:=1;
-      objcmoduleflag:=tai_llvmunnamedmetadatanode.create;
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(1)));
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Objective-C Version')));
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(objcabiversion)));
-      llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(objcmoduleflag));
-      current_asmdata.AsmLists[al_rotypedconsts].Concat(objcmoduleflag);
-
-      { image info version }
-      objcmoduleflag:=tai_llvmunnamedmetadatanode.create;
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(1)));
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Objective-C Image Info Version')));
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(0)));
-      llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(objcmoduleflag));
-      current_asmdata.AsmLists[al_rotypedconsts].Concat(objcmoduleflag);
-
-      { image info section }
-      objcmoduleflag:=tai_llvmunnamedmetadatanode.create;
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(1)));
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Objective-C Image Info Section')));
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create(objc_section_name(sec_objc_image_info))));
-      llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(objcmoduleflag));
-      current_asmdata.AsmLists[al_rotypedconsts].Concat(objcmoduleflag);
-
-      { garbage collection }
-      objcmoduleflag:=tai_llvmunnamedmetadatanode.create;
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(1)));
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Objective-C Garbage Collection')));
-      objcmoduleflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(0)));
-      llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(objcmoduleflag));
-      current_asmdata.AsmLists[al_rotypedconsts].Concat(objcmoduleflag);
-
-      { debug information }
-      if (([cs_debuginfo,cs_lineinfo]*current_settings.moduleswitches)<>[]) and
-         (target_dbg.id in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4]) then
-        begin
-          { the debug info version is the version of the debug info metadata
-            format }
-          dwarfversionflag:=tai_llvmunnamedmetadatanode.create;
-          dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(2)));
-          dwarfversionflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Debug Info Version')));
-          dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(llvm_debuginfo_metadata_format[current_settings.llvmversion])));
-          llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(dwarfversionflag));
-          current_asmdata.AsmLists[al_rotypedconsts].Concat(dwarfversionflag);
-
-          { dwarf version }
-          dwarfversionflag:=tai_llvmunnamedmetadatanode.create;
-          dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(2)));
-          dwarfversionflag.addvalue(tai_simpletypedconst.create(charpointertype,tai_string.Create('Dwarf Version')));
-          case target_dbg.id of
-            dbg_dwarf2:
-              dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(2)));
-            dbg_dwarf3:
-              dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(3)));
-            dbg_dwarf4:
-              dwarfversionflag.addvalue(tai_simpletypedconst.create(s32inttype,tai_const.Create_32bit(4)));
-            else
-              internalerror(2022022012);
-          end;
-          llvmmoduleflags.addvalue(llvm_getmetadatareftypedconst(dwarfversionflag));
-          current_asmdata.AsmLists[al_rotypedconsts].Concat(dwarfversionflag);
-        end;
-    end;
-
-
   class procedure tllvmnodeutils.RegisterModuleInitFunction(pd: tprocdef);
   class procedure tllvmnodeutils.RegisterModuleInitFunction(pd: tprocdef);
     begin
     begin
       current_module.llvminitprocs.add(pd);
       current_module.llvminitprocs.add(pd);

+ 18 - 23
compiler/ngenutil.pas

@@ -146,8 +146,6 @@ interface
       class procedure RegisterModuleInitFunction(pd: tprocdef); virtual;
       class procedure RegisterModuleInitFunction(pd: tprocdef); virtual;
       class procedure RegisterModuleFiniFunction(pd: tprocdef); virtual;
       class procedure RegisterModuleFiniFunction(pd: tprocdef); virtual;
 
 
-      class procedure GenerateObjCImageInfo; virtual;
-
      strict protected
      strict protected
       class procedure add_main_procdef_paras(pd: tdef); virtual;
       class procedure add_main_procdef_paras(pd: tdef); virtual;
     end;
     end;
@@ -1612,8 +1610,25 @@ implementation
 
 
 
 
   class procedure tnodeutils.InsertObjectInfo;
   class procedure tnodeutils.InsertObjectInfo;
+    var
+      tcb: ttai_typedconstbuilder;
     begin
     begin
-      { don't do anything by default }
+      if (m_objectivec1 in current_settings.modeswitches) then
+        begin
+          { first 4 bytes contain version information about this section (currently version 0),
+            next 4 bytes contain flags (currently only regarding whether the code in the object
+            file supports or requires garbage collection)
+          }
+          tcb:=ctai_typedconstbuilder.create([tcalo_new_section,tcalo_no_dead_strip]);
+          tcb.emit_ord_const(0,u64inttype);
+          current_asmdata.asmlists[al_objc_data].concatList(
+            tcb.get_final_asmlist(
+              current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'_OBJC_IMAGE_INFO',AB_LOCAL,AT_DATA,u64inttype),
+              u64inttype,sec_objc_image_info,'_OBJC_IMAGE_INFO',const_align(sizeof(pint))
+            )
+          );
+          tcb.free;
+        end;
     end;
     end;
 
 
 
 
@@ -1637,26 +1652,6 @@ implementation
     end;
     end;
 
 
 
 
-  class procedure tnodeutils.GenerateObjCImageInfo;
-    var
-      tcb: ttai_typedconstbuilder;
-    begin
-      { first 4 bytes contain version information about this section (currently version 0),
-        next 4 bytes contain flags (currently only regarding whether the code in the object
-        file supports or requires garbage collection)
-      }
-      tcb:=ctai_typedconstbuilder.create([tcalo_new_section,tcalo_no_dead_strip]);
-      tcb.emit_ord_const(0,u64inttype);
-      current_asmdata.asmlists[al_objc_data].concatList(
-        tcb.get_final_asmlist(
-          current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'_OBJC_IMAGE_INFO',AB_LOCAL,AT_DATA,u64inttype),
-          u64inttype,sec_objc_image_info,'_OBJC_IMAGE_INFO',const_align(sizeof(pint))
-        )
-      );
-      tcb.free;
-    end;
-
-
    class procedure tnodeutils.add_main_procdef_paras(pd: tdef);
    class procedure tnodeutils.add_main_procdef_paras(pd: tdef);
      var
      var
        pvs: tparavarsym;
        pvs: tparavarsym;

+ 0 - 2
compiler/objcgutl.pas

@@ -1898,8 +1898,6 @@ procedure MaybeGenerateObjectiveCImageInfo(globalst, localst: tsymtable);
   begin
   begin
     if (m_objectivec1 in current_settings.modeswitches) then
     if (m_objectivec1 in current_settings.modeswitches) then
       begin
       begin
-        cnodeutils.GenerateObjCImageInfo;
-
         { generate rtti for all obj-c classes, protocols and categories
         { generate rtti for all obj-c classes, protocols and categories
           defined in this module. }
           defined in this module. }
         if not(target_info.system in systems_objc_nfabi) then
         if not(target_info.system in systems_objc_nfabi) then