t_bsd.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. {
  2. Copyright (c) 1998-2002 by Peter Vreman (original Linux)
  3. (c) 2000 by Marco van de Voort (FreeBSD mods)
  4. This unit implements support import,export,link routines
  5. for the (i386)FreeBSD 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_bsd;
  20. {$i fpcdefs.inc}
  21. interface
  22. implementation
  23. uses
  24. cutils,cclasses,
  25. {$ifdef USE_SYSUTILS}
  26. sysutils,
  27. {$else USE_SYSUTILS}
  28. dos,
  29. {$endif USE_SYSUTILS}
  30. verbose,systems,globtype,globals,
  31. symconst,script,
  32. fmodule,aasmbase,aasmtai,aasmcpu,cpubase,symsym,symdef,
  33. import,export,link,i_bsd,
  34. cgutils,cgbase,cgobj,cpuinfo;
  35. type
  36. tdarwinimported_item = class(timported_item)
  37. procdef : tprocdef;
  38. end;
  39. timportlibdarwin=class(timportlib)
  40. procedure preparelib(const s:string);override;
  41. procedure importprocedure(aprocdef:tprocdef;const module:string;index:longint;const name:string);override;
  42. procedure importvariable(vs:tglobalvarsym;const name,module:string);override;
  43. procedure generatelib;override;
  44. procedure generatesmartlib;override;
  45. end;
  46. timportlibbsd=class(timportlib)
  47. procedure preparelib(const s:string);override;
  48. procedure importprocedure(aprocdef:tprocdef;const module:string;index:longint;const name:string);override;
  49. procedure importvariable(vs:tglobalvarsym;const name,module:string);override;
  50. procedure generatelib;override;
  51. end;
  52. texportlibbsd=class(texportlib)
  53. procedure preparelib(const s : string);override;
  54. procedure exportprocedure(hp : texported_item);override;
  55. procedure exportvar(hp : texported_item);override;
  56. procedure generatelib;override;
  57. end;
  58. tlinkerbsd=class(texternallinker)
  59. private
  60. LdSupportsNoResponseFile : boolean;
  61. LibrarySuffix : Char;
  62. Function WriteResponseFile(isdll:boolean) : Boolean;
  63. public
  64. constructor Create;override;
  65. procedure SetDefaultInfo;override;
  66. function MakeExecutable:boolean;override;
  67. function MakeSharedLibrary:boolean;override;
  68. end;
  69. {*****************************************************************************
  70. TIMPORTLIBDARWIN
  71. *****************************************************************************}
  72. procedure timportlibdarwin.preparelib(const s : string);
  73. begin
  74. if asmlist[al_imports]=nil then
  75. asmlist[al_imports]:=TAAsmoutput.create;
  76. end;
  77. procedure timportlibdarwin.importprocedure(aprocdef:tprocdef;const module : string;index : longint;const name : string);
  78. begin
  79. { insert sharedlibrary }
  80. { current_module.linkothersharedlibs.add(SplitName(module),link_allways); }
  81. end;
  82. procedure timportlibdarwin.importvariable(vs:tglobalvarsym;const name,module:string);
  83. begin
  84. { insert sharedlibrary }
  85. { current_module.linkothersharedlibs.add(SplitName(module),link_allways); }
  86. { the rest is handled in the nppcld.pas tppcloadnode }
  87. vs.set_mangledname(name);
  88. end;
  89. procedure timportlibdarwin.generatesmartlib;
  90. begin
  91. generatelib;
  92. end;
  93. procedure timportlibdarwin.generatelib;
  94. begin
  95. end;
  96. {*****************************************************************************
  97. TIMPORTLIBBSD
  98. *****************************************************************************}
  99. procedure timportlibbsd.preparelib(const s : string);
  100. begin
  101. end;
  102. procedure timportlibbsd.importprocedure(aprocdef:tprocdef;const module:string;index:longint;const name:string);
  103. begin
  104. { insert sharedlibrary }
  105. current_module.linkothersharedlibs.add(SplitName(module),link_allways);
  106. end;
  107. procedure timportlibbsd.importvariable(vs:tglobalvarsym;const name,module:string);
  108. begin
  109. { insert sharedlibrary }
  110. current_module.linkothersharedlibs.add(SplitName(module),link_allways);
  111. { reset the mangledname and turn off the dll_var option }
  112. vs.set_mangledname(name);
  113. exclude(vs.varoptions,vo_is_dll_var);
  114. end;
  115. procedure timportlibbsd.generatelib;
  116. begin
  117. end;
  118. {*****************************************************************************
  119. TEXPORTLIBBSD
  120. *****************************************************************************}
  121. procedure texportlibbsd.preparelib(const s:string);
  122. begin
  123. end;
  124. procedure texportlibbsd.exportprocedure(hp : texported_item);
  125. var
  126. hp2 : texported_item;
  127. begin
  128. { first test the index value }
  129. if (hp.options and eo_index)<>0 then
  130. begin
  131. Message1(parser_e_no_export_with_index_for_target,'*bsd/darwin');
  132. exit;
  133. end;
  134. { now place in correct order }
  135. hp2:=texported_item(current_module._exports.first);
  136. while assigned(hp2) and
  137. (hp.name^>hp2.name^) do
  138. hp2:=texported_item(hp2.next);
  139. { insert hp there !! }
  140. if assigned(hp2) and (hp2.name^=hp.name^) then
  141. begin
  142. { this is not allowed !! }
  143. Message1(parser_e_export_name_double,hp.name^);
  144. exit;
  145. end;
  146. if hp2=texported_item(current_module._exports.first) then
  147. current_module._exports.concat(hp)
  148. else if assigned(hp2) then
  149. begin
  150. hp.next:=hp2;
  151. hp.previous:=hp2.previous;
  152. if assigned(hp2.previous) then
  153. hp2.previous.next:=hp;
  154. hp2.previous:=hp;
  155. end
  156. else
  157. current_module._exports.concat(hp);
  158. end;
  159. procedure texportlibbsd.exportvar(hp : texported_item);
  160. begin
  161. hp.is_var:=true;
  162. exportprocedure(hp);
  163. end;
  164. procedure texportlibbsd.generatelib;
  165. var
  166. hp2 : texported_item;
  167. begin
  168. hp2:=texported_item(current_module._exports.first);
  169. while assigned(hp2) do
  170. begin
  171. if (not hp2.is_var) and
  172. (hp2.sym.typ=procsym) then
  173. begin
  174. { the manglednames can already be the same when the procedure
  175. is declared with cdecl }
  176. if tprocsym(hp2.sym).first_procdef.mangledname<>hp2.name^ then
  177. begin
  178. {$ifdef i386}
  179. { place jump in al_procedures }
  180. asmlist[al_procedures].concat(Tai_align.Create_op(4,$90));
  181. asmlist[al_procedures].concat(Tai_symbol.Createname_global(hp2.name^,AT_FUNCTION,0));
  182. asmlist[al_procedures].concat(Taicpu.Op_sym(A_JMP,S_NO,objectlibrary.newasmsymbol(tprocsym(hp2.sym).first_procdef.mangledname,AB_EXTERNAL,AT_FUNCTION)));
  183. asmlist[al_procedures].concat(Tai_symbol_end.Createname(hp2.name^));
  184. {$endif i386}
  185. {$ifdef powerpc}
  186. asmlist[al_procedures].concat(Tai_align.create(16));
  187. asmlist[al_procedures].concat(Tai_symbol.Createname_global(hp2.name^,AT_FUNCTION,0));
  188. asmlist[al_procedures].concat(Taicpu.Op_sym(A_B,objectlibrary.newasmsymbol(tprocsym(hp2.sym).first_procdef.mangledname,AB_EXTERNAL,AT_FUNCTION)));
  189. asmlist[al_procedures].concat(Tai_symbol_end.Createname(hp2.name^));
  190. {$endif powerpc}
  191. end;
  192. end
  193. else
  194. Message1(parser_e_no_export_of_variables_for_target,'*bsd/darwin');
  195. hp2:=texported_item(hp2.next);
  196. end;
  197. end;
  198. {*****************************************************************************
  199. TLINKERLINUX
  200. *****************************************************************************}
  201. Constructor TLinkerBSD.Create;
  202. begin
  203. Inherited Create;
  204. if not Dontlinkstdlibpath Then
  205. if (target_info.system <> system_powerpc_darwin) then
  206. LibrarySearchPath.AddPath('/lib;/usr/lib;/usr/X11R6/lib',true)
  207. else
  208. { Mac OS X doesn't have a /lib }
  209. LibrarySearchPath.AddPath('/usr/lib',true)
  210. end;
  211. procedure TLinkerBSD.SetDefaultInfo;
  212. {
  213. This will also detect which libc version will be used
  214. }
  215. begin
  216. LibrarySuffix:=' ';
  217. LdSupportsNoResponseFile := (target_info.system in [system_m68k_netbsd,system_powerpc_darwin]);
  218. with Info do
  219. begin
  220. if LdSupportsNoResponseFile then
  221. begin
  222. if (target_info.system <> system_powerpc_darwin) then
  223. begin
  224. ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE `cat $RES`';
  225. DllCmd[1]:='ld $OPT -shared -L. -o $EXE `cat $RES`'
  226. end
  227. else
  228. begin
  229. ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE `cat $RES`';
  230. DllCmd[1]:='libtool $OPT -dynamic -init PASCALMAIN -multiply_defined suppress -L. -o $EXE `cat $RES`'
  231. end
  232. end
  233. else
  234. begin
  235. ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE $RES';
  236. DllCmd[1]:='ld $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES';
  237. end;
  238. if (target_info.system <> system_powerpc_darwin) then
  239. DllCmd[2]:='strip --strip-unneeded $EXE'
  240. else
  241. DllCmd[2]:='strip -x $EXE';
  242. { first try glibc2 }
  243. {$ifdef GLIBC2} {Keep linux code in place. FBSD might go to a different
  244. glibc too once}
  245. DynamicLinker:='/lib/ld-linux.so.2';
  246. if FileExists(DynamicLinker) then
  247. begin
  248. Glibc2:=true;
  249. { Check for 2.0 files, else use the glibc 2.1 stub }
  250. if FileExists('/lib/ld-2.0.*') then
  251. Glibc21:=false
  252. else
  253. Glibc21:=true;
  254. end
  255. else
  256. DynamicLinker:='/lib/ld-linux.so.1';
  257. {$else}
  258. DynamicLinker:='';
  259. {$endif}
  260. end;
  261. end;
  262. Function TLinkerBSD.WriteResponseFile(isdll:boolean) : Boolean;
  263. Var
  264. linkres : TLinkRes;
  265. i : longint;
  266. cprtobj,
  267. gprtobj,
  268. prtobj : string[80];
  269. HPath : TStringListItem;
  270. s,s1,s2 : string;
  271. linkpthread,
  272. linkdynamic,
  273. linklibc : boolean;
  274. Fl1,Fl2 : Boolean;
  275. begin
  276. WriteResponseFile:=False;
  277. { set special options for some targets }
  278. if target_info.system <> system_powerpc_darwin then
  279. begin
  280. linkdynamic:=not(SharedLibFiles.empty);
  281. linklibc:=(SharedLibFiles.Find('c')<>nil);
  282. linkpthread:=(SharedLibFiles.Find('pthread')<>nil);
  283. if (target_info.system =system_i386_freebsd) and linkpthread Then
  284. Begin
  285. if not (cs_link_pthread in aktglobalswitches) Then
  286. begin
  287. {delete pthreads from list, in this case it is in libc_r}
  288. SharedLibFiles.Remove(SharedLibFiles.Find('pthread').str);
  289. LibrarySuffix:='r';
  290. end;
  291. End;
  292. prtobj:='prt0';
  293. cprtobj:='cprt0';
  294. gprtobj:='gprt0';
  295. if cs_profile in aktmoduleswitches then
  296. begin
  297. prtobj:=gprtobj;
  298. AddSharedLibrary('c');
  299. LibrarySuffix:='p';
  300. linklibc:=true;
  301. end
  302. else
  303. begin
  304. if linklibc then
  305. prtobj:=cprtobj;
  306. end;
  307. end
  308. else
  309. begin
  310. { for darwin: always link dynamically against libc }
  311. linklibc := true;
  312. if not(isdll) then
  313. if not(cs_profile in aktmoduleswitches) then
  314. begin
  315. if librarysearchpath.FindFile('crt1.o',s) then
  316. prtobj:=s
  317. else
  318. prtobj:='/usr/lib/crt1.o';
  319. end
  320. else
  321. prtobj:='/usr/lib/gcrt1.o'
  322. else
  323. prtobj:='';
  324. end;
  325. { Open link.res file }
  326. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  327. { Write path to search libraries }
  328. HPath:=TStringListItem(current_module.locallibrarysearchpath.First);
  329. while assigned(HPath) do
  330. begin
  331. if LdSupportsNoResponseFile then
  332. LinkRes.Add(maybequoted('-L'+HPath.Str))
  333. else
  334. LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
  335. HPath:=TStringListItem(HPath.Next);
  336. end;
  337. HPath:=TStringListItem(LibrarySearchPath.First);
  338. while assigned(HPath) do
  339. begin
  340. if LdSupportsNoResponseFile then
  341. LinkRes.Add(maybequoted('-L'+HPath.Str))
  342. else
  343. LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
  344. HPath:=TStringListItem(HPath.Next);
  345. end;
  346. if not LdSupportsNoResponseFile then
  347. LinkRes.Add('INPUT(');
  348. { add objectfiles, start with prt0 always }
  349. if prtobj<>'' then
  350. LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
  351. { try to add crti and crtbegin if linking to C }
  352. if linklibc and
  353. (target_info.system <> system_powerpc_darwin) then
  354. begin
  355. if librarysearchpath.FindFile('crtbegin.o',s) then
  356. LinkRes.AddFileName(s);
  357. if librarysearchpath.FindFile('crti.o',s) then
  358. LinkRes.AddFileName(s);
  359. end;
  360. { main objectfiles }
  361. while not ObjectFiles.Empty do
  362. begin
  363. s:=ObjectFiles.GetFirst;
  364. if s<>'' then
  365. LinkRes.AddFileName(maybequoted(s));
  366. end;
  367. if not LdSupportsNoResponseFile then
  368. LinkRes.Add(')');
  369. { Write staticlibraries }
  370. if not StaticLibFiles.Empty then
  371. begin
  372. if not LdSupportsNoResponseFile then
  373. LinkRes.Add('GROUP(');
  374. While not StaticLibFiles.Empty do
  375. begin
  376. S:=StaticLibFiles.GetFirst;
  377. LinkRes.AddFileName(maybequoted(s))
  378. end;
  379. if not LdSupportsNoResponseFile then
  380. LinkRes.Add(')');
  381. end;
  382. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  383. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  384. if not SharedLibFiles.Empty then
  385. begin
  386. if not LdSupportsNoResponseFile then
  387. LinkRes.Add('INPUT(');
  388. While not SharedLibFiles.Empty do
  389. begin
  390. S:=SharedLibFiles.GetFirst;
  391. if s<>'c' then
  392. begin
  393. i:=Pos(target_info.sharedlibext,S);
  394. if i>0 then
  395. Delete(S,i,255);
  396. LinkRes.Add('-l'+s);
  397. end
  398. else
  399. begin
  400. linklibc:=true;
  401. linkdynamic:=false; { libc will include the ld-linux for us }
  402. end;
  403. end;
  404. { be sure that libc is the last lib }
  405. if linklibc then
  406. Begin
  407. If LibrarySuffix=' ' Then
  408. LinkRes.Add('-lc')
  409. else
  410. LinkRes.Add('-lc_'+LibrarySuffix);
  411. If LibrarySuffix='r' Then
  412. LinkRes.Add('-lc');
  413. end;
  414. { when we have -static for the linker the we also need libgcc }
  415. if (cs_link_staticflag in aktglobalswitches) then
  416. LinkRes.Add('-lgcc');
  417. if linkdynamic and (Info.DynamicLinker<>'') then
  418. LinkRes.AddFileName(Info.DynamicLinker);
  419. if not LdSupportsNoResponseFile then
  420. LinkRes.Add(')');
  421. end;
  422. { objects which must be at the end }
  423. if linklibc and
  424. (target_info.system <> system_powerpc_darwin) then
  425. begin
  426. Fl1:=librarysearchpath.FindFile('crtend.o',s1);
  427. Fl2:=librarysearchpath.FindFile('crtn.o',s2);
  428. if Fl1 or Fl2 then
  429. begin
  430. LinkRes.Add('INPUT(');
  431. If Fl1 Then
  432. LinkRes.AddFileName(s1);
  433. If Fl2 Then
  434. LinkRes.AddFileName(s2);
  435. LinkRes.Add(')');
  436. end;
  437. end;
  438. { ignore the fact that our relocations are in non-writable sections, }
  439. { will be fixed once we have pic support }
  440. if isdll and
  441. (target_info.system = system_powerpc_darwin) then
  442. LinkRes.Add('-read_only_relocs suppress');
  443. { Write and Close response }
  444. linkres.writetodisk;
  445. linkres.Free;
  446. WriteResponseFile:=True;
  447. end;
  448. function TLinkerBSD.MakeExecutable:boolean;
  449. var
  450. binstr : String;
  451. cmdstr : TCmdStr;
  452. success : boolean;
  453. DynLinkStr : string[60];
  454. GCSectionsStr,
  455. StaticStr,
  456. StripStr : string[40];
  457. begin
  458. if not(cs_link_extern in aktglobalswitches) then
  459. Message1(exec_i_linking,current_module.exefilename^);
  460. { Create some replacements }
  461. StaticStr:='';
  462. StripStr:='';
  463. DynLinkStr:='';
  464. GCSectionsStr:='';
  465. if (cs_link_staticflag in aktglobalswitches) then
  466. begin
  467. if (target_info.system=system_m68k_netbsd) and
  468. ((cs_link_on_target in aktglobalswitches) or
  469. (target_info.system=source_info.system)) then
  470. StaticStr:='-Bstatic'
  471. else
  472. StaticStr:='-static';
  473. end;
  474. if (cs_link_strip in aktglobalswitches) then
  475. if (target_info.system <> system_powerpc_darwin) then
  476. StripStr:='-s'
  477. else
  478. StripStr:='-x';
  479. if (cs_link_smart in aktglobalswitches) and
  480. (tf_smartlink_sections in target_info.flags) then
  481. GCSectionsStr:='--gc-sections';
  482. If (cs_profile in aktmoduleswitches) or
  483. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  484. DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
  485. if CShared Then
  486. begin
  487. if (target_info.system <> system_powerpc_darwin) then
  488. DynLinKStr:=DynLinkStr+' --shared'
  489. else
  490. DynLinKStr:=DynLinkStr+' -dynamic'; // one dash!
  491. end;
  492. { Write used files and libraries }
  493. WriteResponseFile(false);
  494. { Call linker }
  495. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  496. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename^));
  497. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  498. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  499. Replace(cmdstr,'$STATIC',StaticStr);
  500. Replace(cmdstr,'$STRIP',StripStr);
  501. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  502. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  503. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,LdSupportsNoResponseFile);
  504. { Remove ReponseFile }
  505. if (success) and not(cs_link_extern in aktglobalswitches) then
  506. RemoveFile(outputexedir+Info.ResName);
  507. MakeExecutable:=success; { otherwise a recursive call to link method }
  508. end;
  509. Function TLinkerBSD.MakeSharedLibrary:boolean;
  510. var
  511. InitStr,
  512. FiniStr,
  513. SoNameStr : string[80];
  514. binstr : String;
  515. cmdstr : TCmdStr;
  516. success : boolean;
  517. begin
  518. MakeSharedLibrary:=false;
  519. if not(cs_link_extern in aktglobalswitches) then
  520. Message1(exec_i_linking,current_module.sharedlibfilename^);
  521. { Write used files and libraries }
  522. WriteResponseFile(true);
  523. InitStr:='-init FPC_LIB_START';
  524. FiniStr:='-fini FPC_LIB_EXIT';
  525. SoNameStr:='-soname '+SplitFileName(current_module.sharedlibfilename^);
  526. { Call linker }
  527. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  528. {$ifndef darwin}
  529. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
  530. {$else darwin}
  531. {$ifdef USE_SYSUTILS}
  532. Replace(cmdstr,'$EXE',maybequoted(ExpandFileName(current_module.sharedlibfilename^)));
  533. {$else USE_SYSUTILS}
  534. Replace(cmdstr,'$EXE',maybequoted(FExpand(current_module.sharedlibfilename^)));
  535. {$endif USE_SYSUTILS}
  536. {$endif darwin}
  537. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  538. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  539. Replace(cmdstr,'$INIT',InitStr);
  540. Replace(cmdstr,'$FINI',FiniStr);
  541. Replace(cmdstr,'$SONAME',SoNameStr);
  542. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,LdSupportsNoResponseFile);
  543. { Strip the library ? }
  544. if success and (cs_link_strip in aktglobalswitches) then
  545. begin
  546. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  547. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
  548. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  549. end;
  550. { Remove ReponseFile }
  551. if (success) and not(cs_link_extern in aktglobalswitches) then
  552. RemoveFile(outputexedir+Info.ResName);
  553. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  554. end;
  555. {*****************************************************************************
  556. Initialize
  557. *****************************************************************************}
  558. initialization
  559. {$ifdef x86_64}
  560. RegisterExternalLinker(system_x86_64_FreeBSD_info,TLinkerBSD);
  561. RegisterImport(system_x86_64_freebsd,timportlibbsd);
  562. RegisterExport(system_x86_64_freebsd,texportlibbsd);
  563. RegisterTarget(system_x86_64_freebsd_info);
  564. {$endif}
  565. {$ifdef i386}
  566. RegisterExternalLinker(system_i386_FreeBSD_info,TLinkerBSD);
  567. RegisterExternalLinker(system_i386_NetBSD_info,TLinkerBSD);
  568. RegisterExternalLinker(system_i386_OpenBSD_info,TLinkerBSD);
  569. RegisterImport(system_i386_freebsd,timportlibbsd);
  570. RegisterExport(system_i386_freebsd,texportlibbsd);
  571. RegisterTarget(system_i386_freebsd_info);
  572. RegisterImport(system_i386_netbsd,timportlibbsd);
  573. RegisterExport(system_i386_netbsd,texportlibbsd);
  574. RegisterTarget(system_i386_netbsd_info);
  575. RegisterImport(system_i386_openbsd,timportlibbsd);
  576. RegisterExport(system_i386_openbsd,texportlibbsd);
  577. RegisterTarget(system_i386_openbsd_info);
  578. {$endif i386}
  579. {$ifdef m68k}
  580. // RegisterExternalLinker(system_m68k_FreeBSD_info,TLinkerBSD);
  581. RegisterExternalLinker(system_m68k_NetBSD_info,TLinkerBSD);
  582. RegisterImport(system_m68k_netbsd,timportlibbsd);
  583. RegisterExport(system_m68k_netbsd,texportlibbsd);
  584. RegisterTarget(system_m68k_netbsd_info);
  585. {$endif m68k}
  586. {$ifdef powerpc}
  587. // RegisterExternalLinker(system_m68k_FreeBSD_info,TLinkerBSD);
  588. RegisterExternalLinker(system_powerpc_darwin_info,TLinkerBSD);
  589. RegisterImport(system_powerpc_darwin,timportlibdarwin);
  590. RegisterExport(system_powerpc_darwin,texportlibbsd);
  591. RegisterTarget(system_powerpc_darwin_info);
  592. RegisterExternalLinker(system_powerpc_netbsd_info,TLinkerBSD);
  593. RegisterImport(system_powerpc_netbsd,timportlibbsd);
  594. RegisterExport(system_powerpc_netbsd,texportlibbsd);
  595. RegisterTarget(system_powerpc_netbsd_info);
  596. {$endif powerpc}
  597. end.