t_linux.pas 76 KB

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