aggas.pas 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  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. co : comp;
  557. sin : single;
  558. d : double;
  559. {$ifdef cpuextended}
  560. e : extended;
  561. {$endif cpuextended}
  562. do_line : boolean;
  563. sepChar : char;
  564. replaceforbidden: boolean;
  565. begin
  566. if not assigned(p) then
  567. exit;
  568. replaceforbidden:=asminfo^.dollarsign<>'$';
  569. last_align := 2;
  570. InlineLevel:=0;
  571. { lineinfo is only needed for al_procedures (PFV) }
  572. do_line:=(cs_asm_source in current_settings.globalswitches) or
  573. ((cs_lineinfo in current_settings.moduleswitches)
  574. and (p=current_asmdata.asmlists[al_procedures]));
  575. lasthp:=nil;
  576. hp:=tai(p.first);
  577. while assigned(hp) do
  578. begin
  579. prefetch(pointer(hp.next)^);
  580. if not(hp.typ in SkipLineInfo) then
  581. begin
  582. current_filepos:=tailineinfo(hp).fileinfo;
  583. { no line info for inlined code }
  584. if do_line and (inlinelevel=0) then
  585. WriteSourceLine(hp as tailineinfo);
  586. end;
  587. case hp.typ of
  588. ait_comment :
  589. Begin
  590. writer.AsmWrite(asminfo^.comment);
  591. writer.AsmWritePChar(tai_comment(hp).str);
  592. writer.AsmLn;
  593. End;
  594. ait_regalloc :
  595. begin
  596. if (cs_asm_regalloc in current_settings.globalswitches) then
  597. begin
  598. writer.AsmWrite(#9+asminfo^.comment+'Register ');
  599. repeat
  600. writer.AsmWrite(std_regname(Tai_regalloc(hp).reg));
  601. if (hp.next=nil) or
  602. (tai(hp.next).typ<>ait_regalloc) or
  603. (tai_regalloc(hp.next).ratype<>tai_regalloc(hp).ratype) then
  604. break;
  605. hp:=tai(hp.next);
  606. writer.AsmWrite(',');
  607. until false;
  608. writer.AsmWrite(' ');
  609. writer.AsmWriteLn(regallocstr[tai_regalloc(hp).ratype]);
  610. end;
  611. end;
  612. ait_tempalloc :
  613. begin
  614. if (cs_asm_tempalloc in current_settings.globalswitches) then
  615. WriteTempalloc(tai_tempalloc(hp));
  616. end;
  617. ait_align :
  618. begin
  619. doalign(tai_align_abstract(hp).aligntype,tai_align_abstract(hp).use_op,tai_align_abstract(hp).fillop,last_align,lasthp);
  620. end;
  621. ait_section :
  622. begin
  623. if tai_section(hp).sectype<>sec_none then
  624. if replaceforbidden then
  625. WriteSection(tai_section(hp).sectype,ReplaceForbiddenAsmSymbolChars(tai_section(hp).name^),tai_section(hp).secorder,tai_section(hp).secalign)
  626. else
  627. WriteSection(tai_section(hp).sectype,tai_section(hp).name^,tai_section(hp).secorder,tai_section(hp).secalign)
  628. else
  629. begin
  630. {$ifdef EXTDEBUG}
  631. writer.AsmWrite(asminfo^.comment);
  632. writer.AsmWriteln(' sec_none');
  633. {$endif EXTDEBUG}
  634. end;
  635. end;
  636. ait_datablock :
  637. begin
  638. if (target_info.system in systems_darwin) then
  639. begin
  640. { On Mac OS X you can't have common symbols in a shared library
  641. since those are in the TEXT section and the text section is
  642. read-only in shared libraries (so it can be shared among different
  643. processes). The alternate code creates some kind of common symbols
  644. in the data segment.
  645. }
  646. if tai_datablock(hp).is_global then
  647. begin
  648. writer.AsmWrite('.globl ');
  649. writer.AsmWriteln(tai_datablock(hp).sym.name);
  650. writer.AsmWriteln('.data');
  651. writer.AsmWrite('.zerofill __DATA, __common, ');
  652. writer.AsmWrite(tai_datablock(hp).sym.name);
  653. writer.AsmWriteln(', '+tostr(tai_datablock(hp).size)+','+tostr(last_align));
  654. if not(LastSecType in [sec_data,sec_none]) then
  655. writesection(LastSecType,'',secorder_default,1 shl last_align);
  656. end
  657. else
  658. begin
  659. writer.AsmWrite(#9'.lcomm'#9);
  660. writer.AsmWrite(tai_datablock(hp).sym.name);
  661. writer.AsmWrite(','+tostr(tai_datablock(hp).size));
  662. writer.AsmWrite(','+tostr(last_align));
  663. writer.AsmLn;
  664. end;
  665. end
  666. else if target_info.system in systems_aix then
  667. begin
  668. if tai_datablock(hp).is_global then
  669. begin
  670. writer.AsmWrite(#9'.globl ');
  671. writer.AsmWriteln(ReplaceForbiddenAsmSymbolChars(tai_datablock(hp).sym.name));
  672. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_datablock(hp).sym.name));
  673. writer.AsmWriteln(':');
  674. writer.AsmWrite(#9'.space ');
  675. writer.AsmWriteln(tostr(tai_datablock(hp).size));
  676. if not(LastSecType in [sec_data,sec_none]) then
  677. writesection(LastSecType,'',secorder_default,1 shl last_align);
  678. end
  679. else
  680. begin
  681. writer.AsmWrite(#9'.lcomm ');
  682. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_datablock(hp).sym.name));
  683. writer.AsmWrite(',');
  684. writer.AsmWrite(tostr(tai_datablock(hp).size)+',');
  685. writer.AsmWrite('_data.bss_,');
  686. writer.AsmWriteln(tostr(last_align));
  687. end;
  688. end
  689. else
  690. begin
  691. {$ifdef USE_COMM_IN_BSS}
  692. if writingpackages then
  693. begin
  694. { The .comm is required for COMMON symbols. These are used
  695. in the shared library loading. All the symbols declared in
  696. the .so file need to resolve to the data allocated in the main
  697. program (PFV) }
  698. if tai_datablock(hp).is_global then
  699. begin
  700. writer.AsmWrite(#9'.comm'#9);
  701. if replaceforbidden then
  702. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_datablock(hp).sym.name))
  703. else
  704. writer.AsmWrite(tai_datablock(hp).sym.name);
  705. writer.AsmWrite(','+tostr(tai_datablock(hp).size));
  706. writer.AsmWrite(','+tostr(last_align));
  707. writer.AsmLn;
  708. end
  709. else
  710. begin
  711. writer.AsmWrite(#9'.lcomm'#9);
  712. if replaceforbidden then
  713. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_datablock(hp).sym.name));
  714. else
  715. writer.AsmWrite(tai_datablock(hp).sym.name);
  716. writer.AsmWrite(','+tostr(tai_datablock(hp).size));
  717. writer.AsmWrite(','+tostr(last_align));
  718. writer.AsmLn;
  719. end
  720. end
  721. else
  722. {$endif USE_COMM_IN_BSS}
  723. begin
  724. if Tai_datablock(hp).is_global then
  725. begin
  726. writer.AsmWrite(#9'.globl ');
  727. if replaceforbidden then
  728. writer.AsmWriteln(ReplaceForbiddenAsmSymbolChars(Tai_datablock(hp).sym.name))
  729. else
  730. writer.AsmWriteln(Tai_datablock(hp).sym.name);
  731. end;
  732. if ((target_info.system <> system_arm_linux) and (target_info.system <> system_arm_android)) then
  733. sepChar := '@'
  734. else
  735. sepChar := '%';
  736. if replaceforbidden then
  737. begin
  738. if (tf_needs_symbol_type in target_info.flags) then
  739. writer.AsmWriteln(#9'.type '+ReplaceForbiddenAsmSymbolChars(Tai_datablock(hp).sym.name)+','+sepChar+'object');
  740. if (tf_needs_symbol_size in target_info.flags) and (tai_datablock(hp).size > 0) then
  741. writer.AsmWriteln(#9'.size '+ReplaceForbiddenAsmSymbolChars(Tai_datablock(hp).sym.name)+','+tostr(Tai_datablock(hp).size));
  742. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(Tai_datablock(hp).sym.name))
  743. end
  744. else
  745. begin
  746. if (tf_needs_symbol_type in target_info.flags) then
  747. writer.AsmWriteln(#9'.type '+Tai_datablock(hp).sym.name+','+sepChar+'object');
  748. if (tf_needs_symbol_size in target_info.flags) and (tai_datablock(hp).size > 0) then
  749. writer.AsmWriteln(#9'.size '+Tai_datablock(hp).sym.name+','+tostr(Tai_datablock(hp).size));
  750. writer.AsmWrite(Tai_datablock(hp).sym.name);
  751. end;
  752. writer.AsmWriteln(':');
  753. writer.AsmWriteln(#9'.zero '+tostr(Tai_datablock(hp).size));
  754. end;
  755. end;
  756. end;
  757. ait_const:
  758. begin
  759. constdef:=tai_const(hp).consttype;
  760. case constdef of
  761. {$ifndef cpu64bitaddr}
  762. aitconst_128bit :
  763. begin
  764. internalerror(200404291);
  765. end;
  766. aitconst_64bit :
  767. begin
  768. if assigned(tai_const(hp).sym) then
  769. internalerror(200404292);
  770. if not(target_info.system in systems_aix) then
  771. begin
  772. writer.AsmWrite(ait_const2str[aitconst_32bit]);
  773. if target_info.endian = endian_little then
  774. begin
  775. writer.AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  776. writer.AsmWrite(',');
  777. writer.AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  778. end
  779. else
  780. begin
  781. writer.AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  782. writer.AsmWrite(',');
  783. writer.AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  784. end;
  785. end
  786. else
  787. WriteAixIntConst(tai_const(hp));
  788. writer.AsmLn;
  789. end;
  790. {$endif cpu64bitaddr}
  791. aitconst_got:
  792. begin
  793. writer.AsmWrite(#9'.word'#9+tai_const(hp).sym.name+'(GOT)');
  794. writer.AsmLn;
  795. end;
  796. aitconst_gotoff_symbol:
  797. begin
  798. if (tai_const(hp).sym=nil) then
  799. InternalError(2014022601);
  800. case target_info.cpu of
  801. cpu_mipseb,cpu_mipsel:
  802. begin
  803. writer.AsmWrite(#9'.gpword'#9);
  804. writer.AsmWrite(tai_const(hp).sym.name);
  805. end;
  806. cpu_i386:
  807. begin
  808. writer.AsmWrite(ait_const2str[aitconst_32bit]);
  809. writer.AsmWrite(tai_const(hp).sym.name);
  810. end;
  811. else
  812. InternalError(2014022602);
  813. end;
  814. if (tai_const(hp).value<>0) then
  815. writer.AsmWrite(tostr_with_plus(tai_const(hp).value));
  816. writer.AsmLn;
  817. end;
  818. aitconst_uleb128bit,
  819. aitconst_sleb128bit,
  820. {$ifdef cpu64bitaddr}
  821. aitconst_128bit,
  822. aitconst_64bit,
  823. {$endif cpu64bitaddr}
  824. aitconst_32bit,
  825. aitconst_16bit,
  826. aitconst_8bit,
  827. aitconst_rva_symbol,
  828. aitconst_secrel32_symbol,
  829. aitconst_darwin_dwarf_delta32,
  830. aitconst_darwin_dwarf_delta64,
  831. aitconst_half16bit,
  832. aitconst_gs,
  833. aitconst_16bit_unaligned,
  834. aitconst_32bit_unaligned,
  835. aitconst_64bit_unaligned:
  836. begin
  837. { the AIX assembler (and for compatibility, the GNU
  838. assembler when targeting AIX) automatically aligns
  839. .short/.long/.llong to a multiple of 2/4/8 bytes. We
  840. don't want that, since this may be data inside a packed
  841. record -> use .vbyte instead (byte stream of fixed
  842. length) }
  843. if (target_info.system in systems_aix) and
  844. (constdef in [aitconst_128bit,aitconst_64bit,aitconst_32bit,aitconst_16bit]) and
  845. not assigned(tai_const(hp).sym) then
  846. begin
  847. WriteAixIntConst(tai_const(hp));
  848. end
  849. else if (target_info.system in systems_darwin) and
  850. (constdef in [aitconst_uleb128bit,aitconst_sleb128bit]) then
  851. begin
  852. writer.AsmWrite(ait_const2str[aitconst_8bit]);
  853. case tai_const(hp).consttype of
  854. aitconst_uleb128bit:
  855. WriteDecodedUleb128(qword(tai_const(hp).value));
  856. aitconst_sleb128bit:
  857. WriteDecodedSleb128(int64(tai_const(hp).value));
  858. end
  859. end
  860. else
  861. begin
  862. if (constdef in ait_unaligned_consts) and
  863. (target_info.system in use_ua_sparc_systems) then
  864. writer.AsmWrite(ait_ua_sparc_const2str[constdef])
  865. else if (constdef in ait_unaligned_consts) and
  866. (target_info.system in use_ua_elf_systems) then
  867. writer.AsmWrite(ait_ua_elf_const2str[constdef])
  868. { we can also have unaligned pointers in packed record
  869. constants, which don't get translated into
  870. unaligned tai -> always use vbyte }
  871. else if target_info.system in systems_aix then
  872. writer.AsmWrite(#9'.vbyte'#9+tostr(tai_const(hp).size)+',')
  873. else
  874. writer.AsmWrite(ait_const2str[constdef]);
  875. l:=0;
  876. t := '';
  877. repeat
  878. if assigned(tai_const(hp).sym) then
  879. begin
  880. if assigned(tai_const(hp).endsym) then
  881. begin
  882. if (constdef in [aitconst_darwin_dwarf_delta32,aitconst_darwin_dwarf_delta64]) then
  883. begin
  884. s := NextSetLabel;
  885. t := #9'.set '+s+','+tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name;
  886. end
  887. else
  888. s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
  889. end
  890. else
  891. s:=tai_const(hp).sym.name;
  892. if replaceforbidden then
  893. s:=ReplaceForbiddenAsmSymbolChars(s);
  894. if tai_const(hp).value<>0 then
  895. s:=s+tostr_with_plus(tai_const(hp).value);
  896. end
  897. else
  898. {$ifdef cpu64bitaddr}
  899. s:=tostr(tai_const(hp).value);
  900. {$else cpu64bitaddr}
  901. { 64 bit constants are already handled above in this case }
  902. s:=tostr(longint(tai_const(hp).value));
  903. {$endif cpu64bitaddr}
  904. if constdef = aitconst_half16bit then
  905. s:='('+s+')/2';
  906. if constdef = aitconst_gs then
  907. s:='gs('+s+')';
  908. writer.AsmWrite(s);
  909. inc(l,length(s));
  910. { Values with symbols are written on a single line to improve
  911. reading of the .s file (PFV) }
  912. if assigned(tai_const(hp).sym) or
  913. not(LastSecType in [sec_data,sec_rodata,sec_rodata_norel]) or
  914. (l>line_length) or
  915. (hp.next=nil) or
  916. (tai(hp.next).typ<>ait_const) or
  917. (tai_const(hp.next).consttype<>constdef) or
  918. assigned(tai_const(hp.next).sym) then
  919. break;
  920. hp:=tai(hp.next);
  921. writer.AsmWrite(',');
  922. until false;
  923. if (t <> '') then
  924. begin
  925. writer.AsmLn;
  926. writer.AsmWrite(t);
  927. end;
  928. end;
  929. writer.AsmLn;
  930. end;
  931. else
  932. internalerror(200704251);
  933. end;
  934. end;
  935. ait_realconst :
  936. begin
  937. WriteRealConstAsBytes(tai_realconst(hp),#9'.byte'#9,do_line);
  938. end;
  939. ait_string :
  940. begin
  941. pos:=0;
  942. if not(target_info.system in systems_aix) then
  943. begin
  944. for i:=1 to tai_string(hp).len do
  945. begin
  946. if pos=0 then
  947. begin
  948. writer.AsmWrite(#9'.ascii'#9'"');
  949. pos:=20;
  950. end;
  951. ch:=tai_string(hp).str[i-1];
  952. case ch of
  953. #0, {This can't be done by range, because a bug in FPC}
  954. #1..#31,
  955. #128..#255 : s:='\'+tostr(ord(ch) shr 6)+tostr((ord(ch) and 63) shr 3)+tostr(ord(ch) and 7);
  956. '"' : s:='\"';
  957. '\' : s:='\\';
  958. else
  959. s:=ch;
  960. end;
  961. writer.AsmWrite(s);
  962. inc(pos,length(s));
  963. if (pos>line_length) or (i=tai_string(hp).len) then
  964. begin
  965. writer.AsmWriteLn('"');
  966. pos:=0;
  967. end;
  968. end;
  969. end
  970. else
  971. WriteAixStringConst(tai_string(hp));
  972. end;
  973. ait_label :
  974. begin
  975. if (tai_label(hp).labsym.is_used) then
  976. begin
  977. if (tai_label(hp).labsym.bind=AB_PRIVATE_EXTERN) then
  978. begin
  979. writer.AsmWrite(#9'.private_extern ');
  980. writer.AsmWriteln(tai_label(hp).labsym.name);
  981. end;
  982. if tai_label(hp).labsym.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN] then
  983. begin
  984. {$ifdef arm}
  985. { do no change arm mode accidently, .globl seems to reset the mode }
  986. if GenerateThumbCode or GenerateThumb2Code then
  987. writer.AsmWriteln(#9'.thumb_func'#9);
  988. {$endif arm}
  989. writer.AsmWrite('.globl'#9);
  990. if replaceforbidden then
  991. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_label(hp).labsym.name))
  992. else
  993. writer.AsmWriteLn(tai_label(hp).labsym.name);
  994. end;
  995. if replaceforbidden then
  996. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_label(hp).labsym.name))
  997. else
  998. writer.AsmWrite(tai_label(hp).labsym.name);
  999. writer.AsmWriteLn(':');
  1000. end;
  1001. end;
  1002. ait_symbol :
  1003. begin
  1004. if (tai_symbol(hp).sym.bind=AB_PRIVATE_EXTERN) then
  1005. begin
  1006. writer.AsmWrite(#9'.private_extern ');
  1007. if replaceforbidden then
  1008. writer.AsmWriteln(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name))
  1009. else
  1010. writer.AsmWriteln(tai_symbol(hp).sym.name);
  1011. end;
  1012. if (target_info.system=system_powerpc64_linux) and
  1013. (tai_symbol(hp).sym.typ=AT_FUNCTION) and
  1014. (cs_profile in current_settings.moduleswitches) then
  1015. writer.AsmWriteLn('.globl _mcount');
  1016. if tai_symbol(hp).is_global then
  1017. begin
  1018. writer.AsmWrite('.globl'#9);
  1019. if replaceforbidden then
  1020. writer.AsmWriteln(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name))
  1021. else
  1022. writer.AsmWriteln(tai_symbol(hp).sym.name);
  1023. end;
  1024. if (target_info.system=system_powerpc64_linux) and
  1025. use_dotted_functions and
  1026. (tai_symbol(hp).sym.typ=AT_FUNCTION) then
  1027. begin
  1028. writer.AsmWriteLn('.section ".opd", "aw"');
  1029. writer.AsmWriteLn('.align 3');
  1030. writer.AsmWriteLn(tai_symbol(hp).sym.name + ':');
  1031. writer.AsmWriteLn('.quad .' + tai_symbol(hp).sym.name + ', .TOC.@tocbase, 0');
  1032. writer.AsmWriteLn('.previous');
  1033. writer.AsmWriteLn('.size ' + tai_symbol(hp).sym.name + ', 24');
  1034. if (tai_symbol(hp).is_global) then
  1035. writer.AsmWriteLn('.globl .' + tai_symbol(hp).sym.name);
  1036. writer.AsmWriteLn('.type .' + tai_symbol(hp).sym.name + ', @function');
  1037. { the dotted name is the name of the actual function entry }
  1038. writer.AsmWrite('.');
  1039. end
  1040. else if (target_info.system in systems_aix) and
  1041. (tai_symbol(hp).sym.typ = AT_FUNCTION) then
  1042. begin
  1043. if target_info.system=system_powerpc_aix then
  1044. begin
  1045. s:=#9'.long .';
  1046. ch:='2';
  1047. end
  1048. else
  1049. begin
  1050. s:=#9'.llong .';
  1051. ch:='3';
  1052. end;
  1053. writer.AsmWriteLn(#9'.csect '+ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name)+'[DS],'+ch);
  1054. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name)+':');
  1055. writer.AsmWriteln(s+ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name)+', TOC[tc0], 0');
  1056. writer.AsmWriteln(#9'.csect .text[PR]');
  1057. if (tai_symbol(hp).is_global) then
  1058. writer.AsmWriteLn('.globl .'+ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name))
  1059. else
  1060. writer.AsmWriteLn('.lglobl .'+ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name));
  1061. { the dotted name is the name of the actual function entry }
  1062. writer.AsmWrite('.');
  1063. end
  1064. else
  1065. begin
  1066. if ((target_info.system <> system_arm_linux) and (target_info.system <> system_arm_android)) then
  1067. sepChar := '@'
  1068. else
  1069. sepChar := '#';
  1070. if (tf_needs_symbol_type in target_info.flags) then
  1071. begin
  1072. writer.AsmWrite(#9'.type'#9 + tai_symbol(hp).sym.name);
  1073. if (needsObject(tai_symbol(hp))) then
  1074. writer.AsmWriteLn(',' + sepChar + 'object')
  1075. else
  1076. writer.AsmWriteLn(',' + sepChar + 'function');
  1077. end;
  1078. end;
  1079. if replaceforbidden then
  1080. if not(tai_symbol(hp).has_value) then
  1081. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name + ':'))
  1082. else
  1083. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_symbol(hp).sym.name + '=' + tostr(tai_symbol(hp).value)))
  1084. else if not(tai_symbol(hp).has_value) then
  1085. writer.AsmWriteLn(tai_symbol(hp).sym.name + ':')
  1086. else
  1087. writer.AsmWriteLn(tai_symbol(hp).sym.name + '=' + tostr(tai_symbol(hp).value));
  1088. end;
  1089. ait_symbolpair:
  1090. begin
  1091. writer.AsmWrite(#9);
  1092. writer.AsmWrite(symbolpairkindstr[tai_symbolpair(hp).kind]);
  1093. writer.AsmWrite(' ');
  1094. if tai_symbolpair(hp).kind<>spk_localentry then
  1095. s:=', '
  1096. else
  1097. { the .localentry directive has to specify the size from the
  1098. start till here of the non-local entry code as second argument }
  1099. s:=', .-';
  1100. if replaceforbidden then
  1101. begin
  1102. { avoid string truncation }
  1103. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_symbolpair(hp).sym^)+s);
  1104. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_symbolpair(hp).value^));
  1105. end
  1106. else
  1107. begin
  1108. { avoid string truncation }
  1109. writer.AsmWrite(tai_symbolpair(hp).sym^+s);
  1110. writer.AsmWriteLn(tai_symbolpair(hp).value^);
  1111. end;
  1112. end;
  1113. ait_weak:
  1114. begin
  1115. if replaceforbidden then
  1116. writer.AsmWriteLn(#9'.weak '+ReplaceForbiddenAsmSymbolChars(tai_weak(hp).sym^))
  1117. else
  1118. writer.AsmWriteLn(#9'.weak '+tai_weak(hp).sym^);
  1119. end;
  1120. ait_symbol_end :
  1121. begin
  1122. if tf_needs_symbol_size in target_info.flags then
  1123. begin
  1124. s:=asminfo^.labelprefix+'e'+tostr(symendcount);
  1125. inc(symendcount);
  1126. writer.AsmWriteLn(s+':');
  1127. writer.AsmWrite(#9'.size'#9);
  1128. if (target_info.system=system_powerpc64_linux) and
  1129. use_dotted_functions and
  1130. (tai_symbol_end(hp).sym.typ=AT_FUNCTION) then
  1131. writer.AsmWrite('.');
  1132. if replaceforbidden then
  1133. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_symbol_end(hp).sym.name))
  1134. else
  1135. writer.AsmWrite(tai_symbol_end(hp).sym.name);
  1136. writer.AsmWrite(', '+s+' - ');
  1137. if (target_info.system=system_powerpc64_linux) and
  1138. use_dotted_functions and
  1139. (tai_symbol_end(hp).sym.typ=AT_FUNCTION) then
  1140. writer.AsmWrite('.');
  1141. if replaceforbidden then
  1142. writer.AsmWriteLn(ReplaceForbiddenAsmSymbolChars(tai_symbol_end(hp).sym.name))
  1143. else
  1144. writer.AsmWriteLn(tai_symbol_end(hp).sym.name);
  1145. end;
  1146. end;
  1147. ait_instruction :
  1148. begin
  1149. WriteInstruction(hp);
  1150. end;
  1151. ait_stab :
  1152. begin
  1153. if assigned(tai_stab(hp).str) then
  1154. begin
  1155. writer.AsmWrite(#9'.'+stabtypestr[tai_stab(hp).stabtype]+' ');
  1156. writer.AsmWritePChar(tai_stab(hp).str);
  1157. writer.AsmLn;
  1158. end;
  1159. end;
  1160. ait_force_line,
  1161. ait_function_name :
  1162. begin
  1163. {$ifdef DEBUG_AGGAS}
  1164. WriteStr(s,hp.typ);
  1165. writer.AsmWriteLn('# '+s);
  1166. {$endif DEBUG_AGGAS}
  1167. end;
  1168. ait_cutobject :
  1169. begin
  1170. {$ifdef DEBUG_AGGAS}
  1171. writer.AsmWriteLn('# ait_cutobject');
  1172. {$endif DEBUG_AGGAS}
  1173. if SmartAsm then
  1174. begin
  1175. { only reset buffer if nothing has changed }
  1176. if not(writer.ClearIfEmpty) then
  1177. begin
  1178. writer.AsmClose;
  1179. DoAssemble;
  1180. writer.AsmCreate(tai_cutobject(hp).place);
  1181. end;
  1182. { avoid empty files }
  1183. while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
  1184. begin
  1185. if tai(hp.next).typ=ait_section then
  1186. LastSecType:=tai_section(hp.next).sectype;
  1187. hp:=tai(hp.next);
  1188. end;
  1189. if LastSecType<>sec_none then
  1190. WriteSection(LastSecType,'',secorder_default,last_align);
  1191. writer.MarkEmpty;
  1192. end;
  1193. end;
  1194. ait_marker :
  1195. begin
  1196. {$ifdef DEBUG_AGGAS}
  1197. WriteStr(s,tai_marker(hp).Kind);
  1198. writer.AsmWriteLn('# ait_marker, kind: '+s);
  1199. {$endif DEBUG_AGGAS}
  1200. if tai_marker(hp).kind=mark_NoLineInfoStart then
  1201. inc(InlineLevel)
  1202. else if tai_marker(hp).kind=mark_NoLineInfoEnd then
  1203. dec(InlineLevel);
  1204. end;
  1205. ait_directive :
  1206. begin
  1207. WriteDirectiveName(tai_directive(hp).directive);
  1208. if tai_directive(hp).name <>'' then
  1209. begin
  1210. if replaceforbidden then
  1211. writer.AsmWrite(ReplaceForbiddenAsmSymbolChars(tai_directive(hp).name))
  1212. else
  1213. writer.AsmWrite(tai_directive(hp).name);
  1214. end;
  1215. writer.AsmLn;
  1216. end;
  1217. ait_seh_directive :
  1218. begin
  1219. {$ifndef DISABLE_WIN64_SEH}
  1220. writer.AsmWrite(sehdirectivestr[tai_seh_directive(hp).kind]);
  1221. case tai_seh_directive(hp).datatype of
  1222. sd_none:;
  1223. sd_string:
  1224. begin
  1225. writer.AsmWrite(' '+tai_seh_directive(hp).data.name^);
  1226. if (tai_seh_directive(hp).data.flags and 1)<>0 then
  1227. writer.AsmWrite(',@except');
  1228. if (tai_seh_directive(hp).data.flags and 2)<>0 then
  1229. writer.AsmWrite(',@unwind');
  1230. end;
  1231. sd_reg:
  1232. writer.AsmWrite(' '+gas_regname(tai_seh_directive(hp).data.reg));
  1233. sd_offset:
  1234. writer.AsmWrite(' '+tostr(tai_seh_directive(hp).data.offset));
  1235. sd_regoffset:
  1236. writer.AsmWrite(' '+gas_regname(tai_seh_directive(hp).data.reg)+', '+
  1237. tostr(tai_seh_directive(hp).data.offset));
  1238. end;
  1239. writer.AsmLn;
  1240. {$endif DISABLE_WIN64_SEH}
  1241. end;
  1242. ait_varloc:
  1243. begin
  1244. if tai_varloc(hp).newlocationhi<>NR_NO then
  1245. writer.AsmWrite(strpnew('Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1246. std_regname(tai_varloc(hp).newlocationhi)+':'+std_regname(tai_varloc(hp).newlocation)))
  1247. else
  1248. writer.AsmWrite(strpnew('Var '+tai_varloc(hp).varsym.realname+' located in register '+
  1249. std_regname(tai_varloc(hp).newlocation)));
  1250. writer.AsmLn;
  1251. end;
  1252. else
  1253. internalerror(2006012201);
  1254. end;
  1255. lasthp:=hp;
  1256. hp:=tai(hp.next);
  1257. end;
  1258. end;
  1259. procedure TGNUAssembler.WriteExtraHeader;
  1260. begin
  1261. end;
  1262. procedure TGNUAssembler.WriteExtraFooter;
  1263. begin
  1264. end;
  1265. procedure TGNUAssembler.WriteInstruction(hp: tai);
  1266. begin
  1267. InstrWriter.WriteInstruction(hp);
  1268. end;
  1269. procedure TGNUAssembler.WriteWeakSymbolDef(s: tasmsymbol);
  1270. begin
  1271. writer.AsmWriteLn(#9'.weak '+s.name);
  1272. end;
  1273. procedure TGNUAssembler.WriteAixStringConst(hp: tai_string);
  1274. type
  1275. tterminationkind = (term_none,term_string,term_nostring);
  1276. var
  1277. i: longint;
  1278. pos: longint;
  1279. s: string;
  1280. ch: char;
  1281. instring: boolean;
  1282. procedure newstatement(terminationkind: tterminationkind);
  1283. begin
  1284. case terminationkind of
  1285. term_none: ;
  1286. term_string:
  1287. writer.AsmWriteLn('"');
  1288. term_nostring:
  1289. writer.AsmLn;
  1290. end;
  1291. writer.AsmWrite(#9'.byte'#9);
  1292. pos:=20;
  1293. instring:=false;
  1294. end;
  1295. begin
  1296. pos:=0;
  1297. instring:=false;
  1298. for i:=1 to hp.len do
  1299. begin
  1300. if pos=0 then
  1301. newstatement(term_none);
  1302. ch:=hp.str[i-1];
  1303. case ch of
  1304. #0..#31,
  1305. #127..#255 :
  1306. begin
  1307. if instring then
  1308. newstatement(term_string);
  1309. if pos=20 then
  1310. s:=tostr(ord(ch))
  1311. else
  1312. s:=', '+tostr(ord(ch))
  1313. end;
  1314. '"' :
  1315. if instring then
  1316. s:='""'
  1317. else
  1318. begin
  1319. if pos<>20 then
  1320. newstatement(term_nostring);
  1321. s:='"""';
  1322. instring:=true;
  1323. end;
  1324. else
  1325. if not instring then
  1326. begin
  1327. if (pos<>20) then
  1328. newstatement(term_nostring);
  1329. s:='"'+ch;
  1330. instring:=true;
  1331. end
  1332. else
  1333. s:=ch;
  1334. end;
  1335. writer.AsmWrite(s);
  1336. inc(pos,length(s));
  1337. if (pos>line_length) or (i=tai_string(hp).len) then
  1338. begin
  1339. if instring then
  1340. writer.AsmWriteLn('"')
  1341. else
  1342. writer.AsmLn;
  1343. pos:=0;
  1344. end;
  1345. end;
  1346. end;
  1347. procedure TGNUAssembler.WriteAixIntConst(hp: tai_const);
  1348. var
  1349. pos, size: longint;
  1350. begin
  1351. { only big endian AIX supported for now }
  1352. if target_info.endian<>endian_big then
  1353. internalerror(2012010401);
  1354. { limitation: can only write 4 bytes at a time }
  1355. pos:=0;
  1356. size:=tai_const(hp).size;
  1357. while pos<(size-4) do
  1358. begin
  1359. writer.AsmWrite(#9'.vbyte'#9'4, ');
  1360. writer.AsmWriteln(tostr(longint(tai_const(hp).value shr ((size-pos-4)*8))));
  1361. inc(pos,4);
  1362. end;
  1363. writer.AsmWrite(#9'.vbyte'#9);
  1364. writer.AsmWrite(tostr(size-pos));
  1365. writer.AsmWrite(', ');
  1366. case size-pos of
  1367. 1: writer.AsmWrite(tostr(byte(tai_const(hp).value)));
  1368. 2: writer.AsmWrite(tostr(word(tai_const(hp).value)));
  1369. 4: writer.AsmWrite(tostr(longint(tai_const(hp).value)));
  1370. else
  1371. internalerror(2012010402);
  1372. end;
  1373. end;
  1374. procedure TGNUAssembler.WriteUnalignedIntConst(hp: tai_const);
  1375. var
  1376. pos, size: longint;
  1377. begin
  1378. size:=tai_const(hp).size;
  1379. writer.AsmWrite(#9'.byte'#9);
  1380. if target_info.endian=endian_big then
  1381. begin
  1382. pos:=size-1;
  1383. while pos>=0 do
  1384. begin
  1385. writer.AsmWrite(tostr((tai_const(hp).value shr (pos*8)) and $ff));
  1386. dec(pos);
  1387. if pos>=0 then
  1388. writer.AsmWrite(', ')
  1389. else
  1390. writer.AsmLn;
  1391. end;
  1392. end
  1393. else
  1394. begin
  1395. pos:=0;
  1396. while pos<size do
  1397. begin
  1398. writer.AsmWriteln(tostr((tai_const(hp).value shr (pos*8)) and $ff));
  1399. inc(pos);
  1400. if pos<=size then
  1401. writer.AsmWrite(', ')
  1402. else
  1403. writer.AsmLn;
  1404. end;
  1405. end;
  1406. writer.AsmLn;
  1407. end;
  1408. procedure TGNUAssembler.WriteDirectiveName(dir: TAsmDirective);
  1409. begin
  1410. writer.AsmWrite('.'+directivestr[dir]+' ');
  1411. end;
  1412. procedure TGNUAssembler.WriteAsmList;
  1413. var
  1414. n : string;
  1415. hal : tasmlisttype;
  1416. i: longint;
  1417. begin
  1418. {$ifdef EXTDEBUG}
  1419. if current_module.mainsource<>'' then
  1420. Comment(V_Debug,'Start writing gas-styled assembler output for '+current_module.mainsource);
  1421. {$endif}
  1422. if current_module.mainsource<>'' then
  1423. n:=ExtractFileName(current_module.mainsource)
  1424. else
  1425. n:=InputFileName;
  1426. { gcc does not add it either for Darwin. Grep for
  1427. TARGET_ASM_FILE_START_FILE_DIRECTIVE in gcc/config/*.h
  1428. }
  1429. if not(target_info.system in systems_darwin) then
  1430. writer.AsmWriteLn(#9'.file "'+FixFileName(n)+'"');
  1431. WriteExtraHeader;
  1432. writer.MarkEmpty;
  1433. symendcount:=0;
  1434. for hal:=low(TasmlistType) to high(TasmlistType) do
  1435. begin
  1436. if not (current_asmdata.asmlists[hal].empty) then
  1437. begin
  1438. writer.AsmWriteLn(asminfo^.comment+'Begin asmlist '+AsmlistTypeStr[hal]);
  1439. writetree(current_asmdata.asmlists[hal]);
  1440. writer.AsmWriteLn(asminfo^.comment+'End asmlist '+AsmlistTypeStr[hal]);
  1441. end;
  1442. end;
  1443. { add weak symbol markers }
  1444. for i:=0 to current_asmdata.asmsymboldict.count-1 do
  1445. if (tasmsymbol(current_asmdata.asmsymboldict[i]).bind=AB_WEAK_EXTERNAL) then
  1446. writeweaksymboldef(tasmsymbol(current_asmdata.asmsymboldict[i]));
  1447. if create_smartlink_sections and
  1448. (target_info.system in systems_darwin) then
  1449. writer.AsmWriteLn(#9'.subsections_via_symbols');
  1450. { "no executable stack" marker }
  1451. { TODO: used by OpenBSD/NetBSD as well? }
  1452. if (target_info.system in (systems_linux + systems_android + systems_freebsd + systems_dragonfly)) and
  1453. not(cs_executable_stack in current_settings.moduleswitches) then
  1454. begin
  1455. writer.AsmWriteLn('.section .note.GNU-stack,"",%progbits');
  1456. end;
  1457. writer.AsmLn;
  1458. WriteExtraFooter;
  1459. {$ifdef EXTDEBUG}
  1460. if current_module.mainsource<>'' then
  1461. Comment(V_Debug,'Done writing gas-styled assembler output for '+current_module.mainsource);
  1462. {$endif EXTDEBUG}
  1463. end;
  1464. {****************************************************************************}
  1465. { Apple/GNU Assembler writer }
  1466. {****************************************************************************}
  1467. function TAppleGNUAssembler.sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
  1468. begin
  1469. if (target_info.system in systems_darwin) then
  1470. case atype of
  1471. sec_bss:
  1472. { all bss (lcomm) symbols are automatically put in the right }
  1473. { place by using the lcomm assembler directive }
  1474. atype := sec_none;
  1475. sec_debug_frame,
  1476. sec_eh_frame:
  1477. begin
  1478. result := '.section __DWARF,__debug_info,regular,debug';
  1479. exit;
  1480. end;
  1481. sec_debug_line:
  1482. begin
  1483. result := '.section __DWARF,__debug_line,regular,debug';
  1484. exit;
  1485. end;
  1486. sec_debug_info:
  1487. begin
  1488. result := '.section __DWARF,__debug_info,regular,debug';
  1489. exit;
  1490. end;
  1491. sec_debug_abbrev:
  1492. begin
  1493. result := '.section __DWARF,__debug_abbrev,regular,debug';
  1494. exit;
  1495. end;
  1496. sec_rodata:
  1497. begin
  1498. result := '.const_data';
  1499. exit;
  1500. end;
  1501. sec_rodata_norel:
  1502. begin
  1503. result := '.const';
  1504. exit;
  1505. end;
  1506. sec_fpc:
  1507. begin
  1508. result := '.section __TEXT, .fpc, regular, no_dead_strip';
  1509. exit;
  1510. end;
  1511. sec_code:
  1512. begin
  1513. if (aname='fpc_geteipasebx') or
  1514. (aname='fpc_geteipasecx') then
  1515. begin
  1516. result:='.section __TEXT,__textcoal_nt,coalesced,pure_instructions'#10'.weak_definition '+aname+
  1517. #10'.private_extern '+aname;
  1518. exit;
  1519. end;
  1520. end;
  1521. sec_data_nonlazy:
  1522. begin
  1523. result:='.section __DATA, __nl_symbol_ptr,non_lazy_symbol_pointers';
  1524. exit;
  1525. end;
  1526. sec_data_lazy:
  1527. begin
  1528. result:='.section __DATA, __la_symbol_ptr,lazy_symbol_pointers';
  1529. exit;
  1530. end;
  1531. sec_init_func:
  1532. begin
  1533. result:='.section __DATA, __mod_init_func, mod_init_funcs';
  1534. exit;
  1535. end;
  1536. sec_term_func:
  1537. begin
  1538. result:='.section __DATA, __mod_term_func, mod_term_funcs';
  1539. exit;
  1540. end;
  1541. sec_objc_protocol_ext:
  1542. begin
  1543. result:='.section __OBJC, __protocol_ext, regular, no_dead_strip';
  1544. exit;
  1545. end;
  1546. sec_objc_class_ext:
  1547. begin
  1548. result:='.section __OBJC, __class_ext, regular, no_dead_strip';
  1549. exit;
  1550. end;
  1551. sec_objc_property:
  1552. begin
  1553. result:='.section __OBJC, __property, regular, no_dead_strip';
  1554. exit;
  1555. end;
  1556. sec_objc_image_info:
  1557. begin
  1558. if (target_info.system in systems_objc_nfabi) then
  1559. result:='.section __DATA,__objc_imageinfo,regular,no_dead_strip'
  1560. else
  1561. result:='.section __OBJC, __image_info, regular, no_dead_strip';
  1562. exit;
  1563. end;
  1564. sec_objc_cstring_object:
  1565. begin
  1566. result:='.section __OBJC, __cstring_object, regular, no_dead_strip';
  1567. exit;
  1568. end;
  1569. sec_objc_sel_fixup:
  1570. begin
  1571. result:='.section __OBJC, __sel_fixup, regular, no_dead_strip';
  1572. exit;
  1573. end;
  1574. sec_objc_message_refs:
  1575. begin
  1576. if (target_info.system in systems_objc_nfabi) then
  1577. begin
  1578. result:='.section __DATA, __objc_selrefs, literal_pointers, no_dead_strip';
  1579. exit;
  1580. end;
  1581. end;
  1582. sec_objc_cls_refs:
  1583. begin
  1584. if (target_info.system in systems_objc_nfabi) then
  1585. begin
  1586. result:='.section __DATA, __objc_clsrefs, regular, no_dead_strip';
  1587. exit;
  1588. end;
  1589. end;
  1590. sec_objc_meth_var_types:
  1591. begin
  1592. if (target_info.system in systems_objc_nfabi) then
  1593. begin
  1594. result:='.section __TEXT,__objc_methtype,cstring_literals';
  1595. exit
  1596. end;
  1597. end;
  1598. sec_objc_meth_var_names:
  1599. begin
  1600. if (target_info.system in systems_objc_nfabi) then
  1601. begin
  1602. result:='.section __TEXT,__objc_methname,cstring_literals';
  1603. exit
  1604. end;
  1605. end;
  1606. sec_objc_class_names:
  1607. begin
  1608. if (target_info.system in systems_objc_nfabi) then
  1609. begin
  1610. result:='.section __TEXT,__objc_classname,cstring_literals';
  1611. exit
  1612. end;
  1613. end;
  1614. sec_objc_inst_meth,
  1615. sec_objc_cls_meth,
  1616. sec_objc_cat_inst_meth,
  1617. sec_objc_cat_cls_meth:
  1618. begin
  1619. if (target_info.system in systems_objc_nfabi) then
  1620. begin
  1621. result:='.section __DATA, __objc_const';
  1622. exit;
  1623. end;
  1624. end;
  1625. sec_objc_meta_class,
  1626. sec_objc_class:
  1627. begin
  1628. if (target_info.system in systems_objc_nfabi) then
  1629. begin
  1630. result:='.section __DATA, __objc_data';
  1631. exit;
  1632. end;
  1633. end;
  1634. sec_objc_sup_refs:
  1635. begin
  1636. result:='.section __DATA, __objc_superrefs, regular, no_dead_strip';
  1637. exit
  1638. end;
  1639. sec_objc_classlist:
  1640. begin
  1641. result:='.section __DATA, __objc_classlist, regular, no_dead_strip';
  1642. exit
  1643. end;
  1644. sec_objc_nlclasslist:
  1645. begin
  1646. result:='.section __DATA, __objc_nlclasslist, regular, no_dead_strip';
  1647. exit
  1648. end;
  1649. sec_objc_catlist:
  1650. begin
  1651. result:='.section __DATA, __objc_catlist, regular, no_dead_strip';
  1652. exit
  1653. end;
  1654. sec_objc_nlcatlist:
  1655. begin
  1656. result:='.section __DATA, __objc_nlcatlist, regular, no_dead_strip';
  1657. exit
  1658. end;
  1659. sec_objc_protolist:
  1660. begin
  1661. result:='.section __DATA, __objc_protolist, coalesced, no_dead_strip';
  1662. exit;
  1663. end;
  1664. end;
  1665. result := inherited sectionname(atype,aname,aorder);
  1666. end;
  1667. procedure TAppleGNUAssembler.WriteWeakSymbolDef(s: tasmsymbol);
  1668. begin
  1669. writer.AsmWriteLn(#9'.weak_reference '+s.name);
  1670. end;
  1671. {****************************************************************************}
  1672. { a.out/GNU Assembler writer }
  1673. {****************************************************************************}
  1674. function TAoutGNUAssembler.sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
  1675. const
  1676. (* Translation table - replace unsupported section types with basic ones. *)
  1677. SecXTable: array[TAsmSectionType] of TAsmSectionType = (
  1678. sec_none,
  1679. sec_none,
  1680. sec_code,
  1681. sec_data,
  1682. sec_data (* sec_rodata *),
  1683. sec_data (* sec_rodata_norel *),
  1684. sec_bss,
  1685. sec_data (* sec_threadvar *),
  1686. { used for wince exception handling }
  1687. sec_code (* sec_pdata *),
  1688. { used for darwin import stubs }
  1689. sec_code (* sec_stub *),
  1690. sec_data,(* sec_data_nonlazy *)
  1691. sec_data,(* sec_data_lazy *)
  1692. sec_data,(* sec_init_func *)
  1693. sec_data,(* sec_term_func *)
  1694. { stabs }
  1695. sec_stab,sec_stabstr,
  1696. { win32 }
  1697. sec_data (* sec_idata2 *),
  1698. sec_data (* sec_idata4 *),
  1699. sec_data (* sec_idata5 *),
  1700. sec_data (* sec_idata6 *),
  1701. sec_data (* sec_idata7 *),
  1702. sec_data (* sec_edata *),
  1703. { C++ exception handling unwinding (uses dwarf) }
  1704. sec_eh_frame,
  1705. { dwarf }
  1706. sec_debug_frame,
  1707. sec_debug_info,
  1708. sec_debug_line,
  1709. sec_debug_abbrev,
  1710. { ELF resources (+ references to stabs debug information sections) }
  1711. sec_code (* sec_fpc *),
  1712. { Table of contents section }
  1713. sec_code (* sec_toc *),
  1714. sec_code (* sec_init *),
  1715. sec_code (* sec_fini *),
  1716. sec_none (* sec_objc_class *),
  1717. sec_none (* sec_objc_meta_class *),
  1718. sec_none (* sec_objc_cat_cls_meth *),
  1719. sec_none (* sec_objc_cat_inst_meth *),
  1720. sec_none (* sec_objc_protocol *),
  1721. sec_none (* sec_objc_string_object *),
  1722. sec_none (* sec_objc_cls_meth *),
  1723. sec_none (* sec_objc_inst_meth *),
  1724. sec_none (* sec_objc_cls_refs *),
  1725. sec_none (* sec_objc_message_refs *),
  1726. sec_none (* sec_objc_symbols *),
  1727. sec_none (* sec_objc_category *),
  1728. sec_none (* sec_objc_class_vars *),
  1729. sec_none (* sec_objc_instance_vars *),
  1730. sec_none (* sec_objc_module_info *),
  1731. sec_none (* sec_objc_class_names *),
  1732. sec_none (* sec_objc_meth_var_types *),
  1733. sec_none (* sec_objc_meth_var_names *),
  1734. sec_none (* sec_objc_selector_strs *),
  1735. sec_none (* sec_objc_protocol_ext *),
  1736. sec_none (* sec_objc_class_ext *),
  1737. sec_none (* sec_objc_property *),
  1738. sec_none (* sec_objc_image_info *),
  1739. sec_none (* sec_objc_cstring_object *),
  1740. sec_none (* sec_objc_sel_fixup *),
  1741. sec_none (* sec_objc_data *),
  1742. sec_none (* sec_objc_const *),
  1743. sec_none (* sec_objc_sup_refs *),
  1744. sec_none (* sec_data_coalesced *),
  1745. sec_none (* sec_objc_classlist *),
  1746. sec_none (* sec_objc_nlclasslist *),
  1747. sec_none (* sec_objc_catlist *),
  1748. sec_none (* sec_objc_nlcatlist *),
  1749. sec_none (* sec_objc_protlist *),
  1750. sec_none (* sec_stack *),
  1751. sec_none (* sec_heap *)
  1752. );
  1753. begin
  1754. Result := inherited SectionName (SecXTable [AType], AName, AOrder);
  1755. end;
  1756. {****************************************************************************}
  1757. { Abstract Instruction Writer }
  1758. {****************************************************************************}
  1759. constructor TCPUInstrWriter.create(_owner: TGNUAssembler);
  1760. begin
  1761. inherited create;
  1762. owner := _owner;
  1763. end;
  1764. end.