t_bsd.pas 42 KB

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