t_go32v1.pas 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Peter Vreman
  4. This unit implements support import,export,link routines
  5. for the (i386) go32v1 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_go32v1;
  20. {$i defines.inc}
  21. interface
  22. uses
  23. link;
  24. type
  25. tlinkergo32v1=class(tlinker)
  26. private
  27. Function WriteResponseFile(isdll:boolean) : Boolean;
  28. public
  29. constructor Create;override;
  30. procedure SetDefaultInfo;override;
  31. function MakeExecutable:boolean;override;
  32. end;
  33. implementation
  34. uses
  35. cutils,cclasses,
  36. globtype,globals,systems,verbose,script,fmodule;
  37. {****************************************************************************
  38. TLinkergo32v1
  39. ****************************************************************************}
  40. Constructor TLinkergo32v1.Create;
  41. begin
  42. Inherited Create;
  43. { allow duplicated libs (PM) }
  44. SharedLibFiles.doubles:=true;
  45. StaticLibFiles.doubles:=true;
  46. end;
  47. procedure TLinkergo32v1.SetDefaultInfo;
  48. begin
  49. with Info do
  50. begin
  51. ExeCmd[1]:='ld -oformat coff-go32 $OPT $STRIP -o $EXE @$RES';
  52. ExeCmd[2]:='aout2exe $EXE';
  53. end;
  54. end;
  55. Function TLinkergo32v1.WriteResponseFile(isdll:boolean) : Boolean;
  56. Var
  57. linkres : TLinkRes;
  58. i : longint;
  59. HPath : TStringListItem;
  60. s : string;
  61. linklibc : boolean;
  62. begin
  63. WriteResponseFile:=False;
  64. { Open link.res file }
  65. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  66. { Write path to search libraries }
  67. HPath:=TStringListItem(current_module.locallibrarysearchpath.First);
  68. while assigned(HPath) do
  69. begin
  70. LinkRes.Add('-L'+HPath.Str);
  71. HPath:=TStringListItem(HPath.Next);
  72. end;
  73. HPath:=TStringListItem(LibrarySearchPath.First);
  74. while assigned(HPath) do
  75. begin
  76. LinkRes.Add('-L'+HPath.Str);
  77. HPath:=TStringListItem(HPath.Next);
  78. end;
  79. { add objectfiles, start with prt0 always }
  80. LinkRes.AddFileName(FindObjectFile('prt0',''));
  81. while not ObjectFiles.Empty do
  82. begin
  83. s:=ObjectFiles.GetFirst;
  84. if s<>'' then
  85. LinkRes.AddFileName(s);
  86. end;
  87. { Write staticlibraries }
  88. if not StaticLibFiles.Empty then
  89. begin
  90. LinkRes.Add('-(');
  91. While not StaticLibFiles.Empty do
  92. begin
  93. S:=StaticLibFiles.GetFirst;
  94. LinkRes.AddFileName(s)
  95. end;
  96. LinkRes.Add('-)');
  97. end;
  98. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  99. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  100. linklibc:=false;
  101. While not SharedLibFiles.Empty do
  102. begin
  103. S:=SharedLibFiles.GetFirst;
  104. if s<>'c' then
  105. begin
  106. i:=Pos(target_info.sharedlibext,S);
  107. if i>0 then
  108. Delete(S,i,255);
  109. LinkRes.Add('-l'+s);
  110. end
  111. else
  112. begin
  113. LinkRes.Add('-l'+s);
  114. linklibc:=true;
  115. end;
  116. end;
  117. { be sure that libc&libgcc is the last lib }
  118. if linklibc then
  119. begin
  120. LinkRes.Add('-lc');
  121. LinkRes.Add('-lgcc');
  122. end;
  123. { Write and Close response }
  124. linkres.writetodisk;
  125. LinkRes.Free;
  126. WriteResponseFile:=True;
  127. end;
  128. function TLinkergo32v1.MakeExecutable:boolean;
  129. var
  130. binstr,
  131. cmdstr : string;
  132. success : boolean;
  133. StripStr : string[40];
  134. begin
  135. if not(cs_link_extern in aktglobalswitches) then
  136. Message1(exec_i_linking,current_module.exefilename^);
  137. { Create some replacements }
  138. StripStr:='';
  139. if (cs_link_strip in aktglobalswitches) then
  140. StripStr:='-s';
  141. { Write used files and libraries }
  142. WriteResponseFile(false);
  143. { Call linker }
  144. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  145. Replace(cmdstr,'$EXE',current_module.exefilename^);
  146. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  147. Replace(cmdstr,'$RES',outputexedir+Info.ResName);
  148. Replace(cmdstr,'$STRIP',StripStr);
  149. success:=DoExec(FindUtil(BinStr),cmdstr,true,false);
  150. { Remove ReponseFile }
  151. if (success) and not(cs_link_extern in aktglobalswitches) then
  152. RemoveFile(outputexedir+Info.ResName);
  153. MakeExecutable:=success; { otherwise a recursive call to link method }
  154. end;
  155. {*****************************************************************************
  156. Initialize
  157. *****************************************************************************}
  158. const
  159. target_i386_go32v1_info : ttargetinfo =
  160. (
  161. target : target_i386_GO32V1;
  162. name : 'GO32 V1 DOS extender';
  163. shortname : 'Go32v1';
  164. flags : [];
  165. cpu : i386;
  166. unit_env : 'GO32V1UNITS';
  167. extradefines : '';
  168. sharedlibext : '.dll';
  169. staticlibext : '.a';
  170. sourceext : '.pp';
  171. pasext : '.pas';
  172. exeext : ''; { No .exe, the linker only output a.out ! }
  173. defext : '.def';
  174. scriptext : '.bat';
  175. smartext : '.sl';
  176. unitext : '.pp1';
  177. unitlibext : '.ppl';
  178. asmext : '.s1';
  179. objext : '.o1';
  180. resext : '.res';
  181. resobjext : '.o1r';
  182. staticlibprefix : '';
  183. sharedlibprefix : '';
  184. Cprefix : '_';
  185. newline : #13#10;
  186. assem : as_i386_as;
  187. assemextern : as_i386_as;
  188. link : ld_i386_go32v1;
  189. linkextern : ld_i386_go32v1;
  190. ar : ar_gnu_ar;
  191. res : res_none;
  192. endian : endian_little;
  193. alignment :
  194. (
  195. procalign : 4;
  196. loopalign : 0;
  197. jumpalign : 0;
  198. constalignmin : 0;
  199. constalignmax : 1;
  200. varalignmin : 0;
  201. varalignmax : 1;
  202. localalignmin : 0;
  203. localalignmax : 1;
  204. paraalign : 2;
  205. recordalignmin : 0;
  206. recordalignmax : 2;
  207. maxCrecordalign : 4
  208. );
  209. size_of_pointer : 4;
  210. size_of_longint : 4;
  211. heapsize : 2048*1024;
  212. maxheapsize : 32768*1024;
  213. stacksize : 16384;
  214. DllScanSupported:false;
  215. use_bound_instruction : false;
  216. use_function_relative_addresses : true
  217. );
  218. initialization
  219. RegisterLinker(ld_i386_go32v1,TLinkerGo32v1);
  220. RegisterTarget(target_i386_go32v1_info);
  221. end.
  222. {
  223. $Log$
  224. Revision 1.7 2001-07-01 20:16:20 peter
  225. * alignmentinfo record added
  226. * -Oa argument supports more alignment settings that can be specified
  227. per type: PROC,LOOP,VARMIN,VARMAX,CONSTMIN,CONSTMAX,RECORDMIN
  228. RECORDMAX,LOCALMIN,LOCALMAX. It is possible to set the mimimum
  229. required alignment and the maximum usefull alignment. The final
  230. alignment will be choosen per variable size dependent on these
  231. settings
  232. Revision 1.6 2001/06/28 19:46:25 peter
  233. * added override and virtual for constructors
  234. Revision 1.5 2001/06/03 15:15:31 peter
  235. * dllprt0 stub for linux shared libs
  236. * pass -init and -fini for linux shared libs
  237. * libprefix splitted into staticlibprefix and sharedlibprefix
  238. Revision 1.4 2001/06/02 19:22:44 peter
  239. * extradefines field added
  240. Revision 1.3 2001/04/18 22:02:04 peter
  241. * registration of targets and assemblers
  242. Revision 1.2 2001/04/13 01:22:21 peter
  243. * symtable change to classes
  244. * range check generation and errors fixed, make cycle DEBUG=1 works
  245. * memory leaks fixed
  246. Revision 1.1 2001/02/26 19:43:11 peter
  247. * moved target units to subdir
  248. Revision 1.5 2000/12/25 00:07:30 peter
  249. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  250. tlinkedlist objects)
  251. Revision 1.4 2000/09/24 15:06:30 peter
  252. * use defines.inc
  253. Revision 1.3 2000/08/27 16:11:54 peter
  254. * moved some util functions from globals,cobjects to cutils
  255. * splitted files into finput,fmodule
  256. Revision 1.2 2000/07/13 11:32:50 michael
  257. + removed logs
  258. }