aggas.pas 71 KB

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