ogcoff.pas 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Peter Vreman and Pierre Muller
  4. Contains the binary coff reader and writer
  5. * This code was inspired by the NASM sources
  6. The Netwide Assembler is copyright (C) 1996 Simon Tatham and
  7. Julian Hall. All rights reserved.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. ****************************************************************************
  20. }
  21. unit ogcoff;
  22. {$i fpcdefs.inc}
  23. interface
  24. uses
  25. { common }
  26. cclasses,
  27. { target }
  28. systems,
  29. { assembler }
  30. cpubase,aasmbase,assemble,link,
  31. { output }
  32. ogbase,ogmap;
  33. type
  34. TCoffObjectSection = class(TAsmSection)
  35. private
  36. orgmempos,
  37. coffrelocs,
  38. coffrelocpos : longint;
  39. public
  40. constructor createsec(sec:TSection;AAlign,AFlags:cardinal);
  41. procedure addsymsizereloc(ofs:longint;p:tasmsymbol;size:longint;relative:TAsmRelocationType);
  42. end;
  43. tcoffobjectdata = class(TAsmObjectData)
  44. private
  45. win32 : boolean;
  46. procedure reset;
  47. public
  48. constructor createdjgpp(const n:string);
  49. constructor createwin32(const n:string);
  50. destructor destroy;override;
  51. procedure seTSectionsizes(var s:TAsmSectionSizes);override;
  52. procedure createsection(sec:TSection);override;
  53. procedure writereloc(data,len:longint;p:tasmsymbol;relative:TAsmRelocationType);override;
  54. procedure writesymbol(p:tasmsymbol);override;
  55. procedure writestabs(section:TSection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);override;
  56. procedure writesymstabs(section:TSection;offset:longint;p:pchar;ps:tasmsymbol;nidx,nother,line:longint;reloc:boolean);override;
  57. procedure fixuprelocs;override;
  58. end;
  59. tcoffobjectoutput = class(tobjectoutput)
  60. private
  61. win32 : boolean;
  62. initsym : longint;
  63. FCoffStrs : tdynamicarray;
  64. procedure write_symbol(const name:string;strpos,value,section,typ,aux:longint);
  65. procedure write_symbols(data:TAsmObjectData);
  66. procedure write_relocs(data:TAsmObjectData);
  67. protected
  68. function writedata(data:TAsmObjectData):boolean;override;
  69. public
  70. constructor createdjgpp(smart:boolean);
  71. constructor createwin32(smart:boolean);
  72. function newobjectdata(const n:string):TAsmObjectData;override;
  73. end;
  74. tcoffexeoutput = class(texeoutput)
  75. private
  76. FCoffsyms,
  77. FCoffStrs : tdynamicarray;
  78. win32 : boolean;
  79. nsects,
  80. nsyms,
  81. sympos : longint;
  82. procedure write_symbol(const name:string;strpos,value,section,typ,aux:longint);
  83. procedure write_symbols;
  84. protected
  85. function writedata:boolean;override;
  86. public
  87. constructor createdjgpp;
  88. constructor createwin32;
  89. function newobjectinput:tobjectinput;override;
  90. procedure CalculateMemoryMap;override;
  91. procedure GenerateExecutable(const fn:string);override;
  92. end;
  93. ttasmsymbolrec = record
  94. sym : tasmsymbol;
  95. orgsize : longint;
  96. end;
  97. ttasmsymbolarray = array[0..high(word)] of ttasmsymbolrec;
  98. tcoffobjectinput = class(tobjectinput)
  99. private
  100. Fidx2sec : array[0..255] of TSection;
  101. FCoffsyms,
  102. FCoffStrs : tdynamicarray;
  103. FSymTbl : ^ttasmsymbolarray;
  104. win32 : boolean;
  105. procedure read_relocs(s:TCoffObjectSection);
  106. procedure handle_symbols(data:TAsmObjectData);
  107. protected
  108. function readobjectdata(data:TAsmObjectData):boolean;override;
  109. public
  110. constructor createdjgpp;
  111. constructor createwin32;
  112. function newobjectdata(const n:string):TAsmObjectData;override;
  113. end;
  114. tcoffassembler = class(tinternalassembler)
  115. constructor create(smart:boolean);override;
  116. end;
  117. tpecoffassembler = class(tinternalassembler)
  118. constructor create(smart:boolean);override;
  119. end;
  120. tcofflinker = class(tinternallinker)
  121. constructor create;override;
  122. end;
  123. implementation
  124. uses
  125. {$ifdef delphi}
  126. sysutils,
  127. {$else}
  128. strings,
  129. {$endif}
  130. cutils,verbose,
  131. globtype,globals,fmodule;
  132. const
  133. COFF_FLAG_NORELOCS = $0001;
  134. COFF_FLAG_EXE = $0002;
  135. COFF_FLAG_NOLINES = $0004;
  136. COFF_FLAG_NOLSYMS = $0008;
  137. COFF_FLAG_AR16WR = $0080; { 16bit little endian }
  138. COFF_FLAG_AR32WR = $0100; { 32bit little endian }
  139. COFF_FLAG_AR32W = $0200; { 32bit big endian }
  140. COFF_FLAG_DLL = $2000;
  141. COFF_SYM_GLOBAL = 2;
  142. COFF_SYM_LOCAL = 3;
  143. COFF_SYM_LABEL = 6;
  144. COFF_SYM_FUNCTION = 101;
  145. COFF_SYM_FILE = 103;
  146. COFF_SYM_SECTION = 104;
  147. type
  148. { Structures which are written directly to the output file }
  149. coffheader=packed record
  150. mach : word;
  151. nsects : word;
  152. time : longint;
  153. sympos : longint;
  154. syms : longint;
  155. opthdr : word;
  156. flag : word;
  157. end;
  158. coffoptheader=packed record
  159. magic : word;
  160. vstamp : word;
  161. tsize : longint;
  162. dsize : longint;
  163. bsize : longint;
  164. entry : longint;
  165. text_start : longint;
  166. data_start : longint;
  167. end;
  168. coffsechdr=packed record
  169. name : array[0..7] of char;
  170. vsize : longint;
  171. rvaofs : longint;
  172. datasize : longint;
  173. datapos : longint;
  174. relocpos : longint;
  175. lineno1 : longint;
  176. nrelocs : word;
  177. lineno2 : word;
  178. flags : cardinal;
  179. end;
  180. coffsectionrec=packed record
  181. len : longint;
  182. nrelocs : word;
  183. empty : array[0..11] of char;
  184. end;
  185. coffreloc=packed record
  186. address : longint;
  187. sym : longint;
  188. relative : word;
  189. end;
  190. coffsymbol=packed record
  191. name : array[0..3] of char; { real is [0..7], which overlaps the strpos ! }
  192. strpos : longint;
  193. value : longint;
  194. section : smallint;
  195. empty : smallint;
  196. typ : byte;
  197. aux : byte;
  198. end;
  199. coffstab=packed record
  200. strpos : longint;
  201. ntype : byte;
  202. nother : byte;
  203. ndesc : word;
  204. nvalue : longint;
  205. end;
  206. const
  207. symbolresize = 200*sizeof(coffsymbol);
  208. strsresize = 8192;
  209. const go32v2stub : array[0..2047] of byte=(
  210. $4D,$5A,$00,$00,$04,$00,$00,$00,$20,$00,$27,$00,$FF,$FF,$00,
  211. $00,$60,$07,$00,$00,$54,$00,$00,$00,$00,$00,$00,$00,$0D,$0A,
  212. $73,$74,$75,$62,$2E,$68,$20,$67,$65,$6E,$65,$72,$61,$74,$65,
  213. $64,$20,$66,$72,$6F,$6D,$20,$73,$74,$75,$62,$2E,$61,$73,$6D,
  214. $20,$62,$79,$20,$64,$6A,$61,$73,$6D,$2C,$20,$6F,$6E,$20,$54,
  215. $68,$75,$20,$44,$65,$63,$20,$20,$39,$20,$31,$30,$3A,$35,$39,
  216. $3A,$33,$31,$20,$31,$39,$39,$39,$0D,$0A,$54,$68,$65,$20,$53,
  217. $54,$55,$42,$2E,$45,$58,$45,$20,$73,$74,$75,$62,$20,$6C,$6F,
  218. $61,$64,$65,$72,$20,$69,$73,$20,$43,$6F,$70,$79,$72,$69,$67,
  219. $68,$74,$20,$28,$43,$29,$20,$31,$39,$39,$33,$2D,$31,$39,$39,
  220. $35,$20,$44,$4A,$20,$44,$65,$6C,$6F,$72,$69,$65,$2E,$20,$0D,
  221. $0A,$50,$65,$72,$6D,$69,$73,$73,$69,$6F,$6E,$20,$67,$72,$61,
  222. $6E,$74,$65,$64,$20,$74,$6F,$20,$75,$73,$65,$20,$66,$6F,$72,
  223. $20,$61,$6E,$79,$20,$70,$75,$72,$70,$6F,$73,$65,$20,$70,$72,
  224. $6F,$76,$69,$64,$65,$64,$20,$74,$68,$69,$73,$20,$63,$6F,$70,
  225. $79,$72,$69,$67,$68,$74,$20,$0D,$0A,$72,$65,$6D,$61,$69,$6E,
  226. $73,$20,$70,$72,$65,$73,$65,$6E,$74,$20,$61,$6E,$64,$20,$75,
  227. $6E,$6D,$6F,$64,$69,$66,$69,$65,$64,$2E,$20,$0D,$0A,$54,$68,
  228. $69,$73,$20,$6F,$6E,$6C,$79,$20,$61,$70,$70,$6C,$69,$65,$73,
  229. $20,$74,$6F,$20,$74,$68,$65,$20,$73,$74,$75,$62,$2C,$20,$61,
  230. $6E,$64,$20,$6E,$6F,$74,$20,$6E,$65,$63,$65,$73,$73,$61,$72,
  231. $69,$6C,$79,$20,$74,$68,$65,$20,$77,$68,$6F,$6C,$65,$20,$70,
  232. $72,$6F,$67,$72,$61,$6D,$2E,$0A,$0D,$0A,$24,$49,$64,$3A,$20,
  233. $73,$74,$75,$62,$2E,$61,$73,$6D,$20,$62,$75,$69,$6C,$74,$20,
  234. $31,$32,$2F,$30,$39,$2F,$39,$39,$20,$31,$30,$3A,$35,$39,$3A,
  235. $33,$31,$20,$62,$79,$20,$64,$6A,$61,$73,$6D,$20,$24,$0A,$0D,
  236. $0A,$40,$28,$23,$29,$20,$73,$74,$75,$62,$2E,$61,$73,$6D,$20,
  237. $62,$75,$69,$6C,$74,$20,$31,$32,$2F,$30,$39,$2F,$39,$39,$20,
  238. $31,$30,$3A,$35,$39,$3A,$33,$31,$20,$62,$79,$20,$64,$6A,$61,
  239. $73,$6D,$0A,$0D,$0A,$1A,$00,$00,$00,$00,$00,$00,$00,$00,$00,
  240. $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
  241. $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
  242. $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
  243. $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
  244. $00,$00,$67,$6F,$33,$32,$73,$74,$75,$62,$2C,$20,$76,$20,$32,
  245. $2E,$30,$32,$54,$00,$00,$00,$00,$00,$08,$00,$00,$00,$00,$00,
  246. $00,$00,$00,$00,$00,$40,$00,$00,$00,$00,$00,$00,$00,$00,$00,
  247. $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
  248. $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$43,$57,$53,$44,$50,
  249. $4D,$49,$2E,$45,$58,$45,$00,$00,$00,$00,$00,$0E,$1F,$8C,$1E,
  250. $24,$00,$8C,$06,$60,$07,$FC,$B4,$30,$CD,$21,$3C,$03,$73,$08,
  251. $B0,$6D,$BA,$A7,$05,$E9,$D4,$03,$A2,$69,$08,$BE,$20,$00,$8B,
  252. $04,$09,$C0,$75,$02,$B4,$FE,$BB,$70,$08,$39,$C3,$73,$02,$89,
  253. $C3,$89,$1C,$FE,$C7,$B9,$04,$FF,$D3,$EB,$B4,$4A,$CD,$21,$73,
  254. $08,$D3,$E3,$FE,$CF,$89,$1C,$EB,$D8,$26,$8E,$06,$2C,$00,$31,
  255. $FF,$30,$C0,$A9,$F2,$AE,$26,$81,$3D,$50,$41,$75,$15,$AF,$26,
  256. $81,$3D,$54,$48,$75,$0D,$AF,$26,$80,$3D,$3D,$75,$06,$47,$89,
  257. $3E,$8C,$04,$4F,$AE,$75,$DF,$AF,$B4,$3E,$BB,$13,$00,$CD,$21,
  258. $B4,$3E,$BB,$12,$00,$CD,$21,$06,$57,$31,$C9,$74,$12,$B0,$6E,
  259. $BA,$7E,$05,$E9,$5E,$03,$09,$C9,$75,$F4,$41,$E8,$A1,$03,$72,
  260. $EE,$B8,$87,$16,$CD,$2F,$09,$C0,$75,$ED,$80,$E3,$01,$74,$E8,
  261. $89,$3E,$00,$06,$8C,$06,$02,$06,$89,$36,$04,$06,$5F,$07,$E8,
  262. $D3,$02,$89,$3E,$2A,$00,$89,$36,$62,$07,$80,$3E,$2C,$00,$00,
  263. $74,$23,$B9,$08,$00,$BF,$2C,$00,$8A,$05,$47,$08,$C0,$74,$05,
  264. $88,$07,$43,$E2,$F4,$66,$C7,$07,$2E,$45,$58,$45,$83,$C3,$04,
  265. $C6,$07,$00,$89,$1E,$62,$07,$B8,$00,$3D,$BA,$64,$07,$CD,$21,
  266. $0F,$82,$B3,$02,$A3,$06,$06,$89,$C3,$B9,$06,$00,$BA,$B5,$07,
  267. $B4,$3F,$CD,$21,$31,$D2,$31,$C9,$A1,$B5,$07,$3D,$4C,$01,$74,
  268. $1B,$3D,$4D,$5A,$0F,$85,$98,$02,$8B,$16,$B9,$07,$C1,$E2,$09,
  269. $8B,$1E,$B7,$07,$09,$DB,$74,$05,$80,$EE,$02,$01,$DA,$89,$16,
  270. $BB,$07,$89,$0E,$BD,$07,$B8,$00,$42,$8B,$1E,$06,$06,$CD,$21,
  271. $B9,$A8,$00,$BA,$BF,$07,$B4,$3F,$CD,$21,$3D,$A8,$00,$75,$06,
  272. $81,$3E,$BF,$07,$4C,$01,$0F,$85,$61,$02,$66,$A1,$E3,$07,$66,
  273. $A3,$10,$06,$66,$8B,$0E,$BB,$07,$66,$A1,$03,$08,$66,$01,$C8,
  274. $66,$A3,$08,$06,$66,$A1,$2B,$08,$66,$01,$C8,$66,$A3,$0C,$06,
  275. $66,$8B,$1E,$4B,$08,$66,$A1,$4F,$08,$66,$01,$C3,$66,$B8,$01,
  276. $00,$01,$00,$66,$39,$C3,$73,$03,$66,$89,$C3,$66,$81,$C3,$FF,
  277. $FF,$00,$00,$31,$DB,$66,$89,$1E,$1C,$00,$E8,$F5,$02,$8B,$1E,
  278. $04,$06,$09,$DB,$74,$0A,$B4,$48,$CD,$21,$0F,$82,$15,$02,$8E,
  279. $C0,$E8,$08,$03,$B8,$01,$00,$FF,$1E,$00,$06,$0F,$82,$0F,$02,
  280. $8C,$06,$26,$00,$8C,$0E,$28,$00,$8C,$D8,$A3,$22,$00,$8E,$C0,
  281. $31,$C0,$B9,$01,$00,$CD,$31,$72,$07,$A3,$14,$06,$31,$C0,$CD,
  282. $31,$0F,$82,$F3,$01,$A3,$16,$06,$66,$8B,$0E,$1C,$00,$B8,$01,
  283. $05,$8B,$1E,$1E,$00,$CD,$31,$0F,$82,$E5,$01,$89,$1E,$1A,$06,
  284. $89,$0E,$18,$06,$89,$36,$1A,$00,$89,$3E,$18,$00,$B8,$07,$00,
  285. $8B,$1E,$14,$06,$8B,$0E,$1A,$06,$8B,$16,$18,$06,$CD,$31,$B8,
  286. $09,$00,$8C,$C9,$83,$E1,$03,$C1,$E1,$05,$51,$81,$C9,$9B,$C0,
  287. $CD,$31,$B8,$08,$00,$8B,$0E,$1E,$00,$49,$BA,$FF,$FF,$CD,$31,
  288. $B8,$07,$00,$8B,$1E,$16,$06,$8B,$0E,$1A,$06,$8B,$16,$18,$06,
  289. $CD,$31,$B8,$09,$00,$59,$81,$C9,$93,$C0,$CD,$31,$B8,$08,$00,
  290. $8B,$0E,$1E,$00,$49,$BA,$FF,$FF,$CD,$31,$B8,$00,$01,$BB,$00,
  291. $0F,$CD,$31,$73,$10,$3D,$08,$00,$0F,$85,$73,$01,$B8,$00,$01,
  292. $CD,$31,$0F,$82,$6A,$01,$A3,$1C,$06,$89,$16,$1E,$06,$C1,$E3,
  293. $04,$89,$1E,$20,$06,$66,$8B,$36,$08,$06,$66,$8B,$3E,$FB,$07,
  294. $66,$8B,$0E,$FF,$07,$E8,$49,$00,$66,$8B,$36,$0C,$06,$66,$8B,
  295. $3E,$23,$08,$66,$8B,$0E,$27,$08,$E8,$37,$00,$8E,$06,$16,$06,
  296. $66,$8B,$3E,$4B,$08,$66,$8B,$0E,$4F,$08,$66,$31,$C0,$66,$C1,
  297. $E9,$02,$67,$F3,$66,$AB,$B4,$3E,$8B,$1E,$06,$06,$CD,$21,$B8,
  298. $01,$01,$8B,$16,$1E,$06,$CD,$31,$1E,$0F,$A1,$8E,$1E,$16,$06,
  299. $66,$64,$FF,$2E,$10,$06,$66,$89,$F0,$66,$25,$FF,$01,$00,$00,
  300. $66,$01,$C1,$29,$C6,$66,$29,$C7,$66,$89,$0E,$26,$06,$66,$89,
  301. $3E,$22,$06,$E8,$0F,$01,$89,$36,$3E,$06,$66,$C1,$EE,$10,$89,
  302. $36,$42,$06,$8B,$1E,$06,$06,$89,$1E,$3A,$06,$C7,$06,$46,$06,
  303. $00,$42,$E8,$03,$01,$A1,$1C,$06,$A3,$4E,$06,$C7,$06,$3E,$06,
  304. $00,$00,$C6,$06,$47,$06,$3F,$A1,$28,$06,$09,$C0,$75,$09,$A1,
  305. $26,$06,$3B,$06,$20,$06,$76,$03,$A1,$20,$06,$A3,$42,$06,$E8,
  306. $D9,$00,$66,$31,$C9,$8B,$0E,$46,$06,$66,$8B,$3E,$22,$06,$66,
  307. $01,$0E,$22,$06,$66,$29,$0E,$26,$06,$66,$31,$F6,$C1,$E9,$02,
  308. $1E,$06,$8E,$06,$16,$06,$8E,$1E,$1E,$06,$67,$F3,$66,$A5,$07,
  309. $1F,$66,$03,$0E,$26,$06,$75,$AF,$C3,$3C,$3A,$74,$06,$3C,$2F,
  310. $74,$02,$3C,$5C,$C3,$BE,$64,$07,$89,$F3,$26,$8A,$05,$47,$88,
  311. $04,$38,$E0,$74,$0E,$08,$C0,$74,$0A,$46,$E8,$DE,$FF,$75,$EC,
  312. $89,$F3,$74,$E8,$C3,$B0,$66,$BA,$48,$05,$EB,$0C,$B0,$67,$BA,
  313. $55,$05,$EB,$05,$B0,$68,$BA,$5F,$05,$52,$8B,$1E,$62,$07,$C6,
  314. $07,$24,$BB,$64,$07,$EB,$28,$E8,$F5,$00,$B0,$69,$BA,$99,$05,
  315. $EB,$1A,$B0,$6A,$BA,$B2,$05,$EB,$13,$B0,$6B,$BA,$C4,$05,$EB,
  316. $0C,$B0,$6C,$BA,$D6,$05,$EB,$05,$B0,$69,$BA,$99,$05,$52,$BB,
  317. $3B,$05,$E8,$15,$00,$5B,$E8,$11,$00,$BB,$67,$04,$E8,$0B,$00,
  318. $B4,$4C,$CD,$21,$43,$50,$B4,$02,$CD,$21,$58,$8A,$17,$80,$FA,
  319. $24,$75,$F2,$C3,$0D,$0A,$24,$50,$51,$57,$31,$C0,$BF,$2A,$06,
  320. $B9,$19,$00,$F3,$AB,$5F,$59,$58,$C3,$B8,$00,$03,$BB,$21,$00,
  321. $31,$C9,$66,$BF,$2A,$06,$00,$00,$CD,$31,$C3,$00,$00,$30,$E4,
  322. $E8,$4E,$FF,$89,$DE,$8B,$3E,$8C,$04,$EB,$17,$B4,$3B,$E8,$41,
  323. $FF,$81,$FE,$64,$07,$74,$12,$8A,$44,$FF,$E8,$2A,$FF,$74,$04,
  324. $C6,$04,$5C,$46,$E8,$03,$00,$72,$E4,$C3,$E8,$34,$00,$BB,$44,
  325. $00,$8A,$07,$88,$04,$43,$46,$08,$C0,$75,$F6,$06,$57,$1E,$07,
  326. $E8,$9B,$FF,$BB,$2A,$06,$8C,$5F,$04,$89,$5F,$02,$BA,$64,$07,
  327. $B8,$00,$4B,$CD,$21,$5F,$07,$72,$09,$B4,$4D,$CD,$21,$2D,$00,
  328. $03,$F7,$D8,$EB,$28,$80,$3E,$69,$08,$05,$72,$20,$B8,$00,$58,
  329. $CD,$21,$A2,$67,$08,$B8,$02,$58,$CD,$21,$A2,$68,$08,$B8,$01,
  330. $58,$BB,$80,$00,$CD,$21,$B8,$03,$58,$BB,$01,$00,$CD,$21,$C3,
  331. $9C,$80,$3E,$69,$08,$05,$72,$1A,$50,$53,$B8,$03,$58,$8A,$1E,
  332. $68,$08,$30,$FF,$CD,$21,$B8,$01,$58,$8A,$1E,$67,$08,$30,$FF,
  333. $CD,$21,$5B,$58,$9D,$C3,$4C,$6F,$61,$64,$20,$65,$72,$72,$6F,
  334. $72,$3A,$20,$24,$3A,$20,$63,$61,$6E,$27,$74,$20,$6F,$70,$65,
  335. $6E,$24,$3A,$20,$6E,$6F,$74,$20,$45,$58,$45,$24,$3A,$20,$6E,
  336. $6F,$74,$20,$43,$4F,$46,$46,$20,$28,$43,$68,$65,$63,$6B,$20,
  337. $66,$6F,$72,$20,$76,$69,$72,$75,$73,$65,$73,$29,$24,$6E,$6F,
  338. $20,$44,$50,$4D,$49,$20,$2D,$20,$47,$65,$74,$20,$63,$73,$64,
  339. $70,$6D,$69,$2A,$62,$2E,$7A,$69,$70,$24,$6E,$6F,$20,$44,$4F,
  340. $53,$20,$6D,$65,$6D,$6F,$72,$79,$24,$6E,$65,$65,$64,$20,$44,
  341. $4F,$53,$20,$33,$24,$63,$61,$6E,$27,$74,$20,$73,$77,$69,$74,
  342. $63,$68,$20,$6D,$6F,$64,$65,$24,$6E,$6F,$20,$44,$50,$4D,$49,
  343. $20,$73,$65,$6C,$65,$63,$74,$6F,$72,$73,$24,$6E,$6F,$20,$44,
  344. $50,$4D,$49,$20,$6D,$65,$6D,$6F,$72,$79,$24,$90,$90,$90,$90,
  345. $90,$90,$90,$90,$90,$90,$90,$90,$90,$90,$90,$90,$90,$90,$90,
  346. $90,$90,$90,$90,$90,$90,$90,$90);
  347. {****************************************************************************
  348. TCoffObjectSection
  349. ****************************************************************************}
  350. constructor TCoffObjectSection.createsec(sec:TSection;AAlign,AFlags:cardinal);
  351. begin
  352. inherited create(target_asm.secnames[sec],AAlign,(sec=sec_bss));
  353. Flags:=AFlags;
  354. end;
  355. procedure TCoffObjectSection.addsymsizereloc(ofs:longint;p:tasmsymbol;size:longint;relative:TAsmRelocationType);
  356. begin
  357. relocations.concat(tasmrelocation.createsymbolsize(ofs,p,size,relative));
  358. end;
  359. {****************************************************************************
  360. tcoffobjectdata
  361. ****************************************************************************}
  362. constructor tcoffobjectdata.createdjgpp(const n:string);
  363. begin
  364. inherited create(n);
  365. win32:=false;
  366. reset;
  367. end;
  368. constructor tcoffobjectdata.createwin32(const n:string);
  369. begin
  370. inherited create(n);
  371. win32:=true;
  372. reset;
  373. end;
  374. destructor tcoffobjectdata.destroy;
  375. begin
  376. inherited destroy;
  377. end;
  378. procedure tcoffobjectdata.reset;
  379. var
  380. s : string;
  381. begin
  382. { we need at least the following 3 sections }
  383. createsection(sec_code);
  384. createsection(sec_data);
  385. createsection(sec_bss);
  386. if (cs_gdb_lineinfo in aktglobalswitches) or
  387. (cs_debuginfo in aktmoduleswitches) then
  388. begin
  389. createsection(sec_stab);
  390. createsection(sec_stabstr);
  391. writestabs(sec_none,0,nil,0,0,0,false);
  392. { write zero pchar and name together (PM) }
  393. s:=#0+SplitFileName(current_module.mainsource^)+#0;
  394. sects[sec_stabstr].write(s[1],length(s));
  395. end;
  396. end;
  397. procedure tcoffobjectdata.createsection(sec:TSection);
  398. var
  399. Flags,
  400. AAlign : cardinal;
  401. begin
  402. { defaults }
  403. Flags:=0;
  404. Aalign:=1;
  405. { alignment after section }
  406. case sec of
  407. sec_code :
  408. begin
  409. if win32 then
  410. Flags:=$60000020
  411. else
  412. Flags:=$20;
  413. Aalign:=16;
  414. end;
  415. sec_data :
  416. begin
  417. if win32 then
  418. Flags:=$c0300040
  419. else
  420. Flags:=$40;
  421. Aalign:=16;
  422. end;
  423. sec_bss :
  424. begin
  425. if win32 then
  426. Flags:=$c0300080
  427. else
  428. Flags:=$80;
  429. Aalign:=16;
  430. end;
  431. sec_idata2,
  432. sec_idata4,
  433. sec_idata5,
  434. sec_idata6,
  435. sec_idata7 :
  436. begin
  437. if win32 then
  438. Flags:=$40000000;
  439. end;
  440. sec_edata :
  441. begin
  442. if win32 then
  443. Flags:=$c0300040;
  444. end;
  445. end;
  446. sects[sec]:=TCoffObjectSection.createsec(Sec,AAlign,Flags);
  447. end;
  448. procedure tcoffobjectdata.writesymbol(p:tasmsymbol);
  449. begin
  450. { already written ? }
  451. if p.indexnr<>-1 then
  452. exit;
  453. { be sure that the section will exists }
  454. if (p.section<>sec_none) and not(assigned(sects[p.section])) then
  455. createsection(p.section);
  456. { calculate symbol index }
  457. if (p.currbind<>AB_LOCAL) then
  458. begin
  459. { insert the symbol in the local index, the indexarray
  460. will take care of the numbering }
  461. symbols.insert(p);
  462. end
  463. else
  464. p.indexnr:=-2; { local }
  465. end;
  466. procedure tcoffobjectdata.writereloc(data,len:longint;p:tasmsymbol;relative:TAsmRelocationType);
  467. var
  468. curraddr,
  469. symaddr : longint;
  470. begin
  471. if not assigned(sects[currsec]) then
  472. createsection(currsec);
  473. if assigned(p) then
  474. begin
  475. { current address }
  476. curraddr:=sects[currsec].mempos+sects[currsec].datasize;
  477. { real address of the symbol }
  478. symaddr:=p.address;
  479. if p.section<>sec_none then
  480. inc(symaddr,sects[p.section].mempos);
  481. { no symbol relocation need inside a section }
  482. if p.section=currsec then
  483. begin
  484. case relative of
  485. RELOC_ABSOLUTE :
  486. begin
  487. sects[currsec].addsectionreloc(curraddr,currsec,RELOC_ABSOLUTE);
  488. inc(data,symaddr);
  489. end;
  490. RELOC_RELATIVE :
  491. begin
  492. inc(data,symaddr-len-sects[currsec].datasize);
  493. end;
  494. RELOC_RVA :
  495. begin
  496. sects[currsec].addsectionreloc(curraddr,currsec,RELOC_RVA);
  497. inc(data,symaddr);
  498. end;
  499. end;
  500. end
  501. else
  502. begin
  503. writesymbol(p);
  504. if (p.section<>sec_none) and (relative<>RELOC_RELATIVE) then
  505. sects[currsec].addsectionreloc(curraddr,p.section,relative)
  506. else
  507. sects[currsec].addsymreloc(curraddr,p,relative);
  508. if not win32 then {seems wrong to me (PM) }
  509. inc(data,symaddr)
  510. else
  511. if (relative<>RELOC_RELATIVE) and (p.section<>sec_none) then
  512. inc(data,symaddr);
  513. if relative=RELOC_RELATIVE then
  514. begin
  515. if win32 then
  516. dec(data,len-4)
  517. else
  518. dec(data,len+sects[currsec].datasize);
  519. end;
  520. end;
  521. end;
  522. sects[currsec].write(data,len);
  523. end;
  524. procedure tcoffobjectdata.writestabs(section:TSection;offset:longint;p:pchar;nidx,nother,line:longint;reloc : boolean);
  525. var
  526. stab : coffstab;
  527. s : TSection;
  528. curraddr : longint;
  529. begin
  530. s:=section;
  531. { local var can be at offset -1 !! PM }
  532. if reloc then
  533. begin
  534. if (offset=-1) then
  535. begin
  536. if s=sec_none then
  537. offset:=0
  538. else
  539. offset:=sects[s].datasize;
  540. end;
  541. if (s<>sec_none) then
  542. inc(offset,sects[s].datapos);
  543. end;
  544. if assigned(p) and (p[0]<>#0) then
  545. begin
  546. stab.strpos:=sects[sec_stabstr].datasize;
  547. sects[sec_stabstr].write(p^,strlen(p)+1);
  548. end
  549. else
  550. stab.strpos:=0;
  551. stab.ntype:=nidx;
  552. stab.ndesc:=line;
  553. stab.nother:=nother;
  554. stab.nvalue:=offset;
  555. sects[sec_stab].write(stab,sizeof(stab));
  556. { when the offset is not 0 then write a relocation, take also the
  557. hdrstab into account with the offset }
  558. if reloc then
  559. begin
  560. { current address }
  561. curraddr:=sects[sec_stab].mempos+sects[sec_stab].datasize;
  562. if DLLSource and RelocSection then
  563. { avoid relocation in the .stab section
  564. because it ends up in the .reloc section instead }
  565. sects[sec_stab].addsectionreloc(curraddr-4,s,RELOC_RVA)
  566. else
  567. sects[sec_stab].addsectionreloc(curraddr-4,s,RELOC_ABSOLUTE);
  568. end;
  569. end;
  570. procedure tcoffobjectdata.writesymstabs(section:TSection;offset:longint;p:pchar;ps:tasmsymbol;
  571. nidx,nother,line:longint;reloc:boolean);
  572. var
  573. stab : coffstab;
  574. curraddr : longint;
  575. begin
  576. { do not use the size stored in offset field
  577. this is DJGPP specific ! PM }
  578. if win32 then
  579. offset:=0;
  580. { local var can be at offset -1 !! PM }
  581. if reloc then
  582. begin
  583. if (offset=-1) then
  584. begin
  585. if section=sec_none then
  586. offset:=0
  587. else
  588. offset:=sects[section].datasize;
  589. end;
  590. if (section<>sec_none) then
  591. inc(offset,sects[section].mempos);
  592. end;
  593. if assigned(p) and (p[0]<>#0) then
  594. begin
  595. stab.strpos:=sects[sec_stabstr].datasize;
  596. sects[sec_stabstr].write(p^,strlen(p)+1);
  597. end
  598. else
  599. stab.strpos:=0;
  600. stab.ntype:=nidx;
  601. stab.ndesc:=line;
  602. stab.nother:=nother;
  603. stab.nvalue:=offset;
  604. sects[sec_stab].write(stab,sizeof(stab));
  605. { when the offset is not 0 then write a relocation, take also the
  606. hdrstab into account with the offset }
  607. if reloc then
  608. begin
  609. { current address }
  610. curraddr:=sects[sec_stab].mempos+sects[sec_stab].datasize;
  611. if DLLSource and RelocSection then
  612. { avoid relocation in the .stab section
  613. because it ends up in the .reloc section instead }
  614. sects[sec_stab].addsymreloc(curraddr-4,ps,RELOC_RVA)
  615. else
  616. sects[sec_stab].addsymreloc(curraddr-4,ps,RELOC_ABSOLUTE);
  617. end;
  618. end;
  619. procedure tcoffobjectdata.seTSectionsizes(var s:TAsmSectionSizes);
  620. var
  621. mempos : longint;
  622. sec : TSection;
  623. begin
  624. { multiply stab with real size }
  625. s[sec_stab]:=s[sec_stab]*sizeof(coffstab);
  626. { if debug then also count header stab }
  627. if (cs_debuginfo in aktmoduleswitches) then
  628. begin
  629. inc(s[sec_stab],sizeof(coffstab));
  630. inc(s[sec_stabstr],length(SplitFileName(current_module.mainsource^))+2);
  631. end;
  632. { calc mempos }
  633. mempos:=0;
  634. for sec:=low(TSection) to high(TSection) do
  635. begin
  636. if (s[sec]>0) and
  637. (not assigned(sects[sec])) then
  638. createsection(sec);
  639. if assigned(sects[sec]) then
  640. begin
  641. sects[sec].memsize:=s[sec];
  642. { memory position }
  643. if not win32 then
  644. begin
  645. sects[sec].mempos:=mempos;
  646. inc(mempos,align(sects[sec].memsize,sects[sec].addralign));
  647. end;
  648. end;
  649. end;
  650. end;
  651. procedure tcoffobjectdata.fixuprelocs;
  652. var
  653. r : TAsmRelocation;
  654. address,i,
  655. relocval : longint;
  656. sec : TSection;
  657. begin
  658. for sec:=low(TSection) to high(TSection) do
  659. if assigned(sects[sec]) then
  660. begin
  661. r:=TAsmRelocation(sects[sec].relocations.first);
  662. if assigned(r) and
  663. (not assigned(sects[sec].data)) then
  664. internalerror(200205183);
  665. while assigned(r) do
  666. begin
  667. if assigned(r.symbol) then
  668. relocval:=r.symbol.address
  669. else
  670. internalerror(200205183);
  671. sects[sec].data.Seek(r.address);
  672. sects[sec].data.Read(address,4);
  673. case r.typ of
  674. RELOC_RELATIVE :
  675. begin
  676. dec(address,sects[sec].mempos);
  677. inc(address,relocval);
  678. end;
  679. RELOC_RVA,
  680. RELOC_ABSOLUTE :
  681. begin
  682. if r.symbol.section=sec_common then
  683. dec(address,r.orgsize)
  684. else
  685. begin
  686. { fixup address when the symbol was known in defined object }
  687. if (r.symbol.section<>sec_none) and
  688. (r.symbol.objectdata=pointer(self)) then
  689. dec(address,TCoffObjectSection(sects[r.symbol.section]).orgmempos);
  690. end;
  691. inc(address,relocval);
  692. end;
  693. end;
  694. sects[sec].data.Seek(r.address);
  695. sects[sec].data.Write(address,4);
  696. { goto next reloc }
  697. r:=TAsmRelocation(r.next);
  698. end;
  699. end;
  700. end;
  701. {****************************************************************************
  702. tcoffobjectoutput
  703. ****************************************************************************}
  704. constructor tcoffobjectoutput.createdjgpp(smart:boolean);
  705. begin
  706. inherited create(smart);
  707. win32:=false;
  708. end;
  709. constructor tcoffobjectoutput.createwin32(smart:boolean);
  710. begin
  711. inherited create(smart);
  712. win32:=true;
  713. end;
  714. function tcoffobjectoutput.newobjectdata(const n:string):TAsmObjectData;
  715. begin
  716. if win32 then
  717. result:=tcoffobjectdata.createwin32(n)
  718. else
  719. result:=tcoffobjectdata.createdjgpp(n);
  720. end;
  721. procedure tcoffobjectoutput.write_symbol(const name:string;strpos,value,section,typ,aux:longint);
  722. var
  723. sym : coffsymbol;
  724. begin
  725. FillChar(sym,sizeof(sym),0);
  726. if strpos=-1 then
  727. move(name[1],sym.name,length(name))
  728. else
  729. sym.strpos:=strpos;
  730. sym.value:=value;
  731. sym.section:=section;
  732. sym.typ:=typ;
  733. sym.aux:=aux;
  734. FWriter.write(sym,sizeof(sym));
  735. end;
  736. procedure tcoffobjectoutput.write_symbols(data:TAsmObjectData);
  737. var
  738. filename : string[18];
  739. sec : TSection;
  740. namestr : string[8];
  741. nameidx,
  742. value,
  743. sectionval,
  744. i : longint;
  745. globalval : byte;
  746. secrec : coffsectionrec;
  747. p : tasmsymbol;
  748. s : string;
  749. begin
  750. with tcoffobjectdata(data) do
  751. begin
  752. { The `.file' record, and the file name auxiliary record }
  753. write_symbol('.file', -1, 0, -2, $67, 1);
  754. fillchar(filename,sizeof(filename),0);
  755. filename:=SplitFileName(current_module.mainsource^);
  756. FWriter.write(filename[1],sizeof(filename)-1);
  757. { The section records, with their auxiliaries, also store the
  758. symbol index }
  759. for sec:=low(TSection) to high(TSection) do
  760. if assigned(sects[sec]) then
  761. begin
  762. write_symbol(target_asm.secnames[sec],-1,sects[sec].mempos,sects[sec].secsymidx,3,1);
  763. fillchar(secrec,sizeof(secrec),0);
  764. secrec.len:=sects[sec].aligneddatasize;
  765. secrec.nrelocs:=sects[sec].relocations.count;
  766. FWriter.write(secrec,sizeof(secrec));
  767. end;
  768. { The symbols used }
  769. p:=Tasmsymbol(symbols.First);
  770. while assigned(p) do
  771. begin
  772. if assigned(sects[p.section]) then
  773. sectionval:=sects[p.section].secsymidx
  774. else
  775. sectionval:=0;
  776. if p.currbind=AB_LOCAL then
  777. globalval:=3
  778. else
  779. globalval:=2;
  780. { if local of global then set the section value to the address
  781. of the symbol }
  782. if p.currbind in [AB_LOCAL,AB_GLOBAL] then
  783. value:=p.address+sects[p.section].mempos
  784. else
  785. value:=p.size;
  786. { symbolname }
  787. s:=p.name;
  788. if length(s)>8 then
  789. begin
  790. nameidx:=FCoffStrs.size+4;
  791. FCoffStrs.writestr(s);
  792. FCoffStrs.writestr(#0);
  793. end
  794. else
  795. begin
  796. nameidx:=-1;
  797. namestr:=s;
  798. end;
  799. write_symbol(namestr,nameidx,value,sectionval,globalval,0);
  800. p:=tasmsymbol(p.indexnext);
  801. end;
  802. end;
  803. end;
  804. procedure tcoffobjectoutput.write_relocs(data:TAsmObjectData);
  805. var
  806. rel : coffreloc;
  807. r : TAsmRelocation;
  808. sec : TSection;
  809. begin
  810. with data do
  811. begin
  812. for sec:=low(TSection) to high(TSection) do
  813. if assigned(sects[sec]) then
  814. begin
  815. r:=TasmRelocation(sects[sec].relocations.first);
  816. while assigned(r) do
  817. begin
  818. rel.address:=r.address;
  819. if assigned(r.symbol) then
  820. begin
  821. if (r.symbol.currbind=AB_LOCAL) then
  822. rel.sym:=2*sects[r.symbol.section].secsymidx
  823. else
  824. begin
  825. if r.symbol.indexnr=-1 then
  826. internalerror(4321);
  827. { indexnr starts with 1, coff starts with 0 }
  828. rel.sym:=r.symbol.indexnr+initsym-1;
  829. end;
  830. end
  831. else
  832. begin
  833. if r.section<>sec_none then
  834. rel.sym:=2*sects[r.section].secsymidx
  835. else
  836. rel.sym:=0;
  837. end;
  838. case r.typ of
  839. RELOC_RELATIVE : rel.relative:=$14;
  840. RELOC_ABSOLUTE : rel.relative:=$6;
  841. RELOC_RVA : rel.relative:=$7;
  842. end;
  843. FWriter.write(rel,sizeof(rel));
  844. r:=TAsmRelocation(r.next);
  845. end;
  846. end;
  847. end;
  848. end;
  849. function tcoffobjectoutput.writedata(data:TAsmObjectData):boolean;
  850. var
  851. datapos,
  852. secsymidx,
  853. nsects,
  854. sympos,i : longint;
  855. hstab : coffstab;
  856. gotreloc : boolean;
  857. namestr : string[8];
  858. nameidx,
  859. value,
  860. sectionval : longint;
  861. globalval : byte;
  862. sec : TSection;
  863. header : coffheader;
  864. sechdr : coffsechdr;
  865. empty : array[0..15] of byte;
  866. hp : pdynamicblock;
  867. begin
  868. result:=false;
  869. FCoffStrs:=TDynamicArray.Create(strsresize);
  870. with tcoffobjectdata(data) do
  871. begin
  872. { calc amount of sections we have }
  873. fillchar(empty,sizeof(empty),0);
  874. nsects:=0;
  875. initsym:=2; { 2 for the file }
  876. secsymidx:=0;
  877. for sec:=low(TSection) to high(TSection) do
  878. if assigned(sects[sec]) then
  879. begin
  880. inc(nsects);
  881. inc(secsymidx);
  882. sects[sec].secsymidx:=secsymidx;
  883. inc(initsym,2); { 2 for each section }
  884. end;
  885. { For the stab section we need an HdrSym which can now be
  886. calculated more easily }
  887. if assigned(sects[sec_stab]) then
  888. begin
  889. hstab.strpos:=1;
  890. hstab.ntype:=0;
  891. hstab.nother:=0;
  892. hstab.ndesc:=(sects[sec_stab].datasize div sizeof(coffstab))-1{+1 according to gas output PM};
  893. hstab.nvalue:=sects[sec_stabstr].datasize;
  894. sects[sec_stab].data.seek(0);
  895. sects[sec_stab].data.write(hstab,sizeof(hstab));
  896. end;
  897. { Calculate the filepositions }
  898. datapos:=sizeof(coffheader)+sizeof(coffsechdr)*nsects;
  899. { sections first }
  900. for sec:=low(TSection) to high(TSection) do
  901. if assigned(sects[sec]) then
  902. begin
  903. sects[sec].datapos:=datapos;
  904. if assigned(sects[sec].data) then
  905. inc(datapos,sects[sec].aligneddatasize);
  906. end;
  907. { relocs }
  908. gotreloc:=false;
  909. for sec:=low(TSection) to high(TSection) do
  910. if assigned(sects[sec]) then
  911. begin
  912. TCoffObjectSection(sects[sec]).coffrelocpos:=datapos;
  913. inc(datapos,10*sects[sec].relocations.count);
  914. if (not gotreloc) and (sects[sec].relocations.count>0) then
  915. gotreloc:=true;
  916. end;
  917. { symbols }
  918. sympos:=datapos;
  919. { COFF header }
  920. fillchar(header,sizeof(coffheader),0);
  921. header.mach:=$14c;
  922. header.nsects:=nsects;
  923. header.sympos:=sympos;
  924. header.syms:=symbols.count+initsym;
  925. header.flag:=COFF_FLAG_AR32WR or COFF_FLAG_NOLINES;
  926. if not gotreloc then
  927. header.flag:=header.flag or COFF_FLAG_NORELOCS;
  928. FWriter.write(header,sizeof(header));
  929. { Section headers }
  930. for sec:=low(TSection) to high(TSection) do
  931. if assigned(sects[sec]) then
  932. begin
  933. fillchar(sechdr,sizeof(sechdr),0);
  934. move(target_asm.secnames[sec][1],sechdr.name,length(target_asm.secnames[sec]));
  935. if not win32 then
  936. begin
  937. sechdr.rvaofs:=sects[sec].mempos;
  938. sechdr.vsize:=sects[sec].mempos;
  939. end
  940. else
  941. begin
  942. if sec=sec_bss then
  943. sechdr.vsize:=sects[sec].aligneddatasize;
  944. end;
  945. sechdr.datasize:=sects[sec].aligneddatasize;
  946. if (sects[sec].datasize>0) and assigned(sects[sec].data) then
  947. sechdr.datapos:=sects[sec].datapos;
  948. sechdr.nrelocs:=sects[sec].relocations.count;
  949. sechdr.relocpos:=TCoffObjectSection(sects[sec]).coffrelocpos;
  950. sechdr.flags:=TCoffObjectSection(sects[sec]).flags;
  951. FWriter.write(sechdr,sizeof(sechdr));
  952. end;
  953. { Sections }
  954. for sec:=low(TSection) to high(TSection) do
  955. if assigned(sects[sec]) and
  956. assigned(sects[sec].data) then
  957. begin
  958. sects[sec].alignsection;
  959. hp:=sects[sec].data.firstblock;
  960. while assigned(hp) do
  961. begin
  962. FWriter.write(hp^.data,hp^.used);
  963. hp:=hp^.next;
  964. end;
  965. end;
  966. { Relocs }
  967. write_relocs(data);
  968. { Symbols }
  969. write_symbols(data);
  970. { Strings }
  971. i:=FCoffStrs.size+4;
  972. FWriter.write(i,4);
  973. hp:=FCoffStrs.firstblock;
  974. while assigned(hp) do
  975. begin
  976. FWriter.write(hp^.data,hp^.used);
  977. hp:=hp^.next;
  978. end;
  979. end;
  980. FCoffStrs.Free;
  981. end;
  982. {****************************************************************************
  983. tcoffexeoutput
  984. ****************************************************************************}
  985. constructor tcoffexeoutput.createdjgpp;
  986. begin
  987. inherited create;
  988. win32:=false;
  989. end;
  990. constructor tcoffexeoutput.createwin32;
  991. begin
  992. inherited create;
  993. win32:=true;
  994. end;
  995. function tcoffexeoutput.newobjectinput:tobjectinput;
  996. begin
  997. if win32 then
  998. result:=tcoffobjectinput.createwin32
  999. else
  1000. result:=tcoffobjectinput.createdjgpp;
  1001. end;
  1002. procedure tcoffexeoutput.write_symbol(const name:string;strpos,value,section,typ,aux:longint);
  1003. var
  1004. sym : coffsymbol;
  1005. begin
  1006. FillChar(sym,sizeof(sym),0);
  1007. if strpos=-1 then
  1008. move(name[1],sym.name,length(name))
  1009. else
  1010. sym.strpos:=strpos;
  1011. sym.value:=value;
  1012. sym.section:=section;
  1013. sym.typ:=typ;
  1014. sym.aux:=aux;
  1015. FWriter.write(sym,sizeof(sym));
  1016. end;
  1017. procedure tcoffexeoutput.write_symbols;
  1018. var
  1019. filename : string[18];
  1020. sec : TSection;
  1021. namestr : string[8];
  1022. nameidx,
  1023. value,
  1024. sectionval,
  1025. i : longint;
  1026. globalval : byte;
  1027. secrec : coffsectionrec;
  1028. objdata : TAsmObjectData;
  1029. p : tasmsymbol;
  1030. s : string;
  1031. begin
  1032. objdata:=TAsmObjectData(objdatalist.first);
  1033. while assigned(objdata) do
  1034. begin
  1035. with tcoffobjectdata(objdata) do
  1036. begin
  1037. { The symbols used }
  1038. p:=Tasmsymbol(symbols.First);
  1039. while assigned(p) do
  1040. begin
  1041. if p.section=sec_common then
  1042. sectionval:=sections[sec_bss].secsymidx
  1043. else
  1044. sectionval:=sections[p.section].secsymidx;
  1045. if p.currbind=AB_LOCAL then
  1046. globalval:=3
  1047. else
  1048. globalval:=2;
  1049. { if local of global then set the section value to the address
  1050. of the symbol }
  1051. if p.currbind in [AB_LOCAL,AB_GLOBAL] then
  1052. value:=p.address
  1053. else
  1054. value:=p.size;
  1055. { symbolname }
  1056. s:=p.name;
  1057. if length(s)>8 then
  1058. begin
  1059. nameidx:=FCoffStrs.size+4;
  1060. FCoffStrs.writestr(s);
  1061. FCoffStrs.writestr(#0);
  1062. end
  1063. else
  1064. begin
  1065. nameidx:=-1;
  1066. namestr:=s;
  1067. end;
  1068. write_symbol(namestr,nameidx,value,sectionval,globalval,0);
  1069. p:=tasmsymbol(p.indexnext);
  1070. end;
  1071. end;
  1072. objdata:=TAsmObjectData(objdata.next);
  1073. end;
  1074. end;
  1075. procedure tcoffexeoutput.CalculateMemoryMap;
  1076. var
  1077. objdata : TAsmObjectData;
  1078. secsymidx,
  1079. mempos,
  1080. datapos : longint;
  1081. sec : TSection;
  1082. sym : tasmsymbol;
  1083. s : TAsmSection;
  1084. begin
  1085. { retrieve amount of sections }
  1086. nsects:=0;
  1087. secsymidx:=0;
  1088. for sec:=low(TSection) to high(TSection) do
  1089. begin
  1090. if sections[sec].available then
  1091. begin
  1092. inc(nsects);
  1093. inc(secsymidx);
  1094. sections[sec].secsymidx:=secsymidx;
  1095. end;
  1096. end;
  1097. { calculate start positions after the headers }
  1098. datapos:=sizeof(coffheader)+sizeof(coffoptheader)+sizeof(coffsechdr)*nsects;
  1099. mempos:=sizeof(coffheader)+sizeof(coffoptheader)+sizeof(coffsechdr)*nsects;
  1100. if not win32 then
  1101. inc(mempos,sizeof(go32v2stub)+$1000);
  1102. { add sections }
  1103. MapObjectdata(datapos,mempos);
  1104. { end symbol }
  1105. AddGlobalSym('_etext',sections[sec_code].mempos+sections[sec_code].memsize);
  1106. AddGlobalSym('_edata',sections[sec_data].mempos+sections[sec_data].memsize);
  1107. AddGlobalSym('end',mempos);
  1108. { symbols }
  1109. nsyms:=0;
  1110. sympos:=0;
  1111. if not(cs_link_strip in aktglobalswitches) then
  1112. begin
  1113. sympos:=datapos;
  1114. objdata:=TAsmObjectData(objdatalist.first);
  1115. while assigned(objdata) do
  1116. begin
  1117. inc(nsyms,objdata.symbols.count);
  1118. objdata:=TAsmObjectData(objdata.next);
  1119. end;
  1120. end;
  1121. end;
  1122. function tcoffexeoutput.writedata:boolean;
  1123. var
  1124. datapos,
  1125. secsymidx,
  1126. i : longint;
  1127. hstab : coffstab;
  1128. gotreloc : boolean;
  1129. sec : TSection;
  1130. header : coffheader;
  1131. optheader : coffoptheader;
  1132. sechdr : coffsechdr;
  1133. empty : array[0..15] of byte;
  1134. hp : pdynamicblock;
  1135. objdata : TAsmObjectData;
  1136. hsym : tasmsymbol;
  1137. begin
  1138. result:=false;
  1139. FCoffSyms:=TDynamicArray.Create(symbolresize);
  1140. FCoffStrs:=TDynamicArray.Create(strsresize);
  1141. { Stub }
  1142. if not win32 then
  1143. FWriter.write(go32v2stub,sizeof(go32v2stub));
  1144. { COFF header }
  1145. fillchar(header,sizeof(header),0);
  1146. header.mach:=$14c;
  1147. header.nsects:=nsects;
  1148. header.sympos:=sympos;
  1149. header.syms:=nsyms;
  1150. header.opthdr:=sizeof(coffoptheader);
  1151. header.flag:=COFF_FLAG_AR32WR or COFF_FLAG_EXE or COFF_FLAG_NORELOCS or COFF_FLAG_NOLINES;
  1152. FWriter.write(header,sizeof(header));
  1153. { Optional COFF Header }
  1154. fillchar(optheader,sizeof(optheader),0);
  1155. optheader.magic:=$10b;
  1156. optheader.tsize:=sections[sec_code].memsize;
  1157. optheader.dsize:=sections[sec_data].memsize;
  1158. optheader.bsize:=sections[sec_bss].memsize;
  1159. hsym:=tasmsymbol(globalsyms.search('start'));
  1160. if not assigned(hsym) then
  1161. begin
  1162. Comment(V_Error,'Entrypoint "start" not defined');
  1163. exit;
  1164. end;
  1165. optheader.entry:=hsym.address;
  1166. optheader.text_start:=sections[sec_code].mempos;
  1167. optheader.data_start:=sections[sec_data].mempos;
  1168. FWriter.write(optheader,sizeof(optheader));
  1169. { Section headers }
  1170. for sec:=low(TSection) to high(TSection) do
  1171. if sections[sec].available then
  1172. begin
  1173. fillchar(sechdr,sizeof(sechdr),0);
  1174. move(target_asm.secnames[sec][1],sechdr.name,length(target_asm.secnames[sec]));
  1175. if not win32 then
  1176. begin
  1177. sechdr.rvaofs:=sections[sec].mempos;
  1178. sechdr.vsize:=sections[sec].mempos;
  1179. end
  1180. else
  1181. begin
  1182. if sec=sec_bss then
  1183. sechdr.vsize:=sections[sec].memsize;
  1184. end;
  1185. if sec=sec_bss then
  1186. sechdr.datasize:=sections[sec].memsize
  1187. else
  1188. begin
  1189. sechdr.datasize:=sections[sec].datasize;
  1190. sechdr.datapos:=sections[sec].datapos;
  1191. end;
  1192. sechdr.nrelocs:=0;
  1193. sechdr.relocpos:=0;
  1194. sechdr.flags:=sections[sec].flags;
  1195. FWriter.write(sechdr,sizeof(sechdr));
  1196. end;
  1197. { Sections }
  1198. for sec:=low(TSection) to high(TSection) do
  1199. if sections[sec].available then
  1200. begin
  1201. { update objectfiles }
  1202. objdata:=TAsmObjectData(objdatalist.first);
  1203. while assigned(objdata) do
  1204. begin
  1205. if assigned(objdata.sects[sec]) and
  1206. assigned(objdata.sects[sec].data) then
  1207. begin
  1208. WriteZeros(objdata.sects[sec].dataalignbytes);
  1209. hp:=objdata.sects[sec].data.firstblock;
  1210. while assigned(hp) do
  1211. begin
  1212. FWriter.write(hp^.data,hp^.used);
  1213. hp:=hp^.next;
  1214. end;
  1215. end;
  1216. objdata:=TAsmObjectData(objdata.next);
  1217. end;
  1218. end;
  1219. { Optional symbols }
  1220. if not(cs_link_strip in aktglobalswitches) then
  1221. begin
  1222. { Symbols }
  1223. write_symbols;
  1224. { Strings }
  1225. i:=FCoffStrs.size+4;
  1226. FWriter.write(i,4);
  1227. hp:=FCoffStrs.firstblock;
  1228. while assigned(hp) do
  1229. begin
  1230. FWriter.write(hp^.data,hp^.used);
  1231. hp:=hp^.next;
  1232. end;
  1233. end;
  1234. { Release }
  1235. FCoffStrs.Free;
  1236. FCoffSyms.Free;
  1237. result:=true;
  1238. end;
  1239. procedure tcoffexeoutput.GenerateExecutable(const fn:string);
  1240. begin
  1241. AddGlobalSym('_etext',0);
  1242. AddGlobalSym('_edata',0);
  1243. AddGlobalSym('end',0);
  1244. if not CalculateSymbols then
  1245. exit;
  1246. CalculateMemoryMap;
  1247. FixupSymbols;
  1248. FixupRelocations;
  1249. writeexefile(fn);
  1250. end;
  1251. {****************************************************************************
  1252. tcoffobjectinput
  1253. ****************************************************************************}
  1254. constructor tcoffobjectinput.createdjgpp;
  1255. begin
  1256. inherited create;
  1257. win32:=false;
  1258. end;
  1259. constructor tcoffobjectinput.createwin32;
  1260. begin
  1261. inherited create;
  1262. win32:=true;
  1263. end;
  1264. function tcoffobjectinput.newobjectdata(const n:string):TAsmObjectData;
  1265. begin
  1266. if win32 then
  1267. result:=tcoffobjectdata.createwin32(n)
  1268. else
  1269. result:=tcoffobjectdata.createdjgpp(n);
  1270. end;
  1271. procedure tcoffobjectinput.read_relocs(s:TCoffObjectSection);
  1272. var
  1273. rel : coffreloc;
  1274. rel_type : TAsmRelocationType;
  1275. i : longint;
  1276. p : tasmsymbol;
  1277. begin
  1278. for i:=1 to s.coffrelocs do
  1279. begin
  1280. FReader.read(rel,sizeof(rel));
  1281. case rel.relative of
  1282. $14 : rel_type:=RELOC_RELATIVE;
  1283. $06 : rel_type:=RELOC_ABSOLUTE;
  1284. $07 : rel_type:=RELOC_RVA;
  1285. else
  1286. begin
  1287. Comment(V_Error,'Error reading coff file');
  1288. exit;
  1289. end;
  1290. end;
  1291. p:=FSymTbl^[rel.sym].sym;
  1292. if assigned(p) then
  1293. begin
  1294. s.addsymsizereloc(rel.address-s.mempos,p,FSymTbl^[rel.sym].orgsize,rel_type);
  1295. end
  1296. else
  1297. begin
  1298. Comment(V_Error,'Error reading coff file');
  1299. exit;
  1300. end;
  1301. end;
  1302. end;
  1303. procedure tcoffobjectinput.handle_symbols(data:TAsmObjectData);
  1304. var
  1305. sec : TSection;
  1306. size,
  1307. address,
  1308. i,nsyms,
  1309. symidx : longint;
  1310. sym : coffsymbol;
  1311. strname : string;
  1312. p : tasmsymbol;
  1313. bind : Tasmsymbind;
  1314. auxrec : array[0..17] of byte;
  1315. begin
  1316. with tcoffobjectdata(data) do
  1317. begin
  1318. nsyms:=FCoffSyms.Size div sizeof(CoffSymbol);
  1319. { Allocate memory for symidx -> tasmsymbol table }
  1320. GetMem(FSymTbl,nsyms*sizeof(ttasmsymbolrec));
  1321. FillChar(FSymTbl^,nsyms*sizeof(ttasmsymbolrec),0);
  1322. { Loop all symbols }
  1323. FCoffSyms.Seek(0);
  1324. symidx:=0;
  1325. while (symidx<nsyms) do
  1326. begin
  1327. FCoffSyms.Read(sym,sizeof(sym));
  1328. if plongint(@sym.name)^<>0 then
  1329. begin
  1330. move(sym.name,strname[1],8);
  1331. strname[9]:=#0;
  1332. end
  1333. else
  1334. begin
  1335. FCoffStrs.Seek(sym.strpos-4);
  1336. FCoffStrs.Read(strname[1],255);
  1337. strname[255]:=#0;
  1338. end;
  1339. strname[0]:=chr(strlen(@strname[1]));
  1340. if strname='' then
  1341. Internalerror(200205172);
  1342. bind:=AB_EXTERNAL;
  1343. sec:=sec_none;
  1344. size:=0;
  1345. address:=0;
  1346. case sym.typ of
  1347. COFF_SYM_GLOBAL :
  1348. begin
  1349. if sym.section=0 then
  1350. begin
  1351. if sym.value=0 then
  1352. bind:=AB_EXTERNAL
  1353. else
  1354. begin
  1355. bind:=AB_COMMON;
  1356. size:=sym.value;
  1357. end;
  1358. end
  1359. else
  1360. begin
  1361. bind:=AB_GLOBAL;
  1362. sec:=Fidx2sec[sym.section];
  1363. if assigned(sects[sec]) then
  1364. begin
  1365. if sym.value>=sects[sec].mempos then
  1366. address:=sym.value-sects[sec].mempos
  1367. else
  1368. internalerror(432432432);
  1369. end
  1370. else
  1371. internalerror(34243214);
  1372. end;
  1373. p:=TAsmSymbol.Create(strname,bind,AT_FUNCTION);
  1374. p.SetAddress(0,sec,address,size);
  1375. p.objectdata:=data;
  1376. symbols.insert(p);
  1377. end;
  1378. COFF_SYM_LABEL,
  1379. COFF_SYM_LOCAL :
  1380. begin
  1381. { do not add constants (section=-1) }
  1382. if sym.section<>-1 then
  1383. begin
  1384. bind:=AB_LOCAL;
  1385. sec:=Fidx2sec[sym.section];
  1386. if assigned(sects[sec]) then
  1387. begin
  1388. if sym.value>=sects[sec].mempos then
  1389. address:=sym.value-sects[sec].mempos
  1390. else
  1391. internalerror(432432432);
  1392. end
  1393. else
  1394. internalerror(34243214);
  1395. p:=TAsmSymbol.Create(strname,bind,AT_FUNCTION);
  1396. p.SetAddress(0,sec,address,size);
  1397. p.objectdata:=data;
  1398. symbols.insert(p);
  1399. end;
  1400. end;
  1401. COFF_SYM_SECTION,
  1402. COFF_SYM_FUNCTION,
  1403. COFF_SYM_FILE :
  1404. ;
  1405. else
  1406. internalerror(4342343);
  1407. end;
  1408. FSymTbl^[symidx].sym:=p;
  1409. FSymTbl^[symidx].orgsize:=size;
  1410. { read aux records }
  1411. for i:=1 to sym.aux do
  1412. begin
  1413. FCoffSyms.Read(auxrec,sizeof(auxrec));
  1414. inc(symidx);
  1415. end;
  1416. inc(symidx);
  1417. end;
  1418. end;
  1419. end;
  1420. function tcoffobjectinput.readobjectdata(data:TAsmObjectData):boolean;
  1421. var
  1422. strsize,
  1423. i : longint;
  1424. sec : TSection;
  1425. header : coffheader;
  1426. sechdr : coffsechdr;
  1427. secname : array[0..15] of char;
  1428. begin
  1429. result:=false;
  1430. FCoffSyms:=TDynamicArray.Create(symbolresize);
  1431. FCoffStrs:=TDynamicArray.Create(strsresize);
  1432. with tcoffobjectdata(data) do
  1433. begin
  1434. FillChar(Fidx2sec,sizeof(Fidx2sec),0);
  1435. { Read COFF header }
  1436. if not reader.read(header,sizeof(coffheader)) then
  1437. begin
  1438. Comment(V_Error,'Error reading coff file');
  1439. exit;
  1440. end;
  1441. if header.mach<>$14c then
  1442. begin
  1443. Comment(V_Error,'Not a coff file');
  1444. exit;
  1445. end;
  1446. if header.nsects>255 then
  1447. begin
  1448. Comment(V_Error,'To many sections');
  1449. exit;
  1450. end;
  1451. { Section headers }
  1452. for i:=1 to header.nsects do
  1453. begin
  1454. if not reader.read(sechdr,sizeof(sechdr)) then
  1455. begin
  1456. Comment(V_Error,'Error reading coff file');
  1457. exit;
  1458. end;
  1459. move(sechdr.name,secname,8);
  1460. secname[8]:=#0;
  1461. sec:=str2sec(strpas(secname));
  1462. if sec<>sec_none then
  1463. begin
  1464. Fidx2sec[i]:=sec;
  1465. createsection(sec);
  1466. if not win32 then
  1467. sects[sec].mempos:=sechdr.rvaofs;
  1468. TCoffObjectSection(sects[sec]).coffrelocs:=sechdr.nrelocs;
  1469. TCoffObjectSection(sects[sec]).coffrelocpos:=sechdr.relocpos;
  1470. sects[sec].datapos:=sechdr.datapos;
  1471. sects[sec].datasize:=sechdr.datasize;
  1472. sects[sec].memsize:=sechdr.datasize;
  1473. TCoffObjectSection(sects[sec]).orgmempos:=sects[sec].mempos;
  1474. sects[sec].flags:=sechdr.flags;
  1475. end
  1476. else
  1477. Comment(V_Warning,'skipping unsupported section '+strpas(sechdr.name));
  1478. end;
  1479. { Symbols }
  1480. Reader.Seek(header.sympos);
  1481. if not Reader.ReadArray(FCoffSyms,header.syms*sizeof(CoffSymbol)) then
  1482. begin
  1483. Comment(V_Error,'Error reading coff file');
  1484. exit;
  1485. end;
  1486. { Strings }
  1487. if not Reader.Read(strsize,4) then
  1488. begin
  1489. Comment(V_Error,'Error reading coff file');
  1490. exit;
  1491. end;
  1492. if strsize<4 then
  1493. begin
  1494. Comment(V_Error,'Error reading coff file');
  1495. exit;
  1496. end;
  1497. if not Reader.ReadArray(FCoffStrs,Strsize-4) then
  1498. begin
  1499. Comment(V_Error,'Error reading coff file');
  1500. exit;
  1501. end;
  1502. { Insert all symbols }
  1503. handle_symbols(data);
  1504. { Sections }
  1505. for sec:=low(TSection) to high(TSection) do
  1506. if assigned(sects[sec]) and
  1507. (sec<>sec_bss) then
  1508. begin
  1509. Reader.Seek(sects[sec].datapos);
  1510. if not Reader.ReadArray(sects[sec].data,sects[sec].datasize) then
  1511. begin
  1512. Comment(V_Error,'Error reading coff file');
  1513. exit;
  1514. end;
  1515. end;
  1516. { Relocs }
  1517. for sec:=low(TSection) to high(TSection) do
  1518. if assigned(sects[sec]) and
  1519. (TCoffObjectSection(sects[sec]).coffrelocs>0) then
  1520. begin
  1521. Reader.Seek(TCoffObjectSection(sects[sec]).coffrelocpos);
  1522. read_relocs(TCoffObjectSection(sects[sec]));
  1523. end;
  1524. end;
  1525. FCoffStrs.Free;
  1526. FCoffSyms.Free;
  1527. result:=true;
  1528. end;
  1529. {****************************************************************************
  1530. TCoffAssembler
  1531. ****************************************************************************}
  1532. constructor TCoffAssembler.Create(smart:boolean);
  1533. begin
  1534. inherited Create(smart);
  1535. objectoutput:=tcoffobjectoutput.createdjgpp(smart);
  1536. end;
  1537. {****************************************************************************
  1538. TPECoffAssembler
  1539. ****************************************************************************}
  1540. constructor TPECoffAssembler.Create(smart:boolean);
  1541. begin
  1542. inherited Create(smart);
  1543. objectoutput:=tcoffobjectoutput.createwin32(smart);
  1544. end;
  1545. {****************************************************************************
  1546. TCoffLinker
  1547. ****************************************************************************}
  1548. constructor TCoffLinker.Create;
  1549. begin
  1550. inherited Create;
  1551. exeoutput:=tcoffexeoutput.createdjgpp;
  1552. end;
  1553. {*****************************************************************************
  1554. Initialize
  1555. *****************************************************************************}
  1556. const
  1557. as_i386_coff_info : tasminfo =
  1558. (
  1559. id : as_i386_coff;
  1560. idtxt : 'COFF';
  1561. asmbin : '';
  1562. asmcmd : '';
  1563. supported_target : system_i386_go32v2;
  1564. outputbinary : true;
  1565. allowdirect : false;
  1566. externals : true;
  1567. needar : false;
  1568. labelprefix_only_inside_procedure: false;
  1569. labelprefix : '.L';
  1570. comment : '';
  1571. secnames : ('',
  1572. '.text','.data','.bss',
  1573. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  1574. '.stab','.stabstr','COMMON')
  1575. );
  1576. const
  1577. as_i386_pecoff_info : tasminfo =
  1578. (
  1579. id : as_i386_pecoff;
  1580. idtxt : 'PECOFF';
  1581. asmbin : '';
  1582. asmcmd : '';
  1583. supported_target : system_i386_win32;
  1584. outputbinary : true;
  1585. allowdirect : false;
  1586. externals : true;
  1587. needar : false;
  1588. labelprefix_only_inside_procedure: false;
  1589. labelprefix : '.L';
  1590. comment : '';
  1591. secnames : ('',
  1592. '.text','.data','.bss',
  1593. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  1594. '.stab','.stabstr','COMMON')
  1595. );
  1596. as_i386_pecoffwdosx_info : tasminfo =
  1597. (
  1598. id : as_i386_pecoffwdosx;
  1599. idtxt : 'PECOFFWDOSX';
  1600. asmbin : '';
  1601. asmcmd : '';
  1602. supported_target : system_i386_wdosx;
  1603. outputbinary : true;
  1604. allowdirect : false;
  1605. externals : true;
  1606. needar : false;
  1607. labelprefix_only_inside_procedure: false;
  1608. labelprefix : '.L';
  1609. comment : '';
  1610. secnames : ('',
  1611. '.text','.data','.bss',
  1612. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  1613. '.stab','.stabstr','COMMON')
  1614. );
  1615. initialization
  1616. RegisterAssembler(as_i386_coff_info,TCoffAssembler);
  1617. RegisterAssembler(as_i386_pecoff_info,TPECoffAssembler);
  1618. RegisterAssembler(as_i386_pecoffwdosx_info,TPECoffAssembler);
  1619. RegisterLinker(ld_i386_coff,TCoffLinker);
  1620. end.
  1621. {
  1622. $Log$
  1623. Revision 1.23 2002-07-26 21:15:38 florian
  1624. * rewrote the system handling
  1625. Revision 1.22 2002/07/01 18:46:24 peter
  1626. * internal linker
  1627. * reorganized aasm layer
  1628. Revision 1.21 2002/05/18 13:34:10 peter
  1629. * readded missing revisions
  1630. Revision 1.20 2002/05/16 19:46:39 carl
  1631. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1632. + try to fix temp allocation (still in ifdef)
  1633. + generic constructor calls
  1634. + start of tassembler / tmodulebase class cleanup
  1635. Revision 1.19 2002/05/14 19:34:43 peter
  1636. * removed old logs and updated copyright year
  1637. Revision 1.18 2002/04/04 19:05:58 peter
  1638. * removed unused units
  1639. * use tlocation.size in cg.a_*loc*() routines
  1640. Revision 1.17 2002/04/04 18:38:30 carl
  1641. + added wdosx support (patch from Pavel)
  1642. }