t_linux.pas 83 KB

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