t_bsd.pas 21 KB

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