t_bsd.pas 22 KB

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