aasmcnst.pas 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288
  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. current_module.linkorderedsymbols.concat(sym.Name);
  981. finalize_asmlist(sym,def,sectype,secname,alignment,options);
  982. end;
  983. procedure ttai_typedconstbuilder.do_emit_tai(p: tai; def: tdef);
  984. begin
  985. { by default we don't care about the type }
  986. fasmlist.concat(p);
  987. end;
  988. function ttai_typedconstbuilder.get_final_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint): tasmlist;
  989. begin
  990. if not fasmlist_finalized then
  991. begin
  992. finalize_asmlist(sym,def,section,secname,alignment,foptions);
  993. finalize_asmlist_add_indirect_sym(sym,def,section,secname,alignment,foptions);
  994. fasmlist_finalized:=true;
  995. end;
  996. result:=fasmlist;
  997. end;
  998. function ttai_typedconstbuilder.get_final_asmlist_vectorized_dead_strip(def: tdef; const basename, itemname: TSymStr; st: TSymtable; alignment: longint): tasmlist;
  999. begin
  1000. if not fasmlist_finalized then
  1001. begin
  1002. finalize_vectorized_dead_strip_asmlist(def,basename,itemname,st,alignment,foptions);
  1003. fasmlist_finalized:=true;
  1004. end;
  1005. result:=fasmlist;
  1006. end;
  1007. class function ttai_typedconstbuilder.get_string_symofs(typ: tstringtype; winlikewidestring: boolean): pint;
  1008. begin
  1009. { darwin's linker does not support negative offsets }
  1010. if not(target_info.system in systems_darwin) then
  1011. result:=0
  1012. else
  1013. result:=get_string_header_size(typ,winlikewidestring);
  1014. end;
  1015. class function ttai_typedconstbuilder.get_dynarray_symofs:pint;
  1016. begin
  1017. { darwin's linker does not support negative offsets }
  1018. if not (target_info.system in systems_darwin) then
  1019. result:=0
  1020. else
  1021. result:=get_dynarray_header_size;
  1022. end;
  1023. class function ttai_typedconstbuilder.get_string_header_size(typ: tstringtype; winlikewidestring: boolean): pint;
  1024. var
  1025. ansistring_header_size: pint;
  1026. unicodestring_header_size: pint;
  1027. begin
  1028. ansistring_header_size:=
  1029. { encoding }
  1030. 2 +
  1031. { elesize }
  1032. 2 +
  1033. {$ifdef cpu64bitaddr}
  1034. { alignment }
  1035. 4 +
  1036. {$endif cpu64bitaddr}
  1037. { reference count }
  1038. sizesinttype.size +
  1039. { length }
  1040. sizesinttype.size;
  1041. unicodestring_header_size:=ansistring_header_size;
  1042. case typ of
  1043. st_ansistring:
  1044. result:=ansistring_header_size;
  1045. st_unicodestring:
  1046. result:=unicodestring_header_size;
  1047. st_widestring:
  1048. if winlikewidestring then
  1049. result:=0
  1050. else
  1051. result:=unicodestring_header_size;
  1052. else
  1053. result:=0;
  1054. end;
  1055. end;
  1056. class function ttai_typedconstbuilder.get_dynarray_header_size:pint;
  1057. begin
  1058. result:=
  1059. { reference count }
  1060. ptrsinttype.size +
  1061. { high value }
  1062. sizesinttype.size;
  1063. end;
  1064. constructor ttai_typedconstbuilder.create(const options: ttcasmlistoptions);
  1065. begin
  1066. inherited create;
  1067. fasmlist:=tasmlist.create;
  1068. foptions:=options;
  1069. { queue is empty }
  1070. fqueue_offset:=low(fqueue_offset);
  1071. finternal_data_current_section:=sec_none;
  1072. end;
  1073. destructor ttai_typedconstbuilder.destroy;
  1074. begin
  1075. { the queue should have been flushed if it was used }
  1076. if fqueue_offset<>low(fqueue_offset) then
  1077. internalerror(2014062901);
  1078. faggregateinformation.free;
  1079. fasmlist.free;
  1080. inherited destroy;
  1081. end;
  1082. procedure ttai_typedconstbuilder.start_internal_data_builder(list: tasmlist; sectype: TAsmSectiontype; const secname: TSymStr; out tcb: ttai_typedconstbuilder; out l: tasmlabel);
  1083. var
  1084. options: ttcasmlistoptions;
  1085. foundsec: longint;
  1086. begin
  1087. { you can't start multiple concurrent internal data builders for the
  1088. same tcb, finish the first before starting another }
  1089. if finternal_data_current_section<>sec_none then
  1090. internalerror(2016082801);
  1091. { we don't know what was previously added to this list, so always add
  1092. a section header. We'll use the same section name in case multiple
  1093. items are added to the same kind of section (rodata, rodata_no_rel,
  1094. ...), so that everything will still end up in the same section even if
  1095. there are multiple section headers }
  1096. options:=[tcalo_is_lab,tcalo_new_section];
  1097. finternal_data_current_section:=sectype;
  1098. l:=nil;
  1099. { did we already create a section of this type for the internal data of
  1100. this builder? }
  1101. foundsec:=get_internal_data_section_index(sectype);
  1102. if foundsec=-1 then
  1103. begin
  1104. { we only need to start a dead-strippable section of data at the
  1105. start of the first subsection of this kind for this block.
  1106. exception: if dead stripping happens based on objects/libraries,
  1107. then we only have to create a new object file for the first
  1108. internal data section of any kind (all the rest will simply be put
  1109. in the same object file) }
  1110. if create_smartlink then
  1111. begin
  1112. if not create_smartlink_library or
  1113. (length(finternal_data_section_info)=0) then
  1114. include(options,tcalo_make_dead_strippable);
  1115. { on Darwin, dead code/data stripping happens based on non-
  1116. temporary labels (any label that doesn't start with "L" -- it
  1117. doesn't have to be global) -> add a non-temporary lobel at the
  1118. start of every kind of subsection created in this builder }
  1119. if target_info.system in systems_darwin then
  1120. l:=get_internal_data_section_start_label;
  1121. end;
  1122. foundsec:=length(finternal_data_section_info);
  1123. setlength(finternal_data_section_info,foundsec+1);
  1124. finternal_data_section_info[foundsec].sectype:=sectype;
  1125. end;
  1126. if not assigned(finternal_data_asmlist) and
  1127. (cs_create_smart in current_settings.moduleswitches) then
  1128. begin
  1129. l:=get_internal_data_section_start_label;
  1130. { the internal data list should only be assigned by this routine,
  1131. the first time that an internal data block is started }
  1132. if not assigned(list) or
  1133. assigned(finternal_data_asmlist) then
  1134. internalerror(2015032101);
  1135. finternal_data_asmlist:=list;
  1136. end
  1137. { all internal data for this tcb must go to the same list (otherwise all
  1138. data we want to add to the dead-strippable block is not guaranteed to
  1139. be sequential and e.g. in the same object file in case of library-based
  1140. dead stripping) }
  1141. else if (assigned(finternal_data_asmlist) and
  1142. (list<>finternal_data_asmlist)) or
  1143. not assigned(list) then
  1144. internalerror(2015032101);
  1145. finternal_data_asmlist:=list;
  1146. if not assigned(l) then
  1147. l:=get_internal_data_section_internal_label;
  1148. { first section of this kind -> set name }
  1149. if finternal_data_section_info[foundsec].secname='' then
  1150. if secname='' then
  1151. finternal_data_section_info[foundsec].secname:=l.Name
  1152. else
  1153. finternal_data_section_info[foundsec].secname:=secname
  1154. { if the name is specified multiple times, it must match }
  1155. else if (secname<>'') and
  1156. (finternal_data_section_info[foundsec].secname<>secname) then
  1157. internalerror(2015032401);
  1158. tcb:=ttai_typedconstbuilderclass(classtype).create(options);
  1159. end;
  1160. procedure ttai_typedconstbuilder.finish_internal_data_builder(var tcb: ttai_typedconstbuilder; l: tasmlabel; def: tdef; alignment: longint);
  1161. begin
  1162. finternal_data_asmlist.concatList(tcb.get_final_asmlist(l,def,
  1163. finternal_data_current_section,
  1164. finternal_data_section_info[get_internal_data_section_index(finternal_data_current_section)].secname,
  1165. alignment));
  1166. tcb.free;
  1167. tcb:=nil;
  1168. finternal_data_current_section:=sec_none;
  1169. end;
  1170. procedure ttai_typedconstbuilder.emit_tai(p: tai; def: tdef);
  1171. var
  1172. kind: ttypedconstkind;
  1173. info: taggregateinformation;
  1174. begin
  1175. { these elements can be aggregates themselves, e.g. a shortstring can
  1176. be emitted as a series of bytes and char arrays }
  1177. kind:=aggregate_kind(def);
  1178. info:=curagginfo;
  1179. if (kind<>tck_simple) and
  1180. (not assigned(info) or
  1181. (info.typ<>kind)) then
  1182. internalerror(2014091001);
  1183. { if we're emitting a record, handle the padding bytes, and in case of
  1184. an anonymous record also add the next field }
  1185. if assigned(info) then
  1186. begin
  1187. { queue_init already adds padding }
  1188. if not queue_is_active and
  1189. (is_record(info.def) or
  1190. is_object(info.def)) and
  1191. { may add support for these later }
  1192. not is_packed_record_or_object(info.def) then
  1193. pad_next_field(def);
  1194. end;
  1195. { emit the data }
  1196. do_emit_tai(p,def);
  1197. end;
  1198. procedure ttai_typedconstbuilder.emit_tai_procvar2procdef(p: tai; pvdef: tprocvardef);
  1199. begin
  1200. { nothing special by default, since we don't care about the type }
  1201. emit_tai(p,pvdef);
  1202. end;
  1203. procedure ttai_typedconstbuilder.maybe_emit_tail_padding(def: tdef);
  1204. var
  1205. info: taggregateinformation;
  1206. fillbytes: asizeint;
  1207. begin
  1208. info:=curagginfo;
  1209. if not assigned(info) then
  1210. internalerror(2014091002);
  1211. if def<>info.def then
  1212. internalerror(2014091205);
  1213. if (is_record(def) or
  1214. is_object(def)) and
  1215. not is_packed_record_or_object(def) then
  1216. begin
  1217. fillbytes:=def.size-info.curoffset;
  1218. while fillbytes>0 do
  1219. begin
  1220. do_emit_tai(Tai_const.Create_8bit(0),u8inttype);
  1221. dec(fillbytes)
  1222. end;
  1223. end;
  1224. end;
  1225. function ttai_typedconstbuilder.emit_string_const_common(stringtype: tstringtype; len: asizeint; encoding: tstringencoding; var startlab: tasmlabel): tasmlabofs;
  1226. var
  1227. string_symofs: asizeint;
  1228. charptrdef: tdef;
  1229. elesize: word;
  1230. begin
  1231. result.lab:=startlab;
  1232. result.ofs:=0;
  1233. { pack the data, so that we don't add unnecessary null bytes after the
  1234. constant string }
  1235. begin_anonymous_record('$'+get_dynstring_rec_name(stringtype,false,len),1,sizeof(TConstPtrUInt),1,1);
  1236. string_symofs:=get_string_symofs(stringtype,false);
  1237. { encoding }
  1238. emit_tai(tai_const.create_16bit(encoding),u16inttype);
  1239. inc(result.ofs,2);
  1240. { element size }
  1241. case stringtype of
  1242. st_ansistring:
  1243. begin
  1244. elesize:=1;
  1245. charptrdef:=charpointertype;
  1246. end;
  1247. st_unicodestring:
  1248. begin
  1249. elesize:=2;
  1250. charptrdef:=widecharpointertype;
  1251. end
  1252. else
  1253. internalerror(2014080401);
  1254. end;
  1255. emit_tai(tai_const.create_16bit(elesize),u16inttype);
  1256. inc(result.ofs,2);
  1257. {$ifdef cpu64bitaddr}
  1258. { dummy for alignment }
  1259. emit_tai(tai_const.create_32bit(0),u32inttype);
  1260. inc(result.ofs,4);
  1261. {$endif cpu64bitaddr}
  1262. emit_tai(tai_const.create_sizeint(-1),sizesinttype);
  1263. inc(result.ofs,sizesinttype.size);
  1264. emit_tai(tai_const.create_sizeint(len),sizesinttype);
  1265. inc(result.ofs,sizesinttype.size);
  1266. if string_symofs=0 then
  1267. begin
  1268. { results in slightly more efficient code }
  1269. emit_tai(tai_label.create(result.lab),charptrdef);
  1270. result.ofs:=0;
  1271. { create new label of the same kind (including whether or not the
  1272. name starts with target_asm.labelprefix in case it's AB_LOCAL,
  1273. so we keep the difference depending on whether the original was
  1274. allocated via getstatic/getlocal/getglobal datalabel) }
  1275. startlab:=tasmlabel.create(current_asmdata.AsmSymbolDict,startlab.name+'$strlab',startlab.bind,startlab.typ);
  1276. end;
  1277. { sanity check }
  1278. if result.ofs<>string_symofs then
  1279. internalerror(2012051701);
  1280. end;
  1281. function ttai_typedconstbuilder.get_dynstring_def_for_type(stringtype: tstringtype; winlikewidestring: boolean): tstringdef;
  1282. begin
  1283. if stringtype=st_ansistring then
  1284. result:=tstringdef(cansistringtype)
  1285. else if (stringtype=st_unicodestring) or
  1286. ((stringtype=st_widestring) and
  1287. not winlikewidestring) then
  1288. result:=tstringdef(cunicodestringtype)
  1289. else if stringtype=st_widestring then
  1290. result:=tstringdef(cwidestringtype)
  1291. else
  1292. internalerror(2015122101);
  1293. end;
  1294. procedure ttai_typedconstbuilder.begin_aggregate_internal(def: tdef; anonymous: boolean);
  1295. var
  1296. info: taggregateinformation;
  1297. tck: ttypedconstkind;
  1298. begin
  1299. tck:=aggregate_kind(def);
  1300. if tck=tck_simple then
  1301. exit;
  1302. if not assigned(faggregateinformation) then
  1303. faggregateinformation:=tfpobjectlist.create
  1304. { if we're starting an anonymous record, we can't align it yet because
  1305. the alignment depends on the fields that will be added -> we'll do
  1306. it at the end }
  1307. else if not anonymous or
  1308. ((def.typ<>recorddef) and
  1309. not is_object(def)) then
  1310. begin
  1311. { add padding if necessary, and update the current field/offset }
  1312. info:=curagginfo;
  1313. if (is_record(curagginfo.def) or
  1314. is_object(curagginfo.def)) and
  1315. not is_packed_record_or_object(curagginfo.def) then
  1316. begin
  1317. if queue_is_active then
  1318. internalerror(2015073001);
  1319. pad_next_field(def);
  1320. end;
  1321. end
  1322. { if this is the outer record, no padding is required; the alignment
  1323. has to be specified explicitly in that case via get_final_asmlist() }
  1324. else if assigned(curagginfo) and
  1325. (curagginfo.def.typ=recorddef) then
  1326. { mark where we'll have to insert the padding bytes at the end }
  1327. mark_anon_aggregate_alignment;
  1328. info:=caggregateinformation.create(def,aggregate_kind(def));
  1329. faggregateinformation.add(info);
  1330. end;
  1331. procedure ttai_typedconstbuilder.end_aggregate_internal(def: tdef; anonymous: boolean);
  1332. var
  1333. info: taggregateinformation;
  1334. tck: ttypedconstkind;
  1335. begin
  1336. tck:=aggregate_kind(def);
  1337. if tck=tck_simple then
  1338. exit;
  1339. { add tail padding if necessary }
  1340. maybe_emit_tail_padding(def);
  1341. { pop and free the information }
  1342. info:=curagginfo;
  1343. faggregateinformation.count:=faggregateinformation.count-1;
  1344. info.free;
  1345. end;
  1346. class function ttai_typedconstbuilder.get_vectorized_dead_strip_section_symbol(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions; start: boolean): tasmsymbol;
  1347. var
  1348. name: TSymStr;
  1349. asmtype : TAsmsymtype;
  1350. begin
  1351. if start then
  1352. name:=make_mangledname(basename,st,'START')
  1353. else
  1354. name:=make_mangledname(basename,st,'END');
  1355. if tcdssso_define in options then
  1356. begin
  1357. if tcdssso_use_indirect in options then
  1358. asmtype:=AT_DATA_FORCEINDIRECT
  1359. else
  1360. asmtype:=AT_DATA;
  1361. result:=current_asmdata.DefineAsmSymbol(name,AB_GLOBAL,asmtype,voidpointertype);
  1362. if tcdssso_register_asmsym in options then
  1363. current_module.add_public_asmsym(result);
  1364. end
  1365. else
  1366. begin
  1367. result:=current_asmdata.RefAsmSymbol(name,AT_DATA,tcdssso_use_indirect in options);
  1368. if tcdssso_register_asmsym in options then
  1369. current_module.add_extern_asmsym(result);
  1370. end;
  1371. end;
  1372. class function ttai_typedconstbuilder.get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; out secname: TSymStr): boolean;
  1373. begin
  1374. result:=false;
  1375. end;
  1376. class function ttai_typedconstbuilder.get_vectorized_dead_strip_section_symbol_start(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol;
  1377. begin
  1378. result:=get_vectorized_dead_strip_section_symbol(basename,st,options,true);
  1379. end;
  1380. class function ttai_typedconstbuilder.get_vectorized_dead_strip_section_symbol_end(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol;
  1381. begin
  1382. result:=get_vectorized_dead_strip_section_symbol(basename,st,options,false);
  1383. end;
  1384. class function ttai_typedconstbuilder.get_dynstring_rec_name(typ: tstringtype; winlike: boolean; len: asizeint): TSymStr;
  1385. begin
  1386. case typ of
  1387. st_ansistring:
  1388. result:='ansistrrec';
  1389. st_unicodestring,
  1390. st_widestring:
  1391. if (typ=st_unicodestring) or
  1392. not winlike then
  1393. result:='unicodestrrec'
  1394. else
  1395. result:='widestrrec';
  1396. else
  1397. internalerror(2014080402);
  1398. end;
  1399. result:=result+tostr(len);
  1400. end;
  1401. class function ttai_typedconstbuilder.get_dynstring_rec(typ: tstringtype; winlike: boolean; len: asizeint): trecorddef;
  1402. var
  1403. name: TSymStr;
  1404. streledef: tdef;
  1405. strtypesym: ttypesym;
  1406. srsym: tsym;
  1407. srsymtable: tsymtable;
  1408. begin
  1409. name:=get_dynstring_rec_name(typ,winlike,len);
  1410. { search in the interface of all units for the type to reuse it }
  1411. if searchsym_type(name,srsym,srsymtable) then
  1412. begin
  1413. result:=trecorddef(ttypesym(srsym).typedef);
  1414. exit;
  1415. end
  1416. else
  1417. begin
  1418. { also search the implementation of the current unit }
  1419. strtypesym:=try_search_current_module_type(name);
  1420. if assigned(strtypesym) then
  1421. begin
  1422. result:=trecorddef(strtypesym.typedef);
  1423. exit;
  1424. end;
  1425. end;
  1426. if (typ<>st_widestring) or
  1427. not winlike then
  1428. begin
  1429. result:=crecorddef.create_global_internal('$'+name,1,1,1);
  1430. { encoding }
  1431. result.add_field_by_def('',u16inttype);
  1432. { element size }
  1433. result.add_field_by_def('',u16inttype);
  1434. { elements }
  1435. case typ of
  1436. st_ansistring:
  1437. streledef:=cansichartype;
  1438. st_unicodestring:
  1439. streledef:=cwidechartype;
  1440. else
  1441. internalerror(2016082301);
  1442. end;
  1443. {$ifdef cpu64bitaddr}
  1444. { dummy for alignment }
  1445. result.add_field_by_def('',u32inttype);
  1446. {$endif cpu64bitaddr}
  1447. { reference count }
  1448. result.add_field_by_def('',sizesinttype);
  1449. { length in elements }
  1450. result.add_field_by_def('',sizesinttype);
  1451. end
  1452. else
  1453. begin
  1454. result:=crecorddef.create_global_internal('$'+name,4,
  1455. targetinfos[target_info.system]^.alignment.recordalignmin,
  1456. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1457. { length in bytes }
  1458. result.add_field_by_def('',s32inttype);
  1459. streledef:=cwidechartype;
  1460. end;
  1461. { data (include zero terminator) }
  1462. result.add_field_by_def('',carraydef.getreusable(streledef,len+1));
  1463. trecordsymtable(trecorddef(result).symtable).addalignmentpadding;
  1464. end;
  1465. function ttai_typedconstbuilder.emit_ansistring_const(datalist: TAsmList; data: pchar; len: asizeint; encoding: tstringencoding): tasmlabofs;
  1466. var
  1467. s: PChar;
  1468. startlab: tasmlabel;
  1469. ansistrrecdef: trecorddef;
  1470. datadef: tdef;
  1471. datatcb: ttai_typedconstbuilder;
  1472. begin
  1473. start_internal_data_builder(datalist,sec_rodata_norel,'',datatcb,startlab);
  1474. result:=datatcb.emit_string_const_common(st_ansistring,len,encoding,startlab);
  1475. getmem(s,len+1);
  1476. move(data^,s^,len);
  1477. s[len]:=#0;
  1478. { terminating zero included }
  1479. datadef:=carraydef.getreusable(cansichartype,len+1);
  1480. datatcb.maybe_begin_aggregate(datadef);
  1481. datatcb.emit_tai(tai_string.create_pchar(s,len+1),datadef);
  1482. datatcb.maybe_end_aggregate(datadef);
  1483. ansistrrecdef:=datatcb.end_anonymous_record;
  1484. finish_internal_data_builder(datatcb,startlab,ansistrrecdef,const_align(voidpointertype.alignment));
  1485. end;
  1486. function ttai_typedconstbuilder.emit_unicodestring_const(datalist: TAsmList; data: pointer; encoding: tstringencoding; winlike: boolean):tasmlabofs;
  1487. var
  1488. i, strlength: longint;
  1489. string_symofs: asizeint;
  1490. startlab: tasmlabel;
  1491. datadef: tdef;
  1492. datatcb: ttai_typedconstbuilder;
  1493. unicodestrrecdef: trecorddef;
  1494. begin
  1495. start_internal_data_builder(datalist,sec_rodata_norel,'',datatcb,startlab);
  1496. strlength:=getlengthwidestring(pcompilerwidestring(data));
  1497. if winlike then
  1498. begin
  1499. result.lab:=startlab;
  1500. datatcb.begin_anonymous_record('$'+get_dynstring_rec_name(st_widestring,true,strlength),
  1501. 4,4,
  1502. targetinfos[target_info.system]^.alignment.recordalignmin,
  1503. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1504. datatcb.emit_tai(Tai_const.Create_32bit(strlength*cwidechartype.size),s32inttype);
  1505. { can we optimise by placing the string constant label at the
  1506. required offset? }
  1507. string_symofs:=get_string_symofs(st_widestring,true);
  1508. if string_symofs=0 then
  1509. begin
  1510. { yes }
  1511. datatcb.emit_tai(Tai_label.Create(result.lab),widecharpointertype);
  1512. { allocate a separate label for the start of the data (see
  1513. emit_string_const_common() for explanation) }
  1514. startlab:=tasmlabel.create(current_asmdata.AsmSymbolDict,startlab.name+'$strlab',startlab.bind,startlab.typ);
  1515. end
  1516. else
  1517. internalerror(2015031502);
  1518. result.ofs:=string_symofs;
  1519. end
  1520. else
  1521. begin
  1522. result:=datatcb.emit_string_const_common(st_unicodestring,strlength,encoding,startlab);
  1523. end;
  1524. if cwidechartype.size = 2 then
  1525. begin
  1526. datadef:=carraydef.getreusable(cwidechartype,strlength+1);
  1527. datatcb.maybe_begin_aggregate(datadef);
  1528. for i:=0 to strlength-1 do
  1529. datatcb.emit_tai(Tai_const.Create_16bit(pcompilerwidestring(data)^.data[i]),cwidechartype);
  1530. { ending #0 }
  1531. datatcb.emit_tai(Tai_const.Create_16bit(0),cwidechartype);
  1532. datatcb.maybe_end_aggregate(datadef);
  1533. unicodestrrecdef:=datatcb.end_anonymous_record;
  1534. end
  1535. else
  1536. { code generation for other sizes must be written }
  1537. internalerror(200904271);
  1538. finish_internal_data_builder(datatcb,startlab,unicodestrrecdef,const_align(voidpointertype.alignment));
  1539. end;
  1540. procedure ttai_typedconstbuilder.emit_string_offset(const ll: tasmlabofs; const strlength: longint; const st: tstringtype; const winlikewidestring: boolean; const charptrdef: tdef);
  1541. begin
  1542. emit_tai(Tai_const.Create_sym_offset(ll.lab,ll.ofs),get_dynstring_def_for_type(st,winlikewidestring));
  1543. end;
  1544. procedure ttai_typedconstbuilder.emit_dynarray_offset(const ll:tasmlabofs;const arrlength:asizeint;const arrdef:tarraydef; const arrconstdatadef: trecorddef);
  1545. begin
  1546. emit_tai(tai_const.create_sym_offset(ll.lab,ll.ofs),arrdef);
  1547. end;
  1548. function ttai_typedconstbuilder.begin_dynarray_const(arrdef:tdef;var startlab:tasmlabel;out arrlengthloc:ttypedconstplaceholder):tasmlabofs;
  1549. var
  1550. dynarray_symofs: asizeint;
  1551. begin
  1552. result.lab:=startlab;
  1553. result.ofs:=0;
  1554. { pack the data, so that we don't add unnecessary null bytes after the
  1555. constant string }
  1556. begin_anonymous_record('',1,sizeof(TConstPtrUInt),1,1);
  1557. dynarray_symofs:=get_dynarray_symofs;
  1558. { what to do if ptrsinttype <> sizesinttype??? }
  1559. emit_tai(tai_const.create_sizeint(-1),ptrsinttype);
  1560. inc(result.ofs,ptrsinttype.size);
  1561. arrlengthloc:=emit_placeholder(sizesinttype);
  1562. inc(result.ofs,sizesinttype.size);
  1563. if dynarray_symofs=0 then
  1564. begin
  1565. { results in slightly more efficient code }
  1566. emit_tai(tai_label.create(result.lab),arrdef);
  1567. result.ofs:=0;
  1568. { create new label of the same kind (including whether or not the
  1569. name starts with target_asm.labelprefix in case it's AB_LOCAL,
  1570. so we keep the difference depending on whether the original was
  1571. allocated via getstatic/getlocal/getglobal datalabel) }
  1572. startlab:=tasmlabel.create(current_asmdata.AsmSymbolDict,startlab.name+'$dynarrlab',startlab.bind,startlab.typ);
  1573. end;
  1574. { sanity check }
  1575. if result.ofs<>dynarray_symofs then
  1576. internalerror(2018020601);
  1577. end;
  1578. function ttai_typedconstbuilder.end_dynarray_const(arrdef:tdef;arrlength:asizeint;arrlengthloc:ttypedconstplaceholder):tdef;
  1579. begin
  1580. { we emit the high value, not the count }
  1581. arrlengthloc.replace(tai_const.Create_sizeint(arrlength-1),sizesinttype);
  1582. result:=end_anonymous_record;
  1583. end;
  1584. function ttai_typedconstbuilder.emit_shortstring_const(const str: shortstring): tdef;
  1585. begin
  1586. { we use an arraydef instead of a shortstringdef, because we don't have
  1587. functionality in place yet to reuse shortstringdefs of the same length
  1588. and neither the lowlevel nor the llvm typedconst builder cares about
  1589. this difference }
  1590. result:=carraydef.getreusable(cansichartype,length(str)+1);
  1591. maybe_begin_aggregate(result);
  1592. emit_tai(Tai_const.Create_8bit(length(str)),u8inttype);
  1593. if str<>'' then
  1594. emit_tai(Tai_string.Create(str),carraydef.getreusable(cansichartype,length(str)));
  1595. maybe_end_aggregate(result);
  1596. end;
  1597. function ttai_typedconstbuilder.emit_pchar_const(str: pchar; len: pint; copypchar: boolean): tdef;
  1598. var
  1599. newstr: pchar;
  1600. begin
  1601. result:=carraydef.getreusable(cansichartype,len+1);
  1602. maybe_begin_aggregate(result);
  1603. if (len=0) and
  1604. (not assigned(str) or
  1605. copypchar) then
  1606. emit_tai(Tai_const.Create_8bit(0),cansichartype)
  1607. else
  1608. begin
  1609. if copypchar then
  1610. begin
  1611. getmem(newstr,len+1);
  1612. move(str^,newstr^,len+1);
  1613. str:=newstr;
  1614. end;
  1615. emit_tai(Tai_string.Create_pchar(str,len+1),result);
  1616. end;
  1617. maybe_end_aggregate(result);
  1618. end;
  1619. procedure ttai_typedconstbuilder.emit_guid_const(const guid: tguid);
  1620. var
  1621. i: longint;
  1622. field: tfieldvarsym;
  1623. begin
  1624. maybe_begin_aggregate(rec_tguid);
  1625. { variant record -> must specify which fields get initialised }
  1626. next_field:=tfieldvarsym(rec_tguid.symtable.Find('DATA1'));
  1627. emit_tai(Tai_const.Create_32bit(longint(guid.D1)),u32inttype);
  1628. next_field:=tfieldvarsym(rec_tguid.symtable.Find('DATA2'));
  1629. emit_tai(Tai_const.Create_16bit(guid.D2),u16inttype);
  1630. next_field:=tfieldvarsym(rec_tguid.symtable.Find('DATA3'));
  1631. emit_tai(Tai_const.Create_16bit(guid.D3),u16inttype);
  1632. field:=tfieldvarsym(rec_tguid.symtable.Find('DATA4'));
  1633. next_field:=field;
  1634. { the array }
  1635. maybe_begin_aggregate(field.vardef);
  1636. for i:=Low(guid.D4) to High(guid.D4) do
  1637. emit_tai(Tai_const.Create_8bit(guid.D4[i]),u8inttype);
  1638. maybe_end_aggregate(field.vardef);
  1639. maybe_end_aggregate(rec_tguid);
  1640. end;
  1641. procedure ttai_typedconstbuilder.emit_procdef_const(pd: tprocdef);
  1642. begin
  1643. emit_tai(Tai_const.Createname(pd.mangledname,AT_FUNCTION,0),cprocvardef.getreusableprocaddr(pd));
  1644. end;
  1645. procedure ttai_typedconstbuilder.emit_ord_const(value: int64; def: tdef);
  1646. begin
  1647. case def.size of
  1648. 1:
  1649. emit_tai(Tai_const.Create_8bit(byte(value)),def);
  1650. 2:
  1651. emit_tai(Tai_const.Create_16bit(word(value)),def);
  1652. 4:
  1653. emit_tai(Tai_const.Create_32bit(longint(value)),def);
  1654. 8:
  1655. emit_tai(Tai_const.Create_64bit(value),def);
  1656. else
  1657. internalerror(2014100501);
  1658. end;
  1659. end;
  1660. procedure ttai_typedconstbuilder.emit_pooled_shortstring_const_ref(const str:shortstring);
  1661. var
  1662. pool : thashset;
  1663. entry : phashsetitem;
  1664. strlab : tasmlabel;
  1665. l : longint;
  1666. pc : pansichar;
  1667. datadef : tdef;
  1668. strtcb : ttai_typedconstbuilder;
  1669. begin
  1670. pool:=current_asmdata.ConstPools[sp_shortstr];
  1671. entry:=pool.FindOrAdd(@str[1],length(str));
  1672. { :-(, we must generate a new entry }
  1673. if not assigned(entry^.Data) then
  1674. begin
  1675. current_asmdata.getglobaldatalabel(strlab);
  1676. { include length and terminating zero for quick conversion to pchar }
  1677. l:=length(str);
  1678. getmem(pc,l+2);
  1679. move(str[1],pc[1],l);
  1680. pc[0]:=chr(l);
  1681. pc[l+1]:=#0;
  1682. datadef:=carraydef.getreusable(cansichartype,l+2);
  1683. { we start a new constbuilder as we don't know whether we're called
  1684. from inside an internal constbuilder }
  1685. strtcb:=ctai_typedconstbuilder.create([tcalo_is_lab,tcalo_make_dead_strippable,tcalo_apply_constalign]);
  1686. strtcb.maybe_begin_aggregate(datadef);
  1687. strtcb.emit_tai(Tai_string.Create_pchar(pc,l+2),datadef);
  1688. strtcb.maybe_end_aggregate(datadef);
  1689. current_asmdata.asmlists[al_typedconsts].concatList(
  1690. strtcb.get_final_asmlist(strlab,datadef,sec_rodata_norel,strlab.name,const_align(sizeof(pint)))
  1691. );
  1692. strtcb.free;
  1693. entry^.Data:=strlab;
  1694. end
  1695. else
  1696. strlab:=tasmlabel(entry^.Data);
  1697. emit_tai(tai_const.Create_sym(strlab),charpointertype);
  1698. end;
  1699. procedure ttai_typedconstbuilder.maybe_begin_aggregate(def: tdef);
  1700. begin
  1701. begin_aggregate_internal(def,false);
  1702. end;
  1703. procedure ttai_typedconstbuilder.maybe_end_aggregate(def: tdef);
  1704. begin
  1705. end_aggregate_internal(def,false);
  1706. end;
  1707. function ttai_typedconstbuilder.begin_anonymous_record(const optionalname: string; packrecords, recordalign, recordalignmin, maxcrecordalign: shortint): trecorddef;
  1708. var
  1709. anonrecorddef: trecorddef;
  1710. typesym: ttypesym;
  1711. begin
  1712. { if the name is specified, we create a typesym with that name in order
  1713. to ensure we can find it again later with that name -> reuse here as
  1714. well if possible (and that also avoids duplicate type name issues) }
  1715. if optionalname<>'' then
  1716. begin
  1717. typesym:=try_search_current_module_type(optionalname);
  1718. if assigned(typesym) then
  1719. begin
  1720. if typesym.typedef.typ<>recorddef then
  1721. internalerror(2015071401);
  1722. result:=trecorddef(typesym.typedef);
  1723. maybe_begin_aggregate(result);
  1724. exit;
  1725. end;
  1726. end;
  1727. { create skeleton def }
  1728. anonrecorddef:=crecorddef.create_global_internal(optionalname,packrecords,recordalignmin,maxcrecordalign);
  1729. trecordsymtable(anonrecorddef.symtable).recordalignment:=recordalign;
  1730. { generic aggregate housekeeping }
  1731. begin_aggregate_internal(anonrecorddef,true);
  1732. { mark as anonymous record }
  1733. curagginfo.anonrecord:=true;
  1734. { in case a descendent wants to do something with the anonrecorddef too }
  1735. result:=anonrecorddef;
  1736. end;
  1737. function ttai_typedconstbuilder.end_anonymous_record: trecorddef;
  1738. var
  1739. info: taggregateinformation;
  1740. anonrecord: boolean;
  1741. begin
  1742. info:=curagginfo;
  1743. if not assigned(info) or
  1744. (info.def.typ<>recorddef) then
  1745. internalerror(2014080201);
  1746. result:=trecorddef(info.def);
  1747. { make a copy, as we need it after info has been freed by
  1748. maybe_end_aggregate(result) }
  1749. anonrecord:=info.anonrecord;
  1750. { finalise the record skeleton (all fields have been added already by
  1751. emit_tai()) -- anonrecord may not be set in case we reused an earlier
  1752. constructed def }
  1753. if anonrecord then
  1754. trecordsymtable(result.symtable).addalignmentpadding;
  1755. end_aggregate_internal(result,true);
  1756. if anonrecord and
  1757. assigned(curagginfo) and
  1758. (curagginfo.def.typ=recorddef) then
  1759. insert_marked_aggregate_alignment(result);
  1760. end;
  1761. procedure ttai_typedconstbuilder.check_add_placeholder(def: tdef);
  1762. begin
  1763. { it only makes sense to add a placeholder inside an aggregate
  1764. (otherwise there can be but one element)
  1765. we cannot add a placeholder in the middle of a queued expression
  1766. either
  1767. the placeholder cannot be an aggregate }
  1768. if not assigned(curagginfo) or
  1769. queue_is_active or
  1770. (aggregate_kind(def)<>tck_simple) then
  1771. internalerror(2015091001);
  1772. end;
  1773. procedure ttai_typedconstbuilder.queue_init(todef: tdef);
  1774. var
  1775. info: taggregateinformation;
  1776. begin
  1777. { nested call to init? }
  1778. if fqueue_offset<>low(fqueue_offset) then
  1779. internalerror(2014062101);
  1780. { insert padding bytes before starting the queue, so that the first
  1781. padding byte won't be interpreted as the emitted value for this queue }
  1782. info:=curagginfo;
  1783. if assigned(info) then
  1784. begin
  1785. if ((info.def.typ=recorddef) or
  1786. is_object(info.def)) and
  1787. { may add support for these later }
  1788. not is_packed_record_or_object(info.def) then
  1789. pad_next_field(todef);
  1790. end;
  1791. fqueue_offset:=0;
  1792. fqueued_def:=todef;
  1793. end;
  1794. procedure ttai_typedconstbuilder.queue_vecn(def: tdef; const index: tconstexprint);
  1795. var
  1796. elelen,
  1797. vecbase: asizeint;
  1798. v: tconstexprint;
  1799. begin
  1800. elelen:=1;
  1801. vecbase:=0;
  1802. case def.typ of
  1803. stringdef :
  1804. ;
  1805. arraydef :
  1806. begin
  1807. if not is_packed_array(def) then
  1808. begin
  1809. elelen:=tarraydef(def).elesize;
  1810. vecbase:=tarraydef(def).lowrange;
  1811. end
  1812. else
  1813. Message(parser_e_packed_dynamic_open_array);
  1814. end;
  1815. else
  1816. Message(parser_e_illegal_expression);
  1817. end;
  1818. { Prevent overflow }
  1819. v:=index-vecbase;
  1820. if (v<int64(low(fqueue_offset))) or (v>int64(high(fqueue_offset))) then
  1821. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(fqueue_offset)),tostr(high(fqueue_offset)));
  1822. if high(fqueue_offset)-fqueue_offset div elelen>v then
  1823. inc(fqueue_offset,elelen*v.svalue)
  1824. else
  1825. message3(type_e_range_check_error_bounds,tostr(index),tostr(vecbase),tostr(high(fqueue_offset)-fqueue_offset div elelen+vecbase))
  1826. end;
  1827. procedure ttai_typedconstbuilder.queue_subscriptn(def: tabstractrecorddef; vs: tfieldvarsym);
  1828. begin
  1829. inc(fqueue_offset,vs.fieldoffset);
  1830. end;
  1831. function ttai_typedconstbuilder.queue_subscriptn_multiple_by_name(def: tabstractrecorddef; const fields: array of TIDString): tdef;
  1832. var
  1833. syms,
  1834. parentdefs: tfplist;
  1835. sym: tsym;
  1836. curdef: tdef;
  1837. i: longint;
  1838. begin
  1839. result:=nil;
  1840. if length(fields)=0 then
  1841. internalerror(2015071601);
  1842. syms:=tfplist.Create;
  1843. syms.count:=length(fields);
  1844. parentdefs:=tfplist.create;
  1845. parentdefs.Count:=length(fields);
  1846. curdef:=def;
  1847. for i:=low(fields) to high(fields) do
  1848. begin
  1849. sym:=search_struct_member_no_helper(tabstractrecorddef(curdef),fields[i]);
  1850. if not assigned(sym) or
  1851. (sym.typ<>fieldvarsym) or
  1852. ((i<>high(fields)) and
  1853. not(tfieldvarsym(sym).vardef.typ in [objectdef,recorddef])) then
  1854. internalerror(2015071505);
  1855. syms[i]:=sym;
  1856. parentdefs[i]:=curdef;
  1857. curdef:=tfieldvarsym(sym).vardef;
  1858. result:=curdef;
  1859. end;
  1860. for i:=high(fields) downto low(fields) do
  1861. queue_subscriptn(tabstractrecorddef(parentdefs[i]),tfieldvarsym(syms[i]));
  1862. syms.free;
  1863. parentdefs.free;
  1864. end;
  1865. procedure ttai_typedconstbuilder.queue_typeconvn(fromdef, todef: tdef);
  1866. begin
  1867. { do nothing }
  1868. end;
  1869. procedure ttai_typedconstbuilder.queue_emit_proc(pd: tprocdef);
  1870. begin
  1871. if fqueue_offset<>0 then
  1872. internalerror(2014092101);
  1873. emit_procdef_const(pd);
  1874. fqueue_offset:=low(fqueue_offset);
  1875. end;
  1876. procedure ttai_typedconstbuilder.queue_emit_staticvar(vs: tstaticvarsym);
  1877. begin
  1878. { pointerdef because we are emitting a pointer to the staticvarsym
  1879. data, not the data itself }
  1880. emit_tai(Tai_const.Createname(vs.mangledname,AT_DATA,fqueue_offset),cpointerdef.getreusable(vs.vardef));
  1881. fqueue_offset:=low(fqueue_offset);
  1882. end;
  1883. procedure ttai_typedconstbuilder.queue_emit_label(l: tlabelsym);
  1884. begin
  1885. emit_tai(Tai_const.Createname(l.mangledname,fqueue_offset),voidcodepointertype);
  1886. fqueue_offset:=low(fqueue_offset);
  1887. end;
  1888. procedure ttai_typedconstbuilder.queue_emit_const(cs: tconstsym);
  1889. var
  1890. resourcestrrec: trecorddef;
  1891. begin
  1892. if cs.consttyp<>constresourcestring then
  1893. internalerror(2014062102);
  1894. if fqueue_offset<>0 then
  1895. internalerror(2014062103);
  1896. { warning: update if/when the type of resource strings changes }
  1897. case cs.consttyp of
  1898. constresourcestring:
  1899. begin
  1900. resourcestrrec:=trecorddef(search_system_type('TRESOURCESTRINGRECORD').typedef);
  1901. queue_subscriptn_multiple_by_name(resourcestrrec,['CURRENTVALUE']);
  1902. queue_emit_asmsym(current_asmdata.RefAsmSymbol(
  1903. make_mangledname('RESSTR',cs.owner,cs.name),AT_DATA),resourcestrrec
  1904. );
  1905. end;
  1906. { can these occur? }
  1907. constord,
  1908. conststring,constreal,
  1909. constset,constpointer,constnil,
  1910. constwstring,constguid:
  1911. internalerror(2015090903);
  1912. else
  1913. internalerror(2015090904);
  1914. end;
  1915. fqueue_offset:=low(fqueue_offset);
  1916. end;
  1917. procedure ttai_typedconstbuilder.queue_emit_asmsym(sym: tasmsymbol; def: tdef);
  1918. begin
  1919. { pointerdef, because "sym" represents the address of whatever the
  1920. data is }
  1921. def:=cpointerdef.getreusable(def);
  1922. emit_tai(Tai_const.Create_sym_offset(sym,fqueue_offset),def);
  1923. fqueue_offset:=low(fqueue_offset);
  1924. end;
  1925. procedure ttai_typedconstbuilder.queue_emit_ordconst(value: int64; def: tdef);
  1926. begin
  1927. emit_ord_const(value,def);
  1928. fqueue_offset:=low(fqueue_offset);
  1929. end;
  1930. function ttai_typedconstbuilder.queue_is_active: boolean;
  1931. begin
  1932. result:=fqueue_offset<>low(fqueue_offset)
  1933. end;
  1934. {****************************************************************************
  1935. tlowleveltypedconstplaceholder
  1936. ****************************************************************************}
  1937. constructor tlowleveltypedconstplaceholder.create(l: tasmlist; pos: tai; d: tdef);
  1938. begin
  1939. inherited create(d);
  1940. list:=l;
  1941. insertpos:=pos;
  1942. end;
  1943. procedure tlowleveltypedconstplaceholder.replace(ai: tai; d: tdef);
  1944. begin
  1945. if d<>def then
  1946. internalerror(2015091007);
  1947. list.insertafter(ai,insertpos);
  1948. list.remove(insertpos);
  1949. insertpos.free;
  1950. end;
  1951. {****************************************************************************
  1952. tai_abstracttypedconst
  1953. ****************************************************************************}
  1954. class constructor ttai_lowleveltypedconstbuilder.classcreate;
  1955. begin
  1956. caggregateinformation:=tlowlevelaggregateinformation;
  1957. end;
  1958. function ttai_lowleveltypedconstbuilder.emit_placeholder(def: tdef): ttypedconstplaceholder;
  1959. var
  1960. p: tai;
  1961. begin
  1962. check_add_placeholder(def);
  1963. p:=tai_marker.Create(mark_position);
  1964. emit_tai(p,def);
  1965. result:=tlowleveltypedconstplaceholder.create(fasmlist,p,def);
  1966. end;
  1967. procedure ttai_lowleveltypedconstbuilder.mark_anon_aggregate_alignment;
  1968. var
  1969. marker: tai_marker;
  1970. begin
  1971. marker:=tai_marker.Create(mark_position);
  1972. fasmlist.concat(marker);
  1973. tlowlevelaggregateinformation(curagginfo).anonrecmarker:=marker;
  1974. end;
  1975. procedure ttai_lowleveltypedconstbuilder.insert_marked_aggregate_alignment(def: tdef);
  1976. var
  1977. info: tlowlevelaggregateinformation;
  1978. fillbytes: asizeint;
  1979. begin
  1980. info:=tlowlevelaggregateinformation(curagginfo);
  1981. if not assigned(info.anonrecmarker) then
  1982. internalerror(2014091401);
  1983. fillbytes:=info.prepare_next_field(def);
  1984. while fillbytes>0 do
  1985. begin
  1986. fasmlist.insertafter(tai_const.create_8bit(0),info.anonrecmarker);
  1987. dec(fillbytes);
  1988. end;
  1989. fasmlist.remove(info.anonrecmarker);
  1990. info.anonrecmarker.free;
  1991. info.anonrecmarker:=nil;
  1992. end;
  1993. procedure ttai_lowleveltypedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
  1994. begin
  1995. inherited;
  1996. { The darwin/ppc64 assembler or linker seems to have trouble }
  1997. { if a section ends with a global label without any data after it. }
  1998. { So for safety, just put a dummy value here. }
  1999. { Further, the regular linker also kills this symbol when turning }
  2000. { on smart linking in case no value appears after it, so put the }
  2001. { dummy byte there always }
  2002. { Update: the Mac OS X 10.6 linker orders data that needs to be }
  2003. { relocated before all other data, so make this data relocatable, }
  2004. { otherwise the end label won't be moved with the rest }
  2005. if (tcalo_vectorized_dead_strip_end in options) and
  2006. (target_info.system in (systems_darwin+systems_aix)) then
  2007. fasmlist.concat(Tai_const.create_sym(sym));
  2008. end;
  2009. begin
  2010. ctai_typedconstbuilder:=ttai_lowleveltypedconstbuilder;
  2011. end.