aggas.pas 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  1. {
  2. Copyright (c) 1998-2006 by the Free Pascal team
  3. This unit implements the generic part of the GNU assembler
  4. (v2.8 or later) writer
  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. { Base unit for writing GNU assembler output.
  19. }
  20. unit aggas;
  21. {$i fpcdefs.inc}
  22. { $define DEBUG_AGGAS}
  23. interface
  24. uses
  25. globtype,globals,
  26. aasmbase,aasmtai,aasmdata,
  27. assemble;
  28. type
  29. TCPUInstrWriter = class;
  30. {# This is a derived class which is used to write
  31. GAS styled assembler.
  32. }
  33. { TGNUAssembler }
  34. TGNUAssembler=class(texternalassembler)
  35. protected
  36. function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;virtual;
  37. function sectionattrs_coff(atype:TAsmSectiontype):string;virtual;
  38. function sectionalignment_aix(atype:TAsmSectiontype;secalign: byte):string;
  39. procedure WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder;secalign:byte);
  40. procedure WriteExtraHeader;virtual;
  41. procedure WriteExtraFooter;virtual;
  42. procedure WriteInstruction(hp: tai);
  43. procedure WriteWeakSymbolDef(s: tasmsymbol); virtual;
  44. procedure WriteAixStringConst(hp: tai_string);
  45. procedure WriteAixIntConst(hp: tai_const);
  46. procedure WriteUnalignedIntConst(hp: tai_const);
  47. procedure WriteDirectiveName(dir: TAsmDirective); virtual;
  48. public
  49. function MakeCmdLine: TCmdStr; override;
  50. procedure WriteTree(p:TAsmList);override;
  51. procedure WriteAsmList;override;
  52. destructor destroy; override;
  53. private
  54. setcount: longint;
  55. procedure WriteDecodedSleb128(a: int64);
  56. procedure WriteDecodedUleb128(a: qword);
  57. function NextSetLabel: string;
  58. protected
  59. InstrWriter: TCPUInstrWriter;
  60. end;
  61. {# This is the base class for writing instructions.
  62. The WriteInstruction() method must be overridden
  63. to write a single instruction to the assembler
  64. file.
  65. }
  66. TCPUInstrWriter = class
  67. constructor create(_owner: TGNUAssembler);
  68. procedure WriteInstruction(hp : tai); virtual; abstract;
  69. protected
  70. owner: TGNUAssembler;
  71. end;
  72. { TAppleGNUAssembler }
  73. TAppleGNUAssembler=class(TGNUAssembler)
  74. protected
  75. function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override;
  76. procedure WriteWeakSymbolDef(s: tasmsymbol); override;
  77. end;
  78. TAoutGNUAssembler=class(TGNUAssembler)
  79. function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override;
  80. end;
  81. implementation
  82. uses
  83. SysUtils,
  84. cutils,cfileutl,systems,
  85. fmodule,verbose,
  86. {$ifndef DISABLE_WIN64_SEH}
  87. itcpugas,
  88. {$endif DISABLE_WIN64_SEH}
  89. {$ifdef m68k}
  90. cpuinfo,aasmcpu,
  91. {$endif m68k}
  92. cpubase;
  93. const
  94. line_length = 70;
  95. var
  96. symendcount : longint;
  97. {****************************************************************************}
  98. { Support routines }
  99. {****************************************************************************}
  100. const
  101. ait_const2str : array[aitconst_128bit..aitconst_64bit_unaligned] of string[20]=(
  102. #9'.fixme128'#9,#9'.quad'#9,#9'.long'#9,#9'.short'#9,#9'.byte'#9,
  103. #9'.sleb128'#9,#9'.uleb128'#9,
  104. #9'.rva'#9,#9'.secrel32'#9,#9'.quad'#9,#9'.long'#9,#9'.short'#9,#9'.short'#9,
  105. #9'.short'#9,#9'.long'#9,#9'.quad'#9
  106. );
  107. ait_unaligned_consts = [aitconst_16bit_unaligned..aitconst_64bit_unaligned];
  108. { Sparc type of unaligned pseudo-instructions }
  109. use_ua_sparc_systems = [system_sparc_linux];
  110. ait_ua_sparc_const2str : array[aitconst_16bit_unaligned..aitconst_64bit_unaligned]
  111. of string[20]=(
  112. #9'.uahalf'#9,#9'.uaword'#9,#9'.uaxword'#9
  113. );
  114. { Generic unaligned pseudo-instructions, seems ELF specific }
  115. use_ua_elf_systems = [system_mipsel_linux,system_mipseb_linux,system_mipsel_android,system_mipsel_embedded,system_mipseb_embedded];
  116. ait_ua_elf_const2str : array[aitconst_16bit_unaligned..aitconst_64bit_unaligned]
  117. of string[20]=(
  118. #9'.2byte'#9,#9'.4byte'#9,#9'.8byte'#9
  119. );
  120. {****************************************************************************}
  121. { GNU Assembler writer }
  122. {****************************************************************************}
  123. destructor TGNUAssembler.Destroy;
  124. begin
  125. InstrWriter.free;
  126. inherited destroy;
  127. end;
  128. function TGNUAssembler.MakeCmdLine: TCmdStr;
  129. begin
  130. result := inherited MakeCmdLine;
  131. // MWE: disabled again. It generates dwarf info for the generated .s
  132. // files as well. This conflicts with the info we generate
  133. // if target_dbg.id = dbg_dwarf then
  134. // result := result + ' --gdwarf-2';
  135. end;
  136. function TGNUAssembler.NextSetLabel: string;
  137. begin
  138. inc(setcount);
  139. result := asminfo^.labelprefix+'$set$'+tostr(setcount);
  140. end;
  141. function is_smart_section(atype:TAsmSectiontype):boolean;
  142. begin
  143. { For bss we need to set some flags that are target dependent,
  144. it is easier to disable it for smartlinking. It doesn't take up
  145. filespace }
  146. result:=not(target_info.system in systems_darwin) and
  147. create_smartlink_sections and
  148. (atype<>sec_toc) and
  149. (atype<>sec_user) and
  150. { on embedded systems every byte counts, so smartlink bss too }
  151. ((atype<>sec_bss) or (target_info.system in systems_embedded));
  152. end;
  153. function TGNUAssembler.sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
  154. const
  155. secnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
  156. '.text',
  157. '.data',
  158. { why doesn't .rodata work? (FK) }
  159. { sometimes we have to create a data.rel.ro instead of .rodata, e.g. for }
  160. { vtables (and anything else containing relocations), otherwise those are }
  161. { not relocated properly on e.g. linux/ppc64. g++ generates there for a }
  162. { vtable for a class called Window: }
  163. { .section .data.rel.ro._ZTV6Window,"awG",@progbits,_ZTV6Window,comdat }
  164. { TODO: .data.ro not yet working}
  165. {$if defined(arm) or defined(powerpc)}
  166. '.rodata',
  167. {$else arm}
  168. '.data',
  169. {$endif arm}
  170. {$if defined(m68k)} { Amiga/m68k GNU AS doesn't seem to like .rodata (KB) }
  171. '.data',
  172. {$else}
  173. '.rodata',
  174. {$endif}
  175. '.bss',
  176. '.threadvar',
  177. '.pdata',
  178. '', { stubs }
  179. '__DATA,__nl_symbol_ptr',
  180. '__DATA,__la_symbol_ptr',
  181. '__DATA,__mod_init_func',
  182. '__DATA,__mod_term_func',
  183. '.stab',
  184. '.stabstr',
  185. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  186. '.eh_frame',
  187. '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
  188. '.fpc',
  189. '.toc',
  190. '.init',
  191. '.fini',
  192. '.objc_class',
  193. '.objc_meta_class',
  194. '.objc_cat_cls_meth',
  195. '.objc_cat_inst_meth',
  196. '.objc_protocol',
  197. '.objc_string_object',
  198. '.objc_cls_meth',
  199. '.objc_inst_meth',
  200. '.objc_cls_refs',
  201. '.objc_message_refs',
  202. '.objc_symbols',
  203. '.objc_category',
  204. '.objc_class_vars',
  205. '.objc_instance_vars',
  206. '.objc_module_info',
  207. '.objc_class_names',
  208. '.objc_meth_var_types',
  209. '.objc_meth_var_names',
  210. '.objc_selector_strs',
  211. '.objc_protocol_ext',
  212. '.objc_class_ext',
  213. '.objc_property',
  214. '.objc_image_info',
  215. '.objc_cstring_object',
  216. '.objc_sel_fixup',
  217. '__DATA,__objc_data',
  218. '__DATA,__objc_const',
  219. '.objc_superrefs',
  220. '__DATA, __datacoal_nt,coalesced',
  221. '.objc_classlist',
  222. '.objc_nlclasslist',
  223. '.objc_catlist',
  224. '.obcj_nlcatlist',
  225. '.objc_protolist',
  226. '.stack',
  227. '.heap'
  228. );
  229. secnames_pic : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
  230. '.text',
  231. '.data.rel',
  232. '.data.rel',
  233. '.data.rel',
  234. '.bss',
  235. '.threadvar',
  236. '.pdata',
  237. '', { stubs }
  238. '__DATA,__nl_symbol_ptr',
  239. '__DATA,__la_symbol_ptr',
  240. '__DATA,__mod_init_func',
  241. '__DATA,__mod_term_func',
  242. '.stab',
  243. '.stabstr',
  244. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  245. '.eh_frame',
  246. '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
  247. '.fpc',
  248. '.toc',
  249. '.init',
  250. '.fini',
  251. '.objc_class',
  252. '.objc_meta_class',
  253. '.objc_cat_cls_meth',
  254. '.objc_cat_inst_meth',
  255. '.objc_protocol',
  256. '.objc_string_object',
  257. '.objc_cls_meth',
  258. '.objc_inst_meth',
  259. '.objc_cls_refs',
  260. '.objc_message_refs',
  261. '.objc_symbols',
  262. '.objc_category',
  263. '.objc_class_vars',
  264. '.objc_instance_vars',
  265. '.objc_module_info',
  266. '.objc_class_names',
  267. '.objc_meth_var_types',
  268. '.objc_meth_var_names',
  269. '.objc_selector_strs',
  270. '.objc_protocol_ext',
  271. '.objc_class_ext',
  272. '.objc_property',
  273. '.objc_image_info',
  274. '.objc_cstring_object',
  275. '.objc_sel_fixup',
  276. '__DATA, __objc_data',
  277. '__DATA, __objc_const',
  278. '.objc_superrefs',
  279. '__DATA, __datacoal_nt,coalesced',
  280. '.objc_classlist',
  281. '.objc_nlclasslist',
  282. '.objc_catlist',
  283. '.obcj_nlcatlist',
  284. '.objc_protolist',
  285. '.stack',
  286. '.heap'
  287. );
  288. var
  289. sep : string[3];
  290. secname : string;
  291. begin
  292. if (cs_create_pic in current_settings.moduleswitches) and
  293. not(target_info.system in systems_darwin) then
  294. secname:=secnames_pic[atype]
  295. else
  296. secname:=secnames[atype];
  297. {$ifdef m68k}
  298. { old Amiga GNU AS doesn't support .section .fpc }
  299. if (atype=sec_fpc) and (target_info.system = system_m68k_amiga) then
  300. secname:=secnames[sec_data];
  301. {$endif}
  302. if (atype=sec_fpc) and (Copy(aname,1,3)='res') then
  303. begin
  304. result:=secname+'.'+aname;
  305. exit;
  306. end;
  307. if (atype=sec_threadvar) and
  308. (target_info.system in (systems_windows+systems_wince)) then
  309. secname:='.tls';
  310. { go32v2 stub only loads .text and .data sections, and allocates space for .bss.
  311. Thus, data which normally goes into .rodata and .rodata_norel sections must
  312. end up in .data section }
  313. if (atype in [sec_rodata,sec_rodata_norel]) and
  314. (target_info.system=system_i386_go32v2) then
  315. secname:='.data';
  316. { section type user gives the user full controll on the section name }
  317. if atype=sec_user then
  318. secname:=aname;
  319. if is_smart_section(atype) and (aname<>'') then
  320. begin
  321. case aorder of
  322. secorder_begin :
  323. sep:='.b_';
  324. secorder_end :
  325. sep:='.z_';
  326. else
  327. sep:='.n_';
  328. end;
  329. result:=secname+sep+aname
  330. end
  331. else
  332. result:=secname;
  333. end;
  334. function TGNUAssembler.sectionattrs_coff(atype:TAsmSectiontype):string;
  335. begin
  336. case atype of
  337. sec_code, sec_init, sec_fini, sec_stub:
  338. result:='x';
  339. { TODO: must be individual for each section }
  340. sec_user:
  341. result:='d';
  342. sec_data, sec_data_lazy, sec_data_nonlazy, sec_fpc,
  343. sec_idata2, sec_idata4, sec_idata5, sec_idata6, sec_idata7:
  344. result:='d';
  345. { TODO: these need a fix to become read-only }
  346. sec_rodata, sec_rodata_norel:
  347. result:='d';
  348. sec_bss:
  349. result:='b';
  350. { TODO: Somewhat questionable. FPC does not allow initialized threadvars,
  351. so no sense to mark it as containing data. But Windows allows it to
  352. contain data, and Linux even has .tdata and .tbss }
  353. sec_threadvar:
  354. result:='b';
  355. sec_pdata, sec_edata, sec_eh_frame, sec_toc:
  356. result:='r';
  357. sec_stab,sec_stabstr,
  358. sec_debug_frame,sec_debug_info,sec_debug_line,sec_debug_abbrev:
  359. result:='n';
  360. else
  361. result:=''; { defaults to data+load }
  362. end;
  363. end;
  364. function TGNUAssembler.sectionalignment_aix(atype:TAsmSectiontype;secalign: byte): string;
  365. var
  366. l: longint;
  367. begin
  368. if (secalign=0) or
  369. not(atype in [sec_code,sec_bss,sec_rodata_norel,sec_rodata,sec_data]) then
  370. begin
  371. result:='';
  372. exit;
  373. end;
  374. if not ispowerof2(secalign,l) then
  375. internalerror(2012022201);
  376. result:=tostr(l);
  377. end;
  378. procedure TGNUAssembler.WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder;secalign:byte);
  379. var
  380. s : string;
  381. begin
  382. writer.AsmLn;
  383. case target_info.system of
  384. system_i386_OS2,
  385. system_i386_EMX,
  386. system_m68k_amiga: ; { amiga has old GNU AS (2.14), which blews up from .section (KB) }
  387. system_powerpc_darwin,
  388. system_i386_darwin,
  389. system_i386_iphonesim,
  390. system_powerpc64_darwin,
  391. system_x86_64_darwin,
  392. system_arm_darwin,
  393. system_aarch64_darwin,
  394. system_x86_64_iphonesim,
  395. system_powerpc_aix,
  396. system_powerpc64_aix:
  397. begin
  398. if (atype in [sec_stub,sec_objc_data,sec_objc_const,sec_data_coalesced]) then
  399. writer.AsmWrite('.section ');
  400. end
  401. else
  402. writer.AsmWrite('.section ');
  403. end;
  404. s:=sectionname(atype,aname,aorder);
  405. writer.AsmWrite(s);
  406. case atype of
  407. sec_fpc :
  408. if aname = 'resptrs' then
  409. writer.AsmWrite(', "a", @progbits');
  410. sec_stub :
  411. begin
  412. case target_info.system of
  413. { there are processor-independent shortcuts available }
  414. { for this, namely .symbol_stub and .picsymbol_stub, but }
  415. { they don't work and gcc doesn't use them either... }
  416. system_powerpc_darwin,
  417. system_powerpc64_darwin:
  418. if (cs_create_pic in current_settings.moduleswitches) then
  419. writer.AsmWriteln('__TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32')
  420. else
  421. writer.AsmWriteln('__TEXT,__symbol_stub1,symbol_stubs,pure_instructions,16');
  422. system_i386_darwin,
  423. system_i386_iphonesim:
  424. writer.AsmWriteln('__IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5');
  425. system_arm_darwin:
  426. if (cs_create_pic in current_settings.moduleswitches) then
  427. writer.AsmWriteln('__TEXT,__picsymbolstub4,symbol_stubs,none,16')
  428. else
  429. writer.AsmWriteln('__TEXT,__symbol_stub4,symbol_stubs,none,12')
  430. { darwin/(x86-64/AArch64) uses PC-based GOT addressing, no
  431. explicit symbol stubs }
  432. else
  433. internalerror(2006031101);
  434. end;
  435. end;
  436. else
  437. { GNU AS won't recognize '.text.n_something' section name as belonging
  438. to '.text' and assigns default attributes to it, which is not
  439. always correct. We have to fix it.
  440. TODO: This likely applies to all systems which smartlink without
  441. creating libraries }
  442. if (target_info.system in [system_i386_win32,system_x86_64_win64]) and
  443. is_smart_section(atype) and (aname<>'') then
  444. begin
  445. s:=sectionattrs_coff(atype);
  446. if (s<>'') then
  447. writer.AsmWrite(',"'+s+'"');
  448. end
  449. else if target_info.system in systems_aix then
  450. begin
  451. s:=sectionalignment_aix(atype,secalign);
  452. if s<>'' then
  453. writer.AsmWrite(','+s);
  454. end;
  455. end;
  456. writer.AsmLn;
  457. LastSecType:=atype;
  458. end;
  459. procedure TGNUAssembler.WriteDecodedUleb128(a: qword);
  460. var
  461. i,len : longint;
  462. buf : array[0..63] of byte;
  463. begin
  464. len:=EncodeUleb128(a,buf);
  465. for i:=0 to len-1 do
  466. begin
  467. if (i > 0) then
  468. writer.AsmWrite(',');
  469. writer.AsmWrite(tostr(buf[i]));
  470. end;
  471. end;
  472. procedure TGNUAssembler.WriteDecodedSleb128(a: int64);
  473. var
  474. i,len : longint;
  475. buf : array[0..255] of byte;
  476. begin
  477. len:=EncodeSleb128(a,buf);
  478. for i:=0 to len-1 do
  479. begin
  480. if (i > 0) then
  481. writer.AsmWrite(',');
  482. writer.AsmWrite(tostr(buf[i]));
  483. end;
  484. end;
  485. procedure TGNUAssembler.WriteTree(p:TAsmList);
  486. function needsObject(hp : tai_symbol) : boolean;
  487. begin
  488. needsObject :=
  489. (
  490. assigned(hp.next) and
  491. (tai(hp.next).typ in [ait_const,ait_datablock,ait_realconst])
  492. ) or
  493. (hp.sym.typ=AT_DATA);
  494. end;
  495. procedure doalign(alignment: byte; use_op: boolean; fillop: byte; out last_align: longint;lasthp:tai);
  496. var
  497. i: longint;
  498. {$ifdef m68k}
  499. instr : string;
  500. {$endif}
  501. begin
  502. last_align:=alignment;
  503. if alignment>1 then
  504. begin
  505. if not(target_info.system in (systems_darwin+systems_aix)) then
  506. begin
  507. {$ifdef m68k}
  508. if not use_op and (lastsectype=sec_code) then
  509. begin
  510. if not ispowerof2(alignment,i) then
  511. internalerror(2014022201);
  512. { the Coldfire manual suggests the TBF instruction for
  513. alignments, but somehow QEMU does not interpret that
  514. correctly... }
  515. {if current_settings.cputype in cpu_coldfire then
  516. instr:='0x51fc'
  517. else}
  518. instr:='0x4e71';
  519. writer.AsmWrite(#9'.balignw '+tostr(alignment)+','+instr);
  520. end
  521. else
  522. begin
  523. {$endif m68k}
  524. writer.AsmWrite(#9'.balign '+tostr(alignment));
  525. if use_op then
  526. writer.AsmWrite(','+tostr(fillop))
  527. {$ifdef x86}
  528. { force NOP as alignment op code }
  529. else if LastSecType=sec_code then
  530. writer.AsmWrite(',0x90');
  531. {$endif x86}
  532. {$ifdef m68k}
  533. end;
  534. {$endif m68k}
  535. end
  536. else
  537. begin
  538. { darwin and aix as only support .align }
  539. if not ispowerof2(alignment,i) then
  540. internalerror(2003010305);
  541. writer.AsmWrite(#9'.align '+tostr(i));
  542. last_align:=i;
  543. end;
  544. writer.AsmLn;
  545. end;
  546. end;
  547. var
  548. ch : char;
  549. lasthp,
  550. hp : tai;
  551. constdef : taiconst_type;
  552. s,t : string;
  553. i,pos,l : longint;
  554. InlineLevel : cardinal;
  555. last_align : longint;
  556. {$ifdef cpuextended}
  557. e : extended;
  558. {$endif cpuextended}
  559. do_line : boolean;
  560. sepChar : char;
  561. replaceforbidden: boolean;
  562. begin
  563. if not assigned(p) then
  564. exit;
  565. replaceforbidden:=asminfo^.dollarsign<>'$';
  566. last_align := 2;
  567. InlineLevel:=0;
  568. { lineinfo is only needed for al_procedures (PFV) }
  569. do_line:=(cs_asm_source in current_settings.globalswitches) or
  570. ((cs_lineinfo in current_settings.moduleswitches)
  571. and (p=current_asmdata.asmlists[al_procedures]));
  572. lasthp:=nil;
  573. hp:=tai(p.first);
  574. while assigned(hp) do
  575. begin
  576. prefetch(pointer(hp.next)^);
  577. if not(hp.typ in SkipLineInfo) then
  578. begin
  579. current_filepos:=tailineinfo(hp).fileinfo;
  580. { no line info for inlined code }
  581. if do_line and (inlinelevel=0) then
  582. WriteSourceLine(hp as tailineinfo);
  583. end;
  584. case hp.typ of
  585. ait_comment :
  586. Begin
  587. writer.AsmWrite(asminfo^.comment);
  588. writer.AsmWritePChar(tai_comment(hp).str);
  589. writer.AsmLn;
  590. End;
  591. ait_regalloc :
  592. begin
  593. if (cs_asm_regalloc in current_settings.globalswitches) then
  594. begin
  595. writer.AsmWrite(#9+asminfo^.comment+'Register ');
  596. repeat
  597. writer.AsmWrite(std_regname(Tai_regalloc(hp).reg));
  598. if (hp.next=nil) or
  599. (tai(hp.next).typ<>ait_regalloc) or
  600. (tai_regalloc(hp.next).ratype<>tai_regalloc(hp).ratype) then
  601. break;
  602. hp:=tai(hp.next);
  603. writer.AsmWrite(',');
  604. until false;
  605. writer.AsmWrite(' ');
  606. writer.AsmWriteLn(regallocstr[tai_regalloc(hp).ratype]);
  607. end;
  608. end;
  609. ait_tempalloc :
  610. begin
  611. if (cs_asm_tempalloc in current_settings.globalswitches) then
  612. WriteTempalloc(tai_tempalloc(hp));
  613. end;
  614. ait_align :
  615. begin
  616. doalign(tai_align_abstract(hp).aligntype,tai_align_abstract(hp).use_op,tai_align_abstract(hp).fillop,last_align,lasthp);
  617. end;
  618. ait_section :
  619. begin
  620. if tai_section(hp).sectype<>sec_none then
  621. if replaceforbidden then
  622. WriteSection(tai_section(hp).sectype,ReplaceForbiddenAsmSymbolChars(tai_section(hp).name^),tai_section(hp).secorder,tai_section(hp).secalign)
  623. else
  624. WriteSection(tai_section(hp).sectype,tai_section(hp).name^,tai_section(hp).secorder,tai_section(hp).secalign)
  625. else
  626. begin
  627. {$ifdef EXTDEBUG}
  628. writer.AsmWrite(asminfo^.comment);
  629. writer.AsmWriteln(' sec_none');
  630. {$endif EXTDEBUG}
  631. end;
  632. end;
  633. ait_datablock :
  634. begin
  635. if (target_info.system in systems_darwin) then
  636. begin
  637. { On Mac OS X you can't have common symbols in a shared library
  638. since those are in the TEXT section and the text section is
  639. read-only in shared libraries (so it can be shared among different
  640. processes). The alternate code creates some kind of common symbols
  641. in the data segment.
  642. }
  643. if tai_datablock(hp).is_global then
  644. begin
  645. writer.AsmWrite('.globl ');
  646. writer.AsmWriteln(tai_datablock(hp).sym.name);
  647. writer.AsmWriteln('.data');
  648. writer.AsmWrite('.zerofill __DATA, __common, ');
  649. writer.AsmWrite(tai_datablock(hp).sym.name);
  650. writer.AsmWriteln(', '+tostr(tai_datablock(hp).size)+','+tostr(last_align));
  651. if not(LastSecType in [sec_data,sec_none]) then
  652. writesection(LastSecType,'',secorder_default,1 shl last_align);
  653. end
  654. else
  655. begin
  656. writer.AsmWrite(#9'.lcomm'#9);
  657. writer.AsmWrite(tai_datablock(hp).sym.name);
  658. writer.AsmWrite(','+tostr(tai_datablock(hp).size));
  659. writer.AsmWrite(','+tostr(last_align));
  660. writer.AsmLn;
  661. end;
  662. end
  663. else if target_info.system in systems_aix then
  664. begin
  665. if tai_datablock(hp).is_global then
  666. begin
  667. writer.AsmWrite(#9'.globl ');
  668. writer.AsmWriteln(ReplaceForbiddenAsmSymbolChars(tai_datablock(hp).sym.name));
  669. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_datablock(hp).sym.name));
  670. writer.AsmWriteln(':');
  671. writer.AsmWrite(#9'.space ');
  672. writer.AsmWriteln(tostr(tai_datablock(hp).size));
  673. if not(LastSecType in [sec_data,sec_none]) then
  674. writesection(LastSecType,'',secorder_default,1 shl last_align);
  675. end
  676. else
  677. begin
  678. writer.AsmWrite(#9'.lcomm ');
  679. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_datablock(hp).sym.name));
  680. writer.AsmWrite(',');
  681. writer.AsmWrite(tostr(tai_datablock(hp).size)+',');
  682. writer.AsmWrite('_data.bss_,');
  683. writer.AsmWriteln(tostr(last_align));
  684. end;
  685. end
  686. else
  687. begin
  688. {$ifdef USE_COMM_IN_BSS}
  689. if writingpackages then
  690. begin
  691. { The .comm is required for COMMON symbols. These are used
  692. in the shared library loading. All the symbols declared in
  693. the .so file need to resolve to the data allocated in the main
  694. program (PFV) }
  695. if tai_datablock(hp).is_global then
  696. begin
  697. writer.AsmWrite(#9'.comm'#9);
  698. if replaceforbidden then
  699. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_datablock(hp).sym.name))
  700. else
  701. writer.AsmWrite(tai_datablock(hp).sym.name);
  702. writer.AsmWrite(','+tostr(tai_datablock(hp).size));
  703. writer.AsmWrite(','+tostr(last_align));
  704. writer.AsmLn;
  705. end
  706. else
  707. begin
  708. writer.AsmWrite(#9'.lcomm'#9);
  709. if replaceforbidden then
  710. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_datablock(hp).sym.name));
  711. else
  712. writer.AsmWrite(tai_datablock(hp).sym.name);
  713. writer.AsmWrite(','+tostr(tai_datablock(hp).size));
  714. writer.AsmWrite(','+tostr(last_align));
  715. writer.AsmLn;
  716. end
  717. end
  718. else
  719. {$endif USE_COMM_IN_BSS}
  720. begin
  721. if Tai_datablock(hp).is_global then
  722. begin
  723. writer.AsmWrite(#9'.globl ');
  724. if replaceforbidden then
  725. writer.AsmWriteln(ReplaceForbiddenAsmSymbolChars(Tai_datablock(hp).sym.name))
  726. else
  727. writer.AsmWriteln(Tai_datablock(hp).sym.name);
  728. end;
  729. if ((target_info.system <> system_arm_linux) and (target_info.system <> system_arm_android)) then
  730. sepChar := '@'
  731. else
  732. sepChar := '%';
  733. if replaceforbidden then
  734. begin
  735. if (tf_needs_symbol_type in target_info.flags) then
  736. writer.AsmWriteln(#9'.type '+ReplaceForbiddenAsmSymbolChars(Tai_datablock(hp).sym.name)+','+sepChar+'object');
  737. if (tf_needs_symbol_size in target_info.flags) and (tai_datablock(hp).size > 0) then
  738. writer.AsmWriteln(#9'.size '+ReplaceForbiddenAsmSymbolChars(Tai_datablock(hp).sym.name)+','+tostr(Tai_datablock(hp).size));
  739. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(Tai_datablock(hp).sym.name))
  740. end
  741. else
  742. begin
  743. if (tf_needs_symbol_type in target_info.flags) then
  744. writer.AsmWriteln(#9'.type '+Tai_datablock(hp).sym.name+','+sepChar+'object');
  745. if (tf_needs_symbol_size in target_info.flags) and (tai_datablock(hp).size > 0) then
  746. writer.AsmWriteln(#9'.size '+Tai_datablock(hp).sym.name+','+tostr(Tai_datablock(hp).size));
  747. writer.AsmWrite(Tai_datablock(hp).sym.name);
  748. end;
  749. writer.AsmWriteln(':');
  750. writer.AsmWriteln(#9'.zero '+tostr(Tai_datablock(hp).size));
  751. end;
  752. end;
  753. end;
  754. ait_const:
  755. begin
  756. constdef:=tai_const(hp).consttype;
  757. case constdef of
  758. {$ifndef cpu64bitaddr}
  759. aitconst_128bit :
  760. begin
  761. internalerror(200404291);
  762. end;
  763. aitconst_64bit :
  764. begin
  765. if assigned(tai_const(hp).sym) then
  766. internalerror(200404292);
  767. if not(target_info.system in systems_aix) then
  768. begin
  769. writer.AsmWrite(ait_const2str[aitconst_32bit]);
  770. if target_info.endian = endian_little then
  771. begin
  772. writer.AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  773. writer.AsmWrite(',');
  774. writer.AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  775. end
  776. else
  777. begin
  778. writer.AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  779. writer.AsmWrite(',');
  780. writer.AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  781. end;
  782. end
  783. else
  784. WriteAixIntConst(tai_const(hp));
  785. writer.AsmLn;
  786. end;
  787. {$endif cpu64bitaddr}
  788. aitconst_got:
  789. begin
  790. if tai_const(hp).symofs<>0 then
  791. InternalError(2015091401); // No symbol offset is allowed for GOT.
  792. writer.AsmWrite(#9'.word'#9+tai_const(hp).sym.name+'(GOT)');
  793. writer.AsmLn;
  794. end;
  795. aitconst_gotoff_symbol:
  796. begin
  797. if (tai_const(hp).sym=nil) then
  798. InternalError(2014022601);
  799. case target_info.cpu of
  800. cpu_mipseb,cpu_mipsel:
  801. begin
  802. writer.AsmWrite(#9'.gpword'#9);
  803. writer.AsmWrite(tai_const(hp).sym.name);
  804. end;
  805. cpu_i386:
  806. begin
  807. writer.AsmWrite(ait_const2str[aitconst_32bit]);
  808. writer.AsmWrite(tai_const(hp).sym.name);
  809. end;
  810. else
  811. InternalError(2014022602);
  812. end;
  813. if (tai_const(hp).value<>0) then
  814. writer.AsmWrite(tostr_with_plus(tai_const(hp).value));
  815. writer.AsmLn;
  816. end;
  817. aitconst_uleb128bit,
  818. aitconst_sleb128bit,
  819. {$ifdef cpu64bitaddr}
  820. aitconst_128bit,
  821. aitconst_64bit,
  822. {$endif cpu64bitaddr}
  823. aitconst_32bit,
  824. aitconst_16bit,
  825. aitconst_8bit,
  826. aitconst_rva_symbol,
  827. aitconst_secrel32_symbol,
  828. aitconst_darwin_dwarf_delta32,
  829. aitconst_darwin_dwarf_delta64,
  830. aitconst_half16bit,
  831. aitconst_gs,
  832. aitconst_16bit_unaligned,
  833. aitconst_32bit_unaligned,
  834. aitconst_64bit_unaligned:
  835. begin
  836. { the AIX assembler (and for compatibility, the GNU
  837. assembler when targeting AIX) automatically aligns
  838. .short/.long/.llong to a multiple of 2/4/8 bytes. We
  839. don't want that, since this may be data inside a packed
  840. record -> use .vbyte instead (byte stream of fixed
  841. length) }
  842. if (target_info.system in systems_aix) and
  843. (constdef in [aitconst_128bit,aitconst_64bit,aitconst_32bit,aitconst_16bit]) and
  844. not assigned(tai_const(hp).sym) then
  845. begin
  846. WriteAixIntConst(tai_const(hp));
  847. end
  848. else if (target_info.system in systems_darwin) and
  849. (constdef in [aitconst_uleb128bit,aitconst_sleb128bit]) then
  850. begin
  851. writer.AsmWrite(ait_const2str[aitconst_8bit]);
  852. case tai_const(hp).consttype of
  853. aitconst_uleb128bit:
  854. WriteDecodedUleb128(qword(tai_const(hp).value));
  855. aitconst_sleb128bit:
  856. WriteDecodedSleb128(int64(tai_const(hp).value));
  857. end
  858. end
  859. else
  860. begin
  861. if (constdef in ait_unaligned_consts) and
  862. (target_info.system in use_ua_sparc_systems) then
  863. writer.AsmWrite(ait_ua_sparc_const2str[constdef])
  864. else if (constdef in ait_unaligned_consts) and
  865. (target_info.system in use_ua_elf_systems) then
  866. writer.AsmWrite(ait_ua_elf_const2str[constdef])
  867. { we can also have unaligned pointers in packed record
  868. constants, which don't get translated into
  869. unaligned tai -> always use vbyte }
  870. else if target_info.system in systems_aix then
  871. writer.AsmWrite(#9'.vbyte'#9+tostr(tai_const(hp).size)+',')
  872. else
  873. writer.AsmWrite(ait_const2str[constdef]);
  874. l:=0;
  875. t := '';
  876. repeat
  877. if assigned(tai_const(hp).sym) then
  878. begin
  879. if assigned(tai_const(hp).endsym) then
  880. begin
  881. if (constdef in [aitconst_darwin_dwarf_delta32,aitconst_darwin_dwarf_delta64]) then
  882. begin
  883. s := NextSetLabel;
  884. t := #9'.set '+s+','+tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name;
  885. end
  886. else
  887. s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
  888. end
  889. else
  890. s:=tai_const(hp).sym.name;
  891. if replaceforbidden then
  892. s:=ReplaceForbiddenAsmSymbolChars(s);
  893. if tai_const(hp).value<>0 then
  894. s:=s+tostr_with_plus(tai_const(hp).value);
  895. end
  896. else
  897. {$ifdef cpu64bitaddr}
  898. s:=tostr(tai_const(hp).value);
  899. {$else cpu64bitaddr}
  900. { 64 bit constants are already handled above in this case }
  901. s:=tostr(longint(tai_const(hp).value));
  902. {$endif cpu64bitaddr}
  903. if constdef = aitconst_half16bit then
  904. s:='('+s+')/2';
  905. if constdef = aitconst_gs then
  906. s:='gs('+s+')';
  907. writer.AsmWrite(s);
  908. inc(l,length(s));
  909. { Values with symbols are written on a single line to improve
  910. reading of the .s file (PFV) }
  911. if assigned(tai_const(hp).sym) or
  912. not(LastSecType in [sec_data,sec_rodata,sec_rodata_norel]) or
  913. (l>line_length) or
  914. (hp.next=nil) or
  915. (tai(hp.next).typ<>ait_const) or
  916. (tai_const(hp.next).consttype<>constdef) or
  917. assigned(tai_const(hp.next).sym) then
  918. break;
  919. hp:=tai(hp.next);
  920. writer.AsmWrite(',');
  921. until false;
  922. if (t <> '') then
  923. begin
  924. writer.AsmLn;
  925. writer.AsmWrite(t);
  926. end;
  927. end;
  928. writer.AsmLn;
  929. end;
  930. else
  931. internalerror(200704251);
  932. end;
  933. end;
  934. ait_realconst :
  935. begin
  936. WriteRealConstAsBytes(tai_realconst(hp),#9'.byte'#9,do_line);
  937. end;
  938. ait_string :
  939. begin
  940. pos:=0;
  941. if not(target_info.system in systems_aix) then
  942. begin
  943. for i:=1 to tai_string(hp).len do
  944. begin
  945. if pos=0 then
  946. begin
  947. writer.AsmWrite(#9'.ascii'#9'"');
  948. pos:=20;
  949. end;
  950. ch:=tai_string(hp).str[i-1];
  951. case ch of
  952. #0, {This can't be done by range, because a bug in FPC}
  953. #1..#31,
  954. #128..#255 : s:='\'+tostr(ord(ch) shr 6)+tostr((ord(ch) and 63) shr 3)+tostr(ord(ch) and 7);
  955. '"' : s:='\"';
  956. '\' : s:='\\';
  957. else
  958. s:=ch;
  959. end;
  960. writer.AsmWrite(s);
  961. inc(pos,length(s));
  962. if (pos>line_length) or (i=tai_string(hp).len) then
  963. begin
  964. writer.AsmWriteLn('"');
  965. pos:=0;
  966. end;
  967. end;
  968. end
  969. else
  970. WriteAixStringConst(tai_string(hp));
  971. end;
  972. ait_label :
  973. begin
  974. if (tai_label(hp).labsym.is_used) then
  975. begin
  976. if (tai_label(hp).labsym.bind=AB_PRIVATE_EXTERN) then
  977. begin
  978. writer.AsmWrite(#9'.private_extern ');
  979. writer.AsmWriteln(tai_label(hp).labsym.name);
  980. end;
  981. if tai_label(hp).labsym.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN] then
  982. begin
  983. {$ifdef arm}
  984. { do no change arm mode accidently, .globl seems to reset the mode }
  985. if GenerateThumbCode or GenerateThumb2Code then
  986. writer.AsmWriteln(#9'.thumb_func'#9);
  987. {$endif arm}
  988. writer.AsmWrite('.globl'#9);
  989. if replaceforbidden then
  990. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_label(hp).labsym.name))
  991. else
  992. writer.AsmWriteLn(tai_label(hp).labsym.name);
  993. end;
  994. if replaceforbidden then
  995. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_label(hp).labsym.name))
  996. else
  997. writer.AsmWrite(tai_label(hp).labsym.name);
  998. writer.AsmWriteLn(':');
  999. end;
  1000. end;
  1001. ait_symbol :
  1002. begin
  1003. if (tai_symbol(hp).sym.bind=AB_PRIVATE_EXTERN) then
  1004. begin
  1005. writer.AsmWrite(#9'.private_extern ');
  1006. if replaceforbidden then
  1007. writer.AsmWriteln(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name))
  1008. else
  1009. writer.AsmWriteln(tai_symbol(hp).sym.name);
  1010. end;
  1011. if (target_info.system=system_powerpc64_linux) and
  1012. (tai_symbol(hp).sym.typ=AT_FUNCTION) and
  1013. (cs_profile in current_settings.moduleswitches) then
  1014. writer.AsmWriteLn('.globl _mcount');
  1015. if tai_symbol(hp).is_global then
  1016. begin
  1017. writer.AsmWrite('.globl'#9);
  1018. if replaceforbidden then
  1019. writer.AsmWriteln(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name))
  1020. else
  1021. writer.AsmWriteln(tai_symbol(hp).sym.name);
  1022. end;
  1023. if (target_info.system=system_powerpc64_linux) and
  1024. use_dotted_functions and
  1025. (tai_symbol(hp).sym.typ=AT_FUNCTION) then
  1026. begin
  1027. writer.AsmWriteLn('.section ".opd", "aw"');
  1028. writer.AsmWriteLn('.align 3');
  1029. writer.AsmWriteLn(tai_symbol(hp).sym.name + ':');
  1030. writer.AsmWriteLn('.quad .' + tai_symbol(hp).sym.name + ', .TOC.@tocbase, 0');
  1031. writer.AsmWriteLn('.previous');
  1032. writer.AsmWriteLn('.size ' + tai_symbol(hp).sym.name + ', 24');
  1033. if (tai_symbol(hp).is_global) then
  1034. writer.AsmWriteLn('.globl .' + tai_symbol(hp).sym.name);
  1035. writer.AsmWriteLn('.type .' + tai_symbol(hp).sym.name + ', @function');
  1036. { the dotted name is the name of the actual function entry }
  1037. writer.AsmWrite('.');
  1038. end
  1039. else if (target_info.system in systems_aix) and
  1040. (tai_symbol(hp).sym.typ = AT_FUNCTION) then
  1041. begin
  1042. if target_info.system=system_powerpc_aix then
  1043. begin
  1044. s:=#9'.long .';
  1045. ch:='2';
  1046. end
  1047. else
  1048. begin
  1049. s:=#9'.llong .';
  1050. ch:='3';
  1051. end;
  1052. writer.AsmWriteLn(#9'.csect '+ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name)+'[DS],'+ch);
  1053. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name)+':');
  1054. writer.AsmWriteln(s+ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name)+', TOC[tc0], 0');
  1055. writer.AsmWriteln(#9'.csect .text[PR]');
  1056. if (tai_symbol(hp).is_global) then
  1057. writer.AsmWriteLn('.globl .'+ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name))
  1058. else
  1059. writer.AsmWriteLn('.lglobl .'+ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name));
  1060. { the dotted name is the name of the actual function entry }
  1061. writer.AsmWrite('.');
  1062. end
  1063. else
  1064. begin
  1065. if ((target_info.system <> system_arm_linux) and (target_info.system <> system_arm_android)) then
  1066. sepChar := '@'
  1067. else
  1068. sepChar := '#';
  1069. if (tf_needs_symbol_type in target_info.flags) then
  1070. begin
  1071. writer.AsmWrite(#9'.type'#9 + tai_symbol(hp).sym.name);
  1072. if (needsObject(tai_symbol(hp))) then
  1073. writer.AsmWriteLn(',' + sepChar + 'object')
  1074. else
  1075. writer.AsmWriteLn(',' + sepChar + 'function');
  1076. end;
  1077. end;
  1078. if replaceforbidden then
  1079. if not(tai_symbol(hp).has_value) then
  1080. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name + ':'))
  1081. else
  1082. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name + '=' + tostr(tai_symbol(hp).value)))
  1083. else if not(tai_symbol(hp).has_value) then
  1084. writer.AsmWriteLn(tai_symbol(hp).sym.name + ':')
  1085. else
  1086. writer.AsmWriteLn(tai_symbol(hp).sym.name + '=' + tostr(tai_symbol(hp).value));
  1087. end;
  1088. ait_symbolpair:
  1089. begin
  1090. writer.AsmWrite(#9);
  1091. writer.AsmWrite(symbolpairkindstr[tai_symbolpair(hp).kind]);
  1092. writer.AsmWrite(' ');
  1093. if tai_symbolpair(hp).kind<>spk_localentry then
  1094. s:=', '
  1095. else
  1096. { the .localentry directive has to specify the size from the
  1097. start till here of the non-local entry code as second argument }
  1098. s:=', .-';
  1099. if replaceforbidden then
  1100. begin
  1101. { avoid string truncation }
  1102. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_symbolpair(hp).sym^)+s);
  1103. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_symbolpair(hp).value^));
  1104. end
  1105. else
  1106. begin
  1107. { avoid string truncation }
  1108. writer.AsmWrite(tai_symbolpair(hp).sym^+s);
  1109. writer.AsmWriteLn(tai_symbolpair(hp).value^);
  1110. end;
  1111. end;
  1112. ait_weak:
  1113. begin
  1114. if replaceforbidden then
  1115. writer.AsmWriteLn(#9'.weak '+ReplaceForbiddenAsmSymbolChars(tai_weak(hp).sym^))
  1116. else
  1117. writer.AsmWriteLn(#9'.weak '+tai_weak(hp).sym^);
  1118. end;
  1119. ait_symbol_end :
  1120. begin
  1121. if tf_needs_symbol_size in target_info.flags then
  1122. begin
  1123. s:=asminfo^.labelprefix+'e'+tostr(symendcount);
  1124. inc(symendcount);
  1125. writer.AsmWriteLn(s+':');
  1126. writer.AsmWrite(#9'.size'#9);
  1127. if (target_info.system=system_powerpc64_linux) and
  1128. use_dotted_functions and
  1129. (tai_symbol_end(hp).sym.typ=AT_FUNCTION) then
  1130. writer.AsmWrite('.');
  1131. if replaceforbidden then
  1132. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_symbol_end(hp).sym.name))
  1133. else
  1134. writer.AsmWrite(tai_symbol_end(hp).sym.name);
  1135. writer.AsmWrite(', '+s+' - ');
  1136. if (target_info.system=system_powerpc64_linux) and
  1137. use_dotted_functions and
  1138. (tai_symbol_end(hp).sym.typ=AT_FUNCTION) then
  1139. writer.AsmWrite('.');
  1140. if replaceforbidden then
  1141. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_symbol_end(hp).sym.name))
  1142. else
  1143. writer.AsmWriteLn(tai_symbol_end(hp).sym.name);
  1144. end;
  1145. end;
  1146. ait_instruction :
  1147. begin
  1148. WriteInstruction(hp);
  1149. end;
  1150. ait_stab :
  1151. begin
  1152. if assigned(tai_stab(hp).str) then
  1153. begin
  1154. writer.AsmWrite(#9'.'+stabtypestr[tai_stab(hp).stabtype]+' ');
  1155. writer.AsmWritePChar(tai_stab(hp).str);
  1156. writer.AsmLn;
  1157. end;
  1158. end;
  1159. ait_force_line,
  1160. ait_function_name :
  1161. begin
  1162. {$ifdef DEBUG_AGGAS}
  1163. WriteStr(s,hp.typ);
  1164. writer.AsmWriteLn('# '+s);
  1165. {$endif DEBUG_AGGAS}
  1166. end;
  1167. ait_cutobject :
  1168. begin
  1169. {$ifdef DEBUG_AGGAS}
  1170. writer.AsmWriteLn('# ait_cutobject');
  1171. {$endif DEBUG_AGGAS}
  1172. if SmartAsm then
  1173. begin
  1174. { only reset buffer if nothing has changed }
  1175. if not(writer.ClearIfEmpty) then
  1176. begin
  1177. writer.AsmClose;
  1178. DoAssemble;
  1179. writer.AsmCreate(tai_cutobject(hp).place);
  1180. end;
  1181. { avoid empty files }
  1182. while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
  1183. begin
  1184. if tai(hp.next).typ=ait_section then
  1185. LastSecType:=tai_section(hp.next).sectype;
  1186. hp:=tai(hp.next);
  1187. end;
  1188. if LastSecType<>sec_none then
  1189. WriteSection(LastSecType,'',secorder_default,last_align);
  1190. writer.MarkEmpty;
  1191. end;
  1192. end;
  1193. ait_marker :
  1194. begin
  1195. {$ifdef DEBUG_AGGAS}
  1196. WriteStr(s,tai_marker(hp).Kind);
  1197. writer.AsmWriteLn('# ait_marker, kind: '+s);
  1198. {$endif DEBUG_AGGAS}
  1199. if tai_marker(hp).kind=mark_NoLineInfoStart then
  1200. inc(InlineLevel)
  1201. else if tai_marker(hp).kind=mark_NoLineInfoEnd then
  1202. dec(InlineLevel);
  1203. end;
  1204. ait_directive :
  1205. begin
  1206. WriteDirectiveName(tai_directive(hp).directive);
  1207. if tai_directive(hp).name <>'' then
  1208. begin
  1209. if replaceforbidden then
  1210. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_directive(hp).name))
  1211. else
  1212. writer.AsmWrite(tai_directive(hp).name);
  1213. end;
  1214. writer.AsmLn;
  1215. end;
  1216. ait_seh_directive :
  1217. begin
  1218. {$ifndef DISABLE_WIN64_SEH}
  1219. writer.AsmWrite(sehdirectivestr[tai_seh_directive(hp).kind]);
  1220. case tai_seh_directive(hp).datatype of
  1221. sd_none:;
  1222. sd_string:
  1223. begin
  1224. writer.AsmWrite(' '+tai_seh_directive(hp).data.name^);
  1225. if (tai_seh_directive(hp).data.flags and 1)<>0 then
  1226. writer.AsmWrite(',@except');
  1227. if (tai_seh_directive(hp).data.flags and 2)<>0 then
  1228. writer.AsmWrite(',@unwind');
  1229. end;
  1230. sd_reg:
  1231. writer.AsmWrite(' '+gas_regname(tai_seh_directive(hp).data.reg));
  1232. sd_offset:
  1233. writer.AsmWrite(' '+tostr(tai_seh_directive(hp).data.offset));
  1234. sd_regoffset:
  1235. writer.AsmWrite(' '+gas_regname(tai_seh_directive(hp).data.reg)+', '+
  1236. tostr(tai_seh_directive(hp).data.offset));
  1237. end;
  1238. writer.AsmLn;
  1239. {$endif DISABLE_WIN64_SEH}
  1240. end;
  1241. ait_varloc:
  1242. begin
  1243. if tai_varloc(hp).newlocationhi<>NR_NO then
  1244. writer.AsmWrite(strpnew('Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1245. std_regname(tai_varloc(hp).newlocationhi)+':'+std_regname(tai_varloc(hp).newlocation)))
  1246. else
  1247. writer.AsmWrite(strpnew('Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1248. std_regname(tai_varloc(hp).newlocation)));
  1249. writer.AsmLn;
  1250. end;
  1251. else
  1252. internalerror(2006012201);
  1253. end;
  1254. lasthp:=hp;
  1255. hp:=tai(hp.next);
  1256. end;
  1257. end;
  1258. procedure TGNUAssembler.WriteExtraHeader;
  1259. begin
  1260. end;
  1261. procedure TGNUAssembler.WriteExtraFooter;
  1262. begin
  1263. end;
  1264. procedure TGNUAssembler.WriteInstruction(hp: tai);
  1265. begin
  1266. InstrWriter.WriteInstruction(hp);
  1267. end;
  1268. procedure TGNUAssembler.WriteWeakSymbolDef(s: tasmsymbol);
  1269. begin
  1270. writer.AsmWriteLn(#9'.weak '+s.name);
  1271. end;
  1272. procedure TGNUAssembler.WriteAixStringConst(hp: tai_string);
  1273. type
  1274. tterminationkind = (term_none,term_string,term_nostring);
  1275. var
  1276. i: longint;
  1277. pos: longint;
  1278. s: string;
  1279. ch: char;
  1280. instring: boolean;
  1281. procedure newstatement(terminationkind: tterminationkind);
  1282. begin
  1283. case terminationkind of
  1284. term_none: ;
  1285. term_string:
  1286. writer.AsmWriteLn('"');
  1287. term_nostring:
  1288. writer.AsmLn;
  1289. end;
  1290. writer.AsmWrite(#9'.byte'#9);
  1291. pos:=20;
  1292. instring:=false;
  1293. end;
  1294. begin
  1295. pos:=0;
  1296. instring:=false;
  1297. for i:=1 to hp.len do
  1298. begin
  1299. if pos=0 then
  1300. newstatement(term_none);
  1301. ch:=hp.str[i-1];
  1302. case ch of
  1303. #0..#31,
  1304. #127..#255 :
  1305. begin
  1306. if instring then
  1307. newstatement(term_string);
  1308. if pos=20 then
  1309. s:=tostr(ord(ch))
  1310. else
  1311. s:=', '+tostr(ord(ch))
  1312. end;
  1313. '"' :
  1314. if instring then
  1315. s:='""'
  1316. else
  1317. begin
  1318. if pos<>20 then
  1319. newstatement(term_nostring);
  1320. s:='"""';
  1321. instring:=true;
  1322. end;
  1323. else
  1324. if not instring then
  1325. begin
  1326. if (pos<>20) then
  1327. newstatement(term_nostring);
  1328. s:='"'+ch;
  1329. instring:=true;
  1330. end
  1331. else
  1332. s:=ch;
  1333. end;
  1334. writer.AsmWrite(s);
  1335. inc(pos,length(s));
  1336. if (pos>line_length) or (i=tai_string(hp).len) then
  1337. begin
  1338. if instring then
  1339. writer.AsmWriteLn('"')
  1340. else
  1341. writer.AsmLn;
  1342. pos:=0;
  1343. end;
  1344. end;
  1345. end;
  1346. procedure TGNUAssembler.WriteAixIntConst(hp: tai_const);
  1347. var
  1348. pos, size: longint;
  1349. begin
  1350. { only big endian AIX supported for now }
  1351. if target_info.endian<>endian_big then
  1352. internalerror(2012010401);
  1353. { limitation: can only write 4 bytes at a time }
  1354. pos:=0;
  1355. size:=tai_const(hp).size;
  1356. while pos<(size-4) do
  1357. begin
  1358. writer.AsmWrite(#9'.vbyte'#9'4, ');
  1359. writer.AsmWriteln(tostr(longint(tai_const(hp).value shr ((size-pos-4)*8))));
  1360. inc(pos,4);
  1361. end;
  1362. writer.AsmWrite(#9'.vbyte'#9);
  1363. writer.AsmWrite(tostr(size-pos));
  1364. writer.AsmWrite(', ');
  1365. case size-pos of
  1366. 1: writer.AsmWrite(tostr(byte(tai_const(hp).value)));
  1367. 2: writer.AsmWrite(tostr(word(tai_const(hp).value)));
  1368. 4: writer.AsmWrite(tostr(longint(tai_const(hp).value)));
  1369. else
  1370. internalerror(2012010402);
  1371. end;
  1372. end;
  1373. procedure TGNUAssembler.WriteUnalignedIntConst(hp: tai_const);
  1374. var
  1375. pos, size: longint;
  1376. begin
  1377. size:=tai_const(hp).size;
  1378. writer.AsmWrite(#9'.byte'#9);
  1379. if target_info.endian=endian_big then
  1380. begin
  1381. pos:=size-1;
  1382. while pos>=0 do
  1383. begin
  1384. writer.AsmWrite(tostr((tai_const(hp).value shr (pos*8)) and $ff));
  1385. dec(pos);
  1386. if pos>=0 then
  1387. writer.AsmWrite(', ')
  1388. else
  1389. writer.AsmLn;
  1390. end;
  1391. end
  1392. else
  1393. begin
  1394. pos:=0;
  1395. while pos<size do
  1396. begin
  1397. writer.AsmWriteln(tostr((tai_const(hp).value shr (pos*8)) and $ff));
  1398. inc(pos);
  1399. if pos<=size then
  1400. writer.AsmWrite(', ')
  1401. else
  1402. writer.AsmLn;
  1403. end;
  1404. end;
  1405. writer.AsmLn;
  1406. end;
  1407. procedure TGNUAssembler.WriteDirectiveName(dir: TAsmDirective);
  1408. begin
  1409. writer.AsmWrite('.'+directivestr[dir]+' ');
  1410. end;
  1411. procedure TGNUAssembler.WriteAsmList;
  1412. var
  1413. n : string;
  1414. hal : tasmlisttype;
  1415. i: longint;
  1416. begin
  1417. {$ifdef EXTDEBUG}
  1418. if current_module.mainsource<>'' then
  1419. Comment(V_Debug,'Start writing gas-styled assembler output for '+current_module.mainsource);
  1420. {$endif}
  1421. if current_module.mainsource<>'' then
  1422. n:=ExtractFileName(current_module.mainsource)
  1423. else
  1424. n:=InputFileName;
  1425. { gcc does not add it either for Darwin. Grep for
  1426. TARGET_ASM_FILE_START_FILE_DIRECTIVE in gcc/config/*.h
  1427. }
  1428. if not(target_info.system in systems_darwin) then
  1429. writer.AsmWriteLn(#9'.file "'+FixFileName(n)+'"');
  1430. WriteExtraHeader;
  1431. writer.MarkEmpty;
  1432. symendcount:=0;
  1433. for hal:=low(TasmlistType) to high(TasmlistType) do
  1434. begin
  1435. if not (current_asmdata.asmlists[hal].empty) then
  1436. begin
  1437. writer.AsmWriteLn(asminfo^.comment+'Begin asmlist '+AsmlistTypeStr[hal]);
  1438. writetree(current_asmdata.asmlists[hal]);
  1439. writer.AsmWriteLn(asminfo^.comment+'End asmlist '+AsmlistTypeStr[hal]);
  1440. end;
  1441. end;
  1442. { add weak symbol markers }
  1443. for i:=0 to current_asmdata.asmsymboldict.count-1 do
  1444. if (tasmsymbol(current_asmdata.asmsymboldict[i]).bind=AB_WEAK_EXTERNAL) then
  1445. writeweaksymboldef(tasmsymbol(current_asmdata.asmsymboldict[i]));
  1446. if create_smartlink_sections and
  1447. (target_info.system in systems_darwin) then
  1448. writer.AsmWriteLn(#9'.subsections_via_symbols');
  1449. { "no executable stack" marker }
  1450. { TODO: used by OpenBSD/NetBSD as well? }
  1451. if (target_info.system in (systems_linux + systems_android + systems_freebsd + systems_dragonfly)) and
  1452. not(cs_executable_stack in current_settings.moduleswitches) then
  1453. begin
  1454. writer.AsmWriteLn('.section .note.GNU-stack,"",%progbits');
  1455. end;
  1456. writer.AsmLn;
  1457. WriteExtraFooter;
  1458. {$ifdef EXTDEBUG}
  1459. if current_module.mainsource<>'' then
  1460. Comment(V_Debug,'Done writing gas-styled assembler output for '+current_module.mainsource);
  1461. {$endif EXTDEBUG}
  1462. end;
  1463. {****************************************************************************}
  1464. { Apple/GNU Assembler writer }
  1465. {****************************************************************************}
  1466. function TAppleGNUAssembler.sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
  1467. begin
  1468. if (target_info.system in systems_darwin) then
  1469. case atype of
  1470. sec_bss:
  1471. { all bss (lcomm) symbols are automatically put in the right }
  1472. { place by using the lcomm assembler directive }
  1473. atype := sec_none;
  1474. sec_debug_frame,
  1475. sec_eh_frame:
  1476. begin
  1477. result := '.section __DWARF,__debug_info,regular,debug';
  1478. exit;
  1479. end;
  1480. sec_debug_line:
  1481. begin
  1482. result := '.section __DWARF,__debug_line,regular,debug';
  1483. exit;
  1484. end;
  1485. sec_debug_info:
  1486. begin
  1487. result := '.section __DWARF,__debug_info,regular,debug';
  1488. exit;
  1489. end;
  1490. sec_debug_abbrev:
  1491. begin
  1492. result := '.section __DWARF,__debug_abbrev,regular,debug';
  1493. exit;
  1494. end;
  1495. sec_rodata:
  1496. begin
  1497. result := '.const_data';
  1498. exit;
  1499. end;
  1500. sec_rodata_norel:
  1501. begin
  1502. result := '.const';
  1503. exit;
  1504. end;
  1505. sec_fpc:
  1506. begin
  1507. result := '.section __TEXT, .fpc, regular, no_dead_strip';
  1508. exit;
  1509. end;
  1510. sec_code:
  1511. begin
  1512. if (aname='fpc_geteipasebx') or
  1513. (aname='fpc_geteipasecx') then
  1514. begin
  1515. result:='.section __TEXT,__textcoal_nt,coalesced,pure_instructions'#10'.weak_definition '+aname+
  1516. #10'.private_extern '+aname;
  1517. exit;
  1518. end;
  1519. end;
  1520. sec_data_nonlazy:
  1521. begin
  1522. result:='.section __DATA, __nl_symbol_ptr,non_lazy_symbol_pointers';
  1523. exit;
  1524. end;
  1525. sec_data_lazy:
  1526. begin
  1527. result:='.section __DATA, __la_symbol_ptr,lazy_symbol_pointers';
  1528. exit;
  1529. end;
  1530. sec_init_func:
  1531. begin
  1532. result:='.section __DATA, __mod_init_func, mod_init_funcs';
  1533. exit;
  1534. end;
  1535. sec_term_func:
  1536. begin
  1537. result:='.section __DATA, __mod_term_func, mod_term_funcs';
  1538. exit;
  1539. end;
  1540. sec_objc_protocol_ext:
  1541. begin
  1542. result:='.section __OBJC, __protocol_ext, regular, no_dead_strip';
  1543. exit;
  1544. end;
  1545. sec_objc_class_ext:
  1546. begin
  1547. result:='.section __OBJC, __class_ext, regular, no_dead_strip';
  1548. exit;
  1549. end;
  1550. sec_objc_property:
  1551. begin
  1552. result:='.section __OBJC, __property, regular, no_dead_strip';
  1553. exit;
  1554. end;
  1555. sec_objc_image_info:
  1556. begin
  1557. if (target_info.system in systems_objc_nfabi) then
  1558. result:='.section __DATA,__objc_imageinfo,regular,no_dead_strip'
  1559. else
  1560. result:='.section __OBJC, __image_info, regular, no_dead_strip';
  1561. exit;
  1562. end;
  1563. sec_objc_cstring_object:
  1564. begin
  1565. result:='.section __OBJC, __cstring_object, regular, no_dead_strip';
  1566. exit;
  1567. end;
  1568. sec_objc_sel_fixup:
  1569. begin
  1570. result:='.section __OBJC, __sel_fixup, regular, no_dead_strip';
  1571. exit;
  1572. end;
  1573. sec_objc_message_refs:
  1574. begin
  1575. if (target_info.system in systems_objc_nfabi) then
  1576. begin
  1577. result:='.section __DATA, __objc_selrefs, literal_pointers, no_dead_strip';
  1578. exit;
  1579. end;
  1580. end;
  1581. sec_objc_cls_refs:
  1582. begin
  1583. if (target_info.system in systems_objc_nfabi) then
  1584. begin
  1585. result:='.section __DATA, __objc_clsrefs, regular, no_dead_strip';
  1586. exit;
  1587. end;
  1588. end;
  1589. sec_objc_meth_var_types:
  1590. begin
  1591. if (target_info.system in systems_objc_nfabi) then
  1592. begin
  1593. result:='.section __TEXT,__objc_methtype,cstring_literals';
  1594. exit
  1595. end;
  1596. end;
  1597. sec_objc_meth_var_names:
  1598. begin
  1599. if (target_info.system in systems_objc_nfabi) then
  1600. begin
  1601. result:='.section __TEXT,__objc_methname,cstring_literals';
  1602. exit
  1603. end;
  1604. end;
  1605. sec_objc_class_names:
  1606. begin
  1607. if (target_info.system in systems_objc_nfabi) then
  1608. begin
  1609. result:='.section __TEXT,__objc_classname,cstring_literals';
  1610. exit
  1611. end;
  1612. end;
  1613. sec_objc_inst_meth,
  1614. sec_objc_cls_meth,
  1615. sec_objc_cat_inst_meth,
  1616. sec_objc_cat_cls_meth:
  1617. begin
  1618. if (target_info.system in systems_objc_nfabi) then
  1619. begin
  1620. result:='.section __DATA, __objc_const';
  1621. exit;
  1622. end;
  1623. end;
  1624. sec_objc_meta_class,
  1625. sec_objc_class:
  1626. begin
  1627. if (target_info.system in systems_objc_nfabi) then
  1628. begin
  1629. result:='.section __DATA, __objc_data';
  1630. exit;
  1631. end;
  1632. end;
  1633. sec_objc_sup_refs:
  1634. begin
  1635. result:='.section __DATA, __objc_superrefs, regular, no_dead_strip';
  1636. exit
  1637. end;
  1638. sec_objc_classlist:
  1639. begin
  1640. result:='.section __DATA, __objc_classlist, regular, no_dead_strip';
  1641. exit
  1642. end;
  1643. sec_objc_nlclasslist:
  1644. begin
  1645. result:='.section __DATA, __objc_nlclasslist, regular, no_dead_strip';
  1646. exit
  1647. end;
  1648. sec_objc_catlist:
  1649. begin
  1650. result:='.section __DATA, __objc_catlist, regular, no_dead_strip';
  1651. exit
  1652. end;
  1653. sec_objc_nlcatlist:
  1654. begin
  1655. result:='.section __DATA, __objc_nlcatlist, regular, no_dead_strip';
  1656. exit
  1657. end;
  1658. sec_objc_protolist:
  1659. begin
  1660. result:='.section __DATA, __objc_protolist, coalesced, no_dead_strip';
  1661. exit;
  1662. end;
  1663. end;
  1664. result := inherited sectionname(atype,aname,aorder);
  1665. end;
  1666. procedure TAppleGNUAssembler.WriteWeakSymbolDef(s: tasmsymbol);
  1667. begin
  1668. writer.AsmWriteLn(#9'.weak_reference '+s.name);
  1669. end;
  1670. {****************************************************************************}
  1671. { a.out/GNU Assembler writer }
  1672. {****************************************************************************}
  1673. function TAoutGNUAssembler.sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
  1674. const
  1675. (* Translation table - replace unsupported section types with basic ones. *)
  1676. SecXTable: array[TAsmSectionType] of TAsmSectionType = (
  1677. sec_none,
  1678. sec_none,
  1679. sec_code,
  1680. sec_data,
  1681. sec_data (* sec_rodata *),
  1682. sec_data (* sec_rodata_norel *),
  1683. sec_bss,
  1684. sec_data (* sec_threadvar *),
  1685. { used for wince exception handling }
  1686. sec_code (* sec_pdata *),
  1687. { used for darwin import stubs }
  1688. sec_code (* sec_stub *),
  1689. sec_data,(* sec_data_nonlazy *)
  1690. sec_data,(* sec_data_lazy *)
  1691. sec_data,(* sec_init_func *)
  1692. sec_data,(* sec_term_func *)
  1693. { stabs }
  1694. sec_stab,sec_stabstr,
  1695. { win32 }
  1696. sec_data (* sec_idata2 *),
  1697. sec_data (* sec_idata4 *),
  1698. sec_data (* sec_idata5 *),
  1699. sec_data (* sec_idata6 *),
  1700. sec_data (* sec_idata7 *),
  1701. sec_data (* sec_edata *),
  1702. { C++ exception handling unwinding (uses dwarf) }
  1703. sec_eh_frame,
  1704. { dwarf }
  1705. sec_debug_frame,
  1706. sec_debug_info,
  1707. sec_debug_line,
  1708. sec_debug_abbrev,
  1709. { ELF resources (+ references to stabs debug information sections) }
  1710. sec_code (* sec_fpc *),
  1711. { Table of contents section }
  1712. sec_code (* sec_toc *),
  1713. sec_code (* sec_init *),
  1714. sec_code (* sec_fini *),
  1715. sec_none (* sec_objc_class *),
  1716. sec_none (* sec_objc_meta_class *),
  1717. sec_none (* sec_objc_cat_cls_meth *),
  1718. sec_none (* sec_objc_cat_inst_meth *),
  1719. sec_none (* sec_objc_protocol *),
  1720. sec_none (* sec_objc_string_object *),
  1721. sec_none (* sec_objc_cls_meth *),
  1722. sec_none (* sec_objc_inst_meth *),
  1723. sec_none (* sec_objc_cls_refs *),
  1724. sec_none (* sec_objc_message_refs *),
  1725. sec_none (* sec_objc_symbols *),
  1726. sec_none (* sec_objc_category *),
  1727. sec_none (* sec_objc_class_vars *),
  1728. sec_none (* sec_objc_instance_vars *),
  1729. sec_none (* sec_objc_module_info *),
  1730. sec_none (* sec_objc_class_names *),
  1731. sec_none (* sec_objc_meth_var_types *),
  1732. sec_none (* sec_objc_meth_var_names *),
  1733. sec_none (* sec_objc_selector_strs *),
  1734. sec_none (* sec_objc_protocol_ext *),
  1735. sec_none (* sec_objc_class_ext *),
  1736. sec_none (* sec_objc_property *),
  1737. sec_none (* sec_objc_image_info *),
  1738. sec_none (* sec_objc_cstring_object *),
  1739. sec_none (* sec_objc_sel_fixup *),
  1740. sec_none (* sec_objc_data *),
  1741. sec_none (* sec_objc_const *),
  1742. sec_none (* sec_objc_sup_refs *),
  1743. sec_none (* sec_data_coalesced *),
  1744. sec_none (* sec_objc_classlist *),
  1745. sec_none (* sec_objc_nlclasslist *),
  1746. sec_none (* sec_objc_catlist *),
  1747. sec_none (* sec_objc_nlcatlist *),
  1748. sec_none (* sec_objc_protlist *),
  1749. sec_none (* sec_stack *),
  1750. sec_none (* sec_heap *)
  1751. );
  1752. begin
  1753. Result := inherited SectionName (SecXTable [AType], AName, AOrder);
  1754. end;
  1755. {****************************************************************************}
  1756. { Abstract Instruction Writer }
  1757. {****************************************************************************}
  1758. constructor TCPUInstrWriter.create(_owner: TGNUAssembler);
  1759. begin
  1760. inherited create;
  1761. owner := _owner;
  1762. end;
  1763. end.