aggas.pas 71 KB

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