t_linux.pas 45 KB

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