t_bsd.pas 22 KB

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