aasmcnst.pas 87 KB

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