t_embed.pas 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191
  1. {
  2. Copyright (c) 2005-2017 by Free Pascal Compiler team
  3. This unit implements support import, export, link routines
  4. for the Embedded Target
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit t_embed;
  19. {$i fpcdefs.inc}
  20. interface
  21. implementation
  22. uses
  23. SysUtils,
  24. cutils,cfileutl,cclasses,
  25. globtype,globals,systems,verbose,comphook,cscript,fmodule,i_embed,link,
  26. {$ifdef wasm32}
  27. t_wasi,import,export,
  28. {$endif wasm32}
  29. cpuinfo,aasmbase;
  30. type
  31. TlinkerEmbedded=class(texternallinker)
  32. private
  33. Function WriteResponseFile: Boolean;
  34. Function GenerateUF2(binFile,uf2File : string;baseAddress : longWord):boolean;
  35. public
  36. constructor Create; override;
  37. procedure SetDefaultInfo; override;
  38. function MakeExecutable:boolean; override;
  39. function postprocessexecutable(const fn : string;isdll:boolean):boolean;
  40. end;
  41. { TlinkerEmbedded_SdccSdld - the sdld linker from the SDCC project ( http://sdcc.sourceforge.net/ ) }
  42. TlinkerEmbedded_SdccSdld=class(texternallinker)
  43. private
  44. Function WriteResponseFile: Boolean;
  45. public
  46. { constructor Create; override;}
  47. procedure SetDefaultInfo; override;
  48. function MakeExecutable:boolean; override;
  49. { function postprocessexecutable(const fn : string;isdll:boolean):boolean;}
  50. end;
  51. { TLinkerEmbedded_Wasm }
  52. TLinkerEmbedded_Wasm=class(texternallinker)
  53. public
  54. constructor Create;override;
  55. procedure SetDefaultInfo;override;
  56. //function MakeExecutable:boolean;override;
  57. function MakeSharedLibrary:boolean;override;
  58. end;
  59. {*****************************************************************************
  60. TlinkerEmbedded
  61. *****************************************************************************}
  62. Constructor TlinkerEmbedded.Create;
  63. begin
  64. Inherited Create;
  65. SharedLibFiles.doubles:=true;
  66. StaticLibFiles.doubles:=true;
  67. end;
  68. procedure TlinkerEmbedded.SetDefaultInfo;
  69. const
  70. {$ifdef mips}
  71. {$ifdef mipsel}
  72. platform_select='-EL';
  73. {$else}
  74. platform_select='-EB';
  75. {$endif}
  76. {$else}
  77. platform_select='';
  78. {$endif}
  79. begin
  80. with Info do
  81. begin
  82. ExeCmd[1]:='ld -g '+platform_select+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE -T $RES';
  83. end;
  84. end;
  85. Function TlinkerEmbedded.WriteResponseFile: Boolean;
  86. Var
  87. linkres : TLinkRes;
  88. i : longint;
  89. HPath : TCmdStrListItem;
  90. s,s1,s2 : TCmdStr;
  91. prtobj,
  92. cprtobj : string[80];
  93. linklibc : boolean;
  94. found1,
  95. found2 : boolean;
  96. {$if defined(ARM)}
  97. LinkStr : string;
  98. {$endif}
  99. begin
  100. WriteResponseFile:=False;
  101. linklibc:=(SharedLibFiles.Find('c')<>nil);
  102. {$if defined(ARM) or defined(i386) or defined(x86_64) or defined(AVR) or defined(MIPSEL) or defined(RISCV32) or defined(XTENSA)}
  103. prtobj:='';
  104. {$else}
  105. prtobj:='prt0';
  106. {$endif}
  107. cprtobj:='cprt0';
  108. if linklibc then
  109. prtobj:=cprtobj;
  110. { Open link.res file }
  111. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  112. { Write path to search libraries }
  113. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  114. while assigned(HPath) do
  115. begin
  116. s:=HPath.Str;
  117. if (cs_link_on_target in current_settings.globalswitches) then
  118. s:=ScriptFixFileName(s);
  119. LinkRes.Add('-L'+s);
  120. HPath:=TCmdStrListItem(HPath.Next);
  121. end;
  122. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  123. while assigned(HPath) do
  124. begin
  125. s:=HPath.Str;
  126. if s<>'' then
  127. LinkRes.Add('SEARCH_DIR("'+s+'")');
  128. HPath:=TCmdStrListItem(HPath.Next);
  129. end;
  130. LinkRes.Add('INPUT (');
  131. { add objectfiles, start with prt0 always }
  132. //s:=FindObjectFile('prt0','',false);
  133. if prtobj<>'' then
  134. begin
  135. s:=FindObjectFile(prtobj,'',false);
  136. LinkRes.AddFileName(s);
  137. end;
  138. { try to add crti and crtbegin if linking to C }
  139. if linklibc then
  140. begin
  141. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  142. LinkRes.AddFileName(s);
  143. if librarysearchpath.FindFile('crti.o',false,s) then
  144. LinkRes.AddFileName(s);
  145. end;
  146. while not ObjectFiles.Empty do
  147. begin
  148. s:=ObjectFiles.GetFirst;
  149. if s<>'' then
  150. begin
  151. { vlink doesn't use SEARCH_DIR for object files }
  152. if not(cs_link_on_target in current_settings.globalswitches) then
  153. s:=FindObjectFile(s,'',false);
  154. LinkRes.AddFileName((maybequoted(s)));
  155. end;
  156. end;
  157. { Write staticlibraries }
  158. if not StaticLibFiles.Empty then
  159. begin
  160. { vlink doesn't need, and doesn't support GROUP }
  161. if (cs_link_on_target in current_settings.globalswitches) then
  162. begin
  163. LinkRes.Add(')');
  164. LinkRes.Add('GROUP(');
  165. end;
  166. while not StaticLibFiles.Empty do
  167. begin
  168. S:=StaticLibFiles.GetFirst;
  169. LinkRes.AddFileName((maybequoted(s)));
  170. end;
  171. end;
  172. if (cs_link_on_target in current_settings.globalswitches) then
  173. begin
  174. LinkRes.Add(')');
  175. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  176. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  177. linklibc:=false;
  178. while not SharedLibFiles.Empty do
  179. begin
  180. S:=SharedLibFiles.GetFirst;
  181. if s<>'c' then
  182. begin
  183. i:=Pos(target_info.sharedlibext,S);
  184. if i>0 then
  185. Delete(S,i,255);
  186. LinkRes.Add('-l'+s);
  187. end
  188. else
  189. begin
  190. LinkRes.Add('-l'+s);
  191. linklibc:=true;
  192. end;
  193. end;
  194. { be sure that libc&libgcc is the last lib }
  195. if linklibc then
  196. begin
  197. LinkRes.Add('-lc');
  198. LinkRes.Add('-lgcc');
  199. end;
  200. end
  201. else
  202. begin
  203. while not SharedLibFiles.Empty do
  204. begin
  205. S:=SharedLibFiles.GetFirst;
  206. LinkRes.Add('lib'+s+target_info.staticlibext);
  207. end;
  208. LinkRes.Add(')');
  209. end;
  210. { objects which must be at the end }
  211. if linklibc then
  212. begin
  213. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  214. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  215. if found1 or found2 then
  216. begin
  217. LinkRes.Add('INPUT(');
  218. if found1 then
  219. LinkRes.AddFileName(s1);
  220. if found2 then
  221. LinkRes.AddFileName(s2);
  222. LinkRes.Add(')');
  223. end;
  224. end;
  225. {$ifdef ARM}
  226. case current_settings.controllertype of
  227. ct_none:
  228. begin
  229. end;
  230. ct_lpc810m021fn8,
  231. ct_lpc811m001fdh16,
  232. ct_lpc812m101fdh16,
  233. ct_lpc812m101fd20,
  234. ct_lpc812m101fdh20,
  235. ct_lpc1110fd20,
  236. ct_lpc1111fdh20_002,
  237. ct_lpc1111fhn33_101,
  238. ct_lpc1111fhn33_102,
  239. ct_lpc1111fhn33_103,
  240. ct_lpc1111fhn33_201,
  241. ct_lpc1111fhn33_202,
  242. ct_lpc1111fhn33_203,
  243. ct_lpc1112fd20_102,
  244. ct_lpc1112fdh20_102,
  245. ct_lpc1112fdh28_102,
  246. ct_lpc1112fhn33_101,
  247. ct_lpc1112fhn33_102,
  248. ct_lpc1112fhn33_103,
  249. ct_lpc1112fhn33_201,
  250. ct_lpc1112fhn24_202,
  251. ct_lpc1112fhn33_202,
  252. ct_lpc1112fhn33_203,
  253. ct_lpc1112fhi33_202,
  254. ct_lpc1112fhi33_203,
  255. ct_lpc1113fhn33_201,
  256. ct_lpc1113fhn33_202,
  257. ct_lpc1113fhn33_203,
  258. ct_lpc1113fhn33_301,
  259. ct_lpc1113fhn33_302,
  260. ct_lpc1113fhn33_303,
  261. ct_lpc1113bfd48_301,
  262. ct_lpc1113bfd48_302,
  263. ct_lpc1113bfd48_303,
  264. ct_lpc1114fdh28_102,
  265. ct_lpc1114fn28_102,
  266. ct_lpc1114fhn33_201,
  267. ct_lpc1114fhn33_202,
  268. ct_lpc1114fhn33_203,
  269. ct_lpc1114fhn33_301,
  270. ct_lpc1114fhn33_302,
  271. ct_lpc1114fhn33_303,
  272. ct_lpc1114fhn33_333,
  273. ct_lpc1114fhi33_302,
  274. ct_lpc1114fhi33_303,
  275. ct_lpc1114bfd48_301,
  276. ct_lpc1114bfd48_302,
  277. ct_lpc1114bfd48_303,
  278. ct_lpc1114bfd48_323,
  279. ct_lpc1114bfd48_333,
  280. ct_lpc1115bfd48_303,
  281. ct_lpc11c12fd48_301,
  282. ct_lpc11c14fd48_301,
  283. ct_lpc11c22fd48_301,
  284. ct_lpc11c24fd48_301,
  285. ct_lpc11d24fd48_301,
  286. ct_lpc1224fbd48_101,
  287. ct_lpc1224fbd48_121,
  288. ct_lpc1224fbd64_101,
  289. ct_lpc1224fbd64_121,
  290. ct_lpc1225fbd48_301,
  291. ct_lpc1225fbd48_321,
  292. ct_lpc1225fbd64_301,
  293. ct_lpc1225fbd64_321,
  294. ct_lpc1226fbd48_301,
  295. ct_lpc1226fbd64_301,
  296. ct_lpc1227fbd48_301,
  297. ct_lpc1227fbd64_301,
  298. ct_lpc12d27fbd100_301,
  299. ct_lpc1311fhn33,
  300. ct_lpc1311fhn33_01,
  301. ct_lpc1313fhn33,
  302. ct_lpc1313fhn33_01,
  303. ct_lpc1313fbd48,
  304. ct_lpc1313fbd48_01,
  305. ct_lpc1315fhn33,
  306. ct_lpc1315fbd48,
  307. ct_lpc1316fhn33,
  308. ct_lpc1316fbd48,
  309. ct_lpc1317fhn33,
  310. ct_lpc1317fbd48,
  311. ct_lpc1317fbd64,
  312. ct_lpc1342fhn33,
  313. ct_lpc1342fbd48,
  314. ct_lpc1343fhn33,
  315. ct_lpc1343fbd48,
  316. ct_lpc1345fhn33,
  317. ct_lpc1345fbd48,
  318. ct_lpc1346fhn33,
  319. ct_lpc1346fbd48,
  320. ct_lpc1347fhn33,
  321. ct_lpc1347fbd48,
  322. ct_lpc1347fbd64,
  323. ct_lpc2114,
  324. ct_lpc2124,
  325. ct_lpc2194,
  326. ct_lpc1768,
  327. ct_at91sam7s256,
  328. ct_at91sam7se256,
  329. ct_at91sam7x256,
  330. ct_at91sam7xc256,
  331. ct_stm32f030c6,
  332. ct_stm32f030c8,
  333. ct_stm32f030f4,
  334. ct_stm32f030k6,
  335. ct_stm32f030r8,
  336. ct_stm32f050c4,
  337. ct_stm32f050c6,
  338. ct_stm32f050f4,
  339. ct_stm32f050f6,
  340. ct_stm32f050g4,
  341. ct_stm32f050g6,
  342. ct_stm32f050k4,
  343. ct_stm32f050k6,
  344. ct_stm32f051c4,
  345. ct_stm32f051c6,
  346. ct_stm32f051c8,
  347. ct_stm32f051k4,
  348. ct_stm32f051k6,
  349. ct_stm32f051k8,
  350. ct_stm32f051r4,
  351. ct_stm32f051r6,
  352. ct_stm32f051r8,
  353. ct_stm32f091cc,
  354. ct_stm32f091cb,
  355. ct_stm32f091rc,
  356. ct_stm32f091rb,
  357. ct_stm32f091vc,
  358. ct_stm32f091vb,
  359. ct_stm32f100x4,
  360. ct_stm32f100x6,
  361. ct_stm32f100x8,
  362. ct_stm32f100xB,
  363. ct_stm32f100xC,
  364. ct_stm32f100xD,
  365. ct_stm32f100xE,
  366. ct_stm32f101x4,
  367. ct_stm32f101x6,
  368. ct_stm32f101x8,
  369. ct_stm32f101xB,
  370. ct_stm32f101xC,
  371. ct_stm32f101xD,
  372. ct_stm32f101xE,
  373. ct_stm32f101xF,
  374. ct_stm32f101xG,
  375. ct_stm32f102x4,
  376. ct_stm32f102x6,
  377. ct_stm32f102x8,
  378. ct_stm32f102xB,
  379. ct_stm32f103x4,
  380. ct_stm32f103x6,
  381. ct_stm32f103x8,
  382. ct_stm32f103xB,
  383. ct_stm32f103xC,
  384. ct_stm32f103xD,
  385. ct_stm32f103xE,
  386. ct_stm32f103xF,
  387. ct_stm32f103xG,
  388. ct_stm32f107x8,
  389. ct_stm32f107xB,
  390. ct_stm32f107xC,
  391. ct_stm32f105r8,
  392. ct_stm32f105rb,
  393. ct_stm32f105rc,
  394. ct_stm32f105v8,
  395. ct_stm32f105vb,
  396. ct_stm32f105vc,
  397. ct_stm32f107rb,
  398. ct_stm32f107rc,
  399. ct_stm32f107vb,
  400. ct_stm32f107vc,
  401. ct_stm32f401cb,
  402. ct_stm32f401rb,
  403. ct_stm32f401vb,
  404. ct_stm32f401cc,
  405. ct_stm32f401rc,
  406. ct_stm32f401vc,
  407. ct_discoveryf401vc,
  408. ct_stm32f401cd,
  409. ct_stm32f401rd,
  410. ct_stm32f401vd,
  411. ct_stm32f401ce,
  412. ct_stm32f401re,
  413. ct_nucleof401re,
  414. ct_stm32f401ve,
  415. ct_stm32f407vg,
  416. ct_discoveryf407vg,
  417. ct_stm32f407ig,
  418. ct_stm32f407zg,
  419. ct_stm32f407ve,
  420. ct_stm32f407ze,
  421. ct_stm32f407ie,
  422. ct_stm32f411cc,
  423. ct_stm32f411rc,
  424. ct_stm32f411vc,
  425. ct_stm32f411ce,
  426. ct_stm32f411re,
  427. ct_nucleof411re,
  428. ct_stm32f411ve,
  429. ct_discoveryf411ve,
  430. ct_stm32f429vg,
  431. ct_stm32f429zg,
  432. ct_stm32f429ig,
  433. ct_stm32f429vi,
  434. ct_stm32f429zi,
  435. ct_discoveryf429zi,
  436. ct_stm32f429ii,
  437. ct_stm32f429ve,
  438. ct_stm32f429ze,
  439. ct_stm32f429ie,
  440. ct_stm32f429bg,
  441. ct_stm32f429bi,
  442. ct_stm32f429be,
  443. ct_stm32f429ng,
  444. ct_stm32f429ni,
  445. ct_stm32f429ne,
  446. ct_stm32f446mc,
  447. ct_stm32f446rc,
  448. ct_stm32f446vc,
  449. ct_stm32f446zc,
  450. ct_stm32f446me,
  451. ct_stm32f446re,
  452. ct_nucleof446re,
  453. ct_stm32f446ve,
  454. ct_stm32f446ze,
  455. ct_stm32f745xe,
  456. ct_stm32f745xg,
  457. ct_stm32f746xe,
  458. ct_stm32f746xg,
  459. ct_stm32f756xe,
  460. ct_stm32f756xg,
  461. ct_stm32g071rb,
  462. ct_nucleog071rb,
  463. { TI - 64 K Flash, 16 K SRAM Devices }
  464. ct_lm3s1110,
  465. ct_lm3s1133,
  466. ct_lm3s1138,
  467. ct_lm3s1150,
  468. ct_lm3s1162,
  469. ct_lm3s1165,
  470. ct_lm3s1166,
  471. ct_lm3s2110,
  472. ct_lm3s2139,
  473. ct_lm3s6100,
  474. ct_lm3s6110,
  475. { TI 128 K Flash, 32 K SRAM devices - Fury Class }
  476. ct_lm3s1601,
  477. ct_lm3s1608,
  478. ct_lm3s1620,
  479. ct_lm3s1635,
  480. ct_lm3s1636,
  481. ct_lm3s1637,
  482. ct_lm3s1651,
  483. ct_lm3s2601,
  484. ct_lm3s2608,
  485. ct_lm3s2620,
  486. ct_lm3s2637,
  487. ct_lm3s2651,
  488. ct_lm3s6610,
  489. ct_lm3s6611,
  490. ct_lm3s6618,
  491. ct_lm3s6633,
  492. ct_lm3s6637,
  493. ct_lm3s8630,
  494. { TI 256 K Flase, 32 K SRAM devices - Fury Class }
  495. ct_lm3s1911,
  496. ct_lm3s1918,
  497. ct_lm3s1937,
  498. ct_lm3s1958,
  499. ct_lm3s1960,
  500. ct_lm3s1968,
  501. ct_lm3s1969,
  502. ct_lm3s2911,
  503. ct_lm3s2918,
  504. ct_lm3s2919,
  505. ct_lm3s2939,
  506. ct_lm3s2948,
  507. ct_lm3s2950,
  508. ct_lm3s2965,
  509. ct_lm3s6911,
  510. ct_lm3s6918,
  511. ct_lm3s6938,
  512. ct_lm3s6950,
  513. ct_lm3s6952,
  514. ct_lm3s6965,
  515. ct_lm3s8930,
  516. ct_lm3s8933,
  517. ct_lm3s8938,
  518. ct_lm3s8962,
  519. ct_lm3s8970,
  520. ct_lm3s8971,
  521. { TI - Tempest Tempest - 256 K Flash, 64 K SRAM }
  522. ct_lm3s5951,
  523. ct_lm3s5956,
  524. ct_lm3s1b21,
  525. ct_lm3s2b93,
  526. ct_lm3s5b91,
  527. ct_lm3s9b81,
  528. ct_lm3s9b90,
  529. ct_lm3s9b92,
  530. ct_lm3s9b95,
  531. ct_lm3s9b96,
  532. ct_lm3s5d51,
  533. { TI - Stellaris something }
  534. ct_lm4f120h5,
  535. { Infineon }
  536. ct_xmc4500x1024,
  537. ct_xmc4500x768,
  538. ct_xmc4502x768,
  539. ct_xmc4504x512,
  540. { Allwinner }
  541. ct_allwinner_a20,
  542. { Freescale }
  543. ct_mk20dx128vfm5,
  544. ct_mk20dx128vft5,
  545. ct_mk20dx128vlf5,
  546. ct_mk20dx128vlh5,
  547. ct_teensy30,
  548. ct_mk20dx128vmp5,
  549. ct_mk20dx32vfm5,
  550. ct_mk20dx32vft5,
  551. ct_mk20dx32vlf5,
  552. ct_mk20dx32vlh5,
  553. ct_mk20dx32vmp5,
  554. ct_mk20dx64vfm5,
  555. ct_mk20dx64vft5,
  556. ct_mk20dx64vlf5,
  557. ct_mk20dx64vlh5,
  558. ct_mk20dx64vmp5,
  559. ct_mk20dx128vlh7,
  560. ct_mk20dx128vlk7,
  561. ct_mk20dx128vll7,
  562. ct_mk20dx128vmc7,
  563. ct_mk20dx256vlh7,
  564. ct_mk20dx256vlk7,
  565. ct_mk20dx256vll7,
  566. ct_mk20dx256vmc7,
  567. ct_teensy31,
  568. ct_teensy32,
  569. ct_mk20dx64vlh7,
  570. ct_mk20dx64vlk7,
  571. ct_mk20dx64vmc7,
  572. ct_mk22fn512cap12,
  573. ct_mk22fn512cbp12,
  574. ct_mk22fn512vdc12,
  575. ct_mk22fn512vlh12,
  576. ct_mk22fn512vll12,
  577. ct_mk22fn512vmp12,
  578. ct_freedom_k22f,
  579. { Atmel }
  580. ct_sam3x8e,
  581. ct_samd51p19a,
  582. ct_arduino_due,
  583. ct_flip_n_click,
  584. ct_wio_terminal,
  585. { Nordic Semiconductor }
  586. ct_nrf51422_xxaa,
  587. ct_nrf51422_xxab,
  588. ct_nrf51422_xxac,
  589. ct_nrf51822_xxaa,
  590. ct_nrf51822_xxab,
  591. ct_nrf51822_xxac,
  592. ct_nrf52832_xxaa,
  593. ct_nrf52840_xxaa,
  594. ct_sc32442b,
  595. { Raspberry Pi 2 }
  596. ct_raspi2,
  597. ct_thumb2bare:
  598. begin
  599. with embedded_controllers[current_settings.controllertype] do
  600. with linkres do
  601. begin
  602. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  603. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  604. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  605. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  606. Add('ENTRY(_LOWLEVELSTART)')
  607. else
  608. Add('ENTRY(_START)');
  609. Add('MEMORY');
  610. Add('{');
  611. if flashsize<>0 then
  612. begin
  613. LinkStr := ' flash : ORIGIN = 0x' + IntToHex(flashbase,8)
  614. + ', LENGTH = 0x' + IntToHex(flashsize,8);
  615. Add(LinkStr);
  616. end;
  617. LinkStr := ' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  618. + ', LENGTH = 0x' + IntToHex(sramsize,8);
  619. Add(LinkStr);
  620. Add('}');
  621. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  622. // Add Checksum Calculation for LPC Controllers so that the bootloader starts the uploaded binary
  623. writeln(controllerunitstr);
  624. if (controllerunitstr = 'LPC8xx') or (controllerunitstr = 'LPC11XX') or (controllerunitstr = 'LPC122X') then
  625. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + Hardfault_interrupt + 1);');
  626. if (controllerunitstr = 'LPC13XX') then
  627. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + MemoryManagement_interrupt + 1 + BusFault_interrupt + 1 + UsageFault_interrupt + 1);');
  628. end;
  629. end
  630. else
  631. if not (cs_link_nolink in current_settings.globalswitches) then
  632. internalerror(200902011);
  633. end;
  634. with linkres do
  635. begin
  636. Add('SECTIONS');
  637. Add('{');
  638. Add(' .text :');
  639. Add(' {');
  640. Add(' _text_start = .;');
  641. Add(' KEEP(*(.init .init.*))');
  642. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  643. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  644. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  645. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  646. begin
  647. Add(' . = 0x400;');
  648. Add(' KEEP(*(.flash_config *.flash_config.*))');
  649. end;
  650. Add(' *(.text .text.*)');
  651. Add(' *(.strings)');
  652. Add(' *(.rodata .rodata.*)');
  653. Add(' *(.comment)');
  654. Add(' . = ALIGN(4);');
  655. Add(' _etext = .;');
  656. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  657. begin
  658. Add(' } >flash');
  659. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  660. end
  661. else
  662. begin
  663. Add(' } >ram');
  664. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  665. end;
  666. Add(' .data :');
  667. Add(' {');
  668. Add(' _data = .;');
  669. Add(' *(.data .data.*)');
  670. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  671. Add(' _edata = .;');
  672. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  673. begin
  674. Add(' } >ram AT >flash');
  675. end
  676. else
  677. begin
  678. Add(' } >ram');
  679. end;
  680. Add(' .bss :');
  681. Add(' {');
  682. Add(' _bss_start = .;');
  683. Add(' *(.bss .bss.*)');
  684. Add(' *(COMMON)');
  685. Add(' } >ram');
  686. Add('. = ALIGN(4);');
  687. Add('_bss_end = . ;');
  688. Add('}');
  689. Add('_end = .;');
  690. end;
  691. {$endif ARM}
  692. {$ifdef i386}
  693. with linkres do
  694. begin
  695. Add('ENTRY(_START)');
  696. Add('SECTIONS');
  697. Add('{');
  698. Add(' . = 0x100000;');
  699. Add(' .text ALIGN (0x1000) :');
  700. Add(' {');
  701. Add(' _text = .;');
  702. Add(' KEEP(*(.init .init.*))');
  703. Add(' *(.text .text.*)');
  704. Add(' *(.strings)');
  705. Add(' *(.rodata .rodata.*)');
  706. Add(' *(.comment)');
  707. Add(' _etext = .;');
  708. Add(' }');
  709. Add(' .data ALIGN (0x1000) :');
  710. Add(' {');
  711. Add(' _data = .;');
  712. Add(' *(.data .data.*)');
  713. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  714. Add(' _edata = .;');
  715. Add(' }');
  716. Add(' . = ALIGN(4);');
  717. Add(' .bss :');
  718. Add(' {');
  719. Add(' _bss_start = .;');
  720. Add(' *(.bss .bss.*)');
  721. Add(' *(COMMON)');
  722. Add(' }');
  723. Add('_bss_end = . ;');
  724. Add('}');
  725. Add('_end = .;');
  726. end;
  727. {$endif i386}
  728. {$ifdef x86_64}
  729. with linkres do
  730. begin
  731. Add('ENTRY(_START)');
  732. Add('SECTIONS');
  733. Add('{');
  734. Add(' . = 0x100000;');
  735. Add(' .text ALIGN (0x1000) :');
  736. Add(' {');
  737. Add(' _text = .;');
  738. Add(' KEEP(*(.init .init.*))');
  739. Add(' *(.text .text.*)');
  740. Add(' *(.strings)');
  741. Add(' *(.rodata .rodata.*)');
  742. Add(' *(.comment)');
  743. Add(' _etext = .;');
  744. Add(' }');
  745. Add(' .data ALIGN (0x1000) :');
  746. Add(' {');
  747. Add(' _data = .;');
  748. Add(' *(.data .data.*)');
  749. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  750. Add(' _edata = .;');
  751. Add(' }');
  752. Add(' . = ALIGN(4);');
  753. Add(' .bss :');
  754. Add(' {');
  755. Add(' _bss_start = .;');
  756. Add(' *(.bss .bss.*)');
  757. Add(' *(COMMON)');
  758. Add(' }');
  759. Add('_bss_end = . ;');
  760. Add('}');
  761. Add('_end = .;');
  762. end;
  763. {$endif x86_64}
  764. {$ifdef AVR}
  765. with linkres do
  766. begin
  767. { linker script from ld 2.19 }
  768. Add('ENTRY(_START)');
  769. Add('OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")');
  770. case current_settings.cputype of
  771. cpu_avr1:
  772. Add('OUTPUT_ARCH(avr:1)');
  773. cpu_avr2:
  774. Add('OUTPUT_ARCH(avr:2)');
  775. cpu_avr25:
  776. Add('OUTPUT_ARCH(avr:25)');
  777. cpu_avr3:
  778. Add('OUTPUT_ARCH(avr:3)');
  779. cpu_avr31:
  780. Add('OUTPUT_ARCH(avr:31)');
  781. cpu_avr35:
  782. Add('OUTPUT_ARCH(avr:35)');
  783. cpu_avr4:
  784. Add('OUTPUT_ARCH(avr:4)');
  785. cpu_avr5:
  786. Add('OUTPUT_ARCH(avr:5)');
  787. cpu_avr51:
  788. Add('OUTPUT_ARCH(avr:51)');
  789. cpu_avr6:
  790. Add('OUTPUT_ARCH(avr:6)');
  791. cpu_avrxmega3:
  792. Add('OUTPUT_ARCH(avr:103)');
  793. cpu_avrtiny:
  794. Add('OUTPUT_ARCH(avr:100)');
  795. else
  796. Internalerror(2015072701);
  797. end;
  798. Add('MEMORY');
  799. with embedded_controllers[current_settings.controllertype] do
  800. begin
  801. Add('{');
  802. Add(' text (rx) : ORIGIN = 0, LENGTH = 0x'+IntToHex(flashsize,6));
  803. Add(' data (rw!x) : ORIGIN = 0x'+IntToHex($800000+srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  804. Add(' eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 0x'+IntToHex(eepromsize,6));
  805. Add(' fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K');
  806. Add(' lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K');
  807. Add(' signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K');
  808. Add('}');
  809. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  810. end;
  811. Add('SECTIONS');
  812. Add('{');
  813. Add(' /* Read-only sections, merged into text segment: */');
  814. Add(' .hash : { *(.hash) }');
  815. Add(' .dynsym : { *(.dynsym) }');
  816. Add(' .dynstr : { *(.dynstr) }');
  817. Add(' .gnu.version : { *(.gnu.version) }');
  818. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  819. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  820. Add(' .rel.init : { *(.rel.init) }');
  821. Add(' .rela.init : { *(.rela.init) }');
  822. Add(' .rel.text :');
  823. Add(' {');
  824. Add(' *(.rel.text)');
  825. Add(' *(.rel.text.*)');
  826. Add(' *(.rel.gnu.linkonce.t*)');
  827. Add(' }');
  828. Add(' .rela.text :');
  829. Add(' {');
  830. Add(' *(.rela.text)');
  831. Add(' *(.rela.text.*)');
  832. Add(' *(.rela.gnu.linkonce.t*)');
  833. Add(' }');
  834. Add(' .rel.fini : { *(.rel.fini) }');
  835. Add(' .rela.fini : { *(.rela.fini) }');
  836. Add(' .rel.rodata :');
  837. Add(' {');
  838. Add(' *(.rel.rodata)');
  839. Add(' *(.rel.rodata.*)');
  840. Add(' *(.rel.gnu.linkonce.r*)');
  841. Add(' }');
  842. Add(' .rela.rodata :');
  843. Add(' {');
  844. Add(' *(.rela.rodata)');
  845. Add(' *(.rela.rodata.*)');
  846. Add(' *(.rela.gnu.linkonce.r*)');
  847. Add(' }');
  848. Add(' .rel.data :');
  849. Add(' {');
  850. Add(' *(.rel.data)');
  851. Add(' *(.rel.data.*)');
  852. Add(' *(.rel.gnu.linkonce.d*)');
  853. Add(' }');
  854. Add(' .rela.data :');
  855. Add(' {');
  856. Add(' *(.rela.data)');
  857. Add(' *(.rela.data.*)');
  858. Add(' *(.rela.gnu.linkonce.d*)');
  859. Add(' }');
  860. Add(' .rel.ctors : { *(.rel.ctors) }');
  861. Add(' .rela.ctors : { *(.rela.ctors) }');
  862. Add(' .rel.dtors : { *(.rel.dtors) }');
  863. Add(' .rela.dtors : { *(.rela.dtors) }');
  864. Add(' .rel.got : { *(.rel.got) }');
  865. Add(' .rela.got : { *(.rela.got) }');
  866. Add(' .rel.bss : { *(.rel.bss) }');
  867. Add(' .rela.bss : { *(.rela.bss) }');
  868. Add(' .rel.plt : { *(.rel.plt) }');
  869. Add(' .rela.plt : { *(.rela.plt) }');
  870. Add(' /* Internal text space or external memory. */');
  871. Add(' .text :');
  872. Add(' {');
  873. Add(' KEEP(*(.init .init.*))');
  874. Add(' /* For data that needs to reside in the lower 64k of progmem. */');
  875. Add(' *(.progmem.gcc*)');
  876. Add(' *(.progmem*)');
  877. Add(' . = ALIGN(2);');
  878. Add(' __trampolines_start = . ;');
  879. Add(' /* The jump trampolines for the 16-bit limited relocs will reside here. */');
  880. Add(' *(.trampolines)');
  881. Add(' *(.trampolines*)');
  882. Add(' __trampolines_end = . ;');
  883. Add(' /* For future tablejump instruction arrays for 3 byte pc devices.');
  884. Add(' We don''t relax jump/call instructions within these sections. */');
  885. Add(' *(.jumptables)');
  886. Add(' *(.jumptables*)');
  887. Add(' /* For code that needs to reside in the lower 128k progmem. */');
  888. Add(' *(.lowtext)');
  889. Add(' *(.lowtext*)');
  890. Add(' __ctors_start = . ;');
  891. Add(' *(.ctors)');
  892. Add(' __ctors_end = . ;');
  893. Add(' __dtors_start = . ;');
  894. Add(' *(.dtors)');
  895. Add(' __dtors_end = . ;');
  896. Add(' KEEP(SORT(*)(.ctors))');
  897. Add(' KEEP(SORT(*)(.dtors))');
  898. Add(' /* From this point on, we don''t bother about wether the insns are');
  899. Add(' below or above the 16 bits boundary. */');
  900. Add(' *(.init0) /* Start here after reset. */');
  901. Add(' KEEP (*(.init0))');
  902. Add(' *(.init1)');
  903. Add(' KEEP (*(.init1))');
  904. Add(' *(.init2) /* Clear __zero_reg__, set up stack pointer. */');
  905. Add(' KEEP (*(.init2))');
  906. Add(' *(.init3)');
  907. Add(' KEEP (*(.init3))');
  908. Add(' *(.init4) /* Initialize data and BSS. */');
  909. Add(' KEEP (*(.init4))');
  910. Add(' *(.init5)');
  911. Add(' KEEP (*(.init5))');
  912. Add(' *(.init6) /* C++ constructors. */');
  913. Add(' KEEP (*(.init6))');
  914. Add(' *(.init7)');
  915. Add(' KEEP (*(.init7))');
  916. Add(' *(.init8)');
  917. Add(' KEEP (*(.init8))');
  918. Add(' *(.init9) /* Call main(). */');
  919. Add(' KEEP (*(.init9))');
  920. Add(' *(.text)');
  921. Add(' . = ALIGN(2);');
  922. Add(' *(.text.*)');
  923. Add(' . = ALIGN(2);');
  924. Add(' *(.fini9) /* _exit() starts here. */');
  925. Add(' KEEP (*(.fini9))');
  926. Add(' *(.fini8)');
  927. Add(' KEEP (*(.fini8))');
  928. Add(' *(.fini7)');
  929. Add(' KEEP (*(.fini7))');
  930. Add(' *(.fini6) /* C++ destructors. */');
  931. Add(' KEEP (*(.fini6))');
  932. Add(' *(.fini5)');
  933. Add(' KEEP (*(.fini5))');
  934. Add(' *(.fini4)');
  935. Add(' KEEP (*(.fini4))');
  936. Add(' *(.fini3)');
  937. Add(' KEEP (*(.fini3))');
  938. Add(' *(.fini2)');
  939. Add(' KEEP (*(.fini2))');
  940. Add(' *(.fini1)');
  941. Add(' KEEP (*(.fini1))');
  942. Add(' *(.fini0) /* Infinite loop after program termination. */');
  943. Add(' KEEP (*(.fini0))');
  944. Add(' _etext = . ;');
  945. Add(' } > text');
  946. Add(' .data : AT (ADDR (.text) + SIZEOF (.text))');
  947. Add(' {');
  948. Add(' PROVIDE (__data_start = .) ;');
  949. Add(' *(.data)');
  950. Add(' *(.data*)');
  951. Add(' *(.rodata) /* We need to include .rodata here if gcc is used */');
  952. Add(' *(.rodata*) /* with -fdata-sections. */');
  953. Add(' *(.gnu.linkonce.d*)');
  954. Add(' . = ALIGN(2);');
  955. Add(' _edata = . ;');
  956. Add(' PROVIDE (__data_end = .) ;');
  957. Add(' } > data');
  958. Add(' .bss : AT (ADDR (.bss))');
  959. Add(' {');
  960. Add(' PROVIDE (__bss_start = .) ;');
  961. Add(' *(.bss)');
  962. Add(' *(.bss*)');
  963. Add(' *(COMMON)');
  964. Add(' PROVIDE (__bss_end = .) ;');
  965. Add(' } > data');
  966. Add(' __data_load_start = LOADADDR(.data);');
  967. Add(' __data_load_end = __data_load_start + SIZEOF(.data);');
  968. Add(' /* Global data not cleared after reset. */');
  969. Add(' .noinit :');
  970. Add(' {');
  971. Add(' PROVIDE (__noinit_start = .) ;');
  972. Add(' *(.noinit*)');
  973. Add(' PROVIDE (__noinit_end = .) ;');
  974. Add(' _end = . ;');
  975. Add(' PROVIDE (__heap_start = .) ;');
  976. Add(' } > data');
  977. Add(' .eeprom :');
  978. Add(' {');
  979. Add(' *(.eeprom*)');
  980. Add(' __eeprom_end = . ;');
  981. Add(' } > eeprom');
  982. Add(' .fuse :');
  983. Add(' {');
  984. Add(' KEEP(*(.fuse))');
  985. Add(' KEEP(*(.lfuse))');
  986. Add(' KEEP(*(.hfuse))');
  987. Add(' KEEP(*(.efuse))');
  988. Add(' } > fuse');
  989. Add(' .lock :');
  990. Add(' {');
  991. Add(' KEEP(*(.lock*))');
  992. Add(' } > lock');
  993. Add(' .signature :');
  994. Add(' {');
  995. Add(' KEEP(*(.signature*))');
  996. Add(' } > signature');
  997. Add(' /* Stabs debugging sections. */');
  998. Add(' .stab 0 : { *(.stab) }');
  999. Add(' .stabstr 0 : { *(.stabstr) }');
  1000. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1001. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1002. Add(' .stab.index 0 : { *(.stab.index) }');
  1003. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1004. Add(' .comment 0 : { *(.comment) }');
  1005. Add(' /* DWARF debug sections.');
  1006. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1007. Add(' of the section so we begin them at 0. */');
  1008. Add(' /* DWARF 1 */');
  1009. Add(' .debug 0 : { *(.debug) }');
  1010. Add(' .line 0 : { *(.line) }');
  1011. Add(' /* GNU DWARF 1 extensions */');
  1012. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1013. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1014. Add(' /* DWARF 1.1 and DWARF 2 */');
  1015. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1016. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1017. Add(' /* DWARF 2 */');
  1018. Add(' .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }');
  1019. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1020. Add(' .debug_line 0 : { *(.debug_line) }');
  1021. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1022. Add(' .debug_str 0 : { *(.debug_str) }');
  1023. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1024. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1025. Add(' /* DWARF 3 */');
  1026. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1027. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1028. Add(' /* DWARF Extension. */');
  1029. Add(' .debug_macro 0 : { *(.debug_macro) }');
  1030. Add('}');
  1031. end;
  1032. {$endif AVR}
  1033. {$ifdef MIPSEL}
  1034. case current_settings.controllertype of
  1035. ct_none:
  1036. begin
  1037. end;
  1038. ct_pic32mx110f016b,
  1039. ct_pic32mx110f016c,
  1040. ct_pic32mx110f016d,
  1041. ct_pic32mx120f032b,
  1042. ct_pic32mx120f032c,
  1043. ct_pic32mx120f032d,
  1044. ct_pic32mx130f064b,
  1045. ct_pic32mx130f064c,
  1046. ct_pic32mx130f064d,
  1047. ct_pic32mx150f128b,
  1048. ct_pic32mx150f128c,
  1049. ct_pic32mx150f128d,
  1050. ct_pic32mx210f016b,
  1051. ct_pic32mx210f016c,
  1052. ct_pic32mx210f016d,
  1053. ct_pic32mx220f032b,
  1054. ct_pic32mx220f032c,
  1055. ct_pic32mx220f032d,
  1056. ct_pic32mx230f064b,
  1057. ct_pic32mx230f064c,
  1058. ct_pic32mx230f064d,
  1059. ct_pic32mx250f128b,
  1060. ct_pic32mx250f128c,
  1061. ct_pic32mx250f128d,
  1062. ct_pic32mx775f256h,
  1063. ct_pic32mx775f256l,
  1064. ct_pic32mx775f512h,
  1065. ct_pic32mx775f512l,
  1066. ct_pic32mx795f512h,
  1067. ct_pic32mx795f512l:
  1068. begin
  1069. with embedded_controllers[current_settings.controllertype] do
  1070. with linkres do
  1071. begin
  1072. Add('OUTPUT_FORMAT("elf32-tradlittlemips")');
  1073. Add('OUTPUT_ARCH(pic32mx)');
  1074. Add('ENTRY(_reset)');
  1075. Add('PROVIDE(_vector_spacing = 0x00000001);');
  1076. Add('_ebase_address = 0x'+IntToHex(flashbase,8)+';');
  1077. Add('_RESET_ADDR = 0xBFC00000;');
  1078. Add('_BEV_EXCPT_ADDR = 0xBFC00380;');
  1079. Add('_DBG_EXCPT_ADDR = 0xBFC00480;');
  1080. Add('_GEN_EXCPT_ADDR = _ebase_address + 0x180;');
  1081. Add('MEMORY');
  1082. Add('{');
  1083. if flashsize<>0 then
  1084. begin
  1085. Add(' kseg0_program_mem : ORIGIN = 0x'+IntToHex(flashbase,8)+', LENGTH = 0x'+IntToHex(flashsize,8));
  1086. //TODO This should better be placed into the controllertype records
  1087. Add(' kseg1_boot_mem : ORIGIN = 0xBFC00000, LENGTH = 0xbef');
  1088. Add(' config3 : ORIGIN = 0xBFC00BF0, LENGTH = 0x4');
  1089. Add(' config2 : ORIGIN = 0xBFC00BF4, LENGTH = 0x4');
  1090. Add(' config1 : ORIGIN = 0xBFC00BF8, LENGTH = 0x4');
  1091. Add(' config0 : ORIGIN = 0xBFC00BFC, LENGTH = 0x4');
  1092. end;
  1093. Add(' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  1094. + ', LENGTH = 0x' + IntToHex(sramsize,8));
  1095. Add('}');
  1096. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  1097. end;
  1098. end
  1099. end;
  1100. with linkres do
  1101. begin
  1102. Add('SECTIONS');
  1103. Add('{');
  1104. Add(' .reset _RESET_ADDR :');
  1105. Add(' {');
  1106. Add(' KEEP(*(.reset .reset.*))');
  1107. Add(' KEEP(*(.startup .startup.*))');
  1108. Add(' } > kseg1_boot_mem');
  1109. Add(' .bev_excpt _BEV_EXCPT_ADDR :');
  1110. Add(' {');
  1111. Add(' KEEP(*(.bev_handler))');
  1112. Add(' } > kseg1_boot_mem');
  1113. Add(' .text :');
  1114. Add(' {');
  1115. Add(' _text_start = .;');
  1116. Add(' . = _text_start + 0x180;');
  1117. Add(' KEEP(*(.gen_handler))');
  1118. Add(' . = _text_start + 0x200;');
  1119. Add(' KEEP(*(.init .init.*))');
  1120. Add(' *(.text .text.*)');
  1121. Add(' *(.strings)');
  1122. Add(' *(.rodata .rodata.*)');
  1123. Add(' *(.comment)');
  1124. Add(' _etext = .;');
  1125. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1126. begin
  1127. Add(' } >kseg0_program_mem');
  1128. end
  1129. else
  1130. begin
  1131. Add(' } >ram');
  1132. end;
  1133. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1134. Add(' .data :');
  1135. Add(' {');
  1136. Add(' _data = .;');
  1137. Add(' *(.data .data.*)');
  1138. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1139. Add(' . = .;');
  1140. Add(' _gp = ALIGN(16) + 0x7ff0;');
  1141. Add(' _edata = .;');
  1142. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1143. begin
  1144. Add(' } >ram AT >kseg0_program_mem');
  1145. end
  1146. else
  1147. begin
  1148. Add(' } >ram');
  1149. end;
  1150. Add(' .config_BFC00BF0 : {');
  1151. Add(' KEEP(*(.config_BFC00BF0))');
  1152. Add(' } > config3');
  1153. Add(' .config_BFC00BF4 : {');
  1154. Add(' KEEP(*(.config_BFC00BF4))');
  1155. Add(' } > config2');
  1156. Add(' .config_BFC00BF8 : {');
  1157. Add(' KEEP(*(.config_BFC00BF8))');
  1158. Add(' } > config1');
  1159. Add(' .config_BFC00BFC : {');
  1160. Add(' KEEP(*(.config_BFC00BFC))');
  1161. Add(' } > config0');
  1162. Add(' .bss :');
  1163. Add(' {');
  1164. Add(' _bss_start = .;');
  1165. Add(' *(.bss .bss.*)');
  1166. Add(' *(COMMON)');
  1167. Add(' } >ram');
  1168. Add('. = ALIGN(4);');
  1169. Add('_bss_end = . ;');
  1170. Add(' .comment 0 : { *(.comment) }');
  1171. Add(' /* DWARF debug sections.');
  1172. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1173. Add(' of the section so we begin them at 0. */');
  1174. Add(' /* DWARF 1 */');
  1175. Add(' .debug 0 : { *(.debug) }');
  1176. Add(' .line 0 : { *(.line) }');
  1177. Add(' /* GNU DWARF 1 extensions */');
  1178. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1179. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1180. Add(' /* DWARF 1.1 and DWARF 2 */');
  1181. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1182. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1183. Add(' /* DWARF 2 */');
  1184. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1185. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1186. Add(' /DISCARD/ : { *(.debug_line) }');
  1187. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1188. Add(' .debug_str 0 : { *(.debug_str) }');
  1189. Add(' /DISCARD/ : { *(.debug_loc) }');
  1190. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1191. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1192. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1193. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1194. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1195. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1196. Add(' /* DWARF 3 */');
  1197. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1198. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1199. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1200. Add(' .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }');
  1201. Add(' .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }');
  1202. Add(' .mdebug.abi32 : { KEEP(*(.mdebug.abi32)) }');
  1203. Add(' .mdebug.abiN32 : { KEEP(*(.mdebug.abiN32)) }');
  1204. Add(' .mdebug.abi64 : { KEEP(*(.mdebug.abi64)) }');
  1205. Add(' .mdebug.abiO64 : { KEEP(*(.mdebug.abiO64)) }');
  1206. Add(' .mdebug.eabi32 : { KEEP(*(.mdebug.eabi32)) }');
  1207. Add(' .mdebug.eabi64 : { KEEP(*(.mdebug.eabi64)) }');
  1208. Add(' /DISCARD/ : { *(.rel.dyn) }');
  1209. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1210. Add('}');
  1211. Add('_end = .;');
  1212. end;
  1213. {$endif MIPSEL}
  1214. {$ifdef RISCV32}
  1215. with linkres do
  1216. begin
  1217. Add('OUTPUT_ARCH("riscv")');
  1218. Add('ENTRY(_START)');
  1219. Add('MEMORY');
  1220. with embedded_controllers[current_settings.controllertype] do
  1221. begin
  1222. Add('{');
  1223. Add(' flash (rx) : ORIGIN = 0x'+IntToHex(flashbase,6)+', LENGTH = 0x'+IntToHex(flashsize,6));
  1224. Add(' ram (rw!x) : ORIGIN = 0x'+IntToHex(srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  1225. Add('}');
  1226. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  1227. end;
  1228. Add('SECTIONS');
  1229. Add('{');
  1230. Add(' .text :');
  1231. Add(' {');
  1232. Add(' _text_start = .;');
  1233. Add(' KEEP(*(.init .init.*))');
  1234. Add(' *(.text .text.*)');
  1235. Add(' *(.strings)');
  1236. Add(' *(.rodata .rodata.*)');
  1237. Add(' *(.comment)');
  1238. Add(' . = ALIGN(4);');
  1239. Add(' _etext = .;');
  1240. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1241. begin
  1242. Add(' } >flash');
  1243. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  1244. end
  1245. else
  1246. begin
  1247. Add(' } >ram');
  1248. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  1249. end;
  1250. Add(' .data :');
  1251. Add(' {');
  1252. Add(' _data = .;');
  1253. Add(' *(.data .data.*)');
  1254. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1255. Add(' _edata = .;');
  1256. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1257. begin
  1258. Add(' } >ram AT >flash');
  1259. end
  1260. else
  1261. begin
  1262. Add(' } >ram');
  1263. end;
  1264. Add(' .bss :');
  1265. Add(' {');
  1266. Add(' _bss_start = .;');
  1267. Add(' *(.bss .bss.*)');
  1268. Add(' *(COMMON)');
  1269. Add(' } >ram');
  1270. Add(' . = ALIGN(4);');
  1271. Add(' _bss_end = . ;');
  1272. Add(' /* Stabs debugging sections. */');
  1273. Add(' .stab 0 : { *(.stab) }');
  1274. Add(' .stabstr 0 : { *(.stabstr) }');
  1275. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1276. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1277. Add(' .stab.index 0 : { *(.stab.index) }');
  1278. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1279. Add(' .comment 0 : { *(.comment) }');
  1280. Add(' /* DWARF debug sections.');
  1281. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1282. Add(' of the section so we begin them at 0. */');
  1283. Add(' /* DWARF 1 */');
  1284. Add(' .debug 0 : { *(.debug) }');
  1285. Add(' .line 0 : { *(.line) }');
  1286. Add(' /* GNU DWARF 1 extensions */');
  1287. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1288. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1289. Add(' /* DWARF 1.1 and DWARF 2 */');
  1290. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1291. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1292. Add(' /* DWARF 2 */');
  1293. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1294. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1295. Add(' .debug_line 0 : { *(.debug_line) }');
  1296. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1297. Add(' .debug_str 0 : { *(.debug_str) }');
  1298. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1299. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1300. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1301. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1302. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1303. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1304. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1305. Add(' /* DWARF 3 */');
  1306. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1307. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1308. Add('}');
  1309. Add('_end = .;');
  1310. end;
  1311. {$endif RISCV32}
  1312. {$ifdef XTENSA}
  1313. with linkres do
  1314. begin
  1315. Add('/* Script for -z combreloc: combine and sort reloc sections */');
  1316. Add('/* Copyright (C) 2014-2018 Free Software Foundation, Inc.');
  1317. Add(' Copying and distribution of this script, with or without modification,');
  1318. Add(' are permitted in any medium without royalty provided the copyright');
  1319. Add(' notice and this notice are preserved. */');
  1320. Add('ENTRY(_start)');
  1321. Add('SEARCH_DIR("=/builds/idf/crosstool-NG/builds/xtensa-esp32-elf/xtensa-esp32-elf/lib"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");');
  1322. Add('SECTIONS');
  1323. Add('{');
  1324. Add(' /* Read-only sections, merged into text segment: */');
  1325. Add(' PROVIDE (__executable_start = 0x400000); . = 0x400000 + SIZEOF_HEADERS;');
  1326. Add(' .interp : { *(.interp) }');
  1327. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1328. Add(' .hash : { *(.hash) }');
  1329. Add(' .gnu.hash : { *(.gnu.hash) }');
  1330. Add(' .dynsym : { *(.dynsym) }');
  1331. Add(' .dynstr : { *(.dynstr) }');
  1332. Add(' .gnu.version : { *(.gnu.version) }');
  1333. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  1334. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  1335. Add(' .rela.dyn :');
  1336. Add(' {');
  1337. Add(' *(.rela.init)');
  1338. Add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  1339. Add(' *(.rela.fini)');
  1340. Add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  1341. Add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  1342. Add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  1343. Add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  1344. Add(' *(.rela.ctors)');
  1345. Add(' *(.rela.dtors)');
  1346. Add(' *(.rela.got)');
  1347. Add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  1348. Add(' }');
  1349. Add(' .rela.plt : { *(.rela.plt) }');
  1350. Add(' /* .plt* sections are embedded in .text */');
  1351. Add(' .text :');
  1352. Add(' {');
  1353. Add(' *(.got.plt* .plt*)');
  1354. Add(' KEEP (*(.init.literal))');
  1355. Add(' KEEP (*(SORT_NONE(.init)))');
  1356. Add(' *(.literal .text .stub .literal.* .text.* .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)');
  1357. Add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  1358. Add(' *(.gnu.warning)');
  1359. Add(' KEEP (*(.fini.literal))');
  1360. Add(' KEEP (*(SORT_NONE(.fini)))');
  1361. Add(' } =0');
  1362. Add(' PROVIDE (__etext = .);');
  1363. Add(' PROVIDE (_etext = .);');
  1364. Add(' PROVIDE (etext = .);');
  1365. Add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
  1366. Add(' .rodata1 : { *(.rodata1) }');
  1367. Add(' .got.loc : { *(.got.loc) }');
  1368. Add(' .xt_except_table : ONLY_IF_RO { KEEP (*(.xt_except_table .xt_except_table.* .gnu.linkonce.e.*)) }');
  1369. Add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  1370. Add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  1371. Add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }');
  1372. Add(' /* Adjust the address for the data segment. We want to adjust up to');
  1373. Add(' the same address within the page on the next page up. */');
  1374. Add(' . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));');
  1375. Add(' /* Exception handling */');
  1376. Add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  1377. Add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  1378. Add(' /* Thread Local Storage sections */');
  1379. Add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  1380. Add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  1381. Add(' .preinit_array :');
  1382. Add(' {');
  1383. Add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
  1384. Add(' KEEP (*(.preinit_array))');
  1385. Add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
  1386. Add(' }');
  1387. Add(' .init_array :');
  1388. Add(' {');
  1389. Add(' PROVIDE_HIDDEN (__init_array_start = .);');
  1390. Add(' KEEP (*(SORT(.init_array.*)))');
  1391. Add(' KEEP (*(.init_array))');
  1392. Add(' PROVIDE_HIDDEN (__init_array_end = .);');
  1393. Add(' }');
  1394. Add(' .fini_array :');
  1395. Add(' {');
  1396. Add(' PROVIDE_HIDDEN (__fini_array_start = .);');
  1397. Add(' KEEP (*(SORT(.fini_array.*)))');
  1398. Add(' KEEP (*(.fini_array))');
  1399. Add(' PROVIDE_HIDDEN (__fini_array_end = .);');
  1400. Add(' }');
  1401. Add(' .ctors :');
  1402. Add(' {');
  1403. Add(' /* gcc uses crtbegin.o to find the start of');
  1404. Add(' the constructors, so we make sure it is');
  1405. Add(' first. Because this is a wildcard, it');
  1406. Add(' doesn''t matter if the user does not');
  1407. Add(' actually link against crtbegin.o; the');
  1408. Add(' linker won''t look for a file to match a');
  1409. Add(' wildcard. The wildcard also means that it');
  1410. Add(' doesn''t matter which directory crtbegin.o');
  1411. Add(' is in. */');
  1412. Add(' KEEP (*crtbegin.o(.ctors))');
  1413. Add(' KEEP (*crtbegin?.o(.ctors))');
  1414. Add(' /* We don''t want to include the .ctor section from');
  1415. Add(' the crtend.o file until after the sorted ctors.');
  1416. Add(' The .ctor section from the crtend file contains the');
  1417. Add(' end of ctors marker and it must be last */');
  1418. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
  1419. Add(' KEEP (*(SORT(.ctors.*)))');
  1420. Add(' KEEP (*(.ctors))');
  1421. Add(' }');
  1422. Add(' .dtors :');
  1423. Add(' {');
  1424. Add(' KEEP (*crtbegin.o(.dtors))');
  1425. Add(' KEEP (*crtbegin?.o(.dtors))');
  1426. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
  1427. Add(' KEEP (*(SORT(.dtors.*)))');
  1428. Add(' KEEP (*(.dtors))');
  1429. Add(' }');
  1430. Add(' .jcr : { KEEP (*(.jcr)) }');
  1431. Add(' .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }');
  1432. Add(' .xt_except_table : ONLY_IF_RW { KEEP (*(.xt_except_table .xt_except_table.* .gnu.linkonce.e.*)) }');
  1433. Add(' .dynamic : { *(.dynamic) }');
  1434. Add(' .got : { *(.got) }');
  1435. Add(' .data :');
  1436. Add(' {');
  1437. Add(' *(.data .data.* .gnu.linkonce.d.*)');
  1438. Add(' SORT(CONSTRUCTORS)');
  1439. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1440. Add(' }');
  1441. Add(' .data1 : { *(.data1) }');
  1442. Add(' .xt_except_desc :');
  1443. Add(' {');
  1444. Add(' *(.xt_except_desc .xt_except_desc.* .gnu.linkonce.h.*)');
  1445. Add(' *(.xt_except_desc_end)');
  1446. Add(' }');
  1447. Add(' .lit4 :');
  1448. Add(' {');
  1449. Add(' PROVIDE (_lit4_start = .);');
  1450. Add(' *(.lit4 .lit4.* .gnu.linkonce.lit4.*)');
  1451. Add(' PROVIDE (_lit4_end = .);');
  1452. Add(' }');
  1453. Add(' _edata = .; PROVIDE (edata = .);');
  1454. Add(' __bss_start = .;');
  1455. Add(' .bss :');
  1456. Add(' {');
  1457. Add(' *(.dynbss)');
  1458. Add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  1459. Add(' *(COMMON)');
  1460. Add(' /* Align here to ensure that the .bss section occupies space up to');
  1461. Add(' _end. Align after .bss to ensure correct alignment even if the');
  1462. Add(' .bss section disappears because there are no input sections.');
  1463. Add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
  1464. Add(' pad the .data section. */');
  1465. Add(' . = ALIGN(. != 0 ? 32 / 8 : 1);');
  1466. Add(' }');
  1467. Add(' . = ALIGN(32 / 8);');
  1468. Add(' . = ALIGN(32 / 8);');
  1469. Add(' _end = .; PROVIDE (end = .);');
  1470. Add(' /* Stabs debugging sections. */');
  1471. Add(' .stab 0 : { *(.stab) }');
  1472. Add(' .stabstr 0 : { *(.stabstr) }');
  1473. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1474. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1475. Add(' .stab.index 0 : { *(.stab.index) }');
  1476. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1477. Add(' .comment 0 : { *(.comment) }');
  1478. Add(' /* DWARF debug sections.');
  1479. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1480. Add(' of the section so we begin them at 0. */');
  1481. Add(' /* DWARF 1 */');
  1482. Add(' .debug 0 : { *(.debug) }');
  1483. Add(' .line 0 : { *(.line) }');
  1484. Add(' /* GNU DWARF 1 extensions */');
  1485. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1486. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1487. Add(' /* DWARF 1.1 and DWARF 2 */');
  1488. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1489. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1490. Add(' /* DWARF 2 */');
  1491. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1492. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1493. Add(' .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }');
  1494. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1495. Add(' .debug_str 0 : { *(.debug_str) }');
  1496. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1497. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1498. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1499. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1500. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1501. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1502. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1503. Add(' /* DWARF 3 */');
  1504. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1505. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1506. Add(' /* DWARF Extension. */');
  1507. Add(' .debug_macro 0 : { *(.debug_macro) }');
  1508. Add(' .debug_addr 0 : { *(.debug_addr) }');
  1509. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1510. Add(' .xt.lit 0 : { KEEP (*(.xt.lit .xt.lit.* .gnu.linkonce.p.*)) }');
  1511. Add(' .xt.insn 0 : { KEEP (*(.xt.insn .gnu.linkonce.x.*)) }');
  1512. Add(' .xt.prop 0 : { KEEP (*(.xt.prop .xt.prop.* .gnu.linkonce.prop.*)) }');
  1513. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1514. Add('}');
  1515. end;
  1516. {$endif XTENSA}
  1517. { Write and Close response }
  1518. linkres.writetodisk;
  1519. linkres.free;
  1520. WriteResponseFile:=True;
  1521. end;
  1522. function TlinkerEmbedded.MakeExecutable:boolean;
  1523. var
  1524. binstr,
  1525. cmdstr,
  1526. mapstr: TCmdStr;
  1527. success : boolean;
  1528. StaticStr,
  1529. GCSectionsStr,
  1530. DynLinkStr,
  1531. StripStr,
  1532. FixedExeFileName: string;
  1533. begin
  1534. { for future use }
  1535. StaticStr:='';
  1536. StripStr:='';
  1537. mapstr:='';
  1538. DynLinkStr:='';
  1539. FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
  1540. GCSectionsStr:='--gc-sections';
  1541. //if not(cs_link_extern in current_settings.globalswitches) then
  1542. if not(cs_link_nolink in current_settings.globalswitches) then
  1543. Message1(exec_i_linking,current_module.exefilename);
  1544. if (cs_link_map in current_settings.globalswitches) then
  1545. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  1546. { Write used files and libraries }
  1547. WriteResponseFile();
  1548. { Call linker }
  1549. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1550. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1551. if not(cs_link_on_target in current_settings.globalswitches) then
  1552. begin
  1553. Replace(cmdstr,'$EXE',FixedExeFileName);
  1554. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  1555. Replace(cmdstr,'$STATIC',StaticStr);
  1556. Replace(cmdstr,'$STRIP',StripStr);
  1557. Replace(cmdstr,'$MAP',mapstr);
  1558. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1559. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1560. end
  1561. else
  1562. begin
  1563. Replace(cmdstr,'$EXE',FixedExeFileName);
  1564. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1565. Replace(cmdstr,'$STATIC',StaticStr);
  1566. Replace(cmdstr,'$STRIP',StripStr);
  1567. Replace(cmdstr,'$MAP',mapstr);
  1568. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1569. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1570. end;
  1571. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1572. { Remove ReponseFile }
  1573. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1574. DeleteFile(outputexedir+Info.ResName);
  1575. { Post process }
  1576. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1577. success:=PostProcessExecutable(FixedExeFileName,false);
  1578. if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded,system_xtensa_embedded]) then
  1579. begin
  1580. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  1581. FixedExeFileName+' '+
  1582. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
  1583. if success then
  1584. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  1585. FixedExeFileName+' '+
  1586. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  1587. if success and (target_info.system in systems_support_uf2) and (cs_generate_uf2 in current_settings.globalswitches) then
  1588. success := GenerateUF2(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),
  1589. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.uf2'))),
  1590. embedded_controllers[current_settings.controllertype].flashbase);
  1591. {$ifdef ARM}
  1592. if success and (current_settings.controllertype = ct_raspi2) then
  1593. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+ FixedExeFileName + ' kernel7.img',true,false);
  1594. {$endif ARM}
  1595. end;
  1596. MakeExecutable:=success; { otherwise a recursive call to link method }
  1597. end;
  1598. function TLinkerEmbedded.postprocessexecutable(const fn : string;isdll:boolean):boolean;
  1599. begin
  1600. Result:=PostProcessELFExecutable(fn,isdll);
  1601. end;
  1602. function TlinkerEmbedded.GenerateUF2(binFile,uf2File : string;baseAddress : longWord):boolean;
  1603. type
  1604. TFamilies= record
  1605. k : String;
  1606. v : longWord;
  1607. end;
  1608. tuf2Block = record
  1609. magicStart0,
  1610. magicStart1,
  1611. flags,
  1612. targetAddr,
  1613. payloadSize,
  1614. blockNo,
  1615. numBlocks,
  1616. familyid : longWord;
  1617. data : array[0..255] of byte;
  1618. padding : array[0..511-256-32-4] of byte;
  1619. magicEnd : longWord;
  1620. end;
  1621. const
  1622. Families : array of TFamilies = (
  1623. (k:'SAMD21'; v:$68ed2b88),
  1624. (k:'SAML21'; v:$1851780a),
  1625. (k:'SAMD51'; v:$55114460),
  1626. (k:'NRF52'; v:$1b57745f),
  1627. (k:'STM32F0';v:$647824b6),
  1628. (k:'STM32F1';v:$5ee21072),
  1629. (k:'STM32F2';v:$5d1a0a2e),
  1630. (k:'STM32F3';v:$6b846188),
  1631. (k:'STM32F4';v:$57755a57),
  1632. (k:'STM32F7';v:$53b80f00),
  1633. (k:'STM32G0';v:$300f5633),
  1634. (k:'STM32G4';v:$4c71240a),
  1635. (k:'STM32H7';v:$6db66082),
  1636. (k:'STM32L0';v:$202e3a91),
  1637. (k:'STM32L1';v:$1e1f432d),
  1638. (k:'STM32L4';v:$00ff6919),
  1639. (k:'STM32L5';v:$04240bdf),
  1640. (k:'STM32WB';v:$70d16653),
  1641. (k:'STM32WL';v:$21460ff0)
  1642. );
  1643. var
  1644. f,g : file;
  1645. uf2block : Tuf2Block;
  1646. totalRead,numRead : longWord;
  1647. familyId,i : longWord;
  1648. ExtraOptions : String;
  1649. begin
  1650. if pos('-Ttext=',Info.ExtraOptions) > 0 then
  1651. begin
  1652. ExtraOptions := copy(Info.ExtraOptions,pos('-Ttext=',Info.ExtraOptions)+7,length(Info.ExtraOptions));
  1653. for i := 1 to length(ExtraOptions) do
  1654. if pos(copy(ExtraOptions,i,1),'0123456789abcdefxABCDEFX') = 0 then
  1655. ExtraOptions := copy(ExtraOptions,1,i);
  1656. baseAddress := StrToIntDef(ExtraOptions,0);
  1657. end;
  1658. familyId := 0;
  1659. for i := 0 to length(Families)-1 do
  1660. begin
  1661. if pos(Families[i].k,embedded_controllers[current_settings.controllertype].controllerunitstr) = 1 then
  1662. familyId := Families[i].v;
  1663. end;
  1664. if (baseAddress and $07ffffff) <> 0 then
  1665. begin
  1666. totalRead := 0;
  1667. numRead := 0;
  1668. assign(f,binfile);
  1669. reset(f,1);
  1670. assign(g,uf2file);
  1671. rewrite(g,1);
  1672. repeat
  1673. fillchar(uf2block,sizeof(uf2block),0);
  1674. uf2block.magicStart0 := $0A324655; // "UF2\n"
  1675. uf2block.magicStart1 := $9E5D5157; // Randomly selected
  1676. if familyId = 0 then
  1677. uf2block.flags := 0
  1678. else
  1679. uf2block.flags := $2000;
  1680. uf2block.targetAddr := baseAddress + totalread;
  1681. uf2block.payloadSize := 256;
  1682. uf2block.blockNo := (totalRead div sizeOf(uf2block.data));
  1683. uf2block.numBlocks := (filesize(f) + 255) div 256;
  1684. uf2block.familyId := familyId;
  1685. uf2block.magicEnd := $0AB16F30; // Randomly selected
  1686. blockRead(f,uf2block.data,sizeof(uf2block.data),numRead);
  1687. blockwrite(g,uf2block,sizeof(uf2block));
  1688. inc(totalRead,numRead);
  1689. until (numRead=0) or (NumRead<>sizeOf(uf2block.data));
  1690. close(f);
  1691. close(g);
  1692. end;
  1693. Result := true;
  1694. end;
  1695. {*****************************************************************************
  1696. TlinkerEmbedded_SdccSdld
  1697. *****************************************************************************}
  1698. function TlinkerEmbedded_SdccSdld.WriteResponseFile: Boolean;
  1699. Var
  1700. linkres : TLinkRes;
  1701. //i : longint;
  1702. //HPath : TCmdStrListItem;
  1703. s{,s1,s2} : TCmdStr;
  1704. prtobj,
  1705. cprtobj : string[80];
  1706. linklibc : boolean;
  1707. //found1,
  1708. //found2 : boolean;
  1709. begin
  1710. WriteResponseFile:=False;
  1711. linklibc:=(SharedLibFiles.Find('c')<>nil);
  1712. prtobj:='prt0';
  1713. cprtobj:='cprt0';
  1714. if linklibc then
  1715. prtobj:=cprtobj;
  1716. { Open link.res file }
  1717. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  1718. { Write path to search libraries }
  1719. (* HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  1720. while assigned(HPath) do
  1721. begin
  1722. s:=HPath.Str;
  1723. if (cs_link_on_target in current_settings.globalswitches) then
  1724. s:=ScriptFixFileName(s);
  1725. LinkRes.Add('-L'+s);
  1726. HPath:=TCmdStrListItem(HPath.Next);
  1727. end;
  1728. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  1729. while assigned(HPath) do
  1730. begin
  1731. s:=HPath.Str;
  1732. if s<>'' then
  1733. LinkRes.Add('SEARCH_DIR("'+s+'")');
  1734. HPath:=TCmdStrListItem(HPath.Next);
  1735. end;
  1736. LinkRes.Add('INPUT (');
  1737. { add objectfiles, start with prt0 always }*)
  1738. //s:=FindObjectFile('prt0','',false);
  1739. if prtobj<>'' then
  1740. begin
  1741. s:=FindObjectFile(prtobj,'',false);
  1742. LinkRes.AddFileName(s);
  1743. end;
  1744. { try to add crti and crtbegin if linking to C }
  1745. if linklibc then
  1746. begin
  1747. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  1748. LinkRes.AddFileName(s);
  1749. if librarysearchpath.FindFile('crti.o',false,s) then
  1750. LinkRes.AddFileName(s);
  1751. end;
  1752. while not ObjectFiles.Empty do
  1753. begin
  1754. s:=ObjectFiles.GetFirst;
  1755. if s<>'' then
  1756. begin
  1757. { vlink doesn't use SEARCH_DIR for object files }
  1758. if not(cs_link_on_target in current_settings.globalswitches) then
  1759. s:=FindObjectFile(s,'',false);
  1760. LinkRes.AddFileName((maybequoted(s)));
  1761. end;
  1762. end;
  1763. { Write staticlibraries }
  1764. if not StaticLibFiles.Empty then
  1765. begin
  1766. { vlink doesn't need, and doesn't support GROUP }
  1767. { if (cs_link_on_target in current_settings.globalswitches) then
  1768. begin
  1769. LinkRes.Add(')');
  1770. LinkRes.Add('GROUP(');
  1771. end;}
  1772. while not StaticLibFiles.Empty do
  1773. begin
  1774. S:=StaticLibFiles.GetFirst;
  1775. LinkRes.Add('-l'+maybequoted(s));
  1776. end;
  1777. end;
  1778. (* if (cs_link_on_target in current_settings.globalswitches) then
  1779. begin
  1780. LinkRes.Add(')');
  1781. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  1782. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  1783. linklibc:=false;
  1784. while not SharedLibFiles.Empty do
  1785. begin
  1786. S:=SharedLibFiles.GetFirst;
  1787. if s<>'c' then
  1788. begin
  1789. i:=Pos(target_info.sharedlibext,S);
  1790. if i>0 then
  1791. Delete(S,i,255);
  1792. LinkRes.Add('-l'+s);
  1793. end
  1794. else
  1795. begin
  1796. LinkRes.Add('-l'+s);
  1797. linklibc:=true;
  1798. end;
  1799. end;
  1800. { be sure that libc&libgcc is the last lib }
  1801. if linklibc then
  1802. begin
  1803. LinkRes.Add('-lc');
  1804. LinkRes.Add('-lgcc');
  1805. end;
  1806. end
  1807. else
  1808. begin
  1809. while not SharedLibFiles.Empty do
  1810. begin
  1811. S:=SharedLibFiles.GetFirst;
  1812. LinkRes.Add('lib'+s+target_info.staticlibext);
  1813. end;
  1814. LinkRes.Add(')');
  1815. end;*)
  1816. { objects which must be at the end }
  1817. (*if linklibc then
  1818. begin
  1819. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  1820. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  1821. if found1 or found2 then
  1822. begin
  1823. LinkRes.Add('INPUT(');
  1824. if found1 then
  1825. LinkRes.AddFileName(s1);
  1826. if found2 then
  1827. LinkRes.AddFileName(s2);
  1828. LinkRes.Add(')');
  1829. end;
  1830. end;*)
  1831. { Write and Close response }
  1832. linkres.writetodisk;
  1833. linkres.free;
  1834. WriteResponseFile:=True;
  1835. end;
  1836. procedure TlinkerEmbedded_SdccSdld.SetDefaultInfo;
  1837. const
  1838. {$if defined(Z80)}
  1839. ExeName='sdldz80';
  1840. {$else}
  1841. ExeName='sdld';
  1842. {$endif}
  1843. begin
  1844. with Info do
  1845. begin
  1846. ExeCmd[1]:=ExeName+' -n $OPT -i $MAP $EXE -f $RES'
  1847. //-g '+platform_select+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE -T $RES';
  1848. end;
  1849. end;
  1850. function TlinkerEmbedded_SdccSdld.MakeExecutable: boolean;
  1851. var
  1852. binstr,
  1853. cmdstr,
  1854. mapstr: TCmdStr;
  1855. success : boolean;
  1856. StaticStr,
  1857. // GCSectionsStr,
  1858. DynLinkStr,
  1859. StripStr,
  1860. FixedExeFileName: string;
  1861. begin
  1862. { for future use }
  1863. StaticStr:='';
  1864. StripStr:='';
  1865. mapstr:='';
  1866. DynLinkStr:='';
  1867. FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.ihx')));
  1868. (* GCSectionsStr:='--gc-sections';
  1869. //if not(cs_link_extern in current_settings.globalswitches) then
  1870. if not(cs_link_nolink in current_settings.globalswitches) then
  1871. Message1(exec_i_linking,current_module.exefilename);*)
  1872. if (cs_link_map in current_settings.globalswitches) then
  1873. mapstr:='-mw';
  1874. { Write used files and libraries }
  1875. WriteResponseFile();
  1876. { Call linker }
  1877. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1878. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1879. if not(cs_link_on_target in current_settings.globalswitches) then
  1880. begin
  1881. Replace(cmdstr,'$EXE',FixedExeFileName);
  1882. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  1883. Replace(cmdstr,'$STATIC',StaticStr);
  1884. Replace(cmdstr,'$STRIP',StripStr);
  1885. Replace(cmdstr,'$MAP',mapstr);
  1886. // Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1887. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1888. end
  1889. else
  1890. begin
  1891. Replace(cmdstr,'$EXE',FixedExeFileName);
  1892. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1893. Replace(cmdstr,'$STATIC',StaticStr);
  1894. Replace(cmdstr,'$STRIP',StripStr);
  1895. Replace(cmdstr,'$MAP',mapstr);
  1896. // Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1897. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1898. end;
  1899. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1900. { Remove ReponseFile }
  1901. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1902. DeleteFile(outputexedir+Info.ResName);
  1903. (* { Post process }
  1904. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1905. success:=PostProcessExecutable(FixedExeFileName,false);
  1906. if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded,system_xtensa_embedded]) then
  1907. begin
  1908. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  1909. FixedExeFileName+' '+
  1910. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
  1911. if success then
  1912. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  1913. FixedExeFileName+' '+
  1914. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  1915. end;*)
  1916. MakeExecutable:=success; { otherwise a recursive call to link method }
  1917. end;
  1918. {*****************************************************************************
  1919. TlinkerEmbedded_Wasm
  1920. *****************************************************************************}
  1921. constructor TLinkerEmbedded_Wasm.Create;
  1922. begin
  1923. inherited Create;
  1924. end;
  1925. procedure TLinkerEmbedded_Wasm.SetDefaultInfo;
  1926. begin
  1927. Info.DllCmd[1] := 'wasm-ld $SONAME $GCSECTIONS -o $EXE';
  1928. //Info.DllCmd[2] := 'wasmtool --exportrename $INPUT $EXE';
  1929. end;
  1930. function TLinkerEmbedded_Wasm.MakeSharedLibrary: boolean;
  1931. var
  1932. GCSectionsStr : ansistring;
  1933. binstr, cmdstr : Tcmdstr;
  1934. InitStr,
  1935. FiniStr,
  1936. SoNameStr : string[80];
  1937. mapstr,ltostr : TCmdStr;
  1938. success : Boolean;
  1939. tmp : TCmdStrListItem;
  1940. tempFileName : ansistring;
  1941. begin
  1942. //Result := true;
  1943. //Result:=inherited MakeSharedLibrary;
  1944. if (cs_link_smart in current_settings.globalswitches) and
  1945. create_smartlink_sections then
  1946. GCSectionsStr:='--gc-sections'
  1947. else
  1948. GCSectionsStr:='';
  1949. SoNameStr:='';
  1950. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  1951. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  1952. tmp := TCmdStrListItem(ObjectFiles.First);
  1953. while Assigned(tmp) do begin
  1954. cmdstr := tmp.Str+ ' ' + cmdstr;
  1955. tmp := TCmdStrListItem(tmp.Next);
  1956. end;
  1957. if HasExports then
  1958. cmdstr := cmdstr + ' --export-dynamic'; //' --export-dynamic';
  1959. cmdstr := cmdstr + ' --no-entry --allow-undefined';
  1960. if (cs_link_strip in current_settings.globalswitches) then
  1961. begin
  1962. { only remove non global symbols and debugging info for a library }
  1963. cmdstr := cmdstr + ' --strip-all';
  1964. end;
  1965. //Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1966. //Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1967. //Replace(cmdstr,'$INIT',InitStr);
  1968. //Replace(cmdstr,'$FINI',FiniStr);
  1969. Replace(cmdstr,'$SONAME',SoNameStr);
  1970. //Replace(cmdstr,'$MAP',mapstr);
  1971. //Replace(cmdstr,'$LTO',ltostr);
  1972. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1973. writeln(utilsprefix+binstr,' ',cmdstr);
  1974. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  1975. //SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  1976. //Replace(cmdstr,'$INPUT',current_module.objfilename );
  1977. //Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  1978. //DoExec(FindUtil(utilsprefix+binstr),cmdstr,false,false);
  1979. MakeSharedLibrary:=success;
  1980. end;
  1981. {*****************************************************************************
  1982. Initialize
  1983. *****************************************************************************}
  1984. initialization
  1985. {$ifdef arm}
  1986. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1987. RegisterTarget(system_arm_embedded_info);
  1988. {$endif arm}
  1989. {$ifdef avr}
  1990. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1991. RegisterTarget(system_avr_embedded_info);
  1992. {$endif avr}
  1993. {$ifdef i386}
  1994. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1995. RegisterTarget(system_i386_embedded_info);
  1996. {$endif i386}
  1997. {$ifdef x86_64}
  1998. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1999. RegisterTarget(system_x86_64_embedded_info);
  2000. {$endif x86_64}
  2001. {$ifdef i8086}
  2002. { no need to register linker ld_embedded, because i8086_embedded uses the
  2003. regular msdos linker. In case a flat binary, relocated for a specific
  2004. segment address is needed (e.g. for a BIOS or a real mode bootloader), it
  2005. can be produced post-compilation with exe2bin or a similar tool. }
  2006. RegisterTarget(system_i8086_embedded_info);
  2007. {$endif i8086}
  2008. {$ifdef mipsel}
  2009. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2010. RegisterTarget(system_mipsel_embedded_info);
  2011. {$endif mipsel}
  2012. {$ifdef m68k}
  2013. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2014. RegisterTarget(system_m68k_embedded_info);
  2015. {$endif m68k}
  2016. {$ifdef riscv32}
  2017. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2018. RegisterTarget(system_riscv32_embedded_info);
  2019. {$endif riscv32}
  2020. {$ifdef riscv64}
  2021. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2022. RegisterTarget(system_riscv64_embedded_info);
  2023. {$endif riscv64}
  2024. {$ifdef xtensa}
  2025. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2026. RegisterTarget(system_xtensa_embedded_info);
  2027. {$endif xtensa}
  2028. {$ifdef z80}
  2029. RegisterLinker(ld_embedded,TlinkerEmbedded_SdccSdld);
  2030. RegisterTarget(system_z80_embedded_info);
  2031. {$endif z80}
  2032. {$ifdef wasm32}
  2033. RegisterTarget(system_wasm32_embedded_info);
  2034. RegisterImport(system_wasm32_embedded, timportlibwasi);
  2035. RegisterExport(system_wasm32_embedded, texportlibwasi);
  2036. RegisterLinker(ld_embedded, TLinkerEmbedded_Wasm);
  2037. {$endif wasm32}
  2038. end.