ogelf.pas 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. {
  2. Copyright (c) 1998-2006 by Peter Vreman
  3. Contains the binary elf writer
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit ogelf;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,globtype,
  23. { target }
  24. systems,
  25. { assembler }
  26. cpuinfo,cpubase,aasmbase,aasmtai,aasmdata,assemble,
  27. { output }
  28. ogbase,
  29. owbase;
  30. type
  31. TElfObjSection = class(TObjSection)
  32. public
  33. secshidx : longint; { index for the section in symtab }
  34. shstridx,
  35. shtype,
  36. shflags,
  37. shlink,
  38. shinfo,
  39. shentsize : longint;
  40. constructor create(AList:TFPHashObjectList;const Aname:string;Aalign:shortint;Aoptions:TObjSectionOptions);override;
  41. constructor create_ext(AList:TFPHashObjectList;const Aname:string;Ashtype,Ashflags,Ashlink,Ashinfo:longint;Aalign:shortint;Aentsize:longint);
  42. end;
  43. TElfObjData = class(TObjData)
  44. public
  45. constructor create(const n:string);override;
  46. function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override;
  47. procedure CreateDebugSections;override;
  48. procedure writereloc(data:aint;len:aword;p:TObjSymbol;reltype:TObjRelocationType);override;
  49. end;
  50. TElfObjectOutput = class(tObjOutput)
  51. private
  52. symtabsect,
  53. strtabsect,
  54. shstrtabsect: TElfObjSection;
  55. {gotpcsect,
  56. gotoffsect,
  57. goTSect,
  58. plTSect,
  59. symsect : TElfObjSection;}
  60. symidx,
  61. localsyms : longint;
  62. procedure createrelocsection(s:TElfObjSection;data:TObjData);
  63. procedure createshstrtab(data:TObjData);
  64. procedure createsymtab(data: TObjData);
  65. procedure writesectionheader(s:TElfObjSection);
  66. procedure writesectiondata(s:TElfObjSection);
  67. procedure write_internal_symbol(astridx:longint;ainfo:byte;ashndx:word);
  68. procedure section_write_symbol(p:TObject;arg:pointer);
  69. procedure section_write_sh_string(p:TObject;arg:pointer);
  70. procedure section_count_sections(p:TObject;arg:pointer);
  71. procedure section_create_relocsec(p:TObject;arg:pointer);
  72. procedure section_set_datapos(p:TObject;arg:pointer);
  73. procedure section_write_data(p:TObject;arg:pointer);
  74. procedure section_write_sechdr(p:TObject;arg:pointer);
  75. protected
  76. function writedata(data:TObjData):boolean;override;
  77. public
  78. constructor Create(AWriter:TObjectWriter);override;
  79. end;
  80. TElfAssembler = class(tinternalassembler)
  81. constructor create(smart:boolean);override;
  82. end;
  83. implementation
  84. uses
  85. SysUtils,
  86. verbose,
  87. cutils,globals,fmodule;
  88. const
  89. symbolresize = 200*18;
  90. const
  91. { Relocation types }
  92. {$ifdef i386}
  93. R_386_32 = 1; { ordinary absolute relocation }
  94. R_386_PC32 = 2; { PC-relative relocation }
  95. R_386_GOT32 = 3; { an offset into GOT }
  96. R_386_PLT32 = 4; { a PC-relative offset into PLT }
  97. R_386_GOTOFF = 9; { an offset from GOT base }
  98. R_386_GOTPC = 10; { a PC-relative offset _to_ GOT }
  99. R_386_GNU_VTINHERIT = 250;
  100. R_386_GNU_VTENTRY = 251;
  101. {$endif i386}
  102. {$ifdef sparc}
  103. R_SPARC_32 = 3;
  104. R_SPARC_WDISP30 = 7;
  105. R_SPARC_HI22 = 9;
  106. R_SPARC_LO10 = 12;
  107. R_SPARC_GNU_VTINHERIT = 250;
  108. R_SPARC_GNU_VTENTRY = 251;
  109. {$endif sparc}
  110. {$ifdef x86_64}
  111. R_X86_64_NONE = 0;
  112. { Direct 64 bit }
  113. R_X86_64_64 = 1;
  114. { PC relative 32 bit signed }
  115. R_X86_64_PC32 = 2;
  116. { 32 bit GOT entry }
  117. R_X86_64_GOT32 = 3;
  118. { 32 bit PLT address }
  119. R_X86_64_PLT32 = 4;
  120. { Copy symbol at runtime }
  121. R_X86_64_COPY = 5;
  122. { Create GOT entry }
  123. R_X86_64_GLOB_DAT = 6;
  124. { Create PLT entry }
  125. R_X86_64_JUMP_SLOT = 7;
  126. { Adjust by program base }
  127. R_X86_64_RELATIVE = 8;
  128. { 32 bit signed PC relative offset to GOT }
  129. R_X86_64_GOTPCREL = 9;
  130. { Direct 32 bit zero extended }
  131. R_X86_64_32 = 10;
  132. { Direct 32 bit sign extended }
  133. R_X86_64_32S = 11;
  134. { Direct 16 bit zero extended }
  135. R_X86_64_16 = 12;
  136. { 16 bit sign extended PC relative }
  137. R_X86_64_PC16 = 13;
  138. { Direct 8 bit sign extended }
  139. R_X86_64_8 = 14;
  140. { 8 bit sign extended PC relative }
  141. R_X86_64_PC8 = 15;
  142. { ID of module containing symbol }
  143. R_X86_64_DTPMOD64 = 16;
  144. { Offset in module's TLS block }
  145. R_X86_64_DTPOFF64 = 17;
  146. { Offset in initial TLS block }
  147. R_X86_64_TPOFF64 = 18;
  148. { 32 bit signed PC relative offset to two GOT entries for GD symbol }
  149. R_X86_64_TLSGD = 19;
  150. { 32 bit signed PC relative offset to two GOT entries for LD symbol }
  151. R_X86_64_TLSLD = 20;
  152. { Offset in TLS block }
  153. R_X86_64_DTPOFF32 = 21;
  154. { 32 bit signed PC relative offset to GOT entry for IE symbol }
  155. R_X86_64_GOTTPOFF = 22;
  156. { Offset in initial TLS block }
  157. R_X86_64_TPOFF32 = 23;
  158. { GNU extension to record C++ vtable hierarchy }
  159. R_X86_64_GNU_VTINHERIT = 24;
  160. { GNU extension to record C++ vtable member usage }
  161. R_X86_64_GNU_VTENTRY = 25;
  162. {$endif x86_64}
  163. SHN_UNDEF = 0;
  164. SHN_ABS = $fff1;
  165. SHN_COMMON = $fff2;
  166. SHT_NULL = 0;
  167. SHT_PROGBITS = 1;
  168. SHT_SYMTAB = 2;
  169. SHT_STRTAB = 3;
  170. SHT_RELA = 4;
  171. SHT_HASH = 5;
  172. SHT_DYNAMIC = 6;
  173. SHT_NOTE = 7;
  174. SHT_NOBITS = 8;
  175. SHT_REL = 9;
  176. SHT_SHLIB = 10;
  177. SHT_DYNSYM = 11;
  178. SHF_WRITE = 1;
  179. SHF_ALLOC = 2;
  180. SHF_EXECINSTR = 4;
  181. STB_LOCAL = 0;
  182. STB_GLOBAL = 1;
  183. STB_WEAK = 2;
  184. STT_NOTYPE = 0;
  185. STT_OBJECT = 1;
  186. STT_FUNC = 2;
  187. STT_SECTION = 3;
  188. STT_FILE = 4;
  189. type
  190. { Structures which are written directly to the output file }
  191. TElf32header=packed record
  192. magic0123 : longint;
  193. file_class : byte;
  194. data_encoding : byte;
  195. file_version : byte;
  196. padding : array[$07..$0f] of byte;
  197. e_type : word;
  198. e_machine : word;
  199. e_version : longint;
  200. e_entry : longint; { entrypoint }
  201. e_phoff : longint; { program header offset }
  202. e_shoff : longint; { sections header offset }
  203. e_flags : longint;
  204. e_ehsize : word; { elf header size in bytes }
  205. e_phentsize : word; { size of an entry in the program header array }
  206. e_phnum : word; { 0..e_phnum-1 of entrys }
  207. e_shentsize : word; { size of an entry in sections header array }
  208. e_shnum : word; { 0..e_shnum-1 of entrys }
  209. e_shstrndx : word; { index of string section header }
  210. end;
  211. TElf32sechdr=packed record
  212. sh_name : longint;
  213. sh_type : longint;
  214. sh_flags : longint;
  215. sh_addr : longint;
  216. sh_offset : longint;
  217. sh_size : longint;
  218. sh_link : longint;
  219. sh_info : longint;
  220. sh_addralign : longint;
  221. sh_entsize : longint;
  222. end;
  223. TElf32reloc=packed record
  224. address : longint;
  225. info : longint; { bit 0-7: type, 8-31: symbol }
  226. end;
  227. TElf32symbol=packed record
  228. st_name : longint;
  229. st_value : longint;
  230. st_size : longint;
  231. st_info : byte; { bit 0-3: type, 4-7: bind }
  232. st_other : byte;
  233. st_shndx : word;
  234. end;
  235. telf64header=packed record
  236. magic0123 : longint;
  237. file_class : byte;
  238. data_encoding : byte;
  239. file_version : byte;
  240. padding : array[$07..$0f] of byte;
  241. e_type : word;
  242. e_machine : word;
  243. e_version : longint;
  244. e_entry : qword; { entrypoint }
  245. e_phoff : qword; { program header offset }
  246. e_shoff : qword; { sections header offset }
  247. e_flags : longint;
  248. e_ehsize : word; { elf header size in bytes }
  249. e_phentsize : word; { size of an entry in the program header array }
  250. e_phnum : word; { 0..e_phnum-1 of entrys }
  251. e_shentsize : word; { size of an entry in sections header array }
  252. e_shnum : word; { 0..e_shnum-1 of entrys }
  253. e_shstrndx : word; { index of string section header }
  254. end;
  255. telf64sechdr=packed record
  256. sh_name : longint;
  257. sh_type : longint;
  258. sh_flags : qword;
  259. sh_addr : qword;
  260. sh_offset : qword;
  261. sh_size : qword;
  262. sh_link : longint;
  263. sh_info : longint;
  264. sh_addralign : qword;
  265. sh_entsize : qword;
  266. end;
  267. telf64reloc=packed record
  268. address : qword;
  269. info : qword; { bit 0-31: type, 32-63: symbol }
  270. addend : int64; { signed! }
  271. end;
  272. telf64symbol=packed record
  273. st_name : longint;
  274. st_info : byte; { bit 0-3: type, 4-7: bind }
  275. st_other : byte;
  276. st_shndx : word;
  277. st_value : qword;
  278. st_size : qword;
  279. end;
  280. {$ifdef cpu64bitaddr}
  281. telfheader = telf64header;
  282. telfreloc = telf64reloc;
  283. telfsymbol = telf64symbol;
  284. telfsechdr = telf64sechdr;
  285. {$else cpu64bitaddr}
  286. telfheader = telf32header;
  287. telfreloc = telf32reloc;
  288. telfsymbol = telf32symbol;
  289. telfsechdr = telf32sechdr;
  290. {$endif cpu64bitaddr}
  291. function MayBeSwapHeader(h : telf32header) : telf32header;
  292. begin
  293. result:=h;
  294. if source_info.endian<>target_info.endian then
  295. with h do
  296. begin
  297. result.e_type:=swapendian(e_type);
  298. result.e_machine:=swapendian(e_machine);
  299. result.e_version:=swapendian(e_version);
  300. result.e_entry:=swapendian(e_entry);
  301. result.e_phoff:=swapendian(e_phoff);
  302. result.e_shoff:=swapendian(e_shoff);
  303. result.e_flags:=swapendian(e_flags);
  304. result.e_ehsize:=swapendian(e_ehsize);
  305. result.e_phentsize:=swapendian(e_phentsize);
  306. result.e_phnum:=swapendian(e_phnum);
  307. result.e_shentsize:=swapendian(e_shentsize);
  308. result.e_shnum:=swapendian(e_shnum);
  309. result.e_shstrndx:=swapendian(e_shstrndx);
  310. end;
  311. end;
  312. function MayBeSwapHeader(h : telf64header) : telf64header;
  313. begin
  314. result:=h;
  315. if source_info.endian<>target_info.endian then
  316. with h do
  317. begin
  318. result.e_type:=swapendian(e_type);
  319. result.e_machine:=swapendian(e_machine);
  320. result.e_version:=swapendian(e_version);
  321. result.e_entry:=swapendian(e_entry);
  322. result.e_phoff:=swapendian(e_phoff);
  323. result.e_shoff:=swapendian(e_shoff);
  324. result.e_flags:=swapendian(e_flags);
  325. result.e_ehsize:=swapendian(e_ehsize);
  326. result.e_phentsize:=swapendian(e_phentsize);
  327. result.e_phnum:=swapendian(e_phnum);
  328. result.e_shentsize:=swapendian(e_shentsize);
  329. result.e_shnum:=swapendian(e_shnum);
  330. result.e_shstrndx:=swapendian(e_shstrndx);
  331. end;
  332. end;
  333. function MaybeSwapSecHeader(h : telf32sechdr) : telf32sechdr;
  334. begin
  335. result:=h;
  336. if source_info.endian<>target_info.endian then
  337. with h do
  338. begin
  339. result.sh_name:=swapendian(sh_name);
  340. result.sh_type:=swapendian(sh_type);
  341. result.sh_flags:=swapendian(sh_flags);
  342. result.sh_addr:=swapendian(sh_addr);
  343. result.sh_offset:=swapendian(sh_offset);
  344. result.sh_size:=swapendian(sh_size);
  345. result.sh_link:=swapendian(sh_link);
  346. result.sh_info:=swapendian(sh_info);
  347. result.sh_addralign:=swapendian(sh_addralign);
  348. result.sh_entsize:=swapendian(sh_entsize);
  349. end;
  350. end;
  351. function MaybeSwapSecHeader(h : telf64sechdr) : telf64sechdr;
  352. begin
  353. result:=h;
  354. if source_info.endian<>target_info.endian then
  355. with h do
  356. begin
  357. result.sh_name:=swapendian(sh_name);
  358. result.sh_type:=swapendian(sh_type);
  359. result.sh_flags:=swapendian(sh_flags);
  360. result.sh_addr:=swapendian(sh_addr);
  361. result.sh_offset:=swapendian(sh_offset);
  362. result.sh_size:=swapendian(sh_size);
  363. result.sh_link:=swapendian(sh_link);
  364. result.sh_info:=swapendian(sh_info);
  365. result.sh_addralign:=swapendian(sh_addralign);
  366. result.sh_entsize:=swapendian(sh_entsize);
  367. end;
  368. end;
  369. function MaybeSwapElfSymbol(h : telf32symbol) : telf32symbol;
  370. begin
  371. result:=h;
  372. if source_info.endian<>target_info.endian then
  373. with h do
  374. begin
  375. result.st_name:=swapendian(st_name);
  376. result.st_value:=swapendian(st_value);
  377. result.st_size:=swapendian(st_size);
  378. result.st_shndx:=swapendian(st_shndx);
  379. end;
  380. end;
  381. function MaybeSwapElfSymbol(h : telf64symbol) : telf64symbol;
  382. begin
  383. result:=h;
  384. if source_info.endian<>target_info.endian then
  385. with h do
  386. begin
  387. result.st_name:=swapendian(st_name);
  388. result.st_value:=swapendian(st_value);
  389. result.st_size:=swapendian(st_size);
  390. result.st_shndx:=swapendian(st_shndx);
  391. end;
  392. end;
  393. function MaybeSwapElfReloc(h : telf32reloc) : telf32reloc;
  394. begin
  395. result:=h;
  396. if source_info.endian<>target_info.endian then
  397. with h do
  398. begin
  399. result.address:=swapendian(address);
  400. result.info:=swapendian(info);
  401. end;
  402. end;
  403. function MaybeSwapElfReloc(h : telf64reloc) : telf64reloc;
  404. begin
  405. result:=h;
  406. if source_info.endian<>target_info.endian then
  407. with h do
  408. begin
  409. result.address:=swapendian(address);
  410. result.info:=swapendian(info);
  411. end;
  412. end;
  413. {****************************************************************************
  414. Helpers
  415. ****************************************************************************}
  416. procedure encodesechdrflags(aoptions:TObjSectionOptions;out AshType:longint;out Ashflags:longint);
  417. begin
  418. { Section Type }
  419. AshType:=SHT_PROGBITS;
  420. if oso_strings in aoptions then
  421. AshType:=SHT_STRTAB
  422. else if not(oso_data in aoptions) then
  423. AshType:=SHT_NOBITS;
  424. { Section Flags }
  425. Ashflags:=0;
  426. if oso_load in aoptions then
  427. Ashflags:=Ashflags or SHF_ALLOC;
  428. if oso_executable in aoptions then
  429. Ashflags:=Ashflags or SHF_EXECINSTR;
  430. if oso_write in aoptions then
  431. Ashflags:=Ashflags or SHF_WRITE;
  432. end;
  433. procedure decodesechdrflags(AshType:longint;Ashflags:longint;out aoptions:TObjSectionOptions);
  434. begin
  435. aoptions:=[];
  436. { Section Type }
  437. if AshType<>SHT_NOBITS then
  438. include(aoptions,oso_data);
  439. if AshType=SHT_STRTAB then
  440. include(aoptions,oso_strings);
  441. { Section Flags }
  442. if Ashflags and SHF_ALLOC<>0 then
  443. include(aoptions,oso_load)
  444. else
  445. include(aoptions,oso_noload);
  446. if Ashflags and SHF_WRITE<>0 then
  447. include(aoptions,oso_write)
  448. else
  449. include(aoptions,oso_readonly);
  450. end;
  451. {****************************************************************************
  452. TElfObjSection
  453. ****************************************************************************}
  454. constructor TElfObjSection.create(AList:TFPHashObjectList;const Aname:string;Aalign:shortint;Aoptions:TObjSectionOptions);
  455. begin
  456. inherited create(AList,Aname,Aalign,aoptions);
  457. secshidx:=0;
  458. shstridx:=0;
  459. encodesechdrflags(aoptions,shtype,shflags);
  460. shlink:=0;
  461. shinfo:=0;
  462. if name='.stab' then
  463. shentsize:=sizeof(TObjStabEntry);
  464. end;
  465. constructor TElfObjSection.create_ext(AList:TFPHashObjectList;const Aname:string;Ashtype,Ashflags,Ashlink,Ashinfo:longint;Aalign:shortint;Aentsize:longint);
  466. var
  467. aoptions : TObjSectionOptions;
  468. begin
  469. decodesechdrflags(Ashtype,Ashflags,aoptions);
  470. inherited create(AList,Aname,Aalign,aoptions);
  471. secshidx:=0;
  472. shstridx:=0;
  473. shtype:=AshType;
  474. shflags:=AshFlags;
  475. shlink:=Ashlink;
  476. shinfo:=Ashinfo;
  477. shentsize:=Aentsize;
  478. end;
  479. {****************************************************************************
  480. TElfObjData
  481. ****************************************************************************}
  482. constructor TElfObjData.create(const n:string);
  483. var
  484. need_datarel : boolean;
  485. begin
  486. inherited create(n);
  487. CObjSection:=TElfObjSection;
  488. { we need at least the following sections }
  489. createsection(sec_code);
  490. if (cs_create_pic in current_settings.moduleswitches) and
  491. not(target_info.system in systems_darwin) then
  492. begin
  493. { We still need an empty data section }
  494. system.exclude(current_settings.moduleswitches,cs_create_pic);
  495. need_datarel:=true;
  496. end
  497. else
  498. need_datarel:=false;
  499. createsection(sec_data);
  500. if need_datarel then
  501. system.include(current_settings.moduleswitches,cs_create_pic);
  502. createsection(sec_bss);
  503. if need_datarel then
  504. createsection(sec_data);
  505. if tf_section_threadvars in target_info.flags then
  506. createsection(sec_threadvar);
  507. if (tf_needs_dwarf_cfi in target_info.flags) and
  508. (af_supports_dwarf in target_asm.flags) then
  509. createsection(sec_debug_frame);
  510. end;
  511. function TElfObjData.sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
  512. const
  513. secnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
  514. {$ifdef userodata}
  515. '.text','.data','.data','.rodata','.bss','.threadvar',
  516. {$else userodata}
  517. '.text','.data','.data','.data','.bss','.threadvar',
  518. {$endif userodata}
  519. '.pdata',
  520. '.text', { darwin stubs }
  521. '__DATA,__nl_symbol_ptr',
  522. '__DATA,__la_symbol_ptr',
  523. '__DATA,__mod_init_func',
  524. '__DATA,__mod_term_func',
  525. '.stab','.stabstr',
  526. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  527. '.eh_frame',
  528. '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
  529. '.fpc',
  530. '.toc',
  531. '.init',
  532. '.fini',
  533. '.objc_class',
  534. '.objc_meta_class',
  535. '.objc_cat_cls_meth',
  536. '.objc_cat_inst_meth',
  537. '.objc_protocol',
  538. '.objc_string_object',
  539. '.objc_cls_meth',
  540. '.objc_inst_meth',
  541. '.objc_cls_refs',
  542. '.objc_message_refs',
  543. '.objc_symbols',
  544. '.objc_category',
  545. '.objc_class_vars',
  546. '.objc_instance_vars',
  547. '.objc_module_info',
  548. '.objc_class_names',
  549. '.objc_meth_var_types',
  550. '.objc_meth_var_names',
  551. '.objc_selector_strs',
  552. '.objc_protocol_ext',
  553. '.objc_class_ext',
  554. '.objc_property',
  555. '.objc_image_info',
  556. '.objc_cstring_object',
  557. '.objc_sel_fixup',
  558. '__DATA,__objc_data',
  559. '__DATA,__objc_const',
  560. '.objc_superrefs',
  561. '__DATA, __datacoal_nt,coalesced',
  562. '.objc_classlist',
  563. '.objc_nlclasslist',
  564. '.objc_catlist',
  565. '.obcj_nlcatlist',
  566. '.objc_protolist'
  567. );
  568. secnames_pic : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
  569. '.text',
  570. '.data.rel',
  571. '.data.rel',
  572. '.data.rel',
  573. '.bss',
  574. '.threadvar',
  575. '.pdata',
  576. '', { stubs }
  577. '__DATA,__nl_symbol_ptr',
  578. '__DATA,__la_symbol_ptr',
  579. '__DATA,__mod_init_func',
  580. '__DATA,__mod_term_func',
  581. '.stab',
  582. '.stabstr',
  583. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  584. '.eh_frame',
  585. '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
  586. '.fpc',
  587. '.toc',
  588. '.init',
  589. '.fini',
  590. '.objc_class',
  591. '.objc_meta_class',
  592. '.objc_cat_cls_meth',
  593. '.objc_cat_inst_meth',
  594. '.objc_protocol',
  595. '.objc_string_object',
  596. '.objc_cls_meth',
  597. '.objc_inst_meth',
  598. '.objc_cls_refs',
  599. '.objc_message_refs',
  600. '.objc_symbols',
  601. '.objc_category',
  602. '.objc_class_vars',
  603. '.objc_instance_vars',
  604. '.objc_module_info',
  605. '.objc_class_names',
  606. '.objc_meth_var_types',
  607. '.objc_meth_var_names',
  608. '.objc_selector_strs',
  609. '.objc_protocol_ext',
  610. '.objc_class_ext',
  611. '.objc_property',
  612. '.objc_image_info',
  613. '.objc_cstring_object',
  614. '.objc_sel_fixup',
  615. '__DATA,__objc_data',
  616. '__DATA,__objc_const',
  617. '.objc_superrefs',
  618. '__DATA, __datacoal_nt,coalesced',
  619. '.objc_classlist',
  620. '.objc_nlclasslist',
  621. '.objc_catlist',
  622. '.obcj_nlcatlist',
  623. '.objc_protolist'
  624. );
  625. var
  626. sep : string[3];
  627. secname : string;
  628. begin
  629. { section type user gives the user full controll on the section name }
  630. if atype=sec_user then
  631. result:=aname
  632. else
  633. begin
  634. if (cs_create_pic in current_settings.moduleswitches) and
  635. not(target_info.system in systems_darwin) then
  636. secname:=secnames_pic[atype]
  637. else
  638. secname:=secnames[atype];
  639. if (atype=sec_fpc) and (Copy(aname,1,3)='res') then
  640. begin
  641. result:=secname+'.'+aname;
  642. exit;
  643. end;
  644. if create_smartlink_sections and (aname<>'') then
  645. begin
  646. case aorder of
  647. secorder_begin :
  648. sep:='.b_';
  649. secorder_end :
  650. sep:='.z_';
  651. else
  652. sep:='.n_';
  653. end;
  654. result:=secname+sep+aname
  655. end
  656. else
  657. result:=secname;
  658. end;
  659. end;
  660. procedure TElfObjData.CreateDebugSections;
  661. begin
  662. if target_dbg.id=dbg_stabs then
  663. begin
  664. stabssec:=createsection(sec_stab);
  665. stabstrsec:=createsection(sec_stabstr);
  666. end;
  667. end;
  668. procedure TElfObjData.writereloc(data:aint;len:aword;p:TObjSymbol;reltype:TObjRelocationType);
  669. var
  670. symaddr : aint;
  671. begin
  672. if CurrObjSec=nil then
  673. internalerror(200403292);
  674. {$ifdef userodata}
  675. if CurrObjSec.sectype in [sec_rodata,sec_bss,sec_threadvar] then
  676. internalerror(200408252);
  677. {$endif userodata}
  678. { Using RELOC_RVA to map 32-bit RELOC_ABSOLUTE to R_X86_64_32
  679. (RELOC_ABSOLUTE maps to R_X86_64_32S) }
  680. if (reltype=RELOC_ABSOLUTE) and (len<>sizeof(pint)) then
  681. reltype:=RELOC_RVA;
  682. if assigned(p) then
  683. begin
  684. { real address of the symbol }
  685. symaddr:=p.address;
  686. { Local ObjSymbols can be resolved already or need a section reloc }
  687. if (p.bind=AB_LOCAL) and
  688. (reltype in [RELOC_RELATIVE,RELOC_ABSOLUTE{$ifdef x86_64},RELOC_ABSOLUTE32,RELOC_RVA{$endif x86_64}]) then
  689. begin
  690. { For a reltype relocation in the same section the
  691. value can be calculated }
  692. if (p.objsection=CurrObjSec) and
  693. (reltype=RELOC_RELATIVE) then
  694. inc(data,symaddr-len-CurrObjSec.Size)
  695. else
  696. begin
  697. CurrObjSec.addsectionreloc(CurrObjSec.Size,p.objsection,reltype);
  698. inc(data,symaddr);
  699. end;
  700. end
  701. else
  702. begin
  703. CurrObjSec.addsymreloc(CurrObjSec.Size,p,reltype);
  704. {$ifndef x86_64}
  705. if (reltype=RELOC_RELATIVE) or (reltype=RELOC_PLT32) then
  706. dec(data,len);
  707. {$endif x86_64}
  708. end;
  709. end;
  710. CurrObjSec.write(data,len);
  711. end;
  712. {****************************************************************************
  713. TElfObjectOutput
  714. ****************************************************************************}
  715. constructor TElfObjectOutput.create(AWriter:TObjectWriter);
  716. begin
  717. inherited Create(AWriter);
  718. CObjData:=TElfObjData;
  719. end;
  720. procedure TElfObjectOutput.createrelocsection(s:TElfObjSection;data:TObjData);
  721. var
  722. i : longint;
  723. rel : telfreloc;
  724. objreloc : TObjRelocation;
  725. relsym,
  726. reltyp : longint;
  727. relocsect : TObjSection;
  728. {$ifdef x86_64}
  729. tmp: aint;
  730. asize: longint;
  731. {$endif x86_64}
  732. begin
  733. with data do
  734. begin
  735. {$ifdef userodata}
  736. { rodata can't have relocations }
  737. if s.sectype=sec_rodata then
  738. begin
  739. if assigned(s.relocations.first) then
  740. internalerror(200408251);
  741. exit;
  742. end;
  743. {$endif userodata}
  744. { create the reloc section }
  745. {$ifdef i386}
  746. relocsect:=TElfObjSection.create_ext(ObjSectionList,'.rel'+s.name,SHT_REL,0,symtabsect.secshidx,s.secshidx,4,sizeof(TElfReloc));
  747. {$else i386}
  748. relocsect:=TElfObjSection.create_ext(ObjSectionList,'.rela'+s.name,SHT_RELA,0,symtabsect.secshidx,s.secshidx,4,sizeof(TElfReloc));
  749. {$endif i386}
  750. { add the relocations }
  751. for i:=0 to s.Objrelocations.count-1 do
  752. begin
  753. objreloc:=TObjRelocation(s.Objrelocations[i]);
  754. fillchar(rel,sizeof(rel),0);
  755. rel.address:=objreloc.dataoffset;
  756. { when things settle down, we can create processor specific
  757. derived classes }
  758. case objreloc.typ of
  759. {$ifdef i386}
  760. RELOC_RELATIVE :
  761. reltyp:=R_386_PC32;
  762. RELOC_ABSOLUTE :
  763. reltyp:=R_386_32;
  764. RELOC_GOT32 :
  765. reltyp:=R_386_GOT32;
  766. RELOC_GOTPC :
  767. reltyp:=R_386_GOTPC;
  768. RELOC_PLT32 :
  769. begin
  770. reltyp:=R_386_PLT32;
  771. end;
  772. {$endif i386}
  773. {$ifdef sparc}
  774. RELOC_ABSOLUTE :
  775. reltyp:=R_SPARC_32;
  776. {$endif sparc}
  777. {$ifdef x86_64}
  778. RELOC_RELATIVE :
  779. begin
  780. reltyp:=R_X86_64_PC32;
  781. { length of the relocated location is handled here }
  782. rel.addend:=-4;
  783. end;
  784. RELOC_ABSOLUTE :
  785. reltyp:=R_X86_64_64;
  786. RELOC_ABSOLUTE32 :
  787. reltyp:=R_X86_64_32S;
  788. RELOC_RVA :
  789. reltyp:=R_X86_64_32;
  790. RELOC_GOTPCREL :
  791. begin
  792. reltyp:=R_X86_64_GOTPCREL;
  793. { length of the relocated location is handled here }
  794. rel.addend:=-4;
  795. end;
  796. RELOC_PLT32 :
  797. begin
  798. reltyp:=R_X86_64_PLT32;
  799. { length of the relocated location is handled here }
  800. rel.addend:=-4;
  801. end;
  802. {$endif x86_64}
  803. else
  804. internalerror(200602261);
  805. end;
  806. { This handles ELF 'rela'-styled relocations, which are currently used only for x86_64,
  807. but can be used other targets, too. }
  808. {$ifdef x86_64}
  809. s.Data.Seek(objreloc.dataoffset);
  810. if objreloc.typ=RELOC_ABSOLUTE then
  811. begin
  812. asize:=8;
  813. s.Data.Read(tmp,8);
  814. rel.addend:=rel.addend+tmp;
  815. end
  816. else
  817. begin
  818. asize:=4;
  819. s.Data.Read(tmp,4);
  820. rel.addend:=rel.addend+longint(tmp);
  821. end;
  822. { and zero the data member out }
  823. tmp:=0;
  824. s.Data.Seek(objreloc.dataoffset);
  825. s.Data.Write(tmp,asize);
  826. {$endif}
  827. { Symbol }
  828. if assigned(objreloc.symbol) then
  829. begin
  830. if objreloc.symbol.symidx=-1 then
  831. begin
  832. writeln(objreloc.symbol.Name);
  833. internalerror(200603012);
  834. end;
  835. relsym:=objreloc.symbol.symidx;
  836. end
  837. else
  838. begin
  839. if objreloc.objsection<>nil then
  840. relsym:=objreloc.objsection.secsymidx
  841. else
  842. relsym:=SHN_UNDEF;
  843. end;
  844. {$ifdef cpu64bitaddr}
  845. rel.info:=(qword(relsym) shl 32) or reltyp;
  846. {$else cpu64bitaddr}
  847. rel.info:=(relsym shl 8) or reltyp;
  848. {$endif cpu64bitaddr}
  849. { write reloc }
  850. relocsect.write(MaybeSwapElfReloc(rel),sizeof(rel));
  851. end;
  852. end;
  853. end;
  854. procedure TElfObjectOutput.write_internal_symbol(astridx:longint;ainfo:byte;ashndx:word);
  855. var
  856. elfsym : telfsymbol;
  857. begin
  858. fillchar(elfsym,sizeof(elfsym),0);
  859. elfsym.st_name:=astridx;
  860. elfsym.st_info:=ainfo;
  861. elfsym.st_shndx:=ashndx;
  862. inc(symidx);
  863. inc(localsyms);
  864. symtabsect.write(MaybeSwapElfSymbol(elfsym),sizeof(elfsym));
  865. end;
  866. procedure TElfObjectOutput.section_write_symbol(p:TObject;arg:pointer);
  867. begin
  868. TObjSection(p).secsymidx:=symidx;
  869. write_internal_symbol(TElfObjSection(p).shstridx,STT_SECTION,TElfObjSection(p).secshidx);
  870. end;
  871. procedure TElfObjectOutput.createsymtab(data: TObjData);
  872. procedure WriteSym(objsym:TObjSymbol);
  873. var
  874. elfsym : telfsymbol;
  875. begin
  876. fillchar(elfsym,sizeof(elfsym),0);
  877. { symbolname, write the #0 separate to overcome 255+1 char not possible }
  878. elfsym.st_name:=strtabsect.Size;
  879. strtabsect.writestr(objsym.name);
  880. strtabsect.writestr(#0);
  881. elfsym.st_size:=objsym.size;
  882. case objsym.bind of
  883. AB_LOCAL :
  884. begin
  885. elfsym.st_value:=objsym.address;
  886. elfsym.st_info:=STB_LOCAL shl 4;
  887. inc(localsyms);
  888. end;
  889. AB_COMMON :
  890. begin
  891. elfsym.st_value:=$10;
  892. elfsym.st_info:=STB_GLOBAL shl 4;
  893. end;
  894. AB_EXTERNAL :
  895. elfsym.st_info:=STB_GLOBAL shl 4;
  896. AB_WEAK_EXTERNAL :
  897. elfsym.st_info:=STB_WEAK shl 4;
  898. AB_GLOBAL :
  899. begin
  900. elfsym.st_value:=objsym.address;
  901. elfsym.st_info:=STB_GLOBAL shl 4;
  902. end;
  903. end;
  904. if (objsym.bind<>AB_EXTERNAL) {and
  905. not(assigned(objsym.objsection) and
  906. not(oso_data in objsym.objsection.secoptions))} then
  907. begin
  908. case objsym.typ of
  909. AT_FUNCTION :
  910. elfsym.st_info:=elfsym.st_info or STT_FUNC;
  911. AT_DATA :
  912. elfsym.st_info:=elfsym.st_info or STT_OBJECT;
  913. end;
  914. end;
  915. if objsym.bind=AB_COMMON then
  916. elfsym.st_shndx:=SHN_COMMON
  917. else
  918. begin
  919. if assigned(objsym.objsection) then
  920. elfsym.st_shndx:=TElfObjSection(objsym.objsection).secshidx
  921. else
  922. elfsym.st_shndx:=SHN_UNDEF;
  923. end;
  924. objsym.symidx:=symidx;
  925. inc(symidx);
  926. symtabsect.write(MaybeSwapElfSymbol(elfsym),sizeof(elfsym));
  927. end;
  928. var
  929. i : longint;
  930. objsym : TObjSymbol;
  931. begin
  932. with data do
  933. begin
  934. symidx:=0;
  935. localsyms:=0;
  936. { empty entry }
  937. write_internal_symbol(0,0,0);
  938. { filename entry }
  939. write_internal_symbol(1,STT_FILE,SHN_ABS);
  940. { section }
  941. ObjSectionList.ForEachCall(@section_write_symbol,nil);
  942. { First the Local Symbols, this is required by ELF. The localsyms
  943. count stored in shinfo is used to skip the local symbols
  944. when traversing the symtab }
  945. for i:=0 to ObjSymbolList.Count-1 do
  946. begin
  947. objsym:=TObjSymbol(ObjSymbolList[i]);
  948. if (objsym.bind=AB_LOCAL) and (objsym.typ<>AT_LABEL) then
  949. WriteSym(objsym);
  950. end;
  951. { Global Symbols }
  952. for i:=0 to ObjSymbolList.Count-1 do
  953. begin
  954. objsym:=TObjSymbol(ObjSymbolList[i]);
  955. if (objsym.bind<>AB_LOCAL) then
  956. WriteSym(objsym);
  957. end;
  958. { update the .symtab section header }
  959. symtabsect.shlink:=strtabsect.secshidx;
  960. symtabsect.shinfo:=localsyms;
  961. end;
  962. end;
  963. procedure TElfObjectOutput.section_write_sh_string(p:TObject;arg:pointer);
  964. begin
  965. TElfObjSection(p).shstridx:=shstrtabsect.writestr(TObjSection(p).name+#0);
  966. end;
  967. procedure TElfObjectOutput.createshstrtab(data: TObjData);
  968. begin
  969. with data do
  970. begin
  971. shstrtabsect.writestr(#0);
  972. ObjSectionList.ForEachCall(@section_write_sh_string,nil);
  973. end;
  974. end;
  975. procedure TElfObjectOutput.writesectionheader(s:TElfObjSection);
  976. var
  977. sechdr : telfsechdr;
  978. begin
  979. fillchar(sechdr,sizeof(sechdr),0);
  980. sechdr.sh_name:=s.shstridx;
  981. sechdr.sh_type:=s.shtype;
  982. sechdr.sh_flags:=s.shflags;
  983. sechdr.sh_offset:=s.datapos;
  984. sechdr.sh_size:=s.Size;
  985. sechdr.sh_link:=s.shlink;
  986. sechdr.sh_info:=s.shinfo;
  987. sechdr.sh_addralign:=s.secalign;
  988. sechdr.sh_entsize:=s.shentsize;
  989. writer.write(MaybeSwapSecHeader(sechdr),sizeof(sechdr));
  990. end;
  991. procedure TElfObjectOutput.writesectiondata(s:TElfObjSection);
  992. begin
  993. FWriter.writezeros(s.dataalignbytes);
  994. if s.Datapos<>FWriter.ObjSize then
  995. internalerror(200604031);
  996. FWriter.writearray(s.data);
  997. end;
  998. procedure TElfObjectOutput.section_count_sections(p:TObject;arg:pointer);
  999. begin
  1000. TElfObjSection(p).secshidx:=pword(arg)^;
  1001. inc(pword(arg)^);
  1002. end;
  1003. procedure TElfObjectOutput.section_create_relocsec(p:TObject;arg:pointer);
  1004. begin
  1005. if (TElfObjSection(p).ObjRelocations.count>0) then
  1006. createrelocsection(TElfObjSection(p),TObjData(arg));
  1007. end;
  1008. procedure TElfObjectOutput.section_set_datapos(p:TObject;arg:pointer);
  1009. begin
  1010. TObjSection(p).setdatapos(paword(arg)^);
  1011. end;
  1012. procedure TElfObjectOutput.section_write_data(p:TObject;arg:pointer);
  1013. begin
  1014. if (oso_data in TObjSection(p).secoptions) then
  1015. begin
  1016. if TObjSection(p).data=nil then
  1017. internalerror(200403073);
  1018. writesectiondata(TElfObjSection(p));
  1019. end;
  1020. end;
  1021. procedure TElfObjectOutput.section_write_sechdr(p:TObject;arg:pointer);
  1022. begin
  1023. writesectionheader(TElfObjSection(p));
  1024. end;
  1025. function TElfObjectOutput.writedata(data:TObjData):boolean;
  1026. var
  1027. header : telfheader;
  1028. shoffset,
  1029. datapos : aint;
  1030. nsections : word;
  1031. begin
  1032. result:=false;
  1033. with data do
  1034. begin
  1035. { default sections }
  1036. symtabsect:=TElfObjSection.create_ext(ObjSectionList,'.symtab',SHT_SYMTAB,0,0,0,4,sizeof(telfsymbol));
  1037. strtabsect:=TElfObjSection.create_ext(ObjSectionList,'.strtab',SHT_STRTAB,0,0,0,1,0);
  1038. shstrtabsect:=TElfObjSection.create_ext(ObjSectionList,'.shstrtab',SHT_STRTAB,0,0,0,1,0);
  1039. { "no executable stack" marker for Linux }
  1040. if (target_info.system in systems_linux) and
  1041. not(cs_executable_stack in current_settings.moduleswitches) then
  1042. TElfObjSection.create_ext(ObjSectionList,'.note.GNU-stack',SHT_PROGBITS,0,0,0,1,0);
  1043. { insert the empty and filename as first in strtab }
  1044. strtabsect.writestr(#0);
  1045. strtabsect.writestr(ExtractFileName(current_module.mainsource)+#0);
  1046. { calc amount of sections we have }
  1047. nsections:=1;
  1048. { also create the index in the section header table }
  1049. ObjSectionList.ForEachCall(@section_count_sections,@nsections);
  1050. { create .symtab and .strtab }
  1051. createsymtab(data);
  1052. { Create the relocation sections, this needs valid secidx and symidx }
  1053. ObjSectionList.ForEachCall(@section_create_relocsec,data);
  1054. { recalc nsections to incude the reloc sections }
  1055. nsections:=1;
  1056. ObjSectionList.ForEachCall(@section_count_sections,@nsections);
  1057. { create .shstrtab }
  1058. createshstrtab(data);
  1059. { Calculate the filepositions }
  1060. datapos:=$40; { elfheader + alignment }
  1061. { section data }
  1062. ObjSectionList.ForEachCall(@section_set_datapos,@datapos);
  1063. { section headers }
  1064. shoffset:=datapos;
  1065. inc(datapos,(nsections+1)*sizeof(telfsechdr));
  1066. { Write ELF Header }
  1067. fillchar(header,sizeof(header),0);
  1068. header.magic0123:=$464c457f; { = #127'ELF' }
  1069. {$ifdef cpu64bitaddr}
  1070. header.file_class:=2;
  1071. {$else cpu64bitaddr}
  1072. header.file_class:=1;
  1073. {$endif cpu64bitaddr}
  1074. if target_info.endian=endian_big then
  1075. header.data_encoding:=2
  1076. else
  1077. header.data_encoding:=1;
  1078. header.file_version:=1;
  1079. header.e_type:=1;
  1080. {$ifdef sparc}
  1081. header.e_machine:=2;
  1082. {$endif sparc}
  1083. {$ifdef i386}
  1084. header.e_machine:=3;
  1085. {$endif i386}
  1086. {$ifdef m68k}
  1087. header.e_machine:=4;
  1088. {$endif m68k}
  1089. {$ifdef powerpc}
  1090. header.e_machine:=20;
  1091. {$endif powerpc}
  1092. {$ifdef arm}
  1093. header.e_machine:=40;
  1094. if (current_settings.fputype=cpu_soft) then
  1095. header.e_flags:=$600;
  1096. {$endif arm}
  1097. {$ifdef x86_64}
  1098. header.e_machine:=62;
  1099. {$endif x86_64}
  1100. header.e_version:=1;
  1101. header.e_shoff:=shoffset;
  1102. header.e_shstrndx:=shstrtabsect.secshidx;
  1103. header.e_shnum:=nsections;
  1104. header.e_ehsize:=sizeof(telfheader);
  1105. header.e_shentsize:=sizeof(telfsechdr);
  1106. writer.write(MaybeSwapHeader(header),sizeof(header));
  1107. writer.writezeros($40-sizeof(header)); { align }
  1108. { Sections }
  1109. ObjSectionList.ForEachCall(@section_write_data,nil);
  1110. { section headers, start with an empty header for sh_undef }
  1111. writer.writezeros(sizeof(telfsechdr));
  1112. ObjSectionList.ForEachCall(@section_write_sechdr,nil);
  1113. end;
  1114. result:=true;
  1115. end;
  1116. {****************************************************************************
  1117. TELFAssembler
  1118. ****************************************************************************}
  1119. constructor TElfAssembler.Create(smart:boolean);
  1120. begin
  1121. inherited Create(smart);
  1122. CObjOutput:=TElfObjectOutput;
  1123. end;
  1124. {*****************************************************************************
  1125. Initialize
  1126. *****************************************************************************}
  1127. {$ifdef i386}
  1128. const
  1129. as_i386_elf32_info : tasminfo =
  1130. (
  1131. id : as_i386_elf32;
  1132. idtxt : 'ELF';
  1133. asmbin : '';
  1134. asmcmd : '';
  1135. supported_targets : [system_i386_linux,system_i386_beos,
  1136. system_i386_freebsd,system_i386_haiku,
  1137. system_i386_openbsd,system_i386_netbsd,
  1138. system_i386_Netware,system_i386_netwlibc,
  1139. system_i386_solaris,system_i386_embedded];
  1140. flags : [af_outputbinary,af_smartlink_sections,af_supports_dwarf];
  1141. labelprefix : '.L';
  1142. comment : '';
  1143. dollarsign: '$';
  1144. );
  1145. {$endif i386}
  1146. {$ifdef x86_64}
  1147. const
  1148. as_x86_64_elf64_info : tasminfo =
  1149. (
  1150. id : as_x86_64_elf64;
  1151. idtxt : 'ELF';
  1152. asmbin : '';
  1153. asmcmd : '';
  1154. supported_targets : [system_x86_64_linux,system_x86_64_freebsd,
  1155. system_x86_64_openbsd,system_x86_64_netbsd];
  1156. flags : [af_outputbinary,af_smartlink_sections,af_supports_dwarf];
  1157. labelprefix : '.L';
  1158. comment : '';
  1159. dollarsign: '$';
  1160. );
  1161. {$endif x86_64}
  1162. {$ifdef sparc}
  1163. const
  1164. as_sparc_elf32_info : tasminfo =
  1165. (
  1166. id : as_sparc_elf32;
  1167. idtxt : 'ELF';
  1168. asmbin : '';
  1169. asmcmd : '';
  1170. supported_targets : [];
  1171. // flags : [af_outputbinary,af_smartlink_sections];
  1172. flags : [af_outputbinary,af_supports_dwarf];
  1173. labelprefix : '.L';
  1174. comment : '';
  1175. dollarsign: '$';
  1176. );
  1177. {$endif sparc}
  1178. initialization
  1179. {$ifdef i386}
  1180. RegisterAssembler(as_i386_elf32_info,TElfAssembler);
  1181. {$endif i386}
  1182. {$ifdef sparc}
  1183. RegisterAssembler(as_sparc_elf32_info,TElfAssembler);
  1184. {$endif sparc}
  1185. {$ifdef x86_64}
  1186. RegisterAssembler(as_x86_64_elf64_info,TElfAssembler);
  1187. {$endif x86_64}
  1188. end.