t_linux.pas 41 KB

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