aggas.pas 73 KB

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