t_sunos.pas 22 KB

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