t_bsd.pas 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  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.AddLibraryPath(sysrootpath,'=/usr/lib',true)
  126. else if target_info.system in systems_openbsd then
  127. LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib;=$OPENBSD_X11BASE/lib;=$OPENBSD_LOCALBASE/lib',true)
  128. else
  129. LibrarySearchPath.AddLibraryPath(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 $LTO $ORDERSYMS -L. -o $EXE $CATRES $FILELIST';
  149. DllCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $MAP $LTO $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 $LTO $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 $LTO $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 $LTO $ORDERSYMS -dynamic -dylib -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
  175. else
  176. DllCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS $MAP $LTO $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 $LTO $ORDERSYMS -L. -o $EXE $RES';
  182. DllCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $INIT $FINI $SONAME $MAP $LTO $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. if (target_info.system in systems_darwin) then
  618. begin
  619. FilesList:=TLinkRes.Create(outputexedir+'linkfiles.res',false);
  620. while not ObjectFiles.Empty do
  621. begin
  622. s:=ObjectFiles.GetFirst;
  623. if s<>'' then
  624. begin
  625. s:=TargetFixFileName(s);
  626. FilesList.Add(s);
  627. end;
  628. end;
  629. FilesList.writetodisk;
  630. FilesList.Free;
  631. end
  632. else
  633. begin
  634. while not ObjectFiles.Empty do
  635. begin
  636. s:=ObjectFiles.GetFirst;
  637. if s<>'' then
  638. if LdSupportsNoResponseFile then
  639. LinkRes.AddFileName(s)
  640. else
  641. LinkRes.AddFileName(maybequoted(s));
  642. end;
  643. end;
  644. if not LdSupportsNoResponseFile then
  645. LinkRes.Add(')');
  646. { Write staticlibraries }
  647. if not StaticLibFiles.Empty then
  648. begin
  649. if not LdSupportsNoResponseFile then
  650. LinkRes.Add('GROUP(');
  651. While not StaticLibFiles.Empty do
  652. begin
  653. S:=StaticLibFiles.GetFirst;
  654. if LdSupportsNoResponseFile then
  655. LinkRes.AddFileName(s)
  656. else
  657. LinkRes.AddFileName(maybequoted(s))
  658. end;
  659. if not LdSupportsNoResponseFile then
  660. LinkRes.Add(')');
  661. end;
  662. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  663. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  664. if not SharedLibFiles.Empty then
  665. begin
  666. if not LdSupportsNoResponseFile then
  667. LinkRes.Add('INPUT(');
  668. While not SharedLibFiles.Empty do
  669. begin
  670. S:=SharedLibFiles.GetFirst;
  671. if (s<>'c') or reorder then
  672. begin
  673. i:=Pos(target_info.sharedlibext,S);
  674. if i>0 then
  675. Delete(S,i,255);
  676. LinkRes.Add('-l'+s);
  677. end
  678. else
  679. begin
  680. linklibc:=true;
  681. linkdynamic:=false; { libc will include the ld-* for us }
  682. end;
  683. end;
  684. { be sure that libc is the last lib }
  685. if linklibc and not reorder then
  686. Begin
  687. If LibrarySuffix=' ' Then
  688. LinkRes.Add('-lc')
  689. else
  690. LinkRes.Add('-lc_'+LibrarySuffix);
  691. If LibrarySuffix='r' Then
  692. LinkRes.Add('-lc');
  693. end;
  694. { when we have -static for the linker the we also need libgcc }
  695. if (cs_link_staticflag in current_settings.globalswitches) then
  696. LinkRes.Add('-lgcc');
  697. if linkdynamic and (Info.DynamicLinker<>'') and
  698. not(target_info.system in systems_openbsd) then
  699. LinkRes.AddFileName(Info.DynamicLinker);
  700. if not LdSupportsNoResponseFile then
  701. LinkRes.Add(')');
  702. end;
  703. { frameworks for Darwin }
  704. if IsDarwin then
  705. while not FrameworkFiles.empty do
  706. begin
  707. LinkRes.Add('-framework');
  708. LinkRes.Add(FrameworkFiles.GetFirst);
  709. end;
  710. { objects which must be at the end }
  711. if linklibc and
  712. not IsDarwin Then
  713. begin
  714. if ((cs_create_pic in current_settings.moduleswitches) and
  715. not (target_info.system in systems_openbsd)) or
  716. (current_module.islibrary and
  717. (target_info.system in systems_openbsd)) then
  718. Fl1:=librarysearchpath.FindFile('crtendS.o',false,s1)
  719. else
  720. Fl1:=librarysearchpath.FindFile('crtend.o',false,s1);
  721. Fl2:=librarysearchpath.FindFile('crtn.o',false,s2);
  722. if Fl1 or Fl2 then
  723. begin
  724. LinkRes.Add('INPUT(');
  725. If Fl1 Then
  726. LinkRes.AddFileName(s1);
  727. If Fl2 Then
  728. LinkRes.AddFileName(s2);
  729. LinkRes.Add(')');
  730. end;
  731. end;
  732. { Write and Close response }
  733. linkres.writetodisk;
  734. linkres.Free;
  735. WriteResponseFile:=True;
  736. end;
  737. function TLinkerBSD.MakeExecutable:boolean;
  738. var
  739. binstr,
  740. cmdstr,
  741. mapstr,
  742. targetstr,
  743. emulstr,
  744. extdbgbinstr,
  745. extdbgcmdstr,
  746. ltostr,
  747. ordersymfile: TCmdStr;
  748. linkscript: TAsmScript;
  749. DynLinkStr : string[60];
  750. GCSectionsStr,
  751. StaticStr,
  752. StripStr : string[63];
  753. success,
  754. useshell : boolean;
  755. begin
  756. if not(cs_link_nolink in current_settings.globalswitches) then
  757. Message1(exec_i_linking,current_module.exefilename);
  758. { Create some replacements }
  759. StaticStr:='';
  760. StripStr:='';
  761. DynLinkStr:='';
  762. GCSectionsStr:='';
  763. linkscript:=nil;
  764. mapstr:='';
  765. ltostr:='';
  766. if (cs_link_map in current_settings.globalswitches) then
  767. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  768. { i386_freebsd needs -b elf32-i386-freebsd and -m elf_i386_fbsd
  769. to avoid creation of a i386:x86_64 arch binary }
  770. if target_info.system=system_i386_freebsd then
  771. begin
  772. targetstr:='-b elf32-i386-freebsd';
  773. emulstr:='-m elf_i386_fbsd';
  774. end
  775. else
  776. begin
  777. targetstr:='';
  778. emulstr:='';
  779. end;
  780. if (cs_link_staticflag in current_settings.globalswitches) then
  781. begin
  782. if (target_info.system=system_m68k_netbsd) and
  783. ((cs_link_on_target in current_settings.globalswitches) or
  784. (target_info.system=source_info.system)) then
  785. StaticStr:='-Bstatic'
  786. else
  787. StaticStr:='-static';
  788. end;
  789. if (cs_link_strip in current_settings.globalswitches) then
  790. if (target_info.system in systems_darwin) then
  791. StripStr:='-x'
  792. else
  793. StripStr:='-s';
  794. if (cs_link_smart in current_settings.globalswitches) and
  795. (tf_smartlink_sections in target_info.flags) then
  796. if not(target_info.system in systems_darwin) then
  797. GCSectionsStr:='--gc-sections'
  798. else
  799. GCSectionsStr:='-dead_strip -no_dead_strip_inits_and_terms';
  800. if(not(target_info.system in systems_darwin) and
  801. (cs_profile in current_settings.moduleswitches)) or
  802. ((Info.DynamicLinker<>'') and
  803. ((not SharedLibFiles.Empty) or
  804. (target_info.system in systems_openbsd))) then
  805. DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
  806. if CShared Then
  807. begin
  808. if not(target_info.system in systems_darwin) then
  809. DynLinKStr:=DynLinkStr+' --shared'
  810. else
  811. DynLinKStr:=DynLinkStr+' -dynamic'; // one dash!
  812. end;
  813. { add custom LTO library if using custom clang }
  814. if (target_info.system in systems_darwin) and
  815. (cs_lto in current_settings.moduleswitches) and
  816. not(cs_link_on_target in current_settings.globalswitches) and
  817. (utilsdirectory<>'') and
  818. FileExists(utilsdirectory+'/../lib/libLTO.dylib',true) then
  819. begin
  820. ltostr:='-lto_library '+maybequoted(utilsdirectory+'/../lib/libLTO.dylib');
  821. end;
  822. { Use -nopie on OpenBSD if PIC support is turned off }
  823. if (target_info.system in systems_openbsd) and
  824. not(cs_create_pic in current_settings.moduleswitches) then
  825. Info.ExtraOptions:=Info.ExtraOptions+' -nopie';
  826. { -N seems to be needed on NetBSD/earm }
  827. if (target_info.system in [system_arm_netbsd]) then
  828. Info.ExtraOptions:=Info.ExtraOptions+' -N';
  829. { Write used files and libraries }
  830. WriteResponseFile(false);
  831. { Write symbol order file }
  832. ordersymfile:=WriteSymbolOrderFile;
  833. { Call linker }
  834. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  835. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  836. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  837. Replace(cmdstr,'$TARGET',targetstr);
  838. Replace(cmdstr,'$EMUL',EmulStr);
  839. Replace(cmdstr,'$MAP',mapstr);
  840. Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
  841. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  842. Replace(cmdstr,'$LTO',ltostr);
  843. if ordersymfile<>'' then
  844. begin
  845. if target_info.system in systems_darwin then
  846. Replace(cmdstr,'$ORDERSYMS','-order_file '+maybequoted(ordersymfile))
  847. else
  848. Replace(cmdstr,'$ORDERSYMS','--symbol-ordering-file '+maybequoted(ordersymfile))
  849. end
  850. else
  851. Replace(cmdstr,'$ORDERSYMS','');
  852. if (target_info.system in systems_darwin) then
  853. Replace(cmdstr,'$FILELIST','-filelist '+maybequoted(outputexedir+'linkfiles.res'))
  854. else
  855. Replace(cmdstr,'$FILELIST','');
  856. Replace(cmdstr,'$STATIC',StaticStr);
  857. Replace(cmdstr,'$STRIP',StripStr);
  858. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  859. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  860. if (target_info.system in systems_darwin) then
  861. Replace(cmdstr,'$PRTOBJ',GetDarwinPrtobjName(false));
  862. BinStr:=FindUtil(utilsprefix+BinStr);
  863. { create dsym file? }
  864. extdbgbinstr:='';
  865. extdbgcmdstr:='';
  866. if (target_info.system in systems_darwin) and
  867. (target_dbg.id in [dbg_dwarf2,dbg_dwarf3]) and
  868. (cs_link_separate_dbg_file in current_settings.globalswitches) then
  869. begin
  870. extdbgbinstr:=FindUtil(utilsprefix+'dsymutil');
  871. extdbgcmdstr:=maybequoted(current_module.exefilename);
  872. end;
  873. if (LdSupportsNoResponseFile) and
  874. not(cs_link_nolink in current_settings.globalswitches) then
  875. begin
  876. { we have to use a script to use the IFS hack }
  877. linkscript:=GenerateScript(outputexedir+'ppaslink');
  878. linkscript.AddLinkCommand(BinStr,CmdStr,'');
  879. if (extdbgcmdstr<>'') then
  880. linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
  881. linkscript.WriteToDisk;
  882. BinStr:=linkscript.fn;
  883. if not path_absolute(BinStr) then
  884. if cs_link_on_target in current_settings.globalswitches then
  885. BinStr:='.'+target_info.dirsep+BinStr
  886. else
  887. BinStr:='.'+source_info.dirsep+BinStr;
  888. CmdStr:='';
  889. end;
  890. useshell:=not (tf_no_backquote_support in source_info.flags);
  891. success:=DoExec(BinStr,CmdStr,true,LdSupportsNoResponseFile or useshell);
  892. if (success and
  893. (extdbgbinstr<>'') and
  894. (cs_link_nolink in current_settings.globalswitches)) then
  895. success:=DoExec(extdbgbinstr,extdbgcmdstr,false,LdSupportsNoResponseFile);
  896. { Remove ReponseFile }
  897. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  898. begin
  899. DeleteFile(outputexedir+Info.ResName);
  900. if ordersymfile<>'' then
  901. DeleteFile(ordersymfile);
  902. if LdSupportsNoResponseFile Then
  903. begin
  904. DeleteFile(linkscript.fn);
  905. linkscript.free
  906. end;
  907. if target_info.system in systems_darwin then
  908. DeleteFile(outputexedir+'linkfiles.res');
  909. end;
  910. MakeExecutable:=success; { otherwise a recursive call to link method }
  911. end;
  912. Function TLinkerBSD.MakeSharedLibrary:boolean;
  913. var
  914. InitStr,
  915. FiniStr,
  916. SoNameStr : string[80];
  917. linkscript: TAsmScript;
  918. binstr,
  919. cmdstr,
  920. mapstr,
  921. ltostr,
  922. ordersymfile,
  923. targetstr,
  924. emulstr,
  925. extdbgbinstr,
  926. extdbgcmdstr : TCmdStr;
  927. GCSectionsStr : string[63];
  928. exportedsyms: text;
  929. success : boolean;
  930. begin
  931. MakeSharedLibrary:=false;
  932. GCSectionsStr:='';
  933. mapstr:='';
  934. ltostr:='';
  935. linkscript:=nil;
  936. if not(cs_link_nolink in current_settings.globalswitches) then
  937. Message1(exec_i_linking,current_module.sharedlibfilename);
  938. { Write used files and libraries }
  939. WriteResponseFile(true);
  940. { Write symbol order file }
  941. ordersymfile:=WriteSymbolOrderFile;
  942. if (cs_link_smart in current_settings.globalswitches) and
  943. (tf_smartlink_sections in target_info.flags) then
  944. if not(target_info.system in systems_darwin) then
  945. { disabled because not tested
  946. GCSectionsStr:='--gc-sections' }
  947. else
  948. GCSectionsStr:='-dead_strip -no_dead_strip_inits_and_terms';
  949. if (cs_link_map in current_settings.globalswitches) then
  950. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.sharedlibfilename,'.map'));
  951. { add custom LTO library if using custom clang }
  952. if (target_info.system in systems_darwin) and
  953. (cs_lto in current_settings.moduleswitches) and
  954. not(cs_link_on_target in current_settings.globalswitches) and
  955. (utilsdirectory<>'') and
  956. FileExists(utilsdirectory+'/../lib/libLTO.dylib',true) then
  957. begin
  958. ltostr:='-lto_library '+maybequoted(utilsdirectory+'/../lib/libLTO.dylib');
  959. end;
  960. { i386_freebsd needs -b elf32-i386-freebsd and -m elf_i386_fbsd
  961. to avoid creation of a i386:x86_64 arch binary }
  962. if target_info.system=system_i386_freebsd then
  963. begin
  964. targetstr:='-b elf32-i386-freebsd';
  965. emulstr:='-m elf_i386_fbsd';
  966. end
  967. else
  968. begin
  969. targetstr:='';
  970. emulstr:='';
  971. end;
  972. InitStr:='-init FPC_LIB_START';
  973. FiniStr:='-fini FPC_LIB_EXIT';
  974. SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename);
  975. { Call linker }
  976. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  977. {$ifndef darwin}
  978. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  979. {$else darwin}
  980. Replace(cmdstr,'$EXE',maybequoted(ExpandFileName(current_module.sharedlibfilename)));
  981. {$endif darwin}
  982. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  983. Replace(cmdstr,'$TARGET',targetstr);
  984. Replace(cmdstr,'$EMUL',EmulStr);
  985. Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
  986. if (target_info.system in systems_darwin) then
  987. Replace(cmdstr,'$FILELIST','-filelist '+maybequoted(outputexedir+'linkfiles.res'))
  988. else
  989. Replace(cmdstr,'$FILELIST','');
  990. Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  991. Replace(cmdstr,'$INIT',InitStr);
  992. Replace(cmdstr,'$FINI',FiniStr);
  993. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  994. Replace(cmdstr,'$SONAME',SoNameStr);
  995. Replace(cmdstr,'$MAP',mapstr);
  996. Replace(cmdstr,'$LTO',ltostr);
  997. if ordersymfile<>'' then
  998. begin
  999. if target_info.system in systems_darwin then
  1000. Replace(cmdstr,'$ORDERSYMS','-order_file '+maybequoted(ordersymfile))
  1001. else
  1002. Replace(cmdstr,'$ORDERSYMS','--symbol-ordering-file '+maybequoted(ordersymfile))
  1003. end
  1004. else
  1005. Replace(cmdstr,'$ORDERSYMS','');
  1006. if (target_info.system in systems_darwin) then
  1007. Replace(cmdstr,'$PRTOBJ',GetDarwinPrtobjName(true));
  1008. BinStr:=FindUtil(utilsprefix+BinStr);
  1009. { create dsym file? }
  1010. extdbgbinstr:='';
  1011. extdbgcmdstr:='';
  1012. if (target_info.system in systems_darwin) and
  1013. (target_dbg.id in [dbg_dwarf2,dbg_dwarf3]) and
  1014. (cs_link_separate_dbg_file in current_settings.globalswitches) then
  1015. begin
  1016. extdbgbinstr:=FindUtil(utilsprefix+'dsymutil');
  1017. extdbgcmdstr:=maybequoted(current_module.sharedlibfilename);
  1018. end;
  1019. if (target_info.system in systems_darwin) then
  1020. begin
  1021. { exported symbols for darwin }
  1022. if not texportlibunix(exportlib).exportedsymnames.empty then
  1023. begin
  1024. assign(exportedsyms,outputexedir+'linksyms.fpc');
  1025. rewrite(exportedsyms);
  1026. repeat
  1027. writeln(exportedsyms,texportlibunix(exportlib).exportedsymnames.getfirst);
  1028. until texportlibunix(exportlib).exportedsymnames.empty;
  1029. close(exportedsyms);
  1030. cmdstr:=cmdstr+' -exported_symbols_list '+maybequoted(outputexedir)+'linksyms.fpc';
  1031. end;
  1032. end;
  1033. if (LdSupportsNoResponseFile) and
  1034. not(cs_link_nolink in current_settings.globalswitches) then
  1035. begin
  1036. { we have to use a script to use the IFS hack }
  1037. linkscript:=GenerateScript(outputexedir+'ppaslink');
  1038. linkscript.AddLinkCommand(BinStr,CmdStr,'');
  1039. if (extdbgbinstr<>'') then
  1040. linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
  1041. linkscript.WriteToDisk;
  1042. BinStr:=linkscript.fn;
  1043. if not path_absolute(BinStr) then
  1044. if cs_link_on_target in current_settings.globalswitches then
  1045. BinStr:='.'+target_info.dirsep+BinStr
  1046. else
  1047. BinStr:='.'+source_info.dirsep+BinStr;
  1048. CmdStr:='';
  1049. end;
  1050. success:=DoExec(BinStr,cmdstr,true,LdSupportsNoResponseFile);
  1051. if (success and
  1052. (extdbgbinstr<>'') and
  1053. (cs_link_nolink in current_settings.globalswitches)) then
  1054. success:=DoExec(extdbgbinstr,extdbgcmdstr,false,LdSupportsNoResponseFile);
  1055. { Strip the library ? }
  1056. if success and (cs_link_strip in current_settings.globalswitches) then
  1057. begin
  1058. SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  1059. Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
  1060. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,false,false);
  1061. end;
  1062. { Remove ReponseFile }
  1063. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  1064. begin
  1065. DeleteFile(outputexedir+Info.ResName);
  1066. if ordersymfile<>'' then
  1067. DeleteFile(ordersymfile);
  1068. if LdSupportsNoResponseFile Then
  1069. begin
  1070. DeleteFile(linkscript.fn);
  1071. linkscript.free
  1072. end;
  1073. if (target_info.system in systems_darwin) then
  1074. begin
  1075. DeleteFile(outputexedir+'linksyms.fpc');
  1076. DeleteFile(outputexedir+'linkfiles.res');
  1077. end;
  1078. end;
  1079. MakeSharedLibrary:=success; { otherwise a recursive call to link method }
  1080. end;
  1081. {*****************************************************************************
  1082. Initialize
  1083. *****************************************************************************}
  1084. initialization
  1085. RegisterLinker(ld_bsd,TLinkerBSD);
  1086. {$ifdef x86_64}
  1087. RegisterImport(system_x86_64_dragonfly,timportlibbsd);
  1088. RegisterExport(system_x86_64_dragonfly,texportlibbsd);
  1089. RegisterTarget(system_x86_64_dragonfly_info);
  1090. RegisterImport(system_x86_64_freebsd,timportlibbsd);
  1091. RegisterExport(system_x86_64_freebsd,texportlibbsd);
  1092. RegisterTarget(system_x86_64_freebsd_info);
  1093. RegisterImport(system_x86_64_openbsd,timportlibbsd);
  1094. RegisterExport(system_x86_64_openbsd,texportlibbsd);
  1095. RegisterTarget(system_x86_64_openbsd_info);
  1096. RegisterImport(system_x86_64_netbsd,timportlibbsd);
  1097. RegisterExport(system_x86_64_netbsd,texportlibbsd);
  1098. RegisterTarget(system_x86_64_netbsd_info);
  1099. RegisterImport(system_x86_64_darwin,timportlibdarwin);
  1100. RegisterExport(system_x86_64_darwin,texportlibdarwin);
  1101. RegisterTarget(system_x86_64_darwin_info);
  1102. RegisterImport(system_x86_64_iphonesim,timportlibdarwin);
  1103. RegisterExport(system_x86_64_iphonesim,texportlibdarwin);
  1104. RegisterTarget(system_x86_64_iphonesim_info);
  1105. {$endif}
  1106. {$ifdef i386}
  1107. RegisterImport(system_i386_freebsd,timportlibbsd);
  1108. RegisterExport(system_i386_freebsd,texportlibbsd);
  1109. RegisterTarget(system_i386_freebsd_info);
  1110. RegisterImport(system_i386_netbsd,timportlibbsd);
  1111. RegisterExport(system_i386_netbsd,texportlibbsd);
  1112. RegisterTarget(system_i386_netbsd_info);
  1113. RegisterImport(system_i386_openbsd,timportlibbsd);
  1114. RegisterExport(system_i386_openbsd,texportlibbsd);
  1115. RegisterTarget(system_i386_openbsd_info);
  1116. RegisterImport(system_i386_darwin,timportlibdarwin);
  1117. RegisterExport(system_i386_darwin,texportlibdarwin);
  1118. RegisterTarget(system_i386_darwin_info);
  1119. RegisterImport(system_i386_iphonesim,timportlibdarwin);
  1120. RegisterExport(system_i386_iphonesim,texportlibdarwin);
  1121. RegisterTarget(system_i386_iphonesim_info);
  1122. {$endif i386}
  1123. {$ifdef m68k}
  1124. RegisterImport(system_m68k_netbsd,timportlibbsd);
  1125. RegisterExport(system_m68k_netbsd,texportlibbsd);
  1126. RegisterTarget(system_m68k_netbsd_info);
  1127. {$endif m68k}
  1128. {$ifdef powerpc}
  1129. RegisterImport(system_powerpc_darwin,timportlibdarwin);
  1130. RegisterExport(system_powerpc_darwin,texportlibdarwin);
  1131. RegisterTarget(system_powerpc_darwin_info);
  1132. RegisterImport(system_powerpc_netbsd,timportlibbsd);
  1133. RegisterExport(system_powerpc_netbsd,texportlibbsd);
  1134. RegisterTarget(system_powerpc_netbsd_info);
  1135. {$endif powerpc}
  1136. {$ifdef powerpc64}
  1137. RegisterImport(system_powerpc64_darwin,timportlibdarwin);
  1138. RegisterExport(system_powerpc64_darwin,texportlibdarwin);
  1139. RegisterTarget(system_powerpc64_darwin_info);
  1140. {$endif powerpc64}
  1141. {$ifdef arm}
  1142. RegisterImport(system_arm_darwin,timportlibdarwin);
  1143. RegisterExport(system_arm_darwin,texportlibdarwin);
  1144. RegisterTarget(system_arm_darwin_info);
  1145. RegisterImport(system_arm_netbsd,timportlibbsd);
  1146. RegisterExport(system_arm_netbsd,texportlibbsd);
  1147. RegisterTarget(system_arm_netbsd_info);
  1148. {$endif arm}
  1149. {$ifdef aarch64}
  1150. RegisterImport(system_aarch64_darwin,timportlibdarwin);
  1151. RegisterExport(system_aarch64_darwin,texportlibdarwin);
  1152. RegisterTarget(system_aarch64_darwin_info);
  1153. {$endif aarch64}
  1154. RegisterRes(res_elf_info,TWinLikeResourceFile);
  1155. RegisterRes(res_macho_info,TWinLikeResourceFile);
  1156. end.