t_linux.pas 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  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. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib/sparc64-linux-gnu',true);
  167. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib64',true);
  168. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib64',true);
  169. {$endif sparc64}
  170. end;
  171. end;
  172. {$ifdef m68k}
  173. const defdynlinker='/lib/ld.so.1';
  174. {$endif m68k}
  175. {$ifdef i386}
  176. const defdynlinker='/lib/ld-linux.so.2';
  177. {$endif}
  178. {$ifdef x86_64}
  179. const defdynlinker='/lib64/ld-linux-x86-64.so.2';
  180. {$endif x86_64}
  181. {$ifdef sparc}
  182. const defdynlinker='/lib/ld-linux.so.2';
  183. {$endif sparc}
  184. {$ifdef powerpc}
  185. const defdynlinker='/lib/ld.so.1';
  186. {$endif powerpc}
  187. {$ifdef powerpc64}
  188. const defdynlinkerv1='/lib64/ld64.so.1';
  189. const defdynlinkerv2='/lib64/ld64.so.2';
  190. var defdynlinker: string;
  191. {$endif powerpc64}
  192. {$ifdef arm}
  193. {$ifdef FPC_ARMHF}
  194. const defdynlinker='/lib/ld-linux-armhf.so.3';
  195. {$else FPC_ARMHF}
  196. {$ifdef FPC_ARMEL}
  197. const defdynlinker='/lib/ld-linux.so.3';
  198. {$else FPC_ARMEL}
  199. const defdynlinker='/lib/ld-linux.so.2';
  200. {$endif FPC_ARMEL}
  201. {$endif FPC_ARMHF}
  202. {$endif arm}
  203. {$ifdef aarch64}
  204. const defdynlinker='/lib/ld-linux-aarch64.so.1';
  205. {$endif aarch64}
  206. {$ifdef mips}
  207. const defdynlinker='/lib/ld.so.1';
  208. {$endif mips}
  209. {$ifdef sparc64}
  210. const defdynlinker='/lib64/ld-linux.so.2';
  211. {$endif sparc64}
  212. procedure SetupDynlinker(out DynamicLinker:string;out libctype:TLibcType);
  213. begin
  214. {$ifdef powerpc64}
  215. if defdynlinker='' then
  216. if target_info.abi=abi_powerpc_sysv then
  217. defdynlinker:=defdynlinkerv1
  218. else
  219. defdynlinker:=defdynlinkerv2;
  220. {$endif powerpc64}
  221. {
  222. Search order:
  223. glibc 2.1+
  224. uclibc
  225. glibc 2.0
  226. If none is found (e.g. when cross compiling) glibc21 is assumed
  227. }
  228. if fileexists(sysrootpath+defdynlinker,false) then
  229. begin
  230. DynamicLinker:=defdynlinker;
  231. {$ifdef i386}
  232. libctype:=glibc21;
  233. {$else i386}
  234. libctype:=glibc2;
  235. {$endif i386}
  236. end
  237. else if fileexists(sysrootpath+'/lib/ld-uClibc.so.0',false) then
  238. begin
  239. DynamicLinker:='/lib/ld-uClibc.so.0';
  240. libctype:=uclibc;
  241. end
  242. {$ifdef i386}
  243. else if FileExists(sysrootpath+'/lib/ld-linux.so.1',false) then
  244. begin
  245. DynamicLinker:='/lib/ld-linux.so.1';
  246. libctype:=glibc2;
  247. end
  248. {$endif i386}
  249. else
  250. begin
  251. { when no dyn. linker is found, we are probably
  252. cross compiling, so use the default dyn. linker }
  253. DynamicLinker:=defdynlinker;
  254. {
  255. the default c startup script is gcrt0.as on all platforms
  256. except i386
  257. }
  258. {$ifdef i386}
  259. libctype:=glibc21;
  260. {$else i386}
  261. libctype:=glibc2;
  262. {$endif i386}
  263. end;
  264. end;
  265. function ModulesLinkToLibc:boolean;
  266. var
  267. hp: tmodule;
  268. begin
  269. { This is called very early, ImportLibraryList is not yet merged into linkothersharedlibs.
  270. The former contains library names qualified with prefix and suffix (coming from
  271. "external 'c' name 'foo' declarations), the latter contains raw names (from "$linklib c"
  272. directives). }
  273. hp:=tmodule(loaded_units.first);
  274. while assigned(hp) do
  275. begin
  276. result:=Assigned(hp.ImportLibraryList.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext));
  277. if result then break;
  278. result:=hp.linkothersharedlibs.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext);
  279. if result then break;
  280. result:=hp.linkothersharedlibs.find('c');
  281. if result then break;
  282. hp:=tmodule(hp.next);
  283. end;
  284. end;
  285. Constructor TLinkerLinux.Create;
  286. begin
  287. Inherited Create;
  288. SetupLibrarySearchPath;
  289. end;
  290. procedure TLinkerLinux.SetDefaultInfo;
  291. {
  292. This will also detect which libc version will be used
  293. }
  294. const
  295. {$ifdef i386} platform_select='-b elf32-i386 -m elf_i386';{$endif}
  296. {$ifdef x86_64} platform_select='-b elf64-x86-64 -m elf_x86_64';{$endif}
  297. {$ifdef powerpc} platform_select='-b elf32-powerpc -m elf32ppclinux';{$endif}
  298. {$ifdef POWERPC64} platform_select='';{$endif}
  299. {$ifdef sparc} platform_select='-b elf32-sparc -m elf32_sparc';{$endif}
  300. {$ifdef sparc64} platform_select='-b elf64-sparc -m elf64_sparc';{$endif}
  301. {$ifdef arm} platform_select='';{$endif} {unknown :( }
  302. {$ifdef aarch64} platform_select='';{$endif} {unknown :( }
  303. {$ifdef m68k} platform_select='';{$endif} {unknown :( }
  304. {$ifdef mips}
  305. {$ifdef mipsel}
  306. platform_select='-EL';
  307. {$else}
  308. platform_select='-EB';
  309. {$endif}
  310. {$endif}
  311. var
  312. platformopt: string;
  313. begin
  314. platformopt:='';
  315. {$ifdef powerpc64}
  316. if (target_info.abi=abi_powerpc_elfv2) and
  317. (target_info.endian=endian_little) then
  318. platformopt:=' -b elf64-powerpcle -m elf64lppc'
  319. else
  320. platformopt:=' -b elf64-powerpc -m elf64ppc';
  321. {$endif powerpc64}
  322. with Info do
  323. begin
  324. ExeCmd[1]:='ld '+platform_select+platformopt+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE';
  325. DllCmd[1]:='ld '+platform_select+platformopt+' $OPT $INIT $FINI $SONAME $MAP -shared $GCSECTIONS -L. -o $EXE';
  326. { when we want to cross-link we need to override default library paths;
  327. when targeting binutils 2.19 or later, we use the "INSERT" command to
  328. augment the default linkerscript, which also requires -T (normally that
  329. option means "completely replace the default linkerscript) }
  330. if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) or
  331. (length(sysrootpath)>0) then
  332. begin
  333. ExeCmd[1]:=ExeCmd[1]+' -T';
  334. DllCmd[1]:=DllCmd[1]+' -T';
  335. end;
  336. ExeCmd[1]:=ExeCmd[1]+' $RES';
  337. DllCmd[1]:=DllCmd[1]+' $RES';
  338. DllCmd[2]:='strip --strip-unneeded $EXE';
  339. ExtDbgCmd[1]:='objcopy --only-keep-debug $EXE $DBG';
  340. ExtDbgCmd[2]:='objcopy "--add-gnu-debuglink=$DBGX" $EXE';
  341. ExtDbgCmd[3]:='strip --strip-unneeded $EXE';
  342. SetupDynlinker(DynamicLinker,libctype);
  343. end;
  344. end;
  345. procedure TLinkerLinux.LoadPredefinedLibraryOrder;
  346. // put your linkorder/linkalias overrides here.
  347. // Note: assumes only called when reordering/aliasing is used.
  348. Begin
  349. if not (cs_link_no_default_lib_order in current_settings.globalswitches) Then
  350. Begin
  351. LinkLibraryOrder.add('gcc','',15);
  352. LinkLibraryOrder.add('c','',100);
  353. LinkLibraryOrder.add('gmon','',120);
  354. LinkLibraryOrder.add('dl','',140);
  355. LinkLibraryOrder.add('pthread','',160);
  356. end;
  357. End;
  358. type
  359. tlibcnames=array [TLibcType] of string[8];
  360. const { libc5 glibc2 glibc21 uclibc }
  361. cprtnames: tlibcnames = ('cprt0', 'cprt0', 'cprt21', 'ucprt0');
  362. csinames: tlibcnames = ('si_c', 'si_c', 'si_c21', 'si_uc');
  363. gprtnames: tlibcnames = ('gprt0', 'gprt0', 'gprt21', 'ugprt0');
  364. gsinames: tlibcnames = ('si_g', 'si_g', 'si_c21g','si_ucg');
  365. defprtnames: array[boolean] of string[8] = ('prt0', 'dllprt0');
  366. defsinames: array[boolean] of string[8] = ('si_prc','si_dll');
  367. { uclibc and glibc21 are not available on x86_64! si_g is also absent. }
  368. Procedure TLinkerLinux.InitSysInitUnitName;
  369. begin
  370. linklibc:=ModulesLinkToLibc;
  371. reorder:=linklibc and ReOrderEntries;
  372. sysinitunit:=defsinames[current_module.islibrary];
  373. prtobj:=defprtnames[current_module.islibrary];
  374. if current_module.islibrary then
  375. exit;
  376. if cs_profile in current_settings.moduleswitches then
  377. begin
  378. prtobj:=gprtnames[libctype];
  379. sysinitunit:=gsinames[libctype];
  380. linklibc:=true;
  381. end
  382. else if linklibc then
  383. begin
  384. prtobj:=cprtnames[libctype];
  385. sysinitunit:=csinames[libctype];
  386. end;
  387. end;
  388. Function TLinkerLinux.WriteResponseFile(isdll:boolean) : Boolean;
  389. Var
  390. linkres : TLinkRes;
  391. i : longint;
  392. HPath : TCmdStrListItem;
  393. s,s1,s2 : TCmdStr;
  394. found1,
  395. found2 : boolean;
  396. linksToSharedLibFiles : boolean;
  397. begin
  398. result:=False;
  399. { set special options for some targets }
  400. if cs_profile in current_settings.moduleswitches then
  401. begin
  402. if not(libctype in [glibc2,glibc21]) then
  403. AddSharedLibrary('gmon');
  404. AddSharedLibrary('c');
  405. end;
  406. { Open link.res file }
  407. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  408. with linkres do
  409. begin
  410. { Write path to search libraries }
  411. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  412. while assigned(HPath) do
  413. begin
  414. Add('SEARCH_DIR("'+HPath.Str+'")');
  415. HPath:=TCmdStrListItem(HPath.Next);
  416. end;
  417. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  418. while assigned(HPath) do
  419. begin
  420. Add('SEARCH_DIR("'+HPath.Str+'")');
  421. HPath:=TCmdStrListItem(HPath.Next);
  422. end;
  423. { force local symbol resolution (i.e., inside the shared }
  424. { library itself) for all non-exorted symbols, otherwise }
  425. { several RTL symbols of FPC-compiled shared libraries }
  426. { will be bound to those of a single shared library or }
  427. { to the main program }
  428. if (isdll) then
  429. begin
  430. add('VERSION');
  431. add('{');
  432. add(' {');
  433. if not texportlibunix(exportlib).exportedsymnames.empty then
  434. begin
  435. add(' global:');
  436. repeat
  437. add(' '+texportlibunix(exportlib).exportedsymnames.getfirst+';');
  438. until texportlibunix(exportlib).exportedsymnames.empty;
  439. end;
  440. add(' local:');
  441. add(' *;');
  442. add(' };');
  443. add('}');
  444. end;
  445. StartSection('INPUT(');
  446. { add objectfiles, start with prt0 always }
  447. if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
  448. AddFileName(maybequoted(FindObjectFile(prtobj,'',false)));
  449. { try to add crti and crtbegin if linking to C }
  450. if linklibc and (libctype<>uclibc) then
  451. begin
  452. { crti.o must come first }
  453. if librarysearchpath.FindFile('crti.o',false,s) then
  454. AddFileName(s)
  455. else
  456. Message1(exec_w_init_file_not_found,'crti.o');
  457. { then the crtbegin* }
  458. if cs_create_pic in current_settings.moduleswitches then
  459. begin
  460. if librarysearchpath.FindFile('crtbeginS.o',false,s) then
  461. AddFileName(s)
  462. else
  463. Message1(exec_w_init_file_not_found,'crtbeginS.o');
  464. end
  465. else
  466. if (cs_link_staticflag in current_settings.globalswitches) then
  467. begin
  468. if librarysearchpath.FindFile('crtbeginT.o',false,s) then
  469. AddFileName(s)
  470. else
  471. Message1(exec_w_init_file_not_found,'crtbeginT.o');
  472. end
  473. else if librarysearchpath.FindFile('crtbegin.o',false,s) then
  474. AddFileName(s)
  475. else
  476. Message1(exec_w_init_file_not_found,'crtbegin.o');
  477. end;
  478. { main objectfiles }
  479. while not ObjectFiles.Empty do
  480. begin
  481. s:=ObjectFiles.GetFirst;
  482. if s<>'' then
  483. AddFileName(maybequoted(s));
  484. end;
  485. EndSection(')');
  486. { Write staticlibraries }
  487. if not StaticLibFiles.Empty then
  488. begin
  489. Add('GROUP(');
  490. While not StaticLibFiles.Empty do
  491. begin
  492. S:=StaticLibFiles.GetFirst;
  493. AddFileName(maybequoted(s))
  494. end;
  495. Add(')');
  496. end;
  497. // we must reorder here because the result could empty sharedlibfiles
  498. if reorder Then
  499. ExpandAndApplyOrder(SharedLibFiles);
  500. // after this point addition of shared libs not allowed.
  501. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  502. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  503. if isdll and not linklibc then
  504. begin
  505. Add('INPUT(');
  506. Add(sysrootpath+info.DynamicLinker);
  507. Add(')');
  508. end;
  509. linksToSharedLibFiles := not SharedLibFiles.Empty;
  510. if not SharedLibFiles.Empty then
  511. begin
  512. if (SharedLibFiles.Count<>1) or
  513. (TCmdStrListItem(SharedLibFiles.First).Str<>'c') or
  514. reorder then
  515. begin
  516. Add('INPUT(');
  517. While not SharedLibFiles.Empty do
  518. begin
  519. S:=SharedLibFiles.GetFirst;
  520. if (s<>'c') or reorder then
  521. begin
  522. i:=Pos(target_info.sharedlibext,S);
  523. if i>0 then
  524. Delete(S,i,255);
  525. Add('-l'+s);
  526. end
  527. else
  528. begin
  529. linklibc:=true;
  530. end;
  531. end;
  532. Add(')');
  533. end
  534. else
  535. linklibc:=true;
  536. if (cs_link_staticflag in current_settings.globalswitches) or
  537. (linklibc and not reorder) then
  538. begin
  539. Add('GROUP(');
  540. { when we have -static for the linker the we also need libgcc }
  541. if (cs_link_staticflag in current_settings.globalswitches) then
  542. begin
  543. Add('-lgcc');
  544. if librarysearchpath.FindFile('libgcc_eh.a',false,s1) then
  545. Add('-lgcc_eh');
  546. end;
  547. { be sure that libc is the last lib }
  548. if linklibc and not reorder then
  549. Add('-lc');
  550. Add(')');
  551. end;
  552. end;
  553. { objects which must be at the end }
  554. if linklibc and (libctype<>uclibc) then
  555. begin
  556. if cs_create_pic in current_settings.moduleswitches then
  557. begin
  558. found1:=librarysearchpath.FindFile('crtendS.o',false,s1);
  559. if not(found1) then
  560. Message1(exec_w_init_file_not_found,'crtendS.o');
  561. end
  562. else
  563. begin
  564. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  565. if not(found1) then
  566. Message1(exec_w_init_file_not_found,'crtend.o');
  567. end;
  568. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  569. if not(found2) then
  570. Message1(exec_w_init_file_not_found,'crtn.o');
  571. if found1 or found2 then
  572. begin
  573. Add('INPUT(');
  574. if found1 then
  575. AddFileName(s1);
  576. if found2 then
  577. AddFileName(s2);
  578. Add(')');
  579. end;
  580. end;
  581. { Entry point. Only needed for executables, as for shared lubraries we use
  582. the -init command line option instead
  583. The "ENTRY" linkerscript command does not have any effect when augmenting
  584. a linker script, so use the command line parameter instead }
  585. if (not isdll) then
  586. if (linksToSharedLibFiles and not linklibc) then
  587. info.ExeCmd[1]:=info.ExeCmd[1]+' -e _dynamic_start'
  588. else
  589. info.ExeCmd[1]:=info.ExeCmd[1]+' -e _start';
  590. add('SECTIONS');
  591. add('{');
  592. if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) then
  593. { we can't use ".data", as that would hide the .data from the
  594. original linker script in combination with the INSERT at the end }
  595. add(' .fpcdata :')
  596. else
  597. add(' .data :');
  598. add(' {');
  599. add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  600. add(' }');
  601. add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }');
  602. add('}');
  603. { this "INSERT" means "merge into the original linker script, even if
  604. -T is used" }
  605. if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) then
  606. add('INSERT AFTER .data;');
  607. { Write and Close response }
  608. writetodisk;
  609. Free;
  610. end;
  611. WriteResponseFile:=True;
  612. end;
  613. function TLinkerLinux.MakeExecutable:boolean;
  614. var
  615. i : longint;
  616. binstr,
  617. cmdstr,
  618. mapstr : TCmdStr;
  619. success : boolean;
  620. DynLinkStr : string;
  621. GCSectionsStr,
  622. StaticStr,
  623. StripStr : string[40];
  624. begin
  625. if not(cs_link_nolink in current_settings.globalswitches) then
  626. Message1(exec_i_linking,current_module.exefilename);
  627. { Create some replacements }
  628. StaticStr:='';
  629. StripStr:='';
  630. GCSectionsStr:='';
  631. DynLinkStr:='';
  632. mapstr:='';
  633. if (cs_link_staticflag in current_settings.globalswitches) then
  634. StaticStr:='-static';
  635. if (cs_link_strip in current_settings.globalswitches) and
  636. not(cs_link_separate_dbg_file in current_settings.globalswitches) then
  637. StripStr:='-s';
  638. if (cs_link_map in current_settings.globalswitches) then
  639. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  640. if (cs_link_smart in current_settings.globalswitches) and
  641. create_smartlink_sections then
  642. GCSectionsStr:='--gc-sections';
  643. If (cs_profile in current_settings.moduleswitches) or
  644. ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
  645. begin
  646. DynLinkStr:='--dynamic-linker='+Info.DynamicLinker;
  647. if cshared then
  648. DynLinkStr:=DynLinkStr+' --shared ';
  649. if rlinkpath<>'' then
  650. DynLinkStr:=DynLinkStr+' --rpath-link '+rlinkpath;
  651. End;
  652. { Write used files and libraries }
  653. WriteResponseFile(false);
  654. { Call linker }
  655. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  656. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  657. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  658. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  659. Replace(cmdstr,'$STATIC',StaticStr);
  660. Replace(cmdstr,'$STRIP',StripStr);
  661. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  662. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  663. Replace(cmdstr,'$MAP',mapstr);
  664. { create dynamic symbol table? }
  665. if HasExports then
  666. cmdstr:=cmdstr+' -E';
  667. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  668. { Create external .dbg file with debuginfo }
  669. if success and (cs_link_separate_dbg_file in current_settings.globalswitches) then
  670. begin
  671. for i:=1 to 3 do
  672. begin
  673. SplitBinCmd(Info.ExtDbgCmd[i],binstr,cmdstr);
  674. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  675. Replace(cmdstr,'$DBGFN',maybequoted(extractfilename(current_module.dbgfilename)));
  676. Replace(cmdstr,'$DBGX',current_module.dbgfilename);
  677. Replace(cmdstr,'$DBG',maybequoted(current_module.dbgfilename));
  678. success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
  679. if not success then
  680. break;
  681. end;
  682. end;
  683. { Remove ReponseFile }
  684. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  685. DeleteFile(outputexedir+Info.ResName);
  686. MakeExecutable:=success; { otherwise a recursive call to link method }
  687. end;
  688. Function TLinkerLinux.MakeSharedLibrary:boolean;
  689. var
  690. InitStr,
  691. FiniStr,
  692. GCSectionsStr,
  693. SoNameStr : string[80];
  694. binstr,
  695. cmdstr,
  696. mapstr : TCmdStr;
  697. success : boolean;
  698. begin
  699. MakeSharedLibrary:=false;
  700. mapstr:='';
  701. if not(cs_link_nolink in current_settings.globalswitches) then
  702. Message1(exec_i_linking,current_module.sharedlibfilename);
  703. if (cs_link_smart in current_settings.globalswitches) and
  704. create_smartlink_sections then
  705. GCSectionsStr:='--gc-sections'
  706. else
  707. GCSectionsStr:='';
  708. { Write used files and libraries }
  709. WriteResponseFile(true);
  710. { Create some replacements }
  711. { note: linux does not use exportlib.initname/fininame due to the custom startup code }
  712. InitStr:='-init FPC_SHARED_LIB_START';
  713. FiniStr:='-fini FPC_LIB_EXIT';
  714. SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename);
  715. if (cs_link_map in current_settings.globalswitches) then
  716. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.sharedlibfilename,'.map'));
  717. { Call linker }
  718. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  719. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  720. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  721. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  722. Replace(cmdstr,'$INIT',InitStr);
  723. Replace(cmdstr,'$FINI',FiniStr);
  724. Replace(cmdstr,'$SONAME',SoNameStr);
  725. Replace(cmdstr,'$MAP',mapstr);
  726. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  727. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  728. { Strip the library ? }
  729. if success and (cs_link_strip in current_settings.globalswitches) then
  730. begin
  731. { only remove non global symbols and debugging info for a library }
  732. Info.DllCmd[2]:='strip --discard-all --strip-debug $EXE';
  733. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  734. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  735. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  736. end;
  737. { Remove ReponseFile }
  738. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  739. DeleteFile(outputexedir+Info.ResName);
  740. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  741. end;
  742. {*****************************************************************************
  743. TINTERNALLINKERLINUX
  744. *****************************************************************************}
  745. constructor TInternalLinkerLinux.Create;
  746. begin
  747. inherited Create;
  748. SetupLibrarySearchPath;
  749. SetupDynlinker(dynlinker,libctype);
  750. CArObjectReader:=TArObjectReader;
  751. CExeOutput:=ElfExeOutputClass;
  752. CObjInput:=TElfObjInput;
  753. end;
  754. procedure TInternalLinkerLinux.InitSysInitUnitName;
  755. begin
  756. linklibc:=ModulesLinkToLibc;
  757. reorder:=linklibc and ReOrderEntries;
  758. sysinitunit:=defsinames[current_module.islibrary];
  759. prtobj:=defprtnames[current_module.islibrary];
  760. if cs_profile in current_settings.moduleswitches then
  761. begin
  762. prtobj:=gprtnames[libctype];
  763. sysinitunit:=gsinames[libctype];
  764. linklibc:=true;
  765. end
  766. else if linklibc then
  767. begin
  768. prtobj:=cprtnames[libctype];
  769. sysinitunit:=csinames[libctype];
  770. end;
  771. end;
  772. const
  773. relsec_prefix:array[boolean] of TCmdStr = ('rel','rela');
  774. procedure TInternalLinkerLinux.DefaultLinkScript;
  775. var
  776. s,s1,s2,relprefix:TCmdStr;
  777. found1,found2:boolean;
  778. linkToSharedLibs:boolean;
  779. procedure AddLibraryStatement(const s:TCmdStr);
  780. var
  781. i:longint;
  782. s1,s2:TCmdStr;
  783. begin
  784. i:=pos(target_info.sharedClibext+'.',s);
  785. if (i>0) then
  786. s1:=target_info.sharedClibprefix+S
  787. else
  788. s1:=target_info.sharedClibprefix+S+target_info.sharedClibext;
  789. { TODO: to be compatible with ld search algorithm, each found file
  790. must be tested for target compatibility, incompatible ones should be skipped. }
  791. { TODO: shall we search library without suffix if one with suffix is not found? }
  792. if (not(cs_link_staticflag in current_settings.globalswitches)) and
  793. FindLibraryFile(s1,'','',s2) then
  794. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(s2))
  795. { TODO: static libraries never have numeric suffix in their names }
  796. else if FindLibraryFile(s,target_info.staticClibprefix,target_info.staticClibext,s2) then
  797. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(s2))
  798. else
  799. Comment(V_Error,'Import library not found for '+S);
  800. end;
  801. begin
  802. if cs_profile in current_settings.moduleswitches then
  803. begin
  804. if not(libctype in [glibc2,glibc21]) then
  805. AddSharedLibrary('gmon');
  806. AddSharedLibrary('c');
  807. end;
  808. TElfExeOutput(exeoutput).interpreter:=stringdup(dynlinker);
  809. { add objectfiles, start with prt0 always }
  810. if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
  811. LinkScript.Concat('READOBJECT '+ maybequoted(FindObjectFile(prtobj,'',false)));
  812. { try to add crti and crtbegin if linking to C }
  813. if linklibc and (libctype<>uclibc) then
  814. begin
  815. { crti.o must come first }
  816. if librarysearchpath.FindFile('crti.o',false,s) then
  817. LinkScript.Concat('READOBJECT '+maybequoted(s));
  818. { then the crtbegin* }
  819. if cs_create_pic in current_settings.moduleswitches then
  820. begin
  821. if librarysearchpath.FindFile('crtbeginS.o',false,s) then
  822. LinkScript.Concat('READOBJECT '+maybequoted(s));
  823. end
  824. else
  825. if (cs_link_staticflag in current_settings.globalswitches) and
  826. librarysearchpath.FindFile('crtbeginT.o',false,s) then
  827. LinkScript.Concat('READOBJECT '+maybequoted(s))
  828. else if librarysearchpath.FindFile('crtbegin.o',false,s) then
  829. LinkScript.Concat('READOBJECT '+maybequoted(s));
  830. end;
  831. ScriptAddSourceStatements(false);
  832. { we must reorder here because the result could empty sharedlibfiles }
  833. if reorder then
  834. ExpandAndApplyOrder(SharedLibFiles);
  835. { See tw9089*.pp: if more than one pure-Pascal shared libs are loaded,
  836. and none have rtld in their DT_NEEDED, then rtld cannot finalize correctly. }
  837. if IsSharedLibrary then
  838. LinkScript.Concat('READSTATICLIBRARY '+maybequoted(sysrootpath+dynlinker));
  839. linkToSharedLibs:=(not SharedLibFiles.Empty);
  840. { Symbols declared as "external 'libx.so'" are added to ImportLibraryList, library
  841. prefix/extension *not* stripped. TImportLibLinux copies these to SharedLibFiles,
  842. stripping prefixes and extensions.
  843. However extension won't be stripped if library is specified with numeric suffix
  844. (like "libpango-1.0.so.0")
  845. Libraries specified with $LINKLIB directive are directly added to SharedLibFiles
  846. and won't be present in ImportLibraryList. }
  847. while not SharedLibFiles.Empty do
  848. begin
  849. S:=SharedLibFiles.GetFirst;
  850. if (S<>'c') or reorder then
  851. AddLibraryStatement(S);
  852. end;
  853. if (cs_link_staticflag in current_settings.globalswitches) or
  854. (linklibc and not reorder) then
  855. begin
  856. LinkScript.Concat('GROUP');
  857. if (cs_link_staticflag in current_settings.globalswitches) then
  858. begin
  859. AddLibraryStatement('gcc');
  860. AddLibraryStatement('gcc_eh');
  861. end;
  862. if linklibc and not reorder then
  863. AddLibraryStatement('c');
  864. LinkScript.Concat('ENDGROUP');
  865. end;
  866. { objects which must be at the end }
  867. if linklibc and (libctype<>uclibc) then
  868. begin
  869. if cs_create_pic in current_settings.moduleswitches then
  870. found1:=librarysearchpath.FindFile('crtendS.o',false,s1)
  871. else
  872. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  873. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  874. if found1 then
  875. LinkScript.Concat('READOBJECT '+maybequoted(s1));
  876. if found2 then
  877. LinkScript.Concat('READOBJECT '+maybequoted(s2));
  878. end;
  879. if (not IsSharedLibrary) then
  880. if (linkToSharedLibs and not linklibc) then
  881. LinkScript.Concat('ENTRYNAME _dynamic_start')
  882. else
  883. LinkScript.Concat('ENTRYNAME _start')
  884. else
  885. LinkScript.Concat('ISSHAREDLIBRARY');
  886. relprefix:=relsec_prefix[ElfTarget.relocs_use_addend];
  887. with LinkScript do
  888. begin
  889. Concat('HEADER');
  890. Concat('EXESECTION .interp');
  891. Concat(' OBJSECTION .interp');
  892. Concat('ENDEXESECTION');
  893. Concat('EXESECTION .note.ABI-tag');
  894. Concat(' OBJSECTION .note.ABI-tag');
  895. Concat('ENDEXESECTION');
  896. Concat('EXESECTION .note.gnu.build-id');
  897. Concat(' OBJSECTION .note.gnu.build-id');
  898. Concat('ENDEXESECTION');
  899. Concat('EXESECTION .hash');
  900. Concat(' OBJSECTION .hash');
  901. Concat('ENDEXESECTION');
  902. Concat('EXESECTION .dynsym');
  903. Concat(' OBJSECTION .dynsym');
  904. Concat('ENDEXESECTION');
  905. Concat('EXESECTION .dynstr');
  906. Concat(' OBJSECTION .dynstr');
  907. Concat('ENDEXESECTION');
  908. Concat('EXESECTION .gnu.version');
  909. Concat(' OBJSECTION .gnu.version');
  910. Concat('ENDEXESECTION');
  911. Concat('EXESECTION .gnu.version_d');
  912. Concat(' OBJSECTION .gnu.version_d');
  913. Concat('ENDEXESECTION');
  914. Concat('EXESECTION .gnu.version_r');
  915. Concat(' OBJSECTION .gnu.version_r');
  916. Concat('ENDEXESECTION');
  917. Concat('EXESECTION .'+relprefix+'.dyn');
  918. Concat(' OBJSECTION .'+relprefix+'.dyn');
  919. Concat('ENDEXESECTION');
  920. Concat('EXESECTION .'+relprefix+'.plt');
  921. Concat(' OBJSECTION .'+relprefix+'.plt');
  922. Concat(' PROVIDE __'+relprefix+'_iplt_start');
  923. Concat(' OBJSECTION .'+relprefix+'.iplt');
  924. Concat(' PROVIDE __'+relprefix+'_iplt_end');
  925. Concat('ENDEXESECTION');
  926. Concat('EXESECTION .init');
  927. Concat(' OBJSECTION .init');
  928. Concat('ENDEXESECTION');
  929. Concat('EXESECTION .plt');
  930. Concat(' OBJSECTION .plt');
  931. Concat('ENDEXESECTION');
  932. Concat('EXESECTION .text');
  933. Concat(' OBJSECTION .text*');
  934. Concat('ENDEXESECTION');
  935. Concat('EXESECTION .fini');
  936. Concat(' OBJSECTION .fini');
  937. Concat(' PROVIDE __etext');
  938. Concat(' PROVIDE _etext');
  939. Concat(' PROVIDE etext');
  940. Concat('ENDEXESECTION');
  941. Concat('EXESECTION .rodata');
  942. Concat(' OBJSECTION .rodata*');
  943. Concat('ENDEXESECTION');
  944. {$ifdef arm}
  945. Concat('EXESECTION .ARM.extab');
  946. Concat(' OBJSECTION .ARM.extab*');
  947. Concat('ENDEXESECTION');
  948. Concat('EXESECTION .ARM.exidx');
  949. Concat(' SYMBOL __exidx_start');
  950. Concat(' OBJSECTION .ARM.exidx*');
  951. Concat(' SYMBOL __exidx_end');
  952. Concat('ENDEXESECTION');
  953. {$endif}
  954. Concat('EXESECTION .eh_frame');
  955. Concat(' OBJSECTION .eh_frame');
  956. Concat('ENDEXESECTION');
  957. Concat('EXESECTION .gcc_except_table');
  958. Concat(' OBJSECTION .gcc_except_table');
  959. Concat(' OBJSECTION .gcc_except_table.*');
  960. Concat('ENDEXESECTION');
  961. Concat('EXESECTION .tdata');
  962. Concat(' OBJSECTION .tdata');
  963. Concat(' OBJSECTION .tdata.*');
  964. Concat('ENDEXESECTION');
  965. Concat('EXESECTION .tbss');
  966. Concat(' OBJSECTION .tbss');
  967. Concat(' OBJSECTION .tbss.*');
  968. Concat('ENDEXESECTION');
  969. Concat('EXESECTION .preinit_array');
  970. Concat(' PROVIDE __preinit_array_start');
  971. Concat(' OBJSECTION .preinit_array');
  972. Concat(' PROVIDE __preinit_array_end');
  973. Concat('ENDEXESECTION');
  974. Concat('EXESECTION .init_array');
  975. Concat(' PROVIDE __init_array_start');
  976. { why the hell .ctors are both here and exesection .ctors below?? }
  977. // KEEP ( *(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
  978. Concat(' OBJSECTION .init_array');
  979. // KEEP ( *(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  980. Concat('PROVIDE __init_array_end');
  981. Concat('ENDEXESECTION');
  982. Concat('EXESECTION .fini_array');
  983. Concat(' PROVIDE __fini_array_start');
  984. // KEEP ( *(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
  985. Concat(' OBJSECTION .fini_array');
  986. // KEEP ( *(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
  987. Concat(' PROVIDE __fini_array_end');
  988. Concat('ENDEXESECTION');
  989. Concat('EXESECTION .ctors');
  990. Concat(' OBJSECTION .ctors*');
  991. Concat('ENDEXESECTION');
  992. Concat('EXESECTION .dtors');
  993. Concat(' OBJSECTION .dtors*');
  994. Concat('ENDEXESECTION');
  995. Concat('EXESECTION .jcr');
  996. Concat(' OBJSECTION .jcr');
  997. Concat('ENDEXESECTION');
  998. Concat('EXESECTION .dynamic');
  999. Concat(' OBJSECTION .dynamic');
  1000. Concat('ENDEXESECTION');
  1001. {$ifndef mips}
  1002. Concat('EXESECTION .got');
  1003. {$ifdef arm}
  1004. Concat(' OBJSECTION .got.plt');
  1005. {$endif arm}
  1006. Concat(' OBJSECTION .got');
  1007. Concat('ENDEXESECTION');
  1008. {$endif mips}
  1009. {$ifndef arm}
  1010. Concat('EXESECTION .got.plt');
  1011. Concat(' OBJSECTION .got.plt');
  1012. Concat('ENDEXESECTION');
  1013. {$endif arm}
  1014. Concat('EXESECTION .data');
  1015. Concat(' OBJSECTION .data*');
  1016. Concat(' OBJSECTION .fpc*');
  1017. Concat(' OBJSECTION fpc.resources');
  1018. Concat(' PROVIDE _edata');
  1019. Concat(' PROVIDE edata');
  1020. Concat('ENDEXESECTION');
  1021. {$ifdef mips}
  1022. Concat('EXESECTION .got');
  1023. Concat(' OBJSECTION .got');
  1024. Concat('ENDEXESECTION');
  1025. {$endif mips}
  1026. Concat('EXESECTION .bss');
  1027. Concat(' OBJSECTION .dynbss');
  1028. Concat(' OBJSECTION .bss*');
  1029. Concat(' OBJSECTION fpc.reshandles');
  1030. Concat(' PROVIDE end');
  1031. Concat(' SYMBOL _end');
  1032. Concat('ENDEXESECTION');
  1033. ScriptAddGenericSections('.debug_aranges,.debug_pubnames,.debug_info,'+
  1034. '.debug_abbrev,.debug_line,.debug_frame,.debug_str,.debug_loc,'+
  1035. '.debug_macinfo,.debug_weaknames,.debug_funcnames,.debug_typenames,.debug_varnames,.debug_ranges');
  1036. Concat('EXESECTION .stab');
  1037. Concat(' OBJSECTION .stab');
  1038. Concat('ENDEXESECTION');
  1039. Concat('EXESECTION .stabstr');
  1040. Concat(' OBJSECTION .stabstr');
  1041. Concat('ENDEXESECTION');
  1042. end;
  1043. end;
  1044. {*****************************************************************************
  1045. Initialize
  1046. *****************************************************************************}
  1047. initialization
  1048. RegisterLinker(ld_linux,TLinkerLinux);
  1049. RegisterLinker(ld_int_linux,TInternalLinkerLinux);
  1050. {$ifdef i386}
  1051. RegisterImport(system_i386_linux,timportliblinux);
  1052. RegisterExport(system_i386_linux,texportliblinux);
  1053. RegisterTarget(system_i386_linux_info);
  1054. {$endif i386}
  1055. {$ifdef m68k}
  1056. RegisterImport(system_m68k_linux,timportliblinux);
  1057. RegisterExport(system_m68k_linux,texportliblinux);
  1058. RegisterTarget(system_m68k_linux_info);
  1059. {$endif m68k}
  1060. {$ifdef powerpc}
  1061. RegisterImport(system_powerpc_linux,timportliblinux);
  1062. RegisterExport(system_powerpc_linux,texportliblinux);
  1063. RegisterTarget(system_powerpc_linux_info);
  1064. {$endif powerpc}
  1065. {$ifdef powerpc64}
  1066. { default to little endian either when compiling with -dppc64le, or when
  1067. compiling on a little endian ppc64 platform }
  1068. {$if defined(ppc64le) or (defined(cpupowerpc64) and defined(FPC_LITTLE_ENDIAN))}
  1069. system_powerpc64_linux_info.endian:=endian_little;
  1070. system_powerpc64_linux_info.abi:=abi_powerpc_elfv2;
  1071. {$endif}
  1072. RegisterImport(system_powerpc64_linux,timportliblinux);
  1073. RegisterExport(system_powerpc64_linux,texportliblinux);
  1074. RegisterTarget(system_powerpc64_linux_info);
  1075. {$endif powerpc64}
  1076. {$ifdef x86_64}
  1077. RegisterImport(system_x86_64_linux,timportliblinux);
  1078. RegisterExport(system_x86_64_linux,texportliblinux);
  1079. RegisterTarget(system_x86_64_linux_info);
  1080. RegisterTarget(system_x86_6432_linux_info);
  1081. {$endif x86_64}
  1082. {$ifdef SPARC}
  1083. RegisterImport(system_SPARC_linux,timportliblinux);
  1084. RegisterExport(system_SPARC_linux,texportliblinux);
  1085. RegisterTarget(system_SPARC_linux_info);
  1086. {$endif SPARC}
  1087. {$ifdef SPARC64}
  1088. RegisterImport(system_SPARC64_linux,timportliblinux);
  1089. RegisterExport(system_SPARC64_linux,texportliblinux);
  1090. RegisterTarget(system_SPARC64_linux_info);
  1091. {$endif SPARC64}
  1092. {$ifdef ARM}
  1093. RegisterImport(system_arm_linux,timportliblinux);
  1094. RegisterExport(system_arm_linux,texportliblinux);
  1095. RegisterTarget(system_arm_linux_info);
  1096. {$endif ARM}
  1097. {$ifdef aarch64}
  1098. RegisterImport(system_aarch64_linux,timportliblinux);
  1099. RegisterExport(system_aarch64_linux,texportliblinux);
  1100. RegisterTarget(system_aarch64_linux_info);
  1101. {$endif aarch64}
  1102. {$ifdef MIPS}
  1103. {$ifdef MIPSEL}
  1104. RegisterImport(system_mipsel_linux,timportliblinux);
  1105. RegisterExport(system_mipsel_linux,texportliblinux);
  1106. RegisterTarget(system_mipsel_linux_info);
  1107. {$else MIPS}
  1108. RegisterImport(system_mipseb_linux,timportliblinux);
  1109. RegisterExport(system_mipseb_linux,texportliblinux);
  1110. RegisterTarget(system_mipseb_linux_info);
  1111. {$endif MIPSEL}
  1112. {$endif MIPS}
  1113. RegisterRes(res_elf_info,TWinLikeResourceFile);
  1114. end.