t_linux.pas 42 KB

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