t_sunos.pas 21 KB

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