aasmdata.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  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. sysutils,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. { data label visible within the current unit, if it's global or local depends if library based smartlinking is used }
  223. procedure getdatalabel(out l: TAsmLabel);
  224. { generate an alternative (duplicate) symbol }
  225. procedure GenerateAltSymbol(p:TAsmSymbol);
  226. procedure ResetAltSymbols;
  227. property AsmSymbolDict:TFPHashObjectList read FAsmSymbolDict;
  228. property AsmCFI:TAsmCFI read FAsmCFI;
  229. { hash tables for reusing constant storage }
  230. property ConstPools[APoolType:TConstPoolType]: THashSet read GetConstPools;
  231. end;
  232. TAsmDataClass = class of TAsmData;
  233. TTCInitItem = class(TLinkedListItem)
  234. sym: tsym;
  235. offset: aint;
  236. datalabel: TAsmSymbol;
  237. datadef: TDef;
  238. constructor Create(asym: tsym; aoffset: aint; alabel: TAsmSymbol; alabeldef: tdef);
  239. end;
  240. var
  241. casmdata: TAsmDataClass;
  242. var
  243. CAsmCFI : TAsmCFIClass;
  244. current_asmdata : TAsmData;
  245. implementation
  246. uses
  247. verbose,
  248. globals,
  249. symconst,
  250. aasmtai;
  251. {$ifdef MEMDEBUG}
  252. var
  253. memasmsymbols,
  254. memasmcfi,
  255. memasmlists : TMemDebug;
  256. {$endif MEMDEBUG}
  257. {*****************************************************************************
  258. TAsmCFI
  259. *****************************************************************************}
  260. constructor TAsmCFI.create;
  261. begin
  262. end;
  263. destructor TAsmCFI.destroy;
  264. begin
  265. end;
  266. procedure TAsmCFI.generate_code(list:TAsmList);
  267. begin
  268. end;
  269. procedure TAsmCFI.start_frame(list:TAsmList);
  270. begin
  271. end;
  272. procedure TAsmCFI.end_frame(list:TAsmList);
  273. begin
  274. end;
  275. procedure TAsmCFI.outmost_frame(list: TAsmList);
  276. begin
  277. end;
  278. procedure TAsmCFI.cfa_offset(list:TAsmList;reg:tregister;ofs:longint);
  279. begin
  280. end;
  281. procedure TAsmCFI.cfa_restore(list:TAsmList;reg:tregister);
  282. begin
  283. end;
  284. procedure TAsmCFI.cfa_def_cfa(list:TAsmList;reg:tregister;ofs:longint);
  285. begin
  286. end;
  287. procedure TAsmCFI.cfa_def_cfa_register(list:TAsmList;reg:tregister);
  288. begin
  289. end;
  290. procedure TAsmCFI.cfa_def_cfa_offset(list:TAsmList;ofs:longint);
  291. begin
  292. end;
  293. function TAsmCFI.get_frame_start: TAsmLabel;
  294. begin
  295. Result:=nil;
  296. end;
  297. function TAsmCFI.get_cfa_list: TAsmList;
  298. begin
  299. Result:=nil;
  300. end;
  301. {*****************************************************************************
  302. TTCInitItem
  303. *****************************************************************************}
  304. constructor TTCInitItem.Create(asym: tsym; aoffset: aint; alabel: TAsmSymbol; alabeldef: tdef);
  305. begin
  306. inherited Create;
  307. sym:=asym;
  308. offset:=aoffset;
  309. datalabel:=alabel;
  310. datadef:=alabeldef;
  311. end;
  312. {*****************************************************************************
  313. TAsmList
  314. *****************************************************************************}
  315. constructor TAsmList.create;
  316. begin
  317. inherited create;
  318. end;
  319. function TAsmList.getlasttaifilepos : pfileposinfo;
  320. var
  321. hp : tlinkedlistitem;
  322. begin
  323. getlasttaifilepos := nil;
  324. if assigned(last) then
  325. begin
  326. { find the last file information record }
  327. if not (tai(last).typ in SkipLineInfo) then
  328. getlasttaifilepos:=@tailineinfo(last).fileinfo
  329. else
  330. { go through list backwards to find the first entry
  331. with line information
  332. }
  333. begin
  334. hp:=tai(last);
  335. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  336. hp:=hp.Previous;
  337. { found entry }
  338. if assigned(hp) then
  339. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  340. end;
  341. end;
  342. end;
  343. procedure TAsmList.insertList(p : TLinkedList);
  344. begin
  345. inherited insertList(p);
  346. inc(section_count,TAsmList(p).section_count);
  347. TAsmList(p).section_count:=0;
  348. end;
  349. procedure TAsmList.insertListBefore(Item : TLinkedListItem; p : TLinkedList);
  350. begin
  351. inherited insertListBefore(Item,p);
  352. inc(section_count,TAsmList(p).section_count);
  353. TAsmList(p).section_count:=0;
  354. end;
  355. procedure TAsmList.insertListAfter(Item : TLinkedListItem; p : TLinkedList);
  356. begin
  357. inherited insertListAfter(Item,p);
  358. inc(section_count,TAsmList(p).section_count);
  359. TAsmList(p).section_count:=0;
  360. end;
  361. procedure TAsmList.concatList(p : TLinkedList);
  362. begin
  363. inherited concatList(p);
  364. inc(section_count,TAsmList(p).section_count);
  365. TAsmList(p).section_count:=0;
  366. end;
  367. procedure TAsmList.insertListcopy(p : TLinkedList);
  368. begin
  369. inherited insertListcopy(p);
  370. inc(section_count,TAsmList(p).section_count);
  371. end;
  372. procedure TAsmList.concatListcopy(p : TLinkedList);
  373. begin
  374. inherited concatListcopy(p);
  375. inc(section_count,TAsmList(p).section_count);
  376. end;
  377. procedure TAsmList.RemoveAll;
  378. begin
  379. inherited RemoveAll;
  380. section_count:=0;
  381. end;
  382. {****************************************************************************
  383. TAsmData
  384. ****************************************************************************}
  385. function TAsmData.GetConstPools(APoolType: TConstPoolType): THashSet;
  386. begin
  387. if FConstPools[APoolType] = nil then
  388. case APoolType of
  389. sp_ansistr: FConstPools[APoolType] := TTagHashSet.Create(64, True, False);
  390. else
  391. FConstPools[APoolType] := THashSet.Create(64, True, False);
  392. end;
  393. Result := FConstPools[APoolType];
  394. end;
  395. function TAsmData.DefineAsmSymbolByClassBase(symclass: TAsmSymbolClass; const s: TSymStr; _bind: TAsmSymBind; _typ: Tasmsymtype; def: tdef; out wasdefined: boolean): TAsmSymbol;
  396. var
  397. hp : TAsmSymbol;
  398. namestr : TSymStr;
  399. begin
  400. { this difference is only necessary to determine whether we always need
  401. indirect references or not }
  402. if _typ in [AT_DATA_FORCEINDIRECT,AT_DATA_NOINDIRECT] then
  403. _typ:=AT_DATA;
  404. namestr:=s;
  405. if _bind in asmsymbindindirect then
  406. namestr:=namestr+suffix_indirect;
  407. hp:=TAsmSymbol(FAsmSymbolDict.Find(namestr));
  408. if assigned(hp) then
  409. begin
  410. { Redefine is allowed, but the types must be the same. The redefine
  411. is needed for Darwin where the labels are first allocated }
  412. wasdefined:=not(hp.bind in [AB_EXTERNAL,AB_WEAK_EXTERNAL]);
  413. if wasdefined then
  414. begin
  415. if (hp.bind<>_bind) and
  416. (hp.typ<>_typ) then
  417. internalerror(200603261);
  418. end;
  419. hp.typ:=_typ;
  420. { Changing bind from AB_GLOBAL to AB_LOCAL is wrong
  421. if bind is already AB_GLOBAL or AB_EXTERNAL,
  422. GOT might have been used, so change might be harmful. }
  423. if (_bind<>hp.bind) and (hp.getrefs>0) then
  424. begin
  425. {$ifdef extdebug}
  426. { the changes that matter must become internalerrors, the rest
  427. should be ignored; a used cannot change anything about this,
  428. so printing a warning/hint is not useful }
  429. if (_bind=AB_LOCAL) then
  430. Message3(asmw_w_changing_bind_type,namestr,asmsymbindname[hp.bind],asmsymbindname[_bind])
  431. else
  432. Message3(asmw_h_changing_bind_type,namestr,asmsymbindname[hp.bind],asmsymbindname[_bind]);
  433. {$endif extdebug}
  434. end;
  435. hp.bind:=_bind;
  436. end
  437. else
  438. begin
  439. wasdefined:=false;
  440. { Not found, insert it. }
  441. hp:=symclass.create(AsmSymbolDict,namestr,_bind,_typ);
  442. end;
  443. result:=hp;
  444. end;
  445. constructor TAsmData.create(n:pshortstring);
  446. var
  447. alt : TAsmLabelType;
  448. hal : TAsmListType;
  449. begin
  450. inherited create;
  451. name:=n;
  452. { symbols }
  453. FAsmSymbolDict:=TFPHashObjectList.create(true);
  454. FAltSymbolList:=TFPObjectList.Create(false);
  455. { labels }
  456. FNextAltNr:=1;
  457. for alt:=low(TAsmLabelType) to high(TAsmLabelType) do
  458. FNextLabelNr[alt]:=1;
  459. { AsmLists }
  460. CurrAsmList:=TAsmList.create;
  461. for hal:=low(TAsmListType) to high(TAsmListType) do
  462. AsmLists[hal]:=TAsmList.create;
  463. WideInits :=TAsmList.create;
  464. ResStrInits:=TAsmList.create;
  465. { CFI }
  466. FAsmCFI:=CAsmCFI.Create;
  467. end;
  468. destructor TAsmData.destroy;
  469. var
  470. hal : TAsmListType;
  471. hp : TConstPoolType;
  472. begin
  473. { Symbols }
  474. {$ifdef MEMDEBUG}
  475. memasmsymbols.start;
  476. {$endif}
  477. FAltSymbolList.free;
  478. FAltSymbolList := nil;
  479. FAsmSymbolDict.free;
  480. FAsmSymbolDict := nil;
  481. {$ifdef MEMDEBUG}
  482. memasmsymbols.stop;
  483. {$endif}
  484. { CFI }
  485. {$ifdef MEMDEBUG}
  486. memasmcfi.start;
  487. {$endif}
  488. FAsmCFI.free;
  489. FAsmCFI := nil;
  490. {$ifdef MEMDEBUG}
  491. memasmcfi.stop;
  492. {$endif}
  493. { Lists }
  494. {$ifdef MEMDEBUG}
  495. memasmlists.start;
  496. {$endif}
  497. ResStrInits.free;
  498. ResStrInits := nil;
  499. WideInits.free;
  500. WideInits := nil;
  501. for hal:=low(TAsmListType) to high(TAsmListType) do
  502. FreeAndNil(AsmLists[hal]);
  503. CurrAsmList.free;
  504. CurrAsmList := nil;
  505. {$ifdef MEMDEBUG}
  506. memasmlists.stop;
  507. {$endif}
  508. for hp := low(TConstPoolType) to high(TConstPoolType) do
  509. FreeAndNil(FConstPools[hp]);
  510. end;
  511. function TAsmData.DefineAsmSymbolByClass(symclass: TAsmSymbolClass; const s: TSymStr; _bind: TAsmSymBind; _typ: Tasmsymtype; def: tdef): TAsmSymbol;
  512. var
  513. wasdefined: boolean;
  514. begin
  515. result:=DefineAsmSymbolByClassBase(symclass,s,_bind,_typ,def,wasdefined);
  516. end;
  517. function TAsmData.DefineAsmSymbol(const s: TSymStr; _bind: TAsmSymBind; _typ: Tasmsymtype; def: tdef): TAsmSymbol;
  518. begin
  519. result:=DefineAsmSymbolByClass(TAsmSymbol,s,_bind,_typ,def);
  520. end;
  521. function TAsmData.DefineProcAsmSymbol(pd: tdef; const s: TSymStr; global: boolean): TAsmSymbol;
  522. begin
  523. { The condition to use global or local symbol must match
  524. the code written in hlcg.gen_proc_symbol to
  525. avoid change from AB_LOCAL to AB_GLOBAL, which generates
  526. erroneous code (at least for targets using GOT) }
  527. if global or
  528. (cs_profile in current_settings.moduleswitches) then
  529. result:=DefineAsmSymbol(s,AB_GLOBAL,AT_FUNCTION,pd)
  530. else if tf_supports_hidden_symbols in target_info.flags then
  531. result:=DefineAsmSymbol(s,AB_PRIVATE_EXTERN,AT_FUNCTION,pd)
  532. else
  533. result:=DefineAsmSymbol(s,AB_LOCAL,AT_FUNCTION,pd);
  534. end;
  535. function TAsmData.RefAsmSymbolByClass(symclass: TAsmSymbolClass; const s : TSymStr;_typ:Tasmsymtype;indirect:boolean) : TAsmSymbol;
  536. var
  537. namestr : TSymStr;
  538. bind : tasmsymbind;
  539. begin
  540. namestr:=s;
  541. if indirect then
  542. begin
  543. namestr:=namestr+suffix_indirect;
  544. bind:=AB_EXTERNAL_INDIRECT;
  545. end
  546. else
  547. begin
  548. bind:=AB_EXTERNAL;
  549. end;
  550. result:=TAsmSymbol(FAsmSymbolDict.Find(namestr));
  551. if not assigned(result) then
  552. result:=symclass.create(AsmSymbolDict,namestr,bind,_typ)
  553. { one normal reference removes the "weak" character of a symbol }
  554. else if (result.bind=AB_WEAK_EXTERNAL) then
  555. result.bind:=bind;
  556. end;
  557. function TAsmData.RefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype;indirect:boolean) : TAsmSymbol;
  558. begin
  559. result:=RefAsmSymbolByClass(TAsmSymbol,s,_typ,indirect);
  560. end;
  561. function TAsmData.WeakRefAsmSymbolByClass(symclass: TAsmSymbolClass; const s : TSymStr;_typ:Tasmsymtype) : TAsmSymbol;
  562. begin
  563. result:=TAsmSymbol(FAsmSymbolDict.Find(s));
  564. if not assigned(result) then
  565. result:=symclass.create(AsmSymbolDict,s,AB_WEAK_EXTERNAL,_typ);
  566. end;
  567. function TAsmData.WeakRefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype) : TAsmSymbol;
  568. begin
  569. result:=WeakRefAsmSymbolByClass(TAsmSymbol,s,_typ);
  570. end;
  571. function TAsmData.GetAsmSymbol(const s : TSymStr) : TAsmSymbol;
  572. begin
  573. result:=TAsmSymbol(FAsmSymbolDict.Find(s));
  574. end;
  575. procedure TAsmData.GenerateAltSymbol(p:TAsmSymbol);
  576. begin
  577. if not assigned(p.altsymbol) then
  578. begin
  579. p.altsymbol:=p.getaltcopy(AsmSymbolDict,FNextAltNr);
  580. FAltSymbolList.Add(p);
  581. end;
  582. end;
  583. procedure TAsmData.ResetAltSymbols;
  584. var
  585. i : longint;
  586. begin
  587. for i:=0 to FAltSymbolList.Count-1 do
  588. TAsmSymbol(FAltSymbolList[i]).altsymbol:=nil;
  589. FAltSymbolList.Clear;
  590. end;
  591. procedure TAsmData.getlabel(out l : TAsmLabel;alt:TAsmLabeltype);
  592. begin
  593. if (target_info.system in (systems_linux + systems_bsd + systems_android)) and
  594. { the next condition was
  595. (cs_create_smart in current_settings.moduleswitches) and
  596. but if we create_smartlink_sections, this is useless }
  597. (create_smartlink_library) and
  598. (alt = alt_dbgline) then
  599. l:=TAsmLabel.createglobal(AsmSymbolDict,name^,FNextLabelNr[alt],alt)
  600. else
  601. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt],alt);
  602. inc(FNextLabelNr[alt]);
  603. end;
  604. procedure TAsmData.getjumplabel(out l : TAsmLabel);
  605. begin
  606. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt_jump],alt_jump);
  607. inc(FNextLabelNr[alt_jump]);
  608. end;
  609. procedure TAsmData.getglobaljumplabel(out l : TAsmLabel);
  610. begin
  611. l:=TAsmLabel.createglobal(AsmSymbolDict,name^,FNextLabelNr[alt_jump],alt_jump);
  612. inc(FNextLabelNr[alt_jump]);
  613. end;
  614. procedure TAsmData.getglobaldatalabel(out l : TAsmLabel);
  615. begin
  616. l:=TAsmLabel.createglobal(AsmSymbolDict,name^,FNextLabelNr[alt_data],alt_data);
  617. inc(FNextLabelNr[alt_data]);
  618. end;
  619. procedure TAsmData.getstaticdatalabel(out l : TAsmLabel);
  620. begin
  621. l:=TAsmLabel.createstatic(AsmSymbolDict,FNextLabelNr[alt_data],alt_data);
  622. inc(FNextLabelNr[alt_data]);
  623. end;
  624. procedure TAsmData.getlocaldatalabel(out l: TAsmLabel);
  625. begin
  626. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt_data],alt_data);
  627. inc(FNextLabelNr[alt_data]);
  628. end;
  629. procedure TAsmData.getdatalabel(out l : TAsmLabel);
  630. begin
  631. if create_smartlink_library then
  632. getglobaldatalabel(l)
  633. else
  634. getlocaldatalabel(l);
  635. end;
  636. procedure TAsmData.getaddrlabel(out l : TAsmLabel);
  637. begin
  638. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt_addr],alt_addr);
  639. inc(FNextLabelNr[alt_addr]);
  640. end;
  641. initialization
  642. {$ifdef MEMDEBUG}
  643. memasmsymbols:=TMemDebug.create('AsmSymbols');
  644. memasmsymbols.stop;
  645. memasmcfi:=TMemDebug.create('AsmCFI');
  646. memasmcfi.stop;
  647. memasmlists:=TMemDebug.create('AsmLists');
  648. memasmlists.stop;
  649. {$endif MEMDEBUG}
  650. if not(assigned(CAsmCFI)) then
  651. CAsmCFI:=TAsmCFI;
  652. finalization
  653. {$ifdef MEMDEBUG}
  654. memasmsymbols.free;
  655. memasmsymbols := nil;
  656. memasmcfi.free;
  657. memasmcfi := nil;
  658. memasmlists.free;
  659. memasmlists := nil;
  660. {$endif MEMDEBUG}
  661. end.