t_linux.pas 76 KB

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