t_bsd.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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. End;
  271. Function TLinkerBSD.WriteResponseFile(isdll:boolean) : Boolean;
  272. Var
  273. linkres : TLinkRes;
  274. i : longint;
  275. cprtobj,
  276. gprtobj,
  277. prtobj : string[80];
  278. HPath : TStringListItem;
  279. s,s1,s2 : string;
  280. linkpthread,
  281. linkdynamic,
  282. linklibc : boolean;
  283. Fl1,Fl2 : Boolean;
  284. IsDarwin : Boolean;
  285. ReOrder : Boolean;
  286. begin
  287. WriteResponseFile:=False;
  288. ReOrder:=False;
  289. IsDarwin:=target_info.system in [system_powerpc_darwin,system_i386_darwin];
  290. { set special options for some targets }
  291. if not IsDarwin Then
  292. begin
  293. prtobj:='prt0';
  294. cprtobj:='cprt0';
  295. gprtobj:='gprt0';
  296. linkdynamic:=not(SharedLibFiles.empty);
  297. linklibc:=(SharedLibFiles.Find('c')<>nil);
  298. // this one is a bit complex.
  299. // Only reorder for now if -XL or -XO params are given
  300. // or when -Xf.
  301. reorder:= linklibc and
  302. (
  303. ReorderEntries
  304. or
  305. (cs_link_pthread in aktglobalswitches));
  306. if cs_profile in aktmoduleswitches then
  307. begin
  308. prtobj:=gprtobj;
  309. AddSharedLibrary('c');
  310. LibrarySuffix:='p';
  311. linklibc:=true;
  312. end
  313. else
  314. begin
  315. if linklibc then
  316. prtobj:=cprtobj;
  317. end;
  318. if reorder Then
  319. ExpandAndApplyOrder(SharedLibFiles);
  320. // after this point addition of shared libs not allowed.
  321. end
  322. else
  323. begin
  324. { for darwin: always link dynamically against libc }
  325. linklibc := true;
  326. if not(isdll) then
  327. if not(cs_profile in aktmoduleswitches) then
  328. begin
  329. if librarysearchpath.FindFile('crt1.o',s) then
  330. prtobj:=s
  331. else
  332. prtobj:='/usr/lib/crt1.o';
  333. end
  334. else
  335. prtobj:='/usr/lib/gcrt1.o'
  336. else
  337. prtobj:='';
  338. end;
  339. { Open link.res file }
  340. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  341. if (not isdll) then
  342. begin
  343. case target_info.system of
  344. system_powerpc_darwin:
  345. LinkRes.Add('-arch ppc');
  346. system_i386_darwin:
  347. LinkRes.Add('-arch i386');
  348. end;
  349. end;
  350. { Write path to search libraries }
  351. HPath:=TStringListItem(current_module.locallibrarysearchpath.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. HPath:=TStringListItem(LibrarySearchPath.First);
  361. while assigned(HPath) do
  362. begin
  363. if LdSupportsNoResponseFile then
  364. LinkRes.Add(maybequoted('-L'+HPath.Str))
  365. else
  366. LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
  367. HPath:=TStringListItem(HPath.Next);
  368. end;
  369. if not LdSupportsNoResponseFile then
  370. LinkRes.Add('INPUT(');
  371. { add objectfiles, start with prt0 always }
  372. if prtobj<>'' then
  373. LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
  374. { try to add crti and crtbegin if linking to C }
  375. if linklibc and
  376. not IsDarwin Then
  377. begin
  378. if librarysearchpath.FindFile('crtbegin.o',s) then
  379. LinkRes.AddFileName(s);
  380. if librarysearchpath.FindFile('crti.o',s) then
  381. LinkRes.AddFileName(s);
  382. end;
  383. { main objectfiles }
  384. while not ObjectFiles.Empty do
  385. begin
  386. s:=ObjectFiles.GetFirst;
  387. if s<>'' then
  388. LinkRes.AddFileName(maybequoted(s));
  389. end;
  390. if not LdSupportsNoResponseFile then
  391. LinkRes.Add(')');
  392. { Write staticlibraries }
  393. if not StaticLibFiles.Empty then
  394. begin
  395. if not LdSupportsNoResponseFile then
  396. LinkRes.Add('GROUP(');
  397. While not StaticLibFiles.Empty do
  398. begin
  399. S:=StaticLibFiles.GetFirst;
  400. LinkRes.AddFileName(maybequoted(s))
  401. end;
  402. if not LdSupportsNoResponseFile then
  403. LinkRes.Add(')');
  404. end;
  405. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  406. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  407. if not SharedLibFiles.Empty then
  408. begin
  409. if not LdSupportsNoResponseFile then
  410. LinkRes.Add('INPUT(');
  411. While not SharedLibFiles.Empty do
  412. begin
  413. S:=SharedLibFiles.GetFirst;
  414. if (s<>'c') or reorder then
  415. begin
  416. i:=Pos(target_info.sharedlibext,S);
  417. if i>0 then
  418. Delete(S,i,255);
  419. LinkRes.Add('-l'+s);
  420. end
  421. else
  422. begin
  423. linklibc:=true;
  424. linkdynamic:=false; { libc will include the ld-* for us }
  425. end;
  426. end;
  427. { be sure that libc is the last lib }
  428. if linklibc and not reorder then
  429. Begin
  430. If LibrarySuffix=' ' Then
  431. LinkRes.Add('-lc')
  432. else
  433. LinkRes.Add('-lc_'+LibrarySuffix);
  434. If LibrarySuffix='r' Then
  435. LinkRes.Add('-lc');
  436. end;
  437. { when we have -static for the linker the we also need libgcc }
  438. if (cs_link_staticflag in aktglobalswitches) then
  439. LinkRes.Add('-lgcc');
  440. if linkdynamic and (Info.DynamicLinker<>'') then
  441. LinkRes.AddFileName(Info.DynamicLinker);
  442. if not LdSupportsNoResponseFile then
  443. LinkRes.Add(')');
  444. end;
  445. { objects which must be at the end }
  446. if linklibc and
  447. not IsDarwin Then
  448. begin
  449. Fl1:=librarysearchpath.FindFile('crtend.o',s1);
  450. Fl2:=librarysearchpath.FindFile('crtn.o',s2);
  451. if Fl1 or Fl2 then
  452. begin
  453. LinkRes.Add('INPUT(');
  454. If Fl1 Then
  455. LinkRes.AddFileName(s1);
  456. If Fl2 Then
  457. LinkRes.AddFileName(s2);
  458. LinkRes.Add(')');
  459. end;
  460. end;
  461. { ignore the fact that our relocations are in non-writable sections, }
  462. { will be fixed once we have pic support }
  463. if isdll and IsDarwin Then
  464. LinkRes.Add('-read_only_relocs suppress');
  465. { Write and Close response }
  466. linkres.writetodisk;
  467. linkres.Free;
  468. WriteResponseFile:=True;
  469. end;
  470. function TLinkerBSD.MakeExecutable:boolean;
  471. var
  472. binstr : String;
  473. cmdstr : TCmdStr;
  474. success : boolean;
  475. DynLinkStr : string[60];
  476. GCSectionsStr,
  477. StaticStr,
  478. StripStr : string[40];
  479. begin
  480. if not(cs_link_nolink in aktglobalswitches) then
  481. Message1(exec_i_linking,current_module.exefilename^);
  482. { Create some replacements }
  483. StaticStr:='';
  484. StripStr:='';
  485. DynLinkStr:='';
  486. GCSectionsStr:='';
  487. if (cs_link_staticflag in aktglobalswitches) then
  488. begin
  489. if (target_info.system=system_m68k_netbsd) and
  490. ((cs_link_on_target in aktglobalswitches) or
  491. (target_info.system=source_info.system)) then
  492. StaticStr:='-Bstatic'
  493. else
  494. StaticStr:='-static';
  495. end;
  496. if (cs_link_strip in aktglobalswitches) then
  497. if not(target_info.system in [system_powerpc_darwin,system_i386_darwin]) then
  498. StripStr:='-s'
  499. else
  500. StripStr:='-x';
  501. if (cs_link_smart in aktglobalswitches) and
  502. (tf_smartlink_sections in target_info.flags) then
  503. GCSectionsStr:='--gc-sections';
  504. If (cs_profile in aktmoduleswitches) or
  505. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  506. DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
  507. if CShared Then
  508. begin
  509. if not(target_info.system in [system_powerpc_darwin,system_i386_darwin]) then
  510. DynLinKStr:=DynLinkStr+' --shared'
  511. else
  512. DynLinKStr:=DynLinkStr+' -dynamic'; // one dash!
  513. end;
  514. { Write used files and libraries }
  515. WriteResponseFile(false);
  516. { Call linker }
  517. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  518. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename^));
  519. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  520. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  521. Replace(cmdstr,'$STATIC',StaticStr);
  522. Replace(cmdstr,'$STRIP',StripStr);
  523. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  524. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  525. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,LdSupportsNoResponseFile);
  526. { Remove ReponseFile }
  527. if (success) and not(cs_link_nolink in aktglobalswitches) then
  528. RemoveFile(outputexedir+Info.ResName);
  529. MakeExecutable:=success; { otherwise a recursive call to link method }
  530. end;
  531. Function TLinkerBSD.MakeSharedLibrary:boolean;
  532. var
  533. InitStr,
  534. FiniStr,
  535. SoNameStr : string[80];
  536. binstr : String;
  537. cmdstr : TCmdStr;
  538. success : boolean;
  539. begin
  540. MakeSharedLibrary:=false;
  541. if not(cs_link_nolink in aktglobalswitches) then
  542. Message1(exec_i_linking,current_module.sharedlibfilename^);
  543. { Write used files and libraries }
  544. WriteResponseFile(true);
  545. InitStr:='-init FPC_LIB_START';
  546. FiniStr:='-fini FPC_LIB_EXIT';
  547. SoNameStr:='-soname '+SplitFileName(current_module.sharedlibfilename^);
  548. { Call linker }
  549. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  550. {$ifndef darwin}
  551. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
  552. {$else darwin}
  553. {$ifdef USE_SYSUTILS}
  554. Replace(cmdstr,'$EXE',maybequoted(ExpandFileName(current_module.sharedlibfilename^)));
  555. {$else USE_SYSUTILS}
  556. Replace(cmdstr,'$EXE',maybequoted(FExpand(current_module.sharedlibfilename^)));
  557. {$endif USE_SYSUTILS}
  558. {$endif darwin}
  559. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  560. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  561. Replace(cmdstr,'$INIT',InitStr);
  562. Replace(cmdstr,'$FINI',FiniStr);
  563. Replace(cmdstr,'$SONAME',SoNameStr);
  564. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,LdSupportsNoResponseFile);
  565. { Strip the library ? }
  566. if success and (cs_link_strip in aktglobalswitches) then
  567. begin
  568. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  569. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
  570. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  571. end;
  572. { Remove ReponseFile }
  573. if (success) and not(cs_link_nolink in aktglobalswitches) then
  574. RemoveFile(outputexedir+Info.ResName);
  575. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  576. end;
  577. {*****************************************************************************
  578. Initialize
  579. *****************************************************************************}
  580. initialization
  581. {$ifdef x86_64}
  582. RegisterExternalLinker(system_x86_64_FreeBSD_info,TLinkerBSD);
  583. RegisterImport(system_x86_64_freebsd,timportlibbsd);
  584. RegisterExport(system_x86_64_freebsd,texportlibbsd);
  585. RegisterTarget(system_x86_64_freebsd_info);
  586. {$endif}
  587. {$ifdef i386}
  588. RegisterExternalLinker(system_i386_FreeBSD_info,TLinkerBSD);
  589. RegisterExternalLinker(system_i386_NetBSD_info,TLinkerBSD);
  590. RegisterExternalLinker(system_i386_OpenBSD_info,TLinkerBSD);
  591. RegisterImport(system_i386_freebsd,timportlibbsd);
  592. RegisterExport(system_i386_freebsd,texportlibbsd);
  593. RegisterTarget(system_i386_freebsd_info);
  594. RegisterImport(system_i386_netbsd,timportlibbsd);
  595. RegisterExport(system_i386_netbsd,texportlibbsd);
  596. RegisterTarget(system_i386_netbsd_info);
  597. RegisterImport(system_i386_openbsd,timportlibbsd);
  598. RegisterExport(system_i386_openbsd,texportlibbsd);
  599. RegisterTarget(system_i386_openbsd_info);
  600. RegisterExternalLinker(system_i386_darwin_info,TLinkerBSD);
  601. RegisterImport(system_i386_darwin,timportlibdarwin);
  602. RegisterExport(system_i386_darwin,texportlibbsd);
  603. RegisterTarget(system_i386_darwin_info);
  604. {$endif i386}
  605. {$ifdef m68k}
  606. // RegisterExternalLinker(system_m68k_FreeBSD_info,TLinkerBSD);
  607. RegisterExternalLinker(system_m68k_NetBSD_info,TLinkerBSD);
  608. RegisterImport(system_m68k_netbsd,timportlibbsd);
  609. RegisterExport(system_m68k_netbsd,texportlibbsd);
  610. RegisterTarget(system_m68k_netbsd_info);
  611. {$endif m68k}
  612. {$ifdef powerpc}
  613. // RegisterExternalLinker(system_m68k_FreeBSD_info,TLinkerBSD);
  614. RegisterExternalLinker(system_powerpc_darwin_info,TLinkerBSD);
  615. RegisterImport(system_powerpc_darwin,timportlibdarwin);
  616. RegisterExport(system_powerpc_darwin,texportlibbsd);
  617. RegisterTarget(system_powerpc_darwin_info);
  618. RegisterExternalLinker(system_powerpc_netbsd_info,TLinkerBSD);
  619. RegisterImport(system_powerpc_netbsd,timportlibbsd);
  620. RegisterExport(system_powerpc_netbsd,texportlibbsd);
  621. RegisterTarget(system_powerpc_netbsd_info);
  622. {$endif powerpc}
  623. end.