t_linux.pas 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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,
  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. cscript,
  66. fmodule,
  67. aasmbase,aasmtai,aasmcpu,cpubase,
  68. cgbase,ogbase,
  69. comprsrc,
  70. ogelf,owar,
  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. { some linuxes might not have the lib64 variants (Arch, LFS }
  108. { don't use PathExists checks, as we need to take sysroots and
  109. cross-compiling into account }
  110. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/X11R6/lib',true);
  111. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/X11R6/lib64',true);
  112. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib',true);
  113. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib64',true);
  114. { /lib64 should be the really first, so add it before everything else }
  115. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib',true);
  116. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib64',true);
  117. {$else}
  118. {$ifdef powerpc64}
  119. if target_info.abi<>abi_powerpc_elfv2 then
  120. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/X11R6/lib64',true)
  121. else
  122. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/powerpc64le-linux-gnu;=/usr/X11R6/powerpc64le-linux-gnu',true);
  123. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib',true);
  124. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib64',true);
  125. { /lib64 should be the really first, so add it before everything else }
  126. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib',true);
  127. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib64',true);
  128. {$else powerpc64}
  129. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib;=/usr/lib;=/usr/X11R6/lib',true);
  130. {$endif powerpc64}
  131. {$endif x86_64}
  132. {$ifdef arm}
  133. { some newer Debian have the crt*.o files at uncommon locations,
  134. for other arm flavours, this cannot hurt }
  135. if target_info.abi=abi_eabihf then
  136. begin
  137. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/arm-linux-gnueabihf',true);
  138. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib/arm-linux-gnueabihf',true);
  139. end;
  140. if target_info.abi=abi_eabi then
  141. begin
  142. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/arm-linux-gnueabi',true);
  143. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib/arm-linux-gnueabi',true);
  144. end;
  145. {$endif arm}
  146. {$ifdef x86_64}
  147. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/x86_64-linux-gnu',true);
  148. {$endif x86_64}
  149. {$ifdef i386}
  150. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/i386-linux-gnu',true);
  151. {$endif i386}
  152. {$ifdef aarch64}
  153. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib64',true);
  154. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/aarch64-linux-gnu',true);
  155. {$endif aarch64}
  156. {$ifdef powerpc}
  157. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/powerpc-linux-gnu',true);
  158. {$endif powerpc}
  159. {$ifdef m68k}
  160. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/m68k-linux-gnu',true);
  161. {$endif m68k}
  162. {$ifdef mipsel}
  163. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/mipsel-linux-gnu',true);
  164. {$endif mipsel}
  165. {$ifdef mips}
  166. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/mips-linux-gnu',true);
  167. {$endif mips}
  168. {$ifdef sparc64}
  169. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib/sparc64-linux-gnu',true);
  170. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib/sparc64-linux-gnu',true);
  171. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib64',true);
  172. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib64',true);
  173. {$endif sparc64}
  174. end;
  175. end;
  176. {$ifdef m68k}
  177. const defdynlinker='/lib/ld.so.1';
  178. {$endif m68k}
  179. {$ifdef i386}
  180. const defdynlinker='/lib/ld-linux.so.2';
  181. {$endif}
  182. {$ifdef x86_64}
  183. const defdynlinker='/lib64/ld-linux-x86-64.so.2';
  184. {$endif x86_64}
  185. {$ifdef sparc}
  186. const defdynlinker='/lib/ld-linux.so.2';
  187. {$endif sparc}
  188. {$ifdef powerpc}
  189. const defdynlinker='/lib/ld.so.1';
  190. {$endif powerpc}
  191. {$ifdef powerpc64}
  192. const defdynlinkerv1='/lib64/ld64.so.1';
  193. const defdynlinkerv2='/lib64/ld64.so.2';
  194. var defdynlinker: string;
  195. {$endif powerpc64}
  196. {$ifdef arm}
  197. {$ifdef FPC_ARMHF}
  198. const defdynlinker='/lib/ld-linux-armhf.so.3';
  199. {$else FPC_ARMHF}
  200. {$ifdef FPC_ARMEL}
  201. const defdynlinker='/lib/ld-linux.so.3';
  202. {$else FPC_ARMEL}
  203. const defdynlinker='/lib/ld-linux.so.2';
  204. {$endif FPC_ARMEL}
  205. {$endif FPC_ARMHF}
  206. {$endif arm}
  207. {$ifdef aarch64}
  208. const defdynlinker='/lib/ld-linux-aarch64.so.1';
  209. {$endif aarch64}
  210. {$ifdef mips}
  211. const defdynlinker='/lib/ld.so.1';
  212. {$endif mips}
  213. {$ifdef sparc64}
  214. const defdynlinker='/lib64/ld-linux.so.2';
  215. {$endif sparc64}
  216. procedure SetupDynlinker(out DynamicLinker:string;out libctype:TLibcType);
  217. begin
  218. {$ifdef powerpc64}
  219. if defdynlinker='' then
  220. if target_info.abi=abi_powerpc_sysv then
  221. defdynlinker:=defdynlinkerv1
  222. else
  223. defdynlinker:=defdynlinkerv2;
  224. {$endif powerpc64}
  225. {
  226. Search order:
  227. glibc 2.1+
  228. uclibc
  229. glibc 2.0
  230. If none is found (e.g. when cross compiling) glibc21 is assumed
  231. }
  232. if fileexists(sysrootpath+defdynlinker,false) then
  233. begin
  234. DynamicLinker:=defdynlinker;
  235. {$ifdef i386}
  236. libctype:=glibc21;
  237. {$else i386}
  238. libctype:=glibc2;
  239. {$endif i386}
  240. end
  241. else if fileexists(sysrootpath+'/lib/ld-uClibc.so.0',false) then
  242. begin
  243. DynamicLinker:='/lib/ld-uClibc.so.0';
  244. libctype:=uclibc;
  245. end
  246. {$ifdef i386}
  247. else if FileExists(sysrootpath+'/lib/ld-linux.so.1',false) then
  248. begin
  249. DynamicLinker:='/lib/ld-linux.so.1';
  250. libctype:=glibc2;
  251. end
  252. {$endif i386}
  253. else
  254. begin
  255. { when no dyn. linker is found, we are probably
  256. cross compiling, so use the default dyn. linker }
  257. DynamicLinker:=defdynlinker;
  258. {
  259. the default c startup script is gcrt0.as on all platforms
  260. except i386
  261. }
  262. {$ifdef i386}
  263. libctype:=glibc21;
  264. {$else i386}
  265. libctype:=glibc2;
  266. {$endif i386}
  267. end;
  268. end;
  269. function ModulesLinkToLibc:boolean;
  270. var
  271. hp: tmodule;
  272. begin
  273. { This is called very early, ImportLibraryList is not yet merged into linkothersharedlibs.
  274. The former contains library names qualified with prefix and suffix (coming from
  275. "external 'c' name 'foo' declarations), the latter contains raw names (from "$linklib c"
  276. directives). }
  277. hp:=tmodule(loaded_units.first);
  278. while assigned(hp) do
  279. begin
  280. result:=Assigned(hp.ImportLibraryList.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext));
  281. if result then break;
  282. result:=hp.linkothersharedlibs.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext);
  283. if result then break;
  284. result:=hp.linkothersharedlibs.find('c');
  285. if result then break;
  286. hp:=tmodule(hp.next);
  287. end;
  288. end;
  289. Constructor TLinkerLinux.Create;
  290. begin
  291. Inherited Create;
  292. SetupLibrarySearchPath;
  293. end;
  294. procedure TLinkerLinux.SetDefaultInfo;
  295. {
  296. This will also detect which libc version will be used
  297. }
  298. const
  299. {$ifdef i386} platform_select='-b elf32-i386 -m elf_i386';{$endif}
  300. {$ifdef x86_64} platform_select='-b elf64-x86-64 -m elf_x86_64';{$endif}
  301. {$ifdef powerpc} platform_select='-b elf32-powerpc -m elf32ppclinux';{$endif}
  302. {$ifdef POWERPC64} platform_select='';{$endif}
  303. {$ifdef sparc} platform_select='-b elf32-sparc -m elf32_sparc';{$endif}
  304. {$ifdef sparc64} platform_select='-b elf64-sparc -m elf64_sparc';{$endif}
  305. {$ifdef arm} platform_select='';{$endif} {unknown :( }
  306. {$ifdef aarch64} platform_select='';{$endif} {unknown :( }
  307. {$ifdef m68k} platform_select='';{$endif} {unknown :( }
  308. {$ifdef mips}
  309. {$ifdef mipsel}
  310. platform_select='-EL';
  311. {$else}
  312. platform_select='-EB';
  313. {$endif}
  314. {$endif}
  315. var
  316. platformopt: string;
  317. begin
  318. platformopt:='';
  319. {$ifdef powerpc64}
  320. if (target_info.abi=abi_powerpc_elfv2) and
  321. (target_info.endian=endian_little) then
  322. platformopt:=' -b elf64-powerpcle -m elf64lppc'
  323. else
  324. platformopt:=' -b elf64-powerpc -m elf64ppc';
  325. {$endif powerpc64}
  326. with Info do
  327. begin
  328. ExeCmd[1]:='ld '+platform_select+platformopt+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE';
  329. DllCmd[1]:='ld '+platform_select+platformopt+' $OPT $INIT $FINI $SONAME $MAP -shared $GCSECTIONS -L. -o $EXE';
  330. { when we want to cross-link we need to override default library paths;
  331. when targeting binutils 2.19 or later, we use the "INSERT" command to
  332. augment the default linkerscript, which also requires -T (normally that
  333. option means "completely replace the default linkerscript) }
  334. if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) or
  335. (length(sysrootpath)>0) then
  336. begin
  337. ExeCmd[1]:=ExeCmd[1]+' -T';
  338. DllCmd[1]:=DllCmd[1]+' -T';
  339. end;
  340. ExeCmd[1]:=ExeCmd[1]+' $RES';
  341. DllCmd[1]:=DllCmd[1]+' $RES';
  342. DllCmd[2]:='strip --strip-unneeded $EXE';
  343. ExtDbgCmd[1]:='objcopy --only-keep-debug $EXE $DBG';
  344. ExtDbgCmd[2]:='objcopy "--add-gnu-debuglink=$DBGX" $EXE';
  345. ExtDbgCmd[3]:='strip --strip-unneeded $EXE';
  346. SetupDynlinker(DynamicLinker,libctype);
  347. end;
  348. end;
  349. procedure TLinkerLinux.LoadPredefinedLibraryOrder;
  350. // put your linkorder/linkalias overrides here.
  351. // Note: assumes only called when reordering/aliasing is used.
  352. Begin
  353. if not (cs_link_no_default_lib_order in current_settings.globalswitches) Then
  354. Begin
  355. LinkLibraryOrder.add('gcc','',15);
  356. LinkLibraryOrder.add('c','',100);
  357. LinkLibraryOrder.add('gmon','',120);
  358. LinkLibraryOrder.add('dl','',140);
  359. LinkLibraryOrder.add('pthread','',160);
  360. end;
  361. End;
  362. type
  363. tlibcnames=array [TLibcType] of string[8];
  364. const { libc5 glibc2 glibc21 uclibc }
  365. cprtnames: tlibcnames = ('cprt0', 'cprt0', 'cprt21', 'ucprt0');
  366. csinames: tlibcnames = ('si_c', 'si_c', 'si_c21', 'si_uc');
  367. gprtnames: tlibcnames = ('gprt0', 'gprt0', 'gprt21', 'ugprt0');
  368. gsinames: tlibcnames = ('si_g', 'si_g', 'si_c21g','si_ucg');
  369. defprtnames: array[boolean] of string[8] = ('prt0', 'dllprt0');
  370. defsinames: array[boolean] of string[8] = ('si_prc','si_dll');
  371. { uclibc and glibc21 are not available on x86_64! si_g is also absent. }
  372. Procedure TLinkerLinux.InitSysInitUnitName;
  373. begin
  374. linklibc:=ModulesLinkToLibc;
  375. reorder:=linklibc and ReOrderEntries;
  376. sysinitunit:=defsinames[current_module.islibrary];
  377. prtobj:=defprtnames[current_module.islibrary];
  378. if current_module.islibrary then
  379. exit;
  380. if cs_profile in current_settings.moduleswitches then
  381. begin
  382. prtobj:=gprtnames[libctype];
  383. sysinitunit:=gsinames[libctype];
  384. linklibc:=true;
  385. end
  386. else if linklibc then
  387. begin
  388. prtobj:=cprtnames[libctype];
  389. sysinitunit:=csinames[libctype];
  390. end;
  391. end;
  392. Function TLinkerLinux.WriteResponseFile(isdll:boolean) : Boolean;
  393. Var
  394. linkres : TLinkRes;
  395. i : longint;
  396. HPath : TCmdStrListItem;
  397. s,s1,s2 : TCmdStr;
  398. found1,
  399. found2 : boolean;
  400. linksToSharedLibFiles : boolean;
  401. begin
  402. result:=False;
  403. { set special options for some targets }
  404. if cs_profile in current_settings.moduleswitches then
  405. begin
  406. if not(libctype in [glibc2,glibc21]) then
  407. AddSharedLibrary('gmon');
  408. AddSharedLibrary('c');
  409. end;
  410. { Open link.res file }
  411. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  412. with linkres do
  413. begin
  414. { Write path to search libraries }
  415. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  416. while assigned(HPath) do
  417. begin
  418. Add('SEARCH_DIR("'+HPath.Str+'")');
  419. HPath:=TCmdStrListItem(HPath.Next);
  420. end;
  421. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  422. while assigned(HPath) do
  423. begin
  424. Add('SEARCH_DIR("'+HPath.Str+'")');
  425. HPath:=TCmdStrListItem(HPath.Next);
  426. end;
  427. { force local symbol resolution (i.e., inside the shared }
  428. { library itself) for all non-exorted symbols, otherwise }
  429. { several RTL symbols of FPC-compiled shared libraries }
  430. { will be bound to those of a single shared library or }
  431. { to the main program }
  432. if (isdll) then
  433. begin
  434. add('VERSION');
  435. add('{');
  436. add(' {');
  437. if not texportlibunix(exportlib).exportedsymnames.empty then
  438. begin
  439. add(' global:');
  440. repeat
  441. add(' '+texportlibunix(exportlib).exportedsymnames.getfirst+';');
  442. until texportlibunix(exportlib).exportedsymnames.empty;
  443. end;
  444. add(' local:');
  445. add(' *;');
  446. add(' };');
  447. add('}');
  448. end;
  449. StartSection('INPUT(');
  450. { add objectfiles, start with prt0 always }
  451. if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
  452. AddFileName(maybequoted(FindObjectFile(prtobj,'',false)));
  453. { try to add crti and crtbegin if linking to C }
  454. if linklibc and (libctype<>uclibc) then
  455. begin
  456. { crti.o must come first }
  457. if librarysearchpath.FindFile('crti.o',false,s) then
  458. AddFileName(s)
  459. else
  460. Message1(exec_w_init_file_not_found,'crti.o');
  461. { then the crtbegin* }
  462. if cs_create_pic in current_settings.moduleswitches then
  463. begin
  464. if librarysearchpath.FindFile('crtbeginS.o',false,s) then
  465. AddFileName(s)
  466. else
  467. Message1(exec_w_init_file_not_found,'crtbeginS.o');
  468. end
  469. else
  470. if (cs_link_staticflag in current_settings.globalswitches) then
  471. begin
  472. if librarysearchpath.FindFile('crtbeginT.o',false,s) then
  473. AddFileName(s)
  474. else
  475. Message1(exec_w_init_file_not_found,'crtbeginT.o');
  476. end
  477. else if librarysearchpath.FindFile('crtbegin.o',false,s) then
  478. AddFileName(s)
  479. else
  480. Message1(exec_w_init_file_not_found,'crtbegin.o');
  481. end;
  482. { main objectfiles }
  483. while not ObjectFiles.Empty do
  484. begin
  485. s:=ObjectFiles.GetFirst;
  486. if s<>'' then
  487. AddFileName(maybequoted(s));
  488. end;
  489. EndSection(')');
  490. { Write staticlibraries }
  491. if not StaticLibFiles.Empty then
  492. begin
  493. Add('GROUP(');
  494. While not StaticLibFiles.Empty do
  495. begin
  496. S:=StaticLibFiles.GetFirst;
  497. AddFileName(maybequoted(s))
  498. end;
  499. Add(')');
  500. end;
  501. // we must reorder here because the result could empty sharedlibfiles
  502. if reorder Then
  503. ExpandAndApplyOrder(SharedLibFiles);
  504. // after this point addition of shared libs not allowed.
  505. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  506. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  507. if isdll and not linklibc then
  508. begin
  509. Add('INPUT(');
  510. Add(sysrootpath+info.DynamicLinker);
  511. Add(')');
  512. end;
  513. linksToSharedLibFiles := not SharedLibFiles.Empty;
  514. if not SharedLibFiles.Empty then
  515. begin
  516. if (SharedLibFiles.Count<>1) or
  517. (TCmdStrListItem(SharedLibFiles.First).Str<>'c') or
  518. reorder then
  519. begin
  520. Add('INPUT(');
  521. While not SharedLibFiles.Empty do
  522. begin
  523. S:=SharedLibFiles.GetFirst;
  524. if (s<>'c') or reorder then
  525. begin
  526. i:=Pos(target_info.sharedlibext,S);
  527. if i>0 then
  528. Delete(S,i,255);
  529. Add('-l'+s);
  530. end
  531. else
  532. begin
  533. linklibc:=true;
  534. end;
  535. end;
  536. Add(')');
  537. end
  538. else
  539. linklibc:=true;
  540. if (cs_link_staticflag in current_settings.globalswitches) or
  541. (linklibc and not reorder) then
  542. begin
  543. Add('GROUP(');
  544. { when we have -static for the linker the we also need libgcc }
  545. if (cs_link_staticflag in current_settings.globalswitches) then
  546. begin
  547. Add('-lgcc');
  548. if librarysearchpath.FindFile('libgcc_eh.a',false,s1) then
  549. Add('-lgcc_eh');
  550. end;
  551. { be sure that libc is the last lib }
  552. if linklibc and not reorder then
  553. Add('-lc');
  554. Add(')');
  555. end;
  556. end;
  557. { objects which must be at the end }
  558. if linklibc and (libctype<>uclibc) then
  559. begin
  560. if cs_create_pic in current_settings.moduleswitches then
  561. begin
  562. found1:=librarysearchpath.FindFile('crtendS.o',false,s1);
  563. if not(found1) then
  564. Message1(exec_w_init_file_not_found,'crtendS.o');
  565. end
  566. else
  567. begin
  568. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  569. if not(found1) then
  570. Message1(exec_w_init_file_not_found,'crtend.o');
  571. end;
  572. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  573. if not(found2) then
  574. Message1(exec_w_init_file_not_found,'crtn.o');
  575. if found1 or found2 then
  576. begin
  577. Add('INPUT(');
  578. if found1 then
  579. AddFileName(s1);
  580. if found2 then
  581. AddFileName(s2);
  582. Add(')');
  583. end;
  584. end;
  585. { Entry point. Only needed for executables, as for shared lubraries we use
  586. the -init command line option instead
  587. The "ENTRY" linkerscript command does not have any effect when augmenting
  588. a linker script, so use the command line parameter instead }
  589. if (not isdll) then
  590. if (linksToSharedLibFiles and not linklibc) then
  591. info.ExeCmd[1]:=info.ExeCmd[1]+' -e _dynamic_start'
  592. else
  593. info.ExeCmd[1]:=info.ExeCmd[1]+' -e _start';
  594. add('SECTIONS');
  595. add('{');
  596. if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) then
  597. { we can't use ".data", as that would hide the .data from the
  598. original linker script in combination with the INSERT at the end }
  599. add(' .fpcdata :')
  600. else
  601. add(' .data :');
  602. add(' {');
  603. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  604. add(' }');
  605. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  606. add('}');
  607. { this "INSERT" means "merge into the original linker script, even if
  608. -T is used" }
  609. if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) then
  610. add('INSERT AFTER .data;');
  611. { Write and Close response }
  612. writetodisk;
  613. Free;
  614. end;
  615. WriteResponseFile:=True;
  616. end;
  617. function TLinkerLinux.MakeExecutable:boolean;
  618. var
  619. i : longint;
  620. binstr,
  621. cmdstr,
  622. mapstr : TCmdStr;
  623. success : boolean;
  624. DynLinkStr : string;
  625. GCSectionsStr,
  626. StaticStr,
  627. StripStr : string[40];
  628. begin
  629. if not(cs_link_nolink in current_settings.globalswitches) then
  630. Message1(exec_i_linking,current_module.exefilename);
  631. { Create some replacements }
  632. StaticStr:='';
  633. StripStr:='';
  634. GCSectionsStr:='';
  635. DynLinkStr:='';
  636. mapstr:='';
  637. if (cs_link_staticflag in current_settings.globalswitches) then
  638. StaticStr:='-static';
  639. if (cs_link_strip in current_settings.globalswitches) and
  640. not(cs_link_separate_dbg_file in current_settings.globalswitches) then
  641. StripStr:='-s';
  642. if (cs_link_map in current_settings.globalswitches) then
  643. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  644. if (cs_link_smart in current_settings.globalswitches) and
  645. create_smartlink_sections then
  646. GCSectionsStr:='--gc-sections';
  647. If (cs_profile in current_settings.moduleswitches) or
  648. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  649. begin
  650. DynLinkStr:='--dynamic-linker='+Info.DynamicLinker;
  651. if cshared then
  652. DynLinkStr:=DynLinkStr+' --shared ';
  653. if rlinkpath<>'' then
  654. DynLinkStr:=DynLinkStr+' --rpath-link '+rlinkpath;
  655. End;
  656. { Write used files and libraries }
  657. WriteResponseFile(false);
  658. { Call linker }
  659. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  660. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  661. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  662. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  663. Replace(cmdstr,'$STATIC',StaticStr);
  664. Replace(cmdstr,'$STRIP',StripStr);
  665. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  666. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  667. Replace(cmdstr,'$MAP',mapstr);
  668. { create dynamic symbol table? }
  669. if HasExports then
  670. cmdstr:=cmdstr+' -E';
  671. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  672. { Create external .dbg file with debuginfo }
  673. if success and (cs_link_separate_dbg_file in current_settings.globalswitches) then
  674. begin
  675. for i:=1 to 3 do
  676. begin
  677. SplitBinCmd(Info.ExtDbgCmd[i],binstr,cmdstr);
  678. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  679. Replace(cmdstr,'$DBGFN',maybequoted(extractfilename(current_module.dbgfilename)));
  680. Replace(cmdstr,'$DBGX',current_module.dbgfilename);
  681. Replace(cmdstr,'$DBG',maybequoted(current_module.dbgfilename));
  682. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  683. if not success then
  684. break;
  685. end;
  686. end;
  687. { Remove ReponseFile }
  688. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  689. DeleteFile(outputexedir+Info.ResName);
  690. MakeExecutable:=success; { otherwise a recursive call to link method }
  691. end;
  692. Function TLinkerLinux.MakeSharedLibrary:boolean;
  693. var
  694. InitStr,
  695. FiniStr,
  696. GCSectionsStr,
  697. SoNameStr : string[80];
  698. binstr,
  699. cmdstr,
  700. mapstr : TCmdStr;
  701. success : boolean;
  702. begin
  703. MakeSharedLibrary:=false;
  704. mapstr:='';
  705. if not(cs_link_nolink in current_settings.globalswitches) then
  706. Message1(exec_i_linking,current_module.sharedlibfilename);
  707. if (cs_link_smart in current_settings.globalswitches) and
  708. create_smartlink_sections then
  709. GCSectionsStr:='--gc-sections'
  710. else
  711. GCSectionsStr:='';
  712. { Write used files and libraries }
  713. WriteResponseFile(true);
  714. { Create some replacements }
  715. { note: linux does not use exportlib.initname/fininame due to the custom startup code }
  716. InitStr:='-init FPC_SHARED_LIB_START';
  717. FiniStr:='-fini FPC_LIB_EXIT';
  718. SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename);
  719. if (cs_link_map in current_settings.globalswitches) then
  720. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.sharedlibfilename,'.map'));
  721. { Call linker }
  722. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  723. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  724. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  725. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  726. Replace(cmdstr,'$INIT',InitStr);
  727. Replace(cmdstr,'$FINI',FiniStr);
  728. Replace(cmdstr,'$SONAME',SoNameStr);
  729. Replace(cmdstr,'$MAP',mapstr);
  730. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  731. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  732. { Strip the library ? }
  733. if success and (cs_link_strip in current_settings.globalswitches) then
  734. begin
  735. { only remove non global symbols and debugging info for a library }
  736. Info.DllCmd[2]:='strip --discard-all --strip-debug $EXE';
  737. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  738. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  739. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  740. end;
  741. { Remove ReponseFile }
  742. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  743. DeleteFile(outputexedir+Info.ResName);
  744. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  745. end;
  746. {*****************************************************************************
  747. TINTERNALLINKERLINUX
  748. *****************************************************************************}
  749. constructor TInternalLinkerLinux.Create;
  750. begin
  751. inherited Create;
  752. SetupLibrarySearchPath;
  753. SetupDynlinker(dynlinker,libctype);
  754. CArObjectReader:=TArObjectReader;
  755. CExeOutput:=ElfExeOutputClass;
  756. CObjInput:=TElfObjInput;
  757. end;
  758. procedure TInternalLinkerLinux.InitSysInitUnitName;
  759. begin
  760. linklibc:=ModulesLinkToLibc;
  761. reorder:=linklibc and ReOrderEntries;
  762. sysinitunit:=defsinames[current_module.islibrary];
  763. prtobj:=defprtnames[current_module.islibrary];
  764. if cs_profile in current_settings.moduleswitches then
  765. begin
  766. prtobj:=gprtnames[libctype];
  767. sysinitunit:=gsinames[libctype];
  768. linklibc:=true;
  769. end
  770. else if linklibc then
  771. begin
  772. prtobj:=cprtnames[libctype];
  773. sysinitunit:=csinames[libctype];
  774. end;
  775. end;
  776. const
  777. relsec_prefix:array[boolean] of TCmdStr = ('rel','rela');
  778. procedure TInternalLinkerLinux.DefaultLinkScript;
  779. var
  780. s,s1,s2,relprefix:TCmdStr;
  781. found1,found2:boolean;
  782. linkToSharedLibs:boolean;
  783. procedure AddLibraryStatement(const s:TCmdStr);
  784. var
  785. i:longint;
  786. s1,s2:TCmdStr;
  787. begin
  788. i:=pos(target_info.sharedClibext+'.',s);
  789. if (i>0) then
  790. s1:=target_info.sharedClibprefix+S
  791. else
  792. s1:=target_info.sharedClibprefix+S+target_info.sharedClibext;
  793. { TODO: to be compatible with ld search algorithm, each found file
  794. must be tested for target compatibility, incompatible ones should be skipped. }
  795. { TODO: shall we search library without suffix if one with suffix is not found? }
  796. if (not(cs_link_staticflag in current_settings.globalswitches)) and
  797. FindLibraryFile(s1,'','',s2) then
  798. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(s2))
  799. { TODO: static libraries never have numeric suffix in their names }
  800. else if FindLibraryFile(s,target_info.staticClibprefix,target_info.staticClibext,s2) then
  801. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(s2))
  802. else
  803. Comment(V_Error,'Import library not found for '+S);
  804. end;
  805. begin
  806. if cs_profile in current_settings.moduleswitches then
  807. begin
  808. if not(libctype in [glibc2,glibc21]) then
  809. AddSharedLibrary('gmon');
  810. AddSharedLibrary('c');
  811. end;
  812. TElfExeOutput(exeoutput).interpreter:=stringdup(dynlinker);
  813. { add objectfiles, start with prt0 always }
  814. if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
  815. LinkScript.Concat('READOBJECT '+ maybequoted(FindObjectFile(prtobj,'',false)));
  816. { try to add crti and crtbegin if linking to C }
  817. if linklibc and (libctype<>uclibc) then
  818. begin
  819. { crti.o must come first }
  820. if librarysearchpath.FindFile('crti.o',false,s) then
  821. LinkScript.Concat('READOBJECT '+maybequoted(s));
  822. { then the crtbegin* }
  823. if cs_create_pic in current_settings.moduleswitches then
  824. begin
  825. if librarysearchpath.FindFile('crtbeginS.o',false,s) then
  826. LinkScript.Concat('READOBJECT '+maybequoted(s));
  827. end
  828. else
  829. if (cs_link_staticflag in current_settings.globalswitches) and
  830. librarysearchpath.FindFile('crtbeginT.o',false,s) then
  831. LinkScript.Concat('READOBJECT '+maybequoted(s))
  832. else if librarysearchpath.FindFile('crtbegin.o',false,s) then
  833. LinkScript.Concat('READOBJECT '+maybequoted(s));
  834. end;
  835. ScriptAddSourceStatements(false);
  836. { we must reorder here because the result could empty sharedlibfiles }
  837. if reorder then
  838. ExpandAndApplyOrder(SharedLibFiles);
  839. { See tw9089*.pp: if more than one pure-Pascal shared libs are loaded,
  840. and none have rtld in their DT_NEEDED, then rtld cannot finalize correctly. }
  841. if IsSharedLibrary then
  842. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(sysrootpath+dynlinker));
  843. linkToSharedLibs:=(not SharedLibFiles.Empty);
  844. { Symbols declared as "external 'libx.so'" are added to ImportLibraryList, library
  845. prefix/extension *not* stripped. TImportLibLinux copies these to SharedLibFiles,
  846. stripping prefixes and extensions.
  847. However extension won't be stripped if library is specified with numeric suffix
  848. (like "libpango-1.0.so.0")
  849. Libraries specified with $LINKLIB directive are directly added to SharedLibFiles
  850. and won't be present in ImportLibraryList. }
  851. while not SharedLibFiles.Empty do
  852. begin
  853. S:=SharedLibFiles.GetFirst;
  854. if (S<>'c') or reorder then
  855. AddLibraryStatement(S);
  856. end;
  857. if (cs_link_staticflag in current_settings.globalswitches) or
  858. (linklibc and not reorder) then
  859. begin
  860. LinkScript.Concat('GROUP');
  861. if (cs_link_staticflag in current_settings.globalswitches) then
  862. begin
  863. AddLibraryStatement('gcc');
  864. AddLibraryStatement('gcc_eh');
  865. end;
  866. if linklibc and not reorder then
  867. AddLibraryStatement('c');
  868. LinkScript.Concat('ENDGROUP');
  869. end;
  870. { objects which must be at the end }
  871. if linklibc and (libctype<>uclibc) then
  872. begin
  873. if cs_create_pic in current_settings.moduleswitches then
  874. found1:=librarysearchpath.FindFile('crtendS.o',false,s1)
  875. else
  876. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  877. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  878. if found1 then
  879. LinkScript.Concat('READOBJECT '+maybequoted(s1));
  880. if found2 then
  881. LinkScript.Concat('READOBJECT '+maybequoted(s2));
  882. end;
  883. if (not IsSharedLibrary) then
  884. if (linkToSharedLibs and not linklibc) then
  885. LinkScript.Concat('ENTRYNAME _dynamic_start')
  886. else
  887. LinkScript.Concat('ENTRYNAME _start')
  888. else
  889. LinkScript.Concat('ISSHAREDLIBRARY');
  890. relprefix:=relsec_prefix[ElfTarget.relocs_use_addend];
  891. with LinkScript do
  892. begin
  893. Concat('HEADER');
  894. Concat('EXESECTION .interp');
  895. Concat(' OBJSECTION .interp');
  896. Concat('ENDEXESECTION');
  897. Concat('EXESECTION .note.ABI-tag');
  898. Concat(' OBJSECTION .note.ABI-tag');
  899. Concat('ENDEXESECTION');
  900. Concat('EXESECTION .note.gnu.build-id');
  901. Concat(' OBJSECTION .note.gnu.build-id');
  902. Concat('ENDEXESECTION');
  903. Concat('EXESECTION .hash');
  904. Concat(' OBJSECTION .hash');
  905. Concat('ENDEXESECTION');
  906. Concat('EXESECTION .dynsym');
  907. Concat(' OBJSECTION .dynsym');
  908. Concat('ENDEXESECTION');
  909. Concat('EXESECTION .dynstr');
  910. Concat(' OBJSECTION .dynstr');
  911. Concat('ENDEXESECTION');
  912. Concat('EXESECTION .gnu.version');
  913. Concat(' OBJSECTION .gnu.version');
  914. Concat('ENDEXESECTION');
  915. Concat('EXESECTION .gnu.version_d');
  916. Concat(' OBJSECTION .gnu.version_d');
  917. Concat('ENDEXESECTION');
  918. Concat('EXESECTION .gnu.version_r');
  919. Concat(' OBJSECTION .gnu.version_r');
  920. Concat('ENDEXESECTION');
  921. Concat('EXESECTION .'+relprefix+'.dyn');
  922. Concat(' OBJSECTION .'+relprefix+'.dyn');
  923. Concat('ENDEXESECTION');
  924. Concat('EXESECTION .'+relprefix+'.plt');
  925. Concat(' OBJSECTION .'+relprefix+'.plt');
  926. Concat(' PROVIDE __'+relprefix+'_iplt_start');
  927. Concat(' OBJSECTION .'+relprefix+'.iplt');
  928. Concat(' PROVIDE __'+relprefix+'_iplt_end');
  929. Concat('ENDEXESECTION');
  930. Concat('EXESECTION .init');
  931. Concat(' OBJSECTION .init');
  932. Concat('ENDEXESECTION');
  933. Concat('EXESECTION .plt');
  934. Concat(' OBJSECTION .plt');
  935. Concat('ENDEXESECTION');
  936. Concat('EXESECTION .text');
  937. Concat(' OBJSECTION .text*');
  938. Concat('ENDEXESECTION');
  939. Concat('EXESECTION .fini');
  940. Concat(' OBJSECTION .fini');
  941. Concat(' PROVIDE __etext');
  942. Concat(' PROVIDE _etext');
  943. Concat(' PROVIDE etext');
  944. Concat('ENDEXESECTION');
  945. Concat('EXESECTION .rodata');
  946. Concat(' OBJSECTION .rodata*');
  947. Concat('ENDEXESECTION');
  948. {$ifdef arm}
  949. Concat('EXESECTION .ARM.extab');
  950. Concat(' OBJSECTION .ARM.extab*');
  951. Concat('ENDEXESECTION');
  952. Concat('EXESECTION .ARM.exidx');
  953. Concat(' SYMBOL __exidx_start');
  954. Concat(' OBJSECTION .ARM.exidx*');
  955. Concat(' SYMBOL __exidx_end');
  956. Concat('ENDEXESECTION');
  957. {$endif}
  958. Concat('EXESECTION .eh_frame');
  959. Concat(' OBJSECTION .eh_frame');
  960. Concat('ENDEXESECTION');
  961. Concat('EXESECTION .gcc_except_table');
  962. Concat(' OBJSECTION .gcc_except_table');
  963. Concat(' OBJSECTION .gcc_except_table.*');
  964. Concat('ENDEXESECTION');
  965. Concat('EXESECTION .tdata');
  966. Concat(' OBJSECTION .tdata');
  967. Concat(' OBJSECTION .tdata.*');
  968. Concat('ENDEXESECTION');
  969. Concat('EXESECTION .tbss');
  970. Concat(' OBJSECTION .tbss');
  971. Concat(' OBJSECTION .tbss.*');
  972. Concat('ENDEXESECTION');
  973. Concat('EXESECTION .preinit_array');
  974. Concat(' PROVIDE __preinit_array_start');
  975. Concat(' OBJSECTION .preinit_array');
  976. Concat(' PROVIDE __preinit_array_end');
  977. Concat('ENDEXESECTION');
  978. Concat('EXESECTION .init_array');
  979. Concat(' PROVIDE __init_array_start');
  980. { why the hell .ctors are both here and exesection .ctors below?? }
  981. // KEEP ( *(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
  982. Concat(' OBJSECTION .init_array');
  983. // KEEP ( *(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  984. Concat('PROVIDE __init_array_end');
  985. Concat('ENDEXESECTION');
  986. Concat('EXESECTION .fini_array');
  987. Concat(' PROVIDE __fini_array_start');
  988. // KEEP ( *(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
  989. Concat(' OBJSECTION .fini_array');
  990. // KEEP ( *(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
  991. Concat(' PROVIDE __fini_array_end');
  992. Concat('ENDEXESECTION');
  993. Concat('EXESECTION .ctors');
  994. Concat(' OBJSECTION .ctors*');
  995. Concat('ENDEXESECTION');
  996. Concat('EXESECTION .dtors');
  997. Concat(' OBJSECTION .dtors*');
  998. Concat('ENDEXESECTION');
  999. Concat('EXESECTION .jcr');
  1000. Concat(' OBJSECTION .jcr');
  1001. Concat('ENDEXESECTION');
  1002. Concat('EXESECTION .dynamic');
  1003. Concat(' OBJSECTION .dynamic');
  1004. Concat('ENDEXESECTION');
  1005. {$ifndef mips}
  1006. Concat('EXESECTION .got');
  1007. {$ifdef arm}
  1008. Concat(' OBJSECTION .got.plt');
  1009. {$endif arm}
  1010. Concat(' OBJSECTION .got');
  1011. Concat('ENDEXESECTION');
  1012. {$endif mips}
  1013. {$ifndef arm}
  1014. Concat('EXESECTION .got.plt');
  1015. Concat(' OBJSECTION .got.plt');
  1016. Concat('ENDEXESECTION');
  1017. {$endif arm}
  1018. Concat('EXESECTION .data');
  1019. Concat(' OBJSECTION .data*');
  1020. Concat(' OBJSECTION .fpc*');
  1021. Concat(' OBJSECTION fpc.resources');
  1022. Concat(' PROVIDE _edata');
  1023. Concat(' PROVIDE edata');
  1024. Concat('ENDEXESECTION');
  1025. {$ifdef mips}
  1026. Concat('EXESECTION .got');
  1027. Concat(' OBJSECTION .got');
  1028. Concat('ENDEXESECTION');
  1029. {$endif mips}
  1030. Concat('EXESECTION .bss');
  1031. Concat(' OBJSECTION .dynbss');
  1032. Concat(' OBJSECTION .bss*');
  1033. Concat(' OBJSECTION fpc.reshandles');
  1034. Concat(' PROVIDE end');
  1035. Concat(' SYMBOL _end');
  1036. Concat('ENDEXESECTION');
  1037. ScriptAddGenericSections('.debug_aranges,.debug_pubnames,.debug_info,'+
  1038. '.debug_abbrev,.debug_line,.debug_frame,.debug_str,.debug_loc,'+
  1039. '.debug_macinfo,.debug_weaknames,.debug_funcnames,.debug_typenames,.debug_varnames,.debug_ranges');
  1040. Concat('EXESECTION .stab');
  1041. Concat(' OBJSECTION .stab');
  1042. Concat('ENDEXESECTION');
  1043. Concat('EXESECTION .stabstr');
  1044. Concat(' OBJSECTION .stabstr');
  1045. Concat('ENDEXESECTION');
  1046. end;
  1047. end;
  1048. {*****************************************************************************
  1049. Initialize
  1050. *****************************************************************************}
  1051. initialization
  1052. RegisterLinker(ld_linux,TLinkerLinux);
  1053. RegisterLinker(ld_int_linux,TInternalLinkerLinux);
  1054. {$ifdef i386}
  1055. RegisterImport(system_i386_linux,timportliblinux);
  1056. RegisterExport(system_i386_linux,texportliblinux);
  1057. RegisterTarget(system_i386_linux_info);
  1058. {$endif i386}
  1059. {$ifdef m68k}
  1060. RegisterImport(system_m68k_linux,timportliblinux);
  1061. RegisterExport(system_m68k_linux,texportliblinux);
  1062. RegisterTarget(system_m68k_linux_info);
  1063. {$endif m68k}
  1064. {$ifdef powerpc}
  1065. RegisterImport(system_powerpc_linux,timportliblinux);
  1066. RegisterExport(system_powerpc_linux,texportliblinux);
  1067. RegisterTarget(system_powerpc_linux_info);
  1068. {$endif powerpc}
  1069. {$ifdef powerpc64}
  1070. { default to little endian either when compiling with -dppc64le, or when
  1071. compiling on a little endian ppc64 platform }
  1072. {$if defined(ppc64le) or (defined(cpupowerpc64) and defined(FPC_LITTLE_ENDIAN))}
  1073. system_powerpc64_linux_info.endian:=endian_little;
  1074. system_powerpc64_linux_info.abi:=abi_powerpc_elfv2;
  1075. {$endif}
  1076. RegisterImport(system_powerpc64_linux,timportliblinux);
  1077. RegisterExport(system_powerpc64_linux,texportliblinux);
  1078. RegisterTarget(system_powerpc64_linux_info);
  1079. {$endif powerpc64}
  1080. {$ifdef x86_64}
  1081. RegisterImport(system_x86_64_linux,timportliblinux);
  1082. RegisterExport(system_x86_64_linux,texportliblinux);
  1083. RegisterTarget(system_x86_64_linux_info);
  1084. RegisterTarget(system_x86_6432_linux_info);
  1085. {$endif x86_64}
  1086. {$ifdef SPARC}
  1087. RegisterImport(system_SPARC_linux,timportliblinux);
  1088. RegisterExport(system_SPARC_linux,texportliblinux);
  1089. RegisterTarget(system_SPARC_linux_info);
  1090. {$endif SPARC}
  1091. {$ifdef SPARC64}
  1092. RegisterImport(system_SPARC64_linux,timportliblinux);
  1093. RegisterExport(system_SPARC64_linux,texportliblinux);
  1094. RegisterTarget(system_SPARC64_linux_info);
  1095. {$endif SPARC64}
  1096. {$ifdef ARM}
  1097. RegisterImport(system_arm_linux,timportliblinux);
  1098. RegisterExport(system_arm_linux,texportliblinux);
  1099. RegisterTarget(system_arm_linux_info);
  1100. {$endif ARM}
  1101. {$ifdef aarch64}
  1102. RegisterImport(system_aarch64_linux,timportliblinux);
  1103. RegisterExport(system_aarch64_linux,texportliblinux);
  1104. RegisterTarget(system_aarch64_linux_info);
  1105. {$endif aarch64}
  1106. {$ifdef MIPS}
  1107. {$ifdef MIPSEL}
  1108. RegisterImport(system_mipsel_linux,timportliblinux);
  1109. RegisterExport(system_mipsel_linux,texportliblinux);
  1110. RegisterTarget(system_mipsel_linux_info);
  1111. {$else MIPS}
  1112. RegisterImport(system_mipseb_linux,timportliblinux);
  1113. RegisterExport(system_mipseb_linux,texportliblinux);
  1114. RegisterTarget(system_mipseb_linux_info);
  1115. {$endif MIPSEL}
  1116. {$endif MIPS}
  1117. RegisterRes(res_elf_info,TWinLikeResourceFile);
  1118. end.