t_win.pas 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674
  1. {
  2. Copyright (c) 1998-2002 by Peter Vreman
  3. This unit implements support import,export,link routines
  4. for the (i386) Win32 target
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit t_win;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. dos,
  23. cutils,cclasses,
  24. aasmbase,aasmtai,aasmdata,aasmcpu,fmodule,globtype,globals,systems,verbose,
  25. symconst,symdef,symsym,
  26. script,gendef,
  27. cpubase,
  28. import,export,link,cgobj,i_win;
  29. const
  30. MAX_DEFAULT_EXTENSIONS = 3;
  31. type
  32. tStr4=array[1..MAX_DEFAULT_EXTENSIONS] of string[4];
  33. pStr4=^tStr4;
  34. twin32imported_item = class(timported_item)
  35. end;
  36. timportlibwin32=class(timportlib)
  37. private
  38. procedure win32importproc(const module : string;index : longint;const name : string);
  39. procedure importvariable_str(const s:string;const name,module:string);
  40. procedure importprocedure_str(const module:string;index:longint;const name:string);
  41. procedure generateimportlib;
  42. procedure generateidatasection;
  43. public
  44. procedure preparelib(const s:string);override;
  45. procedure importprocedure(aprocdef:tprocdef;const module:string;index:longint;const name:string);override;
  46. procedure importvariable(vs:tglobalvarsym;const name,module:string);override;
  47. procedure generatelib;override;
  48. end;
  49. texportlibwin32=class(texportlib)
  50. st : string;
  51. EList_indexed:TFPList;
  52. EList_nonindexed:TFPList;
  53. procedure preparelib(const s:string);override;
  54. procedure exportprocedure(hp : texported_item);override;
  55. procedure exportvar(hp : texported_item);override;
  56. procedure exportfromlist(hp : texported_item);
  57. procedure generatelib;override;
  58. procedure generatenasmlib;virtual;
  59. end;
  60. tlinkerwin32=class(texternallinker)
  61. private
  62. Function WriteResponseFile(isdll:boolean) : Boolean;
  63. Function PostProcessExecutable(const fn:string;isdll:boolean) : Boolean;
  64. public
  65. Constructor Create;override;
  66. Procedure SetDefaultInfo;override;
  67. function MakeExecutable:boolean;override;
  68. function MakeSharedLibrary:boolean;override;
  69. end;
  70. tDLLScannerWin32=class(tDLLScanner)
  71. private
  72. importfound : boolean;
  73. procedure CheckDLLFunc(const dllname,funcname:string);
  74. public
  75. function Scan(const binname:string):boolean;override;
  76. end;
  77. implementation
  78. uses
  79. cpuinfo,cgutils,dbgbase,
  80. owar,ogbase,ogcoff;
  81. const
  82. res_gnu_windres_info : tresinfo =
  83. (
  84. id : res_gnu_windres;
  85. resbin : 'windres';
  86. rescmd : '--include $INC -O coff -o $OBJ $RES'
  87. );
  88. res_gnu_wince_windres_info : tresinfo =
  89. (
  90. id : res_gnu_wince_windres;
  91. resbin : 'windres';
  92. rescmd : '--include $INC -O coff -o $OBJ $RES'
  93. );
  94. {*****************************************************************************
  95. TIMPORTLIBWIN32
  96. *****************************************************************************}
  97. procedure timportlibwin32.preparelib(const s : string);
  98. begin
  99. if current_asmdata.asmlists[al_imports]=nil then
  100. current_asmdata.asmlists[al_imports]:=TAsmList.create;
  101. end;
  102. procedure timportlibwin32.win32importproc(const module : string;index : longint;const name : string);
  103. var
  104. hp1 : timportList;
  105. hp2 : twin32imported_item;
  106. hs : string;
  107. begin
  108. { append extension if required }
  109. hs:=AddExtension(module,target_info.sharedlibext);
  110. { search for the module }
  111. hp1:=timportlist(current_module.imports.first);
  112. while assigned(hp1) do
  113. begin
  114. if hs=hp1.dllname^ then
  115. break;
  116. hp1:=timportlist(hp1.next);
  117. end;
  118. { generate a new item ? }
  119. if not(assigned(hp1)) then
  120. begin
  121. hp1:=timportlist.create(hs);
  122. current_module.imports.concat(hp1);
  123. end;
  124. { search for reuse of old import item }
  125. hp2:=twin32imported_item(hp1.imported_items.first);
  126. while assigned(hp2) do
  127. begin
  128. if (hp2.name^=name) then
  129. break;
  130. hp2:=twin32imported_item(hp2.next);
  131. end;
  132. if not assigned(hp2) then
  133. begin
  134. hp2:=twin32imported_item.create(name,name,index);
  135. hp1.imported_items.concat(hp2);
  136. end;
  137. end;
  138. procedure timportlibwin32.importprocedure(aprocdef:tprocdef;const module : string;index : longint;const name : string);
  139. begin
  140. win32importproc(module,index,name);
  141. end;
  142. procedure timportlibwin32.importprocedure_str(const module : string;index : longint;const name : string);
  143. begin
  144. win32importproc(module,index,name);
  145. end;
  146. procedure timportlibwin32.importvariable(vs:tglobalvarsym;const name,module:string);
  147. begin
  148. importvariable_str(vs.mangledname,name,module);
  149. end;
  150. procedure timportlibwin32.importvariable_str(const s:string;const name,module:string);
  151. var
  152. hp1 : timportList;
  153. hp2 : twin32imported_item;
  154. hs : string;
  155. begin
  156. hs:=AddExtension(module,target_info.sharedlibext);
  157. { search for the module }
  158. hp1:=timportlist(current_module.imports.first);
  159. while assigned(hp1) do
  160. begin
  161. if hs=hp1.dllname^ then
  162. break;
  163. hp1:=timportlist(hp1.next);
  164. end;
  165. { generate a new item ? }
  166. if not(assigned(hp1)) then
  167. begin
  168. hp1:=timportlist.create(hs);
  169. current_module.imports.concat(hp1);
  170. end;
  171. hp2:=twin32imported_item.create_var(s,name);
  172. hp1.imported_items.concat(hp2);
  173. end;
  174. procedure timportlibwin32.generateimportlib;
  175. var
  176. ObjWriter : tarobjectwriter;
  177. ObjOutput : TPECoffObjOutput;
  178. basedllname : string;
  179. AsmPrefix : string;
  180. idatalabnr,
  181. SmartFilesCount,
  182. SmartHeaderCount : longint;
  183. function CreateObjData(place:tcutplace):TObjData;
  184. var
  185. s : string;
  186. begin
  187. s:='';
  188. case place of
  189. cut_begin :
  190. begin
  191. inc(SmartHeaderCount);
  192. s:=asmprefix+tostr(SmartHeaderCount)+'h';
  193. end;
  194. cut_normal :
  195. s:=asmprefix+tostr(SmartHeaderCount)+'s';
  196. cut_end :
  197. s:=asmprefix+tostr(SmartHeaderCount)+'t';
  198. end;
  199. inc(SmartFilesCount);
  200. result:=ObjOutput.NewObjData(FixFileName(s+tostr(SmartFilesCount)+target_info.objext));
  201. ObjOutput.startobjectfile(Result.Name);
  202. end;
  203. procedure WriteObjData(objdata:TObjData);
  204. begin
  205. ObjOutput.writeobjectfile(ObjData);
  206. end;
  207. procedure StartImport(const dllname:string);
  208. var
  209. headlabel,
  210. idata4label,
  211. idata5label,
  212. idata7label : TObjSymbol;
  213. emptyint : longint;
  214. objdata : TObjData;
  215. idata2objsection,
  216. idata4objsection,
  217. idata5objsection : TObjSection;
  218. begin
  219. objdata:=CreateObjData(cut_begin);
  220. idata2objsection:=objdata.createsection(sec_idata2,'');
  221. idata4objsection:=objdata.createsection(sec_idata4,'');
  222. idata5objsection:=objdata.createsection(sec_idata5,'');
  223. emptyint:=0;
  224. basedllname:=splitfilename(dllname);
  225. { idata4 }
  226. objdata.SetSection(idata4objsection);
  227. idata4label:=objdata.SymbolDefine(asmprefix+'_names_'+basedllname,AB_GLOBAL,AT_DATA);
  228. { idata5 }
  229. objdata.SetSection(idata5objsection);
  230. idata5label:=objdata.SymbolDefine(asmprefix+'_fixup_'+basedllname,AB_GLOBAL,AT_DATA);
  231. { idata2 }
  232. objdata.SetSection(idata2objsection);
  233. headlabel:=objdata.SymbolDefine(asmprefix+'_head_'+basedllname,AB_GLOBAL,AT_DATA);
  234. ObjOutput.exportsymbol(headlabel);
  235. objdata.writereloc(0,sizeof(longint),idata4label,RELOC_RVA);
  236. objdata.writebytes(emptyint,sizeof(emptyint));
  237. objdata.writebytes(emptyint,sizeof(emptyint));
  238. idata7label:=objdata.SymbolRef(asmprefix+'_dll_'+basedllname);
  239. objdata.writereloc(0,sizeof(longint),idata7label,RELOC_RVA);
  240. objdata.writereloc(0,sizeof(longint),idata5label,RELOC_RVA);
  241. WriteObjData(objdata);
  242. objdata.free;
  243. end;
  244. procedure EndImport;
  245. var
  246. idata7label : TObjSymbol;
  247. emptyint : longint;
  248. objdata : TObjData;
  249. idata4objsection,
  250. idata5objsection,
  251. idata7objsection : TObjSection;
  252. begin
  253. objdata:=CreateObjData(cut_end);
  254. idata4objsection:=objdata.createsection(sec_idata4,'');
  255. idata5objsection:=objdata.createsection(sec_idata5,'');
  256. idata7objsection:=objdata.createsection(sec_idata7,'');
  257. emptyint:=0;
  258. { idata4 }
  259. objdata.SetSection(idata4objsection);
  260. objdata.writebytes(emptyint,sizeof(emptyint));
  261. if target_info.system=system_x86_64_win64 then
  262. objdata.writebytes(emptyint,sizeof(emptyint));
  263. { idata5 }
  264. objdata.SetSection(idata5objsection);
  265. objdata.writebytes(emptyint,sizeof(emptyint));
  266. if target_info.system=system_x86_64_win64 then
  267. objdata.writebytes(emptyint,sizeof(emptyint));
  268. { idata7 }
  269. objdata.SetSection(idata7objsection);
  270. idata7label:=objdata.SymbolDefine(asmprefix+'_dll_'+basedllname,AB_GLOBAL,AT_DATA);
  271. objoutput.exportsymbol(idata7label);
  272. objdata.writebytes(basedllname[1],length(basedllname));
  273. objdata.writebytes(emptyint,1);
  274. WriteObjData(objdata);
  275. objdata.free;
  276. end;
  277. procedure AddImport(const afuncname:string;ordnr:word;isvar:boolean);
  278. const
  279. {$ifdef x86_64}
  280. jmpopcode : array[0..2] of byte = (
  281. $ff,$24,$25
  282. );
  283. {$else x86_64}
  284. {$ifdef arm}
  285. jmpopcode : array[0..7] of byte = (
  286. $00,$c0,$9f,$e5, // ldr ip, [pc, #0]
  287. $00,$f0,$9c,$e5 // ldr pc, [ip]
  288. );
  289. {$else arm}
  290. jmpopcode : array[0..1] of byte = (
  291. $ff,$25
  292. );
  293. {$endif arm}
  294. {$endif x86_64}
  295. nopopcodes : array[0..1] of byte = (
  296. $90,$90
  297. );
  298. var
  299. implabel,
  300. idata2label,
  301. idata5label,
  302. idata6label : TObjSymbol;
  303. emptyint : longint;
  304. objdata : TObjData;
  305. textobjsection,
  306. idata4objsection,
  307. idata5objsection,
  308. idata6objsection,
  309. idata7objsection : TObjSection;
  310. begin
  311. objdata:=CreateObjData(cut_normal);
  312. if not isvar then
  313. textobjsection:=objdata.createsection(sec_code,'');
  314. idata4objsection:=objdata.createsection(sec_idata4,'');
  315. idata5objsection:=objdata.createsection(sec_idata5,'');
  316. idata6objsection:=objdata.createsection(sec_idata6,'');
  317. idata7objsection:=objdata.createsection(sec_idata7,'');
  318. emptyint:=0;
  319. { idata7, link to head }
  320. objdata.SetSection(idata7objsection);
  321. idata2label:=objdata.SymbolRef(asmprefix+'_head_'+basedllname);
  322. objdata.writereloc(0,sizeof(longint),idata2label,RELOC_RVA);
  323. { idata6, import data (ordnr+name) }
  324. objdata.SetSection(idata6objsection);
  325. inc(idatalabnr);
  326. idata6label:=objdata.SymbolDefine(asmprefix+'_'+tostr(idatalabnr),AB_LOCAL,AT_DATA);
  327. objdata.writebytes(ordnr,2);
  328. objdata.writebytes(afuncname[1],length(afuncname));
  329. objdata.writebytes(emptyint,1);
  330. objdata.writebytes(emptyint,align(objdata.CurrObjSec.size,2)-objdata.CurrObjSec.size);
  331. { idata4, import lookup table }
  332. objdata.SetSection(idata4objsection);
  333. objdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
  334. if target_info.system=system_x86_64_win64 then
  335. objdata.writebytes(emptyint,sizeof(emptyint));
  336. { idata5, import address table }
  337. objdata.SetSection(idata5objsection);
  338. if isvar then
  339. implabel:=objdata.SymbolDefine(afuncname,AB_GLOBAL,AT_DATA)
  340. else
  341. idata5label:=objdata.SymbolDefine(asmprefix+'_'+afuncname,AB_LOCAL,AT_DATA);
  342. objdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
  343. if target_info.system=system_x86_64_win64 then
  344. objdata.writebytes(emptyint,sizeof(emptyint));
  345. { text, jmp }
  346. if not isvar then
  347. begin
  348. objdata.SetSection(textobjsection);
  349. implabel:=objdata.SymbolDefine(afuncname,AB_GLOBAL,AT_FUNCTION);
  350. objdata.writebytes(jmpopcode,sizeof(jmpopcode));
  351. objdata.writereloc(0,sizeof(longint),idata5label,RELOC_ABSOLUTE32);
  352. objdata.writebytes(nopopcodes,align(objdata.CurrObjSec.size,sizeof(nopopcodes))-objdata.CurrObjSec.size);
  353. end;
  354. ObjOutput.exportsymbol(implabel);
  355. WriteObjData(objdata);
  356. objdata.free;
  357. end;
  358. var
  359. hp1 : timportList;
  360. hp2 : twin32imported_item;
  361. begin
  362. AsmPrefix:='imp'+Lower(current_module.modulename^);
  363. idatalabnr:=0;
  364. SmartFilesCount:=0;
  365. SmartHeaderCount:=0;
  366. current_module.linkotherstaticlibs.add(current_module.importlibfilename^,link_always);
  367. ObjWriter:=TARObjectWriter.create(current_module.importlibfilename^);
  368. ObjOutput:=TPECoffObjOutput.Create(ObjWriter);
  369. hp1:=timportlist(current_module.imports.first);
  370. while assigned(hp1) do
  371. begin
  372. StartImport(hp1.dllname^);
  373. hp2:=twin32imported_item(hp1.imported_items.first);
  374. while assigned(hp2) do
  375. begin
  376. AddImport(hp2.name^,hp2.ordnr,hp2.is_var);
  377. hp2:=twin32imported_item(hp2.next);
  378. end;
  379. EndImport;
  380. hp1:=timportlist(hp1.next);
  381. end;
  382. ObjOutput.Free;
  383. ObjWriter.Free;
  384. end;
  385. procedure timportlibwin32.generateidatasection;
  386. var
  387. hp1 : timportList;
  388. hp2 : twin32imported_item;
  389. l1,l2,l3,l4 {$ifdef ARM} ,l5 {$endif ARM} : tasmlabel;
  390. importname : string;
  391. suffix : integer;
  392. href : treference;
  393. begin
  394. if (target_asm.id in [as_i386_masm,as_i386_tasm,as_i386_nasmwin32]) then
  395. begin
  396. new_section(current_asmdata.asmlists[al_imports],sec_code,'',0);
  397. hp1:=timportlist(current_module.imports.first);
  398. while assigned(hp1) do
  399. begin
  400. hp2:=twin32imported_item(hp1.imported_items.first);
  401. while assigned(hp2) do
  402. begin
  403. current_asmdata.asmlists[al_imports].concat(tai_directive.create(asd_extern,hp2.func^));
  404. current_asmdata.asmlists[al_imports].concat(tai_directive.create(asd_nasm_import,hp2.func^+' '+hp1.dllname^+' '+hp2.name^));
  405. hp2:=twin32imported_item(hp2.next);
  406. end;
  407. hp1:=timportlist(hp1.next);
  408. end;
  409. exit;
  410. end;
  411. hp1:=timportlist(current_module.imports.first);
  412. while assigned(hp1) do
  413. begin
  414. { align al_procedures for the jumps }
  415. new_section(current_asmdata.asmlists[al_imports],sec_code,'',sizeof(aint));
  416. { Get labels for the sections }
  417. current_asmdata.getjumplabel(l1);
  418. current_asmdata.getjumplabel(l2);
  419. current_asmdata.getjumplabel(l3);
  420. new_section(current_asmdata.asmlists[al_imports],sec_idata2,'',0);
  421. { pointer to procedure names }
  422. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(l2));
  423. { two empty entries follow }
  424. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  425. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  426. { pointer to dll name }
  427. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(l1));
  428. { pointer to fixups }
  429. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(l3));
  430. { only create one section for each else it will
  431. create a lot of idata* }
  432. { first write the name references }
  433. new_section(current_asmdata.asmlists[al_imports],sec_idata4,'',0);
  434. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l2));
  435. hp2:=twin32imported_item(hp1.imported_items.first);
  436. while assigned(hp2) do
  437. begin
  438. current_asmdata.getjumplabel(tasmlabel(hp2.lab));
  439. if hp2.name^<>'' then
  440. begin
  441. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(hp2.lab));
  442. if target_info.system=system_x86_64_win64 then
  443. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  444. end
  445. else
  446. begin
  447. if target_info.system=system_x86_64_win64 then
  448. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_64bit(int64($8000000000000000) or hp2.ordnr))
  449. else
  450. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(longint($80000000) or hp2.ordnr));
  451. end;
  452. hp2:=twin32imported_item(hp2.next);
  453. end;
  454. { finalize the names ... }
  455. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  456. if target_info.system=system_x86_64_win64 then
  457. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  458. { then the addresses and create also the indirect jump }
  459. new_section(current_asmdata.asmlists[al_imports],sec_idata5,'',0);
  460. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l3));
  461. hp2:=twin32imported_item(hp1.imported_items.first);
  462. while assigned(hp2) do
  463. begin
  464. if not hp2.is_var then
  465. begin
  466. current_asmdata.getjumplabel(l4);
  467. {$ifdef ARM}
  468. current_asmdata.getjumplabel(l5);
  469. {$endif ARM}
  470. { create indirect jump and }
  471. { place jump in al_procedures }
  472. new_section(current_asmdata.asmlists[al_imports],sec_code,'',0);
  473. current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(target_info.cprefix+hp2.func^,AT_FUNCTION,0));
  474. current_asmdata.asmlists[al_imports].concat(tai_function_name.create(''));
  475. {$ifdef ARM}
  476. reference_reset_symbol(href,l5,0);
  477. current_asmdata.asmlists[al_imports].concat(Taicpu.op_reg_ref(A_LDR,NR_R12,href));
  478. reference_reset_base(href,NR_R12,0);
  479. current_asmdata.asmlists[al_imports].concat(Taicpu.op_reg_ref(A_LDR,NR_R15,href));
  480. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l5));
  481. reference_reset_symbol(href,l4,0);
  482. current_asmdata.asmlists[al_imports].concat(tai_const.create_sym_offset(href.symbol,href.offset));
  483. {$else ARM}
  484. reference_reset_symbol(href,l4,0);
  485. current_asmdata.asmlists[al_imports].concat(Taicpu.Op_ref(A_JMP,S_NO,href));
  486. current_asmdata.asmlists[al_imports].concat(Tai_align.Create_op(4,$90));
  487. {$endif ARM}
  488. { add jump field to al_imports }
  489. new_section(current_asmdata.asmlists[al_imports],sec_idata5,'',0);
  490. if (cs_debuginfo in aktmoduleswitches) then
  491. begin
  492. if assigned(hp2.name) then
  493. begin
  494. importname:='__imp_'+hp2.name^;
  495. suffix:=0;
  496. while assigned(current_asmdata.getasmsymbol(importname)) do
  497. begin
  498. inc(suffix);
  499. importname:='__imp_'+hp2.name^+'_'+tostr(suffix);
  500. end;
  501. current_asmdata.asmlists[al_imports].concat(tai_symbol.createname(importname,AT_FUNCTION,4));
  502. end
  503. else
  504. begin
  505. importname:='__imp_by_ordinal'+tostr(hp2.ordnr);
  506. suffix:=0;
  507. while assigned(current_asmdata.getasmsymbol(importname)) do
  508. begin
  509. inc(suffix);
  510. importname:='__imp_by_ordinal'+tostr(hp2.ordnr)+'_'+tostr(suffix);
  511. end;
  512. current_asmdata.asmlists[al_imports].concat(tai_symbol.createname(importname,AT_FUNCTION,4));
  513. end;
  514. end;
  515. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l4));
  516. end
  517. else
  518. begin
  519. current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(hp2.func^,AT_DATA,0));
  520. end;
  521. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(hp2.lab));
  522. if target_info.system=system_x86_64_win64 then
  523. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  524. hp2:=twin32imported_item(hp2.next);
  525. end;
  526. { finalize the addresses }
  527. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  528. if target_info.system=system_x86_64_win64 then
  529. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  530. { finally the import information }
  531. new_section(current_asmdata.asmlists[al_imports],sec_idata6,'',0);
  532. hp2:=twin32imported_item(hp1.imported_items.first);
  533. while assigned(hp2) do
  534. begin
  535. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(hp2.lab));
  536. { the ordinal number }
  537. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_16bit(hp2.ordnr));
  538. current_asmdata.asmlists[al_imports].concat(Tai_string.Create(hp2.name^+#0));
  539. current_asmdata.asmlists[al_imports].concat(Tai_align.Create_op(2,0));
  540. hp2:=twin32imported_item(hp2.next);
  541. end;
  542. { create import dll name }
  543. new_section(current_asmdata.asmlists[al_imports],sec_idata7,'',0);
  544. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l1));
  545. current_asmdata.asmlists[al_imports].concat(Tai_string.Create(hp1.dllname^+#0));
  546. hp1:=timportlist(hp1.next);
  547. end;
  548. end;
  549. procedure timportlibwin32.generatelib;
  550. begin
  551. if GenerateImportSection then
  552. generateidatasection
  553. else
  554. generateimportlib;
  555. end;
  556. {*****************************************************************************
  557. TEXPORTLIBWIN32
  558. *****************************************************************************}
  559. procedure texportlibwin32.preparelib(const s:string);
  560. begin
  561. if current_asmdata.asmlists[al_exports]=nil then
  562. current_asmdata.asmlists[al_exports]:=TAsmList.create;
  563. EList_indexed:=tFPList.Create;
  564. EList_nonindexed:=tFPList.Create;
  565. current_asmdata.getdatalabel(edatalabel);
  566. end;
  567. procedure texportlibwin32.exportvar(hp : texported_item);
  568. begin
  569. { same code used !! PM }
  570. exportprocedure(hp);
  571. end;
  572. var
  573. Gl_DoubleIndex:boolean;
  574. Gl_DoubleIndexValue:longint;
  575. function IdxCompare(Item1, Item2: Pointer): Integer;
  576. var
  577. I1:texported_item absolute Item1;
  578. I2:texported_item absolute Item2;
  579. begin
  580. Result:=I1.index-I2.index;
  581. if(Result=0)and(Item1<>Item2)then
  582. begin
  583. Gl_DoubleIndex:=true;
  584. Gl_DoubleIndexValue:=I1.index;
  585. end;
  586. end;
  587. procedure texportlibwin32.exportprocedure(hp : texported_item);
  588. begin
  589. if ((hp.options and eo_index)<>0)and((hp.index<=0) or (hp.index>$ffff)) then
  590. begin
  591. message1(parser_e_export_invalid_index,tostr(hp.index));
  592. exit;
  593. end;
  594. if hp.options and eo_index=eo_index then
  595. EList_indexed.Add(hp)
  596. else
  597. EList_nonindexed.Add(hp);
  598. end;
  599. procedure texportlibwin32.exportfromlist(hp : texported_item);
  600. //formerly texportlibwin32.exportprocedure
  601. { must be ordered at least for win32 !! }
  602. var
  603. hp2 : texported_item;
  604. begin
  605. hp2:=texported_item(current_module._exports.first);
  606. while assigned(hp2) and
  607. (hp.name^>hp2.name^) do
  608. hp2:=texported_item(hp2.next);
  609. { insert hp there !! }
  610. if hp2=nil then
  611. current_module._exports.concat(hp)
  612. else
  613. begin
  614. if hp2.name^=hp.name^ then
  615. begin
  616. { this is not allowed !! }
  617. message1(parser_e_export_name_double,hp.name^);
  618. exit;
  619. end;
  620. current_module._exports.insertbefore(hp,hp2);
  621. end;
  622. end;
  623. procedure texportlibwin32.generatelib;
  624. var
  625. ordinal_base,ordinal_max,ordinal_min : longint;
  626. current_index : longint;
  627. entries,named_entries : longint;
  628. name_label,dll_name_label,export_address_table : tasmlabel;
  629. export_name_table_pointers,export_ordinal_table : tasmlabel;
  630. hp,hp2 : texported_item;
  631. temtexport : TLinkedList;
  632. address_table,name_table_pointers,
  633. name_table,ordinal_table : TAsmList;
  634. i,autoindex,ni_high : longint;
  635. hole : boolean;
  636. begin
  637. Gl_DoubleIndex:=false;
  638. ELIst_indexed.Sort(@IdxCompare);
  639. if Gl_DoubleIndex then
  640. begin
  641. message1(parser_e_export_ordinal_double,tostr(Gl_DoubleIndexValue));
  642. EList_indexed.Free;
  643. EList_nonindexed.Free;
  644. exit;
  645. end;
  646. autoindex:=1;
  647. while EList_nonindexed.Count>0 do
  648. begin
  649. hole:=(EList_indexed.Count>0)and(texported_item(EList_indexed.Items[0]).index>1);
  650. if not hole then
  651. for i:=autoindex to pred(EList_indexed.Count)do
  652. if texported_item(EList_indexed.Items[i]).index-texported_item(EList_indexed.Items[pred(i)]).index>1 then
  653. begin
  654. autoindex:=succ(texported_item(EList_indexed.Items[pred(i)]).index);
  655. hole:=true;
  656. break;
  657. end;
  658. ni_high:=pred(EList_nonindexed.Count);
  659. if not hole then
  660. begin
  661. autoindex:=succ(EList_indexed.Count);
  662. EList_indexed.Add(EList_nonindexed.Items[ni_high]);
  663. end
  664. else
  665. EList_indexed.Insert(pred(AutoIndex),EList_nonindexed.Items[ni_high]);
  666. EList_nonindexed.Delete(ni_high);
  667. texported_item(EList_indexed.Items[pred(AutoIndex)]).index:=autoindex;
  668. end;
  669. EList_nonindexed.Free;
  670. for i:=0 to pred(EList_indexed.Count)do
  671. exportfromlist(texported_item(EList_indexed.Items[i]));
  672. EList_indexed.Free;
  673. if (target_asm.id in [as_i386_masm,as_i386_tasm,as_i386_nasmwin32]) then
  674. begin
  675. generatenasmlib;
  676. exit;
  677. end;
  678. hp:=texported_item(current_module._exports.first);
  679. if not assigned(hp) then
  680. exit;
  681. ordinal_max:=0;
  682. ordinal_min:=$7FFFFFFF;
  683. entries:=0;
  684. named_entries:=0;
  685. current_asmdata.getjumplabel(dll_name_label);
  686. current_asmdata.getjumplabel(export_address_table);
  687. current_asmdata.getjumplabel(export_name_table_pointers);
  688. current_asmdata.getjumplabel(export_ordinal_table);
  689. { count entries }
  690. while assigned(hp) do
  691. begin
  692. inc(entries);
  693. if (hp.index>ordinal_max) then
  694. ordinal_max:=hp.index;
  695. if (hp.index>0) and (hp.index<ordinal_min) then
  696. ordinal_min:=hp.index;
  697. if assigned(hp.name) then
  698. inc(named_entries);
  699. hp:=texported_item(hp.next);
  700. end;
  701. { no support for higher ordinal base yet !! }
  702. ordinal_base:=1;
  703. current_index:=ordinal_base;
  704. { we must also count the holes !! }
  705. entries:=ordinal_max-ordinal_base+1;
  706. new_section(current_asmdata.asmlists[al_exports],sec_edata,'',0);
  707. { create label to reference from main so smartlink will include
  708. the .edata section }
  709. current_asmdata.asmlists[al_exports].concat(Tai_symbol.Create_global(edatalabel,0));
  710. { export flags }
  711. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_32bit(0));
  712. { date/time stamp }
  713. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_32bit(0));
  714. { major version }
  715. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_16bit(0));
  716. { minor version }
  717. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_16bit(0));
  718. { pointer to dll name }
  719. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_rva_sym(dll_name_label));
  720. { ordinal base normally set to 1 }
  721. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_32bit(ordinal_base));
  722. { number of entries }
  723. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_32bit(entries));
  724. { number of named entries }
  725. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_32bit(named_entries));
  726. { address of export address table }
  727. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_rva_sym(export_address_table));
  728. { address of name pointer pointers }
  729. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_rva_sym(export_name_table_pointers));
  730. { address of ordinal number pointers }
  731. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_rva_sym(export_ordinal_table));
  732. { the name }
  733. current_asmdata.asmlists[al_exports].concat(Tai_label.Create(dll_name_label));
  734. if st='' then
  735. current_asmdata.asmlists[al_exports].concat(Tai_string.Create(current_module.modulename^+target_info.sharedlibext+#0))
  736. else
  737. current_asmdata.asmlists[al_exports].concat(Tai_string.Create(st+target_info.sharedlibext+#0));
  738. { export address table }
  739. address_table:=TAsmList.create;
  740. address_table.concat(Tai_align.Create_op(4,0));
  741. address_table.concat(Tai_label.Create(export_address_table));
  742. name_table_pointers:=TAsmList.create;
  743. name_table_pointers.concat(Tai_align.Create_op(4,0));
  744. name_table_pointers.concat(Tai_label.Create(export_name_table_pointers));
  745. ordinal_table:=TAsmList.create;
  746. ordinal_table.concat(Tai_align.Create_op(4,0));
  747. ordinal_table.concat(Tai_label.Create(export_ordinal_table));
  748. name_table:=TAsmList.Create;
  749. name_table.concat(Tai_align.Create_op(4,0));
  750. { write each address }
  751. hp:=texported_item(current_module._exports.first);
  752. while assigned(hp) do
  753. begin
  754. if (hp.options and eo_name)<>0 then
  755. begin
  756. current_asmdata.getjumplabel(name_label);
  757. name_table_pointers.concat(Tai_const.Create_rva_sym(name_label));
  758. ordinal_table.concat(Tai_const.Create_16bit(hp.index-ordinal_base));
  759. name_table.concat(Tai_align.Create_op(2,0));
  760. name_table.concat(Tai_label.Create(name_label));
  761. name_table.concat(Tai_string.Create(hp.name^+#0));
  762. end;
  763. hp:=texported_item(hp.next);
  764. end;
  765. { order in increasing ordinal values }
  766. { into temtexport list }
  767. temtexport:=TLinkedList.Create;
  768. hp:=texported_item(current_module._exports.first);
  769. while assigned(hp) do
  770. begin
  771. current_module._exports.remove(hp);
  772. hp2:=texported_item(temtexport.first);
  773. while assigned(hp2) and (hp.index>hp2.index) do
  774. hp2:=texported_item(hp2.next);
  775. if hp2=nil then
  776. temtexport.concat(hp)
  777. else
  778. temtexport.insertbefore(hp,hp2);
  779. hp:=texported_item(current_module._exports.first);;
  780. end;
  781. { write the export adress table }
  782. current_index:=ordinal_base;
  783. hp:=texported_item(temtexport.first);
  784. while assigned(hp) do
  785. begin
  786. { fill missing values }
  787. while current_index<hp.index do
  788. begin
  789. address_table.concat(Tai_const.Create_32bit(0));
  790. inc(current_index);
  791. end;
  792. case hp.sym.typ of
  793. globalvarsym :
  794. address_table.concat(Tai_const.Createname_rva(tglobalvarsym(hp.sym).mangledname));
  795. typedconstsym :
  796. address_table.concat(Tai_const.Createname_rva(ttypedconstsym(hp.sym).mangledname));
  797. procsym :
  798. address_table.concat(Tai_const.Createname_rva(tprocsym(hp.sym).first_procdef.mangledname));
  799. end;
  800. inc(current_index);
  801. hp:=texported_item(hp.next);
  802. end;
  803. current_asmdata.asmlists[al_exports].concatlist(address_table);
  804. current_asmdata.asmlists[al_exports].concatlist(name_table_pointers);
  805. current_asmdata.asmlists[al_exports].concatlist(ordinal_table);
  806. current_asmdata.asmlists[al_exports].concatlist(name_table);
  807. address_table.Free;
  808. name_table_pointers.free;
  809. ordinal_table.free;
  810. name_table.free;
  811. temtexport.free;
  812. end;
  813. procedure texportlibwin32.generatenasmlib;
  814. var
  815. hp : texported_item;
  816. p : pchar;
  817. s : string;
  818. begin
  819. new_section(current_asmdata.asmlists[al_exports],sec_code,'',0);
  820. hp:=texported_item(current_module._exports.first);
  821. while assigned(hp) do
  822. begin
  823. case hp.sym.typ of
  824. globalvarsym :
  825. s:=tglobalvarsym(hp.sym).mangledname;
  826. typedconstsym :
  827. s:=ttypedconstsym(hp.sym).mangledname;
  828. procsym :
  829. s:=tprocsym(hp.sym).first_procdef.mangledname;
  830. else
  831. s:='';
  832. end;
  833. p:=strpnew(#9+'export '+s+' '+hp.name^+' '+tostr(hp.index));
  834. {current_asmdata.asmlists[al_exports].concat(tai_direct.create(p));}
  835. hp:=texported_item(hp.next);
  836. end;
  837. end;
  838. {****************************************************************************
  839. TLINKERWIN32
  840. ****************************************************************************}
  841. Constructor TLinkerWin32.Create;
  842. begin
  843. Inherited Create;
  844. { allow duplicated libs (PM) }
  845. SharedLibFiles.doubles:=true;
  846. StaticLibFiles.doubles:=true; if not Dontlinkstdlibpath Then
  847. end;
  848. Procedure TLinkerWin32.SetDefaultInfo;
  849. var
  850. targetopts: string;
  851. begin
  852. with Info do
  853. begin
  854. {$ifdef ARM}
  855. targetopts:='-m armpe';
  856. {$else ARM}
  857. targetopts:='-b pe-i386 -m i386pe';
  858. {$endif ARM}
  859. ExeCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $MAP $STRIP $APPTYPE $ENTRY $IMAGEBASE $RELOC -o $EXE $RES';
  860. DllCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $MAP $STRIP --dll $APPTYPE $ENTRY $IMAGEBASE $RELOC -o $EXE $RES';
  861. { ExeCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF';
  862. use short forms to avoid 128 char limitation problem }
  863. ExeCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
  864. ExeCmd[3]:='ld '+targetopts+' $OPT $STRIP $APPTYPE $ENTRY $IMAGEBASE -o $EXE $RES exp.$$$';
  865. { DllCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF'; }
  866. DllCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
  867. DllCmd[3]:='ld '+targetopts+' $OPT $STRIP --dll $APPTYPE $ENTRY $IMAGEBASE -o $EXE $RES exp.$$$';
  868. end;
  869. end;
  870. Function TLinkerWin32.WriteResponseFile(isdll:boolean) : Boolean;
  871. Var
  872. linkres : TLinkRes;
  873. HPath : TStringListItem;
  874. s,s2 : string;
  875. i : integer;
  876. linklibcygwin : boolean;
  877. begin
  878. WriteResponseFile:=False;
  879. linklibcygwin:=(SharedLibFiles.Find('cygwin')<>nil);
  880. if (cs_profile in aktmoduleswitches) then
  881. begin
  882. SharedLibFiles.Concat('gmon');
  883. SharedLibFiles.Concat('c');
  884. SharedLibFiles.Concat('gcc');
  885. SharedLibFiles.Concat('kernel32');
  886. end;
  887. { Open link.res file }
  888. LinkRes:=TLinkres.Create(outputexedir+Info.ResName);
  889. with linkres do
  890. begin
  891. { Write path to search libraries }
  892. HPath:=TStringListItem(current_module.locallibrarysearchpath.First);
  893. while assigned(HPath) do
  894. begin
  895. Add('SEARCH_DIR('+MaybeQuoted(HPath.Str)+')');
  896. HPath:=TStringListItem(HPath.Next);
  897. end;
  898. HPath:=TStringListItem(LibrarySearchPath.First);
  899. while assigned(HPath) do
  900. begin
  901. Add('SEARCH_DIR('+MaybeQuoted(HPath.Str)+')');
  902. HPath:=TStringListItem(HPath.Next);
  903. end;
  904. { add objectfiles, start with prt0 always }
  905. { profiling of shared libraries is currently not supported }
  906. if not ObjectFiles.Empty then
  907. begin
  908. Add('INPUT(');
  909. { For wince external startup file is used and placed first, }
  910. { because ARM prolog structure must be located at the very }
  911. { beginning of code. Otherwise exceptions do not work properly. }
  912. if target_info.system in [system_arm_wince,system_i386_wince] then
  913. LinkRes.AddFileName(MaybeQuoted(FindObjectFile('wprt0','',false)));
  914. while not ObjectFiles.Empty do
  915. begin
  916. s:=ObjectFiles.GetFirst;
  917. if s<>'' then
  918. AddFileName(MaybeQuoted(s));
  919. end;
  920. Add(')');
  921. end;
  922. { Write staticlibraries }
  923. if (not StaticLibFiles.Empty) then
  924. begin
  925. Add('GROUP(');
  926. While not StaticLibFiles.Empty do
  927. begin
  928. S:=StaticLibFiles.GetFirst;
  929. AddFileName(MaybeQuoted(s));
  930. end;
  931. Add(')');
  932. end;
  933. { Write sharedlibraries (=import libraries) }
  934. if not SharedLibFiles.Empty then
  935. begin
  936. Add('INPUT(') ;
  937. While not SharedLibFiles.Empty do
  938. begin
  939. S:=SharedLibFiles.GetFirst;
  940. if FindLibraryFile(s,target_info.staticClibprefix,target_info.staticClibext,s2) then
  941. begin
  942. Add(MaybeQuoted(s2));
  943. continue;
  944. end;
  945. if pos(target_info.sharedlibprefix,s)=1 then
  946. s:=copy(s,length(target_info.sharedlibprefix)+1,255);
  947. i:=Pos(target_info.sharedlibext,S);
  948. if i>0 then
  949. Delete(S,i,255);
  950. Add('-l'+s);
  951. end;
  952. Add(')');
  953. end;
  954. Add('SEARCH_DIR("/usr/i686-pc-cygwin/lib"); SEARCH_DIR("/usr/lib"); SEARCH_DIR("/usr/lib/w32api");');
  955. Add('OUTPUT_FORMAT(pei-i386)');
  956. Add('ENTRY(_mainCRTStartup)');
  957. Add('SECTIONS');
  958. Add('{');
  959. Add(' . = SIZEOF_HEADERS;');
  960. Add(' . = ALIGN(__section_alignment__);');
  961. Add(' .text __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :');
  962. Add(' {');
  963. Add(' *(.init)');
  964. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  965. Add(' *(SORT(.text$*))');
  966. Add(' ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;');
  967. Add(' LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0);');
  968. Add(' ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;');
  969. Add(' LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0);');
  970. Add(' *(.fini)');
  971. Add(' PROVIDE (etext = .);');
  972. Add(' *(.gcc_except_table)');
  973. Add(' }');
  974. Add(' .data BLOCK(__section_alignment__) :');
  975. Add(' {');
  976. Add(' __data_start__ = . ;');
  977. add(' *(.data .data.* .gnu.linkonce.d.*)');
  978. Add(' *(.data2)');
  979. Add(' *(SORT(.data$*))');
  980. Add(' __data_end__ = . ;');
  981. Add(' *(.data_cygwin_nocopy)');
  982. Add(' }');
  983. Add(' .rdata BLOCK(__section_alignment__) :');
  984. Add(' {');
  985. Add(' *(.rdata)');
  986. add(' *(.rodata .rodata.* .gnu.linkonce.r.*)');
  987. Add(' *(SORT(.rdata$*))');
  988. Add(' *(.eh_frame)');
  989. Add(' ___RUNTIME_PSEUDO_RELOC_LIST__ = .;');
  990. Add(' __RUNTIME_PSEUDO_RELOC_LIST__ = .;');
  991. Add(' *(.rdata_runtime_pseudo_reloc)');
  992. Add(' ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;');
  993. Add(' __RUNTIME_PSEUDO_RELOC_LIST_END__ = .;');
  994. Add(' }');
  995. Add(' .pdata BLOCK(__section_alignment__) : { *(.pdata) }');
  996. Add(' .bss BLOCK(__section_alignment__) :');
  997. Add(' {');
  998. Add(' __bss_start__ = . ;');
  999. Add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  1000. Add(' *(SORT(.bss$*))');
  1001. Add(' *(COMMON)');
  1002. Add(' __bss_end__ = . ;');
  1003. Add(' }');
  1004. Add(' .edata BLOCK(__section_alignment__) : { *(.edata) }');
  1005. Add(' .idata BLOCK(__section_alignment__) :');
  1006. Add(' {');
  1007. Add(' SORT(*)(.idata$2)');
  1008. Add(' SORT(*)(.idata$3)');
  1009. Add(' /* These zeroes mark the end of the import list. */');
  1010. Add(' LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);');
  1011. Add(' SORT(*)(.idata$4)');
  1012. Add(' SORT(*)(.idata$5)');
  1013. Add(' SORT(*)(.idata$6)');
  1014. Add(' SORT(*)(.idata$7)');
  1015. Add(' }');
  1016. Add(' .CRT BLOCK(__section_alignment__) :');
  1017. Add(' {');
  1018. Add(' ___crt_xc_start__ = . ;');
  1019. Add(' *(SORT(.CRT$XC*)) /* C initialization */');
  1020. Add(' ___crt_xc_end__ = . ;');
  1021. Add(' ___crt_xi_start__ = . ;');
  1022. Add(' *(SORT(.CRT$XI*)) /* C++ initialization */');
  1023. Add(' ___crt_xi_end__ = . ;');
  1024. Add(' ___crt_xl_start__ = . ;');
  1025. Add(' *(SORT(.CRT$XL*)) /* TLS callbacks */');
  1026. Add(' /* ___crt_xl_end__ is defined in the TLS Directory support code */');
  1027. Add(' ___crt_xp_start__ = . ;');
  1028. Add(' *(SORT(.CRT$XP*)) /* Pre-termination */');
  1029. Add(' ___crt_xp_end__ = . ;');
  1030. Add(' ___crt_xt_start__ = . ;');
  1031. Add(' *(SORT(.CRT$XT*)) /* Termination */');
  1032. Add(' ___crt_xt_end__ = . ;');
  1033. Add(' }');
  1034. Add(' .tls BLOCK(__section_alignment__) :');
  1035. Add(' {');
  1036. Add(' ___tls_start__ = . ;');
  1037. Add(' *(.tls .tls.*)');
  1038. Add(' *(.tls$)');
  1039. Add(' *(SORT(.tls$*))');
  1040. Add(' ___tls_end__ = . ;');
  1041. Add(' }');
  1042. Add(' .rsrc BLOCK(__section_alignment__) :');
  1043. Add(' {');
  1044. Add(' *(.rsrc)');
  1045. Add(' *(SORT(.rsrc$*))');
  1046. Add(' }');
  1047. Add(' .reloc BLOCK(__section_alignment__) : { *(.reloc) }');
  1048. Add(' .stab BLOCK(__section_alignment__) (NOLOAD) : { *(.stab) }');
  1049. Add(' .stabstr BLOCK(__section_alignment__) (NOLOAD) : { *(.stabstr) }');
  1050. Add(' .debug_aranges BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_aranges) }');
  1051. Add(' .debug_pubnames BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_pubnames) }');
  1052. Add(' .debug_info BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_info) *(.gnu.linkonce.wi.*) }');
  1053. Add(' .debug_abbrev BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_abbrev) }');
  1054. Add(' .debug_line BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_line) }');
  1055. Add(' .debug_frame BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_frame) }');
  1056. Add(' .debug_str BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_str) }');
  1057. Add(' .debug_loc BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_loc) }');
  1058. Add(' .debug_macinfo BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_macinfo) }');
  1059. Add(' .debug_weaknames BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_weaknames) }');
  1060. Add(' .debug_funcnames BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_funcnames) }');
  1061. Add(' .debug_typenames BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_typenames) }');
  1062. Add(' .debug_varnames BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_varnames) }');
  1063. Add(' .debug_ranges BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_ranges) }');
  1064. Add('}');
  1065. { Write and Close response }
  1066. writetodisk;
  1067. Free;
  1068. end;
  1069. WriteResponseFile:=True;
  1070. end;
  1071. function TLinkerWin32.MakeExecutable:boolean;
  1072. var
  1073. MapStr,
  1074. binstr : String;
  1075. cmdstr : TCmdStr;
  1076. success : boolean;
  1077. cmds,i : longint;
  1078. AsBinStr : string[80];
  1079. GCSectionsStr,
  1080. StripStr,
  1081. RelocStr,
  1082. AppTypeStr,
  1083. EntryStr,
  1084. ImageBaseStr : string[40];
  1085. begin
  1086. if not(cs_link_nolink in aktglobalswitches) then
  1087. Message1(exec_i_linking,current_module.exefilename^);
  1088. { Create some replacements }
  1089. RelocStr:='';
  1090. AppTypeStr:='';
  1091. EntryStr:='';
  1092. ImageBaseStr:='';
  1093. StripStr:='';
  1094. MapStr:='';
  1095. GCSectionsStr:='';
  1096. AsBinStr:=FindUtil(utilsprefix+'as');
  1097. if RelocSection then
  1098. RelocStr:='--base-file base.$$$';
  1099. if use_smartlink_section then
  1100. GCSectionsStr:='--gc-sections';
  1101. if target_info.system in [system_arm_wince,system_i386_wince] then
  1102. AppTypeStr:='--subsystem wince'
  1103. else
  1104. begin
  1105. if apptype=app_gui then
  1106. AppTypeStr:='--subsystem windows';
  1107. end;
  1108. if apptype=app_gui then
  1109. EntryStr:='--entry=_WinMainCRTStartup'
  1110. else
  1111. EntryStr:='--entry=_mainCRTStartup';
  1112. if assigned(DLLImageBase) then
  1113. ImageBaseStr:='--image-base=0x'+DLLImageBase^;
  1114. if (cs_link_strip in aktglobalswitches) then
  1115. StripStr:='-s';
  1116. if (cs_link_map in aktglobalswitches) then
  1117. MapStr:='-Map '+maybequoted(ForceExtension(current_module.exefilename^,'.map'));
  1118. { Write used files and libraries }
  1119. WriteResponseFile(false);
  1120. { Call linker }
  1121. success:=false;
  1122. if RelocSection or (not Deffile.empty) then
  1123. cmds:=3
  1124. else
  1125. cmds:=1;
  1126. for i:=1 to cmds do
  1127. begin
  1128. SplitBinCmd(Info.ExeCmd[i],binstr,cmdstr);
  1129. if binstr<>'' then
  1130. begin
  1131. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename^));
  1132. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1133. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1134. Replace(cmdstr,'$APPTYPE',AppTypeStr);
  1135. Replace(cmdstr,'$ENTRY',EntryStr);
  1136. Replace(cmdstr,'$ASBIN',AsbinStr);
  1137. Replace(cmdstr,'$RELOC',RelocStr);
  1138. Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);
  1139. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1140. Replace(cmdstr,'$STRIP',StripStr);
  1141. Replace(cmdstr,'$MAP',MapStr);
  1142. if not DefFile.Empty then
  1143. begin
  1144. DefFile.WriteFile;
  1145. Replace(cmdstr,'$DEF','-d '+maybequoted(deffile.fname));
  1146. end
  1147. else
  1148. Replace(cmdstr,'$DEF','');
  1149. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,(i=1),false);
  1150. if not success then
  1151. break;
  1152. end;
  1153. end;
  1154. { Post process }
  1155. if success then
  1156. success:=PostProcessExecutable(current_module.exefilename^,false);
  1157. { Remove ReponseFile }
  1158. if (success) and not(cs_link_nolink in aktglobalswitches) then
  1159. begin
  1160. RemoveFile(outputexedir+Info.ResName);
  1161. RemoveFile('base.$$$');
  1162. RemoveFile('exp.$$$');
  1163. RemoveFile('deffile.$$$');
  1164. end;
  1165. MakeExecutable:=success; { otherwise a recursive call to link method }
  1166. end;
  1167. Function TLinkerWin32.MakeSharedLibrary:boolean;
  1168. var
  1169. MapStr,
  1170. binstr : String;
  1171. cmdstr : TCmdStr;
  1172. success : boolean;
  1173. cmds,
  1174. i : longint;
  1175. AsBinStr : string[80];
  1176. StripStr,
  1177. GCSectionsStr,
  1178. RelocStr,
  1179. AppTypeStr,
  1180. EntryStr,
  1181. ImageBaseStr : string[40];
  1182. begin
  1183. MakeSharedLibrary:=false;
  1184. if not(cs_link_nolink in aktglobalswitches) then
  1185. Message1(exec_i_linking,current_module.sharedlibfilename^);
  1186. { Create some replacements }
  1187. RelocStr:='';
  1188. AppTypeStr:='';
  1189. EntryStr:='';
  1190. ImageBaseStr:='';
  1191. StripStr:='';
  1192. MapStr:='';
  1193. GCSectionsStr:='';
  1194. AsBinStr:=FindUtil(utilsprefix+'as');
  1195. if RelocSection then
  1196. RelocStr:='--base-file base.$$$';
  1197. if use_smartlink_section then
  1198. GCSectionsStr:='--gc-sections';
  1199. if apptype=app_gui then
  1200. begin
  1201. AppTypeStr:='--subsystem windows';
  1202. EntryStr:='--entry _DLLWinMainCRTStartup'
  1203. end
  1204. else
  1205. EntryStr:='--entry _DLLMainCRTStartup';
  1206. if assigned(DLLImageBase) then
  1207. ImageBaseStr:='--image-base=0x'+DLLImageBase^;
  1208. if (cs_link_strip in aktglobalswitches) then
  1209. StripStr:='-s';
  1210. if (cs_link_map in aktglobalswitches) then
  1211. MapStr:='-Map '+maybequoted(ForceExtension(current_module.exefilename^,'.map'));
  1212. { Write used files and libraries }
  1213. WriteResponseFile(true);
  1214. { Call linker }
  1215. success:=false;
  1216. if RelocSection or (not Deffile.empty) then
  1217. cmds:=3
  1218. else
  1219. cmds:=1;
  1220. for i:=1 to cmds do
  1221. begin
  1222. SplitBinCmd(Info.DllCmd[i],binstr,cmdstr);
  1223. if binstr<>'' then
  1224. begin
  1225. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
  1226. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1227. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1228. Replace(cmdstr,'$APPTYPE',AppTypeStr);
  1229. Replace(cmdstr,'$ENTRY',EntryStr);
  1230. Replace(cmdstr,'$ASBIN',AsbinStr);
  1231. Replace(cmdstr,'$RELOC',RelocStr);
  1232. Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);
  1233. Replace(cmdstr,'$STRIP',StripStr);
  1234. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1235. Replace(cmdstr,'$MAP',MapStr);
  1236. if not DefFile.Empty then
  1237. begin
  1238. DefFile.WriteFile;
  1239. Replace(cmdstr,'$DEF','-d '+maybequoted(deffile.fname));
  1240. end
  1241. else
  1242. Replace(cmdstr,'$DEF','');
  1243. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,(i=1),false);
  1244. if not success then
  1245. break;
  1246. end;
  1247. end;
  1248. { Post process }
  1249. if success then
  1250. success:=PostProcessExecutable(current_module.sharedlibfilename^,true);
  1251. { Remove ReponseFile }
  1252. if (success) and not(cs_link_nolink in aktglobalswitches) then
  1253. begin
  1254. RemoveFile(outputexedir+Info.ResName);
  1255. RemoveFile('base.$$$');
  1256. RemoveFile('exp.$$$');
  1257. RemoveFile('deffile.$$$');
  1258. end;
  1259. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  1260. end;
  1261. function tlinkerwin32.postprocessexecutable(const fn : string;isdll:boolean):boolean;
  1262. type
  1263. tdosheader = packed record
  1264. e_magic : word;
  1265. e_cblp : word;
  1266. e_cp : word;
  1267. e_crlc : word;
  1268. e_cparhdr : word;
  1269. e_minalloc : word;
  1270. e_maxalloc : word;
  1271. e_ss : word;
  1272. e_sp : word;
  1273. e_csum : word;
  1274. e_ip : word;
  1275. e_cs : word;
  1276. e_lfarlc : word;
  1277. e_ovno : word;
  1278. e_res : array[0..3] of word;
  1279. e_oemid : word;
  1280. e_oeminfo : word;
  1281. e_res2 : array[0..9] of word;
  1282. e_lfanew : longint;
  1283. end;
  1284. tpeheader = packed record
  1285. PEMagic : array[0..3] of char;
  1286. Machine : word;
  1287. NumberOfSections : word;
  1288. TimeDateStamp : longint;
  1289. PointerToSymbolTable : longint;
  1290. NumberOfSymbols : longint;
  1291. SizeOfOptionalHeader : word;
  1292. Characteristics : word;
  1293. Magic : word;
  1294. MajorLinkerVersion : byte;
  1295. MinorLinkerVersion : byte;
  1296. SizeOfCode : longint;
  1297. SizeOfInitializedData : longint;
  1298. SizeOfUninitializedData : longint;
  1299. AddressOfEntryPoint : longint;
  1300. BaseOfCode : longint;
  1301. BaseOfData : longint;
  1302. ImageBase : longint;
  1303. SectionAlignment : longint;
  1304. FileAlignment : longint;
  1305. MajorOperatingSystemVersion : word;
  1306. MinorOperatingSystemVersion : word;
  1307. MajorImageVersion : word;
  1308. MinorImageVersion : word;
  1309. MajorSubsystemVersion : word;
  1310. MinorSubsystemVersion : word;
  1311. Reserved1 : longint;
  1312. SizeOfImage : longint;
  1313. SizeOfHeaders : longint;
  1314. CheckSum : longint;
  1315. Subsystem : word;
  1316. DllCharacteristics : word;
  1317. SizeOfStackReserve : longint;
  1318. SizeOfStackCommit : longint;
  1319. SizeOfHeapReserve : longint;
  1320. SizeOfHeapCommit : longint;
  1321. LoaderFlags : longint;
  1322. NumberOfRvaAndSizes : longint;
  1323. DataDirectory : array[1..$80] of byte;
  1324. end;
  1325. tcoffsechdr=packed record
  1326. name : array[0..7] of char;
  1327. vsize : longint;
  1328. rvaofs : longint;
  1329. datalen : longint;
  1330. datapos : longint;
  1331. relocpos : longint;
  1332. lineno1 : longint;
  1333. nrelocs : word;
  1334. lineno2 : word;
  1335. flags : longint;
  1336. end;
  1337. psecfill=^TSecfill;
  1338. TSecfill=record
  1339. fillpos,
  1340. fillsize : longint;
  1341. next : psecfill;
  1342. end;
  1343. var
  1344. f : file;
  1345. cmdstr : string;
  1346. dosheader : tdosheader;
  1347. peheader : tpeheader;
  1348. firstsecpos,
  1349. maxfillsize,
  1350. l,peheaderpos : longint;
  1351. coffsec : tcoffsechdr;
  1352. secroot,hsecroot : psecfill;
  1353. zerobuf : pointer;
  1354. begin
  1355. postprocessexecutable:=false;
  1356. { when -s is used or it's a dll then quit }
  1357. if (cs_link_nolink in aktglobalswitches) then
  1358. begin
  1359. case apptype of
  1360. app_native :
  1361. cmdstr:='--subsystem native';
  1362. app_gui :
  1363. cmdstr:='--subsystem gui';
  1364. app_cui :
  1365. cmdstr:='--subsystem console';
  1366. end;
  1367. if dllversion<>'' then
  1368. cmdstr:=cmdstr+' --version '+dllversion;
  1369. cmdstr:=cmdstr+' --input '+maybequoted(fn);
  1370. cmdstr:=cmdstr+' --stack '+tostr(stacksize);
  1371. DoExec(FindUtil(utilsprefix+'postw32'),cmdstr,false,false);
  1372. postprocessexecutable:=true;
  1373. exit;
  1374. end;
  1375. { open file }
  1376. assign(f,fn);
  1377. {$I-}
  1378. reset(f,1);
  1379. if ioresult<>0 then
  1380. Message1(execinfo_f_cant_open_executable,fn);
  1381. { read headers }
  1382. blockread(f,dosheader,sizeof(tdosheader));
  1383. peheaderpos:=dosheader.e_lfanew;
  1384. seek(f,peheaderpos);
  1385. blockread(f,peheader,sizeof(tpeheader));
  1386. { write info }
  1387. Message1(execinfo_x_codesize,tostr(peheader.SizeOfCode));
  1388. Message1(execinfo_x_initdatasize,tostr(peheader.SizeOfInitializedData));
  1389. Message1(execinfo_x_uninitdatasize,tostr(peheader.SizeOfUninitializedData));
  1390. { change stack size (PM) }
  1391. { I am not sure that the default value is adequate !! }
  1392. peheader.SizeOfStackReserve:=stacksize;
  1393. { change the header }
  1394. { sub system }
  1395. { gui=2 }
  1396. { cui=3 }
  1397. { wincegui=9 }
  1398. if target_info.system in [system_arm_wince,system_i386_wince] then
  1399. peheader.Subsystem:=9
  1400. else
  1401. case apptype of
  1402. app_native :
  1403. peheader.Subsystem:=1;
  1404. app_gui :
  1405. peheader.Subsystem:=2;
  1406. app_cui :
  1407. peheader.Subsystem:=3;
  1408. end;
  1409. if dllversion<>'' then
  1410. begin
  1411. peheader.MajorImageVersion:=dllmajor;
  1412. peheader.MinorImageVersion:=dllminor;
  1413. end;
  1414. { reset timestamp }
  1415. peheader.TimeDateStamp:=0;
  1416. { write header back }
  1417. seek(f,peheaderpos);
  1418. blockwrite(f,peheader,sizeof(tpeheader));
  1419. if ioresult<>0 then
  1420. Message1(execinfo_f_cant_process_executable,fn);
  1421. seek(f,peheaderpos);
  1422. blockread(f,peheader,sizeof(tpeheader));
  1423. { write the value after the change }
  1424. Message1(execinfo_x_stackreserve,tostr(peheader.SizeOfStackReserve));
  1425. Message1(execinfo_x_stackcommit,tostr(peheader.SizeOfStackCommit));
  1426. { read section info }
  1427. maxfillsize:=0;
  1428. firstsecpos:=0;
  1429. secroot:=nil;
  1430. for l:=1 to peheader.NumberOfSections do
  1431. begin
  1432. blockread(f,coffsec,sizeof(tcoffsechdr));
  1433. if coffsec.datapos>0 then
  1434. begin
  1435. if secroot=nil then
  1436. firstsecpos:=coffsec.datapos;
  1437. new(hsecroot);
  1438. hsecroot^.fillpos:=coffsec.datapos+coffsec.vsize;
  1439. hsecroot^.fillsize:=coffsec.datalen-coffsec.vsize;
  1440. hsecroot^.next:=secroot;
  1441. secroot:=hsecroot;
  1442. if secroot^.fillsize>maxfillsize then
  1443. maxfillsize:=secroot^.fillsize;
  1444. end;
  1445. end;
  1446. if firstsecpos>0 then
  1447. begin
  1448. l:=firstsecpos-filepos(f);
  1449. if l>maxfillsize then
  1450. maxfillsize:=l;
  1451. end
  1452. else
  1453. l:=0;
  1454. { get zero buffer }
  1455. getmem(zerobuf,maxfillsize);
  1456. fillchar(zerobuf^,maxfillsize,0);
  1457. { zero from sectioninfo until first section }
  1458. blockwrite(f,zerobuf^,l);
  1459. { zero section alignments }
  1460. while assigned(secroot) do
  1461. begin
  1462. seek(f,secroot^.fillpos);
  1463. blockwrite(f,zerobuf^,secroot^.fillsize);
  1464. hsecroot:=secroot;
  1465. secroot:=secroot^.next;
  1466. dispose(hsecroot);
  1467. end;
  1468. freemem(zerobuf,maxfillsize);
  1469. close(f);
  1470. {$I+}
  1471. if ioresult<>0 then;
  1472. postprocessexecutable:=true;
  1473. end;
  1474. {****************************************************************************
  1475. TDLLScannerWin32
  1476. ****************************************************************************}
  1477. procedure tDLLScannerWin32.CheckDLLFunc(const dllname,funcname:string);
  1478. var
  1479. hp : tExternalsItem;
  1480. begin
  1481. hp:=tExternalsItem(current_module.Externals.first);
  1482. while assigned(hp)do
  1483. begin
  1484. if (not hp.found) and
  1485. assigned(hp.data) and
  1486. (hp.data^=funcname) then
  1487. begin
  1488. hp.found:=true;
  1489. if not(current_module.uses_imports) then
  1490. begin
  1491. current_module.uses_imports:=true;
  1492. importlib.preparelib(current_module.modulename^);
  1493. end;
  1494. timportlibwin32(importlib).importprocedure_str(dllname,0,funcname);
  1495. importfound:=true;
  1496. exit;
  1497. end;
  1498. hp:=tExternalsItem(hp.next);
  1499. end;
  1500. end;
  1501. function tDLLScannerWin32.scan(const binname:string):boolean;
  1502. var
  1503. hs,
  1504. dllname : string;
  1505. begin
  1506. result:=false;
  1507. { is there already an import library the we will use that one }
  1508. if FindLibraryFile(binname,target_info.staticClibprefix,target_info.staticClibext,hs) then
  1509. exit;
  1510. { check if we can find the dll }
  1511. hs:=AddExtension(binname,target_info.sharedlibext);
  1512. if not FindDll(hs,dllname) then
  1513. exit;
  1514. importfound:=false;
  1515. ReadDLLImports(dllname,@CheckDLLFunc);
  1516. result:=importfound;
  1517. end;
  1518. {*****************************************************************************
  1519. Initialize
  1520. *****************************************************************************}
  1521. initialization
  1522. {$ifdef i386}
  1523. RegisterExternalLinker(system_i386_win32_info,TLinkerWin32);
  1524. RegisterInternalLinker(system_i386_win32_info,TPECoffLinker);
  1525. RegisterImport(system_i386_win32,TImportLibWin32);
  1526. RegisterExport(system_i386_win32,TExportLibWin32);
  1527. RegisterDLLScanner(system_i386_win32,TDLLScannerWin32);
  1528. RegisterRes(res_gnu_windres_info);
  1529. RegisterTarget(system_i386_win32_info);
  1530. RegisterExternalLinker(system_i386_wince_info,TLinkerWin32);
  1531. RegisterImport(system_i386_wince,TImportLibWin32);
  1532. RegisterExport(system_i386_wince,TExportLibWin32);
  1533. RegisterDLLScanner(system_i386_wince,TDLLScannerWin32);
  1534. RegisterTarget(system_i386_wince_info);
  1535. {$endif i386}
  1536. {$ifdef x86_64}
  1537. RegisterInternalLinker(system_x64_win64_info,TPECoffLinker);
  1538. RegisterImport(system_x86_64_win64,TImportLibWin32);
  1539. RegisterExport(system_x86_64_win64,TExportLibWin32);
  1540. RegisterDLLScanner(system_x86_64_win64,TDLLScannerWin32);
  1541. RegisterRes(res_gnu_windres_info);
  1542. RegisterTarget(system_x64_win64_info);
  1543. {$endif x86_64}
  1544. {$ifdef arm}
  1545. RegisterExternalLinker(system_arm_wince_info,TLinkerWin32);
  1546. RegisterInternalLinker(system_arm_wince_info,TPECoffLinker);
  1547. RegisterImport(system_arm_wince,TImportLibWin32);
  1548. RegisterExport(system_arm_wince,TExportLibWin32);
  1549. RegisterRes(res_gnu_wince_windres_info);
  1550. RegisterTarget(system_arm_wince_info);
  1551. {$endif arm}
  1552. end.