dos_targ.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. {
  2. $Id$
  3. Copyright (c) 1999 by Peter Vreman
  4. This unit implements some support routines for the Dos targets
  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 dos_targ;
  19. interface
  20. uses
  21. link;
  22. type
  23. plinkergo32v2=^tlinkergo32v2;
  24. tlinkergo32v2=object(tlinker)
  25. procedure postprocessexecutable(const n : string);virtual;
  26. end;
  27. implementation
  28. uses
  29. strings,globtype,globals,cobjects,systems,verbose;
  30. {****************************************************************************
  31. Postprocess Executable
  32. ****************************************************************************}
  33. procedure tlinkergo32v2.postprocessexecutable(const n : string);
  34. begin
  35. end;
  36. {$ifdef dummy}
  37. type
  38. tcoffheader=packed record
  39. mach : word;
  40. nsects : word;
  41. time : longint;
  42. sympos : longint;
  43. syms : longint;
  44. opthdr : word;
  45. flag : word;
  46. end;
  47. tcoffsechdr=packed record
  48. name : array[0..7] of char;
  49. vsize : longint;
  50. rvaofs : longint;
  51. datalen : longint;
  52. datapos : longint;
  53. relocpos : longint;
  54. lineno1 : longint;
  55. nrelocs : word;
  56. lineno2 : word;
  57. flags : longint;
  58. end;
  59. psecfill=^tsecfill;
  60. tsecfill=record
  61. fillpos,
  62. fillsize : longint;
  63. next : psecfill;
  64. end;
  65. var
  66. f : file;
  67. coffheader : tcoffheader;
  68. firstsecpos,
  69. maxfillsize,
  70. l : longint;
  71. coffsec : tcoffsechdr;
  72. secroot,hsecroot : psecfill;
  73. zerobuf : pointer;
  74. begin
  75. { when -s is used quit, because there is no .exe }
  76. if cs_link_extern in aktglobalswitches then
  77. exit;
  78. { open file }
  79. assign(f,n);
  80. {$I-}
  81. reset(f,1);
  82. if ioresult<>0 then
  83. Message1(execinfo_f_cant_open_executable,n);
  84. { read headers }
  85. seek(f,2048);
  86. blockread(f,coffheader,sizeof(tcoffheader));
  87. { read section info }
  88. maxfillsize:=0;
  89. firstsecpos:=0;
  90. secroot:=nil;
  91. for l:=1to coffheader.nSects do
  92. begin
  93. blockread(f,coffsec,sizeof(tcoffsechdr));
  94. if coffsec.datapos>0 then
  95. begin
  96. if secroot=nil then
  97. firstsecpos:=coffsec.datapos;
  98. new(hsecroot);
  99. hsecroot^.fillpos:=coffsec.datapos+coffsec.vsize;
  100. hsecroot^.fillsize:=coffsec.datalen-coffsec.vsize;
  101. hsecroot^.next:=secroot;
  102. secroot:=hsecroot;
  103. if secroot^.fillsize>maxfillsize then
  104. maxfillsize:=secroot^.fillsize;
  105. end;
  106. end;
  107. if firstsecpos>0 then
  108. begin
  109. l:=firstsecpos-filepos(f);
  110. if l>maxfillsize then
  111. maxfillsize:=l;
  112. end
  113. else
  114. l:=0;
  115. { get zero buffer }
  116. getmem(zerobuf,maxfillsize);
  117. fillchar(zerobuf^,maxfillsize,0);
  118. { zero from sectioninfo until first section }
  119. blockwrite(f,zerobuf^,l);
  120. { zero section alignments }
  121. while assigned(secroot) do
  122. begin
  123. seek(f,secroot^.fillpos);
  124. blockwrite(f,zerobuf^,secroot^.fillsize);
  125. hsecroot:=secroot;
  126. secroot:=secroot^.next;
  127. dispose(hsecroot);
  128. end;
  129. freemem(zerobuf,maxfillsize);
  130. close(f);
  131. {$I+}
  132. end;
  133. {$endif}
  134. end.
  135. {
  136. $Log$
  137. Revision 1.1 1999-08-11 17:26:32 peter
  138. * tlinker object is now inherited for win32 and dos
  139. * postprocessexecutable is now a method of tlinker
  140. }