t_bsd.pas 22 KB

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