t_sunos.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. {
  2. Copyright (c) 1998-2008 by Peter Vreman
  3. This unit implements support import,export,link routines
  4. for the (i386) solaris target
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit t_sunos;
  19. {$i fpcdefs.inc}
  20. interface
  21. { copy from t_linux
  22. // Up to now we use gld since the solaris ld seems not support .res-files}
  23. {-$DEFINE LinkTest} { DON't del link.res and write Info }
  24. {$DEFINE GnuLd}{The other is not implemented }
  25. implementation
  26. uses
  27. sysutils,
  28. cutils,cfileutl,cclasses,
  29. verbose,systems,globtype,globals,
  30. cscript,
  31. fmodule,
  32. import,export,expunix,link,comprsrc,rescmn,i_sunos,ogbase;
  33. type
  34. timportlibsolaris=class(timportlib)
  35. procedure generatelib;override;
  36. end;
  37. texportlibsolaris=class(texportlibunix)
  38. end;
  39. tlinkersolaris=class(texternallinker)
  40. private
  41. Glibc2,
  42. Glibc21 : boolean;
  43. use_gnu_ld : boolean;
  44. linkres : TLinkRes;
  45. Function WriteResponseFile(isdll:boolean) : Boolean;
  46. public
  47. constructor Create;override;
  48. procedure SetDefaultInfo;override;
  49. function MakeExecutable:boolean;override;
  50. function MakeSharedLibrary:boolean;override;
  51. end;
  52. {*****************************************************************************
  53. TIMPORTLIBsolaris
  54. *****************************************************************************}
  55. procedure timportlibsolaris.generatelib;
  56. var
  57. i : longint;
  58. ImportLibrary : TImportLibrary;
  59. begin
  60. for i:=0 to current_module.ImportLibraryList.Count-1 do
  61. begin
  62. ImportLibrary:=TImportLibrary(current_module.ImportLibraryList[i]);
  63. current_module.linkothersharedlibs.add(ImportLibrary.Name,link_always);
  64. end;
  65. end;
  66. {*****************************************************************************
  67. TLINKERsolaris
  68. *****************************************************************************}
  69. {$ifdef x86_64}
  70. const
  71. gnu_emul = '-m elf_x86_64_sol2';
  72. {$endif}
  73. {$ifdef i386}
  74. const
  75. gnu_emul = '-m elf_i386_sol2';
  76. {$endif }
  77. {$ifdef sparc}
  78. const
  79. { no emulation specification needed, as long as only 32-bit is supported }
  80. gnu_emul = '';
  81. {$endif}
  82. Constructor TLinkersolaris.Create;
  83. begin
  84. Inherited Create;
  85. if cs_link_native in init_settings.globalswitches then
  86. use_gnu_ld:=false
  87. else
  88. use_gnu_ld:=true;
  89. if NOT Dontlinkstdlibpath Then
  90. {$ifdef x86_64}
  91. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib/64;=/usr/lib/64;=/usr/X11R6/lib/64;=/opt/sfw/lib/64',true);
  92. {$else not x86_64}
  93. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib;=/usr/lib;=/usr/X11R6/lib;=/opt/sfw/lib',true);
  94. {$endif not x86_64}
  95. {$ifdef LinkTest}
  96. if (cs_link_staticflag in current_settings.globalswitches) then WriteLN('ForceLinkStaticFlag');
  97. if (cs_link_static in current_settings.globalswitches) then WriteLN('LinkStatic-Flag');
  98. if (cs_link_shared in current_settings.globalswitches) then WriteLN('LinkSynamicFlag');
  99. {$EndIf}
  100. end;
  101. procedure TLinkersolaris.SetDefaultInfo;
  102. {
  103. This will also detect which libc version will be used
  104. }
  105. {$ifdef x86_64}
  106. const
  107. gld = 'gld $EMUL ';
  108. solaris_ld = 'ld -64 ';
  109. {$endif}
  110. {$ifdef i386}
  111. const
  112. gld = 'gld $EMUL';
  113. solaris_ld = 'ld ';
  114. {$endif }
  115. {$ifdef sparc}
  116. const
  117. gld = 'gld ';
  118. solaris_ld = 'ld ';
  119. {$endif}
  120. begin
  121. Glibc2:=false;
  122. Glibc21:=false;
  123. with Info do
  124. begin
  125. {$IFDEF GnuLd}
  126. ExeCmd[1]:=gld + '$OPT $DYNLINK $STATIC $STRIP -L. -o $EXE $RES';
  127. ExeCmd[2]:=solaris_ld + '$OPT $DYNLINK $STATIC $STRIP -L . -o $EXE $RESDATA $REDIRECT';
  128. DllCmd[1]:=gld + '$OPT $INITFINI -shared -L. $MAP -o $EXE $RES';
  129. DllCmd[2]:='gstrip --strip-unneeded $EXE';
  130. DllCmd[3]:=solaris_ld + '$OPT $INITFINI -M $VERSIONFILE $MAP -G -Bdynamic -L. -o $EXE $RESDATA $REDIRECT';
  131. DynamicLinker:=''; { Gnu uses the default }
  132. Glibc21:=false;
  133. {$ELSE}
  134. Not Implememted
  135. {$ENDIF}
  136. end;
  137. end;
  138. Function TLinkersolaris.WriteResponseFile(isdll:boolean) : Boolean;
  139. Var
  140. i : longint;
  141. { cprtobj,
  142. gprtobj,
  143. prtobj : string[80];}
  144. HPath : TCmdStrListItem;
  145. s,s2 : TCmdStr;
  146. linkdynamic,
  147. linklibc : boolean;
  148. LinkRes2 : TLinkRes;
  149. begin
  150. WriteResponseFile:=False;
  151. { set special options for some targets }
  152. linkdynamic:=not(SharedLibFiles.empty);
  153. { linkdynamic:=false; // da nicht getestet }
  154. linklibc:=(SharedLibFiles.Find('c')<>nil);
  155. { prtobj:='prt0';
  156. cprtobj:='cprt0';
  157. gprtobj:='gprt0';}
  158. if cs_profile in current_settings.moduleswitches then
  159. begin
  160. { prtobj:=gprtobj;}
  161. if not glibc2 then
  162. AddSharedLibrary('gmon');
  163. AddSharedLibrary('c');
  164. linklibc:=true;
  165. end
  166. else
  167. begin
  168. if linklibc then
  169. begin
  170. { prtobj:=cprtobj;}
  171. end
  172. else
  173. AddSharedLibrary('c'); { quick hack: this solaris implementation needs alwys libc }
  174. end;
  175. if use_gnu_ld then
  176. begin
  177. { Open link.res file }
  178. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  179. { Write path to search libraries }
  180. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  181. while assigned(HPath) do
  182. begin
  183. LinkRes.Add('SEARCH_DIR("'+HPath.Str+'")');
  184. HPath:=TCmdStrListItem(HPath.Next);
  185. end;
  186. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  187. while assigned(HPath) do
  188. begin
  189. LinkRes.Add('SEARCH_DIR("'+HPath.Str+'")');
  190. HPath:=TCmdStrListItem(HPath.Next);
  191. end;
  192. { force local symbol resolution (i.e., inside the shared }
  193. { library itself) for all non-exorted symbols, otherwise }
  194. { several RTL symbols of FPC-compiled shared libraries }
  195. { will be bound to those of a single shared library or }
  196. { to the main program }
  197. if (isdll) then
  198. begin
  199. LinkRes.add('VERSION');
  200. LinkRes.add('{ DEFAULT'); { gld 2.25 does not support anonymous version }
  201. LinkRes.add(' {');
  202. if not texportlibunix(exportlib).exportedsymnames.empty then
  203. begin
  204. LinkRes.add(' global:');
  205. repeat
  206. LinkRes.add(' '+texportlibunix(exportlib).exportedsymnames.getfirst+';');
  207. until texportlibunix(exportlib).exportedsymnames.empty;
  208. end;
  209. LinkRes.add(' local:');
  210. LinkRes.add(' *;');
  211. LinkRes.add(' };');
  212. LinkRes.add('}');
  213. end;
  214. LinkRes.Add('INPUT(');
  215. { add objectfiles, start with prt0 always }
  216. { solaris port contains _start inside the system unit, it
  217. needs only one entry because it is linked always against libc
  218. if prtobj<>'' then
  219. LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
  220. }
  221. { try to add crti and crtbegin if linking to C }
  222. if linklibc then { Needed in solaris? }
  223. begin
  224. { if librarysearchpath.FindFile('crtbegin.o',s) then
  225. LinkRes.AddFileName(s);}
  226. if librarysearchpath.FindFile('crti.o',false,s) then
  227. LinkRes.AddFileName(s);
  228. end;
  229. { main objectfiles }
  230. while not ObjectFiles.Empty do
  231. begin
  232. s:=ObjectFiles.GetFirst;
  233. if s<>'' then
  234. LinkRes.AddFileName(maybequoted(s));
  235. end;
  236. LinkRes.Add(')');
  237. { Write staticlibraries }
  238. if not StaticLibFiles.Empty then
  239. begin
  240. LinkRes.Add('GROUP(');
  241. While not StaticLibFiles.Empty do
  242. begin
  243. S:=StaticLibFiles.GetFirst;
  244. LinkRes.AddFileName(maybequoted(s))
  245. end;
  246. LinkRes.Add(')');
  247. end;
  248. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  249. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  250. if not SharedLibFiles.Empty then
  251. begin
  252. LinkRes.Add('INPUT(');
  253. While not SharedLibFiles.Empty do
  254. begin
  255. S:=SharedLibFiles.GetFirst;
  256. if s<>'c' then
  257. begin
  258. i:=Pos(target_info.sharedlibext,S);
  259. if i>0 then
  260. Delete(S,i,255);
  261. LinkRes.Add('-l'+s);
  262. end
  263. else
  264. begin
  265. LinkRes.Add('-lc');
  266. linklibc:=true;
  267. linkdynamic:=false; { libc will include the ld-solaris (war ld-linux) for us }
  268. end;
  269. end;
  270. { be sure that libc is the last lib }
  271. if linklibc then
  272. LinkRes.Add('-lc');
  273. { when we have -static for the linker the we also need libgcc }
  274. if (cs_link_staticflag in current_settings.globalswitches) then begin
  275. LinkRes.Add('-lgcc');
  276. end;
  277. if linkdynamic and (Info.DynamicLinker<>'') then { gld has a default, DynamicLinker is not set in solaris }
  278. LinkRes.AddFileName(Info.DynamicLinker);
  279. LinkRes.Add(')');
  280. end;
  281. { objects which must be at the end }
  282. if linklibc then {needed in solaris ? }
  283. begin
  284. if {librarysearchpath.FindFile('crtend.o',s1) or}
  285. librarysearchpath.FindFile('crtn.o',false,s2) then
  286. begin
  287. LinkRes.Add('INPUT(');
  288. { LinkRes.AddFileName(s1);}
  289. LinkRes.AddFileName(s2);
  290. LinkRes.Add(')');
  291. end;
  292. end;
  293. { Write and Close response }
  294. linkres.writetodisk;
  295. LinkRes.Free;
  296. end
  297. else { not use_gnu_ld }
  298. begin
  299. { Open TlinkRes, will not be written to disk }
  300. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName+'2',false);
  301. { Write path to search libraries }
  302. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  303. while assigned(HPath) do
  304. begin
  305. LinkRes.Add('-L '+maybequoted(HPath.Str));
  306. HPath:=TCmdStrListItem(HPath.Next);
  307. end;
  308. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  309. while assigned(HPath) do
  310. begin
  311. LinkRes.Add('-L '+maybequoted(HPath.Str));
  312. HPath:=TCmdStrListItem(HPath.Next);
  313. end;
  314. { force local symbol resolution (i.e., inside the shared }
  315. { library itself) for all non-exorted symbols, otherwise }
  316. { several RTL symbols of FPC-compiled shared libraries }
  317. { will be bound to those of a single shared library or }
  318. { to the main program }
  319. if (isdll) then
  320. begin
  321. LinkRes2:=TLinkRes.Create(outputexedir+Info.ResName,true);
  322. // LinkRes2.add('VERSION'); not needed for now
  323. LinkRes2.add(' {');
  324. if not texportlibunix(exportlib).exportedsymnames.empty then
  325. begin
  326. LinkRes2.add(' global:');
  327. repeat
  328. LinkRes2.add(' '+texportlibunix(exportlib).exportedsymnames.getfirst+';');
  329. until texportlibunix(exportlib).exportedsymnames.empty;
  330. end;
  331. LinkRes2.add(' local:');
  332. LinkRes2.add(' *;');
  333. LinkRes2.add(' };');
  334. LinkRes2.writetodisk;
  335. LinkRes2.Free;
  336. end;
  337. { add objectfiles, start with prt0 always }
  338. { solaris port contains _start inside the system unit, it
  339. needs only one entry because it is linked always against libc
  340. if prtobj<>'' then
  341. LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
  342. }
  343. { try to add crti and crtbegin if linking to C }
  344. if linklibc then { Needed in solaris? }
  345. begin
  346. { if librarysearchpath.FindFile('crtbegin.o',s) then
  347. LinkRes.AddFileName(s);}
  348. if librarysearchpath.FindFile('crti.o',false,s) then
  349. LinkRes.AddFileName(s);
  350. end;
  351. { main objectfiles }
  352. while not ObjectFiles.Empty do
  353. begin
  354. s:=ObjectFiles.GetFirst;
  355. if s<>'' then
  356. LinkRes.AddFileName(maybequoted(s));
  357. end;
  358. { Write staticlibraries }
  359. if not StaticLibFiles.Empty then
  360. begin
  361. linkres.add('-(');
  362. While not StaticLibFiles.Empty do
  363. begin
  364. S:=StaticLibFiles.GetFirst;
  365. LinkRes.AddFileName(maybequoted(s))
  366. end;
  367. linkres.add('-)');
  368. end;
  369. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  370. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  371. if not SharedLibFiles.Empty then
  372. begin
  373. While not SharedLibFiles.Empty do
  374. begin
  375. S:=SharedLibFiles.GetFirst;
  376. if s<>'c' then
  377. begin
  378. i:=Pos(target_info.sharedlibext,S);
  379. if i>0 then
  380. Delete(S,i,255);
  381. LinkRes.Add('-l'+s);
  382. end
  383. else
  384. begin
  385. linklibc:=true;
  386. linkdynamic:=false; { libc will include the ld-solaris (war ld-linux) for us }
  387. end;
  388. end;
  389. { be sure that libc is the last lib }
  390. if linklibc then
  391. LinkRes.Add('-lc');
  392. { when we have -static for the linker the we also need libgcc }
  393. if (cs_link_staticflag in current_settings.globalswitches) then begin
  394. LinkRes.Add('-lgcc');
  395. end;
  396. if linkdynamic and (Info.DynamicLinker<>'') then { gld has a default, DynamicLinker is not set in solaris }
  397. LinkRes.AddFileName(Info.DynamicLinker);
  398. end;
  399. { objects which must be at the end }
  400. if linklibc then {needed in solaris ? }
  401. begin
  402. if {librarysearchpath.FindFile('crtend.o',s1) or}
  403. librarysearchpath.FindFile('crtn.o',false,s2) then
  404. begin
  405. { LinkRes.AddFileName(s1);}
  406. LinkRes.AddFileName(s2);
  407. end;
  408. end;
  409. { Write and Close response }
  410. //linkres.writetodisk;
  411. //LinkRes.Free;
  412. end;
  413. WriteResponseFile:=True;
  414. end;
  415. function TLinkersolaris.MakeExecutable:boolean;
  416. var
  417. binstr,
  418. s, linkstr,
  419. cmdstr : TCmdStr;
  420. success : boolean;
  421. DynLinkStr : string[60];
  422. StaticStr, RedirectStr,
  423. StripStr : string[40];
  424. begin
  425. success:=false;
  426. if not(cs_link_nolink in current_settings.globalswitches) then
  427. Message1(exec_i_linking,current_module.exefilename);
  428. { Create some replacements }
  429. StaticStr:='';
  430. StripStr:='';
  431. RedirectStr:='';
  432. DynLinkStr:='';
  433. if (cs_link_staticflag in current_settings.globalswitches) then
  434. StaticStr:='-Bstatic';
  435. if (cs_link_strip in current_settings.globalswitches) then
  436. StripStr:='-s';
  437. if (cs_link_map in current_settings.globalswitches) then
  438. begin
  439. if use_gnu_ld then
  440. StripStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'))
  441. else
  442. begin
  443. StripStr:='-m';
  444. RedirectStr:=' > '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  445. end;
  446. end;
  447. If (cs_profile in current_settings.moduleswitches) or
  448. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  449. DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
  450. if rlinkpath<>'' then
  451. if use_gnu_ld then
  452. DynLinkStr:=DynLinkStr+' --rpath-link '+rlinkpath
  453. else
  454. DynLinkStr:=DynLinkStr+' -R '+rlinkpath;
  455. { solaris sets DynamicLinker, but gld will (hopefully) defaults to -Bdynamic and add the default-linker }
  456. { Write used files and libraries }
  457. WriteResponseFile(false);
  458. { Call linker }
  459. if use_gnu_ld then
  460. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr)
  461. else
  462. SplitBinCmd(Info.ExeCmd[2],binstr,cmdstr);
  463. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  464. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  465. if use_gnu_ld then
  466. begin
  467. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  468. Replace(cmdstr,'$EMUL',gnu_emul);
  469. end
  470. else
  471. begin
  472. linkstr:='';
  473. while not linkres.data.Empty do
  474. begin
  475. s:=linkres.data.GetFirst;
  476. if s<>'' then
  477. linkstr:=linkstr+' '+s;
  478. end;
  479. linkres.free;
  480. Replace(cmdstr,'$RESDATA',linkstr);
  481. end;
  482. Replace(cmdstr,'$STATIC',StaticStr);
  483. Replace(cmdstr,'$STRIP',StripStr);
  484. Replace(cmdstr,'$REDIRECT',RedirectStr);
  485. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  486. if BinStr[1]<>'/' then
  487. BinStr:=FindUtil(utilsprefix+BinStr);
  488. { We need shell if output is redirected }
  489. success:=DoExec(BinStr,Trim(CmdStr),true,RedirectStr<>'');
  490. { Remove ReponseFile }
  491. {$IFNDEF LinkTest}
  492. if (success) and use_gnu_ld and
  493. not(cs_link_nolink in current_settings.globalswitches) then
  494. DeleteFile(outputexedir+Info.ResName);
  495. {$ENDIF}
  496. MakeExecutable:=success; { otherwise a recursive call to link method }
  497. end;
  498. Function TLinkersolaris.MakeSharedLibrary:boolean;
  499. var
  500. InitFiniStr : string;
  501. binstr, RedirectStr,
  502. s, linkstr, MapStr,
  503. cmdstr : TCmdStr;
  504. need_quotes, success : boolean;
  505. begin
  506. success:=false;
  507. MakeSharedLibrary:=false;
  508. if not(cs_link_nolink in current_settings.globalswitches) then
  509. Message1(exec_i_linking,current_module.sharedlibfilename);
  510. { Write used files and libraries }
  511. WriteResponseFile(true);
  512. RedirectStr:='';
  513. MapStr:='';
  514. { Create some replacements }
  515. if (cs_link_map in current_settings.globalswitches) then
  516. begin
  517. if use_gnu_ld then
  518. MapStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'))
  519. else
  520. begin
  521. MapStr:='-m';
  522. RedirectStr:=' > '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  523. end;
  524. end;
  525. need_quotes:= (cs_link_nolink in current_settings.globalswitches) or
  526. (RedirectStr<>'');
  527. { initname and fininame may contain $, which can be wrongly interpreted
  528. in a link script, thus we surround them with single quotes
  529. in cs_link_nolink is in globalswitches }
  530. if use_gnu_ld then
  531. begin
  532. InitFiniStr:='-init ';
  533. if need_quotes then
  534. InitFiniStr:=InitFiniStr+''''+exportlib.initname+''''
  535. else
  536. InitFiniStr:=InitFiniStr+exportlib.initname;
  537. if (exportlib.fininame<>'') then
  538. begin
  539. if need_quotes then
  540. InitFiniStr:=InitFiniStr+' -fini '''+exportlib.initname+''''
  541. else
  542. InitFiniStr:=InitFiniStr+' -fini '+exportlib.fininame;
  543. end;
  544. end
  545. else
  546. begin
  547. InitFiniStr:='-z initarray=';
  548. if need_quotes then
  549. InitFiniStr:=InitFiniStr+''''+exportlib.initname+''''
  550. else
  551. InitFiniStr:=InitFiniStr+exportlib.initname;
  552. if (exportlib.fininame<>'') then
  553. begin
  554. if need_quotes then
  555. InitFiniStr:=InitFiniStr+' -z finiarray='''+exportlib.initname+''''
  556. else
  557. InitFiniStr:=InitFiniStr+' -z finiarray='+exportlib.fininame;
  558. end;
  559. end;
  560. { Call linker }
  561. if use_gnu_ld then
  562. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr)
  563. else
  564. SplitBinCmd(Info.DllCmd[3],binstr,cmdstr);
  565. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  566. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  567. Replace(cmdstr,'$INITFINI',InitFiniStr);
  568. if use_gnu_ld then
  569. begin
  570. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  571. Replace(cmdstr,'$EMUL',gnu_emul);
  572. end
  573. else
  574. begin
  575. Replace(cmdstr,'$VERSIONFILE',maybequoted(outputexedir+Info.ResName));
  576. linkstr:='';
  577. while not linkres.data.Empty do
  578. begin
  579. s:=linkres.data.GetFirst;
  580. if s<>'' then
  581. linkstr:=linkstr+' '+s;
  582. end;
  583. linkres.free;
  584. Replace(cmdstr,'$RESDATA',linkstr);
  585. end;
  586. Replace(cmdstr,'$REDIRECT',RedirectStr);
  587. Replace(cmdstr,'$MAP',MapStr);
  588. if BinStr[1]<>'/' then
  589. BinStr:=FindUtil(utilsprefix+BinStr);
  590. { We need shell if output is redirected }
  591. success:=DoExec(BinStr,Trim(CmdStr),true,RedirectStr<>'');
  592. { Strip the library ? }
  593. if success and (cs_link_strip in current_settings.globalswitches) then
  594. begin
  595. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  596. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  597. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  598. end;
  599. { Remove ReponseFile }
  600. {$IFNDEF LinkTest}
  601. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  602. DeleteFile(outputexedir+Info.ResName);
  603. {$ENDIF}
  604. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  605. end;
  606. {*****************************************************************************
  607. Initialize
  608. *****************************************************************************}
  609. initialization
  610. RegisterLinker(ld_solaris,TLinkerSolaris);
  611. {$ifdef i386}
  612. RegisterImport(system_i386_solaris,TImportLibsolaris);
  613. RegisterExport(system_i386_solaris,TExportLibsolaris);
  614. RegisterTarget(system_i386_solaris_info);
  615. {$endif i386}
  616. {$ifdef x86_64}
  617. RegisterImport(system_x86_64_solaris,TImportLibsolaris);
  618. RegisterExport(system_x86_64_solaris,TExportLibsolaris);
  619. RegisterTarget(system_x86_64_solaris_info);
  620. {$endif x86_64}
  621. {$ifdef sparc}
  622. RegisterImport(system_sparc_solaris,TImportLibsolaris);
  623. RegisterExport(system_sparc_solaris,TExportLibsolaris);
  624. RegisterTarget(system_sparc_solaris_info);
  625. {$endif sparc}
  626. RegisterRes(res_elf_info,TWinLikeResourceFile);
  627. end.