t_sunos.pas 21 KB

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