aasmcnst.pas 86 KB

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