t_sunos.pas 21 KB

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