t_linux.pas 43 KB

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