t_bsd.pas 22 KB

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