summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorjonas <jonas@3ad0048d-3df7-0310-abae-a5850022a9f2>2019-05-02 19:45:34 +0000
committerjonas <jonas@3ad0048d-3df7-0310-abae-a5850022a9f2>2019-05-02 19:45:34 +0000
commit0df7d1db05537a3bf08a08036d5de2733335e902 (patch)
tree7137f08a4f5a4031a889da39d3c25ed811899822 /compiler
parentd09d796aba73b68a738bf98a79e1398bf1384f18 (diff)
downloadfpc-0df7d1db05537a3bf08a08036d5de2733335e902.tar.gz
* fixed Objective-C metadata generation for LLVM
git-svn-id: https://svn.freepascal.org/svn/fpc/branches/debug_eh@41980 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'compiler')
-rw-r--r--compiler/llvm/nllvmutil.pas55
-rw-r--r--compiler/ngenutil.pas22
-rw-r--r--compiler/objcgutl.pas16
3 files changed, 76 insertions, 17 deletions
diff --git a/compiler/llvm/nllvmutil.pas b/compiler/llvm/nllvmutil.pas
index 286d4a6be1..9d34e15195 100644
--- a/compiler/llvm/nllvmutil.pas
+++ b/compiler/llvm/nllvmutil.pas
@@ -27,7 +27,7 @@ interface
uses
globtype,cclasses,
- aasmbase,aasmdata,ngenutil,
+ aasmbase,aasmdata,aasmllvmmetadata, ngenutil,
symtype,symconst,symsym,symdef;
@@ -39,6 +39,7 @@ interface
public
class procedure InsertObjectInfo; override;
class procedure RegisterUsedAsmSym(sym: TAsmSymbol; def: tdef; compileronly: boolean); override;
+ class procedure GenerateObjCImageInfo; override;
end;
@@ -49,13 +50,13 @@ implementation
aasmtai,cpubase,llvmbase,aasmllvm,
aasmcnst,nllvmtcon,
symbase,symtable,defutil,
- llvmtype;
+ llvmtype,
+ objcasm;
class procedure tllvmnodeutils.insertbsssym(list: tasmlist; sym: tstaticvarsym; size: asizeint; varalign: shortint);
var
asmsym: tasmsymbol;
field1, field2: tsym;
- tcb: ttai_typedconstbuilder;
begin
if sym.globalasmsym then
asmsym:=current_asmdata.DefineAsmSymbol(sym.mangledname,AB_GLOBAL,AT_DATA,sym.vardef)
@@ -195,6 +196,54 @@ implementation
end;
+ class procedure tllvmnodeutils.GenerateObjCImageInfo;
+ var
+ llvmmoduleflags,
+ objcmoduleflag: 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);
+ end;
+
+
begin
cnodeutils:=tllvmnodeutils;
end.
diff --git a/compiler/ngenutil.pas b/compiler/ngenutil.pas
index 0db0b68e19..aa2179e32c 100644
--- a/compiler/ngenutil.pas
+++ b/compiler/ngenutil.pas
@@ -143,6 +143,8 @@ interface
also for the linker }
class procedure RegisterUsedAsmSym(sym: TAsmSymbol; def: tdef; compileronly: boolean); virtual;
+ class procedure GenerateObjCImageInfo; virtual;
+
strict protected
class procedure add_main_procdef_paras(pd: tdef); virtual;
end;
@@ -1558,6 +1560,26 @@ implementation
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',sizeof(pint)
+ )
+ );
+ tcb.free;
+ end;
+
+
class procedure tnodeutils.add_main_procdef_paras(pd: tdef);
var
pvs: tparavarsym;
diff --git a/compiler/objcgutl.pas b/compiler/objcgutl.pas
index 7036b45a47..637194c647 100644
--- a/compiler/objcgutl.pas
+++ b/compiler/objcgutl.pas
@@ -48,6 +48,7 @@ implementation
objcdef,objcutil,
aasmcnst,
symconst,symtype,symsym,symtable,
+ ngenutil,
verbose;
type
@@ -1909,23 +1910,10 @@ constructor tobjcrttiwriter_nonfragile.create;
procedure MaybeGenerateObjectiveCImageInfo(globalst, localst: tsymtable);
var
objcrttiwriter: tobjcrttiwriter;
- tcb: ttai_typedconstbuilder;
begin
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',sizeof(pint)
- )
- );
- tcb.free;
+ cnodeutils.GenerateObjCImageInfo;
{ generate rtti for all obj-c classes, protocols and categories
defined in this module. }