t_win.pas 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  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) and (hp2.ordnr=index) 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. if afuncname<>'' then
  334. begin
  335. objdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
  336. if target_info.system=system_x86_64_win64 then
  337. objdata.writebytes(emptyint,sizeof(emptyint));
  338. end
  339. else
  340. begin
  341. emptyint:=ordnr;
  342. if target_info.system=system_x86_64_win64 then
  343. begin
  344. objdata.writebytes(emptyint,sizeof(emptyint));
  345. emptyint:=longint($80000000);
  346. objdata.writebytes(emptyint,sizeof(emptyint));
  347. end
  348. else
  349. begin
  350. emptyint:=emptyint or longint($80000000);
  351. objdata.writebytes(emptyint,sizeof(emptyint));
  352. end;
  353. emptyint:=0;
  354. end;
  355. { idata5, import address table }
  356. objdata.SetSection(idata5objsection);
  357. if isvar then
  358. implabel:=objdata.SymbolDefine(afuncname,AB_GLOBAL,AT_DATA)
  359. else
  360. idata5label:=objdata.SymbolDefine(asmprefix+'_'+afuncname,AB_LOCAL,AT_DATA);
  361. objdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
  362. if target_info.system=system_x86_64_win64 then
  363. objdata.writebytes(emptyint,sizeof(emptyint));
  364. { text, jmp }
  365. if not isvar then
  366. begin
  367. objdata.SetSection(textobjsection);
  368. if afuncname <> '' then
  369. implabel:=objdata.SymbolDefine(afuncname,AB_GLOBAL,AT_FUNCTION)
  370. else
  371. implabel:=objdata.SymbolDefine(basedllname+'_index_'+tostr(ordnr),AB_GLOBAL,AT_FUNCTION);
  372. objdata.writebytes(jmpopcode,sizeof(jmpopcode));
  373. objdata.writereloc(0,sizeof(longint),idata5label,RELOC_ABSOLUTE32);
  374. objdata.writebytes(nopopcodes,align(objdata.CurrObjSec.size,sizeof(nopopcodes))-objdata.CurrObjSec.size);
  375. end;
  376. ObjOutput.exportsymbol(implabel);
  377. WriteObjData(objdata);
  378. objdata.free;
  379. end;
  380. var
  381. hp1 : timportList;
  382. hp2 : twin32imported_item;
  383. begin
  384. AsmPrefix:='imp'+Lower(current_module.modulename^);
  385. idatalabnr:=0;
  386. SmartFilesCount:=0;
  387. SmartHeaderCount:=0;
  388. current_module.linkotherstaticlibs.add(current_module.importlibfilename^,link_always);
  389. ObjWriter:=TARObjectWriter.create(current_module.importlibfilename^);
  390. ObjOutput:=TPECoffObjOutput.Create(ObjWriter);
  391. hp1:=timportlist(current_module.imports.first);
  392. while assigned(hp1) do
  393. begin
  394. StartImport(hp1.dllname^);
  395. hp2:=twin32imported_item(hp1.imported_items.first);
  396. while assigned(hp2) do
  397. begin
  398. AddImport(hp2.name^,hp2.ordnr,hp2.is_var);
  399. hp2:=twin32imported_item(hp2.next);
  400. end;
  401. EndImport;
  402. hp1:=timportlist(hp1.next);
  403. end;
  404. ObjOutput.Free;
  405. ObjWriter.Free;
  406. end;
  407. procedure timportlibwin32.generateidatasection;
  408. var
  409. hp1 : timportList;
  410. hp2 : twin32imported_item;
  411. l1,l2,l3,l4 {$ifdef ARM} ,l5 {$endif ARM} : tasmlabel;
  412. importname : string;
  413. suffix : integer;
  414. href : treference;
  415. begin
  416. if (target_asm.id in [as_i386_masm,as_i386_tasm,as_i386_nasmwin32]) then
  417. begin
  418. new_section(current_asmdata.asmlists[al_imports],sec_code,'',0);
  419. hp1:=timportlist(current_module.imports.first);
  420. while assigned(hp1) do
  421. begin
  422. hp2:=twin32imported_item(hp1.imported_items.first);
  423. while assigned(hp2) do
  424. begin
  425. current_asmdata.asmlists[al_imports].concat(tai_directive.create(asd_extern,hp2.func^));
  426. current_asmdata.asmlists[al_imports].concat(tai_directive.create(asd_nasm_import,hp2.func^+' '+hp1.dllname^+' '+hp2.name^));
  427. hp2:=twin32imported_item(hp2.next);
  428. end;
  429. hp1:=timportlist(hp1.next);
  430. end;
  431. exit;
  432. end;
  433. hp1:=timportlist(current_module.imports.first);
  434. while assigned(hp1) do
  435. begin
  436. { align al_procedures for the jumps }
  437. new_section(current_asmdata.asmlists[al_imports],sec_code,'',sizeof(aint));
  438. { Get labels for the sections }
  439. current_asmdata.getjumplabel(l1);
  440. current_asmdata.getjumplabel(l2);
  441. current_asmdata.getjumplabel(l3);
  442. new_section(current_asmdata.asmlists[al_imports],sec_idata2,'',0);
  443. { pointer to procedure names }
  444. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(l2));
  445. { two empty entries follow }
  446. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  447. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  448. { pointer to dll name }
  449. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(l1));
  450. { pointer to fixups }
  451. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(l3));
  452. { only create one section for each else it will
  453. create a lot of idata* }
  454. { first write the name references }
  455. new_section(current_asmdata.asmlists[al_imports],sec_idata4,'',0);
  456. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l2));
  457. hp2:=twin32imported_item(hp1.imported_items.first);
  458. while assigned(hp2) do
  459. begin
  460. current_asmdata.getjumplabel(tasmlabel(hp2.lab));
  461. if hp2.name^<>'' then
  462. begin
  463. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(hp2.lab));
  464. if target_info.system=system_x86_64_win64 then
  465. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  466. end
  467. else
  468. begin
  469. if target_info.system=system_x86_64_win64 then
  470. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_64bit(int64($8000000000000000) or hp2.ordnr))
  471. else
  472. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(longint($80000000) or hp2.ordnr));
  473. end;
  474. hp2:=twin32imported_item(hp2.next);
  475. end;
  476. { finalize the names ... }
  477. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  478. if target_info.system=system_x86_64_win64 then
  479. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  480. { then the addresses and create also the indirect jump }
  481. new_section(current_asmdata.asmlists[al_imports],sec_idata5,'',0);
  482. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l3));
  483. hp2:=twin32imported_item(hp1.imported_items.first);
  484. while assigned(hp2) do
  485. begin
  486. if not hp2.is_var then
  487. begin
  488. current_asmdata.getjumplabel(l4);
  489. {$ifdef ARM}
  490. current_asmdata.getjumplabel(l5);
  491. {$endif ARM}
  492. { create indirect jump and }
  493. { place jump in al_procedures }
  494. new_section(current_asmdata.asmlists[al_imports],sec_code,'',0);
  495. if hp2.name^ <> '' then
  496. current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(hp2.name^,AT_FUNCTION,0))
  497. else
  498. current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(splitfilename(hp1.dllname^)+'_index_'+tostr(hp2.ordnr),AT_FUNCTION,0));
  499. current_asmdata.asmlists[al_imports].concat(tai_function_name.create(''));
  500. {$ifdef ARM}
  501. reference_reset_symbol(href,l5,0);
  502. current_asmdata.asmlists[al_imports].concat(Taicpu.op_reg_ref(A_LDR,NR_R12,href));
  503. reference_reset_base(href,NR_R12,0);
  504. current_asmdata.asmlists[al_imports].concat(Taicpu.op_reg_ref(A_LDR,NR_R15,href));
  505. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l5));
  506. reference_reset_symbol(href,l4,0);
  507. current_asmdata.asmlists[al_imports].concat(tai_const.create_sym_offset(href.symbol,href.offset));
  508. {$else ARM}
  509. reference_reset_symbol(href,l4,0);
  510. current_asmdata.asmlists[al_imports].concat(Taicpu.Op_ref(A_JMP,S_NO,href));
  511. current_asmdata.asmlists[al_imports].concat(Tai_align.Create_op(4,$90));
  512. {$endif ARM}
  513. { add jump field to al_imports }
  514. new_section(current_asmdata.asmlists[al_imports],sec_idata5,'',0);
  515. if (cs_debuginfo in aktmoduleswitches) then
  516. begin
  517. if assigned(hp2.name) then
  518. begin
  519. importname:='__imp_'+hp2.name^;
  520. suffix:=0;
  521. while assigned(current_asmdata.getasmsymbol(importname)) do
  522. begin
  523. inc(suffix);
  524. importname:='__imp_'+hp2.name^+'_'+tostr(suffix);
  525. end;
  526. current_asmdata.asmlists[al_imports].concat(tai_symbol.createname(importname,AT_FUNCTION,4));
  527. end
  528. else
  529. begin
  530. importname:='__imp_by_ordinal'+tostr(hp2.ordnr);
  531. suffix:=0;
  532. while assigned(current_asmdata.getasmsymbol(importname)) do
  533. begin
  534. inc(suffix);
  535. importname:='__imp_by_ordinal'+tostr(hp2.ordnr)+'_'+tostr(suffix);
  536. end;
  537. current_asmdata.asmlists[al_imports].concat(tai_symbol.createname(importname,AT_FUNCTION,4));
  538. end;
  539. end;
  540. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l4));
  541. end
  542. else
  543. begin
  544. current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(hp2.func^,AT_DATA,0));
  545. end;
  546. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(hp2.lab));
  547. if target_info.system=system_x86_64_win64 then
  548. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  549. hp2:=twin32imported_item(hp2.next);
  550. end;
  551. { finalize the addresses }
  552. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  553. if target_info.system=system_x86_64_win64 then
  554. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));
  555. { finally the import information }
  556. new_section(current_asmdata.asmlists[al_imports],sec_idata6,'',0);
  557. hp2:=twin32imported_item(hp1.imported_items.first);
  558. while assigned(hp2) do
  559. begin
  560. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(hp2.lab));
  561. { the ordinal number }
  562. current_asmdata.asmlists[al_imports].concat(Tai_const.Create_16bit(hp2.ordnr));
  563. current_asmdata.asmlists[al_imports].concat(Tai_string.Create(hp2.name^+#0));
  564. current_asmdata.asmlists[al_imports].concat(Tai_align.Create_op(2,0));
  565. hp2:=twin32imported_item(hp2.next);
  566. end;
  567. { create import dll name }
  568. new_section(current_asmdata.asmlists[al_imports],sec_idata7,'',0);
  569. current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l1));
  570. current_asmdata.asmlists[al_imports].concat(Tai_string.Create(hp1.dllname^+#0));
  571. hp1:=timportlist(hp1.next);
  572. end;
  573. end;
  574. procedure timportlibwin32.generatelib;
  575. begin
  576. if GenerateImportSection then
  577. generateidatasection
  578. else
  579. generateimportlib;
  580. end;
  581. {*****************************************************************************
  582. TEXPORTLIBWIN32
  583. *****************************************************************************}
  584. procedure texportlibwin32.preparelib(const s:string);
  585. begin
  586. if current_asmdata.asmlists[al_exports]=nil then
  587. current_asmdata.asmlists[al_exports]:=TAsmList.create;
  588. EList_indexed:=tFPList.Create;
  589. EList_nonindexed:=tFPList.Create;
  590. end;
  591. procedure texportlibwin32.exportvar(hp : texported_item);
  592. begin
  593. { same code used !! PM }
  594. exportprocedure(hp);
  595. end;
  596. var
  597. Gl_DoubleIndex:boolean;
  598. Gl_DoubleIndexValue:longint;
  599. function IdxCompare(Item1, Item2: Pointer): Integer;
  600. var
  601. I1:texported_item absolute Item1;
  602. I2:texported_item absolute Item2;
  603. begin
  604. Result:=I1.index-I2.index;
  605. if(Result=0)and(Item1<>Item2)then
  606. begin
  607. Gl_DoubleIndex:=true;
  608. Gl_DoubleIndexValue:=I1.index;
  609. end;
  610. end;
  611. procedure texportlibwin32.exportprocedure(hp : texported_item);
  612. begin
  613. if ((hp.options and eo_index)<>0)and((hp.index<=0) or (hp.index>$ffff)) then
  614. begin
  615. message1(parser_e_export_invalid_index,tostr(hp.index));
  616. exit;
  617. end;
  618. if hp.options and eo_index=eo_index then
  619. EList_indexed.Add(hp)
  620. else
  621. EList_nonindexed.Add(hp);
  622. end;
  623. procedure texportlibwin32.exportfromlist(hp : texported_item);
  624. //formerly texportlibwin32.exportprocedure
  625. { must be ordered at least for win32 !! }
  626. var
  627. hp2 : texported_item;
  628. begin
  629. hp2:=texported_item(current_module._exports.first);
  630. while assigned(hp2) and
  631. (hp.name^>hp2.name^) do
  632. hp2:=texported_item(hp2.next);
  633. { insert hp there !! }
  634. if hp2=nil then
  635. current_module._exports.concat(hp)
  636. else
  637. begin
  638. if hp2.name^=hp.name^ then
  639. begin
  640. { this is not allowed !! }
  641. message1(parser_e_export_name_double,hp.name^);
  642. exit;
  643. end;
  644. current_module._exports.insertbefore(hp,hp2);
  645. end;
  646. end;
  647. procedure texportlibwin32.generatelib;
  648. var
  649. ordinal_base,ordinal_max,ordinal_min : longint;
  650. current_index : longint;
  651. entries,named_entries : longint;
  652. name_label,dll_name_label,export_address_table : tasmlabel;
  653. export_name_table_pointers,export_ordinal_table : tasmlabel;
  654. hp,hp2 : texported_item;
  655. temtexport : TLinkedList;
  656. address_table,name_table_pointers,
  657. name_table,ordinal_table : TAsmList;
  658. i,autoindex,ni_high : longint;
  659. hole : boolean;
  660. begin
  661. Gl_DoubleIndex:=false;
  662. ELIst_indexed.Sort(@IdxCompare);
  663. if Gl_DoubleIndex then
  664. begin
  665. message1(parser_e_export_ordinal_double,tostr(Gl_DoubleIndexValue));
  666. EList_indexed.Free;
  667. EList_nonindexed.Free;
  668. exit;
  669. end;
  670. autoindex:=1;
  671. while EList_nonindexed.Count>0 do
  672. begin
  673. hole:=(EList_indexed.Count>0)and(texported_item(EList_indexed.Items[0]).index>1);
  674. if not hole then
  675. for i:=autoindex to pred(EList_indexed.Count)do
  676. if texported_item(EList_indexed.Items[i]).index-texported_item(EList_indexed.Items[pred(i)]).index>1 then
  677. begin
  678. autoindex:=succ(texported_item(EList_indexed.Items[pred(i)]).index);
  679. hole:=true;
  680. break;
  681. end;
  682. ni_high:=pred(EList_nonindexed.Count);
  683. if not hole then
  684. begin
  685. autoindex:=succ(EList_indexed.Count);
  686. EList_indexed.Add(EList_nonindexed.Items[ni_high]);
  687. end
  688. else
  689. EList_indexed.Insert(pred(AutoIndex),EList_nonindexed.Items[ni_high]);
  690. EList_nonindexed.Delete(ni_high);
  691. texported_item(EList_indexed.Items[pred(AutoIndex)]).index:=autoindex;
  692. end;
  693. EList_nonindexed.Free;
  694. for i:=0 to pred(EList_indexed.Count)do
  695. exportfromlist(texported_item(EList_indexed.Items[i]));
  696. EList_indexed.Free;
  697. if (target_asm.id in [as_i386_masm,as_i386_tasm,as_i386_nasmwin32]) then
  698. begin
  699. generatenasmlib;
  700. exit;
  701. end;
  702. hp:=texported_item(current_module._exports.first);
  703. if not assigned(hp) then
  704. exit;
  705. ordinal_max:=0;
  706. ordinal_min:=$7FFFFFFF;
  707. entries:=0;
  708. named_entries:=0;
  709. current_asmdata.getjumplabel(dll_name_label);
  710. current_asmdata.getjumplabel(export_address_table);
  711. current_asmdata.getjumplabel(export_name_table_pointers);
  712. current_asmdata.getjumplabel(export_ordinal_table);
  713. { count entries }
  714. while assigned(hp) do
  715. begin
  716. inc(entries);
  717. if (hp.index>ordinal_max) then
  718. ordinal_max:=hp.index;
  719. if (hp.index>0) and (hp.index<ordinal_min) then
  720. ordinal_min:=hp.index;
  721. if assigned(hp.name) then
  722. inc(named_entries);
  723. hp:=texported_item(hp.next);
  724. end;
  725. { no support for higher ordinal base yet !! }
  726. ordinal_base:=1;
  727. current_index:=ordinal_base;
  728. { we must also count the holes !! }
  729. entries:=ordinal_max-ordinal_base+1;
  730. new_section(current_asmdata.asmlists[al_exports],sec_edata,'',0);
  731. { create label to reference from main so smartlink will include
  732. the .edata section }
  733. current_asmdata.asmlists[al_exports].concat(Tai_symbol.Createname_global(make_mangledname('EDATA',current_module.localsymtable,''),AT_DATA,0));
  734. { export flags }
  735. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_32bit(0));
  736. { date/time stamp }
  737. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_32bit(0));
  738. { major version }
  739. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_16bit(0));
  740. { minor version }
  741. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_16bit(0));
  742. { pointer to dll name }
  743. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_rva_sym(dll_name_label));
  744. { ordinal base normally set to 1 }
  745. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_32bit(ordinal_base));
  746. { number of entries }
  747. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_32bit(entries));
  748. { number of named entries }
  749. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_32bit(named_entries));
  750. { address of export address table }
  751. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_rva_sym(export_address_table));
  752. { address of name pointer pointers }
  753. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_rva_sym(export_name_table_pointers));
  754. { address of ordinal number pointers }
  755. current_asmdata.asmlists[al_exports].concat(Tai_const.Create_rva_sym(export_ordinal_table));
  756. { the name }
  757. current_asmdata.asmlists[al_exports].concat(Tai_label.Create(dll_name_label));
  758. if st='' then
  759. current_asmdata.asmlists[al_exports].concat(Tai_string.Create(current_module.modulename^+target_info.sharedlibext+#0))
  760. else
  761. current_asmdata.asmlists[al_exports].concat(Tai_string.Create(st+target_info.sharedlibext+#0));
  762. { export address table }
  763. address_table:=TAsmList.create;
  764. address_table.concat(Tai_align.Create_op(4,0));
  765. address_table.concat(Tai_label.Create(export_address_table));
  766. name_table_pointers:=TAsmList.create;
  767. name_table_pointers.concat(Tai_align.Create_op(4,0));
  768. name_table_pointers.concat(Tai_label.Create(export_name_table_pointers));
  769. ordinal_table:=TAsmList.create;
  770. ordinal_table.concat(Tai_align.Create_op(4,0));
  771. ordinal_table.concat(Tai_label.Create(export_ordinal_table));
  772. name_table:=TAsmList.Create;
  773. name_table.concat(Tai_align.Create_op(4,0));
  774. { write each address }
  775. hp:=texported_item(current_module._exports.first);
  776. while assigned(hp) do
  777. begin
  778. if (hp.options and eo_name)<>0 then
  779. begin
  780. current_asmdata.getjumplabel(name_label);
  781. name_table_pointers.concat(Tai_const.Create_rva_sym(name_label));
  782. ordinal_table.concat(Tai_const.Create_16bit(hp.index-ordinal_base));
  783. name_table.concat(Tai_align.Create_op(2,0));
  784. name_table.concat(Tai_label.Create(name_label));
  785. name_table.concat(Tai_string.Create(hp.name^+#0));
  786. end;
  787. hp:=texported_item(hp.next);
  788. end;
  789. { order in increasing ordinal values }
  790. { into temtexport list }
  791. temtexport:=TLinkedList.Create;
  792. hp:=texported_item(current_module._exports.first);
  793. while assigned(hp) do
  794. begin
  795. current_module._exports.remove(hp);
  796. hp2:=texported_item(temtexport.first);
  797. while assigned(hp2) and (hp.index>hp2.index) do
  798. hp2:=texported_item(hp2.next);
  799. if hp2=nil then
  800. temtexport.concat(hp)
  801. else
  802. temtexport.insertbefore(hp,hp2);
  803. hp:=texported_item(current_module._exports.first);;
  804. end;
  805. { write the export adress table }
  806. current_index:=ordinal_base;
  807. hp:=texported_item(temtexport.first);
  808. while assigned(hp) do
  809. begin
  810. { fill missing values }
  811. while current_index<hp.index do
  812. begin
  813. address_table.concat(Tai_const.Create_32bit(0));
  814. inc(current_index);
  815. end;
  816. case hp.sym.typ of
  817. globalvarsym :
  818. address_table.concat(Tai_const.Createname_rva(tglobalvarsym(hp.sym).mangledname));
  819. typedconstsym :
  820. address_table.concat(Tai_const.Createname_rva(ttypedconstsym(hp.sym).mangledname));
  821. procsym :
  822. address_table.concat(Tai_const.Createname_rva(tprocsym(hp.sym).first_procdef.mangledname));
  823. end;
  824. inc(current_index);
  825. hp:=texported_item(hp.next);
  826. end;
  827. current_asmdata.asmlists[al_exports].concatlist(address_table);
  828. current_asmdata.asmlists[al_exports].concatlist(name_table_pointers);
  829. current_asmdata.asmlists[al_exports].concatlist(ordinal_table);
  830. current_asmdata.asmlists[al_exports].concatlist(name_table);
  831. address_table.Free;
  832. name_table_pointers.free;
  833. ordinal_table.free;
  834. name_table.free;
  835. temtexport.free;
  836. end;
  837. procedure texportlibwin32.generatenasmlib;
  838. var
  839. hp : texported_item;
  840. p : pchar;
  841. s : string;
  842. begin
  843. new_section(current_asmdata.asmlists[al_exports],sec_code,'',0);
  844. hp:=texported_item(current_module._exports.first);
  845. while assigned(hp) do
  846. begin
  847. case hp.sym.typ of
  848. globalvarsym :
  849. s:=tglobalvarsym(hp.sym).mangledname;
  850. typedconstsym :
  851. s:=ttypedconstsym(hp.sym).mangledname;
  852. procsym :
  853. s:=tprocsym(hp.sym).first_procdef.mangledname;
  854. else
  855. s:='';
  856. end;
  857. p:=strpnew(#9+'export '+s+' '+hp.name^+' '+tostr(hp.index));
  858. {current_asmdata.asmlists[al_exports].concat(tai_direct.create(p));}
  859. hp:=texported_item(hp.next);
  860. end;
  861. end;
  862. {****************************************************************************
  863. TLINKERWIN32
  864. ****************************************************************************}
  865. Constructor TLinkerWin32.Create;
  866. begin
  867. Inherited Create;
  868. { allow duplicated libs (PM) }
  869. SharedLibFiles.doubles:=true;
  870. StaticLibFiles.doubles:=true; if not Dontlinkstdlibpath Then
  871. end;
  872. Procedure TLinkerWin32.SetDefaultInfo;
  873. var
  874. targetopts: string;
  875. begin
  876. with Info do
  877. begin
  878. {$ifdef ARM}
  879. targetopts:='-m armpe';
  880. {$else ARM}
  881. targetopts:='-b pe-i386 -m i386pe';
  882. {$endif ARM}
  883. ExeCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $MAP $STRIP $APPTYPE $ENTRY $IMAGEBASE $RELOC -o $EXE $RES';
  884. DllCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $MAP $STRIP --dll $APPTYPE $ENTRY $IMAGEBASE $RELOC -o $EXE $RES';
  885. { ExeCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF';
  886. use short forms to avoid 128 char limitation problem }
  887. ExeCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
  888. ExeCmd[3]:='ld '+targetopts+' $OPT $STRIP $APPTYPE $ENTRY $IMAGEBASE -o $EXE $RES exp.$$$';
  889. { DllCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF'; }
  890. DllCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
  891. DllCmd[3]:='ld '+targetopts+' $OPT $STRIP --dll $APPTYPE $ENTRY $IMAGEBASE -o $EXE $RES exp.$$$';
  892. end;
  893. end;
  894. Function TLinkerWin32.WriteResponseFile(isdll:boolean) : Boolean;
  895. Var
  896. linkres : TLinkRes;
  897. HPath : TStringListItem;
  898. s,s2 : string;
  899. i : integer;
  900. linklibcygwin : boolean;
  901. begin
  902. WriteResponseFile:=False;
  903. linklibcygwin:=(SharedLibFiles.Find('cygwin')<>nil);
  904. if (cs_profile in aktmoduleswitches) then
  905. begin
  906. SharedLibFiles.Concat('gmon');
  907. SharedLibFiles.Concat('c');
  908. SharedLibFiles.Concat('gcc');
  909. SharedLibFiles.Concat('kernel32');
  910. end;
  911. { Open link.res file }
  912. LinkRes:=TLinkres.Create(outputexedir+Info.ResName);
  913. with linkres do
  914. begin
  915. { Write path to search libraries }
  916. HPath:=TStringListItem(current_module.locallibrarysearchpath.First);
  917. while assigned(HPath) do
  918. begin
  919. Add('SEARCH_DIR('+MaybeQuoted(HPath.Str)+')');
  920. HPath:=TStringListItem(HPath.Next);
  921. end;
  922. HPath:=TStringListItem(LibrarySearchPath.First);
  923. while assigned(HPath) do
  924. begin
  925. Add('SEARCH_DIR('+MaybeQuoted(HPath.Str)+')');
  926. HPath:=TStringListItem(HPath.Next);
  927. end;
  928. { add objectfiles, start with prt0 always }
  929. { profiling of shared libraries is currently not supported }
  930. if not ObjectFiles.Empty then
  931. begin
  932. Add('INPUT(');
  933. while not ObjectFiles.Empty do
  934. begin
  935. s:=ObjectFiles.GetFirst;
  936. if s<>'' then
  937. AddFileName(MaybeQuoted(s));
  938. end;
  939. Add(')');
  940. end;
  941. { Write staticlibraries }
  942. if (not StaticLibFiles.Empty) then
  943. begin
  944. Add('GROUP(');
  945. While not StaticLibFiles.Empty do
  946. begin
  947. S:=StaticLibFiles.GetFirst;
  948. AddFileName(MaybeQuoted(s));
  949. end;
  950. Add(')');
  951. end;
  952. { Write sharedlibraries (=import libraries) }
  953. if not SharedLibFiles.Empty then
  954. begin
  955. Add('INPUT(') ;
  956. While not SharedLibFiles.Empty do
  957. begin
  958. S:=SharedLibFiles.GetFirst;
  959. if FindLibraryFile(s,target_info.staticClibprefix,target_info.staticClibext,s2) then
  960. begin
  961. Add(MaybeQuoted(s2));
  962. continue;
  963. end;
  964. if pos(target_info.sharedlibprefix,s)=1 then
  965. s:=copy(s,length(target_info.sharedlibprefix)+1,255);
  966. i:=Pos(target_info.sharedlibext,S);
  967. if i>0 then
  968. Delete(S,i,255);
  969. Add('-l'+s);
  970. end;
  971. Add(')');
  972. end;
  973. Add('SEARCH_DIR("/usr/i686-pc-cygwin/lib"); SEARCH_DIR("/usr/lib"); SEARCH_DIR("/usr/lib/w32api");');
  974. Add('OUTPUT_FORMAT(pei-i386)');
  975. Add('ENTRY(_mainCRTStartup)');
  976. Add('SECTIONS');
  977. Add('{');
  978. Add(' . = SIZEOF_HEADERS;');
  979. Add(' . = ALIGN(__section_alignment__);');
  980. Add(' .text __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :');
  981. Add(' {');
  982. {$ifdef arm}
  983. Add(' *(.pdata.FPC_EH_PROLOG)');
  984. {$endif arm}
  985. Add(' *(.init)');
  986. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  987. Add(' *(SORT(.text$*))');
  988. Add(' ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;');
  989. Add(' LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0);');
  990. Add(' ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;');
  991. Add(' LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0);');
  992. Add(' *(.fini)');
  993. Add(' PROVIDE (etext = .);');
  994. Add(' *(.gcc_except_table)');
  995. Add(' }');
  996. Add(' .data BLOCK(__section_alignment__) :');
  997. Add(' {');
  998. Add(' __data_start__ = . ;');
  999. add(' *(.data .data.* .gnu.linkonce.d.*)');
  1000. Add(' *(.data2)');
  1001. Add(' *(SORT(.data$*))');
  1002. Add(' __data_end__ = . ;');
  1003. Add(' *(.data_cygwin_nocopy)');
  1004. Add(' }');
  1005. Add(' .rdata BLOCK(__section_alignment__) :');
  1006. Add(' {');
  1007. Add(' *(.rdata)');
  1008. add(' *(.rodata .rodata.* .gnu.linkonce.r.*)');
  1009. Add(' *(SORT(.rdata$*))');
  1010. Add(' *(.eh_frame)');
  1011. Add(' ___RUNTIME_PSEUDO_RELOC_LIST__ = .;');
  1012. Add(' __RUNTIME_PSEUDO_RELOC_LIST__ = .;');
  1013. Add(' *(.rdata_runtime_pseudo_reloc)');
  1014. Add(' ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;');
  1015. Add(' __RUNTIME_PSEUDO_RELOC_LIST_END__ = .;');
  1016. Add(' }');
  1017. Add(' .pdata BLOCK(__section_alignment__) : { *(.pdata) }');
  1018. Add(' .bss BLOCK(__section_alignment__) :');
  1019. Add(' {');
  1020. Add(' __bss_start__ = . ;');
  1021. Add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  1022. Add(' *(SORT(.bss$*))');
  1023. Add(' *(COMMON)');
  1024. Add(' __bss_end__ = . ;');
  1025. Add(' }');
  1026. Add(' .edata BLOCK(__section_alignment__) : { *(.edata) }');
  1027. Add(' .idata BLOCK(__section_alignment__) :');
  1028. Add(' {');
  1029. Add(' SORT(*)(.idata$2)');
  1030. Add(' SORT(*)(.idata$3)');
  1031. Add(' /* These zeroes mark the end of the import list. */');
  1032. Add(' LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);');
  1033. Add(' SORT(*)(.idata$4)');
  1034. Add(' SORT(*)(.idata$5)');
  1035. Add(' SORT(*)(.idata$6)');
  1036. Add(' SORT(*)(.idata$7)');
  1037. Add(' }');
  1038. Add(' .CRT BLOCK(__section_alignment__) :');
  1039. Add(' {');
  1040. Add(' ___crt_xc_start__ = . ;');
  1041. Add(' *(SORT(.CRT$XC*)) /* C initialization */');
  1042. Add(' ___crt_xc_end__ = . ;');
  1043. Add(' ___crt_xi_start__ = . ;');
  1044. Add(' *(SORT(.CRT$XI*)) /* C++ initialization */');
  1045. Add(' ___crt_xi_end__ = . ;');
  1046. Add(' ___crt_xl_start__ = . ;');
  1047. Add(' *(SORT(.CRT$XL*)) /* TLS callbacks */');
  1048. Add(' /* ___crt_xl_end__ is defined in the TLS Directory support code */');
  1049. Add(' ___crt_xp_start__ = . ;');
  1050. Add(' *(SORT(.CRT$XP*)) /* Pre-termination */');
  1051. Add(' ___crt_xp_end__ = . ;');
  1052. Add(' ___crt_xt_start__ = . ;');
  1053. Add(' *(SORT(.CRT$XT*)) /* Termination */');
  1054. Add(' ___crt_xt_end__ = . ;');
  1055. Add(' }');
  1056. Add(' .tls BLOCK(__section_alignment__) :');
  1057. Add(' {');
  1058. Add(' ___tls_start__ = . ;');
  1059. Add(' *(.tls .tls.*)');
  1060. Add(' *(.tls$)');
  1061. Add(' *(SORT(.tls$*))');
  1062. Add(' ___tls_end__ = . ;');
  1063. Add(' }');
  1064. Add(' .rsrc BLOCK(__section_alignment__) :');
  1065. Add(' {');
  1066. Add(' *(.rsrc)');
  1067. Add(' *(SORT(.rsrc$*))');
  1068. Add(' }');
  1069. Add(' .reloc BLOCK(__section_alignment__) : { *(.reloc) }');
  1070. Add(' .stab BLOCK(__section_alignment__) (NOLOAD) : { *(.stab) }');
  1071. Add(' .stabstr BLOCK(__section_alignment__) (NOLOAD) : { *(.stabstr) }');
  1072. Add(' .debug_aranges BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_aranges) }');
  1073. Add(' .debug_pubnames BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_pubnames) }');
  1074. Add(' .debug_info BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_info) *(.gnu.linkonce.wi.*) }');
  1075. Add(' .debug_abbrev BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_abbrev) }');
  1076. Add(' .debug_line BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_line) }');
  1077. Add(' .debug_frame BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_frame) }');
  1078. Add(' .debug_str BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_str) }');
  1079. Add(' .debug_loc BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_loc) }');
  1080. Add(' .debug_macinfo BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_macinfo) }');
  1081. Add(' .debug_weaknames BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_weaknames) }');
  1082. Add(' .debug_funcnames BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_funcnames) }');
  1083. Add(' .debug_typenames BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_typenames) }');
  1084. Add(' .debug_varnames BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_varnames) }');
  1085. Add(' .debug_ranges BLOCK(__section_alignment__) (NOLOAD) : { *(.debug_ranges) }');
  1086. Add('}');
  1087. { Write and Close response }
  1088. writetodisk;
  1089. Free;
  1090. end;
  1091. WriteResponseFile:=True;
  1092. end;
  1093. function TLinkerWin32.MakeExecutable:boolean;
  1094. var
  1095. MapStr,
  1096. binstr : String;
  1097. cmdstr : TCmdStr;
  1098. success : boolean;
  1099. cmds,i : longint;
  1100. AsBinStr : string[80];
  1101. GCSectionsStr,
  1102. StripStr,
  1103. RelocStr,
  1104. AppTypeStr,
  1105. EntryStr,
  1106. ImageBaseStr : string[40];
  1107. begin
  1108. if not(cs_link_nolink in aktglobalswitches) then
  1109. Message1(exec_i_linking,current_module.exefilename^);
  1110. { Create some replacements }
  1111. RelocStr:='';
  1112. AppTypeStr:='';
  1113. EntryStr:='';
  1114. ImageBaseStr:='';
  1115. StripStr:='';
  1116. MapStr:='';
  1117. GCSectionsStr:='';
  1118. AsBinStr:=FindUtil(utilsprefix+'as');
  1119. if RelocSection then
  1120. RelocStr:='--base-file base.$$$';
  1121. if use_smartlink_section then
  1122. GCSectionsStr:='--gc-sections';
  1123. if target_info.system in [system_arm_wince,system_i386_wince] then
  1124. AppTypeStr:='--subsystem wince'
  1125. else
  1126. begin
  1127. if apptype=app_gui then
  1128. AppTypeStr:='--subsystem windows';
  1129. end;
  1130. if apptype=app_gui then
  1131. EntryStr:='--entry=_WinMainCRTStartup'
  1132. else
  1133. EntryStr:='--entry=_mainCRTStartup';
  1134. if assigned(DLLImageBase) then
  1135. ImageBaseStr:='--image-base=0x'+DLLImageBase^;
  1136. if (cs_link_strip in aktglobalswitches) then
  1137. StripStr:='-s';
  1138. if (cs_link_map in aktglobalswitches) then
  1139. MapStr:='-Map '+maybequoted(ForceExtension(current_module.exefilename^,'.map'));
  1140. { Write used files and libraries }
  1141. WriteResponseFile(false);
  1142. { Call linker }
  1143. success:=false;
  1144. if RelocSection or (not Deffile.empty) then
  1145. cmds:=3
  1146. else
  1147. cmds:=1;
  1148. for i:=1 to cmds do
  1149. begin
  1150. SplitBinCmd(Info.ExeCmd[i],binstr,cmdstr);
  1151. if binstr<>'' then
  1152. begin
  1153. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename^));
  1154. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1155. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1156. Replace(cmdstr,'$APPTYPE',AppTypeStr);
  1157. Replace(cmdstr,'$ENTRY',EntryStr);
  1158. Replace(cmdstr,'$ASBIN',AsbinStr);
  1159. Replace(cmdstr,'$RELOC',RelocStr);
  1160. Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);
  1161. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1162. Replace(cmdstr,'$STRIP',StripStr);
  1163. Replace(cmdstr,'$MAP',MapStr);
  1164. if not DefFile.Empty then
  1165. begin
  1166. DefFile.WriteFile;
  1167. Replace(cmdstr,'$DEF','-d '+maybequoted(deffile.fname));
  1168. end
  1169. else
  1170. Replace(cmdstr,'$DEF','');
  1171. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,(i=1),false);
  1172. if not success then
  1173. break;
  1174. end;
  1175. end;
  1176. { Post process }
  1177. if success then
  1178. success:=PostProcessExecutable(current_module.exefilename^,false);
  1179. { Remove ReponseFile }
  1180. if (success) and not(cs_link_nolink in aktglobalswitches) then
  1181. begin
  1182. RemoveFile(outputexedir+Info.ResName);
  1183. RemoveFile('base.$$$');
  1184. RemoveFile('exp.$$$');
  1185. RemoveFile('deffile.$$$');
  1186. end;
  1187. MakeExecutable:=success; { otherwise a recursive call to link method }
  1188. end;
  1189. Function TLinkerWin32.MakeSharedLibrary:boolean;
  1190. var
  1191. MapStr,
  1192. binstr : String;
  1193. cmdstr : TCmdStr;
  1194. success : boolean;
  1195. cmds,
  1196. i : longint;
  1197. AsBinStr : string[80];
  1198. StripStr,
  1199. GCSectionsStr,
  1200. RelocStr,
  1201. AppTypeStr,
  1202. EntryStr,
  1203. ImageBaseStr : string[40];
  1204. begin
  1205. MakeSharedLibrary:=false;
  1206. if not(cs_link_nolink in aktglobalswitches) then
  1207. Message1(exec_i_linking,current_module.sharedlibfilename^);
  1208. { Create some replacements }
  1209. RelocStr:='';
  1210. AppTypeStr:='';
  1211. EntryStr:='';
  1212. ImageBaseStr:='';
  1213. StripStr:='';
  1214. MapStr:='';
  1215. GCSectionsStr:='';
  1216. AsBinStr:=FindUtil(utilsprefix+'as');
  1217. if RelocSection then
  1218. RelocStr:='--base-file base.$$$';
  1219. if use_smartlink_section then
  1220. GCSectionsStr:='--gc-sections';
  1221. if apptype=app_gui then
  1222. begin
  1223. AppTypeStr:='--subsystem windows';
  1224. EntryStr:='--entry _DLLWinMainCRTStartup'
  1225. end
  1226. else
  1227. EntryStr:='--entry _DLLMainCRTStartup';
  1228. if assigned(DLLImageBase) then
  1229. ImageBaseStr:='--image-base=0x'+DLLImageBase^;
  1230. if (cs_link_strip in aktglobalswitches) then
  1231. StripStr:='-s';
  1232. if (cs_link_map in aktglobalswitches) then
  1233. MapStr:='-Map '+maybequoted(ForceExtension(current_module.exefilename^,'.map'));
  1234. { Write used files and libraries }
  1235. WriteResponseFile(true);
  1236. { Call linker }
  1237. success:=false;
  1238. if RelocSection or (not Deffile.empty) then
  1239. cmds:=3
  1240. else
  1241. cmds:=1;
  1242. for i:=1 to cmds do
  1243. begin
  1244. SplitBinCmd(Info.DllCmd[i],binstr,cmdstr);
  1245. if binstr<>'' then
  1246. begin
  1247. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
  1248. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1249. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1250. Replace(cmdstr,'$APPTYPE',AppTypeStr);
  1251. Replace(cmdstr,'$ENTRY',EntryStr);
  1252. Replace(cmdstr,'$ASBIN',AsbinStr);
  1253. Replace(cmdstr,'$RELOC',RelocStr);
  1254. Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);
  1255. Replace(cmdstr,'$STRIP',StripStr);
  1256. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1257. Replace(cmdstr,'$MAP',MapStr);
  1258. if not DefFile.Empty then
  1259. begin
  1260. DefFile.WriteFile;
  1261. Replace(cmdstr,'$DEF','-d '+maybequoted(deffile.fname));
  1262. end
  1263. else
  1264. Replace(cmdstr,'$DEF','');
  1265. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,(i=1),false);
  1266. if not success then
  1267. break;
  1268. end;
  1269. end;
  1270. { Post process }
  1271. if success then
  1272. success:=PostProcessExecutable(current_module.sharedlibfilename^,true);
  1273. { Remove ReponseFile }
  1274. if (success) and not(cs_link_nolink in aktglobalswitches) then
  1275. begin
  1276. RemoveFile(outputexedir+Info.ResName);
  1277. RemoveFile('base.$$$');
  1278. RemoveFile('exp.$$$');
  1279. RemoveFile('deffile.$$$');
  1280. end;
  1281. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  1282. end;
  1283. function tlinkerwin32.postprocessexecutable(const fn : string;isdll:boolean):boolean;
  1284. type
  1285. tdosheader = packed record
  1286. e_magic : word;
  1287. e_cblp : word;
  1288. e_cp : word;
  1289. e_crlc : word;
  1290. e_cparhdr : word;
  1291. e_minalloc : word;
  1292. e_maxalloc : word;
  1293. e_ss : word;
  1294. e_sp : word;
  1295. e_csum : word;
  1296. e_ip : word;
  1297. e_cs : word;
  1298. e_lfarlc : word;
  1299. e_ovno : word;
  1300. e_res : array[0..3] of word;
  1301. e_oemid : word;
  1302. e_oeminfo : word;
  1303. e_res2 : array[0..9] of word;
  1304. e_lfanew : longint;
  1305. end;
  1306. psecfill=^TSecfill;
  1307. TSecfill=record
  1308. fillpos,
  1309. fillsize : longint;
  1310. next : psecfill;
  1311. end;
  1312. var
  1313. f : file;
  1314. cmdstr : string;
  1315. dosheader : tdosheader;
  1316. peheader : tcoffheader;
  1317. peoptheader : tcoffpeoptheader;
  1318. firstsecpos,
  1319. maxfillsize,
  1320. l,peheaderpos : longint;
  1321. coffsec : tcoffsechdr;
  1322. secroot,hsecroot : psecfill;
  1323. zerobuf : pointer;
  1324. begin
  1325. postprocessexecutable:=false;
  1326. { when -s is used or it's a dll then quit }
  1327. if (cs_link_nolink in aktglobalswitches) then
  1328. begin
  1329. case apptype of
  1330. app_native :
  1331. cmdstr:='--subsystem native';
  1332. app_gui :
  1333. cmdstr:='--subsystem gui';
  1334. app_cui :
  1335. cmdstr:='--subsystem console';
  1336. end;
  1337. if dllversion<>'' then
  1338. cmdstr:=cmdstr+' --version '+dllversion;
  1339. cmdstr:=cmdstr+' --input '+maybequoted(fn);
  1340. cmdstr:=cmdstr+' --stack '+tostr(stacksize);
  1341. DoExec(FindUtil(utilsprefix+'postw32'),cmdstr,false,false);
  1342. postprocessexecutable:=true;
  1343. exit;
  1344. end;
  1345. { open file }
  1346. assign(f,fn);
  1347. {$I-}
  1348. reset(f,1);
  1349. if ioresult<>0 then
  1350. Message1(execinfo_f_cant_open_executable,fn);
  1351. { read headers }
  1352. blockread(f,dosheader,sizeof(tdosheader));
  1353. peheaderpos:=dosheader.e_lfanew;
  1354. { skip to headerpos and skip pe magic }
  1355. seek(f,peheaderpos+4);
  1356. blockread(f,peheader,sizeof(tcoffheader));
  1357. blockread(f,peoptheader,sizeof(tcoffpeoptheader));
  1358. { write info }
  1359. Message1(execinfo_x_codesize,tostr(peoptheader.tsize));
  1360. Message1(execinfo_x_initdatasize,tostr(peoptheader.dsize));
  1361. Message1(execinfo_x_uninitdatasize,tostr(peoptheader.bsize));
  1362. { change stack size (PM) }
  1363. { I am not sure that the default value is adequate !! }
  1364. peoptheader.SizeOfStackReserve:=stacksize;
  1365. if SetPEFlagsSetExplicity then
  1366. peoptheader.LoaderFlags:=peflags;
  1367. if ImageBaseSetExplicity then
  1368. peoptheader.ImageBase:=imagebase;
  1369. if MinStackSizeSetExplicity then
  1370. peoptheader.SizeOfStackCommit:=minstacksize;
  1371. if MaxStackSizeSetExplicity then
  1372. peoptheader.SizeOfStackReserve:=maxstacksize;
  1373. { change the header }
  1374. { sub system }
  1375. { gui=2 }
  1376. { cui=3 }
  1377. { wincegui=9 }
  1378. if target_info.system in [system_arm_wince,system_i386_wince] then
  1379. peoptheader.Subsystem:=9
  1380. else
  1381. case apptype of
  1382. app_native :
  1383. peoptheader.Subsystem:=1;
  1384. app_gui :
  1385. peoptheader.Subsystem:=2;
  1386. app_cui :
  1387. peoptheader.Subsystem:=3;
  1388. end;
  1389. if dllversion<>'' then
  1390. begin
  1391. peoptheader.MajorImageVersion:=dllmajor;
  1392. peoptheader.MinorImageVersion:=dllminor;
  1393. end;
  1394. { reset timestamp }
  1395. peheader.time:=0;
  1396. { write header back, skip pe magic }
  1397. seek(f,peheaderpos+4);
  1398. blockwrite(f,peheader,sizeof(tcoffheader));
  1399. if ioresult<>0 then
  1400. Message1(execinfo_f_cant_process_executable,fn);
  1401. blockwrite(f,peoptheader,sizeof(tcoffpeoptheader));
  1402. if ioresult<>0 then
  1403. Message1(execinfo_f_cant_process_executable,fn);
  1404. { skip to headerpos and skip pe magic }
  1405. seek(f,peheaderpos+4);
  1406. blockread(f,peheader,sizeof(tcoffheader));
  1407. blockread(f,peoptheader,sizeof(tcoffpeoptheader));
  1408. { write the value after the change }
  1409. Message1(execinfo_x_stackreserve,tostr(peoptheader.SizeOfStackReserve));
  1410. Message1(execinfo_x_stackcommit,tostr(peoptheader.SizeOfStackCommit));
  1411. { read section info }
  1412. maxfillsize:=0;
  1413. firstsecpos:=0;
  1414. secroot:=nil;
  1415. for l:=1 to peheader.nsects do
  1416. begin
  1417. blockread(f,coffsec,sizeof(tcoffsechdr));
  1418. if coffsec.datapos>0 then
  1419. begin
  1420. if secroot=nil then
  1421. firstsecpos:=coffsec.datapos;
  1422. new(hsecroot);
  1423. hsecroot^.fillpos:=coffsec.datapos+coffsec.vsize;
  1424. hsecroot^.fillsize:=coffsec.datasize-coffsec.vsize;
  1425. hsecroot^.next:=secroot;
  1426. secroot:=hsecroot;
  1427. if secroot^.fillsize>maxfillsize then
  1428. maxfillsize:=secroot^.fillsize;
  1429. end;
  1430. end;
  1431. if firstsecpos>0 then
  1432. begin
  1433. l:=firstsecpos-filepos(f);
  1434. if l>maxfillsize then
  1435. maxfillsize:=l;
  1436. end
  1437. else
  1438. l:=0;
  1439. { get zero buffer }
  1440. getmem(zerobuf,maxfillsize);
  1441. fillchar(zerobuf^,maxfillsize,0);
  1442. { zero from sectioninfo until first section }
  1443. blockwrite(f,zerobuf^,l);
  1444. { zero section alignments }
  1445. while assigned(secroot) do
  1446. begin
  1447. seek(f,secroot^.fillpos);
  1448. blockwrite(f,zerobuf^,secroot^.fillsize);
  1449. hsecroot:=secroot;
  1450. secroot:=secroot^.next;
  1451. dispose(hsecroot);
  1452. end;
  1453. freemem(zerobuf,maxfillsize);
  1454. close(f);
  1455. {$I+}
  1456. if ioresult<>0 then;
  1457. postprocessexecutable:=true;
  1458. end;
  1459. {****************************************************************************
  1460. TDLLScannerWin32
  1461. ****************************************************************************}
  1462. procedure tDLLScannerWin32.CheckDLLFunc(const dllname,funcname:string);
  1463. var
  1464. hp : tExternalsItem;
  1465. begin
  1466. hp:=tExternalsItem(current_module.Externals.first);
  1467. while assigned(hp)do
  1468. begin
  1469. if (not hp.found) and
  1470. assigned(hp.data) and
  1471. (hp.data^=funcname) then
  1472. begin
  1473. hp.found:=true;
  1474. if not(current_module.uses_imports) then
  1475. begin
  1476. current_module.uses_imports:=true;
  1477. importlib.preparelib(current_module.modulename^);
  1478. end;
  1479. timportlibwin32(importlib).importprocedure_str(dllname,0,funcname);
  1480. importfound:=true;
  1481. exit;
  1482. end;
  1483. hp:=tExternalsItem(hp.next);
  1484. end;
  1485. end;
  1486. function tDLLScannerWin32.scan(const binname:string):boolean;
  1487. var
  1488. hs,
  1489. dllname : string;
  1490. begin
  1491. result:=false;
  1492. { is there already an import library the we will use that one }
  1493. if FindLibraryFile(binname,target_info.staticClibprefix,target_info.staticClibext,hs) then
  1494. exit;
  1495. { check if we can find the dll }
  1496. hs:=AddExtension(binname,target_info.sharedlibext);
  1497. if not FindDll(hs,dllname) then
  1498. exit;
  1499. importfound:=false;
  1500. ReadDLLImports(dllname,@CheckDLLFunc);
  1501. result:=importfound;
  1502. end;
  1503. {*****************************************************************************
  1504. Initialize
  1505. *****************************************************************************}
  1506. initialization
  1507. {$ifdef i386}
  1508. RegisterExternalLinker(system_i386_win32_info,TLinkerWin32);
  1509. RegisterInternalLinker(system_i386_win32_info,TPECoffLinker);
  1510. RegisterImport(system_i386_win32,TImportLibWin32);
  1511. RegisterExport(system_i386_win32,TExportLibWin32);
  1512. RegisterDLLScanner(system_i386_win32,TDLLScannerWin32);
  1513. RegisterRes(res_gnu_windres_info);
  1514. RegisterTarget(system_i386_win32_info);
  1515. RegisterExternalLinker(system_i386_wince_info,TLinkerWin32);
  1516. RegisterImport(system_i386_wince,TImportLibWin32);
  1517. RegisterExport(system_i386_wince,TExportLibWin32);
  1518. RegisterDLLScanner(system_i386_wince,TDLLScannerWin32);
  1519. RegisterTarget(system_i386_wince_info);
  1520. {$endif i386}
  1521. {$ifdef x86_64}
  1522. RegisterInternalLinker(system_x64_win64_info,TPECoffLinker);
  1523. RegisterImport(system_x86_64_win64,TImportLibWin32);
  1524. RegisterExport(system_x86_64_win64,TExportLibWin32);
  1525. RegisterDLLScanner(system_x86_64_win64,TDLLScannerWin32);
  1526. RegisterRes(res_gnu_windres_info);
  1527. RegisterTarget(system_x64_win64_info);
  1528. {$endif x86_64}
  1529. {$ifdef arm}
  1530. RegisterExternalLinker(system_arm_wince_info,TLinkerWin32);
  1531. RegisterInternalLinker(system_arm_wince_info,TPECoffLinker);
  1532. RegisterImport(system_arm_wince,TImportLibWin32);
  1533. RegisterExport(system_arm_wince,TExportLibWin32);
  1534. RegisterRes(res_gnu_wince_windres_info);
  1535. RegisterTarget(system_arm_wince_info);
  1536. {$endif arm}
  1537. end.