t_linux.pas 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. {
  2. Copyright (c) 1998-2008 by Peter Vreman
  3. This unit implements support import,export,link routines
  4. for the (i386) Linux 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_linux;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. symsym,symdef,ppu,
  23. import,export,expunix,link;
  24. type
  25. timportliblinux=class(timportlib)
  26. procedure generatelib;override;
  27. end;
  28. texportliblinux=class(texportlibunix)
  29. end;
  30. tlinkerlinux=class(texternallinker)
  31. private
  32. libctype:(libc5,glibc2,glibc21,uclibc);
  33. cprtobj,
  34. gprtobj,
  35. prtobj : string[80];
  36. reorder : boolean;
  37. linklibc: boolean;
  38. Function WriteResponseFile(isdll:boolean) : Boolean;
  39. public
  40. constructor Create;override;
  41. procedure SetDefaultInfo;override;
  42. procedure InitSysInitUnitName;override;
  43. function MakeExecutable:boolean;override;
  44. function MakeSharedLibrary:boolean;override;
  45. procedure LoadPredefinedLibraryOrder; override;
  46. end;
  47. implementation
  48. uses
  49. SysUtils,
  50. cutils,cfileutl,cclasses,
  51. verbose,systems,globtype,globals,
  52. symconst,script,
  53. fmodule,
  54. aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,
  55. cgbase,cgobj,cgutils,ogbase,ncgutil,
  56. comprsrc,
  57. rescmn, i_linux
  58. ;
  59. {*****************************************************************************
  60. TIMPORTLIBLINUX
  61. *****************************************************************************}
  62. procedure timportliblinux.generatelib;
  63. var
  64. i : longint;
  65. ImportLibrary : TImportLibrary;
  66. begin
  67. for i:=0 to current_module.ImportLibraryList.Count-1 do
  68. begin
  69. ImportLibrary:=TImportLibrary(current_module.ImportLibraryList[i]);
  70. current_module.linkothersharedlibs.add(ImportLibrary.Name,link_always);
  71. end;
  72. end;
  73. {*****************************************************************************
  74. TLINKERLINUX
  75. *****************************************************************************}
  76. Constructor TLinkerLinux.Create;
  77. begin
  78. Inherited Create;
  79. if not Dontlinkstdlibpath Then
  80. {$ifdef x86_64}
  81. LibrarySearchPath.AddPath(sysrootpath,'/lib64;/usr/lib64;/usr/X11R6/lib64',true);
  82. {$else}
  83. {$ifdef powerpc64}
  84. LibrarySearchPath.AddPath(sysrootpath,'/lib64;/usr/lib64;/usr/X11R6/lib64',true);
  85. {$else powerpc64}
  86. LibrarySearchPath.AddPath(sysrootpath,'/lib;/usr/lib;/usr/X11R6/lib',true);
  87. {$endif powerpc64}
  88. {$endif x86_64}
  89. end;
  90. procedure TLinkerLinux.SetDefaultInfo;
  91. {
  92. This will also detect which libc version will be used
  93. }
  94. const
  95. {$ifdef i386} platform_select='-b elf32-i386 -m elf_i386';{$endif}
  96. {$ifdef x86_64} platform_select='-b elf64-x86-64 -m elf_x86_64';{$endif}
  97. {$ifdef powerpc}platform_select='-b elf32-powerpc -m elf32ppclinux';{$endif}
  98. {$ifdef POWERPC64} platform_select='-b elf64-powerpc -m elf64ppc';{$endif}
  99. {$ifdef sparc} platform_select='-b elf32-sparc -m elf32_sparc';{$endif}
  100. {$ifdef arm} platform_select='';{$endif} {unknown :( }
  101. {$ifdef m68k} platform_select='';{$endif} {unknown :( }
  102. var
  103. defdynlinker: string;
  104. begin
  105. with Info do
  106. begin
  107. ExeCmd[1]:='ld '+platform_select+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE';
  108. { when we want to cross-link we need to override default library paths }
  109. if length(sysrootpath) > 0 then
  110. ExeCmd[1]:=ExeCmd[1]+' -T';
  111. ExeCmd[1]:=ExeCmd[1]+' $RES';
  112. DllCmd[1]:='ld '+platform_select+' $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES';
  113. DllCmd[2]:='strip --strip-unneeded $EXE';
  114. ExtDbgCmd[1]:='objcopy --only-keep-debug $EXE $DBG';
  115. ExtDbgCmd[2]:='objcopy --add-gnu-debuglink=$DBG $EXE';
  116. ExtDbgCmd[3]:='strip --strip-unneeded $EXE';
  117. {$ifdef m68k}
  118. { experimental, is this correct? }
  119. defdynlinker:='/lib/ld-linux.so.2';
  120. {$endif m68k}
  121. {$ifdef i386}
  122. defdynlinker:='/lib/ld-linux.so.1';
  123. {$endif}
  124. {$ifdef x86_64}
  125. defdynlinker:='/lib64/ld-linux-x86-64.so.2';
  126. {$endif x86_64}
  127. {$ifdef sparc}
  128. defdynlinker:='/lib/ld-linux.so.2';
  129. {$endif sparc}
  130. {$ifdef powerpc}
  131. defdynlinker:='/lib/ld.so.1';
  132. {$endif powerpc}
  133. {$ifdef powerpc64}
  134. defdynlinker:='/lib64/ld64.so.1';
  135. {$endif powerpc64}
  136. {$ifdef arm}
  137. defdynlinker:='/lib/ld-linux.so.2';
  138. {$endif arm}
  139. {
  140. Search order:
  141. glibc 2.1+
  142. uclibc
  143. glibc 2.0
  144. If none is found (e.g. when cross compiling) glibc21 is assumed
  145. }
  146. {$ifdef i386}
  147. if FileExists(sysrootpath+'/lib/ld-linux.so.2',false) then
  148. begin
  149. DynamicLinker:='/lib/ld-linux.so.2';
  150. libctype:=glibc21;
  151. end
  152. else
  153. {$endif i386}
  154. if fileexists(sysrootpath+'/lib/ld-uClibc.so.0',false) then
  155. begin
  156. dynamiclinker:='/lib/ld-uClibc.so.0';
  157. libctype:=uclibc;
  158. end
  159. else if fileexists(sysrootpath+defdynlinker,false) then
  160. begin
  161. DynamicLinker:=defdynlinker;
  162. libctype:=glibc2;
  163. end
  164. else
  165. begin
  166. { default is glibc 2.1+ compatible }
  167. DynamicLinker:='/lib/ld-linux.so.2';
  168. libctype:=glibc21;
  169. end;
  170. end;
  171. end;
  172. procedure TLinkerLinux.LoadPredefinedLibraryOrder;
  173. // put your linkorder/linkalias overrides here.
  174. // Note: assumes only called when reordering/aliasing is used.
  175. Begin
  176. if not (cs_link_no_default_lib_order in current_settings.globalswitches) Then
  177. Begin
  178. LinkLibraryOrder.add('gcc','',15);
  179. LinkLibraryOrder.add('c','',100);
  180. LinkLibraryOrder.add('gmon','',120);
  181. LinkLibraryOrder.add('dl','',140);
  182. LinkLibraryOrder.add('pthread','',160);
  183. end;
  184. End;
  185. Procedure TLinkerLinux.InitSysInitUnitName;
  186. var
  187. csysinitunit,
  188. gsysinitunit : string[20];
  189. hp : tmodule;
  190. begin
  191. hp:=tmodule(loaded_units.first);
  192. while assigned(hp) do
  193. begin
  194. linklibc := hp.linkothersharedlibs.find('c');
  195. if linklibc then break;
  196. hp:=tmodule(hp.next);
  197. end;
  198. reorder := linklibc and ReOrderEntries;
  199. if current_module.islibrary then
  200. begin
  201. sysinitunit:='dll';
  202. csysinitunit:='dll';
  203. gsysinitunit:='dll';
  204. prtobj:='dllprt0';
  205. cprtobj:='dllprt0';
  206. gprtobj:='dllprt0';
  207. end
  208. else
  209. begin
  210. prtobj:='prt0';
  211. sysinitunit:='prc';
  212. case libctype of
  213. glibc21:
  214. begin
  215. cprtobj:='cprt21';
  216. gprtobj:='gprt21';
  217. csysinitunit:='c21';
  218. gsysinitunit:='c21g';
  219. end;
  220. uclibc:
  221. begin
  222. cprtobj:='ucprt0';
  223. gprtobj:='ugprt0';
  224. csysinitunit:='uc';
  225. gsysinitunit:='ucg';
  226. end
  227. else
  228. cprtobj:='cprt0';
  229. gprtobj:='gprt0';
  230. csysinitunit:='c';
  231. gsysinitunit:='g';
  232. end;
  233. end;
  234. if cs_profile in current_settings.moduleswitches then
  235. begin
  236. prtobj:=gprtobj;
  237. sysinitunit:=gsysinitunit;
  238. linklibc:=true;
  239. end
  240. else
  241. begin
  242. if linklibc then
  243. begin
  244. prtobj:=cprtobj;
  245. sysinitunit:=csysinitunit;
  246. end;
  247. end;
  248. sysinitunit:='si_'+sysinitunit;
  249. end;
  250. Function TLinkerLinux.WriteResponseFile(isdll:boolean) : Boolean;
  251. Var
  252. linkres : TLinkRes;
  253. i : longint;
  254. HPath : TCmdStrListItem;
  255. s,s1,s2 : TCmdStr;
  256. found1,
  257. found2 : boolean;
  258. begin
  259. result:=False;
  260. { set special options for some targets }
  261. if cs_profile in current_settings.moduleswitches then
  262. begin
  263. if not(libctype in [glibc2,glibc21]) then
  264. AddSharedLibrary('gmon');
  265. AddSharedLibrary('c');
  266. end;
  267. { Open link.res file }
  268. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  269. with linkres do
  270. begin
  271. { Write path to search libraries }
  272. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  273. while assigned(HPath) do
  274. begin
  275. Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
  276. HPath:=TCmdStrListItem(HPath.Next);
  277. end;
  278. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  279. while assigned(HPath) do
  280. begin
  281. Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
  282. HPath:=TCmdStrListItem(HPath.Next);
  283. end;
  284. { force local symbol resolution (i.e., inside the shared }
  285. { library itself) for all non-exorted symbols, otherwise }
  286. { several RTL symbols of FPC-compiled shared libraries }
  287. { will be bound to those of a single shared library or }
  288. { to the main program }
  289. if (isdll) then
  290. begin
  291. add('VERSION');
  292. add('{');
  293. add(' {');
  294. if not texportlibunix(exportlib).exportedsymnames.empty then
  295. begin
  296. add(' global:');
  297. repeat
  298. add(' '+texportlibunix(exportlib).exportedsymnames.getfirst+';');
  299. until texportlibunix(exportlib).exportedsymnames.empty;
  300. end;
  301. add(' local:');
  302. add(' *;');
  303. add(' };');
  304. add('}');
  305. end;
  306. StartSection('INPUT(');
  307. { add objectfiles, start with prt0 always }
  308. if not (target_info.system in system_internal_sysinit) and (prtobj<>'') then
  309. AddFileName(maybequoted(FindObjectFile(prtobj,'',false)));
  310. { try to add crti and crtbegin if linking to C }
  311. if linklibc and (libctype<>uclibc) then
  312. begin
  313. { x86_64 requires this to use entry/exit code with pic,
  314. see also issue #8210 regarding a discussion
  315. no idea about the other non i386 CPUs (FK)
  316. }
  317. {$ifdef x86_64}
  318. if current_module.islibrary then
  319. begin
  320. if librarysearchpath.FindFile('crtbeginS.o',false,s) then
  321. AddFileName(s);
  322. end
  323. else
  324. {$endif x86_64}
  325. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  326. AddFileName(s);
  327. if librarysearchpath.FindFile('crti.o',false,s) then
  328. AddFileName(s);
  329. end;
  330. { main objectfiles }
  331. while not ObjectFiles.Empty do
  332. begin
  333. s:=ObjectFiles.GetFirst;
  334. if s<>'' then
  335. AddFileName(maybequoted(s));
  336. end;
  337. EndSection(')');
  338. { Write staticlibraries }
  339. if not StaticLibFiles.Empty then
  340. begin
  341. Add('GROUP(');
  342. While not StaticLibFiles.Empty do
  343. begin
  344. S:=StaticLibFiles.GetFirst;
  345. AddFileName(maybequoted(s))
  346. end;
  347. Add(')');
  348. end;
  349. // we must reorder here because the result could empty sharedlibfiles
  350. if reorder Then
  351. ExpandAndApplyOrder(SharedLibFiles);
  352. // after this point addition of shared libs not allowed.
  353. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  354. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  355. if not SharedLibFiles.Empty then
  356. begin
  357. Add('INPUT(');
  358. While not SharedLibFiles.Empty do
  359. begin
  360. S:=SharedLibFiles.GetFirst;
  361. if (s<>'c') or reorder then
  362. begin
  363. i:=Pos(target_info.sharedlibext,S);
  364. if i>0 then
  365. Delete(S,i,255);
  366. Add('-l'+s);
  367. end
  368. else
  369. begin
  370. linklibc:=true;
  371. end;
  372. end;
  373. { be sure that libc is the last lib }
  374. if linklibc and not reorder then
  375. Add('-lc');
  376. { when we have -static for the linker the we also need libgcc }
  377. if (cs_link_staticflag in current_settings.globalswitches) then
  378. Add('-lgcc');
  379. Add(')');
  380. end;
  381. { objects which must be at the end }
  382. if linklibc and (libctype<>uclibc) then
  383. begin
  384. { x86_64 requires this to use entry/exit code with pic,
  385. see also issue #8210 regarding a discussion
  386. no idea about the other non i386 CPUs (FK)
  387. }
  388. {$ifdef x86_64}
  389. if current_module.islibrary then
  390. found1:=librarysearchpath.FindFile('crtendS.o',false,s1)
  391. else
  392. {$endif x86_64}
  393. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  394. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  395. if found1 or found2 then
  396. begin
  397. Add('INPUT(');
  398. if found1 then
  399. AddFileName(s1);
  400. if found2 then
  401. AddFileName(s2);
  402. Add(')');
  403. end;
  404. end;
  405. {Entry point.}
  406. add('ENTRY(_start)');
  407. {$ifdef x86_64}
  408. {$define LINKERSCRIPT_INCLUDED}
  409. add('SECTIONS');
  410. add('{');
  411. {Read-only sections, merged into text segment:}
  412. if current_module.islibrary then
  413. add(' . = 0 + SIZEOF_HEADERS;')
  414. else
  415. add(' PROVIDE (__executable_start = 0x0400000); . = 0x0400000 + SIZEOF_HEADERS;');
  416. add(' . = 0 + SIZEOF_HEADERS;');
  417. add(' .interp : { *(.interp) }');
  418. add(' .hash : { *(.hash) }');
  419. add(' .dynsym : { *(.dynsym) }');
  420. add(' .dynstr : { *(.dynstr) }');
  421. add(' .gnu.version : { *(.gnu.version) }');
  422. add(' .gnu.version_d : { *(.gnu.version_d) }');
  423. add(' .gnu.version_r : { *(.gnu.version_r) }');
  424. add(' .rel.dyn :');
  425. add(' {');
  426. add(' *(.rel.init)');
  427. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  428. add(' *(.rel.fini)');
  429. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  430. add(' *(.rel.data.rel.ro*)');
  431. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  432. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  433. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  434. add(' *(.rel.got)');
  435. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  436. add(' }');
  437. add(' .rela.dyn :');
  438. add(' {');
  439. add(' *(.rela.init)');
  440. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  441. add(' *(.rela.fini)');
  442. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  443. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  444. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  445. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  446. add(' *(.rela.got)');
  447. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  448. add(' }');
  449. add(' .rel.plt : { *(.rel.plt) }');
  450. add(' .rela.plt : { *(.rela.plt) }');
  451. add(' .init :');
  452. add(' {');
  453. add(' KEEP (*(.init))');
  454. add(' } =0x90909090');
  455. add(' .plt : { *(.plt) }');
  456. add(' .text :');
  457. add(' {');
  458. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  459. add(' KEEP (*(.text.*personality*))');
  460. {.gnu.warning sections are handled specially by elf32.em.}
  461. add(' *(.gnu.warning)');
  462. add(' } =0x90909090');
  463. add(' .fini :');
  464. add(' {');
  465. add(' KEEP (*(.fini))');
  466. add(' } =0x90909090');
  467. add(' PROVIDE (_etext = .);');
  468. add(' .rodata :');
  469. add(' {');
  470. add(' *(.rodata .rodata.* .gnu.linkonce.r.*)');
  471. add(' }');
  472. {Adjust the address for the data segment. We want to adjust up to
  473. the same address within the page on the next page up.}
  474. add(' . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1));');
  475. add(' .dynamic : { *(.dynamic) }');
  476. add(' .got : { *(.got .toc) }');
  477. add(' .got.plt : { *(.got.plt .toc.plt) }');
  478. add(' .data :');
  479. add(' {');
  480. add(' *(.data .data.* .gnu.linkonce.d.*)');
  481. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  482. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  483. add(' }');
  484. add(' PROVIDE (_edata = .);');
  485. add(' PROVIDE (edata = .);');
  486. {$ifdef zsegment_threadvars}
  487. add(' _z = .;');
  488. add(' .threadvar 0 : AT (_z) { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  489. add(' PROVIDE (_threadvar_size = SIZEOF(.threadvar));');
  490. add(' . = _z + SIZEOF (.threadvar);');
  491. {$else}
  492. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  493. {$endif}
  494. add(' __bss_start = .;');
  495. add(' .bss :');
  496. add(' {');
  497. add(' *(.dynbss)');
  498. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  499. add(' *(COMMON)');
  500. {Align here to ensure that the .bss section occupies space up to
  501. _end. Align after .bss to ensure correct alignment even if the
  502. .bss section disappears because there are no input sections.}
  503. add(' . = ALIGN(32 / 8);');
  504. add(' }');
  505. add(' . = ALIGN(32 / 8);');
  506. add(' PROVIDE (_end = .);');
  507. add(' PROVIDE (end = .);');
  508. {Stabs debugging sections.}
  509. add(' .stab 0 : { *(.stab) }');
  510. add(' .stabstr 0 : { *(.stabstr) }');
  511. add(' /* DWARF debug sections.');
  512. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  513. add(' of the section so we begin them at 0. */');
  514. add(' /* DWARF 1 */');
  515. add(' .debug 0 : { *(.debug) }');
  516. add(' .line 0 : { *(.line) }');
  517. add(' /* GNU DWARF 1 extensions */');
  518. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  519. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  520. add(' /* DWARF 1.1 and DWARF 2 */');
  521. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  522. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  523. add(' /* DWARF 2 */');
  524. add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  525. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  526. add(' .debug_line 0 : { *(.debug_line) }');
  527. add(' .debug_frame 0 : { *(.debug_frame) }');
  528. add(' .debug_str 0 : { *(.debug_str) }');
  529. add(' .debug_loc 0 : { *(.debug_loc) }');
  530. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  531. add(' /* SGI/MIPS DWARF 2 extensions */');
  532. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  533. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  534. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  535. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  536. add(' /DISCARD/ : { *(.note.GNU-stack) }');
  537. add('}');
  538. {$endif x86_64}
  539. {$ifdef ARM}
  540. if target_info.abi=abi_eabi then
  541. begin
  542. { from GNU ld (CodeSourcery Sourcery G++ Lite 2007q3-53) 2.18.50.20070820 }
  543. add('/* Script for -z combreloc: combine and sort reloc sections */');
  544. add('OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm",');
  545. add(' "elf32-littlearm")');
  546. add('OUTPUT_ARCH(arm)');
  547. add('ENTRY(_start)');
  548. add('SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");');
  549. add('SECTIONS');
  550. add('{');
  551. add(' /* Read-only sections, merged into text segment: */');
  552. add(' PROVIDE (__executable_start = 0x8000); . = 0x8000;');
  553. add(' .interp : { *(.interp) }');
  554. add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  555. add(' .hash : { *(.hash) }');
  556. add(' .gnu.hash : { *(.gnu.hash) }');
  557. add(' .dynsym : { *(.dynsym) }');
  558. add(' .dynstr : { *(.dynstr) }');
  559. add(' .gnu.version : { *(.gnu.version) }');
  560. add(' .gnu.version_d : { *(.gnu.version_d) }');
  561. add(' .gnu.version_r : { *(.gnu.version_r) }');
  562. add(' .rel.dyn :');
  563. add(' {');
  564. add(' *(.rel.init)');
  565. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  566. add(' *(.rel.fini)');
  567. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  568. add(' *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*)');
  569. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  570. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  571. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  572. add(' *(.rel.ctors)');
  573. add(' *(.rel.dtors)');
  574. add(' *(.rel.got)');
  575. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  576. add(' }');
  577. add(' .rela.dyn :');
  578. add(' {');
  579. add(' *(.rela.init)');
  580. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  581. add(' *(.rela.fini)');
  582. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  583. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  584. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  585. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  586. add(' *(.rela.ctors)');
  587. add(' *(.rela.dtors)');
  588. add(' *(.rela.got)');
  589. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  590. add(' }');
  591. add(' .rel.plt : { *(.rel.plt) }');
  592. add(' .rela.plt : { *(.rela.plt) }');
  593. add(' .init :');
  594. add(' {');
  595. add(' KEEP (*(.init))');
  596. add(' } =0');
  597. add(' .plt : { *(.plt) }');
  598. add(' .text :');
  599. add(' {');
  600. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  601. add(' KEEP (*(.text.*personality*))');
  602. add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  603. add(' *(.gnu.warning)');
  604. add(' *(.glue_7t) *(.glue_7) *(.vfp11_veneer)');
  605. add(' } =0');
  606. add(' .fini :');
  607. add(' {');
  608. add(' KEEP (*(.fini))');
  609. add(' } =0');
  610. add(' PROVIDE (__etext = .);');
  611. add(' PROVIDE (_etext = .);');
  612. add(' PROVIDE (etext = .);');
  613. add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
  614. add(' .rodata1 : { *(.rodata1) }');
  615. add(' .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) }');
  616. add(' __exidx_start = .;');
  617. add(' .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }');
  618. add(' __exidx_end = .;');
  619. add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  620. add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  621. add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }');
  622. add(' /* Adjust the address for the data segment. We want to adjust up to');
  623. add(' the same address within the page on the next page up. */');
  624. add(' . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));');
  625. add(' /* Exception handling */');
  626. add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  627. add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  628. add(' /* Thread Local Storage sections */');
  629. add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  630. add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  631. add(' .preinit_array :');
  632. add(' {');
  633. add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
  634. add(' KEEP (*(.preinit_array))');
  635. add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
  636. add(' }');
  637. add(' .init_array :');
  638. add(' {');
  639. add(' PROVIDE_HIDDEN (__init_array_start = .);');
  640. add(' KEEP (*(SORT(.init_array.*)))');
  641. add(' KEEP (*(.init_array))');
  642. add(' PROVIDE_HIDDEN (__init_array_end = .);');
  643. add(' }');
  644. add(' .fini_array :');
  645. add(' {');
  646. add(' PROVIDE_HIDDEN (__fini_array_start = .);');
  647. add(' KEEP (*(.fini_array))');
  648. add(' KEEP (*(SORT(.fini_array.*)))');
  649. add(' PROVIDE_HIDDEN (__fini_array_end = .);');
  650. add(' }');
  651. add(' .ctors :');
  652. add(' {');
  653. add(' /* gcc uses crtbegin.o to find the start of');
  654. add(' the constructors, so we make sure it is');
  655. add(' first. Because this is a wildcard, it');
  656. add(' doesn''t matter if the user does not');
  657. add(' actually link against crtbegin.o; the');
  658. add(' linker won''t look for a file to match a');
  659. add(' wildcard. The wildcard also means that it');
  660. add(' doesn''t matter which directory crtbegin.o');
  661. add(' is in. */');
  662. add(' KEEP (*crtbegin.o(.ctors))');
  663. add(' KEEP (*crtbegin?.o(.ctors))');
  664. add(' /* We don''t want to include the .ctor section from');
  665. add(' the crtend.o file until after the sorted ctors.');
  666. add(' The .ctor section from the crtend file contains the');
  667. add(' end of ctors marker and it must be last */');
  668. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
  669. add(' KEEP (*(SORT(.ctors.*)))');
  670. add(' KEEP (*(.ctors))');
  671. add(' }');
  672. add(' .dtors :');
  673. add(' {');
  674. add(' KEEP (*crtbegin.o(.dtors))');
  675. add(' KEEP (*crtbegin?.o(.dtors))');
  676. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
  677. add(' KEEP (*(SORT(.dtors.*)))');
  678. add(' KEEP (*(.dtors))');
  679. add(' }');
  680. add(' .jcr : { KEEP (*(.jcr)) }');
  681. add(' .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }');
  682. add(' .dynamic : { *(.dynamic) }');
  683. add(' .got : { *(.got.plt) *(.got) }');
  684. add(' .data :');
  685. add(' {');
  686. add(' __data_start = . ;');
  687. add(' *(.data .data.* .gnu.linkonce.d.*)');
  688. { extra by FPC }
  689. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  690. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  691. add(' SORT(CONSTRUCTORS)');
  692. add(' }');
  693. add(' .data1 : { *(.data1) }');
  694. add(' _edata = .; PROVIDE (edata = .);');
  695. add(' __bss_start = .;');
  696. add(' __bss_start__ = .;');
  697. add(' .bss :');
  698. add(' {');
  699. add(' *(.dynbss)');
  700. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  701. add(' *(COMMON)');
  702. add(' /* Align here to ensure that the .bss section occupies space up to');
  703. add(' _end. Align after .bss to ensure correct alignment even if the');
  704. add(' .bss section disappears because there are no input sections.');
  705. add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
  706. add(' pad the .data section. */');
  707. add(' . = ALIGN(. != 0 ? 32 / 8 : 1);');
  708. add(' }');
  709. add(' _bss_end__ = . ; __bss_end__ = . ;');
  710. add(' . = ALIGN(32 / 8);');
  711. add(' . = ALIGN(32 / 8);');
  712. add(' __end__ = . ;');
  713. add(' _end = .; PROVIDE (end = .);');
  714. add(' /* Stabs debugging sections. */');
  715. add(' .stab 0 : { *(.stab) }');
  716. add(' .stabstr 0 : { *(.stabstr) }');
  717. add(' .stab.excl 0 : { *(.stab.excl) }');
  718. add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  719. add(' .stab.index 0 : { *(.stab.index) }');
  720. add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  721. add(' .comment 0 : { *(.comment) }');
  722. add(' /* DWARF debug sections.');
  723. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  724. add(' of the section so we begin them at 0. */');
  725. add(' /* DWARF 1 */');
  726. add(' .debug 0 : { *(.debug) }');
  727. add(' .line 0 : { *(.line) }');
  728. add(' /* GNU DWARF 1 extensions */');
  729. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  730. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  731. add(' /* DWARF 1.1 and DWARF 2 */');
  732. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  733. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  734. add(' /* DWARF 2 */');
  735. add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  736. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  737. add(' .debug_line 0 : { *(.debug_line) }');
  738. add(' .debug_frame 0 : { *(.debug_frame) }');
  739. add(' .debug_str 0 : { *(.debug_str) }');
  740. add(' .debug_loc 0 : { *(.debug_loc) }');
  741. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  742. add(' /* SGI/MIPS DWARF 2 extensions */');
  743. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  744. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  745. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  746. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  747. add(' /* DWARF 3 */');
  748. add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  749. add(' .debug_ranges 0 : { *(.debug_ranges) }');
  750. add(' .stack 0x80000 :');
  751. add(' {');
  752. add(' _stack = .;');
  753. add(' *(.stack)');
  754. add(' }');
  755. add(' .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }');
  756. add(' .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }');
  757. add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) }');
  758. add('}');
  759. end
  760. else
  761. {$endif ARM}
  762. {$ifndef LINKERSCRIPT_INCLUDED}
  763. begin
  764. {Sections.}
  765. add('SECTIONS');
  766. add('{');
  767. {Read-only sections, merged into text segment:}
  768. add(' PROVIDE (__executable_start = 0x010000); . = 0x010000 +0x100;');
  769. add(' .interp : { *(.interp) }');
  770. add(' .hash : { *(.hash) }');
  771. add(' .dynsym : { *(.dynsym) }');
  772. add(' .dynstr : { *(.dynstr) }');
  773. add(' .gnu.version : { *(.gnu.version) }');
  774. add(' .gnu.version_d : { *(.gnu.version_d) }');
  775. add(' .gnu.version_r : { *(.gnu.version_r) }');
  776. add(' .rel.dyn :');
  777. add(' {');
  778. add(' *(.rel.init)');
  779. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  780. add(' *(.rel.fini)');
  781. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  782. add(' *(.rel.data.rel.ro*)');
  783. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  784. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  785. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  786. add(' *(.rel.got)');
  787. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  788. add(' }');
  789. add(' .rela.dyn :');
  790. add(' {');
  791. add(' *(.rela.init)');
  792. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  793. add(' *(.rela.fini)');
  794. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  795. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  796. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  797. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  798. add(' *(.rela.got)');
  799. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  800. add(' }');
  801. add(' .rel.plt : { *(.rel.plt) }');
  802. add(' .rela.plt : { *(.rela.plt) }');
  803. add(' .init :');
  804. add(' {');
  805. add(' KEEP (*(.init))');
  806. add(' } =0x90909090');
  807. add(' .plt : { *(.plt) }');
  808. add(' .text :');
  809. add(' {');
  810. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  811. add(' KEEP (*(.text.*personality*))');
  812. {.gnu.warning sections are handled specially by elf32.em.}
  813. add(' *(.gnu.warning)');
  814. add(' } =0x90909090');
  815. add(' .fini :');
  816. add(' {');
  817. add(' KEEP (*(.fini))');
  818. add(' } =0x90909090');
  819. add(' PROVIDE (_etext = .);');
  820. add(' .rodata :');
  821. add(' {');
  822. add(' *(.rodata .rodata.* .gnu.linkonce.r.*)');
  823. add(' }');
  824. {Adjust the address for the data segment. We want to adjust up to
  825. the same address within the page on the next page up.}
  826. add(' . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1));');
  827. add(' .dynamic : { *(.dynamic) }');
  828. add(' .got : { *(.got) }');
  829. add(' .got.plt : { *(.got.plt) }');
  830. add(' .data :');
  831. add(' {');
  832. add(' *(.data .data.* .gnu.linkonce.d.*)');
  833. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  834. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  835. add(' }');
  836. add(' PROVIDE (_edata = .);');
  837. add(' PROVIDE (edata = .);');
  838. {$ifdef zsegment_threadvars}
  839. add(' _z = .;');
  840. add(' .threadvar 0 : AT (_z) { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  841. add(' PROVIDE (_threadvar_size = SIZEOF(.threadvar));');
  842. add(' . = _z + SIZEOF (.threadvar);');
  843. {$else}
  844. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  845. {$endif}
  846. add(' __bss_start = .;');
  847. add(' .bss :');
  848. add(' {');
  849. add(' *(.dynbss)');
  850. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  851. add(' *(COMMON)');
  852. {Align here to ensure that the .bss section occupies space up to
  853. _end. Align after .bss to ensure correct alignment even if the
  854. .bss section disappears because there are no input sections.}
  855. add(' . = ALIGN(32 / 8);');
  856. add(' }');
  857. add(' . = ALIGN(32 / 8);');
  858. add(' PROVIDE (_end = .);');
  859. add(' PROVIDE (end = .);');
  860. {Stabs debugging sections.}
  861. add(' .stab 0 : { *(.stab) }');
  862. add(' .stabstr 0 : { *(.stabstr) }');
  863. add('}');
  864. end;
  865. {$endif LINKERSCRIPT_INCLUDED}
  866. { Write and Close response }
  867. writetodisk;
  868. Free;
  869. end;
  870. WriteResponseFile:=True;
  871. end;
  872. function TLinkerLinux.MakeExecutable:boolean;
  873. var
  874. i : longint;
  875. binstr,
  876. cmdstr : TCmdStr;
  877. success : boolean;
  878. DynLinkStr : string;
  879. GCSectionsStr,
  880. StaticStr,
  881. StripStr : string[40];
  882. begin
  883. if not(cs_link_nolink in current_settings.globalswitches) then
  884. Message1(exec_i_linking,current_module.exefilename^);
  885. { Create some replacements }
  886. StaticStr:='';
  887. StripStr:='';
  888. GCSectionsStr:='';
  889. DynLinkStr:='';
  890. if (cs_link_staticflag in current_settings.globalswitches) then
  891. StaticStr:='-static';
  892. if (cs_link_strip in current_settings.globalswitches) and
  893. not(cs_link_separate_dbg_file in current_settings.globalswitches) then
  894. StripStr:='-s';
  895. if (cs_link_map in current_settings.globalswitches) then
  896. StripStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename^,'.map'));
  897. if create_smartlink_sections then
  898. GCSectionsStr:='--gc-sections';
  899. If (cs_profile in current_settings.moduleswitches) or
  900. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  901. begin
  902. DynLinkStr:='--dynamic-linker='+Info.DynamicLinker;
  903. if cshared then
  904. DynLinkStr:=DynLinkStr+' --shared ';
  905. if rlinkpath<>'' then
  906. DynLinkStr:=DynLinkStr+' --rpath-link '+rlinkpath;
  907. End;
  908. { Write used files and libraries }
  909. WriteResponseFile(false);
  910. { Call linker }
  911. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  912. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename^));
  913. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  914. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  915. Replace(cmdstr,'$STATIC',StaticStr);
  916. Replace(cmdstr,'$STRIP',StripStr);
  917. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  918. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  919. { create dynamic symbol table? }
  920. if HasExports then
  921. cmdstr:=cmdstr+' -E';
  922. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  923. { Create external .dbg file with debuginfo }
  924. if success and (cs_link_separate_dbg_file in current_settings.globalswitches) then
  925. begin
  926. for i:=1 to 3 do
  927. begin
  928. SplitBinCmd(Info.ExtDbgCmd[i],binstr,cmdstr);
  929. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename^));
  930. Replace(cmdstr,'$DBGFN',maybequoted(extractfilename(current_module.dbgfilename^)));
  931. Replace(cmdstr,'$DBG',maybequoted(current_module.dbgfilename^));
  932. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  933. if not success then
  934. break;
  935. end;
  936. end;
  937. { Remove ReponseFile }
  938. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  939. DeleteFile(outputexedir+Info.ResName);
  940. MakeExecutable:=success; { otherwise a recursive call to link method }
  941. end;
  942. Function TLinkerLinux.MakeSharedLibrary:boolean;
  943. var
  944. InitStr,
  945. FiniStr,
  946. SoNameStr : string[80];
  947. binstr,
  948. cmdstr : TCmdStr;
  949. success : boolean;
  950. begin
  951. MakeSharedLibrary:=false;
  952. if not(cs_link_nolink in current_settings.globalswitches) then
  953. Message1(exec_i_linking,current_module.sharedlibfilename^);
  954. { Write used files and libraries }
  955. WriteResponseFile(true);
  956. { Create some replacements }
  957. { note: linux does not use exportlib.initname/fininame due to the custom startup code }
  958. InitStr:='-init FPC_LIB_START';
  959. FiniStr:='-fini FPC_LIB_EXIT';
  960. SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename^);
  961. { Call linker }
  962. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  963. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
  964. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  965. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  966. Replace(cmdstr,'$INIT',InitStr);
  967. Replace(cmdstr,'$FINI',FiniStr);
  968. Replace(cmdstr,'$SONAME',SoNameStr);
  969. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  970. { Strip the library ? }
  971. if success and (cs_link_strip in current_settings.globalswitches) then
  972. begin
  973. { only remove non global symbols and debugging info for a library }
  974. Info.DllCmd[2]:='strip --discard-all --strip-debug $EXE';
  975. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  976. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename^));
  977. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  978. end;
  979. { Remove ReponseFile }
  980. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  981. DeleteFile(outputexedir+Info.ResName);
  982. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  983. end;
  984. {*****************************************************************************
  985. Initialize
  986. *****************************************************************************}
  987. initialization
  988. {$ifdef i386}
  989. RegisterExternalLinker(system_i386_linux_info,TLinkerLinux);
  990. RegisterImport(system_i386_linux,timportliblinux);
  991. RegisterExport(system_i386_linux,texportliblinux);
  992. RegisterTarget(system_i386_linux_info);
  993. RegisterExternalLinker(system_x86_6432_linux_info,TLinkerLinux);
  994. RegisterImport(system_x86_6432_linux,timportliblinux);
  995. RegisterExport(system_x86_6432_linux,texportliblinux);
  996. RegisterTarget(system_x86_6432_linux_info);
  997. {$endif i386}
  998. {$ifdef m68k}
  999. RegisterExternalLinker(system_m68k_linux_info,TLinkerLinux);
  1000. RegisterImport(system_m68k_linux,timportliblinux);
  1001. RegisterExport(system_m68k_linux,texportliblinux);
  1002. RegisterTarget(system_m68k_linux_info);
  1003. {$endif m68k}
  1004. {$ifdef powerpc}
  1005. RegisterExternalLinker(system_powerpc_linux_info,TLinkerLinux);
  1006. RegisterImport(system_powerpc_linux,timportliblinux);
  1007. RegisterExport(system_powerpc_linux,texportliblinux);
  1008. RegisterTarget(system_powerpc_linux_info);
  1009. {$endif powerpc}
  1010. {$ifdef powerpc64}
  1011. RegisterExternalLinker(system_powerpc64_linux_info,TLinkerLinux);
  1012. RegisterImport(system_powerpc64_linux,timportliblinux);
  1013. RegisterExport(system_powerpc64_linux,texportliblinux);
  1014. RegisterTarget(system_powerpc64_linux_info);
  1015. {$endif powerpc64}
  1016. {$ifdef alpha}
  1017. RegisterExternalLinker(system_alpha_linux_info,TLinkerLinux);
  1018. RegisterImport(system_alpha_linux,timportliblinux);
  1019. RegisterExport(system_alpha_linux,texportliblinux);
  1020. RegisterTarget(system_alpha_linux_info);
  1021. {$endif alpha}
  1022. {$ifdef x86_64}
  1023. RegisterExternalLinker(system_x86_64_linux_info,TLinkerLinux);
  1024. RegisterImport(system_x86_64_linux,timportliblinux);
  1025. RegisterExport(system_x86_64_linux,texportliblinux);
  1026. RegisterTarget(system_x86_64_linux_info);
  1027. {$endif x86_64}
  1028. {$ifdef SPARC}
  1029. RegisterExternalLinker(system_sparc_linux_info,TLinkerLinux);
  1030. RegisterImport(system_SPARC_linux,timportliblinux);
  1031. RegisterExport(system_SPARC_linux,texportliblinux);
  1032. RegisterTarget(system_SPARC_linux_info);
  1033. {$endif SPARC}
  1034. {$ifdef ARM}
  1035. RegisterExternalLinker(system_arm_linux_info,TLinkerLinux);
  1036. RegisterImport(system_arm_linux,timportliblinux);
  1037. RegisterExport(system_arm_linux,texportliblinux);
  1038. RegisterTarget(system_arm_linux_info);
  1039. {$endif ARM}
  1040. RegisterRes(res_elf_info,TWinLikeResourceFile);
  1041. end.