t_linux.pas 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975
  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, libraryadded: 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. libraryadded:=false;
  529. Add('INPUT(');
  530. While not SharedLibFiles.Empty do
  531. begin
  532. S:=SharedLibFiles.GetFirst;
  533. if (s<>'c') or reorder then
  534. begin
  535. i:=Pos(target_info.sharedlibext,S);
  536. if i>0 then
  537. Delete(S,i,255);
  538. Add('-l'+s);
  539. libraryadded:=true;
  540. end
  541. else
  542. linklibc:=true;
  543. end;
  544. { link explicitly against the dyn. linker in case we are using section threadvars and
  545. if we link against any other library. We need __tls_get_addr from the dyn. linker in this case.
  546. This does not hurt as in case we use a dyn. library we depend on the dyn. linker anyways.
  547. All this does not apply if we link anyways against libc }
  548. if libraryadded and not(linklibc) and not(isdll) and (tf_section_threadvars in target_info.flags) then
  549. Add('-l:'+ExtractFileName(defdynlinker));
  550. Add(')');
  551. end
  552. else
  553. linklibc:=true;
  554. if (cs_link_staticflag in current_settings.globalswitches) or
  555. (linklibc and not reorder) then
  556. begin
  557. Add('GROUP(');
  558. { when we have -static for the linker the we also need libgcc }
  559. if (cs_link_staticflag in current_settings.globalswitches) then
  560. begin
  561. Add('-lgcc');
  562. if librarysearchpath.FindFile('libgcc_eh.a',false,s1) then
  563. Add('-lgcc_eh');
  564. end;
  565. { be sure that libc is the last lib }
  566. if linklibc and not reorder then
  567. Add('-lc');
  568. Add(')');
  569. end;
  570. end;
  571. { objects which must be at the end }
  572. if linklibc and (libctype<>uclibc) then
  573. begin
  574. if cs_create_pic in current_settings.moduleswitches then
  575. begin
  576. found1:=librarysearchpath.FindFile('crtendS.o',false,s1);
  577. if not(found1) then
  578. Message1(exec_w_init_file_not_found,'crtendS.o');
  579. end
  580. else
  581. begin
  582. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  583. if not(found1) then
  584. Message1(exec_w_init_file_not_found,'crtend.o');
  585. end;
  586. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  587. if not(found2) then
  588. Message1(exec_w_init_file_not_found,'crtn.o');
  589. if found1 or found2 then
  590. begin
  591. Add('INPUT(');
  592. if found1 then
  593. AddFileName(s1);
  594. if found2 then
  595. AddFileName(s2);
  596. Add(')');
  597. end;
  598. end;
  599. { Entry point. Only needed for executables, as for shared lubraries we use
  600. the -init command line option instead
  601. The "ENTRY" linkerscript command does not have any effect when augmenting
  602. a linker script, so use the command line parameter instead }
  603. if (not isdll) then
  604. if (linksToSharedLibFiles and not linklibc) then
  605. info.ExeCmd[1]:=info.ExeCmd[1]+' -e _dynamic_start'
  606. else
  607. info.ExeCmd[1]:=info.ExeCmd[1]+' -e _start';
  608. { If we are using the default sysroot, use the default linker script and
  609. just augment it with the FPC-specific parts.
  610. }
  611. if sysrootpath='' then
  612. begin
  613. add('SECTIONS');
  614. add('{');
  615. if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) then
  616. { we can't use ".data", as that would hide the .data from the
  617. original linker script in combination with the INSERT at the end }
  618. add(' .fpcdata :')
  619. else
  620. add(' .data :');
  621. add(' {');
  622. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  623. add(' }');
  624. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  625. add('}');
  626. { this "INSERT" means "merge into the original linker script, even if
  627. -T is used" }
  628. if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) then
  629. add('INSERT AFTER .data;');
  630. end
  631. else
  632. begin
  633. {$ifdef x86_64}
  634. {$define LINKERSCRIPT_INCLUDED}
  635. add('SECTIONS');
  636. add('{');
  637. {Read-only sections, merged into text segment:}
  638. if current_module.islibrary then
  639. add(' . = 0 + SIZEOF_HEADERS;')
  640. else
  641. add(' PROVIDE (__executable_start = 0x0400000); . = 0x0400000 + SIZEOF_HEADERS;');
  642. add(' . = 0 + SIZEOF_HEADERS;');
  643. add(' .interp : { *(.interp) }');
  644. add(' .hash : { *(.hash) }');
  645. add(' .dynsym : { *(.dynsym) }');
  646. add(' .dynstr : { *(.dynstr) }');
  647. add(' .gnu.version : { *(.gnu.version) }');
  648. add(' .gnu.version_d : { *(.gnu.version_d) }');
  649. add(' .gnu.version_r : { *(.gnu.version_r) }');
  650. add(' .rel.dyn :');
  651. add(' {');
  652. add(' *(.rel.init)');
  653. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  654. add(' *(.rel.fini)');
  655. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  656. add(' *(.rel.data.rel.ro*)');
  657. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  658. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  659. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  660. add(' *(.rel.got)');
  661. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  662. add(' }');
  663. add(' .rela.dyn :');
  664. add(' {');
  665. add(' *(.rela.init)');
  666. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  667. add(' *(.rela.fini)');
  668. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  669. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  670. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  671. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  672. add(' *(.rela.got)');
  673. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  674. add(' }');
  675. add(' .rel.plt : { *(.rel.plt) }');
  676. add(' .rela.plt : { *(.rela.plt) }');
  677. add(' .init :');
  678. add(' {');
  679. add(' KEEP (*(.init))');
  680. add(' } =0x90909090');
  681. add(' .plt : { *(.plt) }');
  682. add(' .text :');
  683. add(' {');
  684. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  685. add(' KEEP (*(.text.*personality*))');
  686. {.gnu.warning sections are handled specially by elf32.em.}
  687. add(' *(.gnu.warning)');
  688. add(' } =0x90909090');
  689. add(' .fini :');
  690. add(' {');
  691. add(' KEEP (*(.fini))');
  692. add(' } =0x90909090');
  693. add(' PROVIDE (_etext = .);');
  694. add(' .rodata :');
  695. add(' {');
  696. add(' *(.rodata .rodata.* .gnu.linkonce.r.*)');
  697. add(' }');
  698. {Adjust the address for the data segment. We want to adjust up to
  699. the same address within the page on the next page up.}
  700. add(' . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1));');
  701. add(' .dynamic : { *(.dynamic) }');
  702. add(' .got : { *(.got .toc) }');
  703. add(' .got.plt : { *(.got.plt .toc.plt) }');
  704. add(' .data :');
  705. add(' {');
  706. add(' *(.data .data.* .gnu.linkonce.d.*)');
  707. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  708. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  709. add(' }');
  710. add(' PROVIDE (_edata = .);');
  711. add(' PROVIDE (edata = .);');
  712. {$ifdef zsegment_threadvars}
  713. add(' _z = .;');
  714. add(' .threadvar 0 : AT (_z) { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  715. add(' PROVIDE (_threadvar_size = SIZEOF(.threadvar));');
  716. add(' . = _z + SIZEOF (.threadvar);');
  717. {$else}
  718. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  719. {$endif}
  720. add(' __bss_start = .;');
  721. add(' .bss :');
  722. add(' {');
  723. add(' *(.dynbss)');
  724. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  725. add(' *(COMMON)');
  726. {Align here to ensure that the .bss section occupies space up to
  727. _end. Align after .bss to ensure correct alignment even if the
  728. .bss section disappears because there are no input sections.}
  729. add(' . = ALIGN(32 / 8);');
  730. add('}');
  731. add(' . = ALIGN(32 / 8);');
  732. add(' PROVIDE (_end = .);');
  733. add(' PROVIDE (end = .);');
  734. {Stabs debugging sections.}
  735. add(' .stab 0 : { *(.stab) }');
  736. add(' .stabstr 0 : { *(.stabstr) }');
  737. add(' /* DWARF debug sections.');
  738. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  739. add(' of the section so we begin them at 0. */');
  740. add(' /* DWARF 1 */');
  741. add(' .debug 0 : { *(.debug) }');
  742. add(' .line 0 : { *(.line) }');
  743. add(' /* GNU DWARF 1 extensions */');
  744. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  745. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  746. add(' /* DWARF 1.1 and DWARF 2 */');
  747. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  748. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  749. add(' /* DWARF 2 */');
  750. add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  751. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  752. add(' .debug_line 0 : { *(.debug_line) }');
  753. add(' .debug_frame 0 : { *(.debug_frame) }');
  754. add(' .debug_str 0 : { *(.debug_str) }');
  755. add(' .debug_loc 0 : { *(.debug_loc) }');
  756. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  757. add(' /* SGI/MIPS DWARF 2 extensions */');
  758. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  759. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  760. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  761. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  762. add(' /DISCARD/ : { *(.note.GNU-stack) }');
  763. add('}');
  764. {$endif x86_64}
  765. {$ifdef AArch64}
  766. {$define LINKERSCRIPT_INCLUDED}
  767. { Complete linker script for aarch64-linux: }
  768. add('SECTIONS');
  769. add('{');
  770. add(' /* Read-only sections, merged into text segment: */');
  771. add(' PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;');
  772. add(' .interp : { *(.interp) }');
  773. add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  774. add(' .hash : { *(.hash) }');
  775. add(' .gnu.hash : { *(.gnu.hash) }');
  776. add(' .dynsym : { *(.dynsym) }');
  777. add(' .dynstr : { *(.dynstr) }');
  778. add(' .gnu.version : { *(.gnu.version) }');
  779. add(' .gnu.version_d : { *(.gnu.version_d) }');
  780. add(' .gnu.version_r : { *(.gnu.version_r) }');
  781. add(' .rela.dyn :');
  782. add(' {');
  783. add(' *(.rela.init)');
  784. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  785. add(' *(.rela.fini)');
  786. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  787. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  788. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  789. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  790. add(' *(.rela.ctors)');
  791. add(' *(.rela.dtors)');
  792. add(' *(.rela.got)');
  793. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  794. add(' *(.rela.ifunc)');
  795. add(' }');
  796. add(' .rela.plt :');
  797. add(' {');
  798. add(' *(.rela.plt)');
  799. add(' PROVIDE_HIDDEN (__rela_iplt_start = .);');
  800. add(' *(.rela.iplt)');
  801. add(' PROVIDE_HIDDEN (__rela_iplt_end = .);');
  802. add(' }');
  803. add(' .init :');
  804. add(' {');
  805. add(' KEEP (*(SORT_NONE(.init)))');
  806. add(' } =0');
  807. add(' .plt : ALIGN(16) { *(.plt) *(.iplt) }');
  808. add(' .text :');
  809. add(' {');
  810. add(' *(.text.unlikely .text.*_unlikely .text.unlikely.*)');
  811. add(' *(.text.exit .text.exit.*)');
  812. add(' *(.text.startup .text.startup.*)');
  813. add(' *(.text.hot .text.hot.*)');
  814. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  815. add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  816. add(' *(.gnu.warning)');
  817. add(' } =0');
  818. add(' .fini :');
  819. add(' {');
  820. add(' KEEP (*(SORT_NONE(.fini)))');
  821. add(' } =0');
  822. add(' PROVIDE (__etext = .);');
  823. add(' PROVIDE (_etext = .);');
  824. add(' PROVIDE (etext = .);');
  825. add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
  826. add(' .rodata1 : { *(.rodata1) }');
  827. add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  828. add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  829. add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table');
  830. add(' .gcc_except_table.*) }');
  831. add(' /* These sections are generated by the Sun/Oracle C++ compiler. */');
  832. add(' .exception_ranges : ONLY_IF_RO { *(.exception_ranges');
  833. add(' .exception_ranges*) }');
  834. add(' /* Adjust the address for the data segment. We want to adjust up to');
  835. add(' the same address within the page on the next page up. */');
  836. add(' . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));');
  837. add(' /* Exception handling */');
  838. add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  839. add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  840. add(' .exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) }');
  841. add(' /* Thread Local Storage sections */');
  842. add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  843. add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  844. add(' .preinit_array :');
  845. add(' {');
  846. add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
  847. add(' KEEP (*(.preinit_array))');
  848. add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
  849. add(' }');
  850. add(' .init_array :');
  851. add(' {');
  852. add(' PROVIDE_HIDDEN (__init_array_start = .);');
  853. add(' KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))');
  854. add(' KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))');
  855. add(' PROVIDE_HIDDEN (__init_array_end = .);');
  856. add(' }');
  857. add(' .fini_array :');
  858. add(' {');
  859. add(' PROVIDE_HIDDEN (__fini_array_start = .);');
  860. add(' KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))');
  861. add(' KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))');
  862. add(' PROVIDE_HIDDEN (__fini_array_end = .);');
  863. add(' }');
  864. add(' .ctors :');
  865. add(' {');
  866. add(' /* gcc uses crtbegin.o to find the start of');
  867. add(' the constructors, so we make sure it is');
  868. add(' first. Because this is a wildcard, it');
  869. add(' doesn''t matter if the user does not');
  870. add(' actually link against crtbegin.o; the');
  871. add(' linker won''t look for a file to match a');
  872. add(' wildcard. The wildcard also means that it');
  873. add(' doesn''t matter which directory crtbegin.o');
  874. add(' is in. */');
  875. add(' KEEP (*crtbegin.o(.ctors))');
  876. add(' KEEP (*crtbegin?.o(.ctors))');
  877. add(' /* We don''t want to include the .ctor section from');
  878. add(' the crtend.o file until after the sorted ctors.');
  879. add(' The .ctor section from the crtend file contains the');
  880. add(' end of ctors marker and it must be last */');
  881. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
  882. add(' KEEP (*(SORT(.ctors.*)))');
  883. add(' KEEP (*(.ctors))');
  884. add(' }');
  885. add(' .dtors :');
  886. add(' {');
  887. add(' KEEP (*crtbegin.o(.dtors))');
  888. add(' KEEP (*crtbegin?.o(.dtors))');
  889. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
  890. add(' KEEP (*(SORT(.dtors.*)))');
  891. add(' KEEP (*(.dtors))');
  892. add(' }');
  893. add(' .jcr : { KEEP (*(.jcr)) }');
  894. 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.*) }');
  895. add(' .dynamic : { *(.dynamic) }');
  896. add(' .got : { *(.got) *(.igot) }');
  897. add(' . = DATA_SEGMENT_RELRO_END (24, .);');
  898. add(' .got.plt : { *(.got.plt) *(.igot.plt) }');
  899. add(' .data :');
  900. add(' {');
  901. add(' PROVIDE (__data_start = .);');
  902. { extra by FPC }
  903. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  904. add(' *(.data .data.* .gnu.linkonce.d.*)');
  905. add(' SORT(CONSTRUCTORS)');
  906. add(' }');
  907. add(' .data1 : { *(.data1) }');
  908. add(' _edata = .; PROVIDE (edata = .);');
  909. add(' . = .;');
  910. add(' __bss_start = .;');
  911. add(' __bss_start__ = .;');
  912. add(' .bss :');
  913. add(' {');
  914. add(' *(.dynbss)');
  915. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  916. add(' *(COMMON)');
  917. add(' /* Align here to ensure that the .bss section occupies space up to');
  918. add(' _end. Align after .bss to ensure correct alignment even if the');
  919. add(' .bss section disappears because there are no input sections.');
  920. add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
  921. add(' pad the .data section. */');
  922. add(' . = ALIGN(. != 0 ? 64 / 8 : 1);');
  923. add(' }');
  924. add(' _bss_end__ = . ; __bss_end__ = . ;');
  925. add(' . = ALIGN(64 / 8);');
  926. add(' . = SEGMENT_START("ldata-segment", .);');
  927. add(' . = ALIGN(64 / 8);');
  928. add(' __end__ = . ;');
  929. add(' _end = .; PROVIDE (end = .);');
  930. add(' . = DATA_SEGMENT_END (.);');
  931. add(' /* Stabs debugging sections. */');
  932. add(' .stab 0 : { *(.stab) }');
  933. add(' .stabstr 0 : { *(.stabstr) }');
  934. add(' .stab.excl 0 : { *(.stab.excl) }');
  935. add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  936. add(' .stab.index 0 : { *(.stab.index) }');
  937. add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  938. add(' .comment 0 : { *(.comment) }');
  939. add(' /* DWARF debug sections.');
  940. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  941. add(' of the section so we begin them at 0. */');
  942. add(' /* DWARF 1 */');
  943. add(' .debug 0 : { *(.debug) }');
  944. add(' .line 0 : { *(.line) }');
  945. add(' /* GNU DWARF 1 extensions */');
  946. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  947. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  948. add(' /* DWARF 1.1 and DWARF 2 */');
  949. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  950. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  951. add(' /* DWARF 2 */');
  952. add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  953. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  954. add(' .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }');
  955. add(' .debug_frame 0 : { *(.debug_frame) }');
  956. add(' .debug_str 0 : { *(.debug_str) }');
  957. add(' .debug_loc 0 : { *(.debug_loc) }');
  958. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  959. add(' /* SGI/MIPS DWARF 2 extensions */');
  960. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  961. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  962. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  963. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  964. add(' /* DWARF 3 */');
  965. add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  966. add(' .debug_ranges 0 : { *(.debug_ranges) }');
  967. add(' /* DWARF Extension. */');
  968. add(' .debug_macro 0 : { *(.debug_macro) }');
  969. add(' .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }');
  970. add(' .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }');
  971. add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  972. add('}');
  973. {$endif AArch64}
  974. {$ifdef ARM}
  975. if target_info.abi in [abi_eabi,abi_eabihf] then
  976. begin
  977. { from GNU ld (CodeSourcery Sourcery G++ Lite 2007q3-53) 2.18.50.20070820 }
  978. add('/* Script for -z combreloc: combine and sort reloc sections */');
  979. add('OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm",');
  980. add(' "elf32-littlearm")');
  981. add('OUTPUT_ARCH(arm)');
  982. add('SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");');
  983. add('SECTIONS');
  984. add('{');
  985. add(' /* Read-only sections, merged into text segment: */');
  986. add(' PROVIDE (__executable_start = 0x8000); . = 0x8000 + SIZEOF_HEADERS;');
  987. add(' .interp : { *(.interp) }');
  988. add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  989. add(' .hash : { *(.hash) }');
  990. add(' .gnu.hash : { *(.gnu.hash) }');
  991. add(' .dynsym : { *(.dynsym) }');
  992. add(' .dynstr : { *(.dynstr) }');
  993. add(' .gnu.version : { *(.gnu.version) }');
  994. add(' .gnu.version_d : { *(.gnu.version_d) }');
  995. add(' .gnu.version_r : { *(.gnu.version_r) }');
  996. add(' .rel.dyn :');
  997. add(' {');
  998. add(' *(.rel.init)');
  999. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  1000. add(' *(.rel.fini)');
  1001. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  1002. add(' *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*)');
  1003. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  1004. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  1005. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  1006. add(' *(.rel.ctors)');
  1007. add(' *(.rel.dtors)');
  1008. add(' *(.rel.got)');
  1009. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  1010. add(' }');
  1011. add(' .rela.dyn :');
  1012. add(' {');
  1013. add(' *(.rela.init)');
  1014. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  1015. add(' *(.rela.fini)');
  1016. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  1017. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  1018. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  1019. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  1020. add(' *(.rela.ctors)');
  1021. add(' *(.rela.dtors)');
  1022. add(' *(.rela.got)');
  1023. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  1024. add(' }');
  1025. add(' .rel.plt : { *(.rel.plt) }');
  1026. add(' .rela.plt : { *(.rela.plt) }');
  1027. add(' .init :');
  1028. add(' {');
  1029. add(' KEEP (*(.init))');
  1030. add(' } =0');
  1031. add(' .plt : { *(.plt) }');
  1032. add(' .text :');
  1033. add(' {');
  1034. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  1035. add(' KEEP (*(.text.*personality*))');
  1036. add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  1037. add(' *(.gnu.warning)');
  1038. add(' *(.glue_7t) *(.glue_7) *(.vfp11_veneer)');
  1039. add(' } =0');
  1040. add(' .fini :');
  1041. add(' {');
  1042. add(' KEEP (*(.fini))');
  1043. add(' } =0');
  1044. add(' PROVIDE (__etext = .);');
  1045. add(' PROVIDE (_etext = .);');
  1046. add(' PROVIDE (etext = .);');
  1047. add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
  1048. add(' .rodata1 : { *(.rodata1) }');
  1049. add(' .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) }');
  1050. add(' __exidx_start = .;');
  1051. add(' .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }');
  1052. add(' __exidx_end = .;');
  1053. add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  1054. add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  1055. add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }');
  1056. add(' /* Adjust the address for the data segment. We want to adjust up to');
  1057. add(' the same address within the page on the next page up. */');
  1058. add(' . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));');
  1059. add(' /* Exception handling */');
  1060. add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  1061. add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  1062. add(' /* Thread Local Storage sections */');
  1063. add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  1064. add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  1065. add(' .preinit_array :');
  1066. add(' {');
  1067. add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
  1068. add(' KEEP (*(.preinit_array))');
  1069. add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
  1070. add(' }');
  1071. add(' .init_array :');
  1072. add(' {');
  1073. add(' PROVIDE_HIDDEN (__init_array_start = .);');
  1074. add(' KEEP (*(SORT(.init_array.*)))');
  1075. add(' KEEP (*(.init_array))');
  1076. add(' PROVIDE_HIDDEN (__init_array_end = .);');
  1077. add(' }');
  1078. add(' .fini_array :');
  1079. add(' {');
  1080. add(' PROVIDE_HIDDEN (__fini_array_start = .);');
  1081. add(' KEEP (*(.fini_array))');
  1082. add(' KEEP (*(SORT(.fini_array.*)))');
  1083. add(' PROVIDE_HIDDEN (__fini_array_end = .);');
  1084. add(' }');
  1085. add(' .ctors :');
  1086. add(' {');
  1087. add(' /* gcc uses crtbegin.o to find the start of');
  1088. add(' the constructors, so we make sure it is');
  1089. add(' first. Because this is a wildcard, it');
  1090. add(' doesn''t matter if the user does not');
  1091. add(' actually link against crtbegin.o; the');
  1092. add(' linker won''t look for a file to match a');
  1093. add(' wildcard. The wildcard also means that it');
  1094. add(' doesn''t matter which directory crtbegin.o');
  1095. add(' is in. */');
  1096. add(' KEEP (*crtbegin.o(.ctors))');
  1097. add(' KEEP (*crtbegin?.o(.ctors))');
  1098. add(' /* We don''t want to include the .ctor section from');
  1099. add(' the crtend.o file until after the sorted ctors.');
  1100. add(' The .ctor section from the crtend file contains the');
  1101. add(' end of ctors marker and it must be last */');
  1102. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
  1103. add(' KEEP (*(SORT(.ctors.*)))');
  1104. add(' KEEP (*(.ctors))');
  1105. add(' }');
  1106. add(' .dtors :');
  1107. add(' {');
  1108. add(' KEEP (*crtbegin.o(.dtors))');
  1109. add(' KEEP (*crtbegin?.o(.dtors))');
  1110. add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
  1111. add(' KEEP (*(SORT(.dtors.*)))');
  1112. add(' KEEP (*(.dtors))');
  1113. add(' }');
  1114. add(' .jcr : { KEEP (*(.jcr)) }');
  1115. add(' .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }');
  1116. add(' .dynamic : { *(.dynamic) }');
  1117. add(' .got : { *(.got.plt) *(.got) }');
  1118. add(' .data :');
  1119. add(' {');
  1120. add(' __data_start = . ;');
  1121. add(' *(.data .data.* .gnu.linkonce.d.*)');
  1122. { extra by FPC }
  1123. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1124. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  1125. add(' SORT(CONSTRUCTORS)');
  1126. add(' }');
  1127. add(' .data1 : { *(.data1) }');
  1128. add(' _edata = .; PROVIDE (edata = .);');
  1129. add(' __bss_start = .;');
  1130. add(' __bss_start__ = .;');
  1131. add(' .bss :');
  1132. add(' {');
  1133. add(' *(.dynbss)');
  1134. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  1135. add(' *(COMMON)');
  1136. add(' /* Align here to ensure that the .bss section occupies space up to');
  1137. add(' _end. Align after .bss to ensure correct alignment even if the');
  1138. add(' .bss section disappears because there are no input sections.');
  1139. add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
  1140. add(' pad the .data section. */');
  1141. add(' . = ALIGN(. != 0 ? 32 / 8 : 1);');
  1142. add(' }');
  1143. add(' _bss_end__ = . ; __bss_end__ = . ;');
  1144. add(' . = ALIGN(32 / 8);');
  1145. add(' . = ALIGN(32 / 8);');
  1146. add(' __end__ = . ;');
  1147. add(' _end = .; PROVIDE (end = .);');
  1148. add(' /* Stabs debugging sections. */');
  1149. add(' .stab 0 : { *(.stab) }');
  1150. add(' .stabstr 0 : { *(.stabstr) }');
  1151. add(' .stab.excl 0 : { *(.stab.excl) }');
  1152. add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1153. add(' .stab.index 0 : { *(.stab.index) }');
  1154. add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1155. add(' .comment 0 : { *(.comment) }');
  1156. add(' /* DWARF debug sections.');
  1157. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1158. add(' of the section so we begin them at 0. */');
  1159. add(' /* DWARF 1 */');
  1160. add(' .debug 0 : { *(.debug) }');
  1161. add(' .line 0 : { *(.line) }');
  1162. add(' /* GNU DWARF 1 extensions */');
  1163. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1164. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1165. add(' /* DWARF 1.1 and DWARF 2 */');
  1166. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1167. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1168. add(' /* DWARF 2 */');
  1169. add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1170. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1171. add(' .debug_line 0 : { *(.debug_line) }');
  1172. add(' .debug_frame 0 : { *(.debug_frame) }');
  1173. add(' .debug_str 0 : { *(.debug_str) }');
  1174. add(' .debug_loc 0 : { *(.debug_loc) }');
  1175. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1176. add(' /* SGI/MIPS DWARF 2 extensions */');
  1177. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1178. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1179. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1180. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1181. add(' /* DWARF 3 */');
  1182. add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1183. add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1184. add(' .stack 0x80000 :');
  1185. add(' {');
  1186. add(' _stack = .;');
  1187. add(' *(.stack)');
  1188. add(' }');
  1189. add(' .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }');
  1190. add(' .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }');
  1191. add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) }');
  1192. add('}');
  1193. end
  1194. else
  1195. {$endif ARM}
  1196. {$ifndef LINKERSCRIPT_INCLUDED}
  1197. begin
  1198. {Sections.}
  1199. add('SECTIONS');
  1200. add('{');
  1201. {Read-only sections, merged into text segment:}
  1202. add(' PROVIDE (__executable_start = 0x010000); . = 0x010000 + SIZEOF_HEADERS;');
  1203. add(' .interp : { *(.interp) }');
  1204. add(' .hash : { *(.hash) }');
  1205. add(' .dynsym : { *(.dynsym) }');
  1206. add(' .dynstr : { *(.dynstr) }');
  1207. add(' .gnu.version : { *(.gnu.version) }');
  1208. add(' .gnu.version_d : { *(.gnu.version_d) }');
  1209. add(' .gnu.version_r : { *(.gnu.version_r) }');
  1210. add(' .rel.dyn :');
  1211. add(' {');
  1212. add(' *(.rel.init)');
  1213. add(' *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)');
  1214. add(' *(.rel.fini)');
  1215. add(' *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)');
  1216. add(' *(.rel.data.rel.ro*)');
  1217. add(' *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)');
  1218. add(' *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)');
  1219. add(' *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)');
  1220. add(' *(.rel.got)');
  1221. add(' *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)');
  1222. add(' }');
  1223. add(' .rela.dyn :');
  1224. add(' {');
  1225. add(' *(.rela.init)');
  1226. add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  1227. add(' *(.rela.fini)');
  1228. add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  1229. add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  1230. add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  1231. add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  1232. add(' *(.rela.got)');
  1233. add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  1234. add(' }');
  1235. add(' .rel.plt : { *(.rel.plt) }');
  1236. add(' .rela.plt : { *(.rela.plt) }');
  1237. add(' .init :');
  1238. add(' {');
  1239. add(' KEEP (*(.init))');
  1240. add(' } =0x90909090');
  1241. add(' .plt : { *(.plt) }');
  1242. add(' .text :');
  1243. add(' {');
  1244. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  1245. add(' KEEP (*(.text.*personality*))');
  1246. {.gnu.warning sections are handled specially by elf32.em.}
  1247. add(' *(.gnu.warning)');
  1248. add(' } =0x90909090');
  1249. add(' .fini :');
  1250. add(' {');
  1251. add(' KEEP (*(.fini))');
  1252. add(' } =0x90909090');
  1253. add(' PROVIDE (_etext = .);');
  1254. add(' .rodata :');
  1255. add(' {');
  1256. add(' *(.rodata .rodata.* .gnu.linkonce.r.*)');
  1257. add(' }');
  1258. add(' .rodata1 : { *(.rodata1) }');
  1259. add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  1260. add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  1261. add(' .gcc_except_table : { KEEP (*(.gcc_except_table .gcc_except_table.*)) }');
  1262. {Adjust the address for the data segment. We want to adjust up to
  1263. the same address within the page on the next page up.}
  1264. add(' . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1));');
  1265. add(' /* Exception handling */');
  1266. add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  1267. add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  1268. add(' .dynamic : { *(.dynamic) }');
  1269. add(' .got : { *(.got) }');
  1270. add(' .got.plt : { *(.got.plt) }');
  1271. add(' .data :');
  1272. add(' {');
  1273. add(' *(.data .data.* .gnu.linkonce.d.*)');
  1274. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1275. add(' KEEP (*(.gnu.linkonce.d.*personality*))');
  1276. add(' }');
  1277. add(' PROVIDE (_edata = .);');
  1278. add(' PROVIDE (edata = .);');
  1279. {$ifdef zsegment_threadvars}
  1280. add(' _z = .;');
  1281. add(' .threadvar 0 : AT (_z) { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  1282. add(' PROVIDE (_threadvar_size = SIZEOF(.threadvar));');
  1283. add(' . = _z + SIZEOF (.threadvar);');
  1284. {$else}
  1285. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  1286. {$endif}
  1287. add(' __bss_start = .;');
  1288. add(' .bss :');
  1289. add(' {');
  1290. add(' *(.dynbss)');
  1291. add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  1292. add(' *(COMMON)');
  1293. {Align here to ensure that the .bss section occupies space up to
  1294. _end. Align after .bss to ensure correct alignment even if the
  1295. .bss section disappears because there are no input sections.}
  1296. add(' . = ALIGN(32 / 8);');
  1297. add(' }');
  1298. add(' . = ALIGN(32 / 8);');
  1299. add(' PROVIDE (_end = .);');
  1300. add(' PROVIDE (end = .);');
  1301. {Stabs debugging sections.}
  1302. add(' .stab 0 : { *(.stab) }');
  1303. add(' .stabstr 0 : { *(.stabstr) }');
  1304. add('}');
  1305. end;
  1306. {$endif LINKERSCRIPT_INCLUDED}
  1307. end;
  1308. { Write and Close response }
  1309. writetodisk;
  1310. Free;
  1311. end;
  1312. WriteResponseFile:=True;
  1313. end;
  1314. function TLinkerLinux.MakeExecutable:boolean;
  1315. var
  1316. i : longint;
  1317. binstr,
  1318. cmdstr,
  1319. mapstr,
  1320. ltostr : TCmdStr;
  1321. success : boolean;
  1322. DynLinkStr : string;
  1323. GCSectionsStr,
  1324. StaticStr,
  1325. StripStr : string[40];
  1326. begin
  1327. if not(cs_link_nolink in current_settings.globalswitches) then
  1328. Message1(exec_i_linking,current_module.exefilename);
  1329. { Create some replacements }
  1330. StaticStr:='';
  1331. StripStr:='';
  1332. GCSectionsStr:='';
  1333. DynLinkStr:='';
  1334. mapstr:='';
  1335. ltostr:='';
  1336. if (cs_link_staticflag in current_settings.globalswitches) then
  1337. StaticStr:='-static';
  1338. if (cs_link_strip in current_settings.globalswitches) and
  1339. not(cs_link_separate_dbg_file in current_settings.globalswitches) then
  1340. StripStr:='-s';
  1341. if (cs_link_map in current_settings.globalswitches) then
  1342. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  1343. if (cs_link_smart in current_settings.globalswitches) and
  1344. create_smartlink_sections then
  1345. GCSectionsStr:='--gc-sections';
  1346. If (cs_profile in current_settings.moduleswitches) or
  1347. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  1348. begin
  1349. DynLinkStr:='--dynamic-linker='+Info.DynamicLinker;
  1350. if cshared then
  1351. DynLinkStr:=DynLinkStr+' --shared ';
  1352. if rlinkpath<>'' then
  1353. DynLinkStr:=DynLinkStr+' --rpath-link '+rlinkpath;
  1354. End;
  1355. { add custom LTO library if using custom clang }
  1356. if (cs_lto in current_settings.moduleswitches) and
  1357. not(cs_link_on_target in current_settings.globalswitches) and
  1358. (utilsdirectory<>'') and
  1359. FileExists(utilsdirectory+'/../lib/LLVMgold.so',true) then
  1360. begin
  1361. ltostr:='-plugin '+maybequoted(utilsdirectory+'/../lib/LLVMgold.so ');
  1362. end;
  1363. { Write used files and libraries }
  1364. WriteResponseFile(false);
  1365. { Call linker }
  1366. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1367. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  1368. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1369. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1370. Replace(cmdstr,'$STATIC',StaticStr);
  1371. Replace(cmdstr,'$STRIP',StripStr);
  1372. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1373. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1374. Replace(cmdstr,'$MAP',mapstr);
  1375. Replace(cmdstr,'$LTO',ltostr);
  1376. { create dynamic symbol table? }
  1377. if HasExports then
  1378. cmdstr:=cmdstr+' -E';
  1379. { create eh_frame_hdr section? }
  1380. if tf_use_psabieh in target_info.flags then
  1381. cmdstr:=cmdstr+ ' --eh-frame-hdr';
  1382. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  1383. { Create external .dbg file with debuginfo }
  1384. if success and (cs_link_separate_dbg_file in current_settings.globalswitches) then
  1385. begin
  1386. for i:=1 to 3 do
  1387. begin
  1388. SplitBinCmd(Info.ExtDbgCmd[i],binstr,cmdstr);
  1389. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  1390. Replace(cmdstr,'$DBGFN',maybequoted(extractfilename(current_module.dbgfilename)));
  1391. Replace(cmdstr,'$DBGX',current_module.dbgfilename);
  1392. Replace(cmdstr,'$DBG',maybequoted(current_module.dbgfilename));
  1393. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  1394. if not success then
  1395. break;
  1396. end;
  1397. end;
  1398. { Remove ReponseFile }
  1399. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  1400. DeleteFile(outputexedir+Info.ResName);
  1401. MakeExecutable:=success; { otherwise a recursive call to link method }
  1402. end;
  1403. Function TLinkerLinux.MakeSharedLibrary:boolean;
  1404. var
  1405. InitStr,
  1406. FiniStr,
  1407. GCSectionsStr,
  1408. SoNameStr : string[80];
  1409. binstr,
  1410. cmdstr,
  1411. mapstr,
  1412. ltostr : TCmdStr;
  1413. success : boolean;
  1414. begin
  1415. MakeSharedLibrary:=false;
  1416. mapstr:='';
  1417. ltostr:='';
  1418. if not(cs_link_nolink in current_settings.globalswitches) then
  1419. Message1(exec_i_linking,current_module.sharedlibfilename);
  1420. if (cs_link_smart in current_settings.globalswitches) and
  1421. create_smartlink_sections then
  1422. GCSectionsStr:='--gc-sections'
  1423. else
  1424. GCSectionsStr:='';
  1425. { Write used files and libraries }
  1426. WriteResponseFile(true);
  1427. { Create some replacements }
  1428. { note: linux does not use exportlib.initname/fininame due to the custom startup code }
  1429. InitStr:='-init FPC_SHARED_LIB_START';
  1430. FiniStr:='-fini FPC_LIB_EXIT';
  1431. SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename);
  1432. if (cs_link_map in current_settings.globalswitches) then
  1433. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.sharedlibfilename,'.map'));
  1434. { add custom LTO library if using custom clang }
  1435. if (cs_lto in current_settings.moduleswitches) and
  1436. not(cs_link_on_target in current_settings.globalswitches) and
  1437. (utilsdirectory<>'') and
  1438. FileExists(utilsdirectory+'/../lib/LLVMgold.so',true) then
  1439. begin
  1440. ltostr:='-plugin '+maybequoted(utilsdirectory+'/../lib/LLVMgold.so ');
  1441. end;
  1442. { Call linker }
  1443. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  1444. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  1445. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1446. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1447. Replace(cmdstr,'$INIT',InitStr);
  1448. Replace(cmdstr,'$FINI',FiniStr);
  1449. Replace(cmdstr,'$SONAME',SoNameStr);
  1450. Replace(cmdstr,'$MAP',mapstr);
  1451. Replace(cmdstr,'$LTO',ltostr);
  1452. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1453. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  1454. { Strip the library ? }
  1455. if success and (cs_link_strip in current_settings.globalswitches) then
  1456. begin
  1457. { only remove non global symbols and debugging info for a library }
  1458. Info.DllCmd[2]:='strip --discard-all --strip-debug $EXE';
  1459. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  1460. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  1461. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  1462. end;
  1463. { Remove ReponseFile }
  1464. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  1465. DeleteFile(outputexedir+Info.ResName);
  1466. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  1467. end;
  1468. {*****************************************************************************
  1469. TINTERNALLINKERLINUX
  1470. *****************************************************************************}
  1471. constructor TInternalLinkerLinux.Create;
  1472. begin
  1473. inherited Create;
  1474. SetupLibrarySearchPath;
  1475. SetupDynlinker(dynlinker,libctype);
  1476. CArObjectReader:=TArObjectReader;
  1477. CExeOutput:=ElfExeOutputClass;
  1478. CObjInput:=TElfObjInput;
  1479. end;
  1480. procedure TInternalLinkerLinux.InitSysInitUnitName;
  1481. begin
  1482. linklibc:=ModulesLinkToLibc;
  1483. reorder:=linklibc and ReOrderEntries;
  1484. sysinitunit:=defsinames[current_module.islibrary];
  1485. prtobj:=defprtnames[current_module.islibrary];
  1486. if cs_profile in current_settings.moduleswitches then
  1487. begin
  1488. prtobj:=gprtnames[libctype];
  1489. sysinitunit:=gsinames[libctype];
  1490. linklibc:=true;
  1491. end
  1492. else if linklibc then
  1493. begin
  1494. prtobj:=cprtnames[libctype];
  1495. sysinitunit:=csinames[libctype];
  1496. end;
  1497. end;
  1498. const
  1499. relsec_prefix:array[boolean] of TCmdStr = ('rel','rela');
  1500. procedure TInternalLinkerLinux.DefaultLinkScript;
  1501. var
  1502. s,s1,s2,relprefix:TCmdStr;
  1503. found1,found2:boolean;
  1504. linkToSharedLibs:boolean;
  1505. procedure AddLibraryStatement(const s:TCmdStr);
  1506. var
  1507. i:longint;
  1508. s1,s2:TCmdStr;
  1509. begin
  1510. i:=pos(target_info.sharedClibext+'.',s);
  1511. if (i>0) then
  1512. s1:=target_info.sharedClibprefix+S
  1513. else
  1514. s1:=target_info.sharedClibprefix+S+target_info.sharedClibext;
  1515. { TODO: to be compatible with ld search algorithm, each found file
  1516. must be tested for target compatibility, incompatible ones should be skipped. }
  1517. { TODO: shall we search library without suffix if one with suffix is not found? }
  1518. if (not(cs_link_staticflag in current_settings.globalswitches)) and
  1519. FindLibraryFile(s1,'','',s2) then
  1520. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(s2))
  1521. { TODO: static libraries never have numeric suffix in their names }
  1522. else if FindLibraryFile(s,target_info.staticClibprefix,target_info.staticClibext,s2) then
  1523. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(s2))
  1524. else
  1525. Comment(V_Error,'Import library not found for '+S);
  1526. end;
  1527. begin
  1528. if cs_profile in current_settings.moduleswitches then
  1529. begin
  1530. if not(libctype in [glibc2,glibc21]) then
  1531. AddSharedLibrary('gmon');
  1532. AddSharedLibrary('c');
  1533. end;
  1534. TElfExeOutput(exeoutput).interpreter:=stringdup(dynlinker);
  1535. { add objectfiles, start with prt0 always }
  1536. if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
  1537. LinkScript.Concat('READOBJECT '+ maybequoted(FindObjectFile(prtobj,'',false)));
  1538. { try to add crti and crtbegin if linking to C }
  1539. if linklibc and (libctype<>uclibc) then
  1540. begin
  1541. { crti.o must come first }
  1542. if librarysearchpath.FindFile('crti.o',false,s) then
  1543. LinkScript.Concat('READOBJECT '+maybequoted(s));
  1544. { then the crtbegin* }
  1545. if cs_create_pic in current_settings.moduleswitches then
  1546. begin
  1547. if librarysearchpath.FindFile('crtbeginS.o',false,s) then
  1548. LinkScript.Concat('READOBJECT '+maybequoted(s));
  1549. end
  1550. else
  1551. if (cs_link_staticflag in current_settings.globalswitches) and
  1552. librarysearchpath.FindFile('crtbeginT.o',false,s) then
  1553. LinkScript.Concat('READOBJECT '+maybequoted(s))
  1554. else if librarysearchpath.FindFile('crtbegin.o',false,s) then
  1555. LinkScript.Concat('READOBJECT '+maybequoted(s));
  1556. end;
  1557. ScriptAddSourceStatements(false);
  1558. { we must reorder here because the result could empty sharedlibfiles }
  1559. if reorder then
  1560. ExpandAndApplyOrder(SharedLibFiles);
  1561. { See tw9089*.pp: if more than one pure-Pascal shared libs are loaded,
  1562. and none have rtld in their DT_NEEDED, then rtld cannot finalize correctly. }
  1563. if IsSharedLibrary then
  1564. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(sysrootpath+dynlinker));
  1565. linkToSharedLibs:=(not SharedLibFiles.Empty);
  1566. { Symbols declared as "external 'libx.so'" are added to ImportLibraryList, library
  1567. prefix/extension *not* stripped. TImportLibLinux copies these to SharedLibFiles,
  1568. stripping prefixes and extensions.
  1569. However extension won't be stripped if library is specified with numeric suffix
  1570. (like "libpango-1.0.so.0")
  1571. Libraries specified with $LINKLIB directive are directly added to SharedLibFiles
  1572. and won't be present in ImportLibraryList. }
  1573. while not SharedLibFiles.Empty do
  1574. begin
  1575. S:=SharedLibFiles.GetFirst;
  1576. if (S<>'c') or reorder then
  1577. AddLibraryStatement(S);
  1578. end;
  1579. if (cs_link_staticflag in current_settings.globalswitches) or
  1580. (linklibc and not reorder) then
  1581. begin
  1582. LinkScript.Concat('GROUP');
  1583. if (cs_link_staticflag in current_settings.globalswitches) then
  1584. begin
  1585. AddLibraryStatement('gcc');
  1586. AddLibraryStatement('gcc_eh');
  1587. end;
  1588. if linklibc and not reorder then
  1589. AddLibraryStatement('c');
  1590. LinkScript.Concat('ENDGROUP');
  1591. end;
  1592. { objects which must be at the end }
  1593. if linklibc and (libctype<>uclibc) then
  1594. begin
  1595. if cs_create_pic in current_settings.moduleswitches then
  1596. found1:=librarysearchpath.FindFile('crtendS.o',false,s1)
  1597. else
  1598. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  1599. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  1600. if found1 then
  1601. LinkScript.Concat('READOBJECT '+maybequoted(s1));
  1602. if found2 then
  1603. LinkScript.Concat('READOBJECT '+maybequoted(s2));
  1604. end;
  1605. if (not IsSharedLibrary) then
  1606. if (linkToSharedLibs and not linklibc) then
  1607. LinkScript.Concat('ENTRYNAME _dynamic_start')
  1608. else
  1609. LinkScript.Concat('ENTRYNAME _start')
  1610. else
  1611. LinkScript.Concat('ISSHAREDLIBRARY');
  1612. relprefix:=relsec_prefix[ElfTarget.relocs_use_addend];
  1613. with LinkScript do
  1614. begin
  1615. Concat('HEADER');
  1616. Concat('EXESECTION .interp');
  1617. Concat(' OBJSECTION .interp');
  1618. Concat('ENDEXESECTION');
  1619. Concat('EXESECTION .note.ABI-tag');
  1620. Concat(' OBJSECTION .note.ABI-tag');
  1621. Concat('ENDEXESECTION');
  1622. Concat('EXESECTION .note.gnu.build-id');
  1623. Concat(' OBJSECTION .note.gnu.build-id');
  1624. Concat('ENDEXESECTION');
  1625. Concat('EXESECTION .hash');
  1626. Concat(' OBJSECTION .hash');
  1627. Concat('ENDEXESECTION');
  1628. Concat('EXESECTION .dynsym');
  1629. Concat(' OBJSECTION .dynsym');
  1630. Concat('ENDEXESECTION');
  1631. Concat('EXESECTION .dynstr');
  1632. Concat(' OBJSECTION .dynstr');
  1633. Concat('ENDEXESECTION');
  1634. Concat('EXESECTION .gnu.version');
  1635. Concat(' OBJSECTION .gnu.version');
  1636. Concat('ENDEXESECTION');
  1637. Concat('EXESECTION .gnu.version_d');
  1638. Concat(' OBJSECTION .gnu.version_d');
  1639. Concat('ENDEXESECTION');
  1640. Concat('EXESECTION .gnu.version_r');
  1641. Concat(' OBJSECTION .gnu.version_r');
  1642. Concat('ENDEXESECTION');
  1643. Concat('EXESECTION .'+relprefix+'.dyn');
  1644. Concat(' OBJSECTION .'+relprefix+'.dyn');
  1645. Concat('ENDEXESECTION');
  1646. Concat('EXESECTION .'+relprefix+'.plt');
  1647. Concat(' OBJSECTION .'+relprefix+'.plt');
  1648. Concat(' PROVIDE __'+relprefix+'_iplt_start');
  1649. Concat(' OBJSECTION .'+relprefix+'.iplt');
  1650. Concat(' PROVIDE __'+relprefix+'_iplt_end');
  1651. Concat('ENDEXESECTION');
  1652. Concat('EXESECTION .init');
  1653. Concat(' OBJSECTION .init');
  1654. Concat('ENDEXESECTION');
  1655. Concat('EXESECTION .plt');
  1656. Concat(' OBJSECTION .plt');
  1657. Concat('ENDEXESECTION');
  1658. Concat('EXESECTION .text');
  1659. Concat(' OBJSECTION .text*');
  1660. Concat('ENDEXESECTION');
  1661. Concat('EXESECTION .fini');
  1662. Concat(' OBJSECTION .fini');
  1663. Concat(' PROVIDE __etext');
  1664. Concat(' PROVIDE _etext');
  1665. Concat(' PROVIDE etext');
  1666. Concat('ENDEXESECTION');
  1667. Concat('EXESECTION .rodata');
  1668. Concat(' OBJSECTION .rodata*');
  1669. Concat('ENDEXESECTION');
  1670. {$ifdef arm}
  1671. Concat('EXESECTION .ARM.extab');
  1672. Concat(' OBJSECTION .ARM.extab*');
  1673. Concat('ENDEXESECTION');
  1674. Concat('EXESECTION .ARM.exidx');
  1675. Concat(' SYMBOL __exidx_start');
  1676. Concat(' OBJSECTION .ARM.exidx*');
  1677. Concat(' SYMBOL __exidx_end');
  1678. Concat('ENDEXESECTION');
  1679. {$endif}
  1680. Concat('EXESECTION .eh_frame');
  1681. Concat(' OBJSECTION .eh_frame');
  1682. Concat('ENDEXESECTION');
  1683. Concat('EXESECTION .gcc_except_table');
  1684. Concat(' OBJSECTION .gcc_except_table');
  1685. Concat(' OBJSECTION .gcc_except_table.*');
  1686. Concat('ENDEXESECTION');
  1687. Concat('EXESECTION .tdata');
  1688. Concat(' OBJSECTION .tdata');
  1689. Concat(' OBJSECTION .tdata.*');
  1690. Concat('ENDEXESECTION');
  1691. Concat('EXESECTION .tbss');
  1692. Concat(' OBJSECTION .tbss');
  1693. Concat(' OBJSECTION .tbss.*');
  1694. Concat('ENDEXESECTION');
  1695. Concat('EXESECTION .preinit_array');
  1696. Concat(' PROVIDE __preinit_array_start');
  1697. Concat(' OBJSECTION .preinit_array');
  1698. Concat(' PROVIDE __preinit_array_end');
  1699. Concat('ENDEXESECTION');
  1700. Concat('EXESECTION .init_array');
  1701. Concat(' PROVIDE __init_array_start');
  1702. { why the hell .ctors are both here and exesection .ctors below?? }
  1703. // KEEP ( *(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
  1704. Concat(' OBJSECTION .init_array');
  1705. // KEEP ( *(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  1706. Concat('PROVIDE __init_array_end');
  1707. Concat('ENDEXESECTION');
  1708. Concat('EXESECTION .fini_array');
  1709. Concat(' PROVIDE __fini_array_start');
  1710. // KEEP ( *(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
  1711. Concat(' OBJSECTION .fini_array');
  1712. // KEEP ( *(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
  1713. Concat(' PROVIDE __fini_array_end');
  1714. Concat('ENDEXESECTION');
  1715. Concat('EXESECTION .ctors');
  1716. Concat(' OBJSECTION .ctors*');
  1717. Concat('ENDEXESECTION');
  1718. Concat('EXESECTION .dtors');
  1719. Concat(' OBJSECTION .dtors*');
  1720. Concat('ENDEXESECTION');
  1721. Concat('EXESECTION .jcr');
  1722. Concat(' OBJSECTION .jcr');
  1723. Concat('ENDEXESECTION');
  1724. Concat('EXESECTION .dynamic');
  1725. Concat(' OBJSECTION .dynamic');
  1726. Concat('ENDEXESECTION');
  1727. {$ifndef mips}
  1728. Concat('EXESECTION .got');
  1729. {$ifdef arm}
  1730. Concat(' OBJSECTION .got.plt');
  1731. {$endif arm}
  1732. Concat(' OBJSECTION .got');
  1733. Concat('ENDEXESECTION');
  1734. {$endif mips}
  1735. {$ifndef arm}
  1736. Concat('EXESECTION .got.plt');
  1737. Concat(' OBJSECTION .got.plt');
  1738. Concat('ENDEXESECTION');
  1739. {$endif arm}
  1740. Concat('EXESECTION .data');
  1741. Concat(' OBJSECTION .data*');
  1742. Concat(' OBJSECTION .fpc*');
  1743. Concat(' OBJSECTION fpc.resources');
  1744. Concat(' PROVIDE _edata');
  1745. Concat(' PROVIDE edata');
  1746. Concat('ENDEXESECTION');
  1747. {$ifdef mips}
  1748. Concat('EXESECTION .got');
  1749. Concat(' OBJSECTION .got');
  1750. Concat('ENDEXESECTION');
  1751. {$endif mips}
  1752. Concat('EXESECTION .bss');
  1753. Concat(' OBJSECTION .dynbss');
  1754. Concat(' OBJSECTION .bss*');
  1755. Concat(' OBJSECTION fpc.reshandles');
  1756. Concat(' PROVIDE end');
  1757. Concat(' SYMBOL _end');
  1758. Concat('ENDEXESECTION');
  1759. ScriptAddGenericSections('.debug_aranges,.debug_pubnames,.debug_info,'+
  1760. '.debug_abbrev,.debug_line,.debug_frame,.debug_str,.debug_loc,'+
  1761. '.debug_macinfo,.debug_weaknames,.debug_funcnames,.debug_typenames,.debug_varnames,.debug_ranges');
  1762. Concat('EXESECTION .stab');
  1763. Concat(' OBJSECTION .stab');
  1764. Concat('ENDEXESECTION');
  1765. Concat('EXESECTION .stabstr');
  1766. Concat(' OBJSECTION .stabstr');
  1767. Concat('ENDEXESECTION');
  1768. end;
  1769. end;
  1770. {*****************************************************************************
  1771. Initialize
  1772. *****************************************************************************}
  1773. initialization
  1774. RegisterLinker(ld_linux,TLinkerLinux);
  1775. RegisterLinker(ld_int_linux,TInternalLinkerLinux);
  1776. {$ifdef i386}
  1777. RegisterImport(system_i386_linux,timportliblinux);
  1778. RegisterExport(system_i386_linux,texportliblinux);
  1779. RegisterTarget(system_i386_linux_info);
  1780. {$endif i386}
  1781. {$ifdef m68k}
  1782. RegisterImport(system_m68k_linux,timportliblinux);
  1783. RegisterExport(system_m68k_linux,texportliblinux);
  1784. RegisterTarget(system_m68k_linux_info);
  1785. {$endif m68k}
  1786. {$ifdef powerpc}
  1787. RegisterImport(system_powerpc_linux,timportliblinux);
  1788. RegisterExport(system_powerpc_linux,texportliblinux);
  1789. RegisterTarget(system_powerpc_linux_info);
  1790. {$endif powerpc}
  1791. {$ifdef powerpc64}
  1792. { default to little endian either when compiling with -dppc64le, or when
  1793. compiling on a little endian ppc64 platform }
  1794. {$if defined(ppc64le) or (defined(cpupowerpc64) and defined(FPC_LITTLE_ENDIAN))}
  1795. system_powerpc64_linux_info.endian:=endian_little;
  1796. system_powerpc64_linux_info.abi:=abi_powerpc_elfv2;
  1797. {$endif}
  1798. RegisterImport(system_powerpc64_linux,timportliblinux);
  1799. RegisterExport(system_powerpc64_linux,texportliblinux);
  1800. RegisterTarget(system_powerpc64_linux_info);
  1801. {$endif powerpc64}
  1802. {$ifdef x86_64}
  1803. RegisterImport(system_x86_64_linux,timportliblinux);
  1804. RegisterExport(system_x86_64_linux,texportliblinux);
  1805. RegisterTarget(system_x86_64_linux_info);
  1806. RegisterTarget(system_x86_6432_linux_info);
  1807. {$endif x86_64}
  1808. {$ifdef SPARC}
  1809. RegisterImport(system_SPARC_linux,timportliblinux);
  1810. RegisterExport(system_SPARC_linux,texportliblinux);
  1811. RegisterTarget(system_SPARC_linux_info);
  1812. {$endif SPARC}
  1813. {$ifdef SPARC64}
  1814. RegisterImport(system_SPARC64_linux,timportliblinux);
  1815. RegisterExport(system_SPARC64_linux,texportliblinux);
  1816. RegisterTarget(system_SPARC64_linux_info);
  1817. {$endif SPARC64}
  1818. {$ifdef ARM}
  1819. RegisterImport(system_arm_linux,timportliblinux);
  1820. RegisterExport(system_arm_linux,texportliblinux);
  1821. RegisterTarget(system_arm_linux_info);
  1822. {$endif ARM}
  1823. {$ifdef aarch64}
  1824. RegisterImport(system_aarch64_linux,timportliblinux);
  1825. RegisterExport(system_aarch64_linux,texportliblinux);
  1826. RegisterTarget(system_aarch64_linux_info);
  1827. {$endif aarch64}
  1828. {$ifdef MIPS}
  1829. {$ifdef MIPSEL}
  1830. RegisterImport(system_mipsel_linux,timportliblinux);
  1831. RegisterExport(system_mipsel_linux,texportliblinux);
  1832. RegisterTarget(system_mipsel_linux_info);
  1833. {$else MIPS}
  1834. RegisterImport(system_mipseb_linux,timportliblinux);
  1835. RegisterExport(system_mipseb_linux,texportliblinux);
  1836. RegisterTarget(system_mipseb_linux_info);
  1837. {$endif MIPSEL}
  1838. {$endif MIPS}
  1839. {$ifdef riscv32}
  1840. RegisterImport(system_riscv32_linux,timportliblinux);
  1841. RegisterExport(system_riscv32_linux,texportliblinux);
  1842. RegisterTarget(system_riscv32_linux_info);
  1843. {$endif riscv32}
  1844. {$ifdef riscv64}
  1845. RegisterImport(system_riscv64_linux,timportliblinux);
  1846. RegisterExport(system_riscv64_linux,texportliblinux);
  1847. RegisterTarget(system_riscv64_linux_info);
  1848. {$endif riscv64}
  1849. RegisterRes(res_elf_info,TWinLikeResourceFile);
  1850. end.