t_linux.pas 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584
  1. {
  2. Copyright (c) 1998-2008 by Peter Vreman
  3. This unit implements support import,export,link routines
  4. for the (i386) Linux target
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit t_linux;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. aasmdata,
  23. symsym,symdef,ppu,
  24. import,export,expunix,link;
  25. type
  26. timportliblinux=class(timportlib)
  27. procedure generatelib;override;
  28. end;
  29. texportliblinux=class(texportlibunix)
  30. procedure setfininame(list: TAsmList; const s: string); override;
  31. end;
  32. TLibcType=(libc5,glibc2,glibc21,uclibc);
  33. tlinkerlinux=class(texternallinker)
  34. private
  35. libctype: TLibcType;
  36. prtobj : string[80];
  37. reorder : boolean;
  38. linklibc: boolean;
  39. Function WriteResponseFile(isdll:boolean) : Boolean;
  40. public
  41. constructor Create;override;
  42. procedure SetDefaultInfo;override;
  43. procedure InitSysInitUnitName;override;
  44. function MakeExecutable:boolean;override;
  45. function MakeSharedLibrary:boolean;override;
  46. procedure LoadPredefinedLibraryOrder; override;
  47. end;
  48. TInternalLinkerLinux=class(TInternalLinker)
  49. private
  50. libctype: TLibcType;
  51. reorder: boolean;
  52. linklibc: boolean;
  53. prtobj: string[20];
  54. dynlinker: string[100];
  55. public
  56. constructor Create;override;
  57. procedure DefaultLinkScript;override;
  58. procedure InitSysInitUnitName;override;
  59. end;
  60. implementation
  61. uses
  62. SysUtils,
  63. cutils,cfileutl,cclasses,
  64. verbose,systems,globtype,globals,
  65. symconst,script,
  66. fmodule,
  67. aasmbase,aasmtai,aasmcpu,cpubase,
  68. cgbase,cgobj,cgutils,ogbase,ncgutil,
  69. comprsrc,
  70. ogelf,
  71. rescmn, i_linux
  72. ;
  73. {*****************************************************************************
  74. TIMPORTLIBLINUX
  75. *****************************************************************************}
  76. procedure timportliblinux.generatelib;
  77. var
  78. i : longint;
  79. ImportLibrary : TImportLibrary;
  80. begin
  81. for i:=0 to current_module.ImportLibraryList.Count-1 do
  82. begin
  83. ImportLibrary:=TImportLibrary(current_module.ImportLibraryList[i]);
  84. current_module.linkothersharedlibs.add(ImportLibrary.Name,link_always);
  85. end;
  86. end;
  87. {*****************************************************************************
  88. TEXPORTLIBLINUX
  89. *****************************************************************************}
  90. procedure texportliblinux.setfininame(list: TAsmList; const s: string);
  91. begin
  92. { the problem with not having a .fini section is that a finalization
  93. routine in regular code can get "smart" linked away -> reference it
  94. just like the debug info }
  95. new_section(list,sec_fpc,'links',0);
  96. list.concat(Tai_const.Createname(s,0));
  97. inherited setfininame(list,s);
  98. end;
  99. {*****************************************************************************
  100. TLINKERLINUX
  101. *****************************************************************************}
  102. procedure SetupLibrarySearchPath;
  103. begin
  104. if not Dontlinkstdlibpath Then
  105. begin
  106. {$ifdef x86_64}
  107. LibrarySearchPath.AddPath(sysrootpath,'/lib64;/usr/lib64;/usr/X11R6/lib64',true);
  108. {$else}
  109. {$ifdef powerpc64}
  110. if target_info.abi<>abi_powerpc_elfv2 then
  111. LibrarySearchPath.AddPath(sysrootpath,'/lib64;/usr/lib64;/usr/X11R6/lib64',true)
  112. else
  113. LibrarySearchPath.AddPath(sysrootpath,'/lib64;/usr/lib/powerpc64le-linux-gnu;/usr/X11R6/powerpc64le-linux-gnu',true);
  114. {$else powerpc64}
  115. LibrarySearchPath.AddPath(sysrootpath,'/lib;/usr/lib;/usr/X11R6/lib',true);
  116. {$endif powerpc64}
  117. {$endif x86_64}
  118. {$ifdef arm}
  119. { some newer Debian have the crt*.o files at uncommon locations,
  120. for other arm flavours, this cannot hurt }
  121. {$ifdef FPC_ARMHF}
  122. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/arm-linux-gnueabihf',true);
  123. {$endif FPC_ARMHF}
  124. {$ifdef FPC_ARMEL}
  125. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/arm-linux-gnueabi',true);
  126. {$endif}
  127. {$endif arm}
  128. {$ifdef x86_64}
  129. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/x86_64-linux-gnu',true);
  130. {$endif x86_64}
  131. end;
  132. end;
  133. {$ifdef m68k}
  134. const defdynlinker='/lib/ld.so.1';
  135. {$endif m68k}
  136. {$ifdef i386}
  137. const defdynlinker='/lib/ld-linux.so.2';
  138. {$endif}
  139. {$ifdef x86_64}
  140. const defdynlinker='/lib64/ld-linux-x86-64.so.2';
  141. {$endif x86_64}
  142. {$ifdef sparc}
  143. const defdynlinker='/lib/ld-linux.so.2';
  144. {$endif sparc}
  145. {$ifdef powerpc}
  146. const defdynlinker='/lib/ld.so.1';
  147. {$endif powerpc}
  148. {$ifdef powerpc64}
  149. const defdynlinkerv1='/lib64/ld64.so.1';
  150. const defdynlinkerv2='/lib64/ld64.so.2';
  151. var defdynlinker: string;
  152. {$endif powerpc64}
  153. {$ifdef arm}
  154. {$ifdef FPC_ARMHF}
  155. const defdynlinker='/lib/ld-linux-armhf.so.3';
  156. {$else FPC_ARMHF}
  157. {$ifdef FPC_ARMEL}
  158. const defdynlinker='/lib/ld-linux.so.3';
  159. {$else FPC_ARMEL}
  160. const defdynlinker='/lib/ld-linux.so.2';
  161. {$endif FPC_ARMEL}
  162. {$endif FPC_ARMHF}
  163. {$endif arm}
  164. {$ifdef mips}
  165. const defdynlinker='/lib/ld.so.1';
  166. {$endif mips}
  167. procedure SetupDynlinker(out DynamicLinker:string;out libctype:TLibcType);
  168. begin
  169. {$ifdef powerpc64}
  170. if defdynlinker='' then
  171. if target_info.abi=abi_powerpc_sysv then
  172. defdynlinker:=defdynlinkerv1
  173. else
  174. defdynlinker:=defdynlinkerv2;
  175. {$endif powerpc64}
  176. {
  177. Search order:
  178. glibc 2.1+
  179. uclibc
  180. glibc 2.0
  181. If none is found (e.g. when cross compiling) glibc21 is assumed
  182. }
  183. if fileexists(sysrootpath+defdynlinker,false) then
  184. begin
  185. DynamicLinker:=defdynlinker;
  186. {$ifdef i386}
  187. libctype:=glibc21;
  188. {$else i386}
  189. libctype:=glibc2;
  190. {$endif i386}
  191. end
  192. else if fileexists(sysrootpath+'/lib/ld-uClibc.so.0',false) then
  193. begin
  194. DynamicLinker:='/lib/ld-uClibc.so.0';
  195. libctype:=uclibc;
  196. end
  197. {$ifdef i386}
  198. else if FileExists(sysrootpath+'/lib/ld-linux.so.1',false) then
  199. begin
  200. DynamicLinker:='/lib/ld-linux.so.1';
  201. libctype:=glibc2;
  202. end
  203. {$endif i386}
  204. else
  205. begin
  206. { when no dyn. linker is found, we are probably
  207. cross compiling, so use the default dyn. linker }
  208. DynamicLinker:=defdynlinker;
  209. {
  210. the default c startup script is gcrt0.as on all platforms
  211. except i386
  212. }
  213. {$ifdef i386}
  214. libctype:=glibc21;
  215. {$else i386}
  216. libctype:=glibc2;
  217. {$endif i386}
  218. end;
  219. end;
  220. function ModulesLinkToLibc:boolean;
  221. var
  222. hp: tmodule;
  223. begin
  224. { This is called very early, ImportLibraryList is not yet merged into linkothersharedlibs.
  225. The former contains library names qualified with prefix and suffix (coming from
  226. "external 'c' name 'foo' declarations), the latter contains raw names (from "$linklib c"
  227. directives). }
  228. hp:=tmodule(loaded_units.first);
  229. while assigned(hp) do
  230. begin
  231. result:=Assigned(hp.ImportLibraryList.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext));
  232. if result then break;
  233. result:=hp.linkothersharedlibs.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext);
  234. if result then break;
  235. result:=hp.linkothersharedlibs.find('c');
  236. if result then break;
  237. hp:=tmodule(hp.next);
  238. end;
  239. end;
  240. Constructor TLinkerLinux.Create;
  241. begin
  242. Inherited Create;
  243. SetupLibrarySearchPath;
  244. end;
  245. procedure TLinkerLinux.SetDefaultInfo;
  246. {
  247. This will also detect which libc version will be used
  248. }
  249. const
  250. {$ifdef i386} platform_select='-b elf32-i386 -m elf_i386';{$endif}
  251. {$ifdef x86_64} platform_select='-b elf64-x86-64 -m elf_x86_64';{$endif}
  252. {$ifdef powerpc} platform_select='-b elf32-powerpc -m elf32ppclinux';{$endif}
  253. {$ifdef POWERPC64} platform_select='';{$endif}
  254. {$ifdef sparc} platform_select='-b elf32-sparc -m elf32_sparc';{$endif}
  255. {$ifdef arm} platform_select='';{$endif} {unknown :( }
  256. {$ifdef m68k} platform_select='';{$endif} {unknown :( }
  257. {$ifdef mips}
  258. {$ifdef mipsel}
  259. platform_select='-EL';
  260. {$else}
  261. platform_select='-EB';
  262. {$endif}
  263. {$endif}
  264. var
  265. platformopt: string;
  266. begin
  267. platformopt:='';
  268. {$ifdef powerpc64}
  269. if (target_info.abi=abi_powerpc_elfv2) and
  270. (target_info.endian=endian_little) then
  271. platformopt:=' -b elf64-powerpcle -m elf64lppc'
  272. else
  273. platformopt:=' -b elf64-powerpc -m elf64ppc';
  274. {$endif powerpc64}
  275. with Info do
  276. begin
  277. ExeCmd[1]:='ld '+platform_select+platformopt+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE';
  278. { when we want to cross-link we need to override default library paths }
  279. if length(sysrootpath) > 0 then
  280. ExeCmd[1]:=ExeCmd[1]+' -T';
  281. ExeCmd[1]:=ExeCmd[1]+' $RES';
  282. DllCmd[1]:='ld '+platform_select+' $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES';
  283. DllCmd[2]:='strip --strip-unneeded $EXE';
  284. ExtDbgCmd[1]:='objcopy --only-keep-debug $EXE $DBG';
  285. ExtDbgCmd[2]:='objcopy --add-gnu-debuglink=$DBG $EXE';
  286. ExtDbgCmd[3]:='strip --strip-unneeded $EXE';
  287. SetupDynlinker(DynamicLinker,libctype);
  288. end;
  289. end;
  290. procedure TLinkerLinux.LoadPredefinedLibraryOrder;
  291. // put your linkorder/linkalias overrides here.
  292. // Note: assumes only called when reordering/aliasing is used.
  293. Begin
  294. if not (cs_link_no_default_lib_order in current_settings.globalswitches) Then
  295. Begin
  296. LinkLibraryOrder.add('gcc','',15);
  297. LinkLibraryOrder.add('c','',100);
  298. LinkLibraryOrder.add('gmon','',120);
  299. LinkLibraryOrder.add('dl','',140);
  300. LinkLibraryOrder.add('pthread','',160);
  301. end;
  302. End;
  303. type
  304. tlibcnames=array [TLibcType] of string[8];
  305. const { libc5 glibc2 glibc21 uclibc }
  306. cprtnames: tlibcnames = ('cprt0', 'cprt0', 'cprt21', 'ucprt0');
  307. csinames: tlibcnames = ('si_c', 'si_c', 'si_c21', 'si_uc');
  308. gprtnames: tlibcnames = ('gprt0', 'gprt0', 'gprt21', 'ugprt0');
  309. gsinames: tlibcnames = ('si_g', 'si_g', 'si_c21g','si_ucg');
  310. defprtnames: array[boolean] of string[8] = ('prt0', 'dllprt0');
  311. defsinames: array[boolean] of string[8] = ('si_prc','si_dll');
  312. { uclibc and glibc21 are not available on x86_64! si_g is also absent. }
  313. Procedure TLinkerLinux.InitSysInitUnitName;
  314. begin
  315. linklibc:=ModulesLinkToLibc;
  316. reorder:=linklibc and ReOrderEntries;
  317. sysinitunit:=defsinames[current_module.islibrary];
  318. prtobj:=defprtnames[current_module.islibrary];
  319. if current_module.islibrary then
  320. exit;
  321. if cs_profile in current_settings.moduleswitches then
  322. begin
  323. prtobj:=gprtnames[libctype];
  324. sysinitunit:=gsinames[libctype];
  325. linklibc:=true;
  326. end
  327. else if linklibc then
  328. begin
  329. prtobj:=cprtnames[libctype];
  330. sysinitunit:=csinames[libctype];
  331. end;
  332. end;
  333. Function TLinkerLinux.WriteResponseFile(isdll:boolean) : Boolean;
  334. Var
  335. linkres : TLinkRes;
  336. i : longint;
  337. HPath : TCmdStrListItem;
  338. s,s1,s2 : TCmdStr;
  339. found1,
  340. found2 : boolean;
  341. linksToSharedLibFiles : boolean;
  342. begin
  343. result:=False;
  344. { set special options for some targets }
  345. if cs_profile in current_settings.moduleswitches then
  346. begin
  347. if not(libctype in [glibc2,glibc21]) then
  348. AddSharedLibrary('gmon');
  349. AddSharedLibrary('c');
  350. end;
  351. { Open link.res file }
  352. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  353. with linkres do
  354. begin
  355. { Write path to search libraries }
  356. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  357. while assigned(HPath) do
  358. begin
  359. Add('SEARCH_DIR("'+HPath.Str+'")');
  360. HPath:=TCmdStrListItem(HPath.Next);
  361. end;
  362. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  363. while assigned(HPath) do
  364. begin
  365. Add('SEARCH_DIR("'+HPath.Str+'")');
  366. HPath:=TCmdStrListItem(HPath.Next);
  367. end;
  368. { force local symbol resolution (i.e., inside the shared }
  369. { library itself) for all non-exorted symbols, otherwise }
  370. { several RTL symbols of FPC-compiled shared libraries }
  371. { will be bound to those of a single shared library or }
  372. { to the main program }
  373. if (isdll) then
  374. begin
  375. add('VERSION');
  376. add('{');
  377. add(' {');
  378. if not texportlibunix(exportlib).exportedsymnames.empty then
  379. begin
  380. add(' global:');
  381. repeat
  382. add(' '+texportlibunix(exportlib).exportedsymnames.getfirst+';');
  383. until texportlibunix(exportlib).exportedsymnames.empty;
  384. end;
  385. add(' local:');
  386. add(' *;');
  387. add(' };');
  388. add('}');
  389. end;
  390. StartSection('INPUT(');
  391. { add objectfiles, start with prt0 always }
  392. if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
  393. AddFileName(maybequoted(FindObjectFile(prtobj,'',false)));
  394. { try to add crti and crtbegin if linking to C }
  395. if linklibc and (libctype<>uclibc) then
  396. begin
  397. { crti.o must come first }
  398. if librarysearchpath.FindFile('crti.o',false,s) then
  399. AddFileName(s)
  400. else
  401. Message1(exec_w_init_file_not_found,'crti.o');
  402. { then the crtbegin* }
  403. if cs_create_pic in current_settings.moduleswitches then
  404. begin
  405. if librarysearchpath.FindFile('crtbeginS.o',false,s) then
  406. AddFileName(s)
  407. else
  408. Message1(exec_w_init_file_not_found,'crtbeginS.o');
  409. end
  410. else
  411. if (cs_link_staticflag in current_settings.globalswitches) then
  412. begin
  413. if librarysearchpath.FindFile('crtbeginT.o',false,s) then
  414. AddFileName(s)
  415. else
  416. Message1(exec_w_init_file_not_found,'crtbeginT.o');
  417. end
  418. else if librarysearchpath.FindFile('crtbegin.o',false,s) then
  419. AddFileName(s)
  420. else
  421. Message1(exec_w_init_file_not_found,'crtbegin.o');
  422. end;
  423. { main objectfiles }
  424. while not ObjectFiles.Empty do
  425. begin
  426. s:=ObjectFiles.GetFirst;
  427. if s<>'' then
  428. AddFileName(maybequoted(s));
  429. end;
  430. EndSection(')');
  431. { Write staticlibraries }
  432. if not StaticLibFiles.Empty then
  433. begin
  434. Add('GROUP(');
  435. While not StaticLibFiles.Empty do
  436. begin
  437. S:=StaticLibFiles.GetFirst;
  438. AddFileName(maybequoted(s))
  439. end;
  440. Add(')');
  441. end;
  442. // we must reorder here because the result could empty sharedlibfiles
  443. if reorder Then
  444. ExpandAndApplyOrder(SharedLibFiles);
  445. // after this point addition of shared libs not allowed.
  446. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  447. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  448. if (isdll) then
  449. begin
  450. Add('INPUT(');
  451. Add(info.DynamicLinker);
  452. Add(')');
  453. end;
  454. linksToSharedLibFiles := not SharedLibFiles.Empty;
  455. if not SharedLibFiles.Empty then
  456. begin
  457. if (SharedLibFiles.Count<>1) or
  458. (TCmdStrListItem(SharedLibFiles.First).Str<>'c') or
  459. reorder 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. Add(')');
  478. end
  479. else
  480. linklibc:=true;
  481. if (cs_link_staticflag in current_settings.globalswitches) or
  482. (linklibc and not reorder) then
  483. begin
  484. Add('GROUP(');
  485. { when we have -static for the linker the we also need libgcc }
  486. if (cs_link_staticflag in current_settings.globalswitches) then
  487. begin
  488. Add('-lgcc');
  489. if librarysearchpath.FindFile('libgcc_eh.a',false,s1) then
  490. Add('-lgcc_eh');
  491. end;
  492. { be sure that libc is the last lib }
  493. if linklibc and not reorder then
  494. Add('-lc');
  495. Add(')');
  496. end;
  497. end;
  498. { objects which must be at the end }
  499. if linklibc and (libctype<>uclibc) then
  500. begin
  501. if cs_create_pic in current_settings.moduleswitches then
  502. begin
  503. found1:=librarysearchpath.FindFile('crtendS.o',false,s1);
  504. if not(found1) then
  505. Message1(exec_w_init_file_not_found,'crtendS.o');
  506. end
  507. else
  508. begin
  509. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  510. if not(found1) then
  511. Message1(exec_w_init_file_not_found,'crtend.o');
  512. end;
  513. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  514. if not(found2) then
  515. Message1(exec_w_init_file_not_found,'crtn.o');
  516. if found1 or found2 then
  517. begin
  518. Add('INPUT(');
  519. if found1 then
  520. AddFileName(s1);
  521. if found2 then
  522. AddFileName(s2);
  523. Add(')');
  524. end;
  525. end;
  526. {Entry point. Only needed for executables, set on the linker command line for
  527. shared libraries. }
  528. if (not isdll) then
  529. if (linksToSharedLibFiles and not linklibc) then
  530. add('ENTRY(_dynamic_start)')
  531. else
  532. add('ENTRY(_start)');
  533. {$ifdef x86_64}
  534. {$define LINKERSCRIPT_INCLUDED}
  535. add('SECTIONS');
  536. add('{');
  537. {Read-only sections, merged into text segment:}
  538. if current_module.islibrary then
  539. add(' . = 0 + SIZEOF_HEADERS;')
  540. else
  541. add(' PROVIDE (__executable_start = 0x0400000); . = 0x0400000 + SIZEOF_HEADERS;');
  542. add(' . = 0 + SIZEOF_HEADERS;');
  543. add(' .interp : { *(.interp) }');
  544. add(' .hash : { *(.hash) }');
  545. add(' .dynsym : { *(.dynsym) }');
  546. add(' .dynstr : { *(.dynstr) }');
  547. add(' .gnu.version : { *(.gnu.version) }');
  548. add(' .gnu.version_d : { *(.gnu.version_d) }');
  549. add(' .gnu.version_r : { *(.gnu.version_r) }');
  550. add(' .rel.dyn :');
  551. add(' {');
  552. add(' *(.rel.init)');
  553. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  554. add(' *(.rel.fini)');
  555. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  556. add(' *(.rel.data.rel.ro*)');
  557. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  558. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  559. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  560. add(' *(.rel.got)');
  561. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  562. add(' }');
  563. add(' .rela.dyn :');
  564. add(' {');
  565. add(' *(.rela.init)');
  566. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  567. add(' *(.rela.fini)');
  568. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  569. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  570. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  571. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  572. add(' *(.rela.got)');
  573. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  574. add(' }');
  575. add(' .rel.plt : { *(.rel.plt) }');
  576. add(' .rela.plt : { *(.rela.plt) }');
  577. add(' .init :');
  578. add(' {');
  579. add(' KEEP (*(.init))');
  580. add(' } =0x90909090');
  581. add(' .plt : { *(.plt) }');
  582. add(' .text :');
  583. add(' {');
  584. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  585. add(' KEEP (*(.text.*personality*))');
  586. {.gnu.warning sections are handled specially by elf32.em.}
  587. add(' *(.gnu.warning)');
  588. add(' } =0x90909090');
  589. add(' .fini :');
  590. add(' {');
  591. add(' KEEP (*(.fini))');
  592. add(' } =0x90909090');
  593. add(' PROVIDE (_etext = .);');
  594. add(' .rodata :');
  595. add(' {');
  596. add(' *(.rodata .rodata.* .gnu.linkonce.r.*)');
  597. add(' }');
  598. {Adjust the address for the data segment. We want to adjust up to
  599. the same address within the page on the next page up.}
  600. add(' . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1));');
  601. add(' .dynamic : { *(.dynamic) }');
  602. add(' .got : { *(.got .toc) }');
  603. add(' .got.plt : { *(.got.plt .toc.plt) }');
  604. add(' .data :');
  605. add(' {');
  606. add(' *(.data .data.* .gnu.linkonce.d.*)');
  607. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  608. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  609. add(' }');
  610. add(' PROVIDE (_edata = .);');
  611. add(' PROVIDE (edata = .);');
  612. {$ifdef zsegment_threadvars}
  613. add(' _z = .;');
  614. add(' .threadvar 0 : AT (_z) { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  615. add(' PROVIDE (_threadvar_size = SIZEOF(.threadvar));');
  616. add(' . = _z + SIZEOF (.threadvar);');
  617. {$else}
  618. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  619. {$endif}
  620. add(' __bss_start = .;');
  621. add(' .bss :');
  622. add(' {');
  623. add(' *(.dynbss)');
  624. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  625. add(' *(COMMON)');
  626. {Align here to ensure that the .bss section occupies space up to
  627. _end. Align after .bss to ensure correct alignment even if the
  628. .bss section disappears because there are no input sections.}
  629. add(' . = ALIGN(32 / 8);');
  630. add('}');
  631. add(' . = ALIGN(32 / 8);');
  632. add(' PROVIDE (_end = .);');
  633. add(' PROVIDE (end = .);');
  634. {Stabs debugging sections.}
  635. add(' .stab 0 : { *(.stab) }');
  636. add(' .stabstr 0 : { *(.stabstr) }');
  637. add(' /* DWARF debug sections.');
  638. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  639. add(' of the section so we begin them at 0. */');
  640. add(' /* DWARF 1 */');
  641. add(' .debug 0 : { *(.debug) }');
  642. add(' .line 0 : { *(.line) }');
  643. add(' /* GNU DWARF 1 extensions */');
  644. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  645. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  646. add(' /* DWARF 1.1 and DWARF 2 */');
  647. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  648. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  649. add(' /* DWARF 2 */');
  650. add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  651. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  652. add(' .debug_line 0 : { *(.debug_line) }');
  653. add(' .debug_frame 0 : { *(.debug_frame) }');
  654. add(' .debug_str 0 : { *(.debug_str) }');
  655. add(' .debug_loc 0 : { *(.debug_loc) }');
  656. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  657. add(' /* SGI/MIPS DWARF 2 extensions */');
  658. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  659. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  660. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  661. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  662. add(' /DISCARD/ : { *(.note.GNU-stack) }');
  663. add('}');
  664. {$endif x86_64}
  665. {$ifdef ARM}
  666. if target_info.abi=abi_eabi then
  667. begin
  668. { from GNU ld (CodeSourcery Sourcery G++ Lite 2007q3-53) 2.18.50.20070820 }
  669. add('/* Script for -z combreloc: combine and sort reloc sections */');
  670. add('OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm",');
  671. add(' "elf32-littlearm")');
  672. add('OUTPUT_ARCH(arm)');
  673. add('SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");');
  674. add('SECTIONS');
  675. add('{');
  676. add(' /* Read-only sections, merged into text segment: */');
  677. add(' PROVIDE (__executable_start = 0x8000); . = 0x8000 + SIZEOF_HEADERS;');
  678. add(' .interp : { *(.interp) }');
  679. add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  680. add(' .hash : { *(.hash) }');
  681. add(' .gnu.hash : { *(.gnu.hash) }');
  682. add(' .dynsym : { *(.dynsym) }');
  683. add(' .dynstr : { *(.dynstr) }');
  684. add(' .gnu.version : { *(.gnu.version) }');
  685. add(' .gnu.version_d : { *(.gnu.version_d) }');
  686. add(' .gnu.version_r : { *(.gnu.version_r) }');
  687. add(' .rel.dyn :');
  688. add(' {');
  689. add(' *(.rel.init)');
  690. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  691. add(' *(.rel.fini)');
  692. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  693. add(' *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*)');
  694. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  695. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  696. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  697. add(' *(.rel.ctors)');
  698. add(' *(.rel.dtors)');
  699. add(' *(.rel.got)');
  700. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  701. add(' }');
  702. add(' .rela.dyn :');
  703. add(' {');
  704. add(' *(.rela.init)');
  705. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  706. add(' *(.rela.fini)');
  707. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  708. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  709. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  710. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  711. add(' *(.rela.ctors)');
  712. add(' *(.rela.dtors)');
  713. add(' *(.rela.got)');
  714. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  715. add(' }');
  716. add(' .rel.plt : { *(.rel.plt) }');
  717. add(' .rela.plt : { *(.rela.plt) }');
  718. add(' .init :');
  719. add(' {');
  720. add(' KEEP (*(.init))');
  721. add(' } =0');
  722. add(' .plt : { *(.plt) }');
  723. add(' .text :');
  724. add(' {');
  725. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  726. add(' KEEP (*(.text.*personality*))');
  727. add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  728. add(' *(.gnu.warning)');
  729. add(' *(.glue_7t) *(.glue_7) *(.vfp11_veneer)');
  730. add(' } =0');
  731. add(' .fini :');
  732. add(' {');
  733. add(' KEEP (*(.fini))');
  734. add(' } =0');
  735. add(' PROVIDE (__etext = .);');
  736. add(' PROVIDE (_etext = .);');
  737. add(' PROVIDE (etext = .);');
  738. add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
  739. add(' .rodata1 : { *(.rodata1) }');
  740. add(' .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) }');
  741. add(' __exidx_start = .;');
  742. add(' .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }');
  743. add(' __exidx_end = .;');
  744. add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  745. add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  746. add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }');
  747. add(' /* Adjust the address for the data segment. We want to adjust up to');
  748. add(' the same address within the page on the next page up. */');
  749. add(' . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));');
  750. add(' /* Exception handling */');
  751. add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  752. add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  753. add(' /* Thread Local Storage sections */');
  754. add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  755. add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  756. add(' .preinit_array :');
  757. add(' {');
  758. add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
  759. add(' KEEP (*(.preinit_array))');
  760. add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
  761. add(' }');
  762. add(' .init_array :');
  763. add(' {');
  764. add(' PROVIDE_HIDDEN (__init_array_start = .);');
  765. add(' KEEP (*(SORT(.init_array.*)))');
  766. add(' KEEP (*(.init_array))');
  767. add(' PROVIDE_HIDDEN (__init_array_end = .);');
  768. add(' }');
  769. add(' .fini_array :');
  770. add(' {');
  771. add(' PROVIDE_HIDDEN (__fini_array_start = .);');
  772. add(' KEEP (*(.fini_array))');
  773. add(' KEEP (*(SORT(.fini_array.*)))');
  774. add(' PROVIDE_HIDDEN (__fini_array_end = .);');
  775. add(' }');
  776. add(' .ctors :');
  777. add(' {');
  778. add(' /* gcc uses crtbegin.o to find the start of');
  779. add(' the constructors, so we make sure it is');
  780. add(' first. Because this is a wildcard, it');
  781. add(' doesn''t matter if the user does not');
  782. add(' actually link against crtbegin.o; the');
  783. add(' linker won''t look for a file to match a');
  784. add(' wildcard. The wildcard also means that it');
  785. add(' doesn''t matter which directory crtbegin.o');
  786. add(' is in. */');
  787. add(' KEEP (*crtbegin.o(.ctors))');
  788. add(' KEEP (*crtbegin?.o(.ctors))');
  789. add(' /* We don''t want to include the .ctor section from');
  790. add(' the crtend.o file until after the sorted ctors.');
  791. add(' The .ctor section from the crtend file contains the');
  792. add(' end of ctors marker and it must be last */');
  793. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
  794. add(' KEEP (*(SORT(.ctors.*)))');
  795. add(' KEEP (*(.ctors))');
  796. add(' }');
  797. add(' .dtors :');
  798. add(' {');
  799. add(' KEEP (*crtbegin.o(.dtors))');
  800. add(' KEEP (*crtbegin?.o(.dtors))');
  801. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
  802. add(' KEEP (*(SORT(.dtors.*)))');
  803. add(' KEEP (*(.dtors))');
  804. add(' }');
  805. add(' .jcr : { KEEP (*(.jcr)) }');
  806. add(' .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }');
  807. add(' .dynamic : { *(.dynamic) }');
  808. add(' .got : { *(.got.plt) *(.got) }');
  809. add(' .data :');
  810. add(' {');
  811. add(' __data_start = . ;');
  812. add(' *(.data .data.* .gnu.linkonce.d.*)');
  813. { extra by FPC }
  814. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  815. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  816. add(' SORT(CONSTRUCTORS)');
  817. add(' }');
  818. add(' .data1 : { *(.data1) }');
  819. add(' _edata = .; PROVIDE (edata = .);');
  820. add(' __bss_start = .;');
  821. add(' __bss_start__ = .;');
  822. add(' .bss :');
  823. add(' {');
  824. add(' *(.dynbss)');
  825. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  826. add(' *(COMMON)');
  827. add(' /* Align here to ensure that the .bss section occupies space up to');
  828. add(' _end. Align after .bss to ensure correct alignment even if the');
  829. add(' .bss section disappears because there are no input sections.');
  830. add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
  831. add(' pad the .data section. */');
  832. add(' . = ALIGN(. != 0 ? 32 / 8 : 1);');
  833. add(' }');
  834. add(' _bss_end__ = . ; __bss_end__ = . ;');
  835. add(' . = ALIGN(32 / 8);');
  836. add(' . = ALIGN(32 / 8);');
  837. add(' __end__ = . ;');
  838. add(' _end = .; PROVIDE (end = .);');
  839. add(' /* Stabs debugging sections. */');
  840. add(' .stab 0 : { *(.stab) }');
  841. add(' .stabstr 0 : { *(.stabstr) }');
  842. add(' .stab.excl 0 : { *(.stab.excl) }');
  843. add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  844. add(' .stab.index 0 : { *(.stab.index) }');
  845. add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  846. add(' .comment 0 : { *(.comment) }');
  847. add(' /* DWARF debug sections.');
  848. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  849. add(' of the section so we begin them at 0. */');
  850. add(' /* DWARF 1 */');
  851. add(' .debug 0 : { *(.debug) }');
  852. add(' .line 0 : { *(.line) }');
  853. add(' /* GNU DWARF 1 extensions */');
  854. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  855. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  856. add(' /* DWARF 1.1 and DWARF 2 */');
  857. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  858. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  859. add(' /* DWARF 2 */');
  860. add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  861. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  862. add(' .debug_line 0 : { *(.debug_line) }');
  863. add(' .debug_frame 0 : { *(.debug_frame) }');
  864. add(' .debug_str 0 : { *(.debug_str) }');
  865. add(' .debug_loc 0 : { *(.debug_loc) }');
  866. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  867. add(' /* SGI/MIPS DWARF 2 extensions */');
  868. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  869. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  870. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  871. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  872. add(' /* DWARF 3 */');
  873. add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  874. add(' .debug_ranges 0 : { *(.debug_ranges) }');
  875. add(' .stack 0x80000 :');
  876. add(' {');
  877. add(' _stack = .;');
  878. add(' *(.stack)');
  879. add(' }');
  880. add(' .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }');
  881. add(' .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }');
  882. add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) }');
  883. add('}');
  884. end
  885. else
  886. {$endif ARM}
  887. {$ifndef LINKERSCRIPT_INCLUDED}
  888. begin
  889. {Sections.}
  890. add('SECTIONS');
  891. add('{');
  892. {Read-only sections, merged into text segment:}
  893. add(' PROVIDE (__executable_start = 0x010000); . = 0x010000 + SIZEOF_HEADERS;');
  894. add(' .interp : { *(.interp) }');
  895. add(' .hash : { *(.hash) }');
  896. add(' .dynsym : { *(.dynsym) }');
  897. add(' .dynstr : { *(.dynstr) }');
  898. add(' .gnu.version : { *(.gnu.version) }');
  899. add(' .gnu.version_d : { *(.gnu.version_d) }');
  900. add(' .gnu.version_r : { *(.gnu.version_r) }');
  901. add(' .rel.dyn :');
  902. add(' {');
  903. add(' *(.rel.init)');
  904. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  905. add(' *(.rel.fini)');
  906. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  907. add(' *(.rel.data.rel.ro*)');
  908. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  909. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  910. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  911. add(' *(.rel.got)');
  912. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  913. add(' }');
  914. add(' .rela.dyn :');
  915. add(' {');
  916. add(' *(.rela.init)');
  917. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  918. add(' *(.rela.fini)');
  919. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  920. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  921. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  922. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  923. add(' *(.rela.got)');
  924. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  925. add(' }');
  926. add(' .rel.plt : { *(.rel.plt) }');
  927. add(' .rela.plt : { *(.rela.plt) }');
  928. add(' .init :');
  929. add(' {');
  930. add(' KEEP (*(.init))');
  931. add(' } =0x90909090');
  932. add(' .plt : { *(.plt) }');
  933. add(' .text :');
  934. add(' {');
  935. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  936. add(' KEEP (*(.text.*personality*))');
  937. {.gnu.warning sections are handled specially by elf32.em.}
  938. add(' *(.gnu.warning)');
  939. add(' } =0x90909090');
  940. add(' .fini :');
  941. add(' {');
  942. add(' KEEP (*(.fini))');
  943. add(' } =0x90909090');
  944. add(' PROVIDE (_etext = .);');
  945. add(' .rodata :');
  946. add(' {');
  947. add(' *(.rodata .rodata.* .gnu.linkonce.r.*)');
  948. add(' }');
  949. {Adjust the address for the data segment. We want to adjust up to
  950. the same address within the page on the next page up.}
  951. add(' . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1));');
  952. add(' .dynamic : { *(.dynamic) }');
  953. add(' .got : { *(.got) }');
  954. add(' .got.plt : { *(.got.plt) }');
  955. add(' .data :');
  956. add(' {');
  957. add(' *(.data .data.* .gnu.linkonce.d.*)');
  958. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  959. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  960. add(' }');
  961. add(' PROVIDE (_edata = .);');
  962. add(' PROVIDE (edata = .);');
  963. {$ifdef zsegment_threadvars}
  964. add(' _z = .;');
  965. add(' .threadvar 0 : AT (_z) { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  966. add(' PROVIDE (_threadvar_size = SIZEOF(.threadvar));');
  967. add(' . = _z + SIZEOF (.threadvar);');
  968. {$else}
  969. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  970. {$endif}
  971. add(' __bss_start = .;');
  972. add(' .bss :');
  973. add(' {');
  974. add(' *(.dynbss)');
  975. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  976. add(' *(COMMON)');
  977. {Align here to ensure that the .bss section occupies space up to
  978. _end. Align after .bss to ensure correct alignment even if the
  979. .bss section disappears because there are no input sections.}
  980. add(' . = ALIGN(32 / 8);');
  981. add(' }');
  982. add(' . = ALIGN(32 / 8);');
  983. add(' PROVIDE (_end = .);');
  984. add(' PROVIDE (end = .);');
  985. {Stabs debugging sections.}
  986. add(' .stab 0 : { *(.stab) }');
  987. add(' .stabstr 0 : { *(.stabstr) }');
  988. add('}');
  989. end;
  990. {$endif LINKERSCRIPT_INCLUDED}
  991. { Write and Close response }
  992. writetodisk;
  993. Free;
  994. end;
  995. WriteResponseFile:=True;
  996. end;
  997. function TLinkerLinux.MakeExecutable:boolean;
  998. var
  999. i : longint;
  1000. binstr,
  1001. cmdstr : TCmdStr;
  1002. success : boolean;
  1003. DynLinkStr : string;
  1004. GCSectionsStr,
  1005. StaticStr,
  1006. StripStr : string[40];
  1007. begin
  1008. if not(cs_link_nolink in current_settings.globalswitches) then
  1009. Message1(exec_i_linking,current_module.exefilename);
  1010. { Create some replacements }
  1011. StaticStr:='';
  1012. StripStr:='';
  1013. GCSectionsStr:='';
  1014. DynLinkStr:='';
  1015. if (cs_link_staticflag in current_settings.globalswitches) then
  1016. StaticStr:='-static';
  1017. if (cs_link_strip in current_settings.globalswitches) and
  1018. not(cs_link_separate_dbg_file in current_settings.globalswitches) then
  1019. StripStr:='-s';
  1020. if (cs_link_map in current_settings.globalswitches) then
  1021. StripStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  1022. if (cs_link_smart in current_settings.globalswitches) and
  1023. create_smartlink_sections then
  1024. GCSectionsStr:='--gc-sections';
  1025. If (cs_profile in current_settings.moduleswitches) or
  1026. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  1027. begin
  1028. DynLinkStr:='--dynamic-linker='+Info.DynamicLinker;
  1029. if cshared then
  1030. DynLinkStr:=DynLinkStr+' --shared ';
  1031. if rlinkpath<>'' then
  1032. DynLinkStr:=DynLinkStr+' --rpath-link '+rlinkpath;
  1033. End;
  1034. { Write used files and libraries }
  1035. WriteResponseFile(false);
  1036. { Call linker }
  1037. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1038. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  1039. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1040. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1041. Replace(cmdstr,'$STATIC',StaticStr);
  1042. Replace(cmdstr,'$STRIP',StripStr);
  1043. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1044. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1045. { create dynamic symbol table? }
  1046. if HasExports then
  1047. cmdstr:=cmdstr+' -E';
  1048. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  1049. { Create external .dbg file with debuginfo }
  1050. if success and (cs_link_separate_dbg_file in current_settings.globalswitches) then
  1051. begin
  1052. for i:=1 to 3 do
  1053. begin
  1054. SplitBinCmd(Info.ExtDbgCmd[i],binstr,cmdstr);
  1055. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  1056. Replace(cmdstr,'$DBGFN',maybequoted(extractfilename(current_module.dbgfilename)));
  1057. Replace(cmdstr,'$DBG',maybequoted(current_module.dbgfilename));
  1058. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  1059. if not success then
  1060. break;
  1061. end;
  1062. end;
  1063. { Remove ReponseFile }
  1064. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  1065. DeleteFile(outputexedir+Info.ResName);
  1066. MakeExecutable:=success; { otherwise a recursive call to link method }
  1067. end;
  1068. Function TLinkerLinux.MakeSharedLibrary:boolean;
  1069. var
  1070. InitStr,
  1071. FiniStr,
  1072. SoNameStr : string[80];
  1073. binstr,
  1074. cmdstr : TCmdStr;
  1075. success : boolean;
  1076. begin
  1077. MakeSharedLibrary:=false;
  1078. if not(cs_link_nolink in current_settings.globalswitches) then
  1079. Message1(exec_i_linking,current_module.sharedlibfilename);
  1080. { Write used files and libraries }
  1081. WriteResponseFile(true);
  1082. { Create some replacements }
  1083. { note: linux does not use exportlib.initname/fininame due to the custom startup code }
  1084. InitStr:='-init FPC_SHARED_LIB_START';
  1085. FiniStr:='-fini FPC_LIB_EXIT';
  1086. SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename);
  1087. { Call linker }
  1088. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  1089. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  1090. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1091. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1092. Replace(cmdstr,'$INIT',InitStr);
  1093. Replace(cmdstr,'$FINI',FiniStr);
  1094. Replace(cmdstr,'$SONAME',SoNameStr);
  1095. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  1096. { Strip the library ? }
  1097. if success and (cs_link_strip in current_settings.globalswitches) then
  1098. begin
  1099. { only remove non global symbols and debugging info for a library }
  1100. Info.DllCmd[2]:='strip --discard-all --strip-debug $EXE';
  1101. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  1102. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  1103. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  1104. end;
  1105. { Remove ReponseFile }
  1106. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  1107. DeleteFile(outputexedir+Info.ResName);
  1108. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  1109. end;
  1110. {*****************************************************************************
  1111. TINTERNALLINKERLINUX
  1112. *****************************************************************************}
  1113. constructor TInternalLinkerLinux.Create;
  1114. begin
  1115. inherited Create;
  1116. SetupLibrarySearchPath;
  1117. SetupDynlinker(dynlinker,libctype);
  1118. CExeOutput:=ElfExeOutputClass;
  1119. CObjInput:=TElfObjInput;
  1120. end;
  1121. procedure TInternalLinkerLinux.InitSysInitUnitName;
  1122. begin
  1123. linklibc:=ModulesLinkToLibc;
  1124. reorder:=linklibc and ReOrderEntries;
  1125. sysinitunit:=defsinames[current_module.islibrary];
  1126. prtobj:=defprtnames[current_module.islibrary];
  1127. if cs_profile in current_settings.moduleswitches then
  1128. begin
  1129. prtobj:=gprtnames[libctype];
  1130. sysinitunit:=gsinames[libctype];
  1131. linklibc:=true;
  1132. end
  1133. else if linklibc then
  1134. begin
  1135. prtobj:=cprtnames[libctype];
  1136. sysinitunit:=csinames[libctype];
  1137. end;
  1138. end;
  1139. const
  1140. relsec_prefix:array[boolean] of TCmdStr = ('rel','rela');
  1141. procedure TInternalLinkerLinux.DefaultLinkScript;
  1142. var
  1143. s,s1,s2,relprefix:TCmdStr;
  1144. found1,found2:boolean;
  1145. linkToSharedLibs:boolean;
  1146. procedure AddLibraryStatement(const s:TCmdStr);
  1147. var
  1148. i:longint;
  1149. s1,s2:TCmdStr;
  1150. begin
  1151. i:=pos(target_info.sharedClibext+'.',s);
  1152. if (i>0) then
  1153. s1:=target_info.sharedClibprefix+S
  1154. else
  1155. s1:=target_info.sharedClibprefix+S+target_info.sharedClibext;
  1156. { TODO: to be compatible with ld search algorithm, each found file
  1157. must be tested for target compatibility, incompatible ones should be skipped. }
  1158. { TODO: shall we search library without suffix if one with suffix is not found? }
  1159. if (not(cs_link_staticflag in current_settings.globalswitches)) and
  1160. FindLibraryFile(s1,'','',s2) then
  1161. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(s2))
  1162. { TODO: static libraries never have numeric suffix in their names }
  1163. else if FindLibraryFile(s,target_info.staticClibprefix,target_info.staticClibext,s2) then
  1164. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(s2))
  1165. else
  1166. Comment(V_Error,'Import library not found for '+S);
  1167. end;
  1168. begin
  1169. if cs_profile in current_settings.moduleswitches then
  1170. begin
  1171. if not(libctype in [glibc2,glibc21]) then
  1172. AddSharedLibrary('gmon');
  1173. AddSharedLibrary('c');
  1174. end;
  1175. TElfExeOutput(exeoutput).interpreter:=stringdup(dynlinker);
  1176. { add objectfiles, start with prt0 always }
  1177. if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
  1178. LinkScript.Concat('READOBJECT '+ maybequoted(FindObjectFile(prtobj,'',false)));
  1179. { try to add crti and crtbegin if linking to C }
  1180. if linklibc and (libctype<>uclibc) then
  1181. begin
  1182. { crti.o must come first }
  1183. if librarysearchpath.FindFile('crti.o',false,s) then
  1184. LinkScript.Concat('READOBJECT '+maybequoted(s));
  1185. { then the crtbegin* }
  1186. if cs_create_pic in current_settings.moduleswitches then
  1187. begin
  1188. if librarysearchpath.FindFile('crtbeginS.o',false,s) then
  1189. LinkScript.Concat('READOBJECT '+maybequoted(s));
  1190. end
  1191. else
  1192. if (cs_link_staticflag in current_settings.globalswitches) and
  1193. librarysearchpath.FindFile('crtbeginT.o',false,s) then
  1194. LinkScript.Concat('READOBJECT '+maybequoted(s))
  1195. else if librarysearchpath.FindFile('crtbegin.o',false,s) then
  1196. LinkScript.Concat('READOBJECT '+maybequoted(s));
  1197. end;
  1198. ScriptAddSourceStatements(false);
  1199. { we must reorder here because the result could empty sharedlibfiles }
  1200. if reorder then
  1201. ExpandAndApplyOrder(SharedLibFiles);
  1202. { See tw9089*.pp: if more than one pure-Pascal shared libs are loaded,
  1203. and none have rtld in their DT_NEEDED, then rtld cannot finalize correctly. }
  1204. if IsSharedLibrary then
  1205. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(sysrootpath+dynlinker));
  1206. linkToSharedLibs:=(not SharedLibFiles.Empty);
  1207. { Symbols declared as "external 'libx.so'" are added to ImportLibraryList, library
  1208. prefix/extension *not* stripped. TImportLibLinux copies these to SharedLibFiles,
  1209. stripping prefixes and extensions.
  1210. However extension won't be stripped if library is specified with numeric suffix
  1211. (like "libpango-1.0.so.0")
  1212. Libraries specified with $LINKLIB directive are directly added to SharedLibFiles
  1213. and won't be present in ImportLibraryList. }
  1214. while not SharedLibFiles.Empty do
  1215. begin
  1216. S:=SharedLibFiles.GetFirst;
  1217. if (S<>'c') or reorder then
  1218. AddLibraryStatement(S);
  1219. end;
  1220. if (cs_link_staticflag in current_settings.globalswitches) or
  1221. (linklibc and not reorder) then
  1222. begin
  1223. LinkScript.Concat('GROUP');
  1224. if (cs_link_staticflag in current_settings.globalswitches) then
  1225. begin
  1226. AddLibraryStatement('gcc');
  1227. AddLibraryStatement('gcc_eh');
  1228. end;
  1229. if linklibc and not reorder then
  1230. AddLibraryStatement('c');
  1231. LinkScript.Concat('ENDGROUP');
  1232. end;
  1233. { objects which must be at the end }
  1234. if linklibc and (libctype<>uclibc) then
  1235. begin
  1236. if cs_create_pic in current_settings.moduleswitches then
  1237. found1:=librarysearchpath.FindFile('crtendS.o',false,s1)
  1238. else
  1239. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  1240. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  1241. if found1 then
  1242. LinkScript.Concat('READOBJECT '+maybequoted(s1));
  1243. if found2 then
  1244. LinkScript.Concat('READOBJECT '+maybequoted(s2));
  1245. end;
  1246. if (not IsSharedLibrary) then
  1247. if (linkToSharedLibs and not linklibc) then
  1248. LinkScript.Concat('ENTRYNAME _dynamic_start')
  1249. else
  1250. LinkScript.Concat('ENTRYNAME _start')
  1251. else
  1252. LinkScript.Concat('ISSHAREDLIBRARY');
  1253. relprefix:=relsec_prefix[ElfTarget.relocs_use_addend];
  1254. with LinkScript do
  1255. begin
  1256. Concat('HEADER');
  1257. Concat('EXESECTION .interp');
  1258. Concat(' OBJSECTION .interp');
  1259. Concat('ENDEXESECTION');
  1260. Concat('EXESECTION .note.ABI-tag');
  1261. Concat(' OBJSECTION .note.ABI-tag');
  1262. Concat('ENDEXESECTION');
  1263. Concat('EXESECTION .note.gnu.build-id');
  1264. Concat(' OBJSECTION .note.gnu.build-id');
  1265. Concat('ENDEXESECTION');
  1266. Concat('EXESECTION .hash');
  1267. Concat(' OBJSECTION .hash');
  1268. Concat('ENDEXESECTION');
  1269. Concat('EXESECTION .dynsym');
  1270. Concat(' OBJSECTION .dynsym');
  1271. Concat('ENDEXESECTION');
  1272. Concat('EXESECTION .dynstr');
  1273. Concat(' OBJSECTION .dynstr');
  1274. Concat('ENDEXESECTION');
  1275. Concat('EXESECTION .gnu.version');
  1276. Concat(' OBJSECTION .gnu.version');
  1277. Concat('ENDEXESECTION');
  1278. Concat('EXESECTION .gnu.version_d');
  1279. Concat(' OBJSECTION .gnu.version_d');
  1280. Concat('ENDEXESECTION');
  1281. Concat('EXESECTION .gnu.version_r');
  1282. Concat(' OBJSECTION .gnu.version_r');
  1283. Concat('ENDEXESECTION');
  1284. Concat('EXESECTION .'+relprefix+'.dyn');
  1285. Concat(' OBJSECTION .'+relprefix+'.dyn');
  1286. Concat('ENDEXESECTION');
  1287. Concat('EXESECTION .'+relprefix+'.plt');
  1288. Concat(' OBJSECTION .'+relprefix+'.plt');
  1289. Concat(' PROVIDE __'+relprefix+'_iplt_start');
  1290. Concat(' OBJSECTION .'+relprefix+'.iplt');
  1291. Concat(' PROVIDE __'+relprefix+'_iplt_end');
  1292. Concat('ENDEXESECTION');
  1293. Concat('EXESECTION .init');
  1294. Concat(' OBJSECTION .init');
  1295. Concat('ENDEXESECTION');
  1296. Concat('EXESECTION .plt');
  1297. Concat(' OBJSECTION .plt');
  1298. Concat('ENDEXESECTION');
  1299. Concat('EXESECTION .text');
  1300. Concat(' OBJSECTION .text*');
  1301. Concat('ENDEXESECTION');
  1302. Concat('EXESECTION .fini');
  1303. Concat(' OBJSECTION .fini');
  1304. Concat(' PROVIDE __etext');
  1305. Concat(' PROVIDE _etext');
  1306. Concat(' PROVIDE etext');
  1307. Concat('ENDEXESECTION');
  1308. Concat('EXESECTION .rodata');
  1309. Concat(' OBJSECTION .rodata*');
  1310. Concat('ENDEXESECTION');
  1311. {$ifdef arm}
  1312. Concat('EXESECTION .ARM.extab');
  1313. Concat(' OBJSECTION .ARM.extab*');
  1314. Concat('ENDEXESECTION');
  1315. Concat('EXESECTION .ARM.exidx');
  1316. Concat(' SYMBOL __exidx_start');
  1317. Concat(' OBJSECTION .ARM.exidx*');
  1318. Concat(' SYMBOL __exidx_end');
  1319. Concat('ENDEXESECTION');
  1320. {$endif}
  1321. Concat('EXESECTION .eh_frame');
  1322. Concat(' OBJSECTION .eh_frame');
  1323. Concat('ENDEXESECTION');
  1324. Concat('EXESECTION .gcc_except_table');
  1325. Concat(' OBJSECTION .gcc_except_table');
  1326. Concat(' OBJSECTION .gcc_except_table.*');
  1327. Concat('ENDEXESECTION');
  1328. Concat('EXESECTION .tdata');
  1329. Concat(' OBJSECTION .tdata');
  1330. Concat(' OBJSECTION .tdata.*');
  1331. Concat('ENDEXESECTION');
  1332. Concat('EXESECTION .tbss');
  1333. Concat(' OBJSECTION .tbss');
  1334. Concat(' OBJSECTION .tbss.*');
  1335. Concat('ENDEXESECTION');
  1336. Concat('EXESECTION .preinit_array');
  1337. Concat(' PROVIDE __preinit_array_start');
  1338. Concat(' OBJSECTION .preinit_array');
  1339. Concat(' PROVIDE __preinit_array_end');
  1340. Concat('ENDEXESECTION');
  1341. Concat('EXESECTION .init_array');
  1342. Concat(' PROVIDE __init_array_start');
  1343. { why the hell .ctors are both here and exesection .ctors below?? }
  1344. // KEEP ( *(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
  1345. Concat(' OBJSECTION .init_array');
  1346. // KEEP ( *(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  1347. Concat('PROVIDE __init_array_end');
  1348. Concat('ENDEXESECTION');
  1349. Concat('EXESECTION .fini_array');
  1350. Concat(' PROVIDE __fini_array_start');
  1351. // KEEP ( *(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
  1352. Concat(' OBJSECTION .fini_array');
  1353. // KEEP ( *(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
  1354. Concat(' PROVIDE __fini_array_end');
  1355. Concat('ENDEXESECTION');
  1356. Concat('EXESECTION .ctors');
  1357. Concat(' OBJSECTION .ctors*');
  1358. Concat('ENDEXESECTION');
  1359. Concat('EXESECTION .dtors');
  1360. Concat(' OBJSECTION .dtors*');
  1361. Concat('ENDEXESECTION');
  1362. Concat('EXESECTION .jcr');
  1363. Concat(' OBJSECTION .jcr');
  1364. Concat('ENDEXESECTION');
  1365. Concat('EXESECTION .dynamic');
  1366. Concat(' OBJSECTION .dynamic');
  1367. Concat('ENDEXESECTION');
  1368. {$ifndef mips}
  1369. Concat('EXESECTION .got');
  1370. {$ifdef arm}
  1371. Concat(' OBJSECTION .got.plt');
  1372. {$endif arm}
  1373. Concat(' OBJSECTION .got');
  1374. Concat('ENDEXESECTION');
  1375. {$endif mips}
  1376. {$ifndef arm}
  1377. Concat('EXESECTION .got.plt');
  1378. Concat(' OBJSECTION .got.plt');
  1379. Concat('ENDEXESECTION');
  1380. {$endif arm}
  1381. Concat('EXESECTION .data');
  1382. Concat(' OBJSECTION .data*');
  1383. Concat(' OBJSECTION .fpc*');
  1384. Concat(' OBJSECTION fpc.resources');
  1385. Concat(' PROVIDE _edata');
  1386. Concat(' PROVIDE edata');
  1387. Concat('ENDEXESECTION');
  1388. {$ifdef mips}
  1389. Concat('EXESECTION .got');
  1390. Concat(' OBJSECTION .got');
  1391. Concat('ENDEXESECTION');
  1392. {$endif mips}
  1393. Concat('EXESECTION .bss');
  1394. Concat(' OBJSECTION .dynbss');
  1395. Concat(' OBJSECTION .bss*');
  1396. Concat(' OBJSECTION fpc.reshandles');
  1397. Concat(' PROVIDE end');
  1398. Concat(' SYMBOL _end');
  1399. Concat('ENDEXESECTION');
  1400. ScriptAddGenericSections('.debug_aranges,.debug_pubnames,.debug_info,'+
  1401. '.debug_abbrev,.debug_line,.debug_frame,.debug_str,.debug_loc,'+
  1402. '.debug_macinfo,.debug_weaknames,.debug_funcnames,.debug_typenames,.debug_varnames,.debug_ranges');
  1403. Concat('EXESECTION .stab');
  1404. Concat(' OBJSECTION .stab');
  1405. Concat('ENDEXESECTION');
  1406. Concat('EXESECTION .stabstr');
  1407. Concat(' OBJSECTION .stabstr');
  1408. Concat('ENDEXESECTION');
  1409. end;
  1410. end;
  1411. {*****************************************************************************
  1412. Initialize
  1413. *****************************************************************************}
  1414. initialization
  1415. RegisterLinker(ld_linux,TLinkerLinux);
  1416. RegisterLinker(ld_int_linux,TInternalLinkerLinux);
  1417. {$ifdef i386}
  1418. RegisterImport(system_i386_linux,timportliblinux);
  1419. RegisterExport(system_i386_linux,texportliblinux);
  1420. RegisterTarget(system_i386_linux_info);
  1421. {$endif i386}
  1422. {$ifdef m68k}
  1423. RegisterImport(system_m68k_linux,timportliblinux);
  1424. RegisterExport(system_m68k_linux,texportliblinux);
  1425. RegisterTarget(system_m68k_linux_info);
  1426. {$endif m68k}
  1427. {$ifdef powerpc}
  1428. RegisterImport(system_powerpc_linux,timportliblinux);
  1429. RegisterExport(system_powerpc_linux,texportliblinux);
  1430. RegisterTarget(system_powerpc_linux_info);
  1431. {$endif powerpc}
  1432. {$ifdef powerpc64}
  1433. { default to little endian either when compiling with -dppc64le, or when
  1434. compiling on a little endian ppc64 platform }
  1435. {$if defined(ppc64le) or (defined(cpupowerpc64) and defined(FPC_LITTLE_ENDIAN))}
  1436. system_powerpc64_linux_info.endian:=endian_little;
  1437. system_powerpc64_linux_info.abi:=abi_powerpc_elfv2;
  1438. {$endif}
  1439. RegisterImport(system_powerpc64_linux,timportliblinux);
  1440. RegisterExport(system_powerpc64_linux,texportliblinux);
  1441. RegisterTarget(system_powerpc64_linux_info);
  1442. {$endif powerpc64}
  1443. {$ifdef alpha}
  1444. RegisterImport(system_alpha_linux,timportliblinux);
  1445. RegisterExport(system_alpha_linux,texportliblinux);
  1446. RegisterTarget(system_alpha_linux_info);
  1447. {$endif alpha}
  1448. {$ifdef x86_64}
  1449. RegisterImport(system_x86_64_linux,timportliblinux);
  1450. RegisterExport(system_x86_64_linux,texportliblinux);
  1451. RegisterTarget(system_x86_64_linux_info);
  1452. {$endif x86_64}
  1453. {$ifdef SPARC}
  1454. RegisterImport(system_SPARC_linux,timportliblinux);
  1455. RegisterExport(system_SPARC_linux,texportliblinux);
  1456. RegisterTarget(system_SPARC_linux_info);
  1457. {$endif SPARC}
  1458. {$ifdef ARM}
  1459. RegisterImport(system_arm_linux,timportliblinux);
  1460. RegisterExport(system_arm_linux,texportliblinux);
  1461. RegisterTarget(system_arm_linux_info);
  1462. {$endif ARM}
  1463. {$ifdef MIPS}
  1464. {$ifdef MIPSEL}
  1465. RegisterImport(system_mipsel_linux,timportliblinux);
  1466. RegisterExport(system_mipsel_linux,texportliblinux);
  1467. RegisterTarget(system_mipsel_linux_info);
  1468. {$else MIPS}
  1469. RegisterImport(system_mipseb_linux,timportliblinux);
  1470. RegisterExport(system_mipseb_linux,texportliblinux);
  1471. RegisterTarget(system_mipseb_linux_info);
  1472. {$endif MIPSEL}
  1473. {$endif MIPS}
  1474. RegisterRes(res_elf_info,TWinLikeResourceFile);
  1475. end.