t_linux.pas 43 KB

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