t_bsd.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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; // straight t_linux copy for now.
  165. var
  166. hp2 : texported_item;
  167. sym : tasmsymbol;
  168. r : treference;
  169. begin
  170. new_section(asmlist[al_procedures],sec_code,'',0);
  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. { place jump in al_procedures }
  182. asmlist[al_procedures].concat(tai_align.create(target_info.alignment.procalign));
  183. asmlist[al_procedures].concat(Tai_symbol.Createname_global(hp2.name^,AT_FUNCTION,0));
  184. if (cs_create_pic in aktmoduleswitches) and
  185. { other targets need to be checked how it works }
  186. (target_info.system in [system_i386_freebsd]) then
  187. begin
  188. {$ifdef x86}
  189. sym:=objectlibrary.newasmsymbol(tprocsym(hp2.sym).first_procdef.mangledname,AB_EXTERNAL,AT_FUNCTION);
  190. reference_reset_symbol(r,sym,0);
  191. if cs_create_pic in aktmoduleswitches then
  192. r.refaddr:=addr_pic
  193. else
  194. r.refaddr:=addr_full;
  195. asmlist[al_procedures].concat(taicpu.op_ref(A_JMP,S_NO,r));
  196. {$endif x86}
  197. end
  198. else
  199. cg.a_jmp_name(asmlist[al_procedures],tprocsym(hp2.sym).first_procdef.mangledname);
  200. asmlist[al_procedures].concat(Tai_symbol_end.Createname(hp2.name^));
  201. end;
  202. end
  203. else
  204. Message1(parser_e_no_export_of_variables_for_target,'*bsd/darwin');
  205. hp2:=texported_item(hp2.next);
  206. end;
  207. end;
  208. {*****************************************************************************
  209. TLINKERBSD
  210. *****************************************************************************}
  211. Constructor TLinkerBSD.Create;
  212. begin
  213. Inherited Create;
  214. if not Dontlinkstdlibpath Then
  215. if (target_info.system <> system_powerpc_darwin) then
  216. LibrarySearchPath.AddPath('/lib;/usr/lib;/usr/X11R6/lib',true)
  217. else
  218. { Mac OS X doesn't have a /lib }
  219. LibrarySearchPath.AddPath('/usr/lib',true)
  220. end;
  221. procedure TLinkerBSD.SetDefaultInfo;
  222. {
  223. This will also detect which libc version will be used
  224. }
  225. begin
  226. LibrarySuffix:=' ';
  227. LdSupportsNoResponseFile := (target_info.system in [system_m68k_netbsd,system_powerpc_darwin]);
  228. with Info do
  229. begin
  230. if LdSupportsNoResponseFile then
  231. begin
  232. if (target_info.system <> system_powerpc_darwin) then
  233. begin
  234. ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE `cat $RES`';
  235. DllCmd[1]:='ld $OPT -shared -L. -o $EXE `cat $RES`'
  236. end
  237. else
  238. begin
  239. ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE `cat $RES`';
  240. DllCmd[1]:='libtool $OPT -dynamic -multiply_defined suppress -L. -o $EXE `cat $RES`'
  241. end
  242. end
  243. else
  244. begin
  245. ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE $RES';
  246. DllCmd[1]:='ld $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES';
  247. end;
  248. if (target_info.system <> system_powerpc_darwin) then
  249. DllCmd[2]:='strip --strip-unneeded $EXE'
  250. else
  251. DllCmd[2]:='strip -x $EXE';
  252. { first try glibc2 }
  253. {$ifdef GLIBC2} {Keep linux code in place. FBSD might go to a different
  254. glibc too once}
  255. DynamicLinker:='/lib/ld-linux.so.2';
  256. if FileExists(DynamicLinker) then
  257. begin
  258. Glibc2:=true;
  259. { Check for 2.0 files, else use the glibc 2.1 stub }
  260. if FileExists('/lib/ld-2.0.*') then
  261. Glibc21:=false
  262. else
  263. Glibc21:=true;
  264. end
  265. else
  266. DynamicLinker:='/lib/ld-linux.so.1';
  267. {$else}
  268. DynamicLinker:='';
  269. {$endif}
  270. end;
  271. end;
  272. Function TLinkerBSD.WriteResponseFile(isdll:boolean) : Boolean;
  273. Var
  274. linkres : TLinkRes;
  275. i : longint;
  276. cprtobj,
  277. gprtobj,
  278. prtobj : string[80];
  279. HPath : TStringListItem;
  280. s,s1,s2 : string;
  281. linkpthread,
  282. linkdynamic,
  283. linklibc : boolean;
  284. Fl1,Fl2 : Boolean;
  285. begin
  286. WriteResponseFile:=False;
  287. { set special options for some targets }
  288. if target_info.system <> system_powerpc_darwin then
  289. begin
  290. linkdynamic:=not(SharedLibFiles.empty);
  291. linklibc:=(SharedLibFiles.Find('c')<>nil);
  292. linkpthread:=(SharedLibFiles.Find('pthread')<>nil);
  293. if (target_info.system =system_i386_freebsd) and linkpthread Then
  294. Begin
  295. if not (cs_link_pthread in aktglobalswitches) Then
  296. begin
  297. {delete pthreads from list, in this case it is in libc_r}
  298. SharedLibFiles.Remove(SharedLibFiles.Find('pthread').str);
  299. LibrarySuffix:='r';
  300. end;
  301. End;
  302. prtobj:='prt0';
  303. cprtobj:='cprt0';
  304. gprtobj:='gprt0';
  305. if cs_profile in aktmoduleswitches then
  306. begin
  307. prtobj:=gprtobj;
  308. AddSharedLibrary('c');
  309. LibrarySuffix:='p';
  310. linklibc:=true;
  311. end
  312. else
  313. begin
  314. if linklibc then
  315. prtobj:=cprtobj;
  316. end;
  317. end
  318. else
  319. begin
  320. { for darwin: always link dynamically against libc }
  321. linklibc := true;
  322. if not(isdll) then
  323. if not(cs_profile in aktmoduleswitches) then
  324. begin
  325. if librarysearchpath.FindFile('crt1.o',s) then
  326. prtobj:=s
  327. else
  328. prtobj:='/usr/lib/crt1.o';
  329. end
  330. else
  331. prtobj:='/usr/lib/gcrt1.o'
  332. else
  333. prtobj:='';
  334. end;
  335. { Open link.res file }
  336. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  337. { Write path to search libraries }
  338. HPath:=TStringListItem(current_module.locallibrarysearchpath.First);
  339. while assigned(HPath) do
  340. begin
  341. if LdSupportsNoResponseFile then
  342. LinkRes.Add(maybequoted('-L'+HPath.Str))
  343. else
  344. LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
  345. HPath:=TStringListItem(HPath.Next);
  346. end;
  347. HPath:=TStringListItem(LibrarySearchPath.First);
  348. while assigned(HPath) do
  349. begin
  350. if LdSupportsNoResponseFile then
  351. LinkRes.Add(maybequoted('-L'+HPath.Str))
  352. else
  353. LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
  354. HPath:=TStringListItem(HPath.Next);
  355. end;
  356. if not LdSupportsNoResponseFile then
  357. LinkRes.Add('INPUT(');
  358. { add objectfiles, start with prt0 always }
  359. if prtobj<>'' then
  360. LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
  361. { try to add crti and crtbegin if linking to C }
  362. if linklibc and
  363. (target_info.system <> system_powerpc_darwin) then
  364. begin
  365. if librarysearchpath.FindFile('crtbegin.o',s) then
  366. LinkRes.AddFileName(s);
  367. if librarysearchpath.FindFile('crti.o',s) then
  368. LinkRes.AddFileName(s);
  369. end;
  370. { main objectfiles }
  371. while not ObjectFiles.Empty do
  372. begin
  373. s:=ObjectFiles.GetFirst;
  374. if s<>'' then
  375. LinkRes.AddFileName(maybequoted(s));
  376. end;
  377. if not LdSupportsNoResponseFile then
  378. LinkRes.Add(')');
  379. { Write staticlibraries }
  380. if not StaticLibFiles.Empty then
  381. begin
  382. if not LdSupportsNoResponseFile then
  383. LinkRes.Add('GROUP(');
  384. While not StaticLibFiles.Empty do
  385. begin
  386. S:=StaticLibFiles.GetFirst;
  387. LinkRes.AddFileName(maybequoted(s))
  388. end;
  389. if not LdSupportsNoResponseFile then
  390. LinkRes.Add(')');
  391. end;
  392. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  393. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  394. if not SharedLibFiles.Empty then
  395. begin
  396. if not LdSupportsNoResponseFile then
  397. LinkRes.Add('INPUT(');
  398. While not SharedLibFiles.Empty do
  399. begin
  400. S:=SharedLibFiles.GetFirst;
  401. if s<>'c' then
  402. begin
  403. i:=Pos(target_info.sharedlibext,S);
  404. if i>0 then
  405. Delete(S,i,255);
  406. LinkRes.Add('-l'+s);
  407. end
  408. else
  409. begin
  410. linklibc:=true;
  411. linkdynamic:=false; { libc will include the ld-* for us }
  412. end;
  413. end;
  414. { be sure that libc is the last lib }
  415. if linklibc then
  416. Begin
  417. If LibrarySuffix=' ' Then
  418. LinkRes.Add('-lc')
  419. else
  420. LinkRes.Add('-lc_'+LibrarySuffix);
  421. If LibrarySuffix='r' Then
  422. LinkRes.Add('-lc');
  423. end;
  424. { when we have -static for the linker the we also need libgcc }
  425. if (cs_link_staticflag in aktglobalswitches) then
  426. LinkRes.Add('-lgcc');
  427. if linkdynamic and (Info.DynamicLinker<>'') then
  428. LinkRes.AddFileName(Info.DynamicLinker);
  429. if not LdSupportsNoResponseFile then
  430. LinkRes.Add(')');
  431. end;
  432. { objects which must be at the end }
  433. if linklibc and
  434. (target_info.system <> system_powerpc_darwin) then
  435. begin
  436. Fl1:=librarysearchpath.FindFile('crtend.o',s1);
  437. Fl2:=librarysearchpath.FindFile('crtn.o',s2);
  438. if Fl1 or Fl2 then
  439. begin
  440. LinkRes.Add('INPUT(');
  441. If Fl1 Then
  442. LinkRes.AddFileName(s1);
  443. If Fl2 Then
  444. LinkRes.AddFileName(s2);
  445. LinkRes.Add(')');
  446. end;
  447. end;
  448. { ignore the fact that our relocations are in non-writable sections, }
  449. { will be fixed once we have pic support }
  450. if isdll and
  451. (target_info.system = system_powerpc_darwin) then
  452. LinkRes.Add('-read_only_relocs suppress');
  453. { Write and Close response }
  454. linkres.writetodisk;
  455. linkres.Free;
  456. WriteResponseFile:=True;
  457. end;
  458. function TLinkerBSD.MakeExecutable:boolean;
  459. var
  460. binstr : String;
  461. cmdstr : TCmdStr;
  462. success : boolean;
  463. DynLinkStr : string[60];
  464. GCSectionsStr,
  465. StaticStr,
  466. StripStr : string[40];
  467. begin
  468. if not(cs_link_extern in aktglobalswitches) then
  469. Message1(exec_i_linking,current_module.exefilename^);
  470. { Create some replacements }
  471. StaticStr:='';
  472. StripStr:='';
  473. DynLinkStr:='';
  474. GCSectionsStr:='';
  475. if (cs_link_staticflag in aktglobalswitches) then
  476. begin
  477. if (target_info.system=system_m68k_netbsd) and
  478. ((cs_link_on_target in aktglobalswitches) or
  479. (target_info.system=source_info.system)) then
  480. StaticStr:='-Bstatic'
  481. else
  482. StaticStr:='-static';
  483. end;
  484. if (cs_link_strip in aktglobalswitches) then
  485. if (target_info.system <> system_powerpc_darwin) then
  486. StripStr:='-s'
  487. else
  488. StripStr:='-x';
  489. if (cs_link_smart in aktglobalswitches) and
  490. (tf_smartlink_sections in target_info.flags) then
  491. GCSectionsStr:='--gc-sections';
  492. If (cs_profile in aktmoduleswitches) or
  493. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  494. DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
  495. if CShared Then
  496. begin
  497. if (target_info.system <> system_powerpc_darwin) then
  498. DynLinKStr:=DynLinkStr+' --shared'
  499. else
  500. DynLinKStr:=DynLinkStr+' -dynamic'; // one dash!
  501. end;
  502. { Write used files and libraries }
  503. WriteResponseFile(false);
  504. { Call linker }
  505. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  506. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename^));
  507. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  508. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  509. Replace(cmdstr,'$STATIC',StaticStr);
  510. Replace(cmdstr,'$STRIP',StripStr);
  511. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  512. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  513. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,LdSupportsNoResponseFile);
  514. { Remove ReponseFile }
  515. if (success) and not(cs_link_extern in aktglobalswitches) then
  516. RemoveFile(outputexedir+Info.ResName);
  517. MakeExecutable:=success; { otherwise a recursive call to link method }
  518. end;
  519. Function TLinkerBSD.MakeSharedLibrary:boolean;
  520. var
  521. InitStr,
  522. FiniStr,
  523. SoNameStr : string[80];
  524. binstr : String;
  525. cmdstr : TCmdStr;
  526. success : boolean;
  527. begin
  528. MakeSharedLibrary:=false;
  529. if not(cs_link_extern in aktglobalswitches) then
  530. Message1(exec_i_linking,current_module.sharedlibfilename^);
  531. { Write used files and libraries }
  532. WriteResponseFile(true);
  533. InitStr:='-init FPC_LIB_START';
  534. FiniStr:='-fini FPC_LIB_EXIT';
  535. SoNameStr:='-soname '+SplitFileName(current_module.sharedlibfilename^);
  536. { Call linker }
  537. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  538. {$ifndef darwin}
  539. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
  540. {$else darwin}
  541. {$ifdef USE_SYSUTILS}
  542. Replace(cmdstr,'$EXE',maybequoted(ExpandFileName(current_module.sharedlibfilename^)));
  543. {$else USE_SYSUTILS}
  544. Replace(cmdstr,'$EXE',maybequoted(FExpand(current_module.sharedlibfilename^)));
  545. {$endif USE_SYSUTILS}
  546. {$endif darwin}
  547. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  548. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  549. Replace(cmdstr,'$INIT',InitStr);
  550. Replace(cmdstr,'$FINI',FiniStr);
  551. Replace(cmdstr,'$SONAME',SoNameStr);
  552. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,LdSupportsNoResponseFile);
  553. { Strip the library ? }
  554. if success and (cs_link_strip in aktglobalswitches) then
  555. begin
  556. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  557. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
  558. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  559. end;
  560. { Remove ReponseFile }
  561. if (success) and not(cs_link_extern in aktglobalswitches) then
  562. RemoveFile(outputexedir+Info.ResName);
  563. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  564. end;
  565. {*****************************************************************************
  566. Initialize
  567. *****************************************************************************}
  568. initialization
  569. {$ifdef x86_64}
  570. RegisterExternalLinker(system_x86_64_FreeBSD_info,TLinkerBSD);
  571. RegisterImport(system_x86_64_freebsd,timportlibbsd);
  572. RegisterExport(system_x86_64_freebsd,texportlibbsd);
  573. RegisterTarget(system_x86_64_freebsd_info);
  574. {$endif}
  575. {$ifdef i386}
  576. RegisterExternalLinker(system_i386_FreeBSD_info,TLinkerBSD);
  577. RegisterExternalLinker(system_i386_NetBSD_info,TLinkerBSD);
  578. RegisterExternalLinker(system_i386_OpenBSD_info,TLinkerBSD);
  579. RegisterImport(system_i386_freebsd,timportlibbsd);
  580. RegisterExport(system_i386_freebsd,texportlibbsd);
  581. RegisterTarget(system_i386_freebsd_info);
  582. RegisterImport(system_i386_netbsd,timportlibbsd);
  583. RegisterExport(system_i386_netbsd,texportlibbsd);
  584. RegisterTarget(system_i386_netbsd_info);
  585. RegisterImport(system_i386_openbsd,timportlibbsd);
  586. RegisterExport(system_i386_openbsd,texportlibbsd);
  587. RegisterTarget(system_i386_openbsd_info);
  588. {$endif i386}
  589. {$ifdef m68k}
  590. // RegisterExternalLinker(system_m68k_FreeBSD_info,TLinkerBSD);
  591. RegisterExternalLinker(system_m68k_NetBSD_info,TLinkerBSD);
  592. RegisterImport(system_m68k_netbsd,timportlibbsd);
  593. RegisterExport(system_m68k_netbsd,texportlibbsd);
  594. RegisterTarget(system_m68k_netbsd_info);
  595. {$endif m68k}
  596. {$ifdef powerpc}
  597. // RegisterExternalLinker(system_m68k_FreeBSD_info,TLinkerBSD);
  598. RegisterExternalLinker(system_powerpc_darwin_info,TLinkerBSD);
  599. RegisterImport(system_powerpc_darwin,timportlibdarwin);
  600. RegisterExport(system_powerpc_darwin,texportlibbsd);
  601. RegisterTarget(system_powerpc_darwin_info);
  602. RegisterExternalLinker(system_powerpc_netbsd_info,TLinkerBSD);
  603. RegisterImport(system_powerpc_netbsd,timportlibbsd);
  604. RegisterExport(system_powerpc_netbsd,texportlibbsd);
  605. RegisterTarget(system_powerpc_netbsd_info);
  606. {$endif powerpc}
  607. end.