aasmcnst.pas 87 KB

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