t_linux.pas 83 KB

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