t_linux.pas 59 KB

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