ogcoff.pas 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762
  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,
  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. value,
  742. nameidx : longint;
  743. sectionval,
  744. globalval : byte;
  745. secrec : coffsectionrec;
  746. p : tasmsymbol;
  747. s : string;
  748. begin
  749. with tcoffobjectdata(data) do
  750. begin
  751. { The `.file' record, and the file name auxiliary record }
  752. write_symbol('.file', -1, 0, -2, $67, 1);
  753. fillchar(filename,sizeof(filename),0);
  754. filename:=SplitFileName(current_module.mainsource^);
  755. FWriter.write(filename[1],sizeof(filename)-1);
  756. { The section records, with their auxiliaries, also store the
  757. symbol index }
  758. for sec:=low(TSection) to high(TSection) do
  759. if assigned(sects[sec]) then
  760. begin
  761. write_symbol(target_asm.secnames[sec],-1,sects[sec].mempos,sects[sec].secsymidx,3,1);
  762. fillchar(secrec,sizeof(secrec),0);
  763. secrec.len:=sects[sec].aligneddatasize;
  764. secrec.nrelocs:=sects[sec].relocations.count;
  765. FWriter.write(secrec,sizeof(secrec));
  766. end;
  767. { The symbols used }
  768. p:=Tasmsymbol(symbols.First);
  769. while assigned(p) do
  770. begin
  771. if assigned(sects[p.section]) then
  772. sectionval:=sects[p.section].secsymidx
  773. else
  774. sectionval:=0;
  775. if p.currbind=AB_LOCAL then
  776. globalval:=3
  777. else
  778. globalval:=2;
  779. { if local of global then set the section value to the address
  780. of the symbol }
  781. if p.currbind in [AB_LOCAL,AB_GLOBAL] then
  782. value:=p.address+sects[p.section].mempos
  783. else
  784. value:=p.size;
  785. { symbolname }
  786. s:=p.name;
  787. if length(s)>8 then
  788. begin
  789. nameidx:=FCoffStrs.size+4;
  790. FCoffStrs.writestr(s);
  791. FCoffStrs.writestr(#0);
  792. end
  793. else
  794. begin
  795. nameidx:=-1;
  796. namestr:=s;
  797. end;
  798. write_symbol(namestr,nameidx,value,sectionval,globalval,0);
  799. p:=tasmsymbol(p.indexnext);
  800. end;
  801. end;
  802. end;
  803. procedure tcoffobjectoutput.write_relocs(data:TAsmObjectData);
  804. var
  805. rel : coffreloc;
  806. r : TAsmRelocation;
  807. sec : TSection;
  808. begin
  809. with data do
  810. begin
  811. for sec:=low(TSection) to high(TSection) do
  812. if assigned(sects[sec]) then
  813. begin
  814. r:=TasmRelocation(sects[sec].relocations.first);
  815. while assigned(r) do
  816. begin
  817. rel.address:=r.address;
  818. if assigned(r.symbol) then
  819. begin
  820. if (r.symbol.currbind=AB_LOCAL) then
  821. rel.sym:=2*sects[r.symbol.section].secsymidx
  822. else
  823. begin
  824. if r.symbol.indexnr=-1 then
  825. internalerror(4321);
  826. { indexnr starts with 1, coff starts with 0 }
  827. rel.sym:=r.symbol.indexnr+initsym-1;
  828. end;
  829. end
  830. else
  831. begin
  832. if r.section<>sec_none then
  833. rel.sym:=2*sects[r.section].secsymidx
  834. else
  835. rel.sym:=0;
  836. end;
  837. case r.typ of
  838. RELOC_RELATIVE : rel.relative:=$14;
  839. RELOC_ABSOLUTE : rel.relative:=$6;
  840. RELOC_RVA : rel.relative:=$7;
  841. end;
  842. FWriter.write(rel,sizeof(rel));
  843. r:=TAsmRelocation(r.next);
  844. end;
  845. end;
  846. end;
  847. end;
  848. function tcoffobjectoutput.writedata(data:TAsmObjectData):boolean;
  849. var
  850. datapos,
  851. secsymidx,
  852. nsects,
  853. sympos,i : longint;
  854. hstab : coffstab;
  855. gotreloc : boolean;
  856. sec : TSection;
  857. header : coffheader;
  858. sechdr : coffsechdr;
  859. empty : array[0..15] of byte;
  860. hp : pdynamicblock;
  861. begin
  862. result:=false;
  863. FCoffStrs:=TDynamicArray.Create(strsresize);
  864. with tcoffobjectdata(data) do
  865. begin
  866. { calc amount of sections we have }
  867. fillchar(empty,sizeof(empty),0);
  868. nsects:=0;
  869. initsym:=2; { 2 for the file }
  870. secsymidx:=0;
  871. for sec:=low(TSection) to high(TSection) do
  872. if assigned(sects[sec]) then
  873. begin
  874. inc(nsects);
  875. inc(secsymidx);
  876. sects[sec].secsymidx:=secsymidx;
  877. inc(initsym,2); { 2 for each section }
  878. end;
  879. { For the stab section we need an HdrSym which can now be
  880. calculated more easily }
  881. if assigned(sects[sec_stab]) then
  882. begin
  883. hstab.strpos:=1;
  884. hstab.ntype:=0;
  885. hstab.nother:=0;
  886. hstab.ndesc:=(sects[sec_stab].datasize div sizeof(coffstab))-1{+1 according to gas output PM};
  887. hstab.nvalue:=sects[sec_stabstr].datasize;
  888. sects[sec_stab].data.seek(0);
  889. sects[sec_stab].data.write(hstab,sizeof(hstab));
  890. end;
  891. { Calculate the filepositions }
  892. datapos:=sizeof(coffheader)+sizeof(coffsechdr)*nsects;
  893. { sections first }
  894. for sec:=low(TSection) to high(TSection) do
  895. if assigned(sects[sec]) then
  896. begin
  897. sects[sec].datapos:=datapos;
  898. if assigned(sects[sec].data) then
  899. inc(datapos,sects[sec].aligneddatasize);
  900. end;
  901. { relocs }
  902. gotreloc:=false;
  903. for sec:=low(TSection) to high(TSection) do
  904. if assigned(sects[sec]) then
  905. begin
  906. TCoffObjectSection(sects[sec]).coffrelocpos:=datapos;
  907. inc(datapos,10*sects[sec].relocations.count);
  908. if (not gotreloc) and (sects[sec].relocations.count>0) then
  909. gotreloc:=true;
  910. end;
  911. { symbols }
  912. sympos:=datapos;
  913. { COFF header }
  914. fillchar(header,sizeof(coffheader),0);
  915. header.mach:=$14c;
  916. header.nsects:=nsects;
  917. header.sympos:=sympos;
  918. header.syms:=symbols.count+initsym;
  919. header.flag:=COFF_FLAG_AR32WR or COFF_FLAG_NOLINES;
  920. if not gotreloc then
  921. header.flag:=header.flag or COFF_FLAG_NORELOCS;
  922. FWriter.write(header,sizeof(header));
  923. { Section headers }
  924. for sec:=low(TSection) to high(TSection) do
  925. if assigned(sects[sec]) then
  926. begin
  927. fillchar(sechdr,sizeof(sechdr),0);
  928. move(target_asm.secnames[sec][1],sechdr.name,length(target_asm.secnames[sec]));
  929. if not win32 then
  930. begin
  931. sechdr.rvaofs:=sects[sec].mempos;
  932. sechdr.vsize:=sects[sec].mempos;
  933. end
  934. else
  935. begin
  936. if sec=sec_bss then
  937. sechdr.vsize:=sects[sec].aligneddatasize;
  938. end;
  939. sechdr.datasize:=sects[sec].aligneddatasize;
  940. if (sects[sec].datasize>0) and assigned(sects[sec].data) then
  941. sechdr.datapos:=sects[sec].datapos;
  942. sechdr.nrelocs:=sects[sec].relocations.count;
  943. sechdr.relocpos:=TCoffObjectSection(sects[sec]).coffrelocpos;
  944. sechdr.flags:=TCoffObjectSection(sects[sec]).flags;
  945. FWriter.write(sechdr,sizeof(sechdr));
  946. end;
  947. { Sections }
  948. for sec:=low(TSection) to high(TSection) do
  949. if assigned(sects[sec]) and
  950. assigned(sects[sec].data) then
  951. begin
  952. sects[sec].alignsection;
  953. hp:=sects[sec].data.firstblock;
  954. while assigned(hp) do
  955. begin
  956. FWriter.write(hp^.data,hp^.used);
  957. hp:=hp^.next;
  958. end;
  959. end;
  960. { Relocs }
  961. write_relocs(data);
  962. { Symbols }
  963. write_symbols(data);
  964. { Strings }
  965. i:=FCoffStrs.size+4;
  966. FWriter.write(i,4);
  967. hp:=FCoffStrs.firstblock;
  968. while assigned(hp) do
  969. begin
  970. FWriter.write(hp^.data,hp^.used);
  971. hp:=hp^.next;
  972. end;
  973. end;
  974. FCoffStrs.Free;
  975. end;
  976. {****************************************************************************
  977. tcoffexeoutput
  978. ****************************************************************************}
  979. constructor tcoffexeoutput.createdjgpp;
  980. begin
  981. inherited create;
  982. win32:=false;
  983. end;
  984. constructor tcoffexeoutput.createwin32;
  985. begin
  986. inherited create;
  987. win32:=true;
  988. end;
  989. function tcoffexeoutput.newobjectinput:tobjectinput;
  990. begin
  991. if win32 then
  992. result:=tcoffobjectinput.createwin32
  993. else
  994. result:=tcoffobjectinput.createdjgpp;
  995. end;
  996. procedure tcoffexeoutput.write_symbol(const name:string;strpos,value,section,typ,aux:longint);
  997. var
  998. sym : coffsymbol;
  999. begin
  1000. FillChar(sym,sizeof(sym),0);
  1001. if strpos=-1 then
  1002. move(name[1],sym.name,length(name))
  1003. else
  1004. sym.strpos:=strpos;
  1005. sym.value:=value;
  1006. sym.section:=section;
  1007. sym.typ:=typ;
  1008. sym.aux:=aux;
  1009. FWriter.write(sym,sizeof(sym));
  1010. end;
  1011. procedure tcoffexeoutput.write_symbols;
  1012. var
  1013. namestr : string[8];
  1014. nameidx : longint;
  1015. value,
  1016. sectionval,
  1017. globalval : byte;
  1018. objdata : TAsmObjectData;
  1019. p : tasmsymbol;
  1020. s : string;
  1021. begin
  1022. objdata:=TAsmObjectData(objdatalist.first);
  1023. while assigned(objdata) do
  1024. begin
  1025. with tcoffobjectdata(objdata) do
  1026. begin
  1027. { The symbols used }
  1028. p:=Tasmsymbol(symbols.First);
  1029. while assigned(p) do
  1030. begin
  1031. if p.section=sec_common then
  1032. sectionval:=sections[sec_bss].secsymidx
  1033. else
  1034. sectionval:=sections[p.section].secsymidx;
  1035. if p.currbind=AB_LOCAL then
  1036. globalval:=3
  1037. else
  1038. globalval:=2;
  1039. { if local of global then set the section value to the address
  1040. of the symbol }
  1041. if p.currbind in [AB_LOCAL,AB_GLOBAL] then
  1042. value:=p.address
  1043. else
  1044. value:=p.size;
  1045. { symbolname }
  1046. s:=p.name;
  1047. if length(s)>8 then
  1048. begin
  1049. nameidx:=FCoffStrs.size+4;
  1050. FCoffStrs.writestr(s);
  1051. FCoffStrs.writestr(#0);
  1052. end
  1053. else
  1054. begin
  1055. nameidx:=-1;
  1056. namestr:=s;
  1057. end;
  1058. write_symbol(namestr,nameidx,value,sectionval,globalval,0);
  1059. p:=tasmsymbol(p.indexnext);
  1060. end;
  1061. end;
  1062. objdata:=TAsmObjectData(objdata.next);
  1063. end;
  1064. end;
  1065. procedure tcoffexeoutput.CalculateMemoryMap;
  1066. var
  1067. objdata : TAsmObjectData;
  1068. secsymidx,
  1069. mempos,
  1070. datapos : longint;
  1071. sec : TSection;
  1072. begin
  1073. { retrieve amount of sections }
  1074. nsects:=0;
  1075. secsymidx:=0;
  1076. for sec:=low(TSection) to high(TSection) do
  1077. begin
  1078. if sections[sec].available then
  1079. begin
  1080. inc(nsects);
  1081. inc(secsymidx);
  1082. sections[sec].secsymidx:=secsymidx;
  1083. end;
  1084. end;
  1085. { calculate start positions after the headers }
  1086. datapos:=sizeof(coffheader)+sizeof(coffoptheader)+sizeof(coffsechdr)*nsects;
  1087. mempos:=sizeof(coffheader)+sizeof(coffoptheader)+sizeof(coffsechdr)*nsects;
  1088. if not win32 then
  1089. inc(mempos,sizeof(go32v2stub)+$1000);
  1090. { add sections }
  1091. MapObjectdata(datapos,mempos);
  1092. { end symbol }
  1093. AddGlobalSym('_etext',sections[sec_code].mempos+sections[sec_code].memsize);
  1094. AddGlobalSym('_edata',sections[sec_data].mempos+sections[sec_data].memsize);
  1095. AddGlobalSym('end',mempos);
  1096. { symbols }
  1097. nsyms:=0;
  1098. sympos:=0;
  1099. if not(cs_link_strip in aktglobalswitches) then
  1100. begin
  1101. sympos:=datapos;
  1102. objdata:=TAsmObjectData(objdatalist.first);
  1103. while assigned(objdata) do
  1104. begin
  1105. inc(nsyms,objdata.symbols.count);
  1106. objdata:=TAsmObjectData(objdata.next);
  1107. end;
  1108. end;
  1109. end;
  1110. function tcoffexeoutput.writedata:boolean;
  1111. var
  1112. i : longint;
  1113. sec : TSection;
  1114. header : coffheader;
  1115. optheader : coffoptheader;
  1116. sechdr : coffsechdr;
  1117. hp : pdynamicblock;
  1118. objdata : TAsmObjectData;
  1119. hsym : tasmsymbol;
  1120. begin
  1121. result:=false;
  1122. FCoffSyms:=TDynamicArray.Create(symbolresize);
  1123. FCoffStrs:=TDynamicArray.Create(strsresize);
  1124. { Stub }
  1125. if not win32 then
  1126. FWriter.write(go32v2stub,sizeof(go32v2stub));
  1127. { COFF header }
  1128. fillchar(header,sizeof(header),0);
  1129. header.mach:=$14c;
  1130. header.nsects:=nsects;
  1131. header.sympos:=sympos;
  1132. header.syms:=nsyms;
  1133. header.opthdr:=sizeof(coffoptheader);
  1134. header.flag:=COFF_FLAG_AR32WR or COFF_FLAG_EXE or COFF_FLAG_NORELOCS or COFF_FLAG_NOLINES;
  1135. FWriter.write(header,sizeof(header));
  1136. { Optional COFF Header }
  1137. fillchar(optheader,sizeof(optheader),0);
  1138. optheader.magic:=$10b;
  1139. optheader.tsize:=sections[sec_code].memsize;
  1140. optheader.dsize:=sections[sec_data].memsize;
  1141. optheader.bsize:=sections[sec_bss].memsize;
  1142. hsym:=tasmsymbol(globalsyms.search('start'));
  1143. if not assigned(hsym) then
  1144. begin
  1145. Comment(V_Error,'Entrypoint "start" not defined');
  1146. exit;
  1147. end;
  1148. optheader.entry:=hsym.address;
  1149. optheader.text_start:=sections[sec_code].mempos;
  1150. optheader.data_start:=sections[sec_data].mempos;
  1151. FWriter.write(optheader,sizeof(optheader));
  1152. { Section headers }
  1153. for sec:=low(TSection) to high(TSection) do
  1154. if sections[sec].available then
  1155. begin
  1156. fillchar(sechdr,sizeof(sechdr),0);
  1157. move(target_asm.secnames[sec][1],sechdr.name,length(target_asm.secnames[sec]));
  1158. if not win32 then
  1159. begin
  1160. sechdr.rvaofs:=sections[sec].mempos;
  1161. sechdr.vsize:=sections[sec].mempos;
  1162. end
  1163. else
  1164. begin
  1165. if sec=sec_bss then
  1166. sechdr.vsize:=sections[sec].memsize;
  1167. end;
  1168. if sec=sec_bss then
  1169. sechdr.datasize:=sections[sec].memsize
  1170. else
  1171. begin
  1172. sechdr.datasize:=sections[sec].datasize;
  1173. sechdr.datapos:=sections[sec].datapos;
  1174. end;
  1175. sechdr.nrelocs:=0;
  1176. sechdr.relocpos:=0;
  1177. sechdr.flags:=sections[sec].flags;
  1178. FWriter.write(sechdr,sizeof(sechdr));
  1179. end;
  1180. { Sections }
  1181. for sec:=low(TSection) to high(TSection) do
  1182. if sections[sec].available then
  1183. begin
  1184. { update objectfiles }
  1185. objdata:=TAsmObjectData(objdatalist.first);
  1186. while assigned(objdata) do
  1187. begin
  1188. if assigned(objdata.sects[sec]) and
  1189. assigned(objdata.sects[sec].data) then
  1190. begin
  1191. WriteZeros(objdata.sects[sec].dataalignbytes);
  1192. hp:=objdata.sects[sec].data.firstblock;
  1193. while assigned(hp) do
  1194. begin
  1195. FWriter.write(hp^.data,hp^.used);
  1196. hp:=hp^.next;
  1197. end;
  1198. end;
  1199. objdata:=TAsmObjectData(objdata.next);
  1200. end;
  1201. end;
  1202. { Optional symbols }
  1203. if not(cs_link_strip in aktglobalswitches) then
  1204. begin
  1205. { Symbols }
  1206. write_symbols;
  1207. { Strings }
  1208. i:=FCoffStrs.size+4;
  1209. FWriter.write(i,4);
  1210. hp:=FCoffStrs.firstblock;
  1211. while assigned(hp) do
  1212. begin
  1213. FWriter.write(hp^.data,hp^.used);
  1214. hp:=hp^.next;
  1215. end;
  1216. end;
  1217. { Release }
  1218. FCoffStrs.Free;
  1219. FCoffSyms.Free;
  1220. result:=true;
  1221. end;
  1222. procedure tcoffexeoutput.GenerateExecutable(const fn:string);
  1223. begin
  1224. AddGlobalSym('_etext',0);
  1225. AddGlobalSym('_edata',0);
  1226. AddGlobalSym('end',0);
  1227. if not CalculateSymbols then
  1228. exit;
  1229. CalculateMemoryMap;
  1230. FixupSymbols;
  1231. FixupRelocations;
  1232. writeexefile(fn);
  1233. end;
  1234. {****************************************************************************
  1235. tcoffobjectinput
  1236. ****************************************************************************}
  1237. constructor tcoffobjectinput.createdjgpp;
  1238. begin
  1239. inherited create;
  1240. win32:=false;
  1241. end;
  1242. constructor tcoffobjectinput.createwin32;
  1243. begin
  1244. inherited create;
  1245. win32:=true;
  1246. end;
  1247. function tcoffobjectinput.newobjectdata(const n:string):TAsmObjectData;
  1248. begin
  1249. if win32 then
  1250. result:=tcoffobjectdata.createwin32(n)
  1251. else
  1252. result:=tcoffobjectdata.createdjgpp(n);
  1253. end;
  1254. procedure tcoffobjectinput.read_relocs(s:TCoffObjectSection);
  1255. var
  1256. rel : coffreloc;
  1257. rel_type : TAsmRelocationType;
  1258. i : longint;
  1259. p : tasmsymbol;
  1260. begin
  1261. for i:=1 to s.coffrelocs do
  1262. begin
  1263. FReader.read(rel,sizeof(rel));
  1264. case rel.relative of
  1265. $14 : rel_type:=RELOC_RELATIVE;
  1266. $06 : rel_type:=RELOC_ABSOLUTE;
  1267. $07 : rel_type:=RELOC_RVA;
  1268. else
  1269. begin
  1270. Comment(V_Error,'Error reading coff file');
  1271. exit;
  1272. end;
  1273. end;
  1274. p:=FSymTbl^[rel.sym].sym;
  1275. if assigned(p) then
  1276. begin
  1277. s.addsymsizereloc(rel.address-s.mempos,p,FSymTbl^[rel.sym].orgsize,rel_type);
  1278. end
  1279. else
  1280. begin
  1281. Comment(V_Error,'Error reading coff file');
  1282. exit;
  1283. end;
  1284. end;
  1285. end;
  1286. procedure tcoffobjectinput.handle_symbols(data:TAsmObjectData);
  1287. var
  1288. sec : TSection;
  1289. size,
  1290. address,
  1291. i,nsyms,
  1292. symidx : longint;
  1293. sym : coffsymbol;
  1294. strname : string;
  1295. p : tasmsymbol;
  1296. bind : Tasmsymbind;
  1297. auxrec : array[0..17] of byte;
  1298. begin
  1299. with tcoffobjectdata(data) do
  1300. begin
  1301. nsyms:=FCoffSyms.Size div sizeof(CoffSymbol);
  1302. { Allocate memory for symidx -> tasmsymbol table }
  1303. GetMem(FSymTbl,nsyms*sizeof(ttasmsymbolrec));
  1304. FillChar(FSymTbl^,nsyms*sizeof(ttasmsymbolrec),0);
  1305. { Loop all symbols }
  1306. FCoffSyms.Seek(0);
  1307. symidx:=0;
  1308. while (symidx<nsyms) do
  1309. begin
  1310. FCoffSyms.Read(sym,sizeof(sym));
  1311. if plongint(@sym.name)^<>0 then
  1312. begin
  1313. move(sym.name,strname[1],8);
  1314. strname[9]:=#0;
  1315. end
  1316. else
  1317. begin
  1318. FCoffStrs.Seek(sym.strpos-4);
  1319. FCoffStrs.Read(strname[1],255);
  1320. strname[255]:=#0;
  1321. end;
  1322. strname[0]:=chr(strlen(@strname[1]));
  1323. if strname='' then
  1324. Internalerror(200205172);
  1325. bind:=AB_EXTERNAL;
  1326. sec:=sec_none;
  1327. size:=0;
  1328. address:=0;
  1329. case sym.typ of
  1330. COFF_SYM_GLOBAL :
  1331. begin
  1332. if sym.section=0 then
  1333. begin
  1334. if sym.value=0 then
  1335. bind:=AB_EXTERNAL
  1336. else
  1337. begin
  1338. bind:=AB_COMMON;
  1339. size:=sym.value;
  1340. end;
  1341. end
  1342. else
  1343. begin
  1344. bind:=AB_GLOBAL;
  1345. sec:=Fidx2sec[sym.section];
  1346. if assigned(sects[sec]) then
  1347. begin
  1348. if sym.value>=sects[sec].mempos then
  1349. address:=sym.value-sects[sec].mempos
  1350. else
  1351. internalerror(432432432);
  1352. end
  1353. else
  1354. internalerror(34243214);
  1355. end;
  1356. p:=TAsmSymbol.Create(strname,bind,AT_FUNCTION);
  1357. p.SetAddress(0,sec,address,size);
  1358. p.objectdata:=data;
  1359. symbols.insert(p);
  1360. end;
  1361. COFF_SYM_LABEL,
  1362. COFF_SYM_LOCAL :
  1363. begin
  1364. { do not add constants (section=-1) }
  1365. if sym.section<>-1 then
  1366. begin
  1367. bind:=AB_LOCAL;
  1368. sec:=Fidx2sec[sym.section];
  1369. if assigned(sects[sec]) then
  1370. begin
  1371. if sym.value>=sects[sec].mempos then
  1372. address:=sym.value-sects[sec].mempos
  1373. else
  1374. internalerror(432432432);
  1375. end
  1376. else
  1377. internalerror(34243214);
  1378. p:=TAsmSymbol.Create(strname,bind,AT_FUNCTION);
  1379. p.SetAddress(0,sec,address,size);
  1380. p.objectdata:=data;
  1381. symbols.insert(p);
  1382. end;
  1383. end;
  1384. COFF_SYM_SECTION,
  1385. COFF_SYM_FUNCTION,
  1386. COFF_SYM_FILE :
  1387. ;
  1388. else
  1389. internalerror(4342343);
  1390. end;
  1391. FSymTbl^[symidx].sym:=p;
  1392. FSymTbl^[symidx].orgsize:=size;
  1393. { read aux records }
  1394. for i:=1 to sym.aux do
  1395. begin
  1396. FCoffSyms.Read(auxrec,sizeof(auxrec));
  1397. inc(symidx);
  1398. end;
  1399. inc(symidx);
  1400. end;
  1401. end;
  1402. end;
  1403. function tcoffobjectinput.readobjectdata(data:TAsmObjectData):boolean;
  1404. var
  1405. strsize,
  1406. i : longint;
  1407. sec : TSection;
  1408. header : coffheader;
  1409. sechdr : coffsechdr;
  1410. secname : array[0..15] of char;
  1411. begin
  1412. result:=false;
  1413. FCoffSyms:=TDynamicArray.Create(symbolresize);
  1414. FCoffStrs:=TDynamicArray.Create(strsresize);
  1415. with tcoffobjectdata(data) do
  1416. begin
  1417. FillChar(Fidx2sec,sizeof(Fidx2sec),0);
  1418. { Read COFF header }
  1419. if not reader.read(header,sizeof(coffheader)) then
  1420. begin
  1421. Comment(V_Error,'Error reading coff file');
  1422. exit;
  1423. end;
  1424. if header.mach<>$14c then
  1425. begin
  1426. Comment(V_Error,'Not a coff file');
  1427. exit;
  1428. end;
  1429. if header.nsects>255 then
  1430. begin
  1431. Comment(V_Error,'To many sections');
  1432. exit;
  1433. end;
  1434. { Section headers }
  1435. for i:=1 to header.nsects do
  1436. begin
  1437. if not reader.read(sechdr,sizeof(sechdr)) then
  1438. begin
  1439. Comment(V_Error,'Error reading coff file');
  1440. exit;
  1441. end;
  1442. move(sechdr.name,secname,8);
  1443. secname[8]:=#0;
  1444. sec:=str2sec(strpas(secname));
  1445. if sec<>sec_none then
  1446. begin
  1447. Fidx2sec[i]:=sec;
  1448. createsection(sec);
  1449. if not win32 then
  1450. sects[sec].mempos:=sechdr.rvaofs;
  1451. TCoffObjectSection(sects[sec]).coffrelocs:=sechdr.nrelocs;
  1452. TCoffObjectSection(sects[sec]).coffrelocpos:=sechdr.relocpos;
  1453. sects[sec].datapos:=sechdr.datapos;
  1454. sects[sec].datasize:=sechdr.datasize;
  1455. sects[sec].memsize:=sechdr.datasize;
  1456. TCoffObjectSection(sects[sec]).orgmempos:=sects[sec].mempos;
  1457. sects[sec].flags:=sechdr.flags;
  1458. end
  1459. else
  1460. Comment(V_Warning,'skipping unsupported section '+strpas(sechdr.name));
  1461. end;
  1462. { Symbols }
  1463. Reader.Seek(header.sympos);
  1464. if not Reader.ReadArray(FCoffSyms,header.syms*sizeof(CoffSymbol)) then
  1465. begin
  1466. Comment(V_Error,'Error reading coff file');
  1467. exit;
  1468. end;
  1469. { Strings }
  1470. if not Reader.Read(strsize,4) then
  1471. begin
  1472. Comment(V_Error,'Error reading coff file');
  1473. exit;
  1474. end;
  1475. if strsize<4 then
  1476. begin
  1477. Comment(V_Error,'Error reading coff file');
  1478. exit;
  1479. end;
  1480. if not Reader.ReadArray(FCoffStrs,Strsize-4) then
  1481. begin
  1482. Comment(V_Error,'Error reading coff file');
  1483. exit;
  1484. end;
  1485. { Insert all symbols }
  1486. handle_symbols(data);
  1487. { Sections }
  1488. for sec:=low(TSection) to high(TSection) do
  1489. if assigned(sects[sec]) and
  1490. (sec<>sec_bss) then
  1491. begin
  1492. Reader.Seek(sects[sec].datapos);
  1493. if not Reader.ReadArray(sects[sec].data,sects[sec].datasize) then
  1494. begin
  1495. Comment(V_Error,'Error reading coff file');
  1496. exit;
  1497. end;
  1498. end;
  1499. { Relocs }
  1500. for sec:=low(TSection) to high(TSection) do
  1501. if assigned(sects[sec]) and
  1502. (TCoffObjectSection(sects[sec]).coffrelocs>0) then
  1503. begin
  1504. Reader.Seek(TCoffObjectSection(sects[sec]).coffrelocpos);
  1505. read_relocs(TCoffObjectSection(sects[sec]));
  1506. end;
  1507. end;
  1508. FCoffStrs.Free;
  1509. FCoffSyms.Free;
  1510. result:=true;
  1511. end;
  1512. {****************************************************************************
  1513. TCoffAssembler
  1514. ****************************************************************************}
  1515. constructor TCoffAssembler.Create(smart:boolean);
  1516. begin
  1517. inherited Create(smart);
  1518. objectoutput:=tcoffobjectoutput.createdjgpp(smart);
  1519. end;
  1520. {****************************************************************************
  1521. TPECoffAssembler
  1522. ****************************************************************************}
  1523. constructor TPECoffAssembler.Create(smart:boolean);
  1524. begin
  1525. inherited Create(smart);
  1526. objectoutput:=tcoffobjectoutput.createwin32(smart);
  1527. end;
  1528. {****************************************************************************
  1529. TCoffLinker
  1530. ****************************************************************************}
  1531. constructor TCoffLinker.Create;
  1532. begin
  1533. inherited Create;
  1534. exeoutput:=tcoffexeoutput.createdjgpp;
  1535. end;
  1536. {*****************************************************************************
  1537. Initialize
  1538. *****************************************************************************}
  1539. const
  1540. as_i386_coff_info : tasminfo =
  1541. (
  1542. id : as_i386_coff;
  1543. idtxt : 'COFF';
  1544. asmbin : '';
  1545. asmcmd : '';
  1546. supported_target : system_i386_go32v2;
  1547. outputbinary : true;
  1548. allowdirect : false;
  1549. needar : false;
  1550. labelprefix_only_inside_procedure: false;
  1551. labelprefix : '.L';
  1552. comment : '';
  1553. secnames : ('',
  1554. '.text','.data','.bss',
  1555. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  1556. '.stab','.stabstr','COMMON')
  1557. );
  1558. const
  1559. as_i386_pecoff_info : tasminfo =
  1560. (
  1561. id : as_i386_pecoff;
  1562. idtxt : 'PECOFF';
  1563. asmbin : '';
  1564. asmcmd : '';
  1565. supported_target : system_i386_win32;
  1566. outputbinary : true;
  1567. allowdirect : false;
  1568. needar : false;
  1569. labelprefix_only_inside_procedure: false;
  1570. labelprefix : '.L';
  1571. comment : '';
  1572. secnames : ('',
  1573. '.text','.data','.bss',
  1574. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  1575. '.stab','.stabstr','COMMON')
  1576. );
  1577. as_i386_pecoffwdosx_info : tasminfo =
  1578. (
  1579. id : as_i386_pecoffwdosx;
  1580. idtxt : 'PEWDOSX';
  1581. asmbin : '';
  1582. asmcmd : '';
  1583. supported_target : system_i386_wdosx;
  1584. outputbinary : true;
  1585. allowdirect : false;
  1586. needar : false;
  1587. labelprefix_only_inside_procedure: false;
  1588. labelprefix : '.L';
  1589. comment : '';
  1590. secnames : ('',
  1591. '.text','.data','.bss',
  1592. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  1593. '.stab','.stabstr','COMMON')
  1594. );
  1595. initialization
  1596. RegisterAssembler(as_i386_coff_info,TCoffAssembler);
  1597. RegisterAssembler(as_i386_pecoff_info,TPECoffAssembler);
  1598. RegisterAssembler(as_i386_pecoffwdosx_info,TPECoffAssembler);
  1599. end.
  1600. {
  1601. $Log$
  1602. Revision 1.27 2003-04-23 11:37:15 peter
  1603. * fix range check error after previous commit
  1604. Revision 1.26 2003/04/22 14:33:38 peter
  1605. * removed some notes/hints
  1606. Revision 1.25 2002/12/07 14:08:11 carl
  1607. * fix warning
  1608. Revision 1.24 2002/08/12 15:08:39 carl
  1609. + stab register indexes for powerpc (moved from gdb to cpubase)
  1610. + tprocessor enumeration moved to cpuinfo
  1611. + linker in target_info is now a class
  1612. * many many updates for m68k (will soon start to compile)
  1613. - removed some ifdef or correct them for correct cpu
  1614. Revision 1.23 2002/07/26 21:15:38 florian
  1615. * rewrote the system handling
  1616. Revision 1.22 2002/07/01 18:46:24 peter
  1617. * internal linker
  1618. * reorganized aasm layer
  1619. Revision 1.21 2002/05/18 13:34:10 peter
  1620. * readded missing revisions
  1621. Revision 1.20 2002/05/16 19:46:39 carl
  1622. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1623. + try to fix temp allocation (still in ifdef)
  1624. + generic constructor calls
  1625. + start of tassembler / tmodulebase class cleanup
  1626. Revision 1.19 2002/05/14 19:34:43 peter
  1627. * removed old logs and updated copyright year
  1628. Revision 1.18 2002/04/04 19:05:58 peter
  1629. * removed unused units
  1630. * use tlocation.size in cg.a_*loc*() routines
  1631. Revision 1.17 2002/04/04 18:38:30 carl
  1632. + added wdosx support (patch from Pavel)
  1633. }