t_linux.pas 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968
  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. if PathExists('/usr/X11R6/lib64',true) then
  109. LibrarySearchPath.AddPath(sysrootpath,'/usr/X11R6/lib64',true)
  110. else if PathExists('/usr/X11R6/lib',true) then
  111. LibrarySearchPath.AddPath(sysrootpath,'/usr/X11R6/lib',true);
  112. if PathExists('/usr/lib64',true) then
  113. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib64',true)
  114. else if PathExists('/usr/lib',true) then
  115. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib',true);
  116. { /lib64 should be the really first, so add it before everything else }
  117. if PathExists('/lib64',true) then
  118. LibrarySearchPath.AddPath(sysrootpath,'/lib64',true)
  119. else if PathExists('/lib',true) then
  120. LibrarySearchPath.AddPath(sysrootpath,'/lib',true);
  121. {$else}
  122. {$ifdef powerpc64}
  123. if target_info.abi<>abi_powerpc_elfv2 then
  124. LibrarySearchPath.AddPath(sysrootpath,'/lib64;/usr/lib64;/usr/X11R6/lib64',true)
  125. else
  126. LibrarySearchPath.AddPath(sysrootpath,'/lib64;/usr/lib/powerpc64le-linux-gnu;/usr/X11R6/powerpc64le-linux-gnu',true);
  127. {$else powerpc64}
  128. LibrarySearchPath.AddPath(sysrootpath,'/lib;/usr/lib;/usr/X11R6/lib',true);
  129. {$endif powerpc64}
  130. {$endif x86_64}
  131. {$ifdef arm}
  132. { some newer Debian have the crt*.o files at uncommon locations,
  133. for other arm flavours, this cannot hurt }
  134. {$ifdef FPC_ARMHF}
  135. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/arm-linux-gnueabihf',true);
  136. {$endif FPC_ARMHF}
  137. {$ifdef FPC_ARMEL}
  138. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/arm-linux-gnueabi',true);
  139. {$endif}
  140. {$endif arm}
  141. {$ifdef x86_64}
  142. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/x86_64-linux-gnu',true);
  143. {$endif x86_64}
  144. {$ifdef i386}
  145. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/i386-linux-gnu',true);
  146. {$endif i386}
  147. {$ifdef aarch64}
  148. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/aarch64-linux-gnu',true);
  149. {$endif aarch64}
  150. {$ifdef powerpc}
  151. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/powerpc-linux-gnu',true);
  152. {$endif powerpc}
  153. {$ifdef m68k}
  154. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/m68k-linux-gnu',true);
  155. {$endif m68k}
  156. {$ifdef mipsel}
  157. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/mipsel-linux-gnu',true);
  158. {$endif mipsel}
  159. {$ifdef mips}
  160. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/mips-linux-gnu',true);
  161. {$endif mips}
  162. {$ifdef sparc64}
  163. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/sparc64-linux-gnu',true);
  164. {$endif sparc64}
  165. {$ifdef riscv32}
  166. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/riscv32-linux-gnu',true);
  167. {$endif riscv32}
  168. {$ifdef riscv64}
  169. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/riscv64-linux-gnu',true);
  170. {$endif riscv64}
  171. end;
  172. end;
  173. {$ifdef m68k}
  174. const defdynlinker='/lib/ld.so.1';
  175. {$endif m68k}
  176. {$ifdef i386}
  177. const defdynlinker='/lib/ld-linux.so.2';
  178. {$endif}
  179. {$ifdef x86_64}
  180. const defdynlinker='/lib64/ld-linux-x86-64.so.2';
  181. {$endif x86_64}
  182. {$ifdef sparc}
  183. const defdynlinker='/lib/ld-linux.so.2';
  184. {$endif sparc}
  185. {$ifdef powerpc}
  186. const defdynlinker='/lib/ld.so.1';
  187. {$endif powerpc}
  188. {$ifdef powerpc64}
  189. const defdynlinkerv1='/lib64/ld64.so.1';
  190. const defdynlinkerv2='/lib64/ld64.so.2';
  191. var defdynlinker: string;
  192. {$endif powerpc64}
  193. {$ifdef arm}
  194. {$ifdef FPC_ARMHF}
  195. const defdynlinker='/lib/ld-linux-armhf.so.3';
  196. {$else FPC_ARMHF}
  197. {$ifdef FPC_ARMEL}
  198. const defdynlinker='/lib/ld-linux.so.3';
  199. {$else FPC_ARMEL}
  200. const defdynlinker='/lib/ld-linux.so.2';
  201. {$endif FPC_ARMEL}
  202. {$endif FPC_ARMHF}
  203. {$endif arm}
  204. {$ifdef aarch64}
  205. const defdynlinker='/lib/ld-linux-aarch64.so.1';
  206. {$endif aarch64}
  207. {$ifdef mips}
  208. const defdynlinker='/lib/ld.so.1';
  209. {$endif mips}
  210. {$ifdef sparc64}
  211. const defdynlinker='/lib64/ld-linux.so.2';
  212. {$endif sparc64}
  213. {$ifdef riscv32}
  214. const defdynlinker='/lib32/ld.so.1';
  215. {$endif riscv32}
  216. {$ifdef riscv64}
  217. const defdynlinker='/lib/ld-linux-riscv64-lp64d.so.1';
  218. {$endif riscv64}
  219. procedure SetupDynlinker(out DynamicLinker:string;out libctype:TLibcType);
  220. begin
  221. {$ifdef powerpc64}
  222. if defdynlinker='' then
  223. if target_info.abi=abi_powerpc_sysv then
  224. defdynlinker:=defdynlinkerv1
  225. else
  226. defdynlinker:=defdynlinkerv2;
  227. {$endif powerpc64}
  228. {
  229. Search order:
  230. glibc 2.1+
  231. uclibc
  232. glibc 2.0
  233. If none is found (e.g. when cross compiling) glibc21 is assumed
  234. }
  235. if fileexists(sysrootpath+defdynlinker,false) then
  236. begin
  237. DynamicLinker:=defdynlinker;
  238. {$ifdef i386}
  239. libctype:=glibc21;
  240. {$else i386}
  241. libctype:=glibc2;
  242. {$endif i386}
  243. end
  244. else if fileexists(sysrootpath+'/lib/ld-uClibc.so.0',false) then
  245. begin
  246. DynamicLinker:='/lib/ld-uClibc.so.0';
  247. libctype:=uclibc;
  248. end
  249. {$ifdef i386}
  250. else if FileExists(sysrootpath+'/lib/ld-linux.so.1',false) then
  251. begin
  252. DynamicLinker:='/lib/ld-linux.so.1';
  253. libctype:=glibc2;
  254. end
  255. {$endif i386}
  256. else
  257. begin
  258. { when no dyn. linker is found, we are probably
  259. cross compiling, so use the default dyn. linker }
  260. DynamicLinker:=defdynlinker;
  261. {
  262. the default c startup script is gcrt0.as on all platforms
  263. except i386
  264. }
  265. {$ifdef i386}
  266. libctype:=glibc21;
  267. {$else i386}
  268. libctype:=glibc2;
  269. {$endif i386}
  270. end;
  271. end;
  272. function ModulesLinkToLibc:boolean;
  273. var
  274. hp: tmodule;
  275. begin
  276. { This is called very early, ImportLibraryList is not yet merged into linkothersharedlibs.
  277. The former contains library names qualified with prefix and suffix (coming from
  278. "external 'c' name 'foo' declarations), the latter contains raw names (from "$linklib c"
  279. directives). }
  280. hp:=tmodule(loaded_units.first);
  281. while assigned(hp) do
  282. begin
  283. result:=Assigned(hp.ImportLibraryList.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext));
  284. if result then break;
  285. result:=hp.linkothersharedlibs.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext);
  286. if result then break;
  287. result:=hp.linkothersharedlibs.find('c');
  288. if result then break;
  289. hp:=tmodule(hp.next);
  290. end;
  291. end;
  292. Constructor TLinkerLinux.Create;
  293. begin
  294. Inherited Create;
  295. SetupLibrarySearchPath;
  296. end;
  297. procedure TLinkerLinux.SetDefaultInfo;
  298. {
  299. This will also detect which libc version will be used
  300. }
  301. const
  302. {$ifdef i386} platform_select='-b elf32-i386 -m elf_i386';{$endif}
  303. {$ifdef x86_64} platform_select='-b elf64-x86-64 -m elf_x86_64';{$endif}
  304. {$ifdef powerpc} platform_select='-b elf32-powerpc -m elf32ppclinux';{$endif}
  305. {$ifdef POWERPC64} platform_select='';{$endif}
  306. {$ifdef sparc} platform_select='-b elf32-sparc -m elf32_sparc';{$endif}
  307. {$ifdef sparc64} platform_select='-b elf64-sparc -m elf64_sparc';{$endif}
  308. {$ifdef arm} platform_select='';{$endif} {unknown :( }
  309. {$ifdef aarch64} platform_select='';{$endif} {unknown :( }
  310. {$ifdef m68k} platform_select='';{$endif} {unknown :( }
  311. {$ifdef mips}
  312. {$ifdef mipsel}
  313. platform_select='-EL';
  314. {$else}
  315. platform_select='-EB';
  316. {$endif}
  317. {$endif}
  318. {$ifdef riscv32} platform_select='';{$endif} {unknown :( }
  319. {$ifdef riscv64} platform_select='';{$endif} {unknown :( }
  320. var
  321. platformopt: string;
  322. begin
  323. platformopt:='';
  324. {$ifdef powerpc64}
  325. if (target_info.abi=abi_powerpc_elfv2) and
  326. (target_info.endian=endian_little) then
  327. platformopt:=' -b elf64-powerpcle -m elf64lppc'
  328. else
  329. platformopt:=' -b elf64-powerpc -m elf64ppc';
  330. {$endif powerpc64}
  331. {$ifdef arm}
  332. platformopt:=' -z noexecstack';
  333. {$endif arm}
  334. with Info do
  335. begin
  336. ExeCmd[1]:='ld '+platform_select+platformopt+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP $LTO -L. -o $EXE';
  337. DllCmd[1]:='ld '+platform_select+' $OPT $INIT $FINI $SONAME $MAP $LTO -shared $GCSECTIONS -L. -o $EXE';
  338. { when we want to cross-link we need to override default library paths;
  339. when targeting binutils 2.19 or later, we use the "INSERT" command to
  340. augment the default linkerscript, which also requires -T (normally that
  341. option means "completely replace the default linkerscript) }
  342. if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) or
  343. (length(sysrootpath)>0) then
  344. begin
  345. ExeCmd[1]:=ExeCmd[1]+' -T';
  346. DllCmd[1]:=DllCmd[1]+' -T';
  347. end;
  348. ExeCmd[1]:=ExeCmd[1]+' $RES';
  349. DllCmd[1]:=DllCmd[1]+' $RES';
  350. DllCmd[2]:='strip --strip-unneeded $EXE';
  351. ExtDbgCmd[1]:='objcopy --only-keep-debug $EXE $DBG';
  352. ExtDbgCmd[2]:='objcopy "--add-gnu-debuglink=$DBGX" $EXE';
  353. ExtDbgCmd[3]:='strip --strip-unneeded $EXE';
  354. SetupDynlinker(DynamicLinker,libctype);
  355. end;
  356. end;
  357. procedure TLinkerLinux.LoadPredefinedLibraryOrder;
  358. // put your linkorder/linkalias overrides here.
  359. // Note: assumes only called when reordering/aliasing is used.
  360. Begin
  361. if not (cs_link_no_default_lib_order in current_settings.globalswitches) Then
  362. Begin
  363. LinkLibraryOrder.add('gcc','',15);
  364. LinkLibraryOrder.add('c','',100);
  365. LinkLibraryOrder.add('gmon','',120);
  366. LinkLibraryOrder.add('dl','',140);
  367. LinkLibraryOrder.add('pthread','',160);
  368. end;
  369. End;
  370. type
  371. tlibcnames=array [TLibcType] of string[8];
  372. const { libc5 glibc2 glibc21 uclibc }
  373. cprtnames: tlibcnames = ('cprt0', 'cprt0', 'cprt21', 'ucprt0');
  374. csinames: tlibcnames = ('si_c', 'si_c', 'si_c21', 'si_uc');
  375. gprtnames: tlibcnames = ('gprt0', 'gprt0', 'gprt21', 'ugprt0');
  376. gsinames: tlibcnames = ('si_g', 'si_g', 'si_c21g','si_ucg');
  377. defprtnames: array[boolean] of string[8] = ('prt0', 'dllprt0');
  378. defsinames: array[boolean] of string[8] = ('si_prc','si_dll');
  379. { uclibc and glibc21 are not available on x86_64! si_g is also absent. }
  380. Procedure TLinkerLinux.InitSysInitUnitName;
  381. begin
  382. linklibc:=ModulesLinkToLibc;
  383. reorder:=linklibc and ReOrderEntries;
  384. sysinitunit:=defsinames[current_module.islibrary];
  385. prtobj:=defprtnames[current_module.islibrary];
  386. if current_module.islibrary then
  387. exit;
  388. if cs_profile in current_settings.moduleswitches then
  389. begin
  390. prtobj:=gprtnames[libctype];
  391. sysinitunit:=gsinames[libctype];
  392. linklibc:=true;
  393. end
  394. else if linklibc then
  395. begin
  396. prtobj:=cprtnames[libctype];
  397. sysinitunit:=csinames[libctype];
  398. end;
  399. end;
  400. Function TLinkerLinux.WriteResponseFile(isdll:boolean) : Boolean;
  401. Var
  402. linkres : TLinkRes;
  403. i : longint;
  404. HPath : TCmdStrListItem;
  405. s,s1,s2 : TCmdStr;
  406. found1,
  407. found2 : boolean;
  408. linksToSharedLibFiles : boolean;
  409. begin
  410. result:=False;
  411. { set special options for some targets }
  412. if cs_profile in current_settings.moduleswitches then
  413. begin
  414. if not(libctype in [glibc2,glibc21]) then
  415. AddSharedLibrary('gmon');
  416. AddSharedLibrary('c');
  417. end;
  418. { Open link.res file }
  419. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  420. with linkres do
  421. begin
  422. { Write path to search libraries }
  423. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  424. while assigned(HPath) do
  425. begin
  426. Add('SEARCH_DIR("'+HPath.Str+'")');
  427. HPath:=TCmdStrListItem(HPath.Next);
  428. end;
  429. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  430. while assigned(HPath) do
  431. begin
  432. Add('SEARCH_DIR("'+HPath.Str+'")');
  433. HPath:=TCmdStrListItem(HPath.Next);
  434. end;
  435. { force local symbol resolution (i.e., inside the shared }
  436. { library itself) for all non-exorted symbols, otherwise }
  437. { several RTL symbols of FPC-compiled shared libraries }
  438. { will be bound to those of a single shared library or }
  439. { to the main program }
  440. if (isdll) then
  441. begin
  442. add('VERSION');
  443. add('{');
  444. add(' {');
  445. if not texportlibunix(exportlib).exportedsymnames.empty then
  446. begin
  447. add(' global:');
  448. repeat
  449. add(' '+texportlibunix(exportlib).exportedsymnames.getfirst+';');
  450. until texportlibunix(exportlib).exportedsymnames.empty;
  451. end;
  452. add(' local:');
  453. add(' *;');
  454. add(' };');
  455. add('}');
  456. end;
  457. StartSection('INPUT(');
  458. { add objectfiles, start with prt0 always }
  459. if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
  460. AddFileName(maybequoted(FindObjectFile(prtobj,'',false)));
  461. { try to add crti and crtbegin if linking to C }
  462. if linklibc and (libctype<>uclibc) then
  463. begin
  464. { crti.o must come first }
  465. if librarysearchpath.FindFile('crti.o',false,s) then
  466. AddFileName(s)
  467. else
  468. Message1(exec_w_init_file_not_found,'crti.o');
  469. { then the crtbegin* }
  470. if cs_create_pic in current_settings.moduleswitches then
  471. begin
  472. if librarysearchpath.FindFile('crtbeginS.o',false,s) then
  473. AddFileName(s)
  474. else
  475. Message1(exec_w_init_file_not_found,'crtbeginS.o');
  476. end
  477. else
  478. if (cs_link_staticflag in current_settings.globalswitches) then
  479. begin
  480. if librarysearchpath.FindFile('crtbeginT.o',false,s) then
  481. AddFileName(s)
  482. else
  483. Message1(exec_w_init_file_not_found,'crtbeginT.o');
  484. end
  485. else if librarysearchpath.FindFile('crtbegin.o',false,s) then
  486. AddFileName(s)
  487. else
  488. Message1(exec_w_init_file_not_found,'crtbegin.o');
  489. end;
  490. { main objectfiles }
  491. while not ObjectFiles.Empty do
  492. begin
  493. s:=ObjectFiles.GetFirst;
  494. if s<>'' then
  495. AddFileName(maybequoted(s));
  496. end;
  497. EndSection(')');
  498. { Write staticlibraries }
  499. if not StaticLibFiles.Empty then
  500. begin
  501. Add('GROUP(');
  502. While not StaticLibFiles.Empty do
  503. begin
  504. S:=StaticLibFiles.GetFirst;
  505. AddFileName(maybequoted(s))
  506. end;
  507. Add(')');
  508. end;
  509. // we must reorder here because the result could empty sharedlibfiles
  510. if reorder Then
  511. ExpandAndApplyOrder(SharedLibFiles);
  512. // after this point addition of shared libs not allowed.
  513. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  514. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  515. if (isdll) then
  516. begin
  517. Add('INPUT(');
  518. Add(sysrootpath+info.DynamicLinker);
  519. Add(')');
  520. end;
  521. linksToSharedLibFiles := not SharedLibFiles.Empty;
  522. if not SharedLibFiles.Empty then
  523. begin
  524. if (SharedLibFiles.Count<>1) or
  525. (TCmdStrListItem(SharedLibFiles.First).Str<>'c') or
  526. reorder then
  527. begin
  528. Add('INPUT(');
  529. While not SharedLibFiles.Empty do
  530. begin
  531. S:=SharedLibFiles.GetFirst;
  532. if (s<>'c') or reorder then
  533. begin
  534. i:=Pos(target_info.sharedlibext,S);
  535. if i>0 then
  536. Delete(S,i,255);
  537. Add('-l'+s);
  538. end
  539. else
  540. begin
  541. linklibc:=true;
  542. end;
  543. end;
  544. Add(')');
  545. end
  546. else
  547. linklibc:=true;
  548. if (cs_link_staticflag in current_settings.globalswitches) or
  549. (linklibc and not reorder) then
  550. begin
  551. Add('GROUP(');
  552. { when we have -static for the linker the we also need libgcc }
  553. if (cs_link_staticflag in current_settings.globalswitches) then
  554. begin
  555. Add('-lgcc');
  556. if librarysearchpath.FindFile('libgcc_eh.a',false,s1) then
  557. Add('-lgcc_eh');
  558. end;
  559. { be sure that libc is the last lib }
  560. if linklibc and not reorder then
  561. Add('-lc');
  562. Add(')');
  563. end;
  564. end;
  565. { objects which must be at the end }
  566. if linklibc and (libctype<>uclibc) then
  567. begin
  568. if cs_create_pic in current_settings.moduleswitches then
  569. begin
  570. found1:=librarysearchpath.FindFile('crtendS.o',false,s1);
  571. if not(found1) then
  572. Message1(exec_w_init_file_not_found,'crtendS.o');
  573. end
  574. else
  575. begin
  576. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  577. if not(found1) then
  578. Message1(exec_w_init_file_not_found,'crtend.o');
  579. end;
  580. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  581. if not(found2) then
  582. Message1(exec_w_init_file_not_found,'crtn.o');
  583. if found1 or found2 then
  584. begin
  585. Add('INPUT(');
  586. if found1 then
  587. AddFileName(s1);
  588. if found2 then
  589. AddFileName(s2);
  590. Add(')');
  591. end;
  592. end;
  593. { Entry point. Only needed for executables, as for shared lubraries we use
  594. the -init command line option instead
  595. The "ENTRY" linkerscript command does not have any effect when augmenting
  596. a linker script, so use the command line parameter instead }
  597. if (not isdll) then
  598. if (linksToSharedLibFiles and not linklibc) then
  599. info.ExeCmd[1]:=info.ExeCmd[1]+' -e _dynamic_start'
  600. else
  601. info.ExeCmd[1]:=info.ExeCmd[1]+' -e _start';
  602. { If we are using the default sysroot, use the default linker script and
  603. just augment it with the FPC-specific parts.
  604. }
  605. if sysrootpath='' then
  606. begin
  607. add('SECTIONS');
  608. add('{');
  609. if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) then
  610. { we can't use ".data", as that would hide the .data from the
  611. original linker script in combination with the INSERT at the end }
  612. add(' .fpcdata :')
  613. else
  614. add(' .data :');
  615. add(' {');
  616. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  617. add(' }');
  618. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  619. add('}');
  620. { this "INSERT" means "merge into the original linker script, even if
  621. -T is used" }
  622. if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) then
  623. add('INSERT AFTER .data;');
  624. end
  625. else
  626. begin
  627. {$ifdef x86_64}
  628. {$define LINKERSCRIPT_INCLUDED}
  629. add('SECTIONS');
  630. add('{');
  631. {Read-only sections, merged into text segment:}
  632. if current_module.islibrary then
  633. add(' . = 0 + SIZEOF_HEADERS;')
  634. else
  635. add(' PROVIDE (__executable_start = 0x0400000); . = 0x0400000 + SIZEOF_HEADERS;');
  636. add(' . = 0 + SIZEOF_HEADERS;');
  637. add(' .interp : { *(.interp) }');
  638. add(' .hash : { *(.hash) }');
  639. add(' .dynsym : { *(.dynsym) }');
  640. add(' .dynstr : { *(.dynstr) }');
  641. add(' .gnu.version : { *(.gnu.version) }');
  642. add(' .gnu.version_d : { *(.gnu.version_d) }');
  643. add(' .gnu.version_r : { *(.gnu.version_r) }');
  644. add(' .rel.dyn :');
  645. add(' {');
  646. add(' *(.rel.init)');
  647. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  648. add(' *(.rel.fini)');
  649. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  650. add(' *(.rel.data.rel.ro*)');
  651. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  652. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  653. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  654. add(' *(.rel.got)');
  655. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  656. add(' }');
  657. add(' .rela.dyn :');
  658. add(' {');
  659. add(' *(.rela.init)');
  660. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  661. add(' *(.rela.fini)');
  662. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  663. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  664. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  665. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  666. add(' *(.rela.got)');
  667. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  668. add(' }');
  669. add(' .rel.plt : { *(.rel.plt) }');
  670. add(' .rela.plt : { *(.rela.plt) }');
  671. add(' .init :');
  672. add(' {');
  673. add(' KEEP (*(.init))');
  674. add(' } =0x90909090');
  675. add(' .plt : { *(.plt) }');
  676. add(' .text :');
  677. add(' {');
  678. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  679. add(' KEEP (*(.text.*personality*))');
  680. {.gnu.warning sections are handled specially by elf32.em.}
  681. add(' *(.gnu.warning)');
  682. add(' } =0x90909090');
  683. add(' .fini :');
  684. add(' {');
  685. add(' KEEP (*(.fini))');
  686. add(' } =0x90909090');
  687. add(' PROVIDE (_etext = .);');
  688. add(' .rodata :');
  689. add(' {');
  690. add(' *(.rodata .rodata.* .gnu.linkonce.r.*)');
  691. add(' }');
  692. {Adjust the address for the data segment. We want to adjust up to
  693. the same address within the page on the next page up.}
  694. add(' . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1));');
  695. add(' .dynamic : { *(.dynamic) }');
  696. add(' .got : { *(.got .toc) }');
  697. add(' .got.plt : { *(.got.plt .toc.plt) }');
  698. add(' .data :');
  699. add(' {');
  700. add(' *(.data .data.* .gnu.linkonce.d.*)');
  701. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  702. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  703. add(' }');
  704. add(' PROVIDE (_edata = .);');
  705. add(' PROVIDE (edata = .);');
  706. {$ifdef zsegment_threadvars}
  707. add(' _z = .;');
  708. add(' .threadvar 0 : AT (_z) { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  709. add(' PROVIDE (_threadvar_size = SIZEOF(.threadvar));');
  710. add(' . = _z + SIZEOF (.threadvar);');
  711. {$else}
  712. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  713. {$endif}
  714. add(' __bss_start = .;');
  715. add(' .bss :');
  716. add(' {');
  717. add(' *(.dynbss)');
  718. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  719. add(' *(COMMON)');
  720. {Align here to ensure that the .bss section occupies space up to
  721. _end. Align after .bss to ensure correct alignment even if the
  722. .bss section disappears because there are no input sections.}
  723. add(' . = ALIGN(32 / 8);');
  724. add('}');
  725. add(' . = ALIGN(32 / 8);');
  726. add(' PROVIDE (_end = .);');
  727. add(' PROVIDE (end = .);');
  728. {Stabs debugging sections.}
  729. add(' .stab 0 : { *(.stab) }');
  730. add(' .stabstr 0 : { *(.stabstr) }');
  731. add(' /* DWARF debug sections.');
  732. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  733. add(' of the section so we begin them at 0. */');
  734. add(' /* DWARF 1 */');
  735. add(' .debug 0 : { *(.debug) }');
  736. add(' .line 0 : { *(.line) }');
  737. add(' /* GNU DWARF 1 extensions */');
  738. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  739. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  740. add(' /* DWARF 1.1 and DWARF 2 */');
  741. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  742. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  743. add(' /* DWARF 2 */');
  744. add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  745. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  746. add(' .debug_line 0 : { *(.debug_line) }');
  747. add(' .debug_frame 0 : { *(.debug_frame) }');
  748. add(' .debug_str 0 : { *(.debug_str) }');
  749. add(' .debug_loc 0 : { *(.debug_loc) }');
  750. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  751. add(' /* SGI/MIPS DWARF 2 extensions */');
  752. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  753. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  754. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  755. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  756. add(' /DISCARD/ : { *(.note.GNU-stack) }');
  757. add('}');
  758. {$endif x86_64}
  759. {$ifdef AArch64}
  760. {$define LINKERSCRIPT_INCLUDED}
  761. { Complete linker script for aarch64-linux: }
  762. add('SECTIONS');
  763. add('{');
  764. add(' /* Read-only sections, merged into text segment: */');
  765. add(' PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;');
  766. add(' .interp : { *(.interp) }');
  767. add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  768. add(' .hash : { *(.hash) }');
  769. add(' .gnu.hash : { *(.gnu.hash) }');
  770. add(' .dynsym : { *(.dynsym) }');
  771. add(' .dynstr : { *(.dynstr) }');
  772. add(' .gnu.version : { *(.gnu.version) }');
  773. add(' .gnu.version_d : { *(.gnu.version_d) }');
  774. add(' .gnu.version_r : { *(.gnu.version_r) }');
  775. add(' .rela.dyn :');
  776. add(' {');
  777. add(' *(.rela.init)');
  778. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  779. add(' *(.rela.fini)');
  780. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  781. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  782. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  783. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  784. add(' *(.rela.ctors)');
  785. add(' *(.rela.dtors)');
  786. add(' *(.rela.got)');
  787. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  788. add(' *(.rela.ifunc)');
  789. add(' }');
  790. add(' .rela.plt :');
  791. add(' {');
  792. add(' *(.rela.plt)');
  793. add(' PROVIDE_HIDDEN (__rela_iplt_start = .);');
  794. add(' *(.rela.iplt)');
  795. add(' PROVIDE_HIDDEN (__rela_iplt_end = .);');
  796. add(' }');
  797. add(' .init :');
  798. add(' {');
  799. add(' KEEP (*(SORT_NONE(.init)))');
  800. add(' } =0');
  801. add(' .plt : ALIGN(16) { *(.plt) *(.iplt) }');
  802. add(' .text :');
  803. add(' {');
  804. add(' *(.text.unlikely .text.*_unlikely .text.unlikely.*)');
  805. add(' *(.text.exit .text.exit.*)');
  806. add(' *(.text.startup .text.startup.*)');
  807. add(' *(.text.hot .text.hot.*)');
  808. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  809. add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  810. add(' *(.gnu.warning)');
  811. add(' } =0');
  812. add(' .fini :');
  813. add(' {');
  814. add(' KEEP (*(SORT_NONE(.fini)))');
  815. add(' } =0');
  816. add(' PROVIDE (__etext = .);');
  817. add(' PROVIDE (_etext = .);');
  818. add(' PROVIDE (etext = .);');
  819. add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
  820. add(' .rodata1 : { *(.rodata1) }');
  821. add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  822. add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  823. add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table');
  824. add(' .gcc_except_table.*) }');
  825. add(' /* These sections are generated by the Sun/Oracle C++ compiler. */');
  826. add(' .exception_ranges : ONLY_IF_RO { *(.exception_ranges');
  827. add(' .exception_ranges*) }');
  828. add(' /* Adjust the address for the data segment. We want to adjust up to');
  829. add(' the same address within the page on the next page up. */');
  830. add(' . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));');
  831. add(' /* Exception handling */');
  832. add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  833. add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  834. add(' .exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) }');
  835. add(' /* Thread Local Storage sections */');
  836. add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  837. add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  838. add(' .preinit_array :');
  839. add(' {');
  840. add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
  841. add(' KEEP (*(.preinit_array))');
  842. add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
  843. add(' }');
  844. add(' .init_array :');
  845. add(' {');
  846. add(' PROVIDE_HIDDEN (__init_array_start = .);');
  847. add(' KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))');
  848. add(' KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))');
  849. add(' PROVIDE_HIDDEN (__init_array_end = .);');
  850. add(' }');
  851. add(' .fini_array :');
  852. add(' {');
  853. add(' PROVIDE_HIDDEN (__fini_array_start = .);');
  854. add(' KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))');
  855. add(' KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))');
  856. add(' PROVIDE_HIDDEN (__fini_array_end = .);');
  857. add(' }');
  858. add(' .ctors :');
  859. add(' {');
  860. add(' /* gcc uses crtbegin.o to find the start of');
  861. add(' the constructors, so we make sure it is');
  862. add(' first. Because this is a wildcard, it');
  863. add(' doesn''t matter if the user does not');
  864. add(' actually link against crtbegin.o; the');
  865. add(' linker won''t look for a file to match a');
  866. add(' wildcard. The wildcard also means that it');
  867. add(' doesn''t matter which directory crtbegin.o');
  868. add(' is in. */');
  869. add(' KEEP (*crtbegin.o(.ctors))');
  870. add(' KEEP (*crtbegin?.o(.ctors))');
  871. add(' /* We don''t want to include the .ctor section from');
  872. add(' the crtend.o file until after the sorted ctors.');
  873. add(' The .ctor section from the crtend file contains the');
  874. add(' end of ctors marker and it must be last */');
  875. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
  876. add(' KEEP (*(SORT(.ctors.*)))');
  877. add(' KEEP (*(.ctors))');
  878. add(' }');
  879. add(' .dtors :');
  880. add(' {');
  881. add(' KEEP (*crtbegin.o(.dtors))');
  882. add(' KEEP (*crtbegin?.o(.dtors))');
  883. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
  884. add(' KEEP (*(SORT(.dtors.*)))');
  885. add(' KEEP (*(.dtors))');
  886. add(' }');
  887. add(' .jcr : { KEEP (*(.jcr)) }');
  888. add(' .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }');
  889. add(' .dynamic : { *(.dynamic) }');
  890. add(' .got : { *(.got) *(.igot) }');
  891. add(' . = DATA_SEGMENT_RELRO_END (24, .);');
  892. add(' .got.plt : { *(.got.plt) *(.igot.plt) }');
  893. add(' .data :');
  894. add(' {');
  895. add(' PROVIDE (__data_start = .);');
  896. { extra by FPC }
  897. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  898. add(' *(.data .data.* .gnu.linkonce.d.*)');
  899. add(' SORT(CONSTRUCTORS)');
  900. add(' }');
  901. add(' .data1 : { *(.data1) }');
  902. add(' _edata = .; PROVIDE (edata = .);');
  903. add(' . = .;');
  904. add(' __bss_start = .;');
  905. add(' __bss_start__ = .;');
  906. add(' .bss :');
  907. add(' {');
  908. add(' *(.dynbss)');
  909. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  910. add(' *(COMMON)');
  911. add(' /* Align here to ensure that the .bss section occupies space up to');
  912. add(' _end. Align after .bss to ensure correct alignment even if the');
  913. add(' .bss section disappears because there are no input sections.');
  914. add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
  915. add(' pad the .data section. */');
  916. add(' . = ALIGN(. != 0 ? 64 / 8 : 1);');
  917. add(' }');
  918. add(' _bss_end__ = . ; __bss_end__ = . ;');
  919. add(' . = ALIGN(64 / 8);');
  920. add(' . = SEGMENT_START("ldata-segment", .);');
  921. add(' . = ALIGN(64 / 8);');
  922. add(' __end__ = . ;');
  923. add(' _end = .; PROVIDE (end = .);');
  924. add(' . = DATA_SEGMENT_END (.);');
  925. add(' /* Stabs debugging sections. */');
  926. add(' .stab 0 : { *(.stab) }');
  927. add(' .stabstr 0 : { *(.stabstr) }');
  928. add(' .stab.excl 0 : { *(.stab.excl) }');
  929. add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  930. add(' .stab.index 0 : { *(.stab.index) }');
  931. add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  932. add(' .comment 0 : { *(.comment) }');
  933. add(' /* DWARF debug sections.');
  934. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  935. add(' of the section so we begin them at 0. */');
  936. add(' /* DWARF 1 */');
  937. add(' .debug 0 : { *(.debug) }');
  938. add(' .line 0 : { *(.line) }');
  939. add(' /* GNU DWARF 1 extensions */');
  940. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  941. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  942. add(' /* DWARF 1.1 and DWARF 2 */');
  943. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  944. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  945. add(' /* DWARF 2 */');
  946. add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  947. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  948. add(' .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }');
  949. add(' .debug_frame 0 : { *(.debug_frame) }');
  950. add(' .debug_str 0 : { *(.debug_str) }');
  951. add(' .debug_loc 0 : { *(.debug_loc) }');
  952. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  953. add(' /* SGI/MIPS DWARF 2 extensions */');
  954. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  955. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  956. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  957. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  958. add(' /* DWARF 3 */');
  959. add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  960. add(' .debug_ranges 0 : { *(.debug_ranges) }');
  961. add(' /* DWARF Extension. */');
  962. add(' .debug_macro 0 : { *(.debug_macro) }');
  963. add(' .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }');
  964. add(' .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }');
  965. add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  966. add('}');
  967. {$endif AArch64}
  968. {$ifdef ARM}
  969. if target_info.abi in [abi_eabi,abi_eabihf] then
  970. begin
  971. { from GNU ld (CodeSourcery Sourcery G++ Lite 2007q3-53) 2.18.50.20070820 }
  972. add('/* Script for -z combreloc: combine and sort reloc sections */');
  973. add('OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm",');
  974. add(' "elf32-littlearm")');
  975. add('OUTPUT_ARCH(arm)');
  976. add('SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");');
  977. add('SECTIONS');
  978. add('{');
  979. add(' /* Read-only sections, merged into text segment: */');
  980. add(' PROVIDE (__executable_start = 0x8000); . = 0x8000 + SIZEOF_HEADERS;');
  981. add(' .interp : { *(.interp) }');
  982. add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  983. add(' .hash : { *(.hash) }');
  984. add(' .gnu.hash : { *(.gnu.hash) }');
  985. add(' .dynsym : { *(.dynsym) }');
  986. add(' .dynstr : { *(.dynstr) }');
  987. add(' .gnu.version : { *(.gnu.version) }');
  988. add(' .gnu.version_d : { *(.gnu.version_d) }');
  989. add(' .gnu.version_r : { *(.gnu.version_r) }');
  990. add(' .rel.dyn :');
  991. add(' {');
  992. add(' *(.rel.init)');
  993. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  994. add(' *(.rel.fini)');
  995. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  996. add(' *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*)');
  997. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  998. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  999. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  1000. add(' *(.rel.ctors)');
  1001. add(' *(.rel.dtors)');
  1002. add(' *(.rel.got)');
  1003. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  1004. add(' }');
  1005. add(' .rela.dyn :');
  1006. add(' {');
  1007. add(' *(.rela.init)');
  1008. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  1009. add(' *(.rela.fini)');
  1010. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  1011. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  1012. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  1013. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  1014. add(' *(.rela.ctors)');
  1015. add(' *(.rela.dtors)');
  1016. add(' *(.rela.got)');
  1017. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  1018. add(' }');
  1019. add(' .rel.plt : { *(.rel.plt) }');
  1020. add(' .rela.plt : { *(.rela.plt) }');
  1021. add(' .init :');
  1022. add(' {');
  1023. add(' KEEP (*(.init))');
  1024. add(' } =0');
  1025. add(' .plt : { *(.plt) }');
  1026. add(' .text :');
  1027. add(' {');
  1028. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  1029. add(' KEEP (*(.text.*personality*))');
  1030. add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  1031. add(' *(.gnu.warning)');
  1032. add(' *(.glue_7t) *(.glue_7) *(.vfp11_veneer)');
  1033. add(' } =0');
  1034. add(' .fini :');
  1035. add(' {');
  1036. add(' KEEP (*(.fini))');
  1037. add(' } =0');
  1038. add(' PROVIDE (__etext = .);');
  1039. add(' PROVIDE (_etext = .);');
  1040. add(' PROVIDE (etext = .);');
  1041. add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
  1042. add(' .rodata1 : { *(.rodata1) }');
  1043. add(' .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) }');
  1044. add(' __exidx_start = .;');
  1045. add(' .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }');
  1046. add(' __exidx_end = .;');
  1047. add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  1048. add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  1049. add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }');
  1050. add(' /* Adjust the address for the data segment. We want to adjust up to');
  1051. add(' the same address within the page on the next page up. */');
  1052. add(' . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));');
  1053. add(' /* Exception handling */');
  1054. add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  1055. add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  1056. add(' /* Thread Local Storage sections */');
  1057. add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  1058. add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  1059. add(' .preinit_array :');
  1060. add(' {');
  1061. add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
  1062. add(' KEEP (*(.preinit_array))');
  1063. add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
  1064. add(' }');
  1065. add(' .init_array :');
  1066. add(' {');
  1067. add(' PROVIDE_HIDDEN (__init_array_start = .);');
  1068. add(' KEEP (*(SORT(.init_array.*)))');
  1069. add(' KEEP (*(.init_array))');
  1070. add(' PROVIDE_HIDDEN (__init_array_end = .);');
  1071. add(' }');
  1072. add(' .fini_array :');
  1073. add(' {');
  1074. add(' PROVIDE_HIDDEN (__fini_array_start = .);');
  1075. add(' KEEP (*(.fini_array))');
  1076. add(' KEEP (*(SORT(.fini_array.*)))');
  1077. add(' PROVIDE_HIDDEN (__fini_array_end = .);');
  1078. add(' }');
  1079. add(' .ctors :');
  1080. add(' {');
  1081. add(' /* gcc uses crtbegin.o to find the start of');
  1082. add(' the constructors, so we make sure it is');
  1083. add(' first. Because this is a wildcard, it');
  1084. add(' doesn''t matter if the user does not');
  1085. add(' actually link against crtbegin.o; the');
  1086. add(' linker won''t look for a file to match a');
  1087. add(' wildcard. The wildcard also means that it');
  1088. add(' doesn''t matter which directory crtbegin.o');
  1089. add(' is in. */');
  1090. add(' KEEP (*crtbegin.o(.ctors))');
  1091. add(' KEEP (*crtbegin?.o(.ctors))');
  1092. add(' /* We don''t want to include the .ctor section from');
  1093. add(' the crtend.o file until after the sorted ctors.');
  1094. add(' The .ctor section from the crtend file contains the');
  1095. add(' end of ctors marker and it must be last */');
  1096. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
  1097. add(' KEEP (*(SORT(.ctors.*)))');
  1098. add(' KEEP (*(.ctors))');
  1099. add(' }');
  1100. add(' .dtors :');
  1101. add(' {');
  1102. add(' KEEP (*crtbegin.o(.dtors))');
  1103. add(' KEEP (*crtbegin?.o(.dtors))');
  1104. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
  1105. add(' KEEP (*(SORT(.dtors.*)))');
  1106. add(' KEEP (*(.dtors))');
  1107. add(' }');
  1108. add(' .jcr : { KEEP (*(.jcr)) }');
  1109. add(' .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }');
  1110. add(' .dynamic : { *(.dynamic) }');
  1111. add(' .got : { *(.got.plt) *(.got) }');
  1112. add(' .data :');
  1113. add(' {');
  1114. add(' __data_start = . ;');
  1115. add(' *(.data .data.* .gnu.linkonce.d.*)');
  1116. { extra by FPC }
  1117. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1118. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  1119. add(' SORT(CONSTRUCTORS)');
  1120. add(' }');
  1121. add(' .data1 : { *(.data1) }');
  1122. add(' _edata = .; PROVIDE (edata = .);');
  1123. add(' __bss_start = .;');
  1124. add(' __bss_start__ = .;');
  1125. add(' .bss :');
  1126. add(' {');
  1127. add(' *(.dynbss)');
  1128. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  1129. add(' *(COMMON)');
  1130. add(' /* Align here to ensure that the .bss section occupies space up to');
  1131. add(' _end. Align after .bss to ensure correct alignment even if the');
  1132. add(' .bss section disappears because there are no input sections.');
  1133. add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
  1134. add(' pad the .data section. */');
  1135. add(' . = ALIGN(. != 0 ? 32 / 8 : 1);');
  1136. add(' }');
  1137. add(' _bss_end__ = . ; __bss_end__ = . ;');
  1138. add(' . = ALIGN(32 / 8);');
  1139. add(' . = ALIGN(32 / 8);');
  1140. add(' __end__ = . ;');
  1141. add(' _end = .; PROVIDE (end = .);');
  1142. add(' /* Stabs debugging sections. */');
  1143. add(' .stab 0 : { *(.stab) }');
  1144. add(' .stabstr 0 : { *(.stabstr) }');
  1145. add(' .stab.excl 0 : { *(.stab.excl) }');
  1146. add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1147. add(' .stab.index 0 : { *(.stab.index) }');
  1148. add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1149. add(' .comment 0 : { *(.comment) }');
  1150. add(' /* DWARF debug sections.');
  1151. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1152. add(' of the section so we begin them at 0. */');
  1153. add(' /* DWARF 1 */');
  1154. add(' .debug 0 : { *(.debug) }');
  1155. add(' .line 0 : { *(.line) }');
  1156. add(' /* GNU DWARF 1 extensions */');
  1157. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1158. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1159. add(' /* DWARF 1.1 and DWARF 2 */');
  1160. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1161. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1162. add(' /* DWARF 2 */');
  1163. add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1164. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1165. add(' .debug_line 0 : { *(.debug_line) }');
  1166. add(' .debug_frame 0 : { *(.debug_frame) }');
  1167. add(' .debug_str 0 : { *(.debug_str) }');
  1168. add(' .debug_loc 0 : { *(.debug_loc) }');
  1169. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1170. add(' /* SGI/MIPS DWARF 2 extensions */');
  1171. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1172. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1173. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1174. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1175. add(' /* DWARF 3 */');
  1176. add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1177. add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1178. add(' .stack 0x80000 :');
  1179. add(' {');
  1180. add(' _stack = .;');
  1181. add(' *(.stack)');
  1182. add(' }');
  1183. add(' .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }');
  1184. add(' .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }');
  1185. add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) }');
  1186. add('}');
  1187. end
  1188. else
  1189. {$endif ARM}
  1190. {$ifndef LINKERSCRIPT_INCLUDED}
  1191. begin
  1192. {Sections.}
  1193. add('SECTIONS');
  1194. add('{');
  1195. {Read-only sections, merged into text segment:}
  1196. add(' PROVIDE (__executable_start = 0x010000); . = 0x010000 + SIZEOF_HEADERS;');
  1197. add(' .interp : { *(.interp) }');
  1198. add(' .hash : { *(.hash) }');
  1199. add(' .dynsym : { *(.dynsym) }');
  1200. add(' .dynstr : { *(.dynstr) }');
  1201. add(' .gnu.version : { *(.gnu.version) }');
  1202. add(' .gnu.version_d : { *(.gnu.version_d) }');
  1203. add(' .gnu.version_r : { *(.gnu.version_r) }');
  1204. add(' .rel.dyn :');
  1205. add(' {');
  1206. add(' *(.rel.init)');
  1207. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  1208. add(' *(.rel.fini)');
  1209. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  1210. add(' *(.rel.data.rel.ro*)');
  1211. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  1212. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  1213. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  1214. add(' *(.rel.got)');
  1215. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  1216. add(' }');
  1217. add(' .rela.dyn :');
  1218. add(' {');
  1219. add(' *(.rela.init)');
  1220. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  1221. add(' *(.rela.fini)');
  1222. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  1223. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  1224. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  1225. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  1226. add(' *(.rela.got)');
  1227. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  1228. add(' }');
  1229. add(' .rel.plt : { *(.rel.plt) }');
  1230. add(' .rela.plt : { *(.rela.plt) }');
  1231. add(' .init :');
  1232. add(' {');
  1233. add(' KEEP (*(.init))');
  1234. add(' } =0x90909090');
  1235. add(' .plt : { *(.plt) }');
  1236. add(' .text :');
  1237. add(' {');
  1238. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  1239. add(' KEEP (*(.text.*personality*))');
  1240. {.gnu.warning sections are handled specially by elf32.em.}
  1241. add(' *(.gnu.warning)');
  1242. add(' } =0x90909090');
  1243. add(' .fini :');
  1244. add(' {');
  1245. add(' KEEP (*(.fini))');
  1246. add(' } =0x90909090');
  1247. add(' PROVIDE (_etext = .);');
  1248. add(' .rodata :');
  1249. add(' {');
  1250. add(' *(.rodata .rodata.* .gnu.linkonce.r.*)');
  1251. add(' }');
  1252. add(' .rodata1 : { *(.rodata1) }');
  1253. add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  1254. add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  1255. add(' .gcc_except_table : { KEEP *(.gcc_except_table .gcc_except_table.*) }');
  1256. {Adjust the address for the data segment. We want to adjust up to
  1257. the same address within the page on the next page up.}
  1258. add(' . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1));');
  1259. add(' /* Exception handling */');
  1260. add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  1261. add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  1262. add(' .dynamic : { *(.dynamic) }');
  1263. add(' .got : { *(.got) }');
  1264. add(' .got.plt : { *(.got.plt) }');
  1265. add(' .data :');
  1266. add(' {');
  1267. add(' *(.data .data.* .gnu.linkonce.d.*)');
  1268. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1269. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  1270. add(' }');
  1271. add(' PROVIDE (_edata = .);');
  1272. add(' PROVIDE (edata = .);');
  1273. {$ifdef zsegment_threadvars}
  1274. add(' _z = .;');
  1275. add(' .threadvar 0 : AT (_z) { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  1276. add(' PROVIDE (_threadvar_size = SIZEOF(.threadvar));');
  1277. add(' . = _z + SIZEOF (.threadvar);');
  1278. {$else}
  1279. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  1280. {$endif}
  1281. add(' __bss_start = .;');
  1282. add(' .bss :');
  1283. add(' {');
  1284. add(' *(.dynbss)');
  1285. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  1286. add(' *(COMMON)');
  1287. {Align here to ensure that the .bss section occupies space up to
  1288. _end. Align after .bss to ensure correct alignment even if the
  1289. .bss section disappears because there are no input sections.}
  1290. add(' . = ALIGN(32 / 8);');
  1291. add(' }');
  1292. add(' . = ALIGN(32 / 8);');
  1293. add(' PROVIDE (_end = .);');
  1294. add(' PROVIDE (end = .);');
  1295. {Stabs debugging sections.}
  1296. add(' .stab 0 : { *(.stab) }');
  1297. add(' .stabstr 0 : { *(.stabstr) }');
  1298. add('}');
  1299. end;
  1300. {$endif LINKERSCRIPT_INCLUDED}
  1301. end;
  1302. { Write and Close response }
  1303. writetodisk;
  1304. Free;
  1305. end;
  1306. WriteResponseFile:=True;
  1307. end;
  1308. function TLinkerLinux.MakeExecutable:boolean;
  1309. var
  1310. i : longint;
  1311. binstr,
  1312. cmdstr,
  1313. mapstr,
  1314. ltostr : TCmdStr;
  1315. success : boolean;
  1316. DynLinkStr : string;
  1317. GCSectionsStr,
  1318. StaticStr,
  1319. StripStr : string[40];
  1320. begin
  1321. if not(cs_link_nolink in current_settings.globalswitches) then
  1322. Message1(exec_i_linking,current_module.exefilename);
  1323. { Create some replacements }
  1324. StaticStr:='';
  1325. StripStr:='';
  1326. GCSectionsStr:='';
  1327. DynLinkStr:='';
  1328. mapstr:='';
  1329. ltostr:='';
  1330. if (cs_link_staticflag in current_settings.globalswitches) then
  1331. StaticStr:='-static';
  1332. if (cs_link_strip in current_settings.globalswitches) and
  1333. not(cs_link_separate_dbg_file in current_settings.globalswitches) then
  1334. StripStr:='-s';
  1335. if (cs_link_map in current_settings.globalswitches) then
  1336. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  1337. if (cs_link_smart in current_settings.globalswitches) and
  1338. create_smartlink_sections then
  1339. GCSectionsStr:='--gc-sections';
  1340. If (cs_profile in current_settings.moduleswitches) or
  1341. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  1342. begin
  1343. DynLinkStr:='--dynamic-linker='+Info.DynamicLinker;
  1344. if cshared then
  1345. DynLinkStr:=DynLinkStr+' --shared ';
  1346. if rlinkpath<>'' then
  1347. DynLinkStr:=DynLinkStr+' --rpath-link '+rlinkpath;
  1348. End;
  1349. { add custom LTO library if using custom clang }
  1350. if (cs_lto in current_settings.moduleswitches) and
  1351. not(cs_link_on_target in current_settings.globalswitches) and
  1352. (utilsdirectory<>'') and
  1353. FileExists(utilsdirectory+'/../lib/LLVMgold.so',true) then
  1354. begin
  1355. ltostr:='-plugin '+maybequoted(utilsdirectory+'/../lib/LLVMgold.so ');
  1356. end;
  1357. { Write used files and libraries }
  1358. WriteResponseFile(false);
  1359. { Call linker }
  1360. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1361. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  1362. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1363. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1364. Replace(cmdstr,'$STATIC',StaticStr);
  1365. Replace(cmdstr,'$STRIP',StripStr);
  1366. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1367. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1368. Replace(cmdstr,'$MAP',mapstr);
  1369. Replace(cmdstr,'$LTO',ltostr);
  1370. { create dynamic symbol table? }
  1371. if HasExports then
  1372. cmdstr:=cmdstr+' -E';
  1373. { create eh_frame_hdr section? }
  1374. if tf_use_psabieh in target_info.flags then
  1375. cmdstr:=cmdstr+ ' --eh-frame-hdr';
  1376. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  1377. { Create external .dbg file with debuginfo }
  1378. if success and (cs_link_separate_dbg_file in current_settings.globalswitches) then
  1379. begin
  1380. for i:=1 to 3 do
  1381. begin
  1382. SplitBinCmd(Info.ExtDbgCmd[i],binstr,cmdstr);
  1383. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  1384. Replace(cmdstr,'$DBGFN',maybequoted(extractfilename(current_module.dbgfilename)));
  1385. Replace(cmdstr,'$DBGX',current_module.dbgfilename);
  1386. Replace(cmdstr,'$DBG',maybequoted(current_module.dbgfilename));
  1387. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  1388. if not success then
  1389. break;
  1390. end;
  1391. end;
  1392. { Remove ReponseFile }
  1393. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  1394. DeleteFile(outputexedir+Info.ResName);
  1395. MakeExecutable:=success; { otherwise a recursive call to link method }
  1396. end;
  1397. Function TLinkerLinux.MakeSharedLibrary:boolean;
  1398. var
  1399. InitStr,
  1400. FiniStr,
  1401. GCSectionsStr,
  1402. SoNameStr : string[80];
  1403. binstr,
  1404. cmdstr,
  1405. mapstr,
  1406. ltostr : TCmdStr;
  1407. success : boolean;
  1408. begin
  1409. MakeSharedLibrary:=false;
  1410. mapstr:='';
  1411. ltostr:='';
  1412. if not(cs_link_nolink in current_settings.globalswitches) then
  1413. Message1(exec_i_linking,current_module.sharedlibfilename);
  1414. if (cs_link_smart in current_settings.globalswitches) and
  1415. create_smartlink_sections then
  1416. GCSectionsStr:='--gc-sections'
  1417. else
  1418. GCSectionsStr:='';
  1419. { Write used files and libraries }
  1420. WriteResponseFile(true);
  1421. { Create some replacements }
  1422. { note: linux does not use exportlib.initname/fininame due to the custom startup code }
  1423. InitStr:='-init FPC_SHARED_LIB_START';
  1424. FiniStr:='-fini FPC_LIB_EXIT';
  1425. SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename);
  1426. if (cs_link_map in current_settings.globalswitches) then
  1427. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.sharedlibfilename,'.map'));
  1428. { add custom LTO library if using custom clang }
  1429. if (cs_lto in current_settings.moduleswitches) and
  1430. not(cs_link_on_target in current_settings.globalswitches) and
  1431. (utilsdirectory<>'') and
  1432. FileExists(utilsdirectory+'/../lib/LLVMgold.so',true) then
  1433. begin
  1434. ltostr:='-plugin '+maybequoted(utilsdirectory+'/../lib/LLVMgold.so ');
  1435. end;
  1436. { Call linker }
  1437. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  1438. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  1439. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1440. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1441. Replace(cmdstr,'$INIT',InitStr);
  1442. Replace(cmdstr,'$FINI',FiniStr);
  1443. Replace(cmdstr,'$SONAME',SoNameStr);
  1444. Replace(cmdstr,'$MAP',mapstr);
  1445. Replace(cmdstr,'$LTO',ltostr);
  1446. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1447. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  1448. { Strip the library ? }
  1449. if success and (cs_link_strip in current_settings.globalswitches) then
  1450. begin
  1451. { only remove non global symbols and debugging info for a library }
  1452. Info.DllCmd[2]:='strip --discard-all --strip-debug $EXE';
  1453. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  1454. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  1455. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  1456. end;
  1457. { Remove ReponseFile }
  1458. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  1459. DeleteFile(outputexedir+Info.ResName);
  1460. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  1461. end;
  1462. {*****************************************************************************
  1463. TINTERNALLINKERLINUX
  1464. *****************************************************************************}
  1465. constructor TInternalLinkerLinux.Create;
  1466. begin
  1467. inherited Create;
  1468. SetupLibrarySearchPath;
  1469. SetupDynlinker(dynlinker,libctype);
  1470. CArObjectReader:=TArObjectReader;
  1471. CExeOutput:=ElfExeOutputClass;
  1472. CObjInput:=TElfObjInput;
  1473. end;
  1474. procedure TInternalLinkerLinux.InitSysInitUnitName;
  1475. begin
  1476. linklibc:=ModulesLinkToLibc;
  1477. reorder:=linklibc and ReOrderEntries;
  1478. sysinitunit:=defsinames[current_module.islibrary];
  1479. prtobj:=defprtnames[current_module.islibrary];
  1480. if cs_profile in current_settings.moduleswitches then
  1481. begin
  1482. prtobj:=gprtnames[libctype];
  1483. sysinitunit:=gsinames[libctype];
  1484. linklibc:=true;
  1485. end
  1486. else if linklibc then
  1487. begin
  1488. prtobj:=cprtnames[libctype];
  1489. sysinitunit:=csinames[libctype];
  1490. end;
  1491. end;
  1492. const
  1493. relsec_prefix:array[boolean] of TCmdStr = ('rel','rela');
  1494. procedure TInternalLinkerLinux.DefaultLinkScript;
  1495. var
  1496. s,s1,s2,relprefix:TCmdStr;
  1497. found1,found2:boolean;
  1498. linkToSharedLibs:boolean;
  1499. procedure AddLibraryStatement(const s:TCmdStr);
  1500. var
  1501. i:longint;
  1502. s1,s2:TCmdStr;
  1503. begin
  1504. i:=pos(target_info.sharedClibext+'.',s);
  1505. if (i>0) then
  1506. s1:=target_info.sharedClibprefix+S
  1507. else
  1508. s1:=target_info.sharedClibprefix+S+target_info.sharedClibext;
  1509. { TODO: to be compatible with ld search algorithm, each found file
  1510. must be tested for target compatibility, incompatible ones should be skipped. }
  1511. { TODO: shall we search library without suffix if one with suffix is not found? }
  1512. if (not(cs_link_staticflag in current_settings.globalswitches)) and
  1513. FindLibraryFile(s1,'','',s2) then
  1514. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(s2))
  1515. { TODO: static libraries never have numeric suffix in their names }
  1516. else if FindLibraryFile(s,target_info.staticClibprefix,target_info.staticClibext,s2) then
  1517. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(s2))
  1518. else
  1519. Comment(V_Error,'Import library not found for '+S);
  1520. end;
  1521. begin
  1522. if cs_profile in current_settings.moduleswitches then
  1523. begin
  1524. if not(libctype in [glibc2,glibc21]) then
  1525. AddSharedLibrary('gmon');
  1526. AddSharedLibrary('c');
  1527. end;
  1528. TElfExeOutput(exeoutput).interpreter:=stringdup(dynlinker);
  1529. { add objectfiles, start with prt0 always }
  1530. if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
  1531. LinkScript.Concat('READOBJECT '+ maybequoted(FindObjectFile(prtobj,'',false)));
  1532. { try to add crti and crtbegin if linking to C }
  1533. if linklibc and (libctype<>uclibc) then
  1534. begin
  1535. { crti.o must come first }
  1536. if librarysearchpath.FindFile('crti.o',false,s) then
  1537. LinkScript.Concat('READOBJECT '+maybequoted(s));
  1538. { then the crtbegin* }
  1539. if cs_create_pic in current_settings.moduleswitches then
  1540. begin
  1541. if librarysearchpath.FindFile('crtbeginS.o',false,s) then
  1542. LinkScript.Concat('READOBJECT '+maybequoted(s));
  1543. end
  1544. else
  1545. if (cs_link_staticflag in current_settings.globalswitches) and
  1546. librarysearchpath.FindFile('crtbeginT.o',false,s) then
  1547. LinkScript.Concat('READOBJECT '+maybequoted(s))
  1548. else if librarysearchpath.FindFile('crtbegin.o',false,s) then
  1549. LinkScript.Concat('READOBJECT '+maybequoted(s));
  1550. end;
  1551. ScriptAddSourceStatements(false);
  1552. { we must reorder here because the result could empty sharedlibfiles }
  1553. if reorder then
  1554. ExpandAndApplyOrder(SharedLibFiles);
  1555. { See tw9089*.pp: if more than one pure-Pascal shared libs are loaded,
  1556. and none have rtld in their DT_NEEDED, then rtld cannot finalize correctly. }
  1557. if IsSharedLibrary then
  1558. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(sysrootpath+dynlinker));
  1559. linkToSharedLibs:=(not SharedLibFiles.Empty);
  1560. { Symbols declared as "external 'libx.so'" are added to ImportLibraryList, library
  1561. prefix/extension *not* stripped. TImportLibLinux copies these to SharedLibFiles,
  1562. stripping prefixes and extensions.
  1563. However extension won't be stripped if library is specified with numeric suffix
  1564. (like "libpango-1.0.so.0")
  1565. Libraries specified with $LINKLIB directive are directly added to SharedLibFiles
  1566. and won't be present in ImportLibraryList. }
  1567. while not SharedLibFiles.Empty do
  1568. begin
  1569. S:=SharedLibFiles.GetFirst;
  1570. if (S<>'c') or reorder then
  1571. AddLibraryStatement(S);
  1572. end;
  1573. if (cs_link_staticflag in current_settings.globalswitches) or
  1574. (linklibc and not reorder) then
  1575. begin
  1576. LinkScript.Concat('GROUP');
  1577. if (cs_link_staticflag in current_settings.globalswitches) then
  1578. begin
  1579. AddLibraryStatement('gcc');
  1580. AddLibraryStatement('gcc_eh');
  1581. end;
  1582. if linklibc and not reorder then
  1583. AddLibraryStatement('c');
  1584. LinkScript.Concat('ENDGROUP');
  1585. end;
  1586. { objects which must be at the end }
  1587. if linklibc and (libctype<>uclibc) then
  1588. begin
  1589. if cs_create_pic in current_settings.moduleswitches then
  1590. found1:=librarysearchpath.FindFile('crtendS.o',false,s1)
  1591. else
  1592. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  1593. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  1594. if found1 then
  1595. LinkScript.Concat('READOBJECT '+maybequoted(s1));
  1596. if found2 then
  1597. LinkScript.Concat('READOBJECT '+maybequoted(s2));
  1598. end;
  1599. if (not IsSharedLibrary) then
  1600. if (linkToSharedLibs and not linklibc) then
  1601. LinkScript.Concat('ENTRYNAME _dynamic_start')
  1602. else
  1603. LinkScript.Concat('ENTRYNAME _start')
  1604. else
  1605. LinkScript.Concat('ISSHAREDLIBRARY');
  1606. relprefix:=relsec_prefix[ElfTarget.relocs_use_addend];
  1607. with LinkScript do
  1608. begin
  1609. Concat('HEADER');
  1610. Concat('EXESECTION .interp');
  1611. Concat(' OBJSECTION .interp');
  1612. Concat('ENDEXESECTION');
  1613. Concat('EXESECTION .note.ABI-tag');
  1614. Concat(' OBJSECTION .note.ABI-tag');
  1615. Concat('ENDEXESECTION');
  1616. Concat('EXESECTION .note.gnu.build-id');
  1617. Concat(' OBJSECTION .note.gnu.build-id');
  1618. Concat('ENDEXESECTION');
  1619. Concat('EXESECTION .hash');
  1620. Concat(' OBJSECTION .hash');
  1621. Concat('ENDEXESECTION');
  1622. Concat('EXESECTION .dynsym');
  1623. Concat(' OBJSECTION .dynsym');
  1624. Concat('ENDEXESECTION');
  1625. Concat('EXESECTION .dynstr');
  1626. Concat(' OBJSECTION .dynstr');
  1627. Concat('ENDEXESECTION');
  1628. Concat('EXESECTION .gnu.version');
  1629. Concat(' OBJSECTION .gnu.version');
  1630. Concat('ENDEXESECTION');
  1631. Concat('EXESECTION .gnu.version_d');
  1632. Concat(' OBJSECTION .gnu.version_d');
  1633. Concat('ENDEXESECTION');
  1634. Concat('EXESECTION .gnu.version_r');
  1635. Concat(' OBJSECTION .gnu.version_r');
  1636. Concat('ENDEXESECTION');
  1637. Concat('EXESECTION .'+relprefix+'.dyn');
  1638. Concat(' OBJSECTION .'+relprefix+'.dyn');
  1639. Concat('ENDEXESECTION');
  1640. Concat('EXESECTION .'+relprefix+'.plt');
  1641. Concat(' OBJSECTION .'+relprefix+'.plt');
  1642. Concat(' PROVIDE __'+relprefix+'_iplt_start');
  1643. Concat(' OBJSECTION .'+relprefix+'.iplt');
  1644. Concat(' PROVIDE __'+relprefix+'_iplt_end');
  1645. Concat('ENDEXESECTION');
  1646. Concat('EXESECTION .init');
  1647. Concat(' OBJSECTION .init');
  1648. Concat('ENDEXESECTION');
  1649. Concat('EXESECTION .plt');
  1650. Concat(' OBJSECTION .plt');
  1651. Concat('ENDEXESECTION');
  1652. Concat('EXESECTION .text');
  1653. Concat(' OBJSECTION .text*');
  1654. Concat('ENDEXESECTION');
  1655. Concat('EXESECTION .fini');
  1656. Concat(' OBJSECTION .fini');
  1657. Concat(' PROVIDE __etext');
  1658. Concat(' PROVIDE _etext');
  1659. Concat(' PROVIDE etext');
  1660. Concat('ENDEXESECTION');
  1661. Concat('EXESECTION .rodata');
  1662. Concat(' OBJSECTION .rodata*');
  1663. Concat('ENDEXESECTION');
  1664. {$ifdef arm}
  1665. Concat('EXESECTION .ARM.extab');
  1666. Concat(' OBJSECTION .ARM.extab*');
  1667. Concat('ENDEXESECTION');
  1668. Concat('EXESECTION .ARM.exidx');
  1669. Concat(' SYMBOL __exidx_start');
  1670. Concat(' OBJSECTION .ARM.exidx*');
  1671. Concat(' SYMBOL __exidx_end');
  1672. Concat('ENDEXESECTION');
  1673. {$endif}
  1674. Concat('EXESECTION .eh_frame');
  1675. Concat(' OBJSECTION .eh_frame');
  1676. Concat('ENDEXESECTION');
  1677. Concat('EXESECTION .gcc_except_table');
  1678. Concat(' OBJSECTION .gcc_except_table');
  1679. Concat(' OBJSECTION .gcc_except_table.*');
  1680. Concat('ENDEXESECTION');
  1681. Concat('EXESECTION .tdata');
  1682. Concat(' OBJSECTION .tdata');
  1683. Concat(' OBJSECTION .tdata.*');
  1684. Concat('ENDEXESECTION');
  1685. Concat('EXESECTION .tbss');
  1686. Concat(' OBJSECTION .tbss');
  1687. Concat(' OBJSECTION .tbss.*');
  1688. Concat('ENDEXESECTION');
  1689. Concat('EXESECTION .preinit_array');
  1690. Concat(' PROVIDE __preinit_array_start');
  1691. Concat(' OBJSECTION .preinit_array');
  1692. Concat(' PROVIDE __preinit_array_end');
  1693. Concat('ENDEXESECTION');
  1694. Concat('EXESECTION .init_array');
  1695. Concat(' PROVIDE __init_array_start');
  1696. { why the hell .ctors are both here and exesection .ctors below?? }
  1697. // KEEP ( *(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
  1698. Concat(' OBJSECTION .init_array');
  1699. // KEEP ( *(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  1700. Concat('PROVIDE __init_array_end');
  1701. Concat('ENDEXESECTION');
  1702. Concat('EXESECTION .fini_array');
  1703. Concat(' PROVIDE __fini_array_start');
  1704. // KEEP ( *(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
  1705. Concat(' OBJSECTION .fini_array');
  1706. // KEEP ( *(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
  1707. Concat(' PROVIDE __fini_array_end');
  1708. Concat('ENDEXESECTION');
  1709. Concat('EXESECTION .ctors');
  1710. Concat(' OBJSECTION .ctors*');
  1711. Concat('ENDEXESECTION');
  1712. Concat('EXESECTION .dtors');
  1713. Concat(' OBJSECTION .dtors*');
  1714. Concat('ENDEXESECTION');
  1715. Concat('EXESECTION .jcr');
  1716. Concat(' OBJSECTION .jcr');
  1717. Concat('ENDEXESECTION');
  1718. Concat('EXESECTION .dynamic');
  1719. Concat(' OBJSECTION .dynamic');
  1720. Concat('ENDEXESECTION');
  1721. {$ifndef mips}
  1722. Concat('EXESECTION .got');
  1723. {$ifdef arm}
  1724. Concat(' OBJSECTION .got.plt');
  1725. {$endif arm}
  1726. Concat(' OBJSECTION .got');
  1727. Concat('ENDEXESECTION');
  1728. {$endif mips}
  1729. {$ifndef arm}
  1730. Concat('EXESECTION .got.plt');
  1731. Concat(' OBJSECTION .got.plt');
  1732. Concat('ENDEXESECTION');
  1733. {$endif arm}
  1734. Concat('EXESECTION .data');
  1735. Concat(' OBJSECTION .data*');
  1736. Concat(' OBJSECTION .fpc*');
  1737. Concat(' OBJSECTION fpc.resources');
  1738. Concat(' PROVIDE _edata');
  1739. Concat(' PROVIDE edata');
  1740. Concat('ENDEXESECTION');
  1741. {$ifdef mips}
  1742. Concat('EXESECTION .got');
  1743. Concat(' OBJSECTION .got');
  1744. Concat('ENDEXESECTION');
  1745. {$endif mips}
  1746. Concat('EXESECTION .bss');
  1747. Concat(' OBJSECTION .dynbss');
  1748. Concat(' OBJSECTION .bss*');
  1749. Concat(' OBJSECTION fpc.reshandles');
  1750. Concat(' PROVIDE end');
  1751. Concat(' SYMBOL _end');
  1752. Concat('ENDEXESECTION');
  1753. ScriptAddGenericSections('.debug_aranges,.debug_pubnames,.debug_info,'+
  1754. '.debug_abbrev,.debug_line,.debug_frame,.debug_str,.debug_loc,'+
  1755. '.debug_macinfo,.debug_weaknames,.debug_funcnames,.debug_typenames,.debug_varnames,.debug_ranges');
  1756. Concat('EXESECTION .stab');
  1757. Concat(' OBJSECTION .stab');
  1758. Concat('ENDEXESECTION');
  1759. Concat('EXESECTION .stabstr');
  1760. Concat(' OBJSECTION .stabstr');
  1761. Concat('ENDEXESECTION');
  1762. end;
  1763. end;
  1764. {*****************************************************************************
  1765. Initialize
  1766. *****************************************************************************}
  1767. initialization
  1768. RegisterLinker(ld_linux,TLinkerLinux);
  1769. RegisterLinker(ld_int_linux,TInternalLinkerLinux);
  1770. {$ifdef i386}
  1771. RegisterImport(system_i386_linux,timportliblinux);
  1772. RegisterExport(system_i386_linux,texportliblinux);
  1773. RegisterTarget(system_i386_linux_info);
  1774. {$endif i386}
  1775. {$ifdef m68k}
  1776. RegisterImport(system_m68k_linux,timportliblinux);
  1777. RegisterExport(system_m68k_linux,texportliblinux);
  1778. RegisterTarget(system_m68k_linux_info);
  1779. {$endif m68k}
  1780. {$ifdef powerpc}
  1781. RegisterImport(system_powerpc_linux,timportliblinux);
  1782. RegisterExport(system_powerpc_linux,texportliblinux);
  1783. RegisterTarget(system_powerpc_linux_info);
  1784. {$endif powerpc}
  1785. {$ifdef powerpc64}
  1786. { default to little endian either when compiling with -dppc64le, or when
  1787. compiling on a little endian ppc64 platform }
  1788. {$if defined(ppc64le) or (defined(cpupowerpc64) and defined(FPC_LITTLE_ENDIAN))}
  1789. system_powerpc64_linux_info.endian:=endian_little;
  1790. system_powerpc64_linux_info.abi:=abi_powerpc_elfv2;
  1791. {$endif}
  1792. RegisterImport(system_powerpc64_linux,timportliblinux);
  1793. RegisterExport(system_powerpc64_linux,texportliblinux);
  1794. RegisterTarget(system_powerpc64_linux_info);
  1795. {$endif powerpc64}
  1796. {$ifdef x86_64}
  1797. RegisterImport(system_x86_64_linux,timportliblinux);
  1798. RegisterExport(system_x86_64_linux,texportliblinux);
  1799. RegisterTarget(system_x86_64_linux_info);
  1800. RegisterTarget(system_x86_6432_linux_info);
  1801. {$endif x86_64}
  1802. {$ifdef SPARC}
  1803. RegisterImport(system_SPARC_linux,timportliblinux);
  1804. RegisterExport(system_SPARC_linux,texportliblinux);
  1805. RegisterTarget(system_SPARC_linux_info);
  1806. {$endif SPARC}
  1807. {$ifdef SPARC64}
  1808. RegisterImport(system_SPARC64_linux,timportliblinux);
  1809. RegisterExport(system_SPARC64_linux,texportliblinux);
  1810. RegisterTarget(system_SPARC64_linux_info);
  1811. {$endif SPARC64}
  1812. {$ifdef ARM}
  1813. RegisterImport(system_arm_linux,timportliblinux);
  1814. RegisterExport(system_arm_linux,texportliblinux);
  1815. RegisterTarget(system_arm_linux_info);
  1816. {$endif ARM}
  1817. {$ifdef aarch64}
  1818. RegisterImport(system_aarch64_linux,timportliblinux);
  1819. RegisterExport(system_aarch64_linux,texportliblinux);
  1820. RegisterTarget(system_aarch64_linux_info);
  1821. {$endif aarch64}
  1822. {$ifdef MIPS}
  1823. {$ifdef MIPSEL}
  1824. RegisterImport(system_mipsel_linux,timportliblinux);
  1825. RegisterExport(system_mipsel_linux,texportliblinux);
  1826. RegisterTarget(system_mipsel_linux_info);
  1827. {$else MIPS}
  1828. RegisterImport(system_mipseb_linux,timportliblinux);
  1829. RegisterExport(system_mipseb_linux,texportliblinux);
  1830. RegisterTarget(system_mipseb_linux_info);
  1831. {$endif MIPSEL}
  1832. {$endif MIPS}
  1833. {$ifdef riscv32}
  1834. RegisterImport(system_riscv32_linux,timportliblinux);
  1835. RegisterExport(system_riscv32_linux,texportliblinux);
  1836. RegisterTarget(system_riscv32_linux_info);
  1837. {$endif riscv32}
  1838. {$ifdef riscv64}
  1839. RegisterImport(system_riscv64_linux,timportliblinux);
  1840. RegisterExport(system_riscv64_linux,texportliblinux);
  1841. RegisterTarget(system_riscv64_linux_info);
  1842. {$endif riscv64}
  1843. RegisterRes(res_elf_info,TWinLikeResourceFile);
  1844. end.