t_linux.pas 82 KB

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