aasmdata.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. {
  2. Copyright (c) 1998-2006 by Florian Klaempfl
  3. This unit implements an abstract asmoutput class for all processor types
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. { @abstract(This unit implements an abstract asm output class for all processor types)
  18. This unit implements an abstract assembler output class for all processors, these
  19. are then overridden for each assembler writer to actually write the data in these
  20. classes to an assembler file.
  21. }
  22. unit aasmdata;
  23. {$i fpcdefs.inc}
  24. interface
  25. uses
  26. cutils,cclasses,
  27. globtype,systems,
  28. cgbase,
  29. symtype,
  30. aasmbase;
  31. type
  32. { Type of AsmLists. The order is important for the layout of the
  33. information in the .o file. The stabs for the types must be defined
  34. before they can be referenced and therefor they need to be written
  35. first (PFV) }
  36. TAsmListType=(
  37. al_start,
  38. al_stabs,
  39. { pure assembler routines }
  40. al_pure_assembler,
  41. al_procedures,
  42. al_globals,
  43. al_const,
  44. al_typedconsts,
  45. al_rotypedconsts,
  46. al_threadvars,
  47. al_imports,
  48. al_exports,
  49. al_resources,
  50. al_rtti,
  51. { all symbols with indirect suffix }
  52. al_indirectglobals,
  53. al_dwarf_frame,
  54. al_dwarf_info,
  55. al_dwarf_abbrev,
  56. al_dwarf_line,
  57. al_dwarf_aranges,
  58. al_dwarf_ranges,
  59. al_dwarf_loc,
  60. al_dwarf_loclists,
  61. al_picdata,
  62. al_indirectpicdata,
  63. al_resourcestrings,
  64. { Objective-C related sections }
  65. al_objc_data,
  66. { keep pool data separate, so we can generate new pool entries
  67. while emitting other data }
  68. al_objc_pools,
  69. al_end
  70. );
  71. {$push}{$j-}
  72. const
  73. globaldataasmlisttypes: array[1..5] of TAsmListType = (
  74. al_globals,
  75. al_const,
  76. al_typedconsts,
  77. al_rotypedconsts,
  78. al_threadvars
  79. );
  80. {$pop}
  81. { Type of constant 'pools'. Mostly for string types, but usable for
  82. floating point and large set constants, too. }
  83. type
  84. TConstPoolType = (
  85. sp_invalid,
  86. sp_conststr,
  87. sp_shortstr,
  88. sp_longstr,
  89. sp_ansistr,
  90. sp_widestr,
  91. sp_unicodestr,
  92. sp_objcclassnamerefs,
  93. sp_varnamerefs,
  94. sp_objcclassnames,
  95. sp_objcvarnames,
  96. sp_objcvartypes,
  97. sp_objcprotocolrefs,
  98. sp_varsets,
  99. sp_floats,
  100. sp_guids,
  101. sp_paraloc
  102. );
  103. const
  104. AsmListTypeStr : array[TAsmListType] of string[24] =(
  105. 'al_begin',
  106. 'al_stabs',
  107. 'al_pure_assembler',
  108. 'al_procedures',
  109. 'al_globals',
  110. 'al_const',
  111. 'al_typedconsts',
  112. 'al_rotypedconsts',
  113. 'al_threadvars',
  114. 'al_imports',
  115. 'al_exports',
  116. 'al_resources',
  117. 'al_rtti',
  118. 'al_indirectglobals',
  119. 'al_dwarf_frame',
  120. 'al_dwarf_info',
  121. 'al_dwarf_abbrev',
  122. 'al_dwarf_line',
  123. 'al_dwarf_aranges',
  124. 'al_dwarf_ranges',
  125. 'al_dwarf_loc',
  126. 'al_dwarf_loclists',
  127. 'al_picdata',
  128. 'al_indirectpicdata',
  129. 'al_resourcestrings',
  130. 'al_objc_data',
  131. 'al_objc_pools',
  132. 'al_end'
  133. );
  134. type
  135. TAsmList = class(tlinkedlist)
  136. section_count : longint;
  137. constructor create;
  138. function getlasttaifilepos : pfileposinfo;
  139. { inserts another List at the begin and make this List empty }
  140. procedure insertList(p : TLinkedList); override;
  141. { inserts another List before the provided item and make this List empty }
  142. procedure insertListBefore(Item:TLinkedListItem;p : TLinkedList); override;
  143. { inserts another List after the provided item and make this List empty }
  144. procedure insertListAfter(Item:TLinkedListItem;p : TLinkedList); override;
  145. { concats another List at the end and make this List empty }
  146. procedure concatList(p : TLinkedList); override;
  147. { concats another List at the start and makes a copy
  148. the list is ordered in reverse.
  149. }
  150. procedure insertListcopy(p : TLinkedList); override;
  151. { concats another List at the end and makes a copy }
  152. procedure concatListcopy(p : TLinkedList); override;
  153. { removes all items from the list, the items are not freed }
  154. procedure RemoveAll; override;
  155. end;
  156. TAsmCFI=class
  157. public
  158. constructor create;virtual;
  159. destructor destroy;override;
  160. procedure generate_code(list:TAsmList);virtual;
  161. procedure start_frame(list:TAsmList);virtual;
  162. procedure end_frame(list:TAsmList);virtual;
  163. procedure outmost_frame(list:TAsmList);virtual;
  164. procedure cfa_offset(list:TAsmList;reg:tregister;ofs:longint);virtual;
  165. procedure cfa_restore(list:TAsmList;reg:tregister);virtual;
  166. procedure cfa_def_cfa(list:TAsmList;reg:tregister;ofs:longint);virtual;
  167. procedure cfa_def_cfa_register(list:TAsmList;reg:tregister);virtual;
  168. procedure cfa_def_cfa_offset(list:TAsmList;ofs:longint);virtual;
  169. function get_frame_start: TAsmLabel;virtual;
  170. function get_cfa_list : TAsmList;virtual;
  171. end;
  172. TAsmCFIClass=class of TAsmCFI;
  173. { TAsmData }
  174. TAsmData = class
  175. private
  176. { Symbols }
  177. FAsmSymbolDict : TFPHashObjectList;
  178. FAltSymbolList : TFPObjectList;
  179. FNextAltNr : longint;
  180. FNextLabelNr : array[TAsmLabeltype] of longint;
  181. { Call Frame Information for stack unwinding}
  182. FAsmCFI : TAsmCFI;
  183. FConstPools : array[TConstPoolType] of THashSet;
  184. function GetConstPools(APoolType: TConstPoolType): THashSet;
  185. protected
  186. function DefineAsmSymbolByClassBase(symclass: TAsmSymbolClass; const s : TSymStr;_bind:TAsmSymBind;_typ:Tasmsymtype; def: tdef; out wasdefined: boolean) : TAsmSymbol;
  187. public
  188. name : pshortstring; { owned by tmodule }
  189. NextVTEntryNr : longint;
  190. { Assembler lists }
  191. AsmLists : array[TAsmListType] of TAsmList;
  192. CurrAsmList : TAsmList;
  193. WideInits : TLinkedList;
  194. ResStrInits : TLinkedList;
  195. constructor create(n: pshortstring);
  196. destructor destroy;override;
  197. { asmsymbol }
  198. function DefineAsmSymbolByClass(symclass: TAsmSymbolClass; const s : TSymStr;_bind:TAsmSymBind;_typ:Tasmsymtype; def: tdef) : TAsmSymbol; virtual;
  199. function DefineAsmSymbol(const s : TSymStr;_bind:TAsmSymBind;_typ:Tasmsymtype; def: tdef) : TAsmSymbol;
  200. function DefineProcAsmSymbol(pd: tdef; const s: TSymStr; global: boolean): TAsmSymbol;
  201. function WeakRefAsmSymbolByClass(symclass: TAsmSymbolClass; const s : TSymStr;_typ:Tasmsymtype) : TAsmSymbol;
  202. function WeakRefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype) : TAsmSymbol;
  203. function RefAsmSymbolByClass(symclass: TAsmSymbolClass; const s : TSymStr;_typ:Tasmsymtype;indirect:boolean=false) : TAsmSymbol;
  204. function RefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype;indirect:boolean=false) : TAsmSymbol;
  205. function GetAsmSymbol(const s : TSymStr) : TAsmSymbol;
  206. { create new assembler label }
  207. procedure getlabel(out l : TAsmLabel;alt:TAsmLabeltype);
  208. procedure getjumplabel(out l : TAsmLabel);
  209. procedure getglobaljumplabel(out l : TAsmLabel);
  210. procedure getaddrlabel(out l : TAsmLabel);
  211. { visible from outside current object }
  212. procedure getglobaldatalabel(out l : TAsmLabel);
  213. { visible only inside current object, but doesn't start with
  214. target_asm.label_prefix (treated the Darwin linker as the start of a
  215. dead-strippable data block) }
  216. procedure getstaticdatalabel(out l : TAsmLabel);
  217. { visible only inside the current object and does start with
  218. target_asm.label_prefix (not treated by the Darwin linker as the start
  219. of a dead-strippable data block, and references to such labels are
  220. also ignored to determine whether a data block should be live) }
  221. procedure getlocaldatalabel(out l : TAsmLabel);
  222. { generate an alternative (duplicate) symbol }
  223. procedure GenerateAltSymbol(p:TAsmSymbol);
  224. procedure ResetAltSymbols;
  225. property AsmSymbolDict:TFPHashObjectList read FAsmSymbolDict;
  226. property AsmCFI:TAsmCFI read FAsmCFI;
  227. { hash tables for reusing constant storage }
  228. property ConstPools[APoolType:TConstPoolType]: THashSet read GetConstPools;
  229. end;
  230. TAsmDataClass = class of TAsmData;
  231. TTCInitItem = class(TLinkedListItem)
  232. sym: tsym;
  233. offset: aint;
  234. datalabel: TAsmSymbol;
  235. datadef: TDef;
  236. constructor Create(asym: tsym; aoffset: aint; alabel: TAsmSymbol; alabeldef: tdef);
  237. end;
  238. var
  239. casmdata: TAsmDataClass;
  240. var
  241. CAsmCFI : TAsmCFIClass;
  242. current_asmdata : TAsmData;
  243. implementation
  244. uses
  245. verbose,
  246. globals,
  247. symconst,
  248. aasmtai;
  249. {$ifdef MEMDEBUG}
  250. var
  251. memasmsymbols,
  252. memasmcfi,
  253. memasmlists : TMemDebug;
  254. {$endif MEMDEBUG}
  255. {*****************************************************************************
  256. TAsmCFI
  257. *****************************************************************************}
  258. constructor TAsmCFI.create;
  259. begin
  260. end;
  261. destructor TAsmCFI.destroy;
  262. begin
  263. end;
  264. procedure TAsmCFI.generate_code(list:TAsmList);
  265. begin
  266. end;
  267. procedure TAsmCFI.start_frame(list:TAsmList);
  268. begin
  269. end;
  270. procedure TAsmCFI.end_frame(list:TAsmList);
  271. begin
  272. end;
  273. procedure TAsmCFI.outmost_frame(list: TAsmList);
  274. begin
  275. end;
  276. procedure TAsmCFI.cfa_offset(list:TAsmList;reg:tregister;ofs:longint);
  277. begin
  278. end;
  279. procedure TAsmCFI.cfa_restore(list:TAsmList;reg:tregister);
  280. begin
  281. end;
  282. procedure TAsmCFI.cfa_def_cfa(list:TAsmList;reg:tregister;ofs:longint);
  283. begin
  284. end;
  285. procedure TAsmCFI.cfa_def_cfa_register(list:TAsmList;reg:tregister);
  286. begin
  287. end;
  288. procedure TAsmCFI.cfa_def_cfa_offset(list:TAsmList;ofs:longint);
  289. begin
  290. end;
  291. function TAsmCFI.get_frame_start: TAsmLabel;
  292. begin
  293. Result:=nil;
  294. end;
  295. function TAsmCFI.get_cfa_list: TAsmList;
  296. begin
  297. Result:=nil;
  298. end;
  299. {*****************************************************************************
  300. TTCInitItem
  301. *****************************************************************************}
  302. constructor TTCInitItem.Create(asym: tsym; aoffset: aint; alabel: TAsmSymbol; alabeldef: tdef);
  303. begin
  304. inherited Create;
  305. sym:=asym;
  306. offset:=aoffset;
  307. datalabel:=alabel;
  308. datadef:=alabeldef;
  309. end;
  310. {*****************************************************************************
  311. TAsmList
  312. *****************************************************************************}
  313. constructor TAsmList.create;
  314. begin
  315. inherited create;
  316. end;
  317. function TAsmList.getlasttaifilepos : pfileposinfo;
  318. var
  319. hp : tlinkedlistitem;
  320. begin
  321. getlasttaifilepos := nil;
  322. if assigned(last) then
  323. begin
  324. { find the last file information record }
  325. if not (tai(last).typ in SkipLineInfo) then
  326. getlasttaifilepos:=@tailineinfo(last).fileinfo
  327. else
  328. { go through list backwards to find the first entry
  329. with line information
  330. }
  331. begin
  332. hp:=tai(last);
  333. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  334. hp:=hp.Previous;
  335. { found entry }
  336. if assigned(hp) then
  337. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  338. end;
  339. end;
  340. end;
  341. procedure TAsmList.insertList(p : TLinkedList);
  342. begin
  343. inherited insertList(p);
  344. inc(section_count,TAsmList(p).section_count);
  345. TAsmList(p).section_count:=0;
  346. end;
  347. procedure TAsmList.insertListBefore(Item : TLinkedListItem; p : TLinkedList);
  348. begin
  349. inherited insertListBefore(Item,p);
  350. inc(section_count,TAsmList(p).section_count);
  351. TAsmList(p).section_count:=0;
  352. end;
  353. procedure TAsmList.insertListAfter(Item : TLinkedListItem; p : TLinkedList);
  354. begin
  355. inherited insertListAfter(Item,p);
  356. inc(section_count,TAsmList(p).section_count);
  357. TAsmList(p).section_count:=0;
  358. end;
  359. procedure TAsmList.concatList(p : TLinkedList);
  360. begin
  361. inherited concatList(p);
  362. inc(section_count,TAsmList(p).section_count);
  363. TAsmList(p).section_count:=0;
  364. end;
  365. procedure TAsmList.insertListcopy(p : TLinkedList);
  366. begin
  367. inherited insertListcopy(p);
  368. inc(section_count,TAsmList(p).section_count);
  369. end;
  370. procedure TAsmList.concatListcopy(p : TLinkedList);
  371. begin
  372. inherited concatListcopy(p);
  373. inc(section_count,TAsmList(p).section_count);
  374. end;
  375. procedure TAsmList.RemoveAll;
  376. begin
  377. inherited RemoveAll;
  378. section_count:=0;
  379. end;
  380. {****************************************************************************
  381. TAsmData
  382. ****************************************************************************}
  383. function TAsmData.GetConstPools(APoolType: TConstPoolType): THashSet;
  384. begin
  385. if FConstPools[APoolType] = nil then
  386. case APoolType of
  387. sp_ansistr: FConstPools[APoolType] := TTagHashSet.Create(64, True, False);
  388. else
  389. FConstPools[APoolType] := THashSet.Create(64, True, False);
  390. end;
  391. Result := FConstPools[APoolType];
  392. end;
  393. function TAsmData.DefineAsmSymbolByClassBase(symclass: TAsmSymbolClass; const s: TSymStr; _bind: TAsmSymBind; _typ: Tasmsymtype; def: tdef; out wasdefined: boolean): TAsmSymbol;
  394. var
  395. hp : TAsmSymbol;
  396. namestr : TSymStr;
  397. begin
  398. { this difference is only necessary to determine whether we always need
  399. indirect references or not }
  400. if _typ in [AT_DATA_FORCEINDIRECT,AT_DATA_NOINDIRECT] then
  401. _typ:=AT_DATA;
  402. namestr:=s;
  403. if _bind in asmsymbindindirect then
  404. namestr:=namestr+suffix_indirect;
  405. hp:=TAsmSymbol(FAsmSymbolDict.Find(namestr));
  406. if assigned(hp) then
  407. begin
  408. { Redefine is allowed, but the types must be the same. The redefine
  409. is needed for Darwin where the labels are first allocated }
  410. wasdefined:=not(hp.bind in [AB_EXTERNAL,AB_WEAK_EXTERNAL]);
  411. if wasdefined then
  412. begin
  413. if (hp.bind<>_bind) and
  414. (hp.typ<>_typ) then
  415. internalerror(200603261);
  416. end;
  417. hp.typ:=_typ;
  418. { Changing bind from AB_GLOBAL to AB_LOCAL is wrong
  419. if bind is already AB_GLOBAL or AB_EXTERNAL,
  420. GOT might have been used, so change might be harmful. }
  421. if (_bind<>hp.bind) and (hp.getrefs>0) then
  422. begin
  423. {$ifdef extdebug}
  424. { the changes that matter must become internalerrors, the rest
  425. should be ignored; a used cannot change anything about this,
  426. so printing a warning/hint is not useful }
  427. if (_bind=AB_LOCAL) then
  428. Message3(asmw_w_changing_bind_type,namestr,asmsymbindname[hp.bind],asmsymbindname[_bind])
  429. else
  430. Message3(asmw_h_changing_bind_type,namestr,asmsymbindname[hp.bind],asmsymbindname[_bind]);
  431. {$endif extdebug}
  432. end;
  433. hp.bind:=_bind;
  434. end
  435. else
  436. begin
  437. wasdefined:=false;
  438. { Not found, insert it. }
  439. hp:=symclass.create(AsmSymbolDict,namestr,_bind,_typ);
  440. end;
  441. result:=hp;
  442. end;
  443. constructor TAsmData.create(n:pshortstring);
  444. var
  445. alt : TAsmLabelType;
  446. hal : TAsmListType;
  447. begin
  448. inherited create;
  449. name:=n;
  450. { symbols }
  451. FAsmSymbolDict:=TFPHashObjectList.create(true);
  452. FAltSymbolList:=TFPObjectList.Create(false);
  453. { labels }
  454. FNextAltNr:=1;
  455. for alt:=low(TAsmLabelType) to high(TAsmLabelType) do
  456. FNextLabelNr[alt]:=1;
  457. { AsmLists }
  458. CurrAsmList:=TAsmList.create;
  459. for hal:=low(TAsmListType) to high(TAsmListType) do
  460. AsmLists[hal]:=TAsmList.create;
  461. WideInits :=TAsmList.create;
  462. ResStrInits:=TAsmList.create;
  463. { CFI }
  464. FAsmCFI:=CAsmCFI.Create;
  465. end;
  466. destructor TAsmData.destroy;
  467. var
  468. hal : TAsmListType;
  469. hp : TConstPoolType;
  470. begin
  471. { Symbols }
  472. {$ifdef MEMDEBUG}
  473. memasmsymbols.start;
  474. {$endif}
  475. FAltSymbolList.free;
  476. FAsmSymbolDict.free;
  477. {$ifdef MEMDEBUG}
  478. memasmsymbols.stop;
  479. {$endif}
  480. { CFI }
  481. {$ifdef MEMDEBUG}
  482. memasmcfi.start;
  483. {$endif}
  484. FAsmCFI.free;
  485. {$ifdef MEMDEBUG}
  486. memasmcfi.stop;
  487. {$endif}
  488. { Lists }
  489. {$ifdef MEMDEBUG}
  490. memasmlists.start;
  491. {$endif}
  492. ResStrInits.free;
  493. WideInits.free;
  494. for hal:=low(TAsmListType) to high(TAsmListType) do
  495. AsmLists[hal].free;
  496. CurrAsmList.free;
  497. {$ifdef MEMDEBUG}
  498. memasmlists.stop;
  499. {$endif}
  500. for hp := low(TConstPoolType) to high(TConstPoolType) do
  501. FConstPools[hp].Free;
  502. end;
  503. function TAsmData.DefineAsmSymbolByClass(symclass: TAsmSymbolClass; const s: TSymStr; _bind: TAsmSymBind; _typ: Tasmsymtype; def: tdef): TAsmSymbol;
  504. var
  505. wasdefined: boolean;
  506. begin
  507. result:=DefineAsmSymbolByClassBase(symclass,s,_bind,_typ,def,wasdefined);
  508. end;
  509. function TAsmData.DefineAsmSymbol(const s: TSymStr; _bind: TAsmSymBind; _typ: Tasmsymtype; def: tdef): TAsmSymbol;
  510. begin
  511. result:=DefineAsmSymbolByClass(TAsmSymbol,s,_bind,_typ,def);
  512. end;
  513. function TAsmData.DefineProcAsmSymbol(pd: tdef; const s: TSymStr; global: boolean): TAsmSymbol;
  514. begin
  515. { The condition to use global or local symbol must match
  516. the code written in hlcg.gen_proc_symbol to
  517. avoid change from AB_LOCAL to AB_GLOBAL, which generates
  518. erroneous code (at least for targets using GOT) }
  519. if global or
  520. (cs_profile in current_settings.moduleswitches) then
  521. result:=DefineAsmSymbol(s,AB_GLOBAL,AT_FUNCTION,pd)
  522. else if tf_supports_hidden_symbols in target_info.flags then
  523. result:=DefineAsmSymbol(s,AB_PRIVATE_EXTERN,AT_FUNCTION,pd)
  524. else
  525. result:=DefineAsmSymbol(s,AB_LOCAL,AT_FUNCTION,pd);
  526. end;
  527. function TAsmData.RefAsmSymbolByClass(symclass: TAsmSymbolClass; const s : TSymStr;_typ:Tasmsymtype;indirect:boolean) : TAsmSymbol;
  528. var
  529. namestr : TSymStr;
  530. bind : tasmsymbind;
  531. begin
  532. namestr:=s;
  533. if indirect then
  534. begin
  535. namestr:=namestr+suffix_indirect;
  536. bind:=AB_EXTERNAL_INDIRECT;
  537. end
  538. else
  539. begin
  540. bind:=AB_EXTERNAL;
  541. end;
  542. result:=TAsmSymbol(FAsmSymbolDict.Find(namestr));
  543. if not assigned(result) then
  544. result:=symclass.create(AsmSymbolDict,namestr,bind,_typ)
  545. { one normal reference removes the "weak" character of a symbol }
  546. else if (result.bind=AB_WEAK_EXTERNAL) then
  547. result.bind:=bind;
  548. end;
  549. function TAsmData.RefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype;indirect:boolean) : TAsmSymbol;
  550. begin
  551. result:=RefAsmSymbolByClass(TAsmSymbol,s,_typ,indirect);
  552. end;
  553. function TAsmData.WeakRefAsmSymbolByClass(symclass: TAsmSymbolClass; const s : TSymStr;_typ:Tasmsymtype) : TAsmSymbol;
  554. begin
  555. result:=TAsmSymbol(FAsmSymbolDict.Find(s));
  556. if not assigned(result) then
  557. result:=symclass.create(AsmSymbolDict,s,AB_WEAK_EXTERNAL,_typ);
  558. end;
  559. function TAsmData.WeakRefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype) : TAsmSymbol;
  560. begin
  561. result:=WeakRefAsmSymbolByClass(TAsmSymbol,s,_typ);
  562. end;
  563. function TAsmData.GetAsmSymbol(const s : TSymStr) : TAsmSymbol;
  564. begin
  565. result:=TAsmSymbol(FAsmSymbolDict.Find(s));
  566. end;
  567. procedure TAsmData.GenerateAltSymbol(p:TAsmSymbol);
  568. begin
  569. if not assigned(p.altsymbol) then
  570. begin
  571. p.altsymbol:=p.getaltcopy(AsmSymbolDict,FNextAltNr);
  572. FAltSymbolList.Add(p);
  573. end;
  574. end;
  575. procedure TAsmData.ResetAltSymbols;
  576. var
  577. i : longint;
  578. begin
  579. for i:=0 to FAltSymbolList.Count-1 do
  580. TAsmSymbol(FAltSymbolList[i]).altsymbol:=nil;
  581. FAltSymbolList.Clear;
  582. end;
  583. procedure TAsmData.getlabel(out l : TAsmLabel;alt:TAsmLabeltype);
  584. begin
  585. if (target_info.system in (systems_linux + systems_bsd + systems_android)) and
  586. { the next condition was
  587. (cs_create_smart in current_settings.moduleswitches) and
  588. but if we create_smartlink_sections, this is useless }
  589. (create_smartlink_library) and
  590. (alt = alt_dbgline) then
  591. l:=TAsmLabel.createglobal(AsmSymbolDict,name^,FNextLabelNr[alt],alt)
  592. else
  593. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt],alt);
  594. inc(FNextLabelNr[alt]);
  595. end;
  596. procedure TAsmData.getjumplabel(out l : TAsmLabel);
  597. begin
  598. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt_jump],alt_jump);
  599. inc(FNextLabelNr[alt_jump]);
  600. end;
  601. procedure TAsmData.getglobaljumplabel(out l : TAsmLabel);
  602. begin
  603. l:=TAsmLabel.createglobal(AsmSymbolDict,name^,FNextLabelNr[alt_jump],alt_jump);
  604. inc(FNextLabelNr[alt_jump]);
  605. end;
  606. procedure TAsmData.getglobaldatalabel(out l : TAsmLabel);
  607. begin
  608. l:=TAsmLabel.createglobal(AsmSymbolDict,name^,FNextLabelNr[alt_data],alt_data);
  609. inc(FNextLabelNr[alt_data]);
  610. end;
  611. procedure TAsmData.getstaticdatalabel(out l : TAsmLabel);
  612. begin
  613. l:=TAsmLabel.createstatic(AsmSymbolDict,FNextLabelNr[alt_data],alt_data);
  614. inc(FNextLabelNr[alt_data]);
  615. end;
  616. procedure TAsmData.getlocaldatalabel(out l: TAsmLabel);
  617. begin
  618. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt_data],alt_data);
  619. inc(FNextLabelNr[alt_data]);
  620. end;
  621. procedure TAsmData.getaddrlabel(out l : TAsmLabel);
  622. begin
  623. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt_addr],alt_addr);
  624. inc(FNextLabelNr[alt_addr]);
  625. end;
  626. initialization
  627. {$ifdef MEMDEBUG}
  628. memasmsymbols:=TMemDebug.create('AsmSymbols');
  629. memasmsymbols.stop;
  630. memasmcfi:=TMemDebug.create('AsmCFI');
  631. memasmcfi.stop;
  632. memasmlists:=TMemDebug.create('AsmLists');
  633. memasmlists.stop;
  634. {$endif MEMDEBUG}
  635. if not(assigned(CAsmCFI)) then
  636. CAsmCFI:=TAsmCFI;
  637. finalization
  638. {$ifdef MEMDEBUG}
  639. memasmsymbols.free;
  640. memasmcfi.free;
  641. memasmlists.free;
  642. {$endif MEMDEBUG}
  643. end.