t_bsd.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. else
  269. begin
  270. LinkLibraryOrder.add('gcc','',15);
  271. LinkLibraryOrder.add('c','',50);
  272. end;
  273. End;
  274. Function TLinkerBSD.WriteResponseFile(isdll:boolean) : Boolean;
  275. Var
  276. linkres : TLinkRes;
  277. i : longint;
  278. cprtobj,
  279. gprtobj,
  280. prtobj : string[80];
  281. HPath : TStringListItem;
  282. s,s1,s2 : string;
  283. linkpthread,
  284. linkdynamic,
  285. linklibc : boolean;
  286. Fl1,Fl2 : Boolean;
  287. IsDarwin : Boolean;
  288. ReOrder : Boolean;
  289. begin
  290. WriteResponseFile:=False;
  291. ReOrder:=False;
  292. IsDarwin:=target_info.system in [system_powerpc_darwin,system_i386_darwin];
  293. { set special options for some targets }
  294. if not IsDarwin Then
  295. begin
  296. prtobj:='prt0';
  297. cprtobj:='cprt0';
  298. gprtobj:='gprt0';
  299. linkdynamic:=not(SharedLibFiles.empty);
  300. linklibc:=(SharedLibFiles.Find('c')<>nil);
  301. // this one is a bit complex.
  302. // Only reorder for now if -XL or -XO params are given
  303. // or when -Xf.
  304. reorder:= linklibc and
  305. (
  306. ReorderEntries
  307. or
  308. (cs_link_pthread in aktglobalswitches));
  309. if cs_profile in aktmoduleswitches then
  310. begin
  311. prtobj:=gprtobj;
  312. AddSharedLibrary('c');
  313. LibrarySuffix:='p';
  314. linklibc:=true;
  315. end
  316. else
  317. begin
  318. if linklibc then
  319. prtobj:=cprtobj;
  320. end;
  321. // after this point addition of shared libs not allowed.
  322. end
  323. else
  324. begin
  325. { for darwin: always link dynamically against libc }
  326. linklibc := true;
  327. reorder:=reorderentries;
  328. if not(isdll) then
  329. if not(cs_profile in aktmoduleswitches) then
  330. begin
  331. if librarysearchpath.FindFile('crt1.o',s) then
  332. prtobj:=s
  333. else
  334. prtobj:='/usr/lib/crt1.o';
  335. end
  336. else
  337. prtobj:='/usr/lib/gcrt1.o'
  338. else
  339. prtobj:='';
  340. end;
  341. if reorder Then
  342. ExpandAndApplyOrder(SharedLibFiles);
  343. { Open link.res file }
  344. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  345. if (not isdll) then
  346. begin
  347. case target_info.system of
  348. system_powerpc_darwin:
  349. LinkRes.Add('-arch ppc');
  350. system_i386_darwin:
  351. LinkRes.Add('-arch i386');
  352. end;
  353. end;
  354. { Write path to search libraries }
  355. HPath:=TStringListItem(current_module.locallibrarysearchpath.First);
  356. while assigned(HPath) do
  357. begin
  358. if LdSupportsNoResponseFile then
  359. LinkRes.Add(maybequoted('-L'+HPath.Str))
  360. else
  361. LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
  362. HPath:=TStringListItem(HPath.Next);
  363. end;
  364. HPath:=TStringListItem(LibrarySearchPath.First);
  365. while assigned(HPath) do
  366. begin
  367. if LdSupportsNoResponseFile then
  368. LinkRes.Add(maybequoted('-L'+HPath.Str))
  369. else
  370. LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
  371. HPath:=TStringListItem(HPath.Next);
  372. end;
  373. if not LdSupportsNoResponseFile then
  374. LinkRes.Add('INPUT(');
  375. { add objectfiles, start with prt0 always }
  376. if prtobj<>'' then
  377. LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
  378. { try to add crti and crtbegin if linking to C }
  379. if linklibc and
  380. not IsDarwin Then
  381. begin
  382. if librarysearchpath.FindFile('crtbegin.o',s) then
  383. LinkRes.AddFileName(s);
  384. if librarysearchpath.FindFile('crti.o',s) then
  385. LinkRes.AddFileName(s);
  386. end;
  387. { main objectfiles }
  388. while not ObjectFiles.Empty do
  389. begin
  390. s:=ObjectFiles.GetFirst;
  391. if s<>'' then
  392. LinkRes.AddFileName(maybequoted(s));
  393. end;
  394. if not LdSupportsNoResponseFile then
  395. LinkRes.Add(')');
  396. { Write staticlibraries }
  397. if not StaticLibFiles.Empty then
  398. begin
  399. if not LdSupportsNoResponseFile then
  400. LinkRes.Add('GROUP(');
  401. While not StaticLibFiles.Empty do
  402. begin
  403. S:=StaticLibFiles.GetFirst;
  404. LinkRes.AddFileName(maybequoted(s))
  405. end;
  406. if not LdSupportsNoResponseFile then
  407. LinkRes.Add(')');
  408. end;
  409. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  410. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  411. if not SharedLibFiles.Empty then
  412. begin
  413. if not LdSupportsNoResponseFile then
  414. LinkRes.Add('INPUT(');
  415. While not SharedLibFiles.Empty do
  416. begin
  417. S:=SharedLibFiles.GetFirst;
  418. if (s<>'c') or reorder then
  419. begin
  420. i:=Pos(target_info.sharedlibext,S);
  421. if i>0 then
  422. Delete(S,i,255);
  423. LinkRes.Add('-l'+s);
  424. end
  425. else
  426. begin
  427. linklibc:=true;
  428. linkdynamic:=false; { libc will include the ld-linux for us }
  429. end;
  430. end;
  431. { be sure that libc is the last lib }
  432. if linklibc and not reorder then
  433. Begin
  434. If LibrarySuffix=' ' Then
  435. LinkRes.Add('-lc')
  436. else
  437. LinkRes.Add('-lc_'+LibrarySuffix);
  438. If LibrarySuffix='r' Then
  439. LinkRes.Add('-lc');
  440. end;
  441. { when we have -static for the linker the we also need libgcc }
  442. if (cs_link_staticflag in aktglobalswitches) then
  443. LinkRes.Add('-lgcc');
  444. if linkdynamic and (Info.DynamicLinker<>'') then
  445. LinkRes.AddFileName(Info.DynamicLinker);
  446. if not LdSupportsNoResponseFile then
  447. LinkRes.Add(')');
  448. end;
  449. { objects which must be at the end }
  450. if linklibc and
  451. not IsDarwin Then
  452. begin
  453. Fl1:=librarysearchpath.FindFile('crtend.o',s1);
  454. Fl2:=librarysearchpath.FindFile('crtn.o',s2);
  455. if Fl1 or Fl2 then
  456. begin
  457. LinkRes.Add('INPUT(');
  458. If Fl1 Then
  459. LinkRes.AddFileName(s1);
  460. If Fl2 Then
  461. LinkRes.AddFileName(s2);
  462. LinkRes.Add(')');
  463. end;
  464. end;
  465. { ignore the fact that our relocations are in non-writable sections, }
  466. { will be fixed once we have pic support }
  467. if isdll and IsDarwin Then
  468. LinkRes.Add('-read_only_relocs suppress');
  469. { Write and Close response }
  470. linkres.writetodisk;
  471. linkres.Free;
  472. WriteResponseFile:=True;
  473. end;
  474. function TLinkerBSD.MakeExecutable:boolean;
  475. var
  476. binstr : String;
  477. cmdstr : TCmdStr;
  478. success : boolean;
  479. DynLinkStr : string[60];
  480. GCSectionsStr,
  481. StaticStr,
  482. StripStr : string[40];
  483. begin
  484. if not(cs_link_extern in aktglobalswitches) then
  485. Message1(exec_i_linking,current_module.exefilename^);
  486. { Create some replacements }
  487. StaticStr:='';
  488. StripStr:='';
  489. DynLinkStr:='';
  490. GCSectionsStr:='';
  491. if (cs_link_staticflag in aktglobalswitches) then
  492. begin
  493. if (target_info.system=system_m68k_netbsd) and
  494. ((cs_link_on_target in aktglobalswitches) or
  495. (target_info.system=source_info.system)) then
  496. StaticStr:='-Bstatic'
  497. else
  498. StaticStr:='-static';
  499. end;
  500. if (cs_link_strip in aktglobalswitches) then
  501. if (target_info.system <> system_powerpc_darwin) then
  502. StripStr:='-s'
  503. else
  504. StripStr:='-x';
  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 (target_info.system <> system_powerpc_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_extern 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_extern 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_extern 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. {$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.