t_bsd.pas 22 KB

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