aasmcnst.pas 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284
  1. {
  2. Copyright (c) 2014 by Jonas Maebe, member of the Free Pascal development
  3. team
  4. This unit implements typed constant data elements at the assembler 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. unit aasmcnst;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,globtype,constexp,
  23. aasmbase,aasmdata,aasmtai,
  24. symconst,symbase,symtype,symdef,symsym;
  25. type
  26. { typed const: integer/floating point/string/pointer/... const along with
  27. tdef info }
  28. ttypedconstkind = (tck_simple, tck_array, tck_record);
  29. { the type of the element and its def }
  30. tai_abstracttypedconst = class abstract (tai)
  31. private
  32. procedure setdef(def: tdef);
  33. protected
  34. fadetyp: ttypedconstkind;
  35. { the def of this element }
  36. fdef: tdef;
  37. public
  38. constructor create(_adetyp: ttypedconstkind; _def: tdef);
  39. property adetyp: ttypedconstkind read fadetyp;
  40. property def: tdef read fdef write setdef;
  41. end;
  42. { a simple data element; the value is stored as a tai }
  43. tai_simpletypedconst = class(tai_abstracttypedconst)
  44. private
  45. procedure setval(AValue: tai);
  46. protected
  47. fval: tai;
  48. public
  49. constructor create(_def: tdef; _val: tai);
  50. destructor destroy; override;
  51. property val: tai read fval write setval;
  52. end;
  53. { an aggregate data element (record or array). Values are stored as an
  54. array of tsimpledataelement. }
  55. tai_aggregatetypedconst = class(tai_abstracttypedconst)
  56. public type
  57. { iterator to walk over all individual items in the aggregate }
  58. tadeenumerator = class(tobject)
  59. private
  60. fvalues: tfpobjectlist;
  61. fvaluespos: longint;
  62. function getcurrent: tai_abstracttypedconst;
  63. public
  64. constructor create(data: tai_aggregatetypedconst);
  65. function movenext: boolean;
  66. procedure reset;
  67. property current: tai_abstracttypedconst read getcurrent;
  68. end;
  69. protected
  70. fvalues: tfpobjectlist;
  71. fisstring: boolean;
  72. { converts the existing data to a single tai_string }
  73. procedure convert_to_string;
  74. procedure add_to_string(strtai: tai_string; othertai: tai);
  75. public
  76. constructor create(_adetyp: ttypedconstkind; _fdef: tdef);
  77. function getenumerator: tadeenumerator;
  78. procedure addvalue(val: tai_abstracttypedconst); virtual;
  79. function valuecount: longint;
  80. procedure insertvaluebeforepos(val: tai_abstracttypedconst; pos: longint);
  81. procedure replacevalueatpos(val: tai_abstracttypedconst; pos: longint);
  82. { change the type to a record, regardless of how the aggregate was created;
  83. the size of the original type and the record must match }
  84. procedure changetorecord(_def: trecorddef);
  85. procedure finish;
  86. destructor destroy; override;
  87. end;
  88. tasmlabofs = record
  89. lab: tasmlabel;
  90. ofs: asizeint;
  91. end;
  92. { flags for the finalisation of the typed const builder asmlist }
  93. ttcasmlistoption = (
  94. { the tasmsymbol is a tasmlabel }
  95. tcalo_is_lab,
  96. { start a new section (e.g., because we don't know the current section
  97. type) }
  98. tcalo_new_section,
  99. { this symbol is the start of a block of data that should be
  100. dead-stripable/smartlinkable; may imply starting a new section, but
  101. not necessarily (depends on what the platform requirements are) }
  102. tcalo_make_dead_strippable,
  103. { this symbol should never be removed by the linker }
  104. tcalo_no_dead_strip,
  105. { start of a vectorized but individually dead strippable list of elements,
  106. like the resource strings of a unit: they have to stay in this order,
  107. but individual elements can be removed }
  108. tcalo_vectorized_dead_strip_start,
  109. { item in the above list }
  110. tcalo_vectorized_dead_strip_item,
  111. { end of the above list }
  112. tcalo_vectorized_dead_strip_end,
  113. { symbol should be weakly defined }
  114. tcalo_weak,
  115. { symbol should be registered with the unit's public assembler symbols }
  116. tcalo_is_public_asm,
  117. { symbol should be declared with AT_DATA_FORCEINDIRECT }
  118. tcalo_data_force_indirect,
  119. { apply const_align() to the alignment, for user-defined data }
  120. tcalo_apply_constalign
  121. );
  122. ttcasmlistoptions = set of ttcasmlistoption;
  123. ttcdeadstripsectionsymboloption = (
  124. { define the symbol }
  125. tcdssso_define,
  126. { register the assembler symbol either with the public or extern assembler
  127. symbols of the unit }
  128. tcdssso_register_asmsym,
  129. { use the indirect symbol }
  130. tcdssso_use_indirect
  131. );
  132. ttcdeadstripsectionsymboloptions = set of ttcdeadstripsectionsymboloption;
  133. { information about aggregates we are parsing }
  134. taggregateinformation = class
  135. private
  136. fnextfieldname: TIDString;
  137. function getcuroffset: asizeint;
  138. procedure setnextfieldname(AValue: TIDString);
  139. protected
  140. { type of the aggregate }
  141. fdef: tdef;
  142. { type of the aggregate }
  143. ftyp: ttypedconstkind;
  144. { symtable entry of the previously emitted field in case of a
  145. record/object (nil if none emitted yet), used to insert alignment bytes
  146. if necessary for variant records and objects }
  147. fcurfield,
  148. { field corresponding to the data that will be emitted next in case of a
  149. record/object (nil if not set), used to handle variant records and
  150. objects }
  151. fnextfield: tfieldvarsym;
  152. { similar as the fcurfield/fnextfield above, but instead of fieldvarsyms
  153. these are indices in the symlist of a recorddef that correspond to
  154. fieldvarsyms. These are used only for non-variant records, simply
  155. traversing the fields in order. We could use the above method here as
  156. well, but to find the next field we'd always have to use
  157. symlist.indexof(fcurfield), which would be quite slow. These have -1 as
  158. value if they're not set }
  159. fcurindex,
  160. fnextindex: longint;
  161. { anonymous record that is being built as we add constant data }
  162. fanonrecord: boolean;
  163. property curindex: longint read fcurindex write fcurindex;
  164. property nextindex: longint read fnextindex write fnextindex;
  165. public
  166. constructor create(_def: tdef; _typ: ttypedconstkind); virtual;
  167. { calculated padding bytes for alignment if needed, and add the def of the
  168. next field in case we are constructing an anonymous record }
  169. function prepare_next_field(nextfielddef: tdef): asizeint; virtual;
  170. property def: tdef read fdef;
  171. property typ: ttypedconstkind read ftyp;
  172. property curfield: tfieldvarsym read fcurfield write fcurfield;
  173. property nextfield: tfieldvarsym read fnextfield write fnextfield;
  174. property nextfieldname: TIDString write setnextfieldname;
  175. property curoffset: asizeint read getcuroffset;
  176. property anonrecord: boolean read fanonrecord write fanonrecord;
  177. end;
  178. taggregateinformationclass = class of taggregateinformation;
  179. { information about a placeholder element that has been added, and which has
  180. to be replaced later with a real data element }
  181. ttypedconstplaceholder = class abstract
  182. def: tdef;
  183. constructor create(d: tdef);
  184. { same usage as ttai_typedconstbuilder.emit_tai }
  185. procedure replace(ai: tai; d: tdef); virtual; abstract;
  186. end;
  187. { Warning: never directly create a ttai_typedconstbuilder instance,
  188. instead create a cai_typedconstbuilder (this class can be overridden) }
  189. ttai_typedconstbuilder = class abstract
  190. { class type to use when creating new aggregate information instances }
  191. protected class var
  192. caggregateinformation: taggregateinformationclass;
  193. private
  194. function getcurragginfo: taggregateinformation;
  195. procedure set_next_field(AValue: tfieldvarsym);
  196. procedure set_next_field_name(AValue: TIDString);
  197. protected
  198. { temporary list in which all data is collected }
  199. fasmlist: tasmlist;
  200. { options for the final asmlist }
  201. foptions: ttcasmlistoptions;
  202. { while queueing elements of a compound expression, this is the current
  203. offset in the top-level array/record }
  204. fqueue_offset: asizeint;
  205. fqueued_def: tdef;
  206. { array of caggregateinformation instances }
  207. faggregateinformation: tfpobjectlist;
  208. { Support for generating data that is only referenced from the typed
  209. constant data that we are currently generated. Such data can all be put
  210. in the same dead-strippable unit, as it's either all included or none of
  211. it is included. This data can be spread over multiple kinds of sections
  212. though (e.g. rodata and rodata_no_rel), so per section keep track whether
  213. we already started a dead-strippable unit and if so, what the section
  214. name was (so that on platforms that perform the dead stripping based on
  215. sections, we put all data for one typed constant into a single section
  216. with the same name) }
  217. protected type
  218. tinternal_data_section_info = record
  219. secname: TSymStr;
  220. sectype: TAsmSectiontype;
  221. end;
  222. protected var
  223. { all internally generated data must be stored in the same list, as it must
  224. be consecutive (if it's spread over multiple lists, we don't know in
  225. which order they'll be concatenated) -> keep track of this list }
  226. finternal_data_asmlist: tasmlist;
  227. { kind of the last section we started in the finternal_data_asmlist, to
  228. avoid creating unnecessary section statements }
  229. finternal_data_current_section: TAsmSectiontype;
  230. { info about in which kinds of sections we have already emitted internal
  231. data, and what their names were }
  232. finternal_data_section_info: array of tinternal_data_section_info;
  233. { ensure that finalize_asmlist is called only once }
  234. fasmlist_finalized: boolean;
  235. { ensure that if it's vectorized dead strippable data, we called
  236. finalize_vectorized_dead_strip_asmlist instead of finalize_asmlist }
  237. fvectorized_finalize_called: boolean;
  238. { returns whether def must be handled as an aggregate on the current
  239. platform }
  240. function aggregate_kind(def: tdef): ttypedconstkind; virtual;
  241. { finalize the asmlist: add the necessary symbols etc }
  242. procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); virtual;
  243. procedure finalize_asmlist_add_indirect_sym(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); virtual;
  244. { prepare finalization (common for the default and overridden versions }
  245. procedure finalize_asmlist_prepare(const options: ttcasmlistoptions; var alignment: shortint);
  246. { functionality of the above for vectorized dead strippable sections }
  247. procedure finalize_vectorized_dead_strip_asmlist(def: tdef; const basename, itemname: TSymStr; st: tsymtable; alignment: shortint; options: ttcasmlistoptions); virtual;
  248. { called by the public emit_tai() routines to actually add the typed
  249. constant data; the public ones also take care of adding extra padding
  250. bytes etc (by calling this one) }
  251. procedure do_emit_tai(p: tai; def: tdef); virtual;
  252. { calls prepare_next_field() and adds the padding bytes in the current
  253. location }
  254. procedure pad_next_field(nextfielddef: tdef);
  255. { returns the index in finternal_data_section_info of the info for the
  256. section of type typ. Returns -1 if there is no such info yet }
  257. function get_internal_data_section_index(typ: TAsmSectiontype): longint;
  258. { get a start label for an internal data section (at the start of a
  259. potentially dead-strippable part) }
  260. function get_internal_data_section_start_label: tasmlabel; virtual;
  261. { get a label in the middle of an internal data section (no dead
  262. stripping) }
  263. function get_internal_data_section_internal_label: tasmlabel; virtual;
  264. { easy access to the top level aggregate information instance }
  265. property curagginfo: taggregateinformation read getcurragginfo;
  266. public
  267. constructor create(const options: ttcasmlistoptions); virtual;
  268. destructor destroy; override;
  269. public
  270. { returns a builder for generating data that is only referrenced by the
  271. typed constant date we are currently generating (e.g. string data for a
  272. pchar constant). Also returns the label that will be placed at the start
  273. of that data. list is the tasmlist to which the data will be added.
  274. secname can be empty to use a default }
  275. procedure start_internal_data_builder(list: tasmlist; sectype: TAsmSectiontype; const secname: TSymStr; out tcb: ttai_typedconstbuilder; out l: tasmlabel);
  276. { finish a previously started internal data builder, including
  277. concatenating all generated data to the provided list and freeing the
  278. builder }
  279. procedure finish_internal_data_builder(var tcb: ttai_typedconstbuilder; l: tasmlabel; def: tdef; alignment: longint);
  280. { add a simple constant data element (p) to the typed constant.
  281. def is the type of the added value }
  282. procedure emit_tai(p: tai; def: tdef); virtual;
  283. { same as above, for a special case: when the def is a procvardef and we
  284. want to use it explicitly as a procdef (i.e., not as a record with a
  285. code and data pointer in case of a complex procvardef) }
  286. procedure emit_tai_procvar2procdef(p: tai; pvdef: tprocvardef); virtual;
  287. protected
  288. procedure maybe_emit_tail_padding(def: tdef); virtual;
  289. function emit_string_const_common(stringtype: tstringtype; len: asizeint; encoding: tstringencoding; var startlab: tasmlabel):tasmlabofs;
  290. function get_dynstring_def_for_type(stringtype: tstringtype; winlikewidestring: boolean): tstringdef;
  291. procedure begin_aggregate_internal(def: tdef; anonymous: boolean); virtual;
  292. procedure end_aggregate_internal(def: tdef; anonymous: boolean); virtual;
  293. { when building an anonymous record, we cannot immediately insert the
  294. alignment before it in case it's nested, since we only know the required
  295. alignment once all fields have been inserted -> mark the location before
  296. the anonymous record, and insert the alignment once it's finished }
  297. procedure mark_anon_aggregate_alignment; virtual; abstract;
  298. procedure insert_marked_aggregate_alignment(def: tdef); virtual; abstract;
  299. class function get_vectorized_dead_strip_section_symbol(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions; start: boolean): tasmsymbol; virtual;
  300. public
  301. class function get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; out secname: TSymStr): boolean; virtual;
  302. { get the start/end symbol for a dead stripable vectorized section, such
  303. as the resourcestring data of a unit }
  304. class function get_vectorized_dead_strip_section_symbol_start(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol; virtual;
  305. class function get_vectorized_dead_strip_section_symbol_end(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol; virtual;
  306. class function get_dynstring_rec_name(typ: tstringtype; winlike: boolean; len: asizeint): TSymStr;
  307. class function get_dynstring_rec(typ: tstringtype; winlike: boolean; len: asizeint): trecorddef;
  308. { the datalist parameter specifies where the data for the string constant
  309. will be emitted (via an internal data builder) }
  310. function emit_ansistring_const(datalist: TAsmList; data: pchar; len: asizeint; encoding: tstringencoding): tasmlabofs;
  311. function emit_unicodestring_const(datalist: TAsmList; data: pointer; encoding: tstringencoding; winlike: boolean):tasmlabofs;
  312. { emits a tasmlabofs as returned by emit_*string_const }
  313. procedure emit_string_offset(const ll: tasmlabofs; const strlength: longint; const st: tstringtype; const winlikewidestring: boolean; const charptrdef: tdef);virtual;
  314. { emits a tasmlabofs as returned by begin_dynarray_const }
  315. procedure emit_dynarray_offset(const ll:tasmlabofs;const arrlength:asizeint;const arrdef:tarraydef; const arrconstdatadef: trecorddef);virtual;
  316. { starts a dynamic array constant so that its data can be emitted directly afterwards }
  317. function begin_dynarray_const(arrdef:tdef;var startlab:tasmlabel;out arrlengthloc:ttypedconstplaceholder):tasmlabofs;virtual;
  318. function end_dynarray_const(arrdef:tdef;arrlength:asizeint;arrlengthloc:ttypedconstplaceholder):tdef;virtual;
  319. { emit a shortstring constant, and return its def }
  320. function emit_shortstring_const(const str: shortstring): tdef;
  321. { emit a pchar string constant (the characters, not a pointer to them), and return its def }
  322. function emit_pchar_const(str: pchar; len: pint; copypchar: boolean): tdef;
  323. { emit a guid constant }
  324. procedure emit_guid_const(const guid: tguid);
  325. { emit a procdef constant }
  326. procedure emit_procdef_const(pd: tprocdef);
  327. { emit an ordinal constant }
  328. procedure emit_ord_const(value: int64; def: tdef);
  329. { emit a reference to a pooled shortstring constant }
  330. procedure emit_pooled_shortstring_const_ref(const str:shortstring);
  331. { begin a potential aggregate type. Must be called for any type
  332. that consists of multiple tai constant data entries, or that
  333. represents an aggregate at the Pascal level (a record, a non-dynamic
  334. array, ... }
  335. procedure maybe_begin_aggregate(def: tdef);
  336. { end a potential aggregate type. Must be paired with every
  337. maybe_begin_aggregate }
  338. procedure maybe_end_aggregate(def: tdef);
  339. { similar as above, but in case
  340. a) it's definitely a record
  341. b) the def of the record should be automatically constructed based on
  342. the types of the emitted fields
  343. packrecords: same as "pacrecords x"
  344. recordalign: specify the (minimum) alignment of the start of the record
  345. (no equivalent in source code), used as an alternative for explicit
  346. align statements. Use "1" if it should be calculated based on the
  347. fields
  348. recordalignmin: same as "codealign recordmin=x"
  349. maxcrecordalign: specify maximum C record alignment (no equivalent in
  350. source code)
  351. }
  352. function begin_anonymous_record(const optionalname: string; packrecords, recordalign, recordalignmin: shortint): trecorddef; virtual;
  353. function end_anonymous_record: trecorddef; virtual;
  354. { add a placeholder element at the current position that later can be
  355. filled in with the actual data (via ttypedconstplaceholder.replace)
  356. useful in case you have table preceded by the number of elements, and
  357. you count the elements while building the table }
  358. function emit_placeholder(def: tdef): ttypedconstplaceholder; virtual; abstract;
  359. protected
  360. { common code to check whether a placeholder can be added at the current
  361. position }
  362. procedure check_add_placeholder(def: tdef);
  363. public
  364. { The next group of routines are for constructing complex expressions.
  365. While parsing a typed constant these operators are encountered from
  366. outer to inner, so that is also the order in which they should be
  367. added to the queue. Only one queue can be active at a time. }
  368. { Init the queue. Gives an internalerror if a queue was already active }
  369. procedure queue_init(todef: tdef); virtual;
  370. { queue an array/string indexing operation (performs all range checking,
  371. so it doesn't have to be duplicated in all descendents). }
  372. procedure queue_vecn(def: tdef; const index: tconstexprint); virtual;
  373. { queue a subscripting operation }
  374. procedure queue_subscriptn(def: tabstractrecorddef; vs: tfieldvarsym); virtual;
  375. { queue indexing a record recursively via several field names. The fields
  376. are specified in the inner to outer order (i.e., def.field1.field2) }
  377. function queue_subscriptn_multiple_by_name(def: tabstractrecorddef; const fields: array of TIDString): tdef;
  378. { queue a type conversion operation }
  379. procedure queue_typeconvn(fromdef, todef: tdef); virtual;
  380. { finalise the queue (so a new one can be created) and flush the
  381. previously queued operations, applying them in reverse order on a...}
  382. { ... procdef }
  383. procedure queue_emit_proc(pd: tprocdef); virtual;
  384. { ... staticvarsym }
  385. procedure queue_emit_staticvar(vs: tstaticvarsym); virtual;
  386. { ... labelsym }
  387. procedure queue_emit_label(l: tlabelsym); virtual;
  388. { ... constsym }
  389. procedure queue_emit_const(cs: tconstsym); virtual;
  390. { ... asmsym/asmlabel }
  391. procedure queue_emit_asmsym(sym: tasmsymbol; def: tdef); virtual;
  392. { ... an ordinal constant }
  393. procedure queue_emit_ordconst(value: int64; def: tdef); virtual;
  394. protected
  395. { returns whether queue_init has been called without a corresponding
  396. queue_emit_* to finish it }
  397. function queue_is_active: boolean;
  398. public
  399. { finalize the internal asmlist (if necessary) and return it.
  400. This asmlist will be freed when the builder is destroyed, so add its
  401. contents to another list first. This property should only be accessed
  402. once all data has been added. }
  403. function get_final_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint): tasmlist;
  404. function get_final_asmlist_vectorized_dead_strip(def: tdef; const basename, itemname: TSymStr; st: TSymtable; alignment: longint): tasmlist;
  405. { returns the offset of the string data relative to ansi/unicode/widestring
  406. constant labels. On most platforms, this is 0 (with the header at a
  407. negative offset), but on some platforms such negative offsets are not
  408. supported this is equal to the header size }
  409. class function get_string_symofs(typ: tstringtype; winlikewidestring: boolean): pint; virtual;
  410. { returns the offset of the array data relatve to dynamic array constant
  411. labels. On most platforms, this is 0 (with the header at a negative
  412. offset), but on some platforms such negative offsets are not supported
  413. and thus this is equal to the header size }
  414. class function get_dynarray_symofs:pint;virtual;
  415. { set the fieldvarsym whose data we will emit next; needed
  416. in case of variant records, so we know which part of the variant gets
  417. initialised. Also in case of objects, because the fieldvarsyms are spread
  418. over the symtables of the entire inheritance tree }
  419. property next_field: tfieldvarsym write set_next_field;
  420. { set the name of the next field that will be emitted for an anonymous
  421. record (also if that field is a nested anonymous record) }
  422. property next_field_name: TIDString write set_next_field_name;
  423. protected
  424. { these ones always return the actual offset, called by the above (and
  425. overridden versions) }
  426. class function get_string_header_size(typ: tstringtype; winlikewidestring: boolean): pint;
  427. class function get_dynarray_header_size:pint;
  428. end;
  429. ttai_typedconstbuilderclass = class of ttai_typedconstbuilder;
  430. tlowlevelaggregateinformation = class(taggregateinformation)
  431. protected
  432. fanonrecmarker: tai;
  433. public
  434. property anonrecmarker: tai read fanonrecmarker write fanonrecmarker;
  435. end;
  436. tlowleveltypedconstplaceholder = class(ttypedconstplaceholder)
  437. list: tasmlist;
  438. insertpos: tai;
  439. constructor create(l: tasmlist; pos: tai; d: tdef);
  440. procedure replace(ai: tai; d: tdef); override;
  441. end;
  442. ttai_lowleveltypedconstbuilder = class(ttai_typedconstbuilder)
  443. protected
  444. procedure mark_anon_aggregate_alignment; override;
  445. procedure insert_marked_aggregate_alignment(def: tdef); override;
  446. procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); override;
  447. public
  448. { set the default value for caggregateinformation (= tlowlevelaggregateinformation) }
  449. class constructor classcreate;
  450. function emit_placeholder(def: tdef): ttypedconstplaceholder; override;
  451. end;
  452. var
  453. ctai_typedconstbuilder: ttai_typedconstbuilderclass;
  454. implementation
  455. uses
  456. cutils,
  457. verbose,globals,systems,widestr,
  458. fmodule,
  459. symtable,defutil;
  460. {****************************************************************************
  461. taggregateinformation
  462. ****************************************************************************}
  463. function taggregateinformation.getcuroffset: asizeint;
  464. var
  465. field: tfieldvarsym;
  466. begin
  467. if assigned(curfield) then
  468. result:=curfield.fieldoffset+curfield.vardef.size
  469. else if curindex<>-1 then
  470. begin
  471. field:=tfieldvarsym(tabstractrecorddef(def).symtable.symlist[curindex]);
  472. result:=field.fieldoffset+field.vardef.size
  473. end
  474. else
  475. result:=0
  476. end;
  477. procedure taggregateinformation.setnextfieldname(AValue: TIDString);
  478. begin
  479. if (fnextfieldname<>'') or
  480. not anonrecord then
  481. internalerror(2015071503);
  482. fnextfieldname:=AValue;
  483. end;
  484. constructor taggregateinformation.create(_def: tdef; _typ: ttypedconstkind);
  485. begin
  486. fdef:=_def;
  487. ftyp:=_typ;
  488. fcurindex:=-1;
  489. fnextindex:=-1;
  490. end;
  491. function taggregateinformation.prepare_next_field(nextfielddef: tdef): asizeint;
  492. var
  493. sym: tsym;
  494. currentoffset,nextoffset: asizeint;
  495. i: longint;
  496. begin
  497. { get the next field and its offset, and make that next field the current
  498. one }
  499. if assigned(nextfield) then
  500. begin
  501. nextoffset:=nextfield.fieldoffset;
  502. currentoffset:=curoffset;
  503. curfield:=nextfield;
  504. end
  505. else
  506. begin
  507. { must set nextfield for unions and objects, as we cannot
  508. automatically detect the "next" field in that case }
  509. if ((def.typ=recorddef) and
  510. trecorddef(def).isunion) or
  511. is_object(def) then
  512. internalerror(2014091202);
  513. { if we are constructing this record as data gets emitted, add a field
  514. for this data }
  515. if anonrecord then
  516. begin
  517. trecorddef(def).add_field_by_def(fnextfieldname,nextfielddef);
  518. fnextfieldname:='';
  519. end
  520. else if fnextfieldname<>'' then
  521. internalerror(2015071501);
  522. currentoffset:=curoffset;
  523. { find next field }
  524. i:=curindex;
  525. repeat
  526. inc(i);
  527. sym:=tsym(tabstractrecorddef(def).symtable.symlist[i]);
  528. until (sym.typ=fieldvarsym) and
  529. not(sp_static in sym.symoptions);
  530. curfield:=tfieldvarsym(sym);
  531. nextoffset:=curfield.fieldoffset;
  532. curindex:=i;
  533. end;
  534. { need padding? }
  535. result:=nextoffset-currentoffset;
  536. end;
  537. {****************************************************************************
  538. ttypedconstplaceholder
  539. ****************************************************************************}
  540. constructor ttypedconstplaceholder.create(d: tdef);
  541. begin
  542. def:=d;
  543. end;
  544. {****************************************************************************
  545. tai_abstracttypedconst
  546. ****************************************************************************}
  547. procedure tai_abstracttypedconst.setdef(def: tdef);
  548. begin
  549. { should not be changed, rewrite the calling code if this happens }
  550. if assigned(fdef) then
  551. Internalerror(2014080203);
  552. fdef:=def;
  553. end;
  554. constructor tai_abstracttypedconst.create(_adetyp: ttypedconstkind; _def: tdef);
  555. begin
  556. inherited create;
  557. typ:=ait_typedconst;
  558. fadetyp:=_adetyp;
  559. fdef:=_def;
  560. end;
  561. {****************************************************************************
  562. tai_simpletypedconst
  563. ****************************************************************************}
  564. procedure tai_simpletypedconst.setval(AValue: tai);
  565. begin
  566. fval:=AValue;
  567. end;
  568. constructor tai_simpletypedconst.create(_def: tdef; _val: tai);
  569. begin
  570. inherited create(tck_simple,_def);
  571. fval:=_val;
  572. end;
  573. destructor tai_simpletypedconst.destroy;
  574. begin
  575. fval.free;
  576. inherited destroy;
  577. end;
  578. {****************************************************************************
  579. tai_aggregatetypedconst.tadeenumerator
  580. ****************************************************************************}
  581. constructor tai_aggregatetypedconst.tadeenumerator.create(data: tai_aggregatetypedconst);
  582. begin
  583. fvalues:=data.fvalues;
  584. fvaluespos:=-1;
  585. end;
  586. function tai_aggregatetypedconst.tadeenumerator.getcurrent: tai_abstracttypedconst;
  587. begin
  588. result:=tai_abstracttypedconst(fvalues[fvaluespos]);
  589. end;
  590. function tai_aggregatetypedconst.tadeenumerator.movenext: boolean;
  591. begin
  592. if fvaluespos<pred(fvalues.count) then
  593. begin
  594. inc(fvaluespos);
  595. result:=true
  596. end
  597. else
  598. result:=false;
  599. end;
  600. procedure tai_aggregatetypedconst.tadeenumerator.reset;
  601. begin
  602. fvaluespos:=0
  603. end;
  604. {****************************************************************************
  605. tai_aggregatetypedconst
  606. ****************************************************************************}
  607. procedure tai_aggregatetypedconst.convert_to_string;
  608. var
  609. ai: tai_abstracttypedconst;
  610. newstr: tai_string;
  611. begin
  612. newstr:=tai_string.Create('');
  613. for ai in self do
  614. begin
  615. if ai.adetyp<>tck_simple then
  616. internalerror(2014070103);
  617. add_to_string(newstr,tai_simpletypedconst(ai).val);
  618. ai.free;
  619. end;
  620. fvalues.count:=0;
  621. { the "nil" def will be replaced with an array def of the appropriate
  622. size once we're finished adding data, so we don't create intermediate
  623. arraydefs all the time }
  624. fvalues.add(tai_simpletypedconst.create(nil,newstr));
  625. end;
  626. procedure tai_aggregatetypedconst.add_to_string(strtai: tai_string; othertai: tai);
  627. begin
  628. case othertai.typ of
  629. ait_string:
  630. begin
  631. strtai.str:=reallocmem(strtai.str,strtai.len+tai_string(othertai).len+1);
  632. { also copy null terminator }
  633. move(tai_string(othertai).str[0],strtai.str[strtai.len],tai_string(othertai).len+1);
  634. { the null terminator is not part of the string data }
  635. strtai.len:=strtai.len+tai_string(othertai).len;
  636. end;
  637. ait_const:
  638. begin
  639. if tai_const(othertai).size<>1 then
  640. internalerror(2014070101);
  641. { it was already len+1 to hold the #0 -> realloc to len+2 }
  642. strtai.str:=reallocmem(strtai.str,strtai.len+2);
  643. strtai.str[strtai.len]:=ansichar(tai_const(othertai).value);
  644. strtai.str[strtai.len+1]:=#0;
  645. inc(strtai.len);
  646. end;
  647. else
  648. internalerror(2014070102);
  649. end;
  650. end;
  651. constructor tai_aggregatetypedconst.create(_adetyp: ttypedconstkind; _fdef: tdef);
  652. begin
  653. inherited;
  654. fisstring:=false;
  655. fvalues:=tfpobjectlist.create(true);
  656. end;
  657. function tai_aggregatetypedconst.getenumerator: tadeenumerator;
  658. begin
  659. result:=tadeenumerator.create(self);
  660. end;
  661. procedure tai_aggregatetypedconst.addvalue(val: tai_abstracttypedconst);
  662. begin
  663. { merge string constants and ordinal constants added in an array of
  664. char, to unify the length and the string data }
  665. if fisstring or
  666. ((val.adetyp=tck_simple) and
  667. (tai_simpletypedconst(val).val.typ=ait_string)) then
  668. begin
  669. if not fisstring and
  670. (fvalues.count>0) then
  671. convert_to_string;
  672. fisstring:=true;
  673. case fvalues.count of
  674. 0: fvalues.add(val);
  675. 1:
  676. begin
  677. add_to_string(tai_string(tai_simpletypedconst(fvalues[0]).val),tai_simpletypedconst(val).val);
  678. val.free
  679. end
  680. else
  681. internalerror(2014070104);
  682. end;
  683. end
  684. else
  685. fvalues.add(val);
  686. end;
  687. function tai_aggregatetypedconst.valuecount: longint;
  688. begin
  689. result:=fvalues.count;
  690. end;
  691. procedure tai_aggregatetypedconst.insertvaluebeforepos(val: tai_abstracttypedconst; pos: longint);
  692. begin
  693. fvalues.insert(pos,val);
  694. end;
  695. procedure tai_aggregatetypedconst.replacevalueatpos(val: tai_abstracttypedconst; pos: longint);
  696. begin
  697. { since fvalues owns its elements, it will automatically free the old value }
  698. fvalues[pos]:=val;
  699. end;
  700. procedure tai_aggregatetypedconst.changetorecord(_def: trecorddef);
  701. begin
  702. { must be a record of the same size as the current data }
  703. if assigned(fdef) and
  704. (fdef.size<>_def.size) then
  705. internalerror(2015122402);
  706. fdef:=_def;
  707. fadetyp:=tck_record;
  708. end;
  709. procedure tai_aggregatetypedconst.finish;
  710. begin
  711. if fisstring then
  712. begin
  713. { set the def: an array of char with the same length as the string
  714. data }
  715. if fvalues.count<>1 then
  716. internalerror(2014070105);
  717. tai_simpletypedconst(fvalues[0]).fdef:=
  718. carraydef.getreusable(cansichartype,
  719. tai_string(tai_simpletypedconst(fvalues[0]).val).len);
  720. end;
  721. end;
  722. destructor tai_aggregatetypedconst.destroy;
  723. var
  724. ai: tai_abstracttypedconst;
  725. begin
  726. fvalues.free;
  727. inherited destroy;
  728. end;
  729. {*****************************************************************************
  730. ttai_typedconstbuilder
  731. *****************************************************************************}
  732. function ttai_typedconstbuilder.getcurragginfo: taggregateinformation;
  733. begin
  734. if assigned(faggregateinformation) and
  735. (faggregateinformation.count>0) then
  736. result:=taggregateinformation(faggregateinformation[faggregateinformation.count-1])
  737. else
  738. result:=nil;
  739. end;
  740. procedure ttai_typedconstbuilder.set_next_field(AValue: tfieldvarsym);
  741. var
  742. info: taggregateinformation;
  743. begin
  744. info:=curagginfo;
  745. if not assigned(info) then
  746. internalerror(2014091206);
  747. info.nextfield:=AValue;
  748. end;
  749. procedure ttai_typedconstbuilder.set_next_field_name(AValue: TIDString);
  750. var
  751. info: taggregateinformation;
  752. begin
  753. info:=curagginfo;
  754. if not assigned(info) then
  755. internalerror(2015071502);
  756. info.nextfieldname:='$'+AValue;
  757. end;
  758. procedure ttai_typedconstbuilder.pad_next_field(nextfielddef: tdef);
  759. var
  760. fillbytes: asizeint;
  761. begin
  762. fillbytes:=curagginfo.prepare_next_field(nextfielddef);
  763. while fillbytes>0 do
  764. begin
  765. do_emit_tai(tai_const.create_8bit(0),u8inttype);
  766. dec(fillbytes);
  767. end;
  768. end;
  769. function ttai_typedconstbuilder.get_internal_data_section_index(typ: TAsmSectiontype): longint;
  770. begin
  771. { avoid wrong warning by -Oodfa }
  772. result:=-1;
  773. for result:=low(finternal_data_section_info) to high(finternal_data_section_info) do
  774. if finternal_data_section_info[result].sectype=typ then
  775. exit;
  776. result:=-1;
  777. end;
  778. function ttai_typedconstbuilder.get_internal_data_section_start_label: tasmlabel;
  779. begin
  780. { on Darwin, dead code/data stripping happens based on non-temporary
  781. labels (any label that doesn't start with "L" -- it doesn't have
  782. to be global) }
  783. if target_info.system in systems_darwin then
  784. current_asmdata.getstaticdatalabel(result)
  785. else if create_smartlink_library then
  786. current_asmdata.getglobaldatalabel(result)
  787. else
  788. current_asmdata.getlocaldatalabel(result);
  789. end;
  790. function ttai_typedconstbuilder.get_internal_data_section_internal_label: tasmlabel;
  791. begin
  792. if create_smartlink_library then
  793. { all labels need to be global in case they're in another object }
  794. current_asmdata.getglobaldatalabel(result)
  795. else
  796. { no special requirement for the label -> just get a local one }
  797. current_asmdata.getlocaldatalabel(result);
  798. end;
  799. function ttai_typedconstbuilder.aggregate_kind(def: tdef): ttypedconstkind;
  800. begin
  801. if (def.typ in [recorddef,filedef,variantdef]) or
  802. is_object(def) or
  803. ((def.typ=procvardef) and
  804. not tprocvardef(def).is_addressonly and
  805. not is_block(def)) then
  806. result:=tck_record
  807. else if ((def.typ=arraydef) and
  808. not is_dynamic_array(def)) or
  809. ((def.typ=setdef) and
  810. not is_smallset(def)) or
  811. is_shortstring(def) then
  812. result:=tck_array
  813. else
  814. result:=tck_simple;
  815. end;
  816. procedure ttai_typedconstbuilder.finalize_asmlist_prepare(const options: ttcasmlistoptions; var alignment: shortint);
  817. begin
  818. if tcalo_apply_constalign in options then
  819. alignment:=const_align(alignment);
  820. { have we finished all aggregates? }
  821. if (getcurragginfo<>nil) and
  822. { in case of syntax errors, the aggregate may not have been finished }
  823. (ErrorCount=0) then
  824. internalerror(2015072301);
  825. { must call finalize_vectorized_dead_strip_asmlist() instead }
  826. if (([tcalo_vectorized_dead_strip_start,
  827. tcalo_vectorized_dead_strip_item,
  828. tcalo_vectorized_dead_strip_end]*options)<>[]) and
  829. not fvectorized_finalize_called then
  830. internalerror(2015110602);
  831. end;
  832. procedure ttai_typedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
  833. var
  834. prelist: tasmlist;
  835. begin
  836. finalize_asmlist_prepare(options, alignment);
  837. prelist:=tasmlist.create;
  838. { only now add items based on the symbolname, because it may be
  839. modified by the "section" specifier in case of a typed constant }
  840. { both in case the data should be dead strippable and never dead
  841. stripped, it should be in a separate section (so this property doesn't
  842. affect other data) }
  843. if ([tcalo_no_dead_strip,tcalo_make_dead_strippable]*options)<>[] then
  844. begin
  845. maybe_new_object_file(prelist);
  846. { we always need a new section here, since if we started a new
  847. object file then we have to say what the section is, and otherwise
  848. we need a new section because that's how the dead stripping works }
  849. new_section(prelist,section,secname,alignment);
  850. end
  851. else if tcalo_new_section in options then
  852. begin
  853. { insert ait_cutobject for smart-linking on targets
  854. that do not support smarlinking based on sections,
  855. like msdos }
  856. if not (tf_smartlink_sections in target_info.flags) then
  857. maybe_new_object_file(prelist);
  858. new_section(prelist,section,secname,alignment);
  859. end
  860. else
  861. prelist.concat(cai_align.Create(alignment));
  862. { On Darwin, use .reference to ensure the data doesn't get dead stripped.
  863. On other platforms, the data must be in the .fpc section (which is
  864. kept via the linker script) }
  865. if tcalo_no_dead_strip in options then
  866. begin
  867. if (target_info.system in systems_darwin) then
  868. begin
  869. { Objective-C section declarations contain "no_dead_strip"
  870. attributes if none of their symbols need to be stripped -> don't
  871. add extra ".reference" statement for their symbols (gcc/clang
  872. don't either) }
  873. if not(section in [low(TObjCAsmSectionType)..high(TObjCAsmSectionType)]) then
  874. prelist.concat(tai_directive.Create(asd_reference,sym.name))
  875. end
  876. else if section<>sec_fpc then
  877. internalerror(2015101402);
  878. end;
  879. if not(tcalo_is_lab in options) then
  880. if sym.bind=AB_LOCAL then
  881. prelist.concat(tai_symbol.Create(sym,0))
  882. else
  883. prelist.concat(tai_symbol.Create_Global(sym,0))
  884. else
  885. prelist.concat(tai_label.Create(tasmlabel(sym)));
  886. if tcalo_weak in options then
  887. prelist.concat(tai_directive.Create(asd_weak_definition,sym.name));
  888. { insert the symbol information before the data }
  889. fasmlist.insertlist(prelist);
  890. { end of the symbol }
  891. fasmlist.concat(tai_symbol_end.Createname(sym.name));
  892. { free the temporary list }
  893. prelist.free;
  894. end;
  895. procedure ttai_typedconstbuilder.finalize_asmlist_add_indirect_sym(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
  896. var
  897. ptrdef : tdef;
  898. symind : tasmsymbol;
  899. indtcb : ttai_typedconstbuilder;
  900. indsecname : tsymstr;
  901. begin
  902. if (tcalo_data_force_indirect in options) and
  903. (sym.bind in [AB_GLOBAL,AB_COMMON]) and
  904. (sym.typ=AT_DATA) then
  905. begin
  906. ptrdef:=cpointerdef.getreusable(def);
  907. symind:=current_asmdata.DefineAsmSymbol(sym.name,AB_INDIRECT,AT_DATA,ptrdef);
  908. { reuse the section if possible }
  909. if section=sec_rodata then
  910. indsecname:=secname
  911. else
  912. indsecname:=lower(symind.name);
  913. indtcb:=ctai_typedconstbuilder.create([tcalo_new_section]);
  914. indtcb.emit_tai(tai_const.create_sym_offset(sym,0),ptrdef);
  915. current_asmdata.asmlists[al_indirectglobals].concatlist(indtcb.get_final_asmlist(
  916. symind,
  917. ptrdef,
  918. sec_rodata,
  919. indsecname,
  920. ptrdef.alignment));
  921. indtcb.free;
  922. if not (target_info.system in systems_indirect_var_imports) then
  923. current_module.add_public_asmsym(symind.name,AB_INDIRECT,AT_DATA);
  924. end;
  925. end;
  926. procedure ttai_typedconstbuilder.finalize_vectorized_dead_strip_asmlist(def: tdef; const basename, itemname: TSymStr; st: tsymtable; alignment: shortint; options: ttcasmlistoptions);
  927. var
  928. sym: tasmsymbol;
  929. secname: TSymStr;
  930. sectype: TAsmSectiontype;
  931. asmtype : TAsmsymtype;
  932. customsecname: boolean;
  933. dsopts : ttcdeadstripsectionsymboloptions;
  934. begin
  935. fvectorized_finalize_called:=true;
  936. sym:=nil;
  937. customsecname:=get_vectorized_dead_strip_custom_section_name(basename,st,secname);
  938. if customsecname then
  939. sectype:=sec_user
  940. else
  941. sectype:=sec_data;
  942. dsopts:=[tcdssso_define];
  943. if tcalo_is_public_asm in options then
  944. include(dsopts,tcdssso_register_asmsym);
  945. if tcalo_data_force_indirect in options then
  946. include(dsopts,tcdssso_use_indirect);
  947. if tcalo_vectorized_dead_strip_start in options then
  948. begin
  949. { the start and end names are predefined }
  950. if itemname<>'' then
  951. internalerror(2015110801);
  952. sym:=get_vectorized_dead_strip_section_symbol_start(basename,st,dsopts);
  953. if not customsecname then
  954. secname:=make_mangledname(basename,st,'1_START');
  955. end
  956. else if tcalo_vectorized_dead_strip_end in options then
  957. begin
  958. { the start and end names are predefined }
  959. if itemname<>'' then
  960. internalerror(2015110802);
  961. sym:=get_vectorized_dead_strip_section_symbol_end(basename,st,dsopts);
  962. if not customsecname then
  963. secname:=make_mangledname(basename,st,'3_END');
  964. end
  965. else if tcalo_vectorized_dead_strip_item in options then
  966. begin
  967. if tcalo_data_force_indirect in options then
  968. asmtype:=AT_DATA_FORCEINDIRECT
  969. else
  970. asmtype:=AT_DATA;
  971. sym:=current_asmdata.DefineAsmSymbol(make_mangledname(basename,st,itemname),AB_GLOBAL,asmtype,def);
  972. if tcalo_is_public_asm in options then
  973. current_module.add_public_asmsym(sym);
  974. if not customsecname then
  975. secname:=make_mangledname(basename,st,'2_'+itemname);
  976. exclude(options,tcalo_vectorized_dead_strip_item);
  977. end;
  978. current_module.linkorderedsymbols.concat(sym.Name);
  979. finalize_asmlist(sym,def,sectype,secname,alignment,options);
  980. end;
  981. procedure ttai_typedconstbuilder.do_emit_tai(p: tai; def: tdef);
  982. begin
  983. { by default we don't care about the type }
  984. fasmlist.concat(p);
  985. end;
  986. function ttai_typedconstbuilder.get_final_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint): tasmlist;
  987. begin
  988. if not fasmlist_finalized then
  989. begin
  990. finalize_asmlist(sym,def,section,secname,alignment,foptions);
  991. finalize_asmlist_add_indirect_sym(sym,def,section,secname,alignment,foptions);
  992. fasmlist_finalized:=true;
  993. end;
  994. result:=fasmlist;
  995. end;
  996. function ttai_typedconstbuilder.get_final_asmlist_vectorized_dead_strip(def: tdef; const basename, itemname: TSymStr; st: TSymtable; alignment: longint): tasmlist;
  997. begin
  998. if not fasmlist_finalized then
  999. begin
  1000. finalize_vectorized_dead_strip_asmlist(def,basename,itemname,st,alignment,foptions);
  1001. fasmlist_finalized:=true;
  1002. end;
  1003. result:=fasmlist;
  1004. end;
  1005. class function ttai_typedconstbuilder.get_string_symofs(typ: tstringtype; winlikewidestring: boolean): pint;
  1006. begin
  1007. { darwin's linker does not support negative offsets }
  1008. if not(target_info.system in systems_darwin) then
  1009. result:=0
  1010. else
  1011. result:=get_string_header_size(typ,winlikewidestring);
  1012. end;
  1013. class function ttai_typedconstbuilder.get_dynarray_symofs:pint;
  1014. begin
  1015. { darwin's linker does not support negative offsets }
  1016. if not (target_info.system in systems_darwin) then
  1017. result:=0
  1018. else
  1019. result:=get_dynarray_header_size;
  1020. end;
  1021. class function ttai_typedconstbuilder.get_string_header_size(typ: tstringtype; winlikewidestring: boolean): pint;
  1022. var
  1023. ansistring_header_size: pint;
  1024. unicodestring_header_size: pint;
  1025. begin
  1026. ansistring_header_size:=
  1027. { encoding }
  1028. 2 +
  1029. { elesize }
  1030. 2 +
  1031. {$ifdef cpu64bitaddr}
  1032. { alignment }
  1033. 4 +
  1034. {$endif cpu64bitaddr}
  1035. { reference count }
  1036. sizesinttype.size +
  1037. { length }
  1038. sizesinttype.size;
  1039. unicodestring_header_size:=ansistring_header_size;
  1040. case typ of
  1041. st_ansistring:
  1042. result:=ansistring_header_size;
  1043. st_unicodestring:
  1044. result:=unicodestring_header_size;
  1045. st_widestring:
  1046. if winlikewidestring then
  1047. result:=0
  1048. else
  1049. result:=unicodestring_header_size;
  1050. else
  1051. result:=0;
  1052. end;
  1053. end;
  1054. class function ttai_typedconstbuilder.get_dynarray_header_size:pint;
  1055. begin
  1056. result:=
  1057. { reference count }
  1058. ptrsinttype.size +
  1059. { high value }
  1060. sizesinttype.size;
  1061. end;
  1062. constructor ttai_typedconstbuilder.create(const options: ttcasmlistoptions);
  1063. begin
  1064. inherited create;
  1065. fasmlist:=tasmlist.create;
  1066. foptions:=options;
  1067. { queue is empty }
  1068. fqueue_offset:=low(fqueue_offset);
  1069. finternal_data_current_section:=sec_none;
  1070. end;
  1071. destructor ttai_typedconstbuilder.destroy;
  1072. begin
  1073. { the queue should have been flushed if it was used }
  1074. if fqueue_offset<>low(fqueue_offset) then
  1075. internalerror(2014062901);
  1076. faggregateinformation.free;
  1077. fasmlist.free;
  1078. inherited destroy;
  1079. end;
  1080. procedure ttai_typedconstbuilder.start_internal_data_builder(list: tasmlist; sectype: TAsmSectiontype; const secname: TSymStr; out tcb: ttai_typedconstbuilder; out l: tasmlabel);
  1081. var
  1082. options: ttcasmlistoptions;
  1083. foundsec: longint;
  1084. begin
  1085. { you can't start multiple concurrent internal data builders for the
  1086. same tcb, finish the first before starting another }
  1087. if finternal_data_current_section<>sec_none then
  1088. internalerror(2016082801);
  1089. { we don't know what was previously added to this list, so always add
  1090. a section header. We'll use the same section name in case multiple
  1091. items are added to the same kind of section (rodata, rodata_no_rel,
  1092. ...), so that everything will still end up in the same section even if
  1093. there are multiple section headers }
  1094. options:=[tcalo_is_lab,tcalo_new_section];
  1095. finternal_data_current_section:=sectype;
  1096. l:=nil;
  1097. { did we already create a section of this type for the internal data of
  1098. this builder? }
  1099. foundsec:=get_internal_data_section_index(sectype);
  1100. if foundsec=-1 then
  1101. begin
  1102. { we only need to start a dead-strippable section of data at the
  1103. start of the first subsection of this kind for this block.
  1104. exception: if dead stripping happens based on objects/libraries,
  1105. then we only have to create a new object file for the first
  1106. internal data section of any kind (all the rest will simply be put
  1107. in the same object file) }
  1108. if create_smartlink then
  1109. begin
  1110. if not create_smartlink_library or
  1111. (length(finternal_data_section_info)=0) then
  1112. include(options,tcalo_make_dead_strippable);
  1113. { on Darwin, dead code/data stripping happens based on non-
  1114. temporary labels (any label that doesn't start with "L" -- it
  1115. doesn't have to be global) -> add a non-temporary lobel at the
  1116. start of every kind of subsection created in this builder }
  1117. if target_info.system in systems_darwin then
  1118. l:=get_internal_data_section_start_label;
  1119. end;
  1120. foundsec:=length(finternal_data_section_info);
  1121. setlength(finternal_data_section_info,foundsec+1);
  1122. finternal_data_section_info[foundsec].sectype:=sectype;
  1123. end;
  1124. if not assigned(finternal_data_asmlist) and
  1125. (cs_create_smart in current_settings.moduleswitches) then
  1126. begin
  1127. l:=get_internal_data_section_start_label;
  1128. { the internal data list should only be assigned by this routine,
  1129. the first time that an internal data block is started }
  1130. if not assigned(list) or
  1131. assigned(finternal_data_asmlist) then
  1132. internalerror(2015032101);
  1133. finternal_data_asmlist:=list;
  1134. end
  1135. { all internal data for this tcb must go to the same list (otherwise all
  1136. data we want to add to the dead-strippable block is not guaranteed to
  1137. be sequential and e.g. in the same object file in case of library-based
  1138. dead stripping) }
  1139. else if (assigned(finternal_data_asmlist) and
  1140. (list<>finternal_data_asmlist)) or
  1141. not assigned(list) then
  1142. internalerror(2015032101);
  1143. finternal_data_asmlist:=list;
  1144. if not assigned(l) then
  1145. l:=get_internal_data_section_internal_label;
  1146. { first section of this kind -> set name }
  1147. if finternal_data_section_info[foundsec].secname='' then
  1148. if secname='' then
  1149. finternal_data_section_info[foundsec].secname:=l.Name
  1150. else
  1151. finternal_data_section_info[foundsec].secname:=secname
  1152. { if the name is specified multiple times, it must match }
  1153. else if (secname<>'') and
  1154. (finternal_data_section_info[foundsec].secname<>secname) then
  1155. internalerror(2015032401);
  1156. tcb:=ttai_typedconstbuilderclass(classtype).create(options);
  1157. end;
  1158. procedure ttai_typedconstbuilder.finish_internal_data_builder(var tcb: ttai_typedconstbuilder; l: tasmlabel; def: tdef; alignment: longint);
  1159. begin
  1160. finternal_data_asmlist.concatList(tcb.get_final_asmlist(l,def,
  1161. finternal_data_current_section,
  1162. finternal_data_section_info[get_internal_data_section_index(finternal_data_current_section)].secname,
  1163. alignment));
  1164. tcb.free;
  1165. tcb:=nil;
  1166. finternal_data_current_section:=sec_none;
  1167. end;
  1168. procedure ttai_typedconstbuilder.emit_tai(p: tai; def: tdef);
  1169. var
  1170. kind: ttypedconstkind;
  1171. info: taggregateinformation;
  1172. begin
  1173. { these elements can be aggregates themselves, e.g. a shortstring can
  1174. be emitted as a series of bytes and char arrays }
  1175. kind:=aggregate_kind(def);
  1176. info:=curagginfo;
  1177. if (kind<>tck_simple) and
  1178. (not assigned(info) or
  1179. (info.typ<>kind)) then
  1180. internalerror(2014091001);
  1181. { if we're emitting a record, handle the padding bytes, and in case of
  1182. an anonymous record also add the next field }
  1183. if assigned(info) then
  1184. begin
  1185. { queue_init already adds padding }
  1186. if not queue_is_active and
  1187. (is_record(info.def) or
  1188. is_object(info.def)) and
  1189. { may add support for these later }
  1190. not is_packed_record_or_object(info.def) then
  1191. pad_next_field(def);
  1192. end;
  1193. { emit the data }
  1194. do_emit_tai(p,def);
  1195. end;
  1196. procedure ttai_typedconstbuilder.emit_tai_procvar2procdef(p: tai; pvdef: tprocvardef);
  1197. begin
  1198. { nothing special by default, since we don't care about the type }
  1199. emit_tai(p,pvdef);
  1200. end;
  1201. procedure ttai_typedconstbuilder.maybe_emit_tail_padding(def: tdef);
  1202. var
  1203. info: taggregateinformation;
  1204. fillbytes: asizeint;
  1205. begin
  1206. info:=curagginfo;
  1207. if not assigned(info) then
  1208. internalerror(2014091002);
  1209. if def<>info.def then
  1210. internalerror(2014091205);
  1211. if (is_record(def) or
  1212. is_object(def)) and
  1213. not is_packed_record_or_object(def) then
  1214. begin
  1215. fillbytes:=def.size-info.curoffset;
  1216. while fillbytes>0 do
  1217. begin
  1218. do_emit_tai(Tai_const.Create_8bit(0),u8inttype);
  1219. dec(fillbytes)
  1220. end;
  1221. end;
  1222. end;
  1223. function ttai_typedconstbuilder.emit_string_const_common(stringtype: tstringtype; len: asizeint; encoding: tstringencoding; var startlab: tasmlabel): tasmlabofs;
  1224. var
  1225. string_symofs: asizeint;
  1226. charptrdef: tdef;
  1227. elesize: word;
  1228. begin
  1229. result.lab:=startlab;
  1230. result.ofs:=0;
  1231. { pack the data, so that we don't add unnecessary null bytes after the
  1232. constant string }
  1233. begin_anonymous_record('$'+get_dynstring_rec_name(stringtype,false,len),1,sizeof(TConstPtrUInt),1);
  1234. string_symofs:=get_string_symofs(stringtype,false);
  1235. { encoding }
  1236. emit_tai(tai_const.create_16bit(encoding),u16inttype);
  1237. inc(result.ofs,2);
  1238. { element size }
  1239. case stringtype of
  1240. st_ansistring:
  1241. begin
  1242. elesize:=1;
  1243. charptrdef:=charpointertype;
  1244. end;
  1245. st_unicodestring:
  1246. begin
  1247. elesize:=2;
  1248. charptrdef:=widecharpointertype;
  1249. end
  1250. else
  1251. internalerror(2014080401);
  1252. end;
  1253. emit_tai(tai_const.create_16bit(elesize),u16inttype);
  1254. inc(result.ofs,2);
  1255. {$ifdef cpu64bitaddr}
  1256. { dummy for alignment }
  1257. emit_tai(tai_const.create_32bit(0),u32inttype);
  1258. inc(result.ofs,4);
  1259. {$endif cpu64bitaddr}
  1260. emit_tai(tai_const.create_sizeint(-1),sizesinttype);
  1261. inc(result.ofs,sizesinttype.size);
  1262. emit_tai(tai_const.create_sizeint(len),sizesinttype);
  1263. inc(result.ofs,sizesinttype.size);
  1264. if string_symofs=0 then
  1265. begin
  1266. { results in slightly more efficient code }
  1267. emit_tai(tai_label.create(result.lab),charptrdef);
  1268. result.ofs:=0;
  1269. { create new label of the same kind (including whether or not the
  1270. name starts with target_asm.labelprefix in case it's AB_LOCAL,
  1271. so we keep the difference depending on whether the original was
  1272. allocated via getstatic/getlocal/getglobal datalabel) }
  1273. startlab:=tasmlabel.create(current_asmdata.AsmSymbolDict,startlab.name+'$strlab',startlab.bind,startlab.typ);
  1274. end;
  1275. { sanity check }
  1276. if result.ofs<>string_symofs then
  1277. internalerror(2012051701);
  1278. end;
  1279. function ttai_typedconstbuilder.get_dynstring_def_for_type(stringtype: tstringtype; winlikewidestring: boolean): tstringdef;
  1280. begin
  1281. if stringtype=st_ansistring then
  1282. result:=tstringdef(cansistringtype)
  1283. else if (stringtype=st_unicodestring) or
  1284. ((stringtype=st_widestring) and
  1285. not winlikewidestring) then
  1286. result:=tstringdef(cunicodestringtype)
  1287. else if stringtype=st_widestring then
  1288. result:=tstringdef(cwidestringtype)
  1289. else
  1290. internalerror(2015122101);
  1291. end;
  1292. procedure ttai_typedconstbuilder.begin_aggregate_internal(def: tdef; anonymous: boolean);
  1293. var
  1294. info: taggregateinformation;
  1295. tck: ttypedconstkind;
  1296. begin
  1297. tck:=aggregate_kind(def);
  1298. if tck=tck_simple then
  1299. exit;
  1300. if not assigned(faggregateinformation) then
  1301. faggregateinformation:=tfpobjectlist.create
  1302. { if we're starting an anonymous record, we can't align it yet because
  1303. the alignment depends on the fields that will be added -> we'll do
  1304. it at the end }
  1305. else if not anonymous or
  1306. ((def.typ<>recorddef) and
  1307. not is_object(def)) then
  1308. begin
  1309. { add padding if necessary, and update the current field/offset }
  1310. info:=curagginfo;
  1311. if (is_record(curagginfo.def) or
  1312. is_object(curagginfo.def)) and
  1313. not is_packed_record_or_object(curagginfo.def) then
  1314. begin
  1315. if queue_is_active then
  1316. internalerror(2015073001);
  1317. pad_next_field(def);
  1318. end;
  1319. end
  1320. { if this is the outer record, no padding is required; the alignment
  1321. has to be specified explicitly in that case via get_final_asmlist() }
  1322. else if assigned(curagginfo) and
  1323. (curagginfo.def.typ=recorddef) then
  1324. { mark where we'll have to insert the padding bytes at the end }
  1325. mark_anon_aggregate_alignment;
  1326. info:=caggregateinformation.create(def,aggregate_kind(def));
  1327. faggregateinformation.add(info);
  1328. end;
  1329. procedure ttai_typedconstbuilder.end_aggregate_internal(def: tdef; anonymous: boolean);
  1330. var
  1331. info: taggregateinformation;
  1332. tck: ttypedconstkind;
  1333. begin
  1334. tck:=aggregate_kind(def);
  1335. if tck=tck_simple then
  1336. exit;
  1337. { add tail padding if necessary }
  1338. maybe_emit_tail_padding(def);
  1339. { pop and free the information }
  1340. info:=curagginfo;
  1341. faggregateinformation.count:=faggregateinformation.count-1;
  1342. info.free;
  1343. end;
  1344. class function ttai_typedconstbuilder.get_vectorized_dead_strip_section_symbol(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions; start: boolean): tasmsymbol;
  1345. var
  1346. name: TSymStr;
  1347. asmtype : TAsmsymtype;
  1348. begin
  1349. if start then
  1350. name:=make_mangledname(basename,st,'START')
  1351. else
  1352. name:=make_mangledname(basename,st,'END');
  1353. if tcdssso_define in options then
  1354. begin
  1355. if tcdssso_use_indirect in options then
  1356. asmtype:=AT_DATA_FORCEINDIRECT
  1357. else
  1358. asmtype:=AT_DATA;
  1359. result:=current_asmdata.DefineAsmSymbol(name,AB_GLOBAL,asmtype,voidpointertype);
  1360. if tcdssso_register_asmsym in options then
  1361. current_module.add_public_asmsym(result);
  1362. end
  1363. else
  1364. begin
  1365. result:=current_asmdata.RefAsmSymbol(name,AT_DATA,tcdssso_use_indirect in options);
  1366. if tcdssso_register_asmsym in options then
  1367. current_module.add_extern_asmsym(result);
  1368. end;
  1369. end;
  1370. class function ttai_typedconstbuilder.get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; out secname: TSymStr): boolean;
  1371. begin
  1372. result:=false;
  1373. end;
  1374. class function ttai_typedconstbuilder.get_vectorized_dead_strip_section_symbol_start(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol;
  1375. begin
  1376. result:=get_vectorized_dead_strip_section_symbol(basename,st,options,true);
  1377. end;
  1378. class function ttai_typedconstbuilder.get_vectorized_dead_strip_section_symbol_end(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol;
  1379. begin
  1380. result:=get_vectorized_dead_strip_section_symbol(basename,st,options,false);
  1381. end;
  1382. class function ttai_typedconstbuilder.get_dynstring_rec_name(typ: tstringtype; winlike: boolean; len: asizeint): TSymStr;
  1383. begin
  1384. case typ of
  1385. st_ansistring:
  1386. result:='ansistrrec';
  1387. st_unicodestring,
  1388. st_widestring:
  1389. if (typ=st_unicodestring) or
  1390. not winlike then
  1391. result:='unicodestrrec'
  1392. else
  1393. result:='widestrrec';
  1394. else
  1395. internalerror(2014080402);
  1396. end;
  1397. result:=result+tostr(len);
  1398. end;
  1399. class function ttai_typedconstbuilder.get_dynstring_rec(typ: tstringtype; winlike: boolean; len: asizeint): trecorddef;
  1400. var
  1401. name: TSymStr;
  1402. streledef: tdef;
  1403. strtypesym: ttypesym;
  1404. srsym: tsym;
  1405. srsymtable: tsymtable;
  1406. begin
  1407. name:=get_dynstring_rec_name(typ,winlike,len);
  1408. { search in the interface of all units for the type to reuse it }
  1409. if searchsym_type(name,srsym,srsymtable) then
  1410. begin
  1411. result:=trecorddef(ttypesym(srsym).typedef);
  1412. exit;
  1413. end
  1414. else
  1415. begin
  1416. { also search the implementation of the current unit }
  1417. strtypesym:=try_search_current_module_type(name);
  1418. if assigned(strtypesym) then
  1419. begin
  1420. result:=trecorddef(strtypesym.typedef);
  1421. exit;
  1422. end;
  1423. end;
  1424. if (typ<>st_widestring) or
  1425. not winlike then
  1426. begin
  1427. result:=crecorddef.create_global_internal('$'+name,1,1);
  1428. { encoding }
  1429. result.add_field_by_def('',u16inttype);
  1430. { element size }
  1431. result.add_field_by_def('',u16inttype);
  1432. { elements }
  1433. case typ of
  1434. st_ansistring:
  1435. streledef:=cansichartype;
  1436. st_unicodestring:
  1437. streledef:=cwidechartype;
  1438. else
  1439. internalerror(2016082301);
  1440. end;
  1441. {$ifdef cpu64bitaddr}
  1442. { dummy for alignment }
  1443. result.add_field_by_def('',u32inttype);
  1444. {$endif cpu64bitaddr}
  1445. { reference count }
  1446. result.add_field_by_def('',sizesinttype);
  1447. { length in elements }
  1448. result.add_field_by_def('',sizesinttype);
  1449. end
  1450. else
  1451. begin
  1452. result:=crecorddef.create_global_internal('$'+name,4,
  1453. targetinfos[target_info.system]^.alignment.recordalignmin);
  1454. { length in bytes }
  1455. result.add_field_by_def('',s32inttype);
  1456. streledef:=cwidechartype;
  1457. end;
  1458. { data (include zero terminator) }
  1459. result.add_field_by_def('',carraydef.getreusable(streledef,len+1));
  1460. trecordsymtable(trecorddef(result).symtable).addalignmentpadding;
  1461. end;
  1462. function ttai_typedconstbuilder.emit_ansistring_const(datalist: TAsmList; data: pchar; len: asizeint; encoding: tstringencoding): tasmlabofs;
  1463. var
  1464. s: PChar;
  1465. startlab: tasmlabel;
  1466. ansistrrecdef: trecorddef;
  1467. datadef: tdef;
  1468. datatcb: ttai_typedconstbuilder;
  1469. begin
  1470. start_internal_data_builder(datalist,sec_rodata_norel,'',datatcb,startlab);
  1471. result:=datatcb.emit_string_const_common(st_ansistring,len,encoding,startlab);
  1472. getmem(s,len+1);
  1473. move(data^,s^,len);
  1474. s[len]:=#0;
  1475. { terminating zero included }
  1476. datadef:=carraydef.getreusable(cansichartype,len+1);
  1477. datatcb.maybe_begin_aggregate(datadef);
  1478. datatcb.emit_tai(tai_string.create_pchar(s,len+1),datadef);
  1479. datatcb.maybe_end_aggregate(datadef);
  1480. ansistrrecdef:=datatcb.end_anonymous_record;
  1481. finish_internal_data_builder(datatcb,startlab,ansistrrecdef,const_align(voidpointertype.alignment));
  1482. end;
  1483. function ttai_typedconstbuilder.emit_unicodestring_const(datalist: TAsmList; data: pointer; encoding: tstringencoding; winlike: boolean):tasmlabofs;
  1484. var
  1485. i, strlength: longint;
  1486. string_symofs: asizeint;
  1487. startlab: tasmlabel;
  1488. datadef: tdef;
  1489. datatcb: ttai_typedconstbuilder;
  1490. unicodestrrecdef: trecorddef;
  1491. begin
  1492. start_internal_data_builder(datalist,sec_rodata_norel,'',datatcb,startlab);
  1493. strlength:=getlengthwidestring(pcompilerwidestring(data));
  1494. if winlike then
  1495. begin
  1496. result.lab:=startlab;
  1497. datatcb.begin_anonymous_record('$'+get_dynstring_rec_name(st_widestring,true,strlength),
  1498. 4,4,
  1499. targetinfos[target_info.system]^.alignment.recordalignmin);
  1500. datatcb.emit_tai(Tai_const.Create_32bit(strlength*cwidechartype.size),s32inttype);
  1501. { can we optimise by placing the string constant label at the
  1502. required offset? }
  1503. string_symofs:=get_string_symofs(st_widestring,true);
  1504. if string_symofs=0 then
  1505. begin
  1506. { yes }
  1507. datatcb.emit_tai(Tai_label.Create(result.lab),widecharpointertype);
  1508. { allocate a separate label for the start of the data (see
  1509. emit_string_const_common() for explanation) }
  1510. startlab:=tasmlabel.create(current_asmdata.AsmSymbolDict,startlab.name+'$strlab',startlab.bind,startlab.typ);
  1511. end
  1512. else
  1513. internalerror(2015031502);
  1514. result.ofs:=string_symofs;
  1515. end
  1516. else
  1517. begin
  1518. result:=datatcb.emit_string_const_common(st_unicodestring,strlength,encoding,startlab);
  1519. end;
  1520. if cwidechartype.size = 2 then
  1521. begin
  1522. datadef:=carraydef.getreusable(cwidechartype,strlength+1);
  1523. datatcb.maybe_begin_aggregate(datadef);
  1524. for i:=0 to strlength-1 do
  1525. datatcb.emit_tai(Tai_const.Create_16bit(pcompilerwidestring(data)^.data[i]),cwidechartype);
  1526. { ending #0 }
  1527. datatcb.emit_tai(Tai_const.Create_16bit(0),cwidechartype);
  1528. datatcb.maybe_end_aggregate(datadef);
  1529. unicodestrrecdef:=datatcb.end_anonymous_record;
  1530. end
  1531. else
  1532. { code generation for other sizes must be written }
  1533. internalerror(200904271);
  1534. finish_internal_data_builder(datatcb,startlab,unicodestrrecdef,const_align(voidpointertype.alignment));
  1535. end;
  1536. procedure ttai_typedconstbuilder.emit_string_offset(const ll: tasmlabofs; const strlength: longint; const st: tstringtype; const winlikewidestring: boolean; const charptrdef: tdef);
  1537. begin
  1538. emit_tai(Tai_const.Create_sym_offset(ll.lab,ll.ofs),get_dynstring_def_for_type(st,winlikewidestring));
  1539. end;
  1540. procedure ttai_typedconstbuilder.emit_dynarray_offset(const ll:tasmlabofs;const arrlength:asizeint;const arrdef:tarraydef; const arrconstdatadef: trecorddef);
  1541. begin
  1542. emit_tai(tai_const.create_sym_offset(ll.lab,ll.ofs),arrdef);
  1543. end;
  1544. function ttai_typedconstbuilder.begin_dynarray_const(arrdef:tdef;var startlab:tasmlabel;out arrlengthloc:ttypedconstplaceholder):tasmlabofs;
  1545. var
  1546. dynarray_symofs: asizeint;
  1547. begin
  1548. result.lab:=startlab;
  1549. result.ofs:=0;
  1550. { pack the data, so that we don't add unnecessary null bytes after the
  1551. constant string }
  1552. begin_anonymous_record('',1,sizeof(TConstPtrUInt),1);
  1553. dynarray_symofs:=get_dynarray_symofs;
  1554. { what to do if ptrsinttype <> sizesinttype??? }
  1555. emit_tai(tai_const.create_sizeint(-1),ptrsinttype);
  1556. inc(result.ofs,ptrsinttype.size);
  1557. arrlengthloc:=emit_placeholder(sizesinttype);
  1558. inc(result.ofs,sizesinttype.size);
  1559. if dynarray_symofs=0 then
  1560. begin
  1561. { results in slightly more efficient code }
  1562. emit_tai(tai_label.create(result.lab),arrdef);
  1563. result.ofs:=0;
  1564. { create new label of the same kind (including whether or not the
  1565. name starts with target_asm.labelprefix in case it's AB_LOCAL,
  1566. so we keep the difference depending on whether the original was
  1567. allocated via getstatic/getlocal/getglobal datalabel) }
  1568. startlab:=tasmlabel.create(current_asmdata.AsmSymbolDict,startlab.name+'$dynarrlab',startlab.bind,startlab.typ);
  1569. end;
  1570. { sanity check }
  1571. if result.ofs<>dynarray_symofs then
  1572. internalerror(2018020601);
  1573. end;
  1574. function ttai_typedconstbuilder.end_dynarray_const(arrdef:tdef;arrlength:asizeint;arrlengthloc:ttypedconstplaceholder):tdef;
  1575. begin
  1576. { we emit the high value, not the count }
  1577. arrlengthloc.replace(tai_const.Create_sizeint(arrlength-1),sizesinttype);
  1578. result:=end_anonymous_record;
  1579. end;
  1580. function ttai_typedconstbuilder.emit_shortstring_const(const str: shortstring): tdef;
  1581. begin
  1582. { we use an arraydef instead of a shortstringdef, because we don't have
  1583. functionality in place yet to reuse shortstringdefs of the same length
  1584. and neither the lowlevel nor the llvm typedconst builder cares about
  1585. this difference }
  1586. result:=carraydef.getreusable(cansichartype,length(str)+1);
  1587. maybe_begin_aggregate(result);
  1588. emit_tai(Tai_const.Create_8bit(length(str)),u8inttype);
  1589. if str<>'' then
  1590. emit_tai(Tai_string.Create(str),carraydef.getreusable(cansichartype,length(str)));
  1591. maybe_end_aggregate(result);
  1592. end;
  1593. function ttai_typedconstbuilder.emit_pchar_const(str: pchar; len: pint; copypchar: boolean): tdef;
  1594. var
  1595. newstr: pchar;
  1596. begin
  1597. result:=carraydef.getreusable(cansichartype,len+1);
  1598. maybe_begin_aggregate(result);
  1599. if (len=0) and
  1600. (not assigned(str) or
  1601. copypchar) then
  1602. emit_tai(Tai_const.Create_8bit(0),cansichartype)
  1603. else
  1604. begin
  1605. if copypchar then
  1606. begin
  1607. getmem(newstr,len+1);
  1608. move(str^,newstr^,len+1);
  1609. str:=newstr;
  1610. end;
  1611. emit_tai(Tai_string.Create_pchar(str,len+1),result);
  1612. end;
  1613. maybe_end_aggregate(result);
  1614. end;
  1615. procedure ttai_typedconstbuilder.emit_guid_const(const guid: tguid);
  1616. var
  1617. i: longint;
  1618. field: tfieldvarsym;
  1619. begin
  1620. maybe_begin_aggregate(rec_tguid);
  1621. { variant record -> must specify which fields get initialised }
  1622. next_field:=tfieldvarsym(rec_tguid.symtable.Find('DATA1'));
  1623. emit_tai(Tai_const.Create_32bit(longint(guid.D1)),u32inttype);
  1624. next_field:=tfieldvarsym(rec_tguid.symtable.Find('DATA2'));
  1625. emit_tai(Tai_const.Create_16bit(guid.D2),u16inttype);
  1626. next_field:=tfieldvarsym(rec_tguid.symtable.Find('DATA3'));
  1627. emit_tai(Tai_const.Create_16bit(guid.D3),u16inttype);
  1628. field:=tfieldvarsym(rec_tguid.symtable.Find('DATA4'));
  1629. next_field:=field;
  1630. { the array }
  1631. maybe_begin_aggregate(field.vardef);
  1632. for i:=Low(guid.D4) to High(guid.D4) do
  1633. emit_tai(Tai_const.Create_8bit(guid.D4[i]),u8inttype);
  1634. maybe_end_aggregate(field.vardef);
  1635. maybe_end_aggregate(rec_tguid);
  1636. end;
  1637. procedure ttai_typedconstbuilder.emit_procdef_const(pd: tprocdef);
  1638. begin
  1639. emit_tai(Tai_const.Createname(pd.mangledname,AT_FUNCTION,0),cprocvardef.getreusableprocaddr(pd));
  1640. end;
  1641. procedure ttai_typedconstbuilder.emit_ord_const(value: int64; def: tdef);
  1642. begin
  1643. case def.size of
  1644. 1:
  1645. emit_tai(Tai_const.Create_8bit(byte(value)),def);
  1646. 2:
  1647. emit_tai(Tai_const.Create_16bit(word(value)),def);
  1648. 4:
  1649. emit_tai(Tai_const.Create_32bit(longint(value)),def);
  1650. 8:
  1651. emit_tai(Tai_const.Create_64bit(value),def);
  1652. else
  1653. internalerror(2014100501);
  1654. end;
  1655. end;
  1656. procedure ttai_typedconstbuilder.emit_pooled_shortstring_const_ref(const str:shortstring);
  1657. var
  1658. pool : thashset;
  1659. entry : phashsetitem;
  1660. strlab : tasmlabel;
  1661. l : longint;
  1662. pc : pansichar;
  1663. datadef : tdef;
  1664. strtcb : ttai_typedconstbuilder;
  1665. begin
  1666. pool:=current_asmdata.ConstPools[sp_shortstr];
  1667. entry:=pool.FindOrAdd(@str[1],length(str));
  1668. { :-(, we must generate a new entry }
  1669. if not assigned(entry^.Data) then
  1670. begin
  1671. current_asmdata.getglobaldatalabel(strlab);
  1672. { include length and terminating zero for quick conversion to pchar }
  1673. l:=length(str);
  1674. getmem(pc,l+2);
  1675. move(str[1],pc[1],l);
  1676. pc[0]:=chr(l);
  1677. pc[l+1]:=#0;
  1678. datadef:=carraydef.getreusable(cansichartype,l+2);
  1679. { we start a new constbuilder as we don't know whether we're called
  1680. from inside an internal constbuilder }
  1681. strtcb:=ctai_typedconstbuilder.create([tcalo_is_lab,tcalo_make_dead_strippable,tcalo_apply_constalign]);
  1682. strtcb.maybe_begin_aggregate(datadef);
  1683. strtcb.emit_tai(Tai_string.Create_pchar(pc,l+2),datadef);
  1684. strtcb.maybe_end_aggregate(datadef);
  1685. current_asmdata.asmlists[al_typedconsts].concatList(
  1686. strtcb.get_final_asmlist(strlab,datadef,sec_rodata_norel,strlab.name,const_align(sizeof(pint)))
  1687. );
  1688. strtcb.free;
  1689. entry^.Data:=strlab;
  1690. end
  1691. else
  1692. strlab:=tasmlabel(entry^.Data);
  1693. emit_tai(tai_const.Create_sym(strlab),charpointertype);
  1694. end;
  1695. procedure ttai_typedconstbuilder.maybe_begin_aggregate(def: tdef);
  1696. begin
  1697. begin_aggregate_internal(def,false);
  1698. end;
  1699. procedure ttai_typedconstbuilder.maybe_end_aggregate(def: tdef);
  1700. begin
  1701. end_aggregate_internal(def,false);
  1702. end;
  1703. function ttai_typedconstbuilder.begin_anonymous_record(const optionalname: string; packrecords, recordalign, recordalignmin: shortint): trecorddef;
  1704. var
  1705. anonrecorddef: trecorddef;
  1706. typesym: ttypesym;
  1707. begin
  1708. { if the name is specified, we create a typesym with that name in order
  1709. to ensure we can find it again later with that name -> reuse here as
  1710. well if possible (and that also avoids duplicate type name issues) }
  1711. if optionalname<>'' then
  1712. begin
  1713. typesym:=try_search_current_module_type(optionalname);
  1714. if assigned(typesym) then
  1715. begin
  1716. if typesym.typedef.typ<>recorddef then
  1717. internalerror(2015071401);
  1718. result:=trecorddef(typesym.typedef);
  1719. maybe_begin_aggregate(result);
  1720. exit;
  1721. end;
  1722. end;
  1723. { create skeleton def }
  1724. anonrecorddef:=crecorddef.create_global_internal(optionalname,packrecords,recordalignmin);
  1725. trecordsymtable(anonrecorddef.symtable).recordalignment:=recordalign;
  1726. { generic aggregate housekeeping }
  1727. begin_aggregate_internal(anonrecorddef,true);
  1728. { mark as anonymous record }
  1729. curagginfo.anonrecord:=true;
  1730. { in case a descendent wants to do something with the anonrecorddef too }
  1731. result:=anonrecorddef;
  1732. end;
  1733. function ttai_typedconstbuilder.end_anonymous_record: trecorddef;
  1734. var
  1735. info: taggregateinformation;
  1736. anonrecord: boolean;
  1737. begin
  1738. info:=curagginfo;
  1739. if not assigned(info) or
  1740. (info.def.typ<>recorddef) then
  1741. internalerror(2014080201);
  1742. result:=trecorddef(info.def);
  1743. { make a copy, as we need it after info has been freed by
  1744. maybe_end_aggregate(result) }
  1745. anonrecord:=info.anonrecord;
  1746. { finalise the record skeleton (all fields have been added already by
  1747. emit_tai()) -- anonrecord may not be set in case we reused an earlier
  1748. constructed def }
  1749. if anonrecord then
  1750. trecordsymtable(result.symtable).addalignmentpadding;
  1751. end_aggregate_internal(result,true);
  1752. if anonrecord and
  1753. assigned(curagginfo) and
  1754. (curagginfo.def.typ=recorddef) then
  1755. insert_marked_aggregate_alignment(result);
  1756. end;
  1757. procedure ttai_typedconstbuilder.check_add_placeholder(def: tdef);
  1758. begin
  1759. { it only makes sense to add a placeholder inside an aggregate
  1760. (otherwise there can be but one element)
  1761. we cannot add a placeholder in the middle of a queued expression
  1762. either
  1763. the placeholder cannot be an aggregate }
  1764. if not assigned(curagginfo) or
  1765. queue_is_active or
  1766. (aggregate_kind(def)<>tck_simple) then
  1767. internalerror(2015091001);
  1768. end;
  1769. procedure ttai_typedconstbuilder.queue_init(todef: tdef);
  1770. var
  1771. info: taggregateinformation;
  1772. begin
  1773. { nested call to init? }
  1774. if fqueue_offset<>low(fqueue_offset) then
  1775. internalerror(2014062101);
  1776. { insert padding bytes before starting the queue, so that the first
  1777. padding byte won't be interpreted as the emitted value for this queue }
  1778. info:=curagginfo;
  1779. if assigned(info) then
  1780. begin
  1781. if ((info.def.typ=recorddef) or
  1782. is_object(info.def)) and
  1783. { may add support for these later }
  1784. not is_packed_record_or_object(info.def) then
  1785. pad_next_field(todef);
  1786. end;
  1787. fqueue_offset:=0;
  1788. fqueued_def:=todef;
  1789. end;
  1790. procedure ttai_typedconstbuilder.queue_vecn(def: tdef; const index: tconstexprint);
  1791. var
  1792. elelen,
  1793. vecbase: asizeint;
  1794. v: tconstexprint;
  1795. begin
  1796. elelen:=1;
  1797. vecbase:=0;
  1798. case def.typ of
  1799. stringdef :
  1800. ;
  1801. arraydef :
  1802. begin
  1803. if not is_packed_array(def) then
  1804. begin
  1805. elelen:=tarraydef(def).elesize;
  1806. vecbase:=tarraydef(def).lowrange;
  1807. end
  1808. else
  1809. Message(parser_e_packed_dynamic_open_array);
  1810. end;
  1811. else
  1812. Message(parser_e_illegal_expression);
  1813. end;
  1814. { Prevent overflow }
  1815. v:=index-vecbase;
  1816. if (v<int64(low(fqueue_offset))) or (v>int64(high(fqueue_offset))) then
  1817. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(fqueue_offset)),tostr(high(fqueue_offset)));
  1818. if high(fqueue_offset)-fqueue_offset div elelen>v then
  1819. inc(fqueue_offset,elelen*v.svalue)
  1820. else
  1821. message3(type_e_range_check_error_bounds,tostr(index),tostr(vecbase),tostr(high(fqueue_offset)-fqueue_offset div elelen+vecbase))
  1822. end;
  1823. procedure ttai_typedconstbuilder.queue_subscriptn(def: tabstractrecorddef; vs: tfieldvarsym);
  1824. begin
  1825. inc(fqueue_offset,vs.fieldoffset);
  1826. end;
  1827. function ttai_typedconstbuilder.queue_subscriptn_multiple_by_name(def: tabstractrecorddef; const fields: array of TIDString): tdef;
  1828. var
  1829. syms,
  1830. parentdefs: tfplist;
  1831. sym: tsym;
  1832. curdef: tdef;
  1833. i: longint;
  1834. begin
  1835. result:=nil;
  1836. if length(fields)=0 then
  1837. internalerror(2015071601);
  1838. syms:=tfplist.Create;
  1839. syms.count:=length(fields);
  1840. parentdefs:=tfplist.create;
  1841. parentdefs.Count:=length(fields);
  1842. curdef:=def;
  1843. for i:=low(fields) to high(fields) do
  1844. begin
  1845. sym:=search_struct_member_no_helper(tabstractrecorddef(curdef),fields[i]);
  1846. if not assigned(sym) or
  1847. (sym.typ<>fieldvarsym) or
  1848. ((i<>high(fields)) and
  1849. not(tfieldvarsym(sym).vardef.typ in [objectdef,recorddef])) then
  1850. internalerror(2015071505);
  1851. syms[i]:=sym;
  1852. parentdefs[i]:=curdef;
  1853. curdef:=tfieldvarsym(sym).vardef;
  1854. result:=curdef;
  1855. end;
  1856. for i:=high(fields) downto low(fields) do
  1857. queue_subscriptn(tabstractrecorddef(parentdefs[i]),tfieldvarsym(syms[i]));
  1858. syms.free;
  1859. parentdefs.free;
  1860. end;
  1861. procedure ttai_typedconstbuilder.queue_typeconvn(fromdef, todef: tdef);
  1862. begin
  1863. { do nothing }
  1864. end;
  1865. procedure ttai_typedconstbuilder.queue_emit_proc(pd: tprocdef);
  1866. begin
  1867. if fqueue_offset<>0 then
  1868. internalerror(2014092101);
  1869. emit_procdef_const(pd);
  1870. fqueue_offset:=low(fqueue_offset);
  1871. end;
  1872. procedure ttai_typedconstbuilder.queue_emit_staticvar(vs: tstaticvarsym);
  1873. begin
  1874. { pointerdef because we are emitting a pointer to the staticvarsym
  1875. data, not the data itself }
  1876. emit_tai(Tai_const.Createname(vs.mangledname,AT_DATA,fqueue_offset),cpointerdef.getreusable(vs.vardef));
  1877. fqueue_offset:=low(fqueue_offset);
  1878. end;
  1879. procedure ttai_typedconstbuilder.queue_emit_label(l: tlabelsym);
  1880. begin
  1881. emit_tai(Tai_const.Createname(l.mangledname,fqueue_offset),voidcodepointertype);
  1882. fqueue_offset:=low(fqueue_offset);
  1883. end;
  1884. procedure ttai_typedconstbuilder.queue_emit_const(cs: tconstsym);
  1885. var
  1886. resourcestrrec: trecorddef;
  1887. begin
  1888. if cs.consttyp<>constresourcestring then
  1889. internalerror(2014062102);
  1890. if fqueue_offset<>0 then
  1891. internalerror(2014062103);
  1892. { warning: update if/when the type of resource strings changes }
  1893. case cs.consttyp of
  1894. constresourcestring:
  1895. begin
  1896. resourcestrrec:=trecorddef(search_system_type('TRESOURCESTRINGRECORD').typedef);
  1897. queue_subscriptn_multiple_by_name(resourcestrrec,['CURRENTVALUE']);
  1898. queue_emit_asmsym(current_asmdata.RefAsmSymbol(
  1899. make_mangledname('RESSTR',cs.owner,cs.name),AT_DATA),resourcestrrec
  1900. );
  1901. end;
  1902. { can these occur? }
  1903. constord,
  1904. conststring,constreal,
  1905. constset,constpointer,constnil,
  1906. constwstring,constguid:
  1907. internalerror(2015090903);
  1908. else
  1909. internalerror(2015090904);
  1910. end;
  1911. fqueue_offset:=low(fqueue_offset);
  1912. end;
  1913. procedure ttai_typedconstbuilder.queue_emit_asmsym(sym: tasmsymbol; def: tdef);
  1914. begin
  1915. { pointerdef, because "sym" represents the address of whatever the
  1916. data is }
  1917. def:=cpointerdef.getreusable(def);
  1918. emit_tai(Tai_const.Create_sym_offset(sym,fqueue_offset),def);
  1919. fqueue_offset:=low(fqueue_offset);
  1920. end;
  1921. procedure ttai_typedconstbuilder.queue_emit_ordconst(value: int64; def: tdef);
  1922. begin
  1923. emit_ord_const(value,def);
  1924. fqueue_offset:=low(fqueue_offset);
  1925. end;
  1926. function ttai_typedconstbuilder.queue_is_active: boolean;
  1927. begin
  1928. result:=fqueue_offset<>low(fqueue_offset)
  1929. end;
  1930. {****************************************************************************
  1931. tlowleveltypedconstplaceholder
  1932. ****************************************************************************}
  1933. constructor tlowleveltypedconstplaceholder.create(l: tasmlist; pos: tai; d: tdef);
  1934. begin
  1935. inherited create(d);
  1936. list:=l;
  1937. insertpos:=pos;
  1938. end;
  1939. procedure tlowleveltypedconstplaceholder.replace(ai: tai; d: tdef);
  1940. begin
  1941. if d<>def then
  1942. internalerror(2015091007);
  1943. list.insertafter(ai,insertpos);
  1944. list.remove(insertpos);
  1945. insertpos.free;
  1946. end;
  1947. {****************************************************************************
  1948. tai_abstracttypedconst
  1949. ****************************************************************************}
  1950. class constructor ttai_lowleveltypedconstbuilder.classcreate;
  1951. begin
  1952. caggregateinformation:=tlowlevelaggregateinformation;
  1953. end;
  1954. function ttai_lowleveltypedconstbuilder.emit_placeholder(def: tdef): ttypedconstplaceholder;
  1955. var
  1956. p: tai;
  1957. begin
  1958. check_add_placeholder(def);
  1959. p:=tai_marker.Create(mark_position);
  1960. emit_tai(p,def);
  1961. result:=tlowleveltypedconstplaceholder.create(fasmlist,p,def);
  1962. end;
  1963. procedure ttai_lowleveltypedconstbuilder.mark_anon_aggregate_alignment;
  1964. var
  1965. marker: tai_marker;
  1966. begin
  1967. marker:=tai_marker.Create(mark_position);
  1968. fasmlist.concat(marker);
  1969. tlowlevelaggregateinformation(curagginfo).anonrecmarker:=marker;
  1970. end;
  1971. procedure ttai_lowleveltypedconstbuilder.insert_marked_aggregate_alignment(def: tdef);
  1972. var
  1973. info: tlowlevelaggregateinformation;
  1974. fillbytes: asizeint;
  1975. begin
  1976. info:=tlowlevelaggregateinformation(curagginfo);
  1977. if not assigned(info.anonrecmarker) then
  1978. internalerror(2014091401);
  1979. fillbytes:=info.prepare_next_field(def);
  1980. while fillbytes>0 do
  1981. begin
  1982. fasmlist.insertafter(tai_const.create_8bit(0),info.anonrecmarker);
  1983. dec(fillbytes);
  1984. end;
  1985. fasmlist.remove(info.anonrecmarker);
  1986. info.anonrecmarker.free;
  1987. info.anonrecmarker:=nil;
  1988. end;
  1989. procedure ttai_lowleveltypedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
  1990. begin
  1991. inherited;
  1992. { The darwin/ppc64 assembler or linker seems to have trouble }
  1993. { if a section ends with a global label without any data after it. }
  1994. { So for safety, just put a dummy value here. }
  1995. { Further, the regular linker also kills this symbol when turning }
  1996. { on smart linking in case no value appears after it, so put the }
  1997. { dummy byte there always }
  1998. { Update: the Mac OS X 10.6 linker orders data that needs to be }
  1999. { relocated before all other data, so make this data relocatable, }
  2000. { otherwise the end label won't be moved with the rest }
  2001. if (tcalo_vectorized_dead_strip_end in options) and
  2002. (target_info.system in (systems_darwin+systems_aix)) then
  2003. fasmlist.concat(Tai_const.create_sym(sym));
  2004. end;
  2005. begin
  2006. ctai_typedconstbuilder:=ttai_lowleveltypedconstbuilder;
  2007. end.