t_win32.pas 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Peter Vreman
  4. This unit implements support import,export,link routines
  5. for the (i386) Win32 target
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit t_win32;
  20. {$i defines.inc}
  21. interface
  22. uses
  23. import,export,link;
  24. const
  25. winstackpagesize = 4096;
  26. type
  27. timportlibwin32=class(timportlib)
  28. procedure preparelib(const s:string);override;
  29. procedure importprocedure(const func,module:string;index:longint;const name:string);override;
  30. procedure importvariable(const varname,module:string;const name:string);override;
  31. procedure generatelib;override;
  32. procedure generatenasmlib;virtual;
  33. procedure generatesmartlib;override;
  34. end;
  35. texportlibwin32=class(texportlib)
  36. st : string;
  37. last_index : longint;
  38. procedure preparelib(const s:string);override;
  39. procedure exportprocedure(hp : texported_item);override;
  40. procedure exportvar(hp : texported_item);override;
  41. procedure generatelib;override;
  42. procedure generatenasmlib;virtual;
  43. end;
  44. tlinkerwin32=class(tlinker)
  45. private
  46. Function WriteResponseFile(isdll:boolean) : Boolean;
  47. Function PostProcessExecutable(const fn:string;isdll:boolean) : Boolean;
  48. public
  49. Constructor Create;
  50. Procedure SetDefaultInfo;override;
  51. function MakeExecutable:boolean;override;
  52. function MakeSharedLibrary:boolean;override;
  53. end;
  54. implementation
  55. uses
  56. {$ifdef Delphi}
  57. dmisc,
  58. {$else Delphi}
  59. dos,
  60. {$endif Delphi}
  61. cutils,cclasses,
  62. aasm,fmodule,globtype,globals,systems,verbose,
  63. script,gendef,impdef,
  64. cpubase,cpuasm
  65. {$ifdef GDB}
  66. ,gdb
  67. {$endif}
  68. ;
  69. function DllName(Const Name : string) : string;
  70. var n : string;
  71. begin
  72. n:=Upper(SplitExtension(Name));
  73. if (n='.DLL') or (n='.DRV') or (n='.EXE') then
  74. DllName:=Name
  75. else
  76. DllName:=Name+target_os.sharedlibext;
  77. end;
  78. function FindDLL(const s:string):string;
  79. var
  80. sysdir : string;
  81. FoundDll : string;
  82. Found : boolean;
  83. begin
  84. Found:=false;
  85. { Look for DLL in:
  86. 1. Current dir
  87. 2. Library Path
  88. 3. windir,windir/system,windir/system32 }
  89. Found:=FindFile(s,'.'+DirSep,founddll);
  90. if (not found) then
  91. Found:=includesearchpath.FindFile(s,founddll);
  92. if (not found) then
  93. begin
  94. sysdir:=FixPath(GetEnv('windir'),false);
  95. Found:=FindFile(s,sysdir+';'+sysdir+'system'+DirSep+';'+sysdir+'system32'+DirSep,founddll);
  96. end;
  97. if (not found) then
  98. begin
  99. message1(exec_w_libfile_not_found,s);
  100. FoundDll:=s;
  101. end;
  102. FindDll:=FoundDll;
  103. end;
  104. {*****************************************************************************
  105. TIMPORTLIBWIN32
  106. *****************************************************************************}
  107. procedure timportlibwin32.preparelib(const s : string);
  108. begin
  109. if not(assigned(importssection)) then
  110. importssection:=TAAsmoutput.create;
  111. end;
  112. procedure timportlibwin32.importprocedure(const func,module : string;index : longint;const name : string);
  113. var
  114. hp1 : timportlist;
  115. hp2 : timported_item;
  116. hs : string;
  117. begin
  118. hs:=DllName(module);
  119. { search for the module }
  120. hp1:=timportlist(current_module.imports.first);
  121. while assigned(hp1) do
  122. begin
  123. if hs=hp1.dllname^ then
  124. break;
  125. hp1:=timportlist(hp1.next);
  126. end;
  127. { generate a new item ? }
  128. if not(assigned(hp1)) then
  129. begin
  130. hp1:=timportlist.create(hs);
  131. current_module.imports.concat(hp1);
  132. end;
  133. { search for reuse of old import item }
  134. hp2:=timported_item(hp1.imported_items.first);
  135. while assigned(hp2) do
  136. begin
  137. if hp2.func^=func then
  138. break;
  139. hp2:=timported_item(hp2.next);
  140. end;
  141. if not assigned(hp2) then
  142. begin
  143. hp2:=timported_item.create(func,name,index);
  144. hp1.imported_items.concat(hp2);
  145. end;
  146. end;
  147. procedure timportlibwin32.importvariable(const varname,module:string;const name:string);
  148. var
  149. hp1 : timportlist;
  150. hp2 : timported_item;
  151. hs : string;
  152. begin
  153. hs:=DllName(module);
  154. { search for the module }
  155. hp1:=timportlist(current_module.imports.first);
  156. while assigned(hp1) do
  157. begin
  158. if hs=hp1.dllname^ then
  159. break;
  160. hp1:=timportlist(hp1.next);
  161. end;
  162. { generate a new item ? }
  163. if not(assigned(hp1)) then
  164. begin
  165. hp1:=timportlist.create(hs);
  166. current_module.imports.concat(hp1);
  167. end;
  168. hp2:=timported_item.create_var(varname,name);
  169. hp1.imported_items.concat(hp2);
  170. end;
  171. procedure timportlibwin32.generatenasmlib;
  172. var
  173. hp1 : timportlist;
  174. hp2 : timported_item;
  175. p : pchar;
  176. begin
  177. importssection.concat(tai_section.create(sec_code));
  178. hp1:=timportlist(current_module.imports.first);
  179. while assigned(hp1) do
  180. begin
  181. hp2:=timported_item(hp1.imported_items.first);
  182. while assigned(hp2) do
  183. begin
  184. if (aktoutputformat=as_i386_tasm) or
  185. (aktoutputformat=as_i386_masm) then
  186. p:=strpnew(#9+'EXTRN '+hp2.func^)
  187. else
  188. p:=strpnew(#9+'EXTERN '+hp2.func^);
  189. importssection.concat(tai_direct.create(p));
  190. p:=strpnew(#9+'import '+hp2.func^+' '+hp1.dllname^+' '+hp2.name^);
  191. importssection.concat(tai_direct.create(p));
  192. hp2:=timported_item(hp2.next);
  193. end;
  194. hp1:=timportlist(hp1.next);
  195. end;
  196. end;
  197. procedure timportlibwin32.generatesmartlib;
  198. var
  199. hp1 : timportlist;
  200. hp2 : timported_item;
  201. lhead,lname,lcode,
  202. lidata4,lidata5 : pasmlabel;
  203. r : preference;
  204. begin
  205. if (aktoutputformat<>as_i386_asw) and
  206. (aktoutputformat<>as_i386_pecoff) then
  207. begin
  208. generatenasmlib;
  209. exit;
  210. end;
  211. hp1:=timportlist(current_module.imports.first);
  212. while assigned(hp1) do
  213. begin
  214. { Get labels for the sections }
  215. getdatalabel(lhead);
  216. getdatalabel(lname);
  217. getaddrlabel(lidata4);
  218. getaddrlabel(lidata5);
  219. { create header for this importmodule }
  220. importsSection.concat(Tai_cut.Create_begin);
  221. importsSection.concat(Tai_section.Create(sec_idata2));
  222. importsSection.concat(Tai_label.Create(lhead));
  223. { pointer to procedure names }
  224. importsSection.concat(Tai_const_symbol.Create_rva(lidata4));
  225. { two empty entries follow }
  226. importsSection.concat(Tai_const.Create_32bit(0));
  227. importsSection.concat(Tai_const.Create_32bit(0));
  228. { pointer to dll name }
  229. importsSection.concat(Tai_const_symbol.Create_rva(lname));
  230. { pointer to fixups }
  231. importsSection.concat(Tai_const_symbol.Create_rva(lidata5));
  232. { first write the name references }
  233. importsSection.concat(Tai_section.Create(sec_idata4));
  234. importsSection.concat(Tai_const.Create_32bit(0));
  235. importsSection.concat(Tai_label.Create(lidata4));
  236. { then the addresses and create also the indirect jump }
  237. importsSection.concat(Tai_section.Create(sec_idata5));
  238. importsSection.concat(Tai_const.Create_32bit(0));
  239. importsSection.concat(Tai_label.Create(lidata5));
  240. { create procedures }
  241. hp2:=timported_item(hp1.imported_items.first);
  242. while assigned(hp2) do
  243. begin
  244. { insert cuts }
  245. importsSection.concat(Tai_cut.Create);
  246. { create indirect jump }
  247. if not hp2.is_var then
  248. begin
  249. getlabel(lcode);
  250. new(r);
  251. reset_reference(r^);
  252. r^.symbol:=lcode;
  253. { place jump in codesegment, insert a code section in the
  254. importsection to reduce the amount of .s files (PFV) }
  255. importsSection.concat(Tai_section.Create(sec_code));
  256. {$IfDef GDB}
  257. if (cs_debuginfo in aktmoduleswitches) then
  258. importsSection.concat(Tai_stab_function_name.Create(nil));
  259. {$EndIf GDB}
  260. importsSection.concat(Tai_symbol.Createname_global(hp2.func^,0));
  261. importsSection.concat(Taicpu.Op_ref(A_JMP,S_NO,r));
  262. importsSection.concat(Tai_align.Create_op(4,$90));
  263. end;
  264. { create head link }
  265. importsSection.concat(Tai_section.Create(sec_idata7));
  266. importsSection.concat(Tai_const_symbol.Create_rva(lhead));
  267. { fixup }
  268. getlabel(pasmlabel(hp2.lab));
  269. importsSection.concat(Tai_section.Create(sec_idata4));
  270. importsSection.concat(Tai_const_symbol.Create_rva(hp2.lab));
  271. { add jump field to importsection }
  272. importsSection.concat(Tai_section.Create(sec_idata5));
  273. if hp2.is_var then
  274. importsSection.concat(Tai_symbol.Createname_global(hp2.func^,0))
  275. else
  276. importsSection.concat(Tai_label.Create(lcode));
  277. if hp2.name^<>'' then
  278. importsSection.concat(Tai_const_symbol.Create_rva(hp2.lab))
  279. else
  280. importsSection.concat(Tai_const.Create_32bit($80000000 or hp2.ordnr));
  281. { finally the import information }
  282. importsSection.concat(Tai_section.Create(sec_idata6));
  283. importsSection.concat(Tai_label.Create(hp2.lab));
  284. importsSection.concat(Tai_const.Create_16bit(hp2.ordnr));
  285. importsSection.concat(Tai_string.Create(hp2.name^+#0));
  286. importsSection.concat(Tai_align.Create_op(2,0));
  287. hp2:=timported_item(hp2.next);
  288. end;
  289. { write final section }
  290. importsSection.concat(Tai_cut.Create_end);
  291. { end of name references }
  292. importsSection.concat(Tai_section.Create(sec_idata4));
  293. importsSection.concat(Tai_const.Create_32bit(0));
  294. { end if addresses }
  295. importsSection.concat(Tai_section.Create(sec_idata5));
  296. importsSection.concat(Tai_const.Create_32bit(0));
  297. { dllname }
  298. importsSection.concat(Tai_section.Create(sec_idata7));
  299. importsSection.concat(Tai_label.Create(lname));
  300. importsSection.concat(Tai_string.Create(hp1.dllname^+#0));
  301. hp1:=timportlist(hp1.next);
  302. end;
  303. end;
  304. procedure timportlibwin32.generatelib;
  305. var
  306. hp1 : timportlist;
  307. hp2 : timported_item;
  308. l1,l2,l3,l4 : pasmlabel;
  309. r : preference;
  310. begin
  311. if (aktoutputformat<>as_i386_asw) and
  312. (aktoutputformat<>as_i386_pecoff) then
  313. begin
  314. generatenasmlib;
  315. exit;
  316. end;
  317. hp1:=timportlist(current_module.imports.first);
  318. while assigned(hp1) do
  319. begin
  320. { align codesegment for the jumps }
  321. importsSection.concat(Tai_section.Create(sec_code));
  322. importsSection.concat(Tai_align.Create_op(4,$90));
  323. { Get labels for the sections }
  324. getlabel(l1);
  325. getlabel(l2);
  326. getlabel(l3);
  327. importsSection.concat(Tai_section.Create(sec_idata2));
  328. { pointer to procedure names }
  329. importsSection.concat(Tai_const_symbol.Create_rva(l2));
  330. { two empty entries follow }
  331. importsSection.concat(Tai_const.Create_32bit(0));
  332. importsSection.concat(Tai_const.Create_32bit(0));
  333. { pointer to dll name }
  334. importsSection.concat(Tai_const_symbol.Create_rva(l1));
  335. { pointer to fixups }
  336. importsSection.concat(Tai_const_symbol.Create_rva(l3));
  337. { only create one section for each else it will
  338. create a lot of idata* }
  339. { first write the name references }
  340. importsSection.concat(Tai_section.Create(sec_idata4));
  341. importsSection.concat(Tai_label.Create(l2));
  342. hp2:=timported_item(hp1.imported_items.first);
  343. while assigned(hp2) do
  344. begin
  345. getlabel(pasmlabel(hp2.lab));
  346. if hp2.name^<>'' then
  347. importsSection.concat(Tai_const_symbol.Create_rva(hp2.lab))
  348. else
  349. importsSection.concat(Tai_const.Create_32bit($80000000 or hp2.ordnr));
  350. hp2:=timported_item(hp2.next);
  351. end;
  352. { finalize the names ... }
  353. importsSection.concat(Tai_const.Create_32bit(0));
  354. { then the addresses and create also the indirect jump }
  355. importsSection.concat(Tai_section.Create(sec_idata5));
  356. importsSection.concat(Tai_label.Create(l3));
  357. hp2:=timported_item(hp1.imported_items.first);
  358. while assigned(hp2) do
  359. begin
  360. if not hp2.is_var then
  361. begin
  362. getlabel(l4);
  363. { create indirect jump }
  364. new(r);
  365. reset_reference(r^);
  366. r^.symbol:=l4;
  367. { place jump in codesegment }
  368. importsSection.concat(Tai_section.Create(sec_code));
  369. importsSection.concat(Tai_symbol.Createname_global(hp2.func^,0));
  370. importsSection.concat(Taicpu.Op_ref(A_JMP,S_NO,r));
  371. importsSection.concat(Tai_align.Create_op(4,$90));
  372. { add jump field to importsection }
  373. importsSection.concat(Tai_section.Create(sec_idata5));
  374. importsSection.concat(Tai_label.Create(l4));
  375. end
  376. else
  377. begin
  378. importsSection.concat(Tai_symbol.Createname_global(hp2.func^,0));
  379. end;
  380. importsSection.concat(Tai_const_symbol.Create_rva(hp2.lab));
  381. hp2:=timported_item(hp2.next);
  382. end;
  383. { finalize the addresses }
  384. importsSection.concat(Tai_const.Create_32bit(0));
  385. { finally the import information }
  386. importsSection.concat(Tai_section.Create(sec_idata6));
  387. hp2:=timported_item(hp1.imported_items.first);
  388. while assigned(hp2) do
  389. begin
  390. importsSection.concat(Tai_label.Create(hp2.lab));
  391. { the ordinal number }
  392. importsSection.concat(Tai_const.Create_16bit(hp2.ordnr));
  393. importsSection.concat(Tai_string.Create(hp2.name^+#0));
  394. importsSection.concat(Tai_align.Create_op(2,0));
  395. hp2:=timported_item(hp2.next);
  396. end;
  397. { create import dll name }
  398. importsSection.concat(Tai_section.Create(sec_idata7));
  399. importsSection.concat(Tai_label.Create(l1));
  400. importsSection.concat(Tai_string.Create(hp1.dllname^+#0));
  401. hp1:=timportlist(hp1.next);
  402. end;
  403. end;
  404. {*****************************************************************************
  405. TEXPORTLIBWIN32
  406. *****************************************************************************}
  407. procedure texportlibwin32.preparelib(const s:string);
  408. begin
  409. if not(assigned(exportssection)) then
  410. exportssection:=TAAsmoutput.create;
  411. last_index:=0;
  412. end;
  413. procedure texportlibwin32.exportvar(hp : texported_item);
  414. begin
  415. { same code used !! PM }
  416. exportprocedure(hp);
  417. end;
  418. procedure texportlibwin32.exportprocedure(hp : texported_item);
  419. { must be ordered at least for win32 !! }
  420. var
  421. hp2 : texported_item;
  422. begin
  423. { first test the index value }
  424. if (hp.options and eo_index)<>0 then
  425. begin
  426. if (hp.index<=0) or (hp.index>$ffff) then
  427. begin
  428. message1(parser_e_export_invalid_index,tostr(hp.index));
  429. exit;
  430. end;
  431. if (hp.index<=last_index) then
  432. begin
  433. message1(parser_e_export_ordinal_double,tostr(hp.index));
  434. { disregard index value }
  435. inc(last_index);
  436. hp.index:=last_index;
  437. exit;
  438. end
  439. else
  440. begin
  441. last_index:=hp.index;
  442. end;
  443. end
  444. else
  445. begin
  446. inc(last_index);
  447. hp.index:=last_index;
  448. end;
  449. { now place in correct order }
  450. hp2:=texported_item(current_module._exports.first);
  451. while assigned(hp2) and
  452. (hp.name^>hp2.name^) do
  453. hp2:=texported_item(hp2.next);
  454. { insert hp there !! }
  455. if assigned(hp2) and (hp2.name^=hp.name^) then
  456. begin
  457. { this is not allowed !! }
  458. message1(parser_e_export_name_double,hp.name^);
  459. exit;
  460. end;
  461. if hp2=texported_item(current_module._exports.first) then
  462. current_module._exports.concat(hp)
  463. else if assigned(hp2) then
  464. begin
  465. hp.next:=hp2;
  466. hp.previous:=hp2.previous;
  467. if assigned(hp2.previous) then
  468. hp2.previous.next:=hp;
  469. hp2.previous:=hp;
  470. end
  471. else
  472. current_module._exports.concat(hp);
  473. end;
  474. procedure texportlibwin32.generatelib;
  475. var
  476. ordinal_base,ordinal_max,ordinal_min : longint;
  477. current_index : longint;
  478. entries,named_entries : longint;
  479. name_label,dll_name_label,export_address_table : pasmlabel;
  480. export_name_table_pointers,export_ordinal_table : pasmlabel;
  481. hp,hp2 : texported_item;
  482. temtexport : TLinkedList;
  483. address_table,name_table_pointers,
  484. name_table,ordinal_table : TAAsmoutput;
  485. begin
  486. if (aktoutputformat<>as_i386_asw) and
  487. (aktoutputformat<>as_i386_pecoff) then
  488. begin
  489. generatenasmlib;
  490. exit;
  491. end;
  492. hp:=texported_item(current_module._exports.first);
  493. if not assigned(hp) then
  494. exit;
  495. ordinal_max:=0;
  496. ordinal_min:=$7FFFFFFF;
  497. entries:=0;
  498. named_entries:=0;
  499. getlabel(dll_name_label);
  500. getlabel(export_address_table);
  501. getlabel(export_name_table_pointers);
  502. getlabel(export_ordinal_table);
  503. { count entries }
  504. while assigned(hp) do
  505. begin
  506. inc(entries);
  507. if (hp.index>ordinal_max) then
  508. ordinal_max:=hp.index;
  509. if (hp.index>0) and (hp.index<ordinal_min) then
  510. ordinal_min:=hp.index;
  511. if assigned(hp.name) then
  512. inc(named_entries);
  513. hp:=texported_item(hp.next);
  514. end;
  515. { no support for higher ordinal base yet !! }
  516. ordinal_base:=1;
  517. current_index:=ordinal_base;
  518. { we must also count the holes !! }
  519. entries:=ordinal_max-ordinal_base+1;
  520. exportsSection.concat(Tai_section.Create(sec_edata));
  521. { export flags }
  522. exportsSection.concat(Tai_const.Create_32bit(0));
  523. { date/time stamp }
  524. exportsSection.concat(Tai_const.Create_32bit(0));
  525. { major version }
  526. exportsSection.concat(Tai_const.Create_16bit(0));
  527. { minor version }
  528. exportsSection.concat(Tai_const.Create_16bit(0));
  529. { pointer to dll name }
  530. exportsSection.concat(Tai_const_symbol.Create_rva(dll_name_label));
  531. { ordinal base normally set to 1 }
  532. exportsSection.concat(Tai_const.Create_32bit(ordinal_base));
  533. { number of entries }
  534. exportsSection.concat(Tai_const.Create_32bit(entries));
  535. { number of named entries }
  536. exportsSection.concat(Tai_const.Create_32bit(named_entries));
  537. { address of export address table }
  538. exportsSection.concat(Tai_const_symbol.Create_rva(export_address_table));
  539. { address of name pointer pointers }
  540. exportsSection.concat(Tai_const_symbol.Create_rva(export_name_table_pointers));
  541. { address of ordinal number pointers }
  542. exportsSection.concat(Tai_const_symbol.Create_rva(export_ordinal_table));
  543. { the name }
  544. exportsSection.concat(Tai_label.Create(dll_name_label));
  545. if st='' then
  546. exportsSection.concat(Tai_string.Create(current_module.modulename^+target_os.sharedlibext+#0))
  547. else
  548. exportsSection.concat(Tai_string.Create(st+target_os.sharedlibext+#0));
  549. { export address table }
  550. address_table:=TAAsmoutput.create;
  551. address_table.concat(Tai_align.Create_op(4,0));
  552. address_table.concat(Tai_label.Create(export_address_table));
  553. name_table_pointers:=TAAsmoutput.create;
  554. name_table_pointers.concat(Tai_align.Create_op(4,0));
  555. name_table_pointers.concat(Tai_label.Create(export_name_table_pointers));
  556. ordinal_table:=TAAsmoutput.create;
  557. ordinal_table.concat(Tai_align.Create_op(4,0));
  558. ordinal_table.concat(Tai_label.Create(export_ordinal_table));
  559. name_table:=TAAsmoutput.Create;
  560. name_table.concat(Tai_align.Create_op(4,0));
  561. { write each address }
  562. hp:=texported_item(current_module._exports.first);
  563. while assigned(hp) do
  564. begin
  565. if (hp.options and eo_name)<>0 then
  566. begin
  567. getlabel(name_label);
  568. name_table_pointers.concat(Tai_const_symbol.Create_rva(name_label));
  569. ordinal_table.concat(Tai_const.Create_16bit(hp.index-ordinal_base));
  570. name_table.concat(Tai_align.Create_op(2,0));
  571. name_table.concat(Tai_label.Create(name_label));
  572. name_table.concat(Tai_string.Create(hp.name^+#0));
  573. end;
  574. hp:=texported_item(hp.next);
  575. end;
  576. { order in increasing ordinal values }
  577. { into temtexport list }
  578. temtexport:=TLinkedList.Create;
  579. hp:=texported_item(current_module._exports.first);
  580. while assigned(hp) do
  581. begin
  582. current_module._exports.remove(hp);
  583. hp2:=texported_item(temtexport.first);
  584. while assigned(hp2) and (hp.index>hp2.index) do
  585. begin
  586. hp2:=texported_item(hp2.next);
  587. end;
  588. if hp2=texported_item(temtexport.first) then
  589. temtexport.insert(hp)
  590. else
  591. begin
  592. if assigned(hp2) then
  593. begin
  594. hp.next:=hp2;
  595. hp.previous:=hp2.previous;
  596. hp2.previous:=hp;
  597. if assigned(hp.previous) then
  598. hp.previous.next:=hp;
  599. end
  600. else
  601. temtexport.concat(hp);
  602. end;
  603. hp:=texported_item(current_module._exports.first);;
  604. end;
  605. { write the export adress table }
  606. current_index:=ordinal_base;
  607. hp:=texported_item(temtexport.first);
  608. while assigned(hp) do
  609. begin
  610. { fill missing values }
  611. while current_index<hp.index do
  612. begin
  613. address_table.concat(Tai_const.Create_32bit(0));
  614. inc(current_index);
  615. end;
  616. address_table.concat(Tai_const_symbol.Createname_rva(hp.sym^.mangledname));
  617. inc(current_index);
  618. hp:=texported_item(hp.next);
  619. end;
  620. exportsSection.concatlist(address_table);
  621. exportsSection.concatlist(name_table_pointers);
  622. exportsSection.concatlist(ordinal_table);
  623. exportsSection.concatlist(name_table);
  624. address_table.Free;
  625. name_table_pointers.free;
  626. ordinal_table.free;
  627. name_table.free;
  628. temtexport.free;
  629. end;
  630. procedure texportlibwin32.generatenasmlib;
  631. var
  632. hp : texported_item;
  633. p : pchar;
  634. begin
  635. exportssection.concat(tai_section.create(sec_code));
  636. hp:=texported_item(current_module._exports.first);
  637. while assigned(hp) do
  638. begin
  639. p:=strpnew(#9+'export '+hp.sym^.mangledname+' '+hp.name^+' '+tostr(hp.index));
  640. exportssection.concat(tai_direct.create(p));
  641. hp:=texported_item(hp.next);
  642. end;
  643. end;
  644. {****************************************************************************
  645. TLINKERWIN32
  646. ****************************************************************************}
  647. Constructor TLinkerWin32.Create;
  648. begin
  649. Inherited Create;
  650. { allow duplicated libs (PM) }
  651. SharedLibFiles.doubles:=true;
  652. StaticLibFiles.doubles:=true;
  653. If not ForceDeffileForExport then
  654. UseDeffileForExport:=false;
  655. end;
  656. Procedure TLinkerWin32.SetDefaultInfo;
  657. begin
  658. with Info do
  659. begin
  660. ExeCmd[1]:='ldw $OPT $STRIP $APPTYPE $IMAGEBASE $RELOC -o $EXE $RES';
  661. DllCmd[1]:='ldw $OPT $STRIP --dll $APPTYPE $IMAGEBASE $RELOC -o $EXE $RES';
  662. if RelocSection or UseDeffileForExport then
  663. begin
  664. { ExeCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF';
  665. use short forms to avoid 128 char limitation problem }
  666. ExeCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
  667. ExeCmd[3]:='ldw $OPT $STRIP $APPTYPE $IMAGEBASE -o $EXE $RES exp.$$$';
  668. { DllCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF'; }
  669. DllCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
  670. DllCmd[3]:='ldw $OPT $STRIP --dll $APPTYPE $IMAGEBASE -o $EXE $RES exp.$$$';
  671. end;
  672. end;
  673. end;
  674. Function TLinkerWin32.WriteResponseFile(isdll:boolean) : Boolean;
  675. function do_makedef(const DllName,LibName:string):boolean;
  676. var
  677. CmdLine : string;
  678. begin
  679. if (not do_build) and
  680. FileExists(LibName) then
  681. begin
  682. if GetNamedFileTime(LibName)>GetNamedFileTime(DllName) then
  683. begin
  684. do_makedef:=true;
  685. exit;
  686. end;
  687. end;
  688. asw_name:=FindUtil('asw');
  689. arw_name:=FindUtil('arw');
  690. if cs_link_extern in aktglobalswitches then
  691. begin
  692. CmdLine:='-l '+LibName+' -i '+DLLName;
  693. if asw_name<>'' then
  694. CmdLine:=CmdLine+' -a '+asw_name;
  695. if arw_name<>'' then
  696. CmdLine:=CmdLine+' -r '+arw_name;
  697. do_makedef:=DoExec(FindUtil('fpimpdef'),CmdLine,false,false);
  698. end
  699. else
  700. do_makedef:=makedef(DLLName,LIbName);
  701. end;
  702. Var
  703. linkres : TLinkRes;
  704. i : longint;
  705. HPath : TStringListItem;
  706. s,s2 : string;
  707. found,
  708. linklibc : boolean;
  709. begin
  710. WriteResponseFile:=False;
  711. { Create static import libraries for DLL that are
  712. included using the $linklib directive }
  713. While not SharedLibFiles.Empty do
  714. begin
  715. s:=SharedLibFiles.GetFirst;
  716. s2:=AddExtension(s,target_os.sharedlibext);
  717. s:=target_os.libprefix+SplitName(s)+target_os.staticlibext;
  718. if Do_makedef(FindDLL(s2),s) then
  719. begin
  720. if s<>''then
  721. StaticLibFiles.insert(s);
  722. end
  723. else
  724. begin
  725. Message(exec_w_error_while_linking);
  726. aktglobalswitches:=aktglobalswitches+[cs_link_extern];
  727. end;
  728. end;
  729. { Open link.res file }
  730. LinkRes.Init(outputexedir+Info.ResName);
  731. { Write path to search libraries }
  732. HPath:=TStringListItem(current_module.locallibrarysearchpath.First);
  733. while assigned(HPath) do
  734. begin
  735. LinkRes.Add('SEARCH_DIR('+GetShortName(HPath.Str)+')');
  736. HPath:=TStringListItem(HPath.Next);
  737. end;
  738. HPath:=TStringListItem(LibrarySearchPath.First);
  739. while assigned(HPath) do
  740. begin
  741. LinkRes.Add('SEARCH_DIR('+GetShortName(HPath.Str)+')');
  742. HPath:=TStringListItem(HPath.Next);
  743. end;
  744. { add objectfiles, start with prt0 always }
  745. LinkRes.Add('INPUT(');
  746. if isdll then
  747. LinkRes.AddFileName(GetShortName(FindObjectFile('wdllprt0','')))
  748. else
  749. LinkRes.AddFileName(GetShortName(FindObjectFile('wprt0','')));
  750. while not ObjectFiles.Empty do
  751. begin
  752. s:=ObjectFiles.GetFirst;
  753. if s<>'' then
  754. LinkRes.AddFileName(GetShortName(s));
  755. end;
  756. LinkRes.Add(')');
  757. { Write staticlibraries }
  758. if not StaticLibFiles.Empty then
  759. begin
  760. LinkRes.Add('GROUP(');
  761. While not StaticLibFiles.Empty do
  762. begin
  763. S:=StaticLibFiles.GetFirst;
  764. LinkRes.AddFileName(GetShortName(s));
  765. end;
  766. LinkRes.Add(')');
  767. end;
  768. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  769. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  770. if not SharedLibFiles.Empty then
  771. begin
  772. linklibc:=false;
  773. LinkRes.Add('INPUT(');
  774. While not SharedLibFiles.Empty do
  775. begin
  776. S:=SharedLibFiles.GetFirst;
  777. if pos('.',s)=0 then
  778. { we never directly link a DLL
  779. its allways through an import library PM }
  780. { libraries created by C compilers have .a extensions }
  781. s2:=s+'.a'{ target_os.sharedlibext }
  782. else
  783. s2:=s;
  784. s2:=FindLibraryFile(s2,'',found);
  785. if found then
  786. begin
  787. LinkRes.Add(s2);
  788. continue;
  789. end;
  790. if pos(target_os.libprefix,s)=1 then
  791. s:=copy(s,length(target_os.libprefix)+1,255);
  792. if s<>'c' then
  793. begin
  794. i:=Pos(target_os.sharedlibext,S);
  795. if i>0 then
  796. Delete(S,i,255);
  797. LinkRes.Add('-l'+s);
  798. end
  799. else
  800. begin
  801. LinkRes.Add('-l'+s);
  802. linklibc:=true;
  803. end;
  804. end;
  805. { be sure that libc is the last lib }
  806. if linklibc then
  807. LinkRes.Add('-lc');
  808. LinkRes.Add(')');
  809. end;
  810. { Write and Close response }
  811. linkres.writetodisk;
  812. linkres.done;
  813. WriteResponseFile:=True;
  814. end;
  815. function TLinkerWin32.MakeExecutable:boolean;
  816. var
  817. binstr,
  818. cmdstr : string;
  819. success : boolean;
  820. i : longint;
  821. AsBinStr : string[80];
  822. StripStr,
  823. RelocStr,
  824. AppTypeStr,
  825. ImageBaseStr : string[40];
  826. begin
  827. if not(cs_link_extern in aktglobalswitches) then
  828. Message1(exec_i_linking,current_module.exefilename^);
  829. { Create some replacements }
  830. RelocStr:='';
  831. AppTypeStr:='';
  832. ImageBaseStr:='';
  833. StripStr:='';
  834. FindExe('asw',AsBinStr);
  835. if RelocSection then
  836. { Using short form to avoid problems with 128 char limitation under Dos. }
  837. RelocStr:='-b base.$$$';
  838. if apptype=app_gui then
  839. AppTypeStr:='--subsystem windows';
  840. if assigned(DLLImageBase) then
  841. ImageBaseStr:='--image-base=0x'+DLLImageBase^;
  842. if (cs_link_strip in aktglobalswitches) then
  843. StripStr:='-s';
  844. { Write used files and libraries }
  845. WriteResponseFile(false);
  846. { Call linker }
  847. success:=false;
  848. for i:=1 to 3 do
  849. begin
  850. SplitBinCmd(Info.ExeCmd[i],binstr,cmdstr);
  851. if binstr<>'' then
  852. begin
  853. Replace(cmdstr,'$EXE',current_module.exefilename^);
  854. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  855. Replace(cmdstr,'$RES',outputexedir+Info.ResName);
  856. Replace(cmdstr,'$APPTYPE',AppTypeStr);
  857. Replace(cmdstr,'$ASBIN',AsbinStr);
  858. Replace(cmdstr,'$RELOC',RelocStr);
  859. Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);
  860. Replace(cmdstr,'$STRIP',StripStr);
  861. if not DefFile.Empty {and UseDefFileForExport} then
  862. begin
  863. DefFile.WriteFile;
  864. Replace(cmdstr,'$DEF','-d '+deffile.fname);
  865. end
  866. else
  867. Replace(cmdstr,'$DEF','');
  868. success:=DoExec(FindUtil(binstr),cmdstr,(i=1),false);
  869. if not success then
  870. break;
  871. end;
  872. end;
  873. { Post process }
  874. if success then
  875. success:=PostProcessExecutable(current_module.exefilename^,false);
  876. { Remove ReponseFile }
  877. if (success) and not(cs_link_extern in aktglobalswitches) then
  878. begin
  879. RemoveFile(outputexedir+Info.ResName);
  880. RemoveFile('base.$$$');
  881. RemoveFile('exp.$$$');
  882. RemoveFile('deffile.$$$');
  883. end;
  884. MakeExecutable:=success; { otherwise a recursive call to link method }
  885. end;
  886. Function TLinkerWin32.MakeSharedLibrary:boolean;
  887. var
  888. binstr,
  889. cmdstr : string;
  890. success : boolean;
  891. i : longint;
  892. AsBinStr : string[80];
  893. StripStr,
  894. RelocStr,
  895. AppTypeStr,
  896. ImageBaseStr : string[40];
  897. begin
  898. MakeSharedLibrary:=false;
  899. if not(cs_link_extern in aktglobalswitches) then
  900. Message1(exec_i_linking,current_module.sharedlibfilename^);
  901. { Create some replacements }
  902. RelocStr:='';
  903. AppTypeStr:='';
  904. ImageBaseStr:='';
  905. StripStr:='';
  906. FindExe('asw',AsBinStr);
  907. if RelocSection then
  908. { Using short form to avoid problems with 128 char limitation under Dos. }
  909. RelocStr:='-b base.$$$';
  910. if apptype=app_gui then
  911. AppTypeStr:='--subsystem windows';
  912. if assigned(DLLImageBase) then
  913. ImageBaseStr:='--image-base=0x'+DLLImageBase^;
  914. if (cs_link_strip in aktglobalswitches) then
  915. StripStr:='-s';
  916. { Write used files and libraries }
  917. WriteResponseFile(true);
  918. { Call linker }
  919. success:=false;
  920. for i:=1 to 3 do
  921. begin
  922. SplitBinCmd(Info.DllCmd[i],binstr,cmdstr);
  923. if binstr<>'' then
  924. begin
  925. Replace(cmdstr,'$EXE',current_module.sharedlibfilename^);
  926. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  927. Replace(cmdstr,'$RES',outputexedir+Info.ResName);
  928. Replace(cmdstr,'$APPTYPE',AppTypeStr);
  929. Replace(cmdstr,'$ASBIN',AsbinStr);
  930. Replace(cmdstr,'$RELOC',RelocStr);
  931. Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);
  932. Replace(cmdstr,'$STRIP',StripStr);
  933. if not DefFile.Empty {and UseDefFileForExport} then
  934. begin
  935. DefFile.WriteFile;
  936. Replace(cmdstr,'$DEF','-d '+deffile.fname);
  937. end
  938. else
  939. Replace(cmdstr,'$DEF','');
  940. success:=DoExec(FindUtil(binstr),cmdstr,(i=1),false);
  941. if not success then
  942. break;
  943. end;
  944. end;
  945. { Post process }
  946. if success then
  947. success:=PostProcessExecutable(current_module.sharedlibfilename^,true);
  948. { Remove ReponseFile }
  949. if (success) and not(cs_link_extern in aktglobalswitches) then
  950. begin
  951. RemoveFile(outputexedir+Info.ResName);
  952. RemoveFile('base.$$$');
  953. RemoveFile('exp.$$$');
  954. end;
  955. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  956. end;
  957. function tlinkerwin32.postprocessexecutable(const fn : string;isdll:boolean):boolean;
  958. type
  959. tdosheader = packed record
  960. e_magic : word;
  961. e_cblp : word;
  962. e_cp : word;
  963. e_crlc : word;
  964. e_cparhdr : word;
  965. e_minalloc : word;
  966. e_maxalloc : word;
  967. e_ss : word;
  968. e_sp : word;
  969. e_csum : word;
  970. e_ip : word;
  971. e_cs : word;
  972. e_lfarlc : word;
  973. e_ovno : word;
  974. e_res : array[0..3] of word;
  975. e_oemid : word;
  976. e_oeminfo : word;
  977. e_res2 : array[0..9] of word;
  978. e_lfanew : longint;
  979. end;
  980. tpeheader = packed record
  981. PEMagic : array[0..3] of char;
  982. Machine : word;
  983. NumberOfSections : word;
  984. TimeDateStamp : longint;
  985. PointerToSymbolTable : longint;
  986. NumberOfSymbols : longint;
  987. SizeOfOptionalHeader : word;
  988. Characteristics : word;
  989. Magic : word;
  990. MajorLinkerVersion : byte;
  991. MinorLinkerVersion : byte;
  992. SizeOfCode : longint;
  993. SizeOfInitializedData : longint;
  994. SizeOfUninitializedData : longint;
  995. AddressOfEntryPoint : longint;
  996. BaseOfCode : longint;
  997. BaseOfData : longint;
  998. ImageBase : longint;
  999. SectionAlignment : longint;
  1000. FileAlignment : longint;
  1001. MajorOperatingSystemVersion : word;
  1002. MinorOperatingSystemVersion : word;
  1003. MajorImageVersion : word;
  1004. MinorImageVersion : word;
  1005. MajorSubsystemVersion : word;
  1006. MinorSubsystemVersion : word;
  1007. Reserved1 : longint;
  1008. SizeOfImage : longint;
  1009. SizeOfHeaders : longint;
  1010. CheckSum : longint;
  1011. Subsystem : word;
  1012. DllCharacteristics : word;
  1013. SizeOfStackReserve : longint;
  1014. SizeOfStackCommit : longint;
  1015. SizeOfHeapReserve : longint;
  1016. SizeOfHeapCommit : longint;
  1017. LoaderFlags : longint;
  1018. NumberOfRvaAndSizes : longint;
  1019. DataDirectory : array[1..$80] of byte;
  1020. end;
  1021. tcoffsechdr=packed record
  1022. name : array[0..7] of char;
  1023. vsize : longint;
  1024. rvaofs : longint;
  1025. datalen : longint;
  1026. datapos : longint;
  1027. relocpos : longint;
  1028. lineno1 : longint;
  1029. nrelocs : word;
  1030. lineno2 : word;
  1031. flags : longint;
  1032. end;
  1033. psecfill=^tsecfill;
  1034. tsecfill=record
  1035. fillpos,
  1036. fillsize : longint;
  1037. next : psecfill;
  1038. end;
  1039. var
  1040. f : file;
  1041. cmdstr : string;
  1042. dosheader : tdosheader;
  1043. peheader : tpeheader;
  1044. firstsecpos,
  1045. maxfillsize,
  1046. l,peheaderpos : longint;
  1047. coffsec : tcoffsechdr;
  1048. secroot,hsecroot : psecfill;
  1049. zerobuf : pointer;
  1050. begin
  1051. postprocessexecutable:=false;
  1052. { when -s is used or it's a dll then quit }
  1053. if (cs_link_extern in aktglobalswitches) then
  1054. begin
  1055. case apptype of
  1056. app_gui :
  1057. cmdstr:='--subsystem gui';
  1058. app_cui :
  1059. cmdstr:='--subsystem console';
  1060. end;
  1061. if dllversion<>'' then
  1062. cmdstr:=cmdstr+' --version '+dllversion;
  1063. cmdstr:=cmdstr+' --input '+fn;
  1064. cmdstr:=cmdstr+' --stack '+tostr(stacksize);
  1065. DoExec(FindUtil('postw32'),cmdstr,false,false);
  1066. postprocessexecutable:=true;
  1067. exit;
  1068. end;
  1069. { open file }
  1070. assign(f,fn);
  1071. {$I-}
  1072. reset(f,1);
  1073. if ioresult<>0 then
  1074. Message1(execinfo_f_cant_open_executable,fn);
  1075. { read headers }
  1076. blockread(f,dosheader,sizeof(tdosheader));
  1077. peheaderpos:=dosheader.e_lfanew;
  1078. seek(f,peheaderpos);
  1079. blockread(f,peheader,sizeof(tpeheader));
  1080. { write info }
  1081. Message1(execinfo_x_codesize,tostr(peheader.SizeOfCode));
  1082. Message1(execinfo_x_initdatasize,tostr(peheader.SizeOfInitializedData));
  1083. Message1(execinfo_x_uninitdatasize,tostr(peheader.SizeOfUninitializedData));
  1084. { change stack size (PM) }
  1085. { I am not sure that the default value is adequate !! }
  1086. peheader.SizeOfStackReserve:=stacksize;
  1087. { change the header }
  1088. { sub system }
  1089. { gui=2 }
  1090. { cui=3 }
  1091. case apptype of
  1092. app_gui :
  1093. peheader.Subsystem:=2;
  1094. app_cui :
  1095. peheader.Subsystem:=3;
  1096. end;
  1097. if dllversion<>'' then
  1098. begin
  1099. peheader.MajorImageVersion:=dllmajor;
  1100. peheader.MinorImageVersion:=dllminor;
  1101. end;
  1102. { reset timestamp }
  1103. peheader.TimeDateStamp:=0;
  1104. { write header back }
  1105. seek(f,peheaderpos);
  1106. blockwrite(f,peheader,sizeof(tpeheader));
  1107. if ioresult<>0 then
  1108. Message1(execinfo_f_cant_process_executable,fn);
  1109. seek(f,peheaderpos);
  1110. blockread(f,peheader,sizeof(tpeheader));
  1111. { write the value after the change }
  1112. Message1(execinfo_x_stackreserve,tostr(peheader.SizeOfStackReserve));
  1113. Message1(execinfo_x_stackcommit,tostr(peheader.SizeOfStackCommit));
  1114. { read section info }
  1115. maxfillsize:=0;
  1116. firstsecpos:=0;
  1117. secroot:=nil;
  1118. for l:=1 to peheader.NumberOfSections do
  1119. begin
  1120. blockread(f,coffsec,sizeof(tcoffsechdr));
  1121. if coffsec.datapos>0 then
  1122. begin
  1123. if secroot=nil then
  1124. firstsecpos:=coffsec.datapos;
  1125. new(hsecroot);
  1126. hsecroot^.fillpos:=coffsec.datapos+coffsec.vsize;
  1127. hsecroot^.fillsize:=coffsec.datalen-coffsec.vsize;
  1128. hsecroot^.next:=secroot;
  1129. secroot:=hsecroot;
  1130. if secroot^.fillsize>maxfillsize then
  1131. maxfillsize:=secroot^.fillsize;
  1132. end;
  1133. end;
  1134. if firstsecpos>0 then
  1135. begin
  1136. l:=firstsecpos-filepos(f);
  1137. if l>maxfillsize then
  1138. maxfillsize:=l;
  1139. end
  1140. else
  1141. l:=0;
  1142. { get zero buffer }
  1143. getmem(zerobuf,maxfillsize);
  1144. fillchar(zerobuf^,maxfillsize,0);
  1145. { zero from sectioninfo until first section }
  1146. blockwrite(f,zerobuf^,l);
  1147. { zero section alignments }
  1148. while assigned(secroot) do
  1149. begin
  1150. seek(f,secroot^.fillpos);
  1151. blockwrite(f,zerobuf^,secroot^.fillsize);
  1152. hsecroot:=secroot;
  1153. secroot:=secroot^.next;
  1154. dispose(hsecroot);
  1155. end;
  1156. freemem(zerobuf,maxfillsize);
  1157. close(f);
  1158. {$I+}
  1159. if ioresult<>0 then;
  1160. postprocessexecutable:=true;
  1161. end;
  1162. end.
  1163. {
  1164. $Log$
  1165. Revision 1.10 2001-02-20 21:41:16 peter
  1166. * new fixfilename, findfile for unix. Look first for lowercase, then
  1167. NormalCase and last for UPPERCASE names.
  1168. Revision 1.9 2001/01/13 00:09:22 peter
  1169. * made Pavel O. happy ;)
  1170. Revision 1.8 2000/12/30 22:53:25 peter
  1171. * export with the case provided in the exports section
  1172. Revision 1.7 2000/12/25 00:07:30 peter
  1173. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1174. tlinkedlist objects)
  1175. Revision 1.6 2000/11/12 22:20:37 peter
  1176. * create generic toutputsection for binary writers
  1177. Revision 1.5 2000/09/24 15:06:31 peter
  1178. * use defines.inc
  1179. Revision 1.4 2000/08/27 16:11:54 peter
  1180. * moved some util functions from globals,cobjects to cutils
  1181. * splitted files into finput,fmodule
  1182. Revision 1.3 2000/07/21 15:14:02 jonas
  1183. + added is_addr field for labels, if they are only used for getting the address
  1184. (e.g. for io checks) and corresponding getaddrlabel() procedure
  1185. Revision 1.2 2000/07/13 11:32:50 michael
  1186. + removed logs
  1187. }