aggas.pas 71 KB

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