t_go32v1.pas 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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 : 'DPMI';
  168. sourceext : '.pp';
  169. pasext : '.pas';
  170. exeext : ''; { No .exe, the linker only output a.out ! }
  171. defext : '.def';
  172. scriptext : '.bat';
  173. smartext : '.sl';
  174. unitext : '.pp1';
  175. unitlibext : '.ppl';
  176. asmext : '.s1';
  177. objext : '.o1';
  178. resext : '.res';
  179. resobjext : '.o1r';
  180. sharedlibext : '.dll';
  181. staticlibext : '.a';
  182. staticlibprefix : '';
  183. sharedlibprefix : '';
  184. sharedClibext : '.dll';
  185. staticClibext : '.a';
  186. staticClibprefix : '';
  187. sharedClibprefix : '';
  188. Cprefix : '_';
  189. newline : #13#10;
  190. dirsep : '\';
  191. files_case_relevent : false;
  192. assem : as_i386_as;
  193. assemextern : as_i386_as;
  194. link : ld_i386_go32v1;
  195. linkextern : ld_i386_go32v1;
  196. ar : ar_gnu_ar;
  197. res : res_none;
  198. script : script_dos;
  199. endian : endian_little;
  200. alignment :
  201. (
  202. procalign : 4;
  203. loopalign : 0;
  204. jumpalign : 0;
  205. constalignmin : 0;
  206. constalignmax : 4;
  207. varalignmin : 0;
  208. varalignmax : 4;
  209. localalignmin : 0;
  210. localalignmax : 4;
  211. paraalign : 2;
  212. recordalignmin : 0;
  213. recordalignmax : 2;
  214. maxCrecordalign : 4
  215. );
  216. size_of_pointer : 4;
  217. size_of_longint : 4;
  218. heapsize : 2048*1024;
  219. maxheapsize : 32768*1024;
  220. stacksize : 16384;
  221. DllScanSupported:false;
  222. use_bound_instruction : false;
  223. use_function_relative_addresses : true
  224. );
  225. initialization
  226. RegisterLinker(ld_i386_go32v1,TLinkerGo32v1);
  227. RegisterTarget(target_i386_go32v1_info);
  228. end.
  229. {
  230. $Log$
  231. Revision 1.12 2002-01-29 21:27:34 peter
  232. * default alignment changed to 4 bytes for locals and static const,var
  233. Revision 1.11 2001/09/18 11:32:00 michael
  234. * Fixes win32 linking problems with import libraries
  235. * LINKLIB Libraries are now looked for using C file extensions
  236. * get_exepath fix
  237. Revision 1.10 2001/09/17 21:29:16 peter
  238. * merged netbsd, fpu-overflow from fixes branch
  239. Revision 1.9 2001/08/19 11:22:24 peter
  240. * palmos support from v10 merged
  241. Revision 1.8 2001/08/07 18:47:15 peter
  242. * merged netbsd start
  243. * profile for win32
  244. Revision 1.7 2001/07/01 20:16:20 peter
  245. * alignmentinfo record added
  246. * -Oa argument supports more alignment settings that can be specified
  247. per type: PROC,LOOP,VARMIN,VARMAX,CONSTMIN,CONSTMAX,RECORDMIN
  248. RECORDMAX,LOCALMIN,LOCALMAX. It is possible to set the mimimum
  249. required alignment and the maximum usefull alignment. The final
  250. alignment will be choosen per variable size dependent on these
  251. settings
  252. Revision 1.6 2001/06/28 19:46:25 peter
  253. * added override and virtual for constructors
  254. Revision 1.5 2001/06/03 15:15:31 peter
  255. * dllprt0 stub for linux shared libs
  256. * pass -init and -fini for linux shared libs
  257. * libprefix splitted into staticlibprefix and sharedlibprefix
  258. Revision 1.4 2001/06/02 19:22:44 peter
  259. * extradefines field added
  260. Revision 1.3 2001/04/18 22:02:04 peter
  261. * registration of targets and assemblers
  262. Revision 1.2 2001/04/13 01:22:21 peter
  263. * symtable change to classes
  264. * range check generation and errors fixed, make cycle DEBUG=1 works
  265. * memory leaks fixed
  266. Revision 1.1 2001/02/26 19:43:11 peter
  267. * moved target units to subdir
  268. Revision 1.5 2000/12/25 00:07:30 peter
  269. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  270. tlinkedlist objects)
  271. Revision 1.4 2000/09/24 15:06:30 peter
  272. * use defines.inc
  273. Revision 1.3 2000/08/27 16:11:54 peter
  274. * moved some util functions from globals,cobjects to cutils
  275. * splitted files into finput,fmodule
  276. Revision 1.2 2000/07/13 11:32:50 michael
  277. + removed logs
  278. }