objcgutl.pas 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625
  1. {
  2. Copyright (c) 2009 by Jonas Maebe
  3. This unit implements some Objective-C helper routines at the code generator
  4. level.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License,or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {$i fpcdefs.inc}
  19. unit objcgutl;
  20. interface
  21. uses
  22. cclasses,
  23. aasmbase,aasmdata,
  24. symbase,symdef;
  25. procedure objcfinishstringrefpoolentry(entry: phashsetitem; stringpool: tconstpooltype; refsec, stringsec: tasmsectiontype);
  26. procedure objcfinishclassrefnfpoolentry(entry: phashsetitem; classdef: tobjectdef);
  27. procedure MaybeGenerateObjectiveCImageInfo(globalst, localst: tsymtable);
  28. implementation
  29. uses
  30. globtype,globals,fmodule,
  31. systems,
  32. aasmtai,
  33. cgbase,
  34. objcdef,objcutil,
  35. symconst,symtype,symsym,symtable,
  36. verbose;
  37. type
  38. tobjcabi = (oa_fragile, oa_nonfragile);
  39. (* tivarlayouttype = (il_weak,il_strong); *)
  40. tobjcrttiwriter = class
  41. protected
  42. fabi: tobjcabi;
  43. classdefs,
  44. catdefs: tfpobjectlist;
  45. classsyms,
  46. catsyms: tfpobjectlist;
  47. procedure gen_objc_methods(list: tasmlist; objccls: tobjectdef; out methodslabel: tasmlabel; classmethods, iscategory: Boolean);
  48. procedure gen_objc_protocol_elements(list: tasmlist; protocol: tobjectdef; out reqinstsym, optinstsym, reqclssym, optclssym: TAsmLabel);
  49. procedure gen_objc_protocol_list(list:TAsmList; protolist: TFPObjectList; out protolistsym: TAsmLabel);
  50. procedure gen_objc_cat_methods(list:TAsmList; items: TFPObjectList; section: tasmsectiontype;const sectname: string; out listsym: TAsmLabel);
  51. procedure gen_objc_protocol(list:TAsmList; protocol: tobjectdef; out protocollabel: TAsmSymbol);virtual;abstract;
  52. procedure gen_objc_category_sections(list:TAsmList; objccat: tobjectdef; out catlabel: TAsmSymbol);virtual;abstract;
  53. procedure gen_objc_classes_sections(list:TAsmList; objclss: tobjectdef; out classlabel: TAsmSymbol);virtual;abstract;
  54. procedure gen_objc_info_sections(list: tasmlist);virtual;abstract;
  55. public
  56. constructor create(_abi: tobjcabi);
  57. destructor destroy;override;
  58. procedure gen_objc_rtti_sections(list:TAsmList; st:TSymtable);
  59. property abi: tobjcabi read fabi;
  60. end;
  61. { Used by by PowerPC/32 and i386 }
  62. tobjcrttiwriter_fragile = class(tobjcrttiwriter)
  63. protected
  64. function gen_objc_protocol_ext(list: TAsmList; optinstsym, optclssym: TAsmLabel): TAsmLabel;
  65. procedure gen_objc_ivars(list: TAsmList; objccls: tobjectdef; out ivarslabel: TAsmLabel);
  66. procedure gen_objc_protocol(list:TAsmList; protocol: tobjectdef; out protocollabel: TAsmSymbol);override;
  67. procedure gen_objc_category_sections(list:TAsmList; objccat: tobjectdef; out catlabel: TAsmSymbol);override;
  68. procedure gen_objc_classes_sections(list:TAsmList; objclss: tobjectdef; out classlabel: TAsmSymbol);override;
  69. procedure gen_objc_info_sections(list: tasmlist);override;
  70. public
  71. constructor create;
  72. end;
  73. { Used by PowerPC/64, ARM, and x86_64 }
  74. tobjcrttiwriter_nonfragile = class(tobjcrttiwriter)
  75. protected
  76. ObjCEmptyCacheVar,
  77. ObjCEmptyVtableVar: TAsmSymbol;
  78. procedure gen_objc_class_ro_part(list: TAsmList; objclss: tobjectdef; protolistsym: TAsmSymbol; out classrolabel: TAsmSymbol; metaclass: boolean);
  79. procedure addclasslist(list: tasmlist; section: tasmsectiontype; const symname: string; classes: tfpobjectlist);
  80. procedure gen_objc_ivars(list: TAsmList; objccls: tobjectdef; out ivarslabel: TAsmLabel);
  81. procedure gen_objc_protocol(list:TAsmList; protocol: tobjectdef; out protocollabel: TAsmSymbol);override;
  82. procedure gen_objc_category_sections(list:TAsmList; objccat: tobjectdef; out catlabel: TAsmSymbol);override;
  83. procedure gen_objc_classes_sections(list:TAsmList; objclss: tobjectdef; out classlabel: TAsmSymbol);override;
  84. procedure gen_objc_info_sections(list: tasmlist);override;
  85. public
  86. constructor create;
  87. end;
  88. {******************************************************************
  89. Protocol declaration helpers
  90. *******************************************************************}
  91. function objcfindprotocolentry(const p: shortstring): TAsmSymbol;
  92. var
  93. item : PHashSetItem;
  94. begin
  95. result:=nil;
  96. if not assigned(current_asmdata.ConstPools[sp_objcprotocolrefs]) then
  97. exit;
  98. item:=current_asmdata.constpools[sp_objcprotocolrefs].Find(@p[1], length(p));
  99. if not assigned(item) then
  100. exit;
  101. result:=TAsmSymbol(item^.Data);
  102. end;
  103. function objcaddprotocolentry(const p: shortstring; ref: TAsmSymbol): Boolean;
  104. var
  105. item : PHashSetItem;
  106. begin
  107. item:=current_asmdata.constpools[sp_objcprotocolrefs].FindOrAdd(@p[1], length(p));
  108. Result:=(item^.Data=nil);
  109. if Result then
  110. item^.Data:=ref;
  111. end;
  112. {******************************************************************
  113. Pool section helpers
  114. *******************************************************************}
  115. function objcreatestringpoolentryintern(p: pchar; len: longint; pooltype: tconstpooltype; stringsec: tasmsectiontype): TAsmSymbol;
  116. var
  117. entry : PHashSetItem;
  118. strlab : tasmlabel;
  119. pc : pchar;
  120. pool : THashSet;
  121. begin
  122. pool := current_asmdata.constpools[pooltype];
  123. entry:=pool.FindOrAdd(p,len);
  124. if not assigned(entry^.data) then
  125. begin
  126. { create new entry }
  127. current_asmdata.getlabel(strlab,alt_data);
  128. entry^.Data:=strlab;
  129. getmem(pc,entry^.keylength+1);
  130. move(entry^.key^,pc^,entry^.keylength);
  131. pc[entry^.keylength]:=#0;
  132. { add the string to the approriate section }
  133. new_section(current_asmdata.asmlists[al_objc_pools],stringsec,strlab.name,0);
  134. current_asmdata.asmlists[al_objc_pools].concat(Tai_label.Create(strlab));
  135. current_asmdata.asmlists[al_objc_pools].concat(Tai_string.Create_pchar(pc,entry^.keylength+1));
  136. Result := strlab;
  137. end
  138. else
  139. Result := TAsmLabel(Entry^.Data);
  140. end;
  141. procedure objcfinishstringrefpoolentry(entry: phashsetitem; stringpool: tconstpooltype; refsec, stringsec: tasmsectiontype);
  142. var
  143. reflab : tasmlabel;
  144. strlab : tasmsymbol;
  145. classname: string;
  146. begin
  147. { have we already generated a reference for this string entry? }
  148. if not assigned(entry^.Data) then
  149. begin
  150. { no, add the string to the associated strings section }
  151. strlab:=objcreatestringpoolentryintern(pchar(entry^.key),entry^.keylength,stringpool,stringsec);
  152. { and now finish the reference }
  153. current_asmdata.getlabel(reflab,alt_data);
  154. entry^.Data:=reflab;
  155. { add a pointer to the string in the string references section }
  156. new_section(current_asmdata.asmlists[al_objc_pools],refsec,reflab.name,sizeof(pint));
  157. current_asmdata.asmlists[al_objc_pools].concat(Tai_label.Create(reflab));
  158. current_asmdata.asmlists[al_objc_pools].concat(Tai_const.Create_sym(strlab));
  159. { in case of a class reference, also add a lazy symbol reference for
  160. the class (the linker requires this for the fragile ABI). }
  161. if (refsec=sec_objc_cls_refs) and
  162. not(target_info.system in systems_objc_nfabi) then
  163. begin
  164. setlength(classname,entry^.keylength);
  165. move(entry^.key^,classname[1],entry^.keylength);
  166. current_asmdata.asmlists[al_objc_pools].concat(tai_directive.Create(asd_lazy_reference,'.objc_class_name_'+classname));
  167. end;
  168. end;
  169. end;
  170. function objcreatestringpoolentry(const s: string; pooltype: tconstpooltype; stringsec: tasmsectiontype): TAsmSymbol;
  171. begin
  172. result:=objcreatestringpoolentryintern(@s[1],length(s),pooltype,stringsec);
  173. end;
  174. procedure objcfinishclassrefnfpoolentry(entry: phashsetitem; classdef: tobjectdef);
  175. var
  176. reflab: TAsmLabel;
  177. classym: TasmSymbol;
  178. begin
  179. { have we already generated a reference for this class ref entry? }
  180. if not assigned(entry^.Data) then
  181. begin
  182. { no, add the classref to the sec_objc_cls_refs section }
  183. current_asmdata.getlabel(reflab,alt_data);
  184. entry^.Data:=reflab;
  185. { add a pointer to the class }
  186. new_section(current_asmdata.asmlists[al_objc_pools],sec_objc_cls_refs,reflab.name,sizeof(pint));
  187. current_asmdata.asmlists[al_objc_pools].concat(Tai_label.Create(reflab));
  188. classym:=current_asmdata.RefAsmSymbol(classdef.rtti_mangledname(objcclassrtti));
  189. current_asmdata.asmlists[al_objc_pools].concat(Tai_const.Create_sym(classym));
  190. end;
  191. end;
  192. {******************************************************************
  193. RTTI generation -- Helpers
  194. *******************************************************************}
  195. procedure ConcatSymOrNil(list: tasmlist; sym: TAsmSymbol); inline;
  196. begin
  197. if Assigned(sym) then
  198. list.Concat(tai_const.Create_sym(sym))
  199. else
  200. list.Concat(tai_const.Create_pint(0));
  201. end;
  202. {******************************************************************
  203. RTTI generation -- Common
  204. *******************************************************************}
  205. { generate a method list, either of class methods or of instance methods,
  206. and both for obj-c classes and categories. }
  207. procedure tobjcrttiwriter.gen_objc_methods(list: tasmlist; objccls: tobjectdef; out methodslabel: tasmlabel; classmethods, iscategory: Boolean);
  208. const
  209. clsSectType : array [Boolean] of tasmsectiontype = (sec_objc_inst_meth, sec_objc_cls_meth);
  210. clsSectName : array [Boolean] of string = ('_OBJC_INST_METH','_OBJC_CLS_METH');
  211. catSectType : array [Boolean] of tasmsectiontype = (sec_objc_cat_inst_meth, sec_objc_cat_cls_meth);
  212. catSectName : array [Boolean] of string = ('_OBJC_CAT_INST_METH','_OBJC_CAT_CLS_METH');
  213. type
  214. method_data = record
  215. def : tprocdef;
  216. selsym : TAsmSymbol;
  217. encsym : TAsmSymbol;
  218. end;
  219. var
  220. i : Integer;
  221. def : tprocdef;
  222. defs : array of method_data;
  223. mcnt : integer;
  224. sym : tasmsymbol;
  225. mtype : tdef;
  226. begin
  227. methodslabel:=nil;
  228. mcnt:=0;
  229. { collect all instance/class methods }
  230. SetLength(defs,objccls.vmtentries.count);
  231. for i:=0 to objccls.vmtentries.count-1 do
  232. begin
  233. def:=pvmtentry(objccls.vmtentries[i])^.procdef;
  234. if (def.owner.defowner=objccls) and
  235. (classmethods = (po_classmethod in def.procoptions)) then
  236. begin
  237. defs[mcnt].def:=def;
  238. defs[mcnt].selsym:=objcreatestringpoolentry(def.messageinf.str^,sp_objcvarnames,sec_objc_meth_var_names);
  239. defs[mcnt].encsym:=objcreatestringpoolentry(objcencodemethod(def),sp_objcvartypes,sec_objc_meth_var_types);
  240. inc(mcnt);
  241. end;
  242. end;
  243. if mcnt=0 then
  244. exit;
  245. if iscategory then
  246. new_section(list,catSectType[classmethods],catSectName[classmethods],sizeof(ptrint))
  247. else
  248. new_section(list,clsSectType[classmethods],clsSectName[classmethods],sizeof(ptrint));
  249. current_asmdata.getlabel(methodslabel,alt_data);
  250. list.Concat(tai_label.Create(methodslabel));
  251. if (abi=oa_fragile) then
  252. { not used, always zero }
  253. list.Concat(tai_const.Create_32bit(0))
  254. else
  255. begin
  256. { size of each entry -- always 32 bit value }
  257. mtype:=search_named_unit_globaltype('OBJC','OBJC_METHOD',true).typedef;
  258. list.Concat(tai_const.Create_32bit(mtype.size));
  259. end;
  260. { number of objc_method entries in the method_list array -- always 32 bit}
  261. list.Concat(tai_const.Create_32bit(mcnt));
  262. for i:=0 to mcnt-1 do
  263. begin
  264. { reference to the selector name }
  265. list.Concat(tai_const.Create_sym(defs[i].selsym));
  266. { reference to the obj-c encoded function parameters (signature) }
  267. list.Concat(tai_const.Create_sym(defs[i].encsym));
  268. { mangled name of the method }
  269. sym:=current_asmdata.GetAsmSymbol(defs[i].def.mangledname);
  270. if not assigned(sym) then
  271. internalerror(2009091601);
  272. list.Concat(tai_const.Create_sym(sym));
  273. end;
  274. end;
  275. { generate method (and in the future also property) info for protocols }
  276. procedure tobjcrttiwriter.gen_objc_protocol_elements(list: tasmlist; protocol: tobjectdef; out reqinstsym, optinstsym, reqclssym, optclssym: TAsmLabel);
  277. var
  278. proc : tprocdef;
  279. reqinstmlist,
  280. reqclsmlist,
  281. optinstmlist,
  282. optclsmlist : TFPObjectList;
  283. i : ptrint;
  284. begin
  285. reqinstmlist:=TFPObjectList.Create(false);
  286. reqclsmlist:=TFPObjectList.Create(false);
  287. optinstmlist:=TFPObjectList.Create(false);
  288. optclsmlist:=TFPObjectList.Create(false);
  289. for i:=0 to protocol.vmtentries.Count-1 do
  290. begin
  291. proc:=pvmtentry(protocol.vmtentries[i])^.procdef;
  292. if (po_classmethod in proc.procoptions) then
  293. if not(po_optional in proc.procoptions) then
  294. reqclsmlist.Add(proc)
  295. else
  296. optclsmlist.Add(proc)
  297. else if not(po_optional in proc.procoptions) then
  298. reqinstmlist.Add(proc)
  299. else
  300. optinstmlist.Add(proc);
  301. end;
  302. if reqinstmlist.Count > 0 then
  303. gen_objc_cat_methods(list,reqinstmlist,sec_objc_cat_inst_meth,'_OBJC_CAT_INST_METH',reqinstsym)
  304. else
  305. reqinstsym:=nil;
  306. if optinstmlist.Count > 0 then
  307. gen_objc_cat_methods(list,optinstmlist,sec_objc_cat_inst_meth,'_OBJC_CAT_INST_METH',optinstsym)
  308. else
  309. optinstsym:=nil;
  310. if reqclsmlist.Count>0 then
  311. gen_objc_cat_methods(list,reqclsmlist,sec_objc_cat_cls_meth,'_OBJC_CAT_CLS_METH',reqclssym)
  312. else
  313. reqclssym:=nil;
  314. if optclsmlist.Count>0 then
  315. gen_objc_cat_methods(list,optclsmlist,sec_objc_cat_cls_meth,'_OBJC_CAT_CLS_METH',optclssym)
  316. else
  317. optclssym:=nil;
  318. reqinstmlist.Free;
  319. reqclsmlist.Free;
  320. optinstmlist.Free;
  321. optclsmlist.Free;
  322. end;
  323. (*
  324. From CLang:
  325. struct objc_protocol_list
  326. {
  327. #ifdef FRAGILE_ABI
  328. struct objc_protocol_list *next;
  329. int count;
  330. #else
  331. long count;
  332. #endif
  333. Protocol *list[1];
  334. };
  335. *)
  336. procedure tobjcrttiwriter.gen_objc_protocol_list(list: tasmlist; protolist: tfpobjectlist; out protolistsym: tasmlabel);
  337. var
  338. i : Integer;
  339. protosym : TAsmSymbol;
  340. protodef : tobjectdef;
  341. begin
  342. if not Assigned(protolist) or
  343. (protolist.Count=0) then
  344. begin
  345. protolistsym:=nil;
  346. Exit;
  347. end;
  348. for i:=0 to protolist.Count-1 do
  349. begin
  350. protodef:=TImplementedInterface(protolist[i]).IntfDef;
  351. protosym:=objcfindprotocolentry(protodef.objextname^);
  352. if not assigned(protosym) then
  353. begin
  354. gen_objc_protocol(list,protodef,protosym);
  355. objcaddprotocolentry(protodef.objextname^,protosym);
  356. end;
  357. end;
  358. { protocol lists are stored in .objc_cat_cls_meth section }
  359. new_section(list,sec_objc_cat_cls_meth,'_OBJC_PROTOCOLLIST',sizeof(pint));
  360. current_asmdata.getlabel(protolistsym, alt_data);
  361. list.Concat(tai_label.Create(protolistsym));
  362. if (abi=oa_fragile) then
  363. { From Clang: next, always nil}
  364. list.Concat(tai_const.Create_pint(0));
  365. { From Clang: protocols count}
  366. list.Concat(Tai_const.Create_pint(protolist.Count));
  367. for i:=0 to protolist.Count-1 do
  368. begin
  369. protodef:=(protolist[i] as TImplementedInterface).IntfDef;
  370. protosym:=objcfindprotocolentry(protodef.objextname^);
  371. if not Assigned(protosym) then
  372. begin
  373. { For some reason protosym is not declared, though must be!
  374. Probably gen_obcj1_protocol returned wrong protosym
  375. }
  376. InternalError(2009091602);
  377. end;
  378. list.Concat(tai_const.Create_sym(protosym));
  379. end;
  380. end;
  381. { Generate rtti for an Objective-C methods (methods without implementation) }
  382. { items : TFPObjectList of Tprocdef }
  383. procedure tobjcrttiwriter.gen_objc_cat_methods(list:TAsmList; items: TFPObjectList; section: tasmsectiontype;
  384. const sectname: string; out listsym: TAsmLabel);
  385. var
  386. i : integer;
  387. m : tprocdef;
  388. mtype : tdef;
  389. begin
  390. if not assigned(items) or
  391. (items.count=0) then
  392. exit;
  393. new_section(list, section, sectname, sizeof(pint));
  394. current_asmdata.getlabel(listsym,alt_data);
  395. list.Concat(tai_label.Create(listsym));
  396. if (abi=oa_nonfragile) then
  397. begin
  398. { size of each entry -- always 32 bit value }
  399. mtype:=search_named_unit_globaltype('OBJC','OBJC_METHOD',true).typedef;
  400. list.Concat(tai_const.Create_32bit(mtype.size));
  401. end;
  402. list.Concat(Tai_const.Create_32bit(items.count));
  403. for i:=0 to items.Count-1 do
  404. begin
  405. m:=tprocdef(items[i]);
  406. list.Concat(Tai_const.Create_sym(
  407. objcreatestringpoolentry(m.messageinf.str^,sp_objcvarnames,sec_objc_meth_var_names)));
  408. list.Concat(Tai_const.Create_sym(
  409. objcreatestringpoolentry(objcencodemethod(m),sp_objcvartypes,sec_objc_meth_var_types)));
  410. { placeholder for address of implementation? }
  411. if (abi=oa_nonfragile) then
  412. list.Concat(Tai_const.Create_pint(0));
  413. end;
  414. end;
  415. { Generate the rtti sections for all obj-c classes defined in st, and return
  416. these classes in the classes list. }
  417. procedure tobjcrttiwriter.gen_objc_rtti_sections(list:TAsmList; st:TSymtable);
  418. var
  419. i: longint;
  420. def: tdef;
  421. sym : TAsmSymbol;
  422. begin
  423. if not Assigned(st) then
  424. exit;
  425. for i:=0 to st.DefList.Count-1 do
  426. begin
  427. def:=tdef(st.DefList[i]);
  428. { check whether all types used in Objective-C class/protocol/category
  429. declarations can be used with the Objective-C run time (can only be
  430. done now, because at parse-time some of these types can still be
  431. forwarddefs) }
  432. if is_objc_class_or_protocol(def) then
  433. if not tobjectdef(def).check_objc_types then
  434. continue;
  435. if is_objcclass(def) and
  436. not(oo_is_external in tobjectdef(def).objectoptions) then
  437. begin
  438. if not(oo_is_classhelper in tobjectdef(def).objectoptions) then
  439. begin
  440. gen_objc_classes_sections(list,tobjectdef(def),sym);
  441. classsyms.add(sym);
  442. classdefs.add(def);
  443. end
  444. else
  445. begin
  446. gen_objc_category_sections(list,tobjectdef(def),sym);
  447. catsyms.add(sym);
  448. catdefs.add(def);
  449. end
  450. end;
  451. end;
  452. end;
  453. constructor tobjcrttiwriter.create(_abi: tobjcabi);
  454. begin
  455. fabi:=_abi;
  456. classdefs:=tfpobjectlist.create(false);
  457. classsyms:=tfpobjectlist.create(false);
  458. catdefs:=tfpobjectlist.create(false);
  459. catsyms:=tfpobjectlist.create(false);
  460. end;
  461. destructor tobjcrttiwriter.destroy;
  462. begin
  463. classdefs.free;
  464. classsyms.free;
  465. catdefs.free;
  466. catsyms.free;
  467. inherited destroy;
  468. end;
  469. {******************************************************************
  470. RTTI generation -- Fragile ABI
  471. *******************************************************************}
  472. { generate an instance variables list for an obj-c class. }
  473. procedure tobjcrttiwriter_fragile.gen_objc_ivars(list: TAsmList; objccls: tobjectdef; out ivarslabel: TAsmLabel);
  474. type
  475. ivar_data = record
  476. vf : tfieldvarsym;
  477. namesym : TAsmSymbol;
  478. typesym : TAsmSymbol;
  479. end;
  480. var
  481. i : integer;
  482. vf : tfieldvarsym;
  483. vars : array of ivar_data;
  484. vcnt : Integer;
  485. enctype : ansistring;
  486. encerr : tdef;
  487. begin
  488. ivarslabel:=nil;
  489. vcnt:=0;
  490. setLength(vars,objccls.symtable.SymList.Count);
  491. for i:=0 to objccls.symtable.SymList.Count-1 do
  492. if tsym(objccls.symtable.SymList[i]).typ=fieldvarsym then
  493. begin
  494. vf:=tfieldvarsym(objccls.symtable.SymList[i]);
  495. if objctryencodetype(vf.vardef,enctype,encerr) then
  496. begin
  497. vars[vcnt].vf:=vf;
  498. vars[vcnt].namesym:=objcreatestringpoolentry(vf.RealName,sp_objcvarnames,sec_objc_meth_var_names);
  499. vars[vcnt].typesym:=objcreatestringpoolentry(enctype,sp_objcvartypes,sec_objc_meth_var_types);
  500. inc(vcnt);
  501. end
  502. else
  503. { Should be caught during parsing }
  504. internalerror(2009090601);
  505. end;
  506. if vcnt=0 then
  507. exit;
  508. new_section(list,sec_objc_instance_vars,'_OBJC_INSTANCE_VARS',sizeof(pint));
  509. current_asmdata.getlabel(ivarslabel,alt_data);
  510. list.Concat(tai_label.Create(ivarslabel));
  511. { objc_ivar_list: first the number of elements }
  512. list.Concat(tai_const.Create_32bit(vcnt));
  513. for i:=0 to vcnt-1 do
  514. begin
  515. { reference to the instance variable name }
  516. list.Concat(tai_const.Create_sym(vars[i].namesym));
  517. { reference to the encoded type }
  518. list.Concat(tai_const.Create_sym(vars[i].typesym));
  519. { and the offset of the field }
  520. list.Concat(tai_const.Create_32bit(vars[i].vf.fieldoffset));
  521. end;
  522. end;
  523. (* From GCC:
  524. struct _objc_protocol_extension
  525. {
  526. uint32_t size; // sizeof (struct _objc_protocol_extension)
  527. struct objc_method_list *optional_instance_methods;
  528. struct objc_method_list *optional_class_methods;
  529. struct objc_prop_list *instance_properties;
  530. }
  531. *)
  532. function tobjcrttiwriter_fragile.gen_objc_protocol_ext(list: TAsmList; optinstsym, optclssym: TAsmLabel): TAsmLabel;
  533. begin
  534. if assigned(optinstsym) or
  535. assigned(optclssym) then
  536. begin
  537. new_section(list, sec_objc_protocol_ext,'_OBJC_PROTOCOLEXT',sizeof(pint));
  538. current_asmdata.getlabel(Result,alt_data);
  539. list.Concat(tai_label.Create(Result));
  540. { size of this structure }
  541. list.Concat(Tai_const.Create_32bit(16));
  542. { optional instance methods }
  543. ConcatSymOrNil(list,optinstsym);
  544. { optional class methods }
  545. ConcatSymOrNil(list,optclssym);
  546. { optional properties (todo) }
  547. ConcatSymOrNil(list,nil);
  548. end
  549. else
  550. Result:=nil;
  551. end;
  552. { Generate rtti for an Objective-C protocol }
  553. procedure tobjcrttiwriter_fragile.gen_objc_protocol(list:TAsmList; protocol: tobjectdef; out protocollabel: TAsmSymbol);
  554. var
  555. namesym : TAsmSymbol;
  556. protolist : TAsmLabel;
  557. reqinstsym,
  558. optinstsym,
  559. reqclssym,
  560. optclssym,
  561. protoext,
  562. lbl : TAsmLabel;
  563. begin
  564. gen_objc_protocol_list(list,protocol.ImplementedInterfaces,protolist);
  565. gen_objc_protocol_elements(list,protocol,reqinstsym,optinstsym,reqclssym,optclssym);
  566. protoext:=gen_objc_protocol_ext(list,optinstsym,optclssym);
  567. new_section(list, sec_objc_protocol,'_OBJC_PROTOCOL',sizeof(pint));
  568. current_asmdata.getlabel(lbl,alt_data);
  569. list.Concat(tai_label.Create(lbl));
  570. protocollabel:=lbl;
  571. { protocol's isa - points to information about optional methods/properties }
  572. ConcatSymOrNil(list,protoext);
  573. { name }
  574. namesym:=objcreatestringpoolentry(protocol.objextname^,sp_objcclassnames,sec_objc_class_names);
  575. list.Concat(Tai_const.Create_sym(namesym));
  576. { protocol's list }
  577. ConcatSymOrNil(list,protolist);
  578. { instance methods, in __cat_inst_meth }
  579. ConcatSymOrNil(list,reqinstsym);
  580. { class methods, in __cat_cls_meth }
  581. ConcatSymOrNil(list,reqclssym);
  582. end;
  583. (*
  584. From Clang:
  585. struct _objc_category {
  586. char *category_name;
  587. char *class_name;
  588. struct _objc_method_list *instance_methods;
  589. struct _objc_method_list *class_methods;
  590. struct _objc_protocol_list *protocols;
  591. uint32_t size; // <rdar://4585769>
  592. struct _objc_property_list *instance_properties;
  593. };
  594. *)
  595. { Generate rtti for an Objective-C class and its meta-class. }
  596. procedure tobjcrttiwriter_fragile.gen_objc_category_sections(list:TAsmList; objccat: tobjectdef; out catlabel: TAsmSymbol);
  597. var
  598. instmthdlist,
  599. clsmthdlist,
  600. protolistsym : TAsmLabel;
  601. catstrsym,
  602. clsstrsym,
  603. catsym : TAsmSymbol;
  604. begin
  605. { the category name }
  606. catstrsym:=objcreatestringpoolentry(objccat.objextname^,sp_objcclassnames,sec_objc_class_names);
  607. { the name of the class it extends }
  608. clsstrsym:=objcreatestringpoolentry(objccat.childof.objextname^,sp_objcclassnames,sec_objc_class_names);
  609. { generate the methods lists }
  610. gen_objc_methods(list,objccat,instmthdlist,false,true);
  611. gen_objc_methods(list,objccat,clsmthdlist,true,true);
  612. { generate implemented protocols list }
  613. gen_objc_protocol_list(list,objccat.ImplementedInterfaces,protolistsym);
  614. { category declaration section }
  615. new_section(list,sec_objc_category,'_OBJC_CATEGORY',sizeof(pint));
  616. catsym:=current_asmdata.DefineAsmSymbol(objccat.rtti_mangledname(objcclassrtti),AB_LOCAL,AT_DATA);
  617. list.Concat(tai_symbol.Create(catsym,0));
  618. list.Concat(Tai_const.Create_sym(catstrsym));
  619. list.Concat(Tai_const.Create_sym(clsstrsym));
  620. ConcatSymOrNil(list,instmthdlist);
  621. ConcatSymOrNil(list,clsmthdlist);
  622. ConcatSymOrNil(list,protolistsym);
  623. { size of this structure }
  624. list.Concat(Tai_const.Create_32bit(28));
  625. { properties, not yet supported }
  626. list.Concat(Tai_const.Create_32bit(0));
  627. catlabel:=catsym;
  628. end;
  629. (*
  630. From Clang:
  631. struct _objc_class {
  632. Class isa;
  633. Class super_class;
  634. const char *name;
  635. long version;
  636. long info;
  637. long instance_size;
  638. struct _objc_ivar_list *ivars;
  639. struct _objc_method_list *methods;
  640. struct _objc_cache *cache;
  641. struct _objc_protocol_list *protocols;
  642. // Objective-C 1.0 extensions (<rdr://4585769>) -- for garbage collection
  643. const char *ivar_layout;
  644. struct _objc_class_ext *ext;
  645. };
  646. *)
  647. { Generate rtti for an Objective-C class and its meta-class. }
  648. procedure tobjcrttiwriter_fragile.gen_objc_classes_sections(list:TAsmList; objclss: tobjectdef; out classlabel: TAsmSymbol);
  649. const
  650. CLS_CLASS = 1;
  651. CLS_META = 2;
  652. CLS_HIDDEN = $20000;
  653. META_INST_SIZE = 40+8; // sizeof(objc_class) + 8
  654. var
  655. root : tobjectdef;
  656. superStrSym,
  657. classStrSym,
  658. metaisaStrSym,
  659. metasym,
  660. clssym : TAsmSymbol;
  661. mthdlist,
  662. ivarslist,
  663. protolistsym : TAsmLabel;
  664. hiddenflag : cardinal;
  665. begin
  666. { generate the class methods list }
  667. gen_objc_methods(list,objclss,mthdlist,true,false);
  668. { generate implemented protocols list }
  669. gen_objc_protocol_list(list,objclss.ImplementedInterfaces,protolistsym);
  670. { register necessary names }
  671. { 1) the superclass }
  672. if assigned(objclss.childof) then
  673. superStrSym:=objcreatestringpoolentry(objclss.childof.objextname^,sp_objcclassnames,sec_objc_class_names)
  674. else
  675. { not empty string, but nil! }
  676. superStrSym:=nil;
  677. { 2) the current class }
  678. classStrSym:=objcreatestringpoolentry(objclss.objextname^,sp_objcclassnames,sec_objc_class_names);
  679. { 3) the isa }
  680. { From Clang: The isa for the meta-class is the root of the hierarchy. }
  681. root:=objclss;
  682. while assigned(root.childof) do
  683. root:=root.childof;
  684. metaisaStrSym:=objcreatestringpoolentry(root.objextname^,sp_objcclassnames,sec_objc_class_names);
  685. { 4) the flags }
  686. { consider every class declared in the implementation section of a unit
  687. as "hidden"
  688. }
  689. hiddenflag:=0;
  690. if (objclss.owner.symtabletype=staticsymtable) and
  691. current_module.is_unit then
  692. hiddenflag:=CLS_HIDDEN;
  693. { class declaration section }
  694. new_section(list,sec_objc_meta_class,'_OBJC_META_CLASS',sizeof(pint));
  695. { 1) meta-class declaration }
  696. metasym:=current_asmdata.DefineAsmSymbol(objclss.rtti_mangledname(objcmetartti),AB_LOCAL,AT_DATA);
  697. list.Concat(tai_symbol.Create(metasym,0));
  698. list.Concat(Tai_const.Create_sym(metaisaStrSym));
  699. { pointer to the superclass name if any, otherwise nil }
  700. if assigned(superstrsym) then
  701. list.Concat(Tai_const.Create_sym(superStrSym))
  702. else
  703. list.concat(tai_const.create_32bit(0));
  704. { pointer to the class name }
  705. list.Concat(Tai_const.Create_sym(classStrSym));
  706. { version is always 0 currently }
  707. list.Concat(Tai_const.Create_32bit(0));
  708. { CLS_META for meta-classes }
  709. list.Concat(Tai_const.Create_32bit(hiddenflag or CLS_META));
  710. { size of the meta-class instance: sizeof(objc_class) + 8 bytes }
  711. list.Concat(Tai_const.Create_32bit(META_INST_SIZE) );
  712. { meta-classes don't have ivars list (=0) }
  713. list.Concat(Tai_const.Create_32bit(0));
  714. { class methods list (stored in "__cls_meth" section) }
  715. if Assigned(mthdlist) then
  716. list.Concat(Tai_const.Create_sym(mthdlist))
  717. else
  718. list.Concat(Tai_const.Create_32bit(0));
  719. { From Clang: cache is always nil }
  720. list.Concat(Tai_const.Create_32bit(0));
  721. { protocols }
  722. ConcatSymOrNil(list, protolistsym);
  723. { From Clang: ivar_layout for meta-class is always NULL. }
  724. list.Concat(Tai_const.Create_32bit(0));
  725. { From Clang: The class extension is always unused for meta-classes. }
  726. list.Concat(Tai_const.Create_32bit(0));
  727. { 2) regular class declaration }
  728. { generate the instance methods list }
  729. gen_objc_methods(list,objclss,mthdlist,false,false);
  730. { generate the instance variables list }
  731. gen_objc_ivars(list,objclss,ivarslist);
  732. new_section(list,sec_objc_class,'_OBJC_CLASS',sizeof(pint));
  733. clssym:=current_asmdata.DefineAsmSymbol(objclss.rtti_mangledname(objcclassrtti),AB_LOCAL,AT_DATA);
  734. list.Concat(tai_symbol.Create(clssym,0));
  735. { for class declaration: the isa points to the meta-class declaration }
  736. list.Concat(Tai_const.Create_sym(metasym));
  737. { pointer to the super_class name if any, nil otherwise }
  738. if assigned(superStrSym) then
  739. list.Concat(Tai_const.Create_sym(superStrSym))
  740. else
  741. list.Concat(Tai_const.Create_32bit(0));
  742. { pointer to the class name }
  743. list.Concat(Tai_const.Create_sym(classStrSym));
  744. { version is always 0 currently }
  745. list.Concat(Tai_const.Create_32bit(0));
  746. { CLS_CLASS for classes }
  747. list.Concat(Tai_const.Create_32bit(hiddenflag or CLS_CLASS));
  748. { size of instance: total size of instance variables }
  749. list.Concat(Tai_const.Create_32bit(tobjectsymtable(objclss.symtable).datasize));
  750. { objc_ivar_list (stored in "__instance_vars" section) }
  751. if assigned(ivarslist) then
  752. list.Concat(Tai_const.Create_sym(ivarslist))
  753. else
  754. list.Concat(tai_const.create_32bit(0));
  755. { instance methods list (stored in "__inst_meth" section) }
  756. if Assigned(mthdlist) then
  757. list.Concat(Tai_const.Create_sym(mthdlist))
  758. else
  759. list.Concat(Tai_const.Create_32bit(0));
  760. { From Clang: cache is always NULL }
  761. list.Concat(Tai_const.Create_32bit(0));
  762. { protocols, protolistsym has been created for meta-class, no need to create another one}
  763. ConcatSymOrNil(list, protolistsym);
  764. { TODO: From Clang: strong ivar_layout, necessary for garbage collection support }
  765. list.Concat(Tai_const.Create_32bit(0));
  766. { TODO: From Clang: weak ivar_layout, necessary for garbage collection support }
  767. list.Concat(Tai_const.Create_32bit(0));
  768. classlabel:=clssym;
  769. end;
  770. { Generate the global information sections (objc_symbols and objc_module_info)
  771. for this module. }
  772. procedure tobjcrttiwriter_fragile.gen_objc_info_sections(list: tasmlist);
  773. var
  774. i: longint;
  775. sym : TAsmSymbol;
  776. parent: tobjectdef;
  777. superclasses: tfpobjectlist;
  778. begin
  779. if (classsyms.count<>0) or
  780. (catsyms.count<>0) then
  781. begin
  782. new_section(list,sec_objc_symbols,'_OBJC_SYMBOLS',sizeof(pint));
  783. sym := current_asmdata.DefineAsmSymbol(target_asm.labelprefix+'_OBJC_SYMBOLS_$',AB_LOCAL,AT_DATA);
  784. { symbol to refer to this information }
  785. list.Concat(tai_symbol.Create(sym,0));
  786. { ??? (always 0 in Clang) }
  787. list.Concat(Tai_const.Create_pint(0));
  788. { ??? (From Clang: always 0, pointer to some selector) }
  789. list.Concat(Tai_const.Create_pint(0));
  790. { From Clang: number of defined classes }
  791. list.Concat(Tai_const.Create_16bit(classsyms.count));
  792. { From Clang: number of defined categories }
  793. list.Concat(Tai_const.Create_16bit(catsyms.count));
  794. { first all classes }
  795. for i:=0 to classsyms.count-1 do
  796. list.Concat(Tai_const.Create_sym(tasmsymbol(classsyms[i])));
  797. { then all categories }
  798. for i:=0 to catsyms.count-1 do
  799. list.Concat(Tai_const.Create_sym(tasmsymbol(catsyms[i])));
  800. end
  801. else
  802. sym:=nil;
  803. new_section(list,sec_objc_module_info,'_OBJC_MODULE_INFO',4);
  804. { version number = 7 (always, both for gcc and clang) }
  805. list.Concat(Tai_const.Create_pint(7));
  806. { sizeof(objc_module): 4 pointer-size entities }
  807. list.Concat(Tai_const.Create_pint(sizeof(pint)*4));
  808. { used to be file name, now unused (points to empty string) }
  809. list.Concat(Tai_const.Create_sym(objcreatestringpoolentry('',sp_objcclassnames,sec_objc_class_names)));
  810. { pointer to classes/categories list declared in this module }
  811. if assigned(sym) then
  812. list.Concat(Tai_const.Create_sym(sym))
  813. else
  814. list.concat(tai_const.create_pint(0));
  815. { Add lazy references to parent classes of all classes defined in this unit }
  816. superclasses:=tfpobjectlist.create(false);
  817. for i:=0 to classdefs.count-1 do
  818. begin
  819. parent:=tobjectdef(classdefs[i]).childof;
  820. { warning: linear search, performance hazard if large number of subclasses }
  821. if assigned(parent) and
  822. (superclasses.indexof(parent)=-1) then
  823. begin
  824. list.concat(tai_directive.create(asd_lazy_reference,'.objc_class_name_'+parent.objextname^));
  825. superclasses.add(parent);
  826. end;
  827. end;
  828. for i:=0 to catdefs.count-1 do
  829. begin
  830. parent:=tobjectdef(catdefs[i]).childof;
  831. { warning: linear search, performance hazard if large number of subclasses }
  832. if assigned(parent) and
  833. (superclasses.indexof(parent)=-1) then
  834. begin
  835. list.concat(tai_directive.create(asd_lazy_reference,'.objc_class_name_'+parent.objextname^));
  836. superclasses.add(parent);
  837. end;
  838. end;
  839. superclasses.free;
  840. { reference symbols for all classes and categories defined in this unit }
  841. for i:=0 to classdefs.count-1 do
  842. list.concat(tai_symbol.Createname_global_value('.objc_class_name_'+tobjectdef(classdefs[i]).objextname^,AT_DATA,0,0));
  843. for i:=0 to catdefs.count-1 do
  844. list.concat(tai_symbol.Createname_global_value('.objc_category_name_'+
  845. tobjectdef(catdefs[i]).childof.objextname^+'_'+
  846. tobjectdef(catdefs[i]).objextname^,AT_DATA,0,0));
  847. end;
  848. constructor tobjcrttiwriter_fragile.create;
  849. begin
  850. inherited create(oa_fragile);
  851. end;
  852. {******************************************************************
  853. RTTI generation -- Non-Fragile ABI
  854. *******************************************************************}
  855. (*
  856. From Clang:
  857. /// EmitIvarList - Emit the ivar list for the given
  858. /// implementation. The return value has type
  859. /// IvarListnfABIPtrTy.
  860. /// struct _ivar_t {
  861. /// unsigned long int *offset; // pointer to ivar offset location
  862. /// char *name;
  863. /// char *type;
  864. /// uint32_t alignment;
  865. /// uint32_t size;
  866. /// }
  867. /// struct _ivar_list_t {
  868. /// uint32 entsize; // sizeof(struct _ivar_t)
  869. /// uint32 count;
  870. /// struct _iver_t list[count];
  871. /// }
  872. ///
  873. *)
  874. procedure tobjcrttiwriter_nonfragile.gen_objc_ivars(list: tasmlist; objccls: tobjectdef; out ivarslabel: tasmlabel);
  875. type
  876. ivar_data = record
  877. vf : tfieldvarsym;
  878. namesym : TAsmSymbol;
  879. typesym : TAsmSymbol;
  880. offssym : TAsmSymbol;
  881. end;
  882. var
  883. ivtype: tdef;
  884. vf : tfieldvarsym;
  885. vars : array of ivar_data;
  886. i : integer;
  887. vcnt : integer;
  888. enctype : ansistring;
  889. encerr : tdef;
  890. prefix : shortstring;
  891. vis : TAsmsymbind;
  892. begin
  893. ivarslabel:=nil;
  894. vcnt:=0;
  895. setLength(vars,objccls.symtable.SymList.Count);
  896. for i:=0 to objccls.symtable.SymList.Count-1 do
  897. if tsym(objccls.symtable.SymList[i]).typ=fieldvarsym then
  898. begin
  899. vf:=tfieldvarsym(objccls.symtable.SymList[i]);
  900. if objctryencodetype(vf.vardef,enctype,encerr) then
  901. begin
  902. vars[vcnt].vf:=vf;
  903. vars[vcnt].namesym:=objcreatestringpoolentry(vf.RealName,sp_objcvarnames,sec_objc_meth_var_names);
  904. vars[vcnt].typesym:=objcreatestringpoolentry(enctype,sp_objcvartypes,sec_objc_meth_var_types);
  905. if (vcnt=0) then
  906. begin
  907. new_section(list,sec_objc_const,'_OBJC_IVAR_OFFSETS',sizeof(pint));
  908. prefix:=target_info.cprefix+'OBJC_IVAR_$_'+objccls.objextname^+'.';
  909. end;
  910. { This matches gcc/Clang, but is strange: I would expect private
  911. fields to be local symbols rather than private_extern (which
  912. is "package-global") (JM)
  913. }
  914. if not(vf.visibility in [vis_public,vis_protected,vis_strictprotected]) then
  915. vis:=AB_PRIVATE_EXTERN
  916. else
  917. vis:=AB_GLOBAL;
  918. vars[vcnt].offssym:=current_asmdata.DefineAsmSymbol(prefix+vf.RealName,vis,AT_DATA);
  919. list.concat(tai_symbol.Create_Global(vars[vcnt].offssym,0));
  920. list.concat(tai_const.create_pint(vf.fieldoffset));
  921. inc(vcnt);
  922. end
  923. else
  924. { must be caught during parsing }
  925. internalerror(2009092301);
  926. end;
  927. if vcnt=0 then
  928. exit;
  929. new_section(list,sec_objc_instance_vars,'_OBJC_INSTANCE_VARS',sizeof(pint));
  930. current_asmdata.getlabel(ivarslabel,alt_data);
  931. list.Concat(tai_label.Create(ivarslabel));
  932. { size of each entry -- always 32 bit value }
  933. ivtype:=search_named_unit_globaltype('OBJC','OBJC_IVAR',true).typedef;
  934. list.concat(tai_const.Create_32bit(ivtype.size));
  935. { number of entries -- always 32 bit value }
  936. list.Concat(tai_const.Create_32bit(vcnt));
  937. for i:=0 to vcnt-1 do
  938. begin
  939. { reference to the offset }
  940. list.Concat(tai_const.Create_sym(vars[i].offssym));
  941. { reference to the instance variable name }
  942. list.Concat(tai_const.Create_sym(vars[i].namesym));
  943. { reference to the encoded type }
  944. list.Concat(tai_const.Create_sym(vars[i].typesym));
  945. { alignment -- always 32 bit value }
  946. list.Concat(tai_const.create_32bit(vars[i].vf.vardef.alignment));
  947. { size -- always 32 bit value }
  948. list.Concat(tai_const.Create_32bit(vars[i].vf.vardef.size));
  949. end;
  950. end;
  951. (*
  952. From Clang:
  953. /// GetOrEmitProtocol - Generate the protocol meta-data:
  954. /// @code
  955. /// struct _protocol_t {
  956. /// id isa; // NULL
  957. /// const char * const protocol_name;
  958. /// const struct _protocol_list_t * protocol_list; // super protocols
  959. /// const struct method_list_t * const instance_methods;
  960. /// const struct method_list_t * const class_methods;
  961. /// const struct method_list_t *optionalInstanceMethods;
  962. /// const struct method_list_t *optionalClassMethods;
  963. /// const struct _prop_list_t * properties;
  964. /// const uint32_t size; // sizeof(struct _protocol_t)
  965. /// const uint32_t flags; // = 0
  966. /// }
  967. /// @endcode
  968. *)
  969. procedure tobjcrttiwriter_nonfragile.gen_objc_protocol(list: tasmlist; protocol: tobjectdef; out protocollabel: tasmsymbol);
  970. var
  971. lbl,
  972. namesym,
  973. listsym : TAsmSymbol;
  974. protolist : TAsmLabel;
  975. reqinstsym,
  976. reqclssym,
  977. optinstsym,
  978. optclssym : TAsmLabel;
  979. prottype : tdef;
  980. begin
  981. gen_objc_protocol_list(list,protocol.ImplementedInterfaces,protolist);
  982. gen_objc_protocol_elements(list,protocol,reqinstsym,optinstsym,reqclssym,optclssym);
  983. new_section(list, sec_data_coalesced,'_OBJC_PROTOCOL',sizeof(pint));
  984. { label for the protocol needs to be
  985. a) in a coalesced section (so multiple definitions of the same protocol
  986. can be merged by the linker)
  987. b) private_extern (should only be merged within the same module)
  988. c) weakly defined (so multiple definitions don't cause errors)
  989. }
  990. lbl:=current_asmdata.DefineAsmSymbol(protocol.rtti_mangledname(objcclassrtti),AB_PRIVATE_EXTERN,AT_DATA);
  991. list.Concat(tai_symbol.Create_Global(lbl,0));
  992. list.Concat(tai_directive.Create(asd_weak_definition,lbl.name));
  993. protocollabel:=lbl;
  994. { protocol's isa - always nil }
  995. list.Concat(Tai_const.Create_pint(0));
  996. { name }
  997. namesym:=objcreatestringpoolentry(protocol.objextname^,sp_objcclassnames,sec_objc_class_names);
  998. list.Concat(Tai_const.Create_sym(namesym));
  999. { parent protocols list }
  1000. ConcatSymOrNil(list,protolist);
  1001. { required instance methods }
  1002. ConcatSymOrNil(list,reqinstsym);
  1003. { required class methods }
  1004. ConcatSymOrNil(list,reqclssym);
  1005. { optional instance methods }
  1006. ConcatSymOrNil(list,optinstsym);
  1007. { optional class methods }
  1008. ConcatSymOrNil(list,optclssym);
  1009. { TODO: properties }
  1010. list.Concat(Tai_const.Create_pint(0));
  1011. { size of this type }
  1012. prottype:=search_named_unit_globaltype('OBJC','OBJC_PROTOCOL',true).typedef;
  1013. list.concat(tai_const.Create_32bit(prottype.size));
  1014. { flags }
  1015. list.concat(tai_const.Create_32bit(0));
  1016. { also add an entry to the __DATA, __objc_protolist section, required to
  1017. register the protocol with the runtime }
  1018. new_section(list, sec_objc_protolist,'_OBJC_PROTOLIST',sizeof(pint));
  1019. listsym:=current_asmdata.DefineAsmSymbol(protocol.rtti_mangledname(objcmetartti),AB_PRIVATE_EXTERN,AT_DATA);
  1020. list.Concat(tai_symbol.Create_Global(listsym,0));
  1021. list.Concat(tai_const.Create_sym(lbl));
  1022. list.Concat(tai_directive.Create(asd_weak_definition,listsym.name));
  1023. end;
  1024. (*
  1025. From Clang:
  1026. /// struct _category_t {
  1027. /// const char * const name;
  1028. /// struct _class_t *const cls;
  1029. /// const struct _method_list_t * const instance_methods;
  1030. /// const struct _method_list_t * const class_methods;
  1031. /// const struct _protocol_list_t * const protocols;
  1032. /// const struct _prop_list_t * const properties;
  1033. /// }
  1034. *)
  1035. procedure tobjcrttiwriter_nonfragile.gen_objc_category_sections(list:TAsmList; objccat: tobjectdef; out catlabel: TAsmSymbol);
  1036. var
  1037. instmthdlist,
  1038. clsmthdlist,
  1039. protolistsym : TAsmLabel;
  1040. catstrsym,
  1041. clssym,
  1042. catsym : TAsmSymbol;
  1043. begin
  1044. { the category name }
  1045. catstrsym:=objcreatestringpoolentry(objccat.objextname^,sp_objcclassnames,sec_objc_class_names);
  1046. { the class it extends }
  1047. clssym:=current_asmdata.RefAsmSymbol(objccat.childof.rtti_mangledname(objcclassrtti));
  1048. { generate the methods lists }
  1049. gen_objc_methods(list,objccat,instmthdlist,false,true);
  1050. gen_objc_methods(list,objccat,clsmthdlist,true,true);
  1051. { generate implemented protocols list }
  1052. gen_objc_protocol_list(list,objccat.ImplementedInterfaces,protolistsym);
  1053. { category declaration section }
  1054. new_section(list,sec_objc_const,'_OBJC_CATEGORY',sizeof(pint));
  1055. catsym:=current_asmdata.DefineAsmSymbol(objccat.rtti_mangledname(objcclassrtti),AB_LOCAL,AT_DATA);
  1056. list.Concat(tai_symbol.Create(catsym,0));
  1057. list.Concat(Tai_const.Create_sym(catstrsym));
  1058. list.Concat(Tai_const.Create_sym(clssym));
  1059. ConcatSymOrNil(list,instmthdlist);
  1060. ConcatSymOrNil(list,clsmthdlist);
  1061. ConcatSymOrNil(list,protolistsym);
  1062. { properties, not yet supported }
  1063. list.Concat(Tai_const.Create_pint(0));
  1064. catlabel:=catsym;
  1065. end;
  1066. (*
  1067. From Clang:
  1068. /// BuildIvarLayout - Builds ivar layout bitmap for the class
  1069. /// implementation for the __strong or __weak case.
  1070. /// The layout map displays which words in ivar list must be skipped
  1071. /// and which must be scanned by GC (see below). String is built of bytes.
  1072. /// Each byte is divided up in two nibbles (4-bit each). Left nibble is count
  1073. /// of words to skip and right nibble is count of words to scan. So, each
  1074. /// nibble represents up to 15 workds to skip or scan. Skipping the rest is
  1075. /// represented by a 0x00 byte which also ends the string.
  1076. /// 1. when ForStrongLayout is true, following ivars are scanned:
  1077. /// - id, Class
  1078. /// - object * // note: this "object" means "Objective-C object" (JM)
  1079. /// - __strong anything
  1080. ///
  1081. /// 2. When ForStrongLayout is false, following ivars are scanned:
  1082. /// - __weak anything
  1083. *)
  1084. (*
  1085. Only required when supporting garbage collection
  1086. procedure tobjcrttiwriter_nonfragile.gen_objc_ivargc_recursive(st: tabstractrecordsymtable; ptrbset: tbitset; startoffset: puint; il: tivarlayouttype);
  1087. var
  1088. i: longint;
  1089. fs: tfieldvarsym;
  1090. includelen: longint;
  1091. begin
  1092. for i:=0 to st.SymList.count-1 do
  1093. if (tsym(st.symlist[i]).typ=fieldvarsym) then
  1094. begin
  1095. fs:=tfieldvarsym(st.symlist[i]);
  1096. includelen:=0;
  1097. case fs.vardef.typ of
  1098. pointerdef,
  1099. classrefdef:
  1100. if (fs.vardef=objc_idtype) or
  1101. (fs.vardef=objc_metaclasstype) then
  1102. includelen:=1;
  1103. recorddef:
  1104. TODO: bitpacking -> offset differences
  1105. gen_objc_ivargc_recursive(tabstractrecordsymtable(trecorddef(fs.vardef).symtable),ptrbset,startoffset+fs.fieldoffset,il);
  1106. arraydef:
  1107. begin
  1108. if not is_special_
  1109. end;
  1110. objectdef :
  1111. begin
  1112. case tobjectdef(fs.vardef).objecttype of
  1113. odt_objcclass,
  1114. odt_objcprotocol:
  1115. includelen:=1;
  1116. odt_object:
  1117. gen_objc_ivargc_recursive(tabstractrecordsymtable(tobjectdef(fs.vardef).symtable),ptrbset,startoffset+fs.fieldoffset,il);
  1118. end;
  1119. end;
  1120. end;
  1121. end;
  1122. end;
  1123. function tobjcrttiwriter_nonfragile.gen_objc_ivargcstring(objclss: tobjectdef; il: tivarlayouttype): ansistring;
  1124. var
  1125. ptrbset: tbitset;
  1126. parent: tobjectdef;
  1127. size,
  1128. startoffset: puint;
  1129. i: longint;
  1130. begin
  1131. size:=tObjectSymtable(objclss.symtable).datasize;
  1132. if assigned(objclss.childof) then
  1133. startoffset:=tObjectSymtable(objclss.childof.symtable).datasize
  1134. else
  1135. startoffset:=0;
  1136. size:=size-startoffset;
  1137. ptrbset:=tbitset.create_bytesize((size+sizeof(ptruint)-1) div sizeof(ptruint));
  1138. { has to include info for this class' fields and those of all parent
  1139. classes as well
  1140. }
  1141. parent:=obclss;
  1142. repeat
  1143. gen_objc_ivargc_recursive(parent.symtable,ptrbset,0,il);
  1144. parent:=parent.childof;
  1145. until not assigned(parent);
  1146. { convert bits set to encoded string }
  1147. end;
  1148. *)
  1149. (*
  1150. From Clang:
  1151. /// struct _class_ro_t {
  1152. /// uint32_t const flags;
  1153. /// uint32_t const instanceStart;
  1154. /// uint32_t const instanceSize;
  1155. /// uint32_t const reserved; // only when building for 64bit targets
  1156. /// const uint8_t * const ivarLayout;
  1157. /// const char *const name;
  1158. /// const struct _method_list_t * const baseMethods;
  1159. /// const struct _protocol_list_t *const baseProtocols;
  1160. /// const struct _ivar_list_t *const ivars;
  1161. /// const uint8_t * const weakIvarLayout;
  1162. /// const struct _prop_list_t * const properties;
  1163. /// }
  1164. *)
  1165. procedure tobjcrttiwriter_nonfragile.gen_objc_class_ro_part(list: tasmlist; objclss: tobjectdef; protolistsym: TAsmSymbol; out classrolabel: tasmsymbol; metaclass: boolean);
  1166. const
  1167. CLS_CLASS = 0;
  1168. CLS_META = 1;
  1169. CLS_ROOT = 2;
  1170. OBJC2_CLS_HIDDEN = $10;
  1171. CLS_EXCEPTION = $20;
  1172. var
  1173. classStrSym,
  1174. rosym : TAsmSymbol;
  1175. methodslab,
  1176. ivarslab : TAsmLabel;
  1177. class_type : tdef;
  1178. start,
  1179. size,
  1180. flags : cardinal;
  1181. rttitype : trttitype;
  1182. firstfield : tfieldvarsym;
  1183. i : longint;
  1184. begin
  1185. { consider every class declared in the implementation section of a unit
  1186. as "hidden"
  1187. }
  1188. flags:=0;
  1189. if (objclss.owner.symtabletype=staticsymtable) and
  1190. current_module.is_unit then
  1191. flags:=OBJC2_CLS_HIDDEN;
  1192. if metaclass then
  1193. begin
  1194. flags:=flags or CLS_META;
  1195. rttitype:=objcmetarortti;
  1196. { metaclass size/start: always size of objc_object }
  1197. class_type:=search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef;
  1198. start:=class_type.size;
  1199. size:=start;
  1200. end
  1201. else
  1202. begin
  1203. flags:=flags or CLS_CLASS;
  1204. rttitype:=objcclassrortti;
  1205. size:=tObjectSymtable(objclss.symtable).datasize;
  1206. { can't simply use childof's datasize, because alignment may cause the
  1207. first field to skip a couple of bytes after the previous end }
  1208. firstfield:=nil;
  1209. for i:=0 to objclss.symtable.SymList.Count-1 do
  1210. if (tsym(objclss.symtable.SymList[i]).typ=fieldvarsym) then
  1211. begin
  1212. firstfield:=tfieldvarsym(objclss.symtable.SymList[i]);
  1213. break;
  1214. end;
  1215. if assigned(firstfield) then
  1216. start:=firstfield.fieldoffset
  1217. else
  1218. { no extra fields -> start = size }
  1219. start:=size;
  1220. end;
  1221. if not assigned(objclss.childof) then
  1222. flags:=flags or CLS_ROOT;
  1223. classStrSym:=objcreatestringpoolentry(objclss.objextname^,sp_objcclassnames,sec_objc_class_names);
  1224. { generate methods list }
  1225. gen_objc_methods(list,objclss,methodslab,metaclass,false);
  1226. { generate ivars (nil for metaclass) }
  1227. if metaclass then
  1228. ivarslab:=nil
  1229. else
  1230. gen_objc_ivars(list,objclss,ivarslab);
  1231. { class declaration section }
  1232. new_section(list,sec_objc_const,'_OBJC_META_CLASS',sizeof(pint));
  1233. rosym:=current_asmdata.DefineAsmSymbol(objclss.rtti_mangledname(rttitype),AB_LOCAL,AT_DATA);
  1234. classrolabel:=rosym;
  1235. list.Concat(tai_symbol.create(rosym,0));
  1236. list.Concat(tai_const.Create_32bit(longint(flags)));
  1237. list.Concat(tai_const.Create_32bit(longint(start)));
  1238. list.Concat(tai_const.Create_32bit(longint(size)));
  1239. {$ifdef cpu64bitaddr}
  1240. { alignment }
  1241. list.Concat(tai_const.Create_32bit(0));
  1242. {$endif}
  1243. { TODO: strong ivar layout for garbage collection }
  1244. list.concat(tai_const.Create_pint(0));
  1245. list.concat(tai_const.Create_sym(classStrSym));
  1246. ConcatSymOrNil(list,methodslab);
  1247. ConcatSymOrNil(list,protolistsym);
  1248. ConcatSymOrNil(list,ivarslab);
  1249. { TODO: weak ivar layout for garbage collection }
  1250. list.concat(tai_const.Create_pint(0));
  1251. { TODO: properties }
  1252. list.concat(tai_const.Create_pint(0));
  1253. end;
  1254. (*
  1255. From Clang:
  1256. /// struct _class_t {
  1257. /// struct _class_t *isa;
  1258. /// struct _class_t * const superclass;
  1259. /// void *cache;
  1260. /// IMP *vtable;
  1261. /// struct class_ro_t *ro;
  1262. /// }
  1263. ///
  1264. *)
  1265. { Generate rtti for an Objective-C class and its meta-class. }
  1266. procedure tobjcrttiwriter_nonfragile.gen_objc_classes_sections(list:TAsmList; objclss: tobjectdef; out classlabel: TAsmSymbol);
  1267. var
  1268. root : tobjectdef;
  1269. superSym,
  1270. superMetaSym,
  1271. metaisaSym,
  1272. metasym,
  1273. clssym,
  1274. metarosym,
  1275. rosym : TAsmSymbol;
  1276. protolistsym : TAsmLabel;
  1277. vis : TAsmsymbind;
  1278. begin
  1279. { A) Register necessary names }
  1280. { 1) the current class and metaclass }
  1281. if (objclss.owner.symtabletype=globalsymtable) then
  1282. vis:=AB_GLOBAL
  1283. else
  1284. vis:=AB_PRIVATE_EXTERN;
  1285. clssym:=current_asmdata.DefineAsmSymbol(objclss.rtti_mangledname(objcclassrtti),vis,AT_DATA);
  1286. metasym:=current_asmdata.DefineAsmSymbol(objclss.rtti_mangledname(objcmetartti),vis,AT_DATA);
  1287. { 2) the superclass and meta superclass }
  1288. if assigned(objclss.childof) then
  1289. begin
  1290. superSym:=current_asmdata.RefAsmSymbol(objclss.childof.rtti_mangledname(objcclassrtti));
  1291. superMetaSym:=current_asmdata.RefAsmSymbol(objclss.childof.rtti_mangledname(objcmetartti));
  1292. end
  1293. else
  1294. begin
  1295. superSym:=nil;
  1296. { the class itself }
  1297. superMetaSym:=clssym;
  1298. end;
  1299. { 3) the isa }
  1300. { From Clang: The isa for the meta-class is the root of the hierarchy. }
  1301. root:=objclss;
  1302. while assigned(root.childof) do
  1303. root:=root.childof;
  1304. metaisaSym:=current_asmdata.RefAsmSymbol(root.rtti_mangledname(objcmetartti));
  1305. { 4) the implemented protocols (same for metaclass and regular class) }
  1306. gen_objc_protocol_list(list,objclss.ImplementedInterfaces,protolistsym);
  1307. { 5) the read-only parts of the class definitions }
  1308. gen_objc_class_ro_part(list,objclss,protolistsym,metarosym,true);
  1309. gen_objc_class_ro_part(list,objclss,protolistsym,rosym,false);
  1310. { B) Class declaration section }
  1311. { both class and metaclass are in the objc_data section for obj-c 2 }
  1312. new_section(list,sec_objc_data,'_OBJC_CLASS',sizeof(pint));
  1313. { 1) meta-class declaration }
  1314. list.Concat(tai_symbol.Create_Global(metasym,0));
  1315. { the isa }
  1316. list.Concat(Tai_const.Create_sym(metaisaSym));
  1317. { the superclass }
  1318. list.Concat(Tai_const.Create_sym(superMetaSym));
  1319. { pointer to cache }
  1320. if not assigned(ObjCEmptyCacheVar) then
  1321. ObjCEmptyCacheVar:=current_asmdata.RefAsmSymbol(target_info.Cprefix+'_objc_empty_cache');
  1322. list.Concat(Tai_const.Create_sym(ObjCEmptyCacheVar));
  1323. { pointer to vtable }
  1324. if not assigned(ObjCEmptyVtableVar) then
  1325. ObjCEmptyVtableVar:=current_asmdata.RefAsmSymbol(target_info.Cprefix+'_objc_empty_vtable');
  1326. list.Concat(Tai_const.Create_sym(ObjCEmptyVtableVar));
  1327. { the read-only part }
  1328. list.Concat(Tai_const.Create_sym(metarosym));
  1329. { 2) regular class declaration }
  1330. list.Concat(tai_symbol.Create_Global(clssym,0));
  1331. { the isa }
  1332. list.Concat(Tai_const.Create_sym(metasym));
  1333. { the superclass }
  1334. list.Concat(Tai_const.Create_sym(superSym));
  1335. { pointer to cache }
  1336. list.Concat(Tai_const.Create_sym(ObjCEmptyCacheVar));
  1337. { pointer to vtable }
  1338. list.Concat(Tai_const.Create_sym(ObjCEmptyVtableVar));
  1339. { the read-only part }
  1340. list.Concat(Tai_const.Create_sym(rosym));
  1341. classlabel:=clssym;
  1342. end;
  1343. procedure tobjcrttiwriter_nonfragile.addclasslist(list: tasmlist; section: tasmsectiontype; const symname: string; classes: tfpobjectlist);
  1344. var
  1345. i: longint;
  1346. sym: TAsmSymbol;
  1347. begin
  1348. if classes.count=0 then
  1349. exit;
  1350. new_section(list,section,symname,sizeof(pint));
  1351. sym:=current_asmdata.DefineAsmSymbol(symname,AB_LOCAL,AT_DATA);
  1352. list.concat(tai_symbol.Create(sym,0));
  1353. for i:=0 to classes.count-1 do
  1354. list.concat(tai_const.Create_sym(current_asmdata.RefAsmSymbol(tobjectdef(classes[i]).rtti_mangledname(objcclassrtti))));
  1355. end;
  1356. procedure tobjcrttiwriter_nonfragile.gen_objc_info_sections(list: tasmlist);
  1357. function collectnonlazyclasses(classes: tfpobjectlist): tfpobjectlist;
  1358. var
  1359. symentry : tsym;
  1360. procdef : tprocdef;
  1361. i,j : longint;
  1362. begin
  1363. { non-lazy classes are all classes that define a class method with the
  1364. selector called "load" (simply inheriting this class method is not enough,
  1365. they have to implement it themselves)
  1366. -- TODO: this currently only works if the Pascal identifier is also 'load'! }
  1367. result:=tfpobjectlist.create(false);
  1368. for i:=0 to classes.count-1 do
  1369. begin
  1370. symentry:=tsym(tobjectsymtable(tobjectdef(classes[i]).symtable).find('LOAD'));
  1371. if assigned(symentry) and
  1372. (symentry.typ=procsym) then
  1373. begin
  1374. for j:=0 to tprocsym(symentry).ProcdefList.count do
  1375. begin
  1376. procdef:=tprocdef(tprocsym(symentry).ProcdefList[0]);
  1377. if ((po_classmethod in procdef.procoptions) and
  1378. (procdef.messageinf.str^='load')) then
  1379. begin
  1380. result.add(classes[i]);
  1381. break;
  1382. end;
  1383. end;
  1384. end;
  1385. end;
  1386. end;
  1387. var
  1388. nonlazyclasses,
  1389. nonlazycategories : tfpobjectlist;
  1390. begin
  1391. if (classdefs.count=0) and
  1392. (catdefs.count=0) then
  1393. exit;
  1394. nonlazyclasses:=collectnonlazyclasses(classdefs);
  1395. nonlazycategories:=collectnonlazyclasses(catdefs);
  1396. { this list has to include all classes, also the non-lazy ones }
  1397. addclasslist(list,sec_objc_classlist,target_asm.labelprefix+'_OBJC_LABEL_CLASS_$',classdefs);
  1398. addclasslist(list,sec_objc_nlclasslist,target_asm.labelprefix+'_OBJC_LABEL_NONLAZY_CLASS_$',nonlazyclasses);
  1399. { category and non-lazy category lists }
  1400. addclasslist(list,sec_objc_catlist,target_asm.labelprefix+'_OBJC_LABEL_CATEGORY_$',catdefs);
  1401. addclasslist(list,sec_objc_nlcatlist,target_asm.labelprefix+'_OBJC_LABEL_NONLAZY_CATEGORY_$',nonlazycategories);
  1402. nonlazyclasses.free;
  1403. nonlazycategories.free;
  1404. { the non-fragile abi doesn't have any module info, nor lazy references
  1405. to used classes or to parent classes }
  1406. end;
  1407. constructor tobjcrttiwriter_nonfragile.create;
  1408. begin
  1409. inherited create(oa_nonfragile);
  1410. end;
  1411. {******************************************************************
  1412. RTTI generation -- Main function
  1413. *******************************************************************}
  1414. procedure MaybeGenerateObjectiveCImageInfo(globalst, localst: tsymtable);
  1415. var
  1416. objcrttiwriter: tobjcrttiwriter;
  1417. begin
  1418. if (m_objectivec1 in current_settings.modeswitches) then
  1419. begin
  1420. { first 4 bytes contain version information about this section (currently version 0),
  1421. next 4 bytes contain flags (currently only regarding whether the code in the object
  1422. file supports or requires garbage collection)
  1423. }
  1424. new_section(current_asmdata.asmlists[al_objc_data],sec_objc_image_info,'_OBJC_IMAGE_INFO',sizeof(pint));
  1425. current_asmdata.asmlists[al_objc_data].concat(Tai_symbol.Createname(target_asm.labelprefix+'_OBJC_IMAGE_INFO',AT_LABEL,sizeof(pint)));
  1426. current_asmdata.asmlists[al_objc_data].concat(Tai_const.Create_64bit(0));
  1427. { generate rtti for all obj-c classes, protocols and categories
  1428. defined in this module. }
  1429. if not(target_info.system in systems_objc_nfabi) then
  1430. objcrttiwriter:=tobjcrttiwriter_fragile.create
  1431. else
  1432. objcrttiwriter:=tobjcrttiwriter_nonfragile.create;
  1433. objcrttiwriter.gen_objc_rtti_sections(current_asmdata.asmlists[al_objc_data],globalst);
  1434. objcrttiwriter.gen_objc_rtti_sections(current_asmdata.asmlists[al_objc_data],localst);
  1435. objcrttiwriter.gen_objc_info_sections(current_asmdata.asmlists[al_objc_data]);
  1436. objcrttiwriter.free;
  1437. end;
  1438. end;
  1439. end.