t_bsd.pas 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. {
  2. Copyright (c) 1998-2002 by Peter Vreman (original Linux)
  3. (c) 2000 by Marco van de Voort (FreeBSD mods)
  4. This unit implements support import,export,link routines
  5. for the (i386)FreeBSD target
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit t_bsd;
  20. {$i fpcdefs.inc}
  21. interface
  22. implementation
  23. uses
  24. sysutils,
  25. cutils,cfileutl,cclasses,
  26. verbose,systems,globtype,globals,
  27. symconst,cscript,
  28. fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,symsym,symdef,
  29. import,export,link,comprsrc,rescmn,i_bsd,expunix,
  30. cgutils,cgbase,cgobj,cpuinfo,ogbase;
  31. type
  32. timportlibdarwin=class(timportlib)
  33. procedure generatelib;override;
  34. end;
  35. timportlibbsd=class(timportlib)
  36. procedure generatelib;override;
  37. end;
  38. texportlibbsd=class(texportlibunix)
  39. end;
  40. texportlibdarwin=class(texportlibbsd)
  41. procedure setinitname(list: TAsmList; const s: string); override;
  42. procedure setfininame(list: TAsmList; const s: string); override;
  43. end;
  44. tlinkerbsd=class(texternallinker)
  45. private
  46. LdSupportsNoResponseFile : boolean;
  47. LibrarySuffix : Char;
  48. prtobj : string[80];
  49. ReOrder : Boolean;
  50. linklibc : boolean;
  51. Function WriteResponseFile(isdll:boolean) : Boolean;
  52. function GetDarwinCrt1ObjName(isdll: boolean): TCmdStr;
  53. Function GetDarwinPrtobjName(isdll: boolean): TCmdStr;
  54. Function WriteSymbolOrderFile: TCmdStr;
  55. public
  56. constructor Create;override;
  57. procedure SetDefaultInfo;override;
  58. function MakeExecutable:boolean;override;
  59. function MakeSharedLibrary:boolean;override;
  60. procedure LoadPredefinedLibraryOrder; override;
  61. procedure InitSysInitUnitName; override;
  62. end;
  63. function ModulesLinkToLibc:boolean;
  64. var
  65. hp: tmodule;
  66. begin
  67. { This is called very early, ImportLibraryList is not yet merged into linkothersharedlibs.
  68. The former contains library names qualified with prefix and suffix (coming from
  69. "external 'c' name 'foo' declarations), the latter contains raw names (from "$linklib c"
  70. directives). }
  71. hp:=tmodule(loaded_units.first);
  72. while assigned(hp) do
  73. begin
  74. result:=Assigned(hp.ImportLibraryList.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext));
  75. if result then break;
  76. result:=hp.linkothersharedlibs.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext);
  77. if result then break;
  78. result:=hp.linkothersharedlibs.find('c');
  79. if result then break;
  80. hp:=tmodule(hp.next);
  81. end;
  82. end;
  83. {*****************************************************************************
  84. TIMPORTLIBDARWIN
  85. *****************************************************************************}
  86. procedure timportlibdarwin.generatelib;
  87. begin
  88. end;
  89. {*****************************************************************************
  90. TEXPORTLIBDARWIN
  91. *****************************************************************************}
  92. procedure texportlibdarwin.setinitname(list: TAsmList; const s: string);
  93. begin
  94. new_section(list,sec_init_func,'',sizeof(pint));
  95. list.concat(Tai_const.Createname(s,0));
  96. end;
  97. procedure texportlibdarwin.setfininame(list: TAsmList; const s: string);
  98. begin
  99. new_section(list,sec_term_func,'',sizeof(pint));
  100. list.concat(Tai_const.Createname(s,0));
  101. end;
  102. {*****************************************************************************
  103. TIMPORTLIBBSD
  104. *****************************************************************************}
  105. procedure timportlibbsd.generatelib;
  106. var
  107. i : longint;
  108. ImportLibrary : TImportLibrary;
  109. begin
  110. for i:=0 to current_module.ImportLibraryList.Count-1 do
  111. begin
  112. ImportLibrary:=TImportLibrary(current_module.ImportLibraryList[i]);
  113. current_module.linkothersharedlibs.add(ImportLibrary.Name,link_always);
  114. end;
  115. end;
  116. {*****************************************************************************
  117. TLINKERBSD
  118. *****************************************************************************}
  119. Constructor TLinkerBSD.Create;
  120. begin
  121. Inherited Create;
  122. if not Dontlinkstdlibpath Then
  123. if target_info.system in systems_darwin then
  124. { Mac OS X doesn't have a /lib }
  125. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib',true)
  126. else if target_info.system in systems_openbsd then
  127. LibrarySearchPath.AddPath(sysrootpath,'/usr/lib;$OPENBSD_X11BASE/lib;$OPENBSD_LOCALBASE/lib',true)
  128. else
  129. LibrarySearchPath.AddPath(sysrootpath,'/lib;/usr/lib;/usr/X11R6/lib',true);
  130. end;
  131. procedure TLinkerBSD.SetDefaultInfo;
  132. {
  133. This will also detect which libc version will be used
  134. }
  135. var
  136. LdProgram: string='ld';
  137. begin
  138. if target_info.system in systems_openbsd then
  139. LdProgram:='ld.bfd';
  140. LibrarySuffix:=' ';
  141. LdSupportsNoResponseFile := (target_info.system in ([system_m68k_netbsd]+systems_darwin));
  142. with Info do
  143. begin
  144. if LdSupportsNoResponseFile then
  145. begin
  146. if not(target_info.system in systems_darwin) then
  147. begin
  148. ExeCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP $ORDERSYMS -L. -o $EXE $CATRES $FILELIST';
  149. DllCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $MAP $ORDERSYMS -shared -L. -o $EXE $CATRES $FILELIST'
  150. end
  151. else
  152. begin
  153. {$ifndef cpu64bitaddr}
  154. { Set the size of the page at address zero to 64kb, so nothing
  155. is loaded below that address. This avoids problems with the
  156. strange Windows-compatible resource handling that assumes
  157. that addresses below 64kb do not exist.
  158. On 64bit systems, page zero is 4GB by default, so no problems
  159. there.
  160. }
  161. { In case of valgrind, don't do that, because it cannot deal with
  162. a custom pagezero size -- in general, this should not cause any
  163. problems because the resources are added at the end and most
  164. programs with problems that require Valgrind will have more
  165. than 60KB of data (first 4KB of address space is always invalid)
  166. }
  167. ExeCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP $ORDERSYMS -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
  168. if not(cs_gdb_valgrind in current_settings.globalswitches) then
  169. ExeCmd[1]:=ExeCmd[1]+' -pagezero_size 0x10000';
  170. {$else ndef cpu64bitaddr}
  171. ExeCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP $ORDERSYMS -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
  172. {$endif ndef cpu64bitaddr}
  173. if (apptype<>app_bundle) then
  174. DllCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS $MAP $ORDERSYMS -dynamic -dylib -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
  175. else
  176. DllCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS $MAP $ORDERSYMS -dynamic -bundle -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
  177. end
  178. end
  179. else
  180. begin
  181. ExeCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP $ORDERSYMS -L. -o $EXE $RES';
  182. DllCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $INIT $FINI $SONAME $MAP $ORDERSYMS -shared -L. -o $EXE $RES';
  183. end;
  184. if not(target_info.system in systems_darwin) then
  185. DllCmd[2]:='strip --strip-unneeded $EXE'
  186. else
  187. DllCmd[2]:='strip -x $EXE';
  188. { OpenBSD seems to use a wrong dynamic linker by default }
  189. if target_info.system in systems_openbsd then
  190. DynamicLinker:='/usr/libexec/ld.so'
  191. else if target_info.system in systems_netbsd then
  192. DynamicLinker:='/usr/libexec/ld.elf_so'
  193. else if target_info.system=system_x86_64_dragonfly then
  194. DynamicLinker:='/libexec/ld-elf.so.2'
  195. else
  196. DynamicLinker:='';
  197. end;
  198. end;
  199. procedure TLinkerBSD.LoadPredefinedLibraryOrder;
  200. // put your linkorder/linkalias overrides here.
  201. // Note: assumes only called when reordering/aliasing is used.
  202. Begin
  203. if not(target_info.system in systems_darwin) then
  204. begin
  205. if (target_info.system =system_i386_freebsd) and
  206. not (cs_link_no_default_lib_order in current_settings.globalswitches) Then
  207. Begin
  208. LinkLibraryOrder.add('gcc','',15);
  209. LinkLibraryOrder.add('c','',50); // c and c_p mutual. excl?
  210. LinkLibraryOrder.add('c_p','',55);
  211. LinkLibraryOrder.add('pthread','',75); // pthread and c_r should be mutually exclusive
  212. LinkLibraryOrder.add('c_r','',76);
  213. LinkLibraryOrder.add('kvm','',80); // must be before ncurses
  214. if (cs_link_pthread in current_settings.globalswitches) Then // convert libpthread to libc_r.
  215. LinkLibraryAliases.add('pthread','c_r');
  216. end;
  217. end
  218. else
  219. begin
  220. LinkLibraryOrder.add('gcc','',15);
  221. LinkLibraryOrder.add('c','',50);
  222. end;
  223. End;
  224. procedure TLinkerBSD.InitSysInitUnitName;
  225. var
  226. cprtobj,
  227. gprtobj,
  228. si_cprt,
  229. si_gprt : string[80];
  230. begin
  231. if target_info.system in systems_darwin then
  232. begin
  233. { for darwin: always link dynamically against libc }
  234. linklibc := true;
  235. reorder:=reorderentries;
  236. prtobj:='';
  237. SysInitUnit:='sysinit';
  238. end
  239. else
  240. begin
  241. linklibc:=ModulesLinkToLibc;
  242. if current_module.islibrary and
  243. (target_info.system in systems_bsd) then
  244. begin
  245. prtobj:='dllprt0';
  246. cprtobj:='dllprt0';
  247. gprtobj:='dllprt0';
  248. SysInitUnit:='si_dll';
  249. si_cprt:='si_dll';
  250. si_gprt:='si_dll';
  251. end
  252. else
  253. begin
  254. prtobj:='prt0';
  255. cprtobj:='cprt0';
  256. gprtobj:='gprt0';
  257. SysInitUnit:='si_prc';
  258. si_cprt:='si_c';
  259. si_gprt:='si_g';
  260. end;
  261. // this one is a bit complex.
  262. // Only reorder for now if -XL or -XO params are given
  263. // or when -Xf.
  264. reorder:= linklibc and
  265. (
  266. ReorderEntries
  267. or
  268. (cs_link_pthread in current_settings.globalswitches));
  269. if cs_profile in current_settings.moduleswitches then
  270. begin
  271. prtobj:=gprtobj;
  272. SysInitUnit:=si_gprt;
  273. AddSharedLibrary('c');
  274. LibrarySuffix:='p';
  275. linklibc:=true;
  276. end
  277. else
  278. begin
  279. if linklibc then
  280. begin
  281. prtobj:=cprtobj;
  282. SysInitUnit:=si_cprt;
  283. end;
  284. end;
  285. end;
  286. end;
  287. function TLinkerBSD.GetDarwinCrt1ObjName(isdll: boolean): TCmdStr;
  288. begin
  289. if not isdll then
  290. begin
  291. if not(cs_profile in current_settings.moduleswitches) then
  292. begin
  293. case target_info.system of
  294. system_powerpc_darwin,
  295. system_powerpc64_darwin,
  296. system_i386_darwin,
  297. system_x86_64_darwin:
  298. begin
  299. { 10.8 and later: no crt1.* }
  300. if CompareVersionStrings(MacOSXVersionMin,'10.8')>=0 then
  301. exit('');
  302. { x86: crt1.10.6.o -> crt1.10.5.o -> crt1.o }
  303. { others: crt1.10.5 -> crt1.o }
  304. if (target_info.system in [system_i386_darwin,system_x86_64_darwin]) and
  305. (CompareVersionStrings(MacOSXVersionMin,'10.6')>=0) then
  306. exit('crt1.10.6.o');
  307. if CompareVersionStrings(MacOSXVersionMin,'10.5')>=0 then
  308. exit('crt1.10.5.o');
  309. end;
  310. system_arm_darwin:
  311. begin
  312. { iOS:
  313. iOS 6 and later: nothing
  314. iOS 3.1 - 5.x: crt1.3.1.o
  315. pre-iOS 3.1: crt1.o
  316. }
  317. if (CompareVersionStrings(iPhoneOSVersionMin,'6.0')>=0) then
  318. exit('');
  319. if (CompareVersionStrings(iPhoneOSVersionMin,'3.1')>=0) then
  320. exit('crt1.3.1.o');
  321. end;
  322. system_i386_iphonesim,
  323. system_x86_64_iphonesim:
  324. begin
  325. { "recent versions" must not use anything (https://github.com/llvm-mirror/clang/commit/e6d04f3d152a22077022cf9287d4c538a0918ab0 )
  326. What those recent versions could be, is anyone's guess. It
  327. still seems to work with 8.1 and no longer with 8.3, so use
  328. 8.1 as a cut-off point }
  329. if (CompareVersionStrings(iPhoneOSVersionMin,'8.1')>0) then
  330. exit('');
  331. end;
  332. system_aarch64_darwin:
  333. { never anything }
  334. exit('');
  335. else
  336. Internalerror(2019050709);
  337. end;
  338. { nothing special -> default }
  339. result:='crt1.o';
  340. end
  341. else
  342. begin
  343. result:='gcrt1.o';
  344. { 10.8 and later: tell the linker to use 'start' instead of "_main"
  345. as entry point }
  346. if CompareVersionStrings(MacOSXVersionMin,'10.8')>=0 then
  347. Info.ExeCmd[1]:=Info.ExeCmd[1]+' -no_new_main';
  348. end;
  349. end
  350. else
  351. begin
  352. if (apptype=app_bundle) then
  353. begin
  354. case target_info.system of
  355. system_powerpc_darwin,
  356. system_powerpc64_darwin,
  357. system_i386_darwin,
  358. system_x86_64_darwin:
  359. begin
  360. { < 10.6: bundle1.o
  361. >= 10.6: nothing }
  362. if CompareVersionStrings(MacOSXVersionMin,'10.6')>=0 then
  363. exit('');
  364. end;
  365. system_arm_darwin,
  366. system_aarch64_darwin:
  367. begin
  368. { iOS: < 3.1: bundle1.o
  369. >= 3.1: nothing }
  370. if (CompareVersionStrings(iPhoneOSVersionMin,'3.1')>=0) then
  371. exit('');
  372. end;
  373. system_i386_iphonesim,
  374. system_x86_64_iphonesim:
  375. begin
  376. { see rule for crt1.o }
  377. if (CompareVersionStrings(iPhoneOSVersionMin,'8.1')>0) then
  378. exit('');
  379. end;
  380. else
  381. Internalerror(2019050710);
  382. end;
  383. result:='bundle1.o';
  384. end
  385. else
  386. begin
  387. case target_info.system of
  388. system_powerpc_darwin,
  389. system_powerpc64_darwin,
  390. system_i386_darwin,
  391. system_x86_64_darwin:
  392. begin
  393. { >= 10.6: nothing
  394. = 10.5: dylib1.10.5.o
  395. < 10.5: dylib1.o
  396. }
  397. if CompareVersionStrings(MacOSXVersionMin,'10.6')>=0 then
  398. exit('');
  399. if CompareVersionStrings(MacOSXVersionMin,'10.5')>=0 then
  400. exit('dylib1.10.5.o');
  401. end;
  402. system_arm_darwin,
  403. system_aarch64_darwin:
  404. begin
  405. { iOS: < 3.1: dylib1.o
  406. >= 3.1: nothing }
  407. if (CompareVersionStrings(iPhoneOSVersionMin,'3.1')>=0) then
  408. exit('');
  409. end;
  410. system_i386_iphonesim,
  411. system_x86_64_iphonesim:
  412. begin
  413. { see rule for crt1.o }
  414. if (CompareVersionStrings(iPhoneOSVersionMin,'8.1')>0) then
  415. exit('');
  416. end;
  417. else
  418. Internalerror(2019050711);
  419. end;
  420. result:='dylib1.o';
  421. end;
  422. end;
  423. end;
  424. Function TLinkerBSD.GetDarwinPrtobjName(isdll: boolean): TCmdStr;
  425. var
  426. startupfile: TCmdStr;
  427. begin
  428. result:='';
  429. startupfile:=GetDarwinCrt1ObjName(isdll);
  430. if startupfile<>'' then
  431. begin
  432. if not librarysearchpath.FindFile(startupfile,false,result) then
  433. result:='/usr/lib/'+startupfile;
  434. end;
  435. result:=maybequoted(result);
  436. end;
  437. function tlinkerbsd.WriteSymbolOrderFile: TCmdStr;
  438. var
  439. item: TCmdStrListItem;
  440. symfile: TScript;
  441. begin
  442. result:='';
  443. { only for darwin for now; can also enable for other platforms when using
  444. the LLVM linker }
  445. if (OrderedSymbols.Empty) or
  446. not(tf_supports_symbolorderfile in target_info.flags) then
  447. exit;
  448. symfile:=TScript.Create(outputexedir+'symbol_order.fpc');
  449. item:=TCmdStrListItem(OrderedSymbols.First);
  450. while assigned(item) do
  451. begin
  452. symfile.add(item.str);
  453. item:=TCmdStrListItem(item.next);
  454. end;
  455. symfile.WriteToDisk;
  456. result:=symfile.fn;
  457. symfile.Free;
  458. end;
  459. Function TLinkerBSD.WriteResponseFile(isdll:boolean) : Boolean;
  460. Var
  461. linkres : TLinkRes;
  462. FilesList : TLinkRes;
  463. i : longint;
  464. HPath : TCmdStrListItem;
  465. s,s1,s2 : TCmdStr;
  466. linkdynamic : boolean;
  467. Fl1,Fl2 : Boolean;
  468. IsDarwin : Boolean;
  469. begin
  470. WriteResponseFile:=False;
  471. ReOrder:=False;
  472. linkdynamic:=False;
  473. IsDarwin:=target_info.system in systems_darwin;
  474. { set special options for some targets }
  475. if not IsDarwin Then
  476. begin
  477. linkdynamic:=not(SharedLibFiles.empty);
  478. // after this point addition of shared libs not allowed.
  479. end
  480. else
  481. begin
  482. {$ifdef MACOSX104ORHIGHER}
  483. { not sure what this is for, but gcc always links against it }
  484. if not(cs_profile in current_settings.moduleswitches) then
  485. AddSharedLibrary('SystemStubs')
  486. else
  487. AddSharedLibrary('SystemStubs_profile');
  488. {$endif MACOSX104ORHIGHER}
  489. end;
  490. if reorder Then
  491. ExpandAndApplyOrder(SharedLibFiles);
  492. { Open link.res file }
  493. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,not LdSupportsNoResponseFile);
  494. if (target_info.system in systems_darwin) and
  495. (sysrootpath<>'') then
  496. begin
  497. LinkRes.Add('-syslibroot');
  498. LinkRes.Add(sysrootpath);
  499. end;
  500. if (target_info.system in systems_darwin) then
  501. begin
  502. LinkRes.Add('-arch');
  503. case target_info.system of
  504. system_powerpc_darwin:
  505. LinkRes.Add('ppc');
  506. system_i386_darwin,
  507. system_i386_iphonesim:
  508. LinkRes.Add('i386');
  509. system_powerpc64_darwin:
  510. LinkRes.Add('ppc64');
  511. system_x86_64_darwin,
  512. system_x86_64_iphonesim:
  513. LinkRes.Add('x86_64');
  514. system_arm_darwin:
  515. { current versions of the linker require the sub-architecture type
  516. to be specified }
  517. LinkRes.Add(lower(cputypestr[current_settings.cputype]));
  518. system_aarch64_darwin:
  519. LinkRes.Add('arm64');
  520. else
  521. internalerror(2014121801);
  522. end;
  523. if MacOSXVersionMin<>'' then
  524. begin
  525. LinkRes.Add('-macosx_version_min');
  526. LinkRes.Add(MacOSXVersionMin);
  527. end
  528. else if iPhoneOSVersionMin<>'' then
  529. begin
  530. LinkRes.Add('-iphoneos_version_min');
  531. LinkRes.Add(iPhoneOSVersionMin);
  532. end;
  533. end;
  534. { Write path to search libraries }
  535. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  536. while assigned(HPath) do
  537. begin
  538. if LdSupportsNoResponseFile then
  539. LinkRes.Add('-L'+HPath.Str)
  540. else
  541. LinkRes.Add('SEARCH_DIR("'+HPath.Str+'")');
  542. HPath:=TCmdStrListItem(HPath.Next);
  543. end;
  544. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  545. while assigned(HPath) do
  546. begin
  547. if LdSupportsNoResponseFile then
  548. LinkRes.Add('-L'+HPath.Str)
  549. else
  550. LinkRes.Add('SEARCH_DIR("'+HPath.Str+'")');
  551. HPath:=TCmdStrListItem(HPath.Next);
  552. end;
  553. if (target_info.system in systems_darwin) then
  554. begin
  555. HPath:=TCmdStrListItem(current_module.localframeworksearchpath.First);
  556. while assigned(HPath) do
  557. begin
  558. LinkRes.Add('-F'+HPath.Str);
  559. HPath:=TCmdStrListItem(HPath.Next);
  560. end;
  561. HPath:=TCmdStrListItem(FrameworkSearchPath.First);
  562. while assigned(HPath) do
  563. begin
  564. LinkRes.Add('-F'+HPath.Str);
  565. HPath:=TCmdStrListItem(HPath.Next);
  566. end;
  567. end;
  568. { force local symbol resolution (i.e., inside the shared }
  569. { library itself) for all non-exorted symbols, otherwise }
  570. { several RTL symbols of FPC-compiled shared libraries }
  571. { will be bound to those of a single shared library or }
  572. { to the main program }
  573. if (isdll) and (target_info.system in systems_bsd) then
  574. begin
  575. LinkRes.add('VERSION');
  576. LinkRes.add('{');
  577. LinkRes.add(' {');
  578. if not texportlibunix(exportlib).exportedsymnames.empty then
  579. begin
  580. LinkRes.add(' global:');
  581. repeat
  582. LinkRes.add(' '+texportlibunix(exportlib).exportedsymnames.getfirst+';');
  583. until texportlibunix(exportlib).exportedsymnames.empty;
  584. end;
  585. LinkRes.add(' local:');
  586. LinkRes.add(' *;');
  587. LinkRes.add(' };');
  588. LinkRes.add('}');
  589. end;
  590. if not LdSupportsNoResponseFile then
  591. LinkRes.Add('INPUT(');
  592. { add objectfiles, start with prt0 always }
  593. if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
  594. LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
  595. { try to add crti and crtbegin if linking to C }
  596. if linklibc and
  597. not IsDarwin Then
  598. begin
  599. if librarysearchpath.FindFile('crti.o',false,s) then
  600. LinkRes.AddFileName(s);
  601. if ((cs_create_pic in current_settings.moduleswitches) and
  602. not (target_info.system in systems_openbsd)) or
  603. (current_module.islibrary and
  604. (target_info.system in systems_openbsd)) then
  605. begin
  606. if librarysearchpath.FindFile('crtbeginS.o',false,s) then
  607. LinkRes.AddFileName(s);
  608. end
  609. else
  610. if (cs_link_staticflag in current_settings.globalswitches) and
  611. librarysearchpath.FindFile('crtbeginT.o',false,s) then
  612. LinkRes.AddFileName(s)
  613. else if librarysearchpath.FindFile('crtbegin.o',false,s) then
  614. LinkRes.AddFileName(s);
  615. end;
  616. { main objectfiles }
  617. { Generate linkfiles.res file if needed }
  618. { Only needed on Windows, due to the limitation of 8196 characters for command line }
  619. if (LdSupportsNoResponseFile) and
  620. (source_info.system in systems_all_windows) then
  621. begin
  622. FilesList:=TLinkRes.Create(outputexedir+'linkfiles.res',false);
  623. while not ObjectFiles.Empty do
  624. begin
  625. s:=ObjectFiles.GetFirst;
  626. if s<>'' then
  627. begin
  628. repeat
  629. i:=Pos(source_info.dirsep,s);
  630. if i>0 then
  631. s[i]:=target_info.dirsep;
  632. until i=0;
  633. FilesList.Add(s);
  634. end;
  635. end;
  636. FilesList.writetodisk;
  637. FilesList.Free;
  638. end
  639. else
  640. begin
  641. while not ObjectFiles.Empty do
  642. begin
  643. s:=ObjectFiles.GetFirst;
  644. if s<>'' then
  645. if LdSupportsNoResponseFile then
  646. LinkRes.AddFileName(s)
  647. else
  648. LinkRes.AddFileName(maybequoted(s));
  649. end;
  650. end;
  651. if not LdSupportsNoResponseFile then
  652. LinkRes.Add(')');
  653. { Write staticlibraries }
  654. if not StaticLibFiles.Empty then
  655. begin
  656. if not LdSupportsNoResponseFile then
  657. LinkRes.Add('GROUP(');
  658. While not StaticLibFiles.Empty do
  659. begin
  660. S:=StaticLibFiles.GetFirst;
  661. if LdSupportsNoResponseFile then
  662. LinkRes.AddFileName(s)
  663. else
  664. LinkRes.AddFileName(maybequoted(s))
  665. end;
  666. if not LdSupportsNoResponseFile then
  667. LinkRes.Add(')');
  668. end;
  669. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  670. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  671. if not SharedLibFiles.Empty then
  672. begin
  673. if not LdSupportsNoResponseFile then
  674. LinkRes.Add('INPUT(');
  675. While not SharedLibFiles.Empty do
  676. begin
  677. S:=SharedLibFiles.GetFirst;
  678. if (s<>'c') or reorder then
  679. begin
  680. i:=Pos(target_info.sharedlibext,S);
  681. if i>0 then
  682. Delete(S,i,255);
  683. LinkRes.Add('-l'+s);
  684. end
  685. else
  686. begin
  687. linklibc:=true;
  688. linkdynamic:=false; { libc will include the ld-* for us }
  689. end;
  690. end;
  691. { be sure that libc is the last lib }
  692. if linklibc and not reorder then
  693. Begin
  694. If LibrarySuffix=' ' Then
  695. LinkRes.Add('-lc')
  696. else
  697. LinkRes.Add('-lc_'+LibrarySuffix);
  698. If LibrarySuffix='r' Then
  699. LinkRes.Add('-lc');
  700. end;
  701. { when we have -static for the linker the we also need libgcc }
  702. if (cs_link_staticflag in current_settings.globalswitches) then
  703. LinkRes.Add('-lgcc');
  704. if linkdynamic and (Info.DynamicLinker<>'') and
  705. not(target_info.system in systems_openbsd) then
  706. LinkRes.AddFileName(Info.DynamicLinker);
  707. if not LdSupportsNoResponseFile then
  708. LinkRes.Add(')');
  709. end;
  710. { frameworks for Darwin }
  711. if IsDarwin then
  712. while not FrameworkFiles.empty do
  713. begin
  714. LinkRes.Add('-framework');
  715. LinkRes.Add(FrameworkFiles.GetFirst);
  716. end;
  717. { objects which must be at the end }
  718. if linklibc and
  719. not IsDarwin Then
  720. begin
  721. if ((cs_create_pic in current_settings.moduleswitches) and
  722. not (target_info.system in systems_openbsd)) or
  723. (current_module.islibrary and
  724. (target_info.system in systems_openbsd)) then
  725. Fl1:=librarysearchpath.FindFile('crtendS.o',false,s1)
  726. else
  727. Fl1:=librarysearchpath.FindFile('crtend.o',false,s1);
  728. Fl2:=librarysearchpath.FindFile('crtn.o',false,s2);
  729. if Fl1 or Fl2 then
  730. begin
  731. LinkRes.Add('INPUT(');
  732. If Fl1 Then
  733. LinkRes.AddFileName(s1);
  734. If Fl2 Then
  735. LinkRes.AddFileName(s2);
  736. LinkRes.Add(')');
  737. end;
  738. end;
  739. { Write and Close response }
  740. linkres.writetodisk;
  741. linkres.Free;
  742. WriteResponseFile:=True;
  743. end;
  744. function TLinkerBSD.MakeExecutable:boolean;
  745. var
  746. binstr,
  747. cmdstr,
  748. mapstr,
  749. targetstr,
  750. emulstr,
  751. extdbgbinstr,
  752. extdbgcmdstr,
  753. ordersymfile: TCmdStr;
  754. linkscript: TAsmScript;
  755. DynLinkStr : string[60];
  756. GCSectionsStr,
  757. StaticStr,
  758. StripStr : string[63];
  759. success,
  760. useshell : boolean;
  761. begin
  762. if not(cs_link_nolink in current_settings.globalswitches) then
  763. Message1(exec_i_linking,current_module.exefilename);
  764. { Create some replacements }
  765. StaticStr:='';
  766. StripStr:='';
  767. DynLinkStr:='';
  768. GCSectionsStr:='';
  769. linkscript:=nil;
  770. mapstr:='';
  771. if (cs_link_map in current_settings.globalswitches) then
  772. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  773. { i386_freebsd needs -b elf32-i386-freebsd and -m elf_i386_fbsd
  774. to avoid creation of a i386:x86_64 arch binary }
  775. if target_info.system=system_i386_freebsd then
  776. begin
  777. targetstr:='-b elf32-i386-freebsd';
  778. emulstr:='-m elf_i386_fbsd';
  779. end
  780. else
  781. begin
  782. targetstr:='';
  783. emulstr:='';
  784. end;
  785. if (cs_link_staticflag in current_settings.globalswitches) then
  786. begin
  787. if (target_info.system=system_m68k_netbsd) and
  788. ((cs_link_on_target in current_settings.globalswitches) or
  789. (target_info.system=source_info.system)) then
  790. StaticStr:='-Bstatic'
  791. else
  792. StaticStr:='-static';
  793. end;
  794. if (cs_link_strip in current_settings.globalswitches) then
  795. if (target_info.system in systems_darwin) then
  796. StripStr:='-x'
  797. else
  798. StripStr:='-s';
  799. if (cs_link_smart in current_settings.globalswitches) and
  800. (tf_smartlink_sections in target_info.flags) then
  801. if not(target_info.system in systems_darwin) then
  802. GCSectionsStr:='--gc-sections'
  803. else
  804. GCSectionsStr:='-dead_strip -no_dead_strip_inits_and_terms';
  805. if(not(target_info.system in systems_darwin) and
  806. (cs_profile in current_settings.moduleswitches)) or
  807. ((Info.DynamicLinker<>'') and
  808. ((not SharedLibFiles.Empty) or
  809. (target_info.system in systems_openbsd))) then
  810. DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
  811. if CShared Then
  812. begin
  813. if not(target_info.system in systems_darwin) then
  814. DynLinKStr:=DynLinkStr+' --shared'
  815. else
  816. DynLinKStr:=DynLinkStr+' -dynamic'; // one dash!
  817. end;
  818. { Use -nopie on OpenBSD if PIC support is turned off }
  819. if (target_info.system in systems_openbsd) and
  820. not(cs_create_pic in current_settings.moduleswitches) then
  821. Info.ExtraOptions:=Info.ExtraOptions+' -nopie';
  822. { -N seems to be needed on NetBSD/earm }
  823. if (target_info.system in [system_arm_netbsd]) then
  824. Info.ExtraOptions:=Info.ExtraOptions+' -N';
  825. { Write used files and libraries }
  826. WriteResponseFile(false);
  827. { Write symbol order file }
  828. ordersymfile:=WriteSymbolOrderFile;
  829. { Call linker }
  830. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  831. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  832. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  833. Replace(cmdstr,'$TARGET',targetstr);
  834. Replace(cmdstr,'$EMUL',EmulStr);
  835. Replace(cmdstr,'$MAP',mapstr);
  836. Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
  837. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  838. if ordersymfile<>'' then
  839. begin
  840. if target_info.system in systems_darwin then
  841. Replace(cmdstr,'$ORDERSYMS','-order_file '+maybequoted(ordersymfile))
  842. else
  843. Replace(cmdstr,'$ORDERSYMS','--symbol-ordering-file '+maybequoted(ordersymfile))
  844. end
  845. else
  846. Replace(cmdstr,'$ORDERSYMS','');
  847. if (LdSupportsNoResponseFile) and (source_info.system in systems_all_windows) then
  848. Replace(cmdstr,'$FILELIST','-filelist '+maybequoted(outputexedir+'linkfiles.res'))
  849. else
  850. Replace(cmdstr,'$FILELIST','');
  851. Replace(cmdstr,'$STATIC',StaticStr);
  852. Replace(cmdstr,'$STRIP',StripStr);
  853. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  854. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  855. if (target_info.system in systems_darwin) then
  856. Replace(cmdstr,'$PRTOBJ',GetDarwinPrtobjName(false));
  857. BinStr:=FindUtil(utilsprefix+BinStr);
  858. { create dsym file? }
  859. extdbgbinstr:='';
  860. extdbgcmdstr:='';
  861. if (target_info.system in systems_darwin) and
  862. (target_dbg.id in [dbg_dwarf2,dbg_dwarf3]) and
  863. (cs_link_separate_dbg_file in current_settings.globalswitches) then
  864. begin
  865. extdbgbinstr:=FindUtil(utilsprefix+'dsymutil');
  866. extdbgcmdstr:=maybequoted(current_module.exefilename);
  867. end;
  868. if (LdSupportsNoResponseFile) and
  869. not(cs_link_nolink in current_settings.globalswitches) then
  870. begin
  871. { we have to use a script to use the IFS hack }
  872. linkscript:=GenerateScript(outputexedir+'ppaslink');
  873. linkscript.AddLinkCommand(BinStr,CmdStr,'');
  874. if (extdbgcmdstr<>'') then
  875. linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
  876. linkscript.WriteToDisk;
  877. BinStr:=linkscript.fn;
  878. if not path_absolute(BinStr) then
  879. if cs_link_on_target in current_settings.globalswitches then
  880. BinStr:='.'+target_info.dirsep+BinStr
  881. else
  882. BinStr:='.'+source_info.dirsep+BinStr;
  883. CmdStr:='';
  884. end;
  885. useshell:=not (tf_no_backquote_support in source_info.flags);
  886. success:=DoExec(BinStr,CmdStr,true,LdSupportsNoResponseFile or useshell);
  887. if (success and
  888. (extdbgbinstr<>'') and
  889. (cs_link_nolink in current_settings.globalswitches)) then
  890. success:=DoExec(extdbgbinstr,extdbgcmdstr,false,LdSupportsNoResponseFile);
  891. { Remove ReponseFile }
  892. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  893. begin
  894. DeleteFile(outputexedir+Info.ResName);
  895. if ordersymfile<>'' then
  896. DeleteFile(ordersymfile);
  897. if LdSupportsNoResponseFile Then
  898. begin
  899. DeleteFile(linkscript.fn);
  900. linkscript.free
  901. end;
  902. end;
  903. { Remove linkfiles.res }
  904. if (success) and (LdSupportsNoResponseFile) and (source_info.system in systems_all_windows) then
  905. DeleteFile(outputexedir+'linkfiles.res');
  906. MakeExecutable:=success; { otherwise a recursive call to link method }
  907. end;
  908. Function TLinkerBSD.MakeSharedLibrary:boolean;
  909. var
  910. InitStr,
  911. FiniStr,
  912. SoNameStr : string[80];
  913. linkscript: TAsmScript;
  914. binstr,
  915. cmdstr,
  916. mapstr,
  917. ordersymfile,
  918. targetstr,
  919. emulstr,
  920. extdbgbinstr,
  921. extdbgcmdstr : TCmdStr;
  922. GCSectionsStr : string[63];
  923. exportedsyms: text;
  924. success : boolean;
  925. begin
  926. MakeSharedLibrary:=false;
  927. GCSectionsStr:='';
  928. mapstr:='';
  929. linkscript:=nil;
  930. if not(cs_link_nolink in current_settings.globalswitches) then
  931. Message1(exec_i_linking,current_module.sharedlibfilename);
  932. { Write used files and libraries }
  933. WriteResponseFile(true);
  934. { Write symbol order file }
  935. ordersymfile:=WriteSymbolOrderFile;
  936. if (cs_link_smart in current_settings.globalswitches) and
  937. (tf_smartlink_sections in target_info.flags) then
  938. if not(target_info.system in systems_darwin) then
  939. { disabled because not tested
  940. GCSectionsStr:='--gc-sections' }
  941. else
  942. GCSectionsStr:='-dead_strip -no_dead_strip_inits_and_terms';
  943. if (cs_link_map in current_settings.globalswitches) then
  944. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.sharedlibfilename,'.map'));
  945. { i386_freebsd needs -b elf32-i386-freebsd and -m elf_i386_fbsd
  946. to avoid creation of a i386:x86_64 arch binary }
  947. if target_info.system=system_i386_freebsd then
  948. begin
  949. targetstr:='-b elf32-i386-freebsd';
  950. emulstr:='-m elf_i386_fbsd';
  951. end
  952. else
  953. begin
  954. targetstr:='';
  955. emulstr:='';
  956. end;
  957. InitStr:='-init FPC_LIB_START';
  958. FiniStr:='-fini FPC_LIB_EXIT';
  959. SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename);
  960. { Call linker }
  961. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  962. {$ifndef darwin}
  963. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  964. {$else darwin}
  965. Replace(cmdstr,'$EXE',maybequoted(ExpandFileName(current_module.sharedlibfilename)));
  966. {$endif darwin}
  967. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  968. Replace(cmdstr,'$TARGET',targetstr);
  969. Replace(cmdstr,'$EMUL',EmulStr);
  970. Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
  971. if (LdSupportsNoResponseFile) and (source_info.system in systems_all_windows) then
  972. Replace(cmdstr,'$FILELIST','-filelist '+maybequoted(outputexedir+'linkfiles.res'))
  973. else
  974. Replace(cmdstr,'$FILELIST','');
  975. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  976. Replace(cmdstr,'$INIT',InitStr);
  977. Replace(cmdstr,'$FINI',FiniStr);
  978. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  979. Replace(cmdstr,'$SONAME',SoNameStr);
  980. Replace(cmdstr,'$MAP',mapstr);
  981. if ordersymfile<>'' then
  982. begin
  983. if target_info.system in systems_darwin then
  984. Replace(cmdstr,'$ORDERSYMS','-order_file '+maybequoted(ordersymfile))
  985. else
  986. Replace(cmdstr,'$ORDERSYMS','--symbol-ordering-file '+maybequoted(ordersymfile))
  987. end
  988. else
  989. Replace(cmdstr,'$ORDERSYMS','');
  990. if (target_info.system in systems_darwin) then
  991. Replace(cmdstr,'$PRTOBJ',GetDarwinPrtobjName(true));
  992. BinStr:=FindUtil(utilsprefix+BinStr);
  993. { create dsym file? }
  994. extdbgbinstr:='';
  995. extdbgcmdstr:='';
  996. if (target_info.system in systems_darwin) and
  997. (target_dbg.id in [dbg_dwarf2,dbg_dwarf3]) and
  998. (cs_link_separate_dbg_file in current_settings.globalswitches) then
  999. begin
  1000. extdbgbinstr:=FindUtil(utilsprefix+'dsymutil');
  1001. extdbgcmdstr:=maybequoted(current_module.sharedlibfilename);
  1002. end;
  1003. if (target_info.system in systems_darwin) then
  1004. begin
  1005. { exported symbols for darwin }
  1006. if not texportlibunix(exportlib).exportedsymnames.empty then
  1007. begin
  1008. assign(exportedsyms,outputexedir+'linksyms.fpc');
  1009. rewrite(exportedsyms);
  1010. repeat
  1011. writeln(exportedsyms,texportlibunix(exportlib).exportedsymnames.getfirst);
  1012. until texportlibunix(exportlib).exportedsymnames.empty;
  1013. close(exportedsyms);
  1014. cmdstr:=cmdstr+' -exported_symbols_list '+maybequoted(outputexedir)+'linksyms.fpc';
  1015. end;
  1016. end;
  1017. if (LdSupportsNoResponseFile) and
  1018. not(cs_link_nolink in current_settings.globalswitches) then
  1019. begin
  1020. { we have to use a script to use the IFS hack }
  1021. linkscript:=GenerateScript(outputexedir+'ppaslink');
  1022. linkscript.AddLinkCommand(BinStr,CmdStr,'');
  1023. if (extdbgbinstr<>'') then
  1024. linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
  1025. linkscript.WriteToDisk;
  1026. BinStr:=linkscript.fn;
  1027. if not path_absolute(BinStr) then
  1028. if cs_link_on_target in current_settings.globalswitches then
  1029. BinStr:='.'+target_info.dirsep+BinStr
  1030. else
  1031. BinStr:='.'+source_info.dirsep+BinStr;
  1032. CmdStr:='';
  1033. end;
  1034. success:=DoExec(BinStr,cmdstr,true,LdSupportsNoResponseFile);
  1035. if (success and
  1036. (extdbgbinstr<>'') and
  1037. (cs_link_nolink in current_settings.globalswitches)) then
  1038. success:=DoExec(extdbgbinstr,extdbgcmdstr,false,LdSupportsNoResponseFile);
  1039. { Strip the library ? }
  1040. if success and (cs_link_strip in current_settings.globalswitches) then
  1041. begin
  1042. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  1043. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  1044. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,false,false);
  1045. end;
  1046. { Remove ReponseFile }
  1047. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  1048. begin
  1049. DeleteFile(outputexedir+Info.ResName);
  1050. if ordersymfile<>'' then
  1051. DeleteFile(ordersymfile);
  1052. if LdSupportsNoResponseFile Then
  1053. begin
  1054. DeleteFile(linkscript.fn);
  1055. linkscript.free
  1056. end;
  1057. if (target_info.system in systems_darwin) then
  1058. DeleteFile(outputexedir+'linksyms.fpc');
  1059. end;
  1060. { Remove linkfiles.res }
  1061. if (success) and (LdSupportsNoResponseFile) and (source_info.system in systems_all_windows) then
  1062. DeleteFile(outputexedir+'linkfiles.res');
  1063. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  1064. end;
  1065. {*****************************************************************************
  1066. Initialize
  1067. *****************************************************************************}
  1068. initialization
  1069. RegisterLinker(ld_bsd,TLinkerBSD);
  1070. {$ifdef x86_64}
  1071. RegisterImport(system_x86_64_dragonfly,timportlibbsd);
  1072. RegisterExport(system_x86_64_dragonfly,texportlibbsd);
  1073. RegisterTarget(system_x86_64_dragonfly_info);
  1074. RegisterImport(system_x86_64_freebsd,timportlibbsd);
  1075. RegisterExport(system_x86_64_freebsd,texportlibbsd);
  1076. RegisterTarget(system_x86_64_freebsd_info);
  1077. RegisterImport(system_x86_64_openbsd,timportlibbsd);
  1078. RegisterExport(system_x86_64_openbsd,texportlibbsd);
  1079. RegisterTarget(system_x86_64_openbsd_info);
  1080. RegisterImport(system_x86_64_netbsd,timportlibbsd);
  1081. RegisterExport(system_x86_64_netbsd,texportlibbsd);
  1082. RegisterTarget(system_x86_64_netbsd_info);
  1083. RegisterImport(system_x86_64_darwin,timportlibdarwin);
  1084. RegisterExport(system_x86_64_darwin,texportlibdarwin);
  1085. RegisterTarget(system_x86_64_darwin_info);
  1086. RegisterImport(system_x86_64_iphonesim,timportlibdarwin);
  1087. RegisterExport(system_x86_64_iphonesim,texportlibdarwin);
  1088. RegisterTarget(system_x86_64_iphonesim_info);
  1089. {$endif}
  1090. {$ifdef i386}
  1091. RegisterImport(system_i386_freebsd,timportlibbsd);
  1092. RegisterExport(system_i386_freebsd,texportlibbsd);
  1093. RegisterTarget(system_i386_freebsd_info);
  1094. RegisterImport(system_i386_netbsd,timportlibbsd);
  1095. RegisterExport(system_i386_netbsd,texportlibbsd);
  1096. RegisterTarget(system_i386_netbsd_info);
  1097. RegisterImport(system_i386_openbsd,timportlibbsd);
  1098. RegisterExport(system_i386_openbsd,texportlibbsd);
  1099. RegisterTarget(system_i386_openbsd_info);
  1100. RegisterImport(system_i386_darwin,timportlibdarwin);
  1101. RegisterExport(system_i386_darwin,texportlibdarwin);
  1102. RegisterTarget(system_i386_darwin_info);
  1103. RegisterImport(system_i386_iphonesim,timportlibdarwin);
  1104. RegisterExport(system_i386_iphonesim,texportlibdarwin);
  1105. RegisterTarget(system_i386_iphonesim_info);
  1106. {$endif i386}
  1107. {$ifdef m68k}
  1108. RegisterImport(system_m68k_netbsd,timportlibbsd);
  1109. RegisterExport(system_m68k_netbsd,texportlibbsd);
  1110. RegisterTarget(system_m68k_netbsd_info);
  1111. {$endif m68k}
  1112. {$ifdef powerpc}
  1113. RegisterImport(system_powerpc_darwin,timportlibdarwin);
  1114. RegisterExport(system_powerpc_darwin,texportlibdarwin);
  1115. RegisterTarget(system_powerpc_darwin_info);
  1116. RegisterImport(system_powerpc_netbsd,timportlibbsd);
  1117. RegisterExport(system_powerpc_netbsd,texportlibbsd);
  1118. RegisterTarget(system_powerpc_netbsd_info);
  1119. {$endif powerpc}
  1120. {$ifdef powerpc64}
  1121. RegisterImport(system_powerpc64_darwin,timportlibdarwin);
  1122. RegisterExport(system_powerpc64_darwin,texportlibdarwin);
  1123. RegisterTarget(system_powerpc64_darwin_info);
  1124. {$endif powerpc64}
  1125. {$ifdef arm}
  1126. RegisterImport(system_arm_darwin,timportlibdarwin);
  1127. RegisterExport(system_arm_darwin,texportlibdarwin);
  1128. RegisterTarget(system_arm_darwin_info);
  1129. RegisterImport(system_arm_netbsd,timportlibbsd);
  1130. RegisterExport(system_arm_netbsd,texportlibbsd);
  1131. RegisterTarget(system_arm_netbsd_info);
  1132. {$endif arm}
  1133. {$ifdef aarch64}
  1134. RegisterImport(system_aarch64_darwin,timportlibdarwin);
  1135. RegisterExport(system_aarch64_darwin,texportlibdarwin);
  1136. RegisterTarget(system_aarch64_darwin_info);
  1137. {$endif aarch64}
  1138. RegisterRes(res_elf_info,TWinLikeResourceFile);
  1139. RegisterRes(res_macho_info,TWinLikeResourceFile);
  1140. end.