aggas.pas 71 KB

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