aggas.pas 71 KB

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