t_embed.pas 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189
  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_arduino_due,
  582. ct_flip_n_click,
  583. { Nordic Semiconductor }
  584. ct_nrf51422_xxaa,
  585. ct_nrf51422_xxab,
  586. ct_nrf51422_xxac,
  587. ct_nrf51822_xxaa,
  588. ct_nrf51822_xxab,
  589. ct_nrf51822_xxac,
  590. ct_nrf52832_xxaa,
  591. ct_nrf52840_xxaa,
  592. ct_sc32442b,
  593. { Raspberry Pi 2 }
  594. ct_raspi2,
  595. ct_thumb2bare:
  596. begin
  597. with embedded_controllers[current_settings.controllertype] do
  598. with linkres do
  599. begin
  600. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  601. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  602. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  603. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  604. Add('ENTRY(_LOWLEVELSTART)')
  605. else
  606. Add('ENTRY(_START)');
  607. Add('MEMORY');
  608. Add('{');
  609. if flashsize<>0 then
  610. begin
  611. LinkStr := ' flash : ORIGIN = 0x' + IntToHex(flashbase,8)
  612. + ', LENGTH = 0x' + IntToHex(flashsize,8);
  613. Add(LinkStr);
  614. end;
  615. LinkStr := ' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  616. + ', LENGTH = 0x' + IntToHex(sramsize,8);
  617. Add(LinkStr);
  618. Add('}');
  619. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  620. // Add Checksum Calculation for LPC Controllers so that the bootloader starts the uploaded binary
  621. writeln(controllerunitstr);
  622. if (controllerunitstr = 'LPC8xx') or (controllerunitstr = 'LPC11XX') or (controllerunitstr = 'LPC122X') then
  623. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + Hardfault_interrupt + 1);');
  624. if (controllerunitstr = 'LPC13XX') then
  625. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + MemoryManagement_interrupt + 1 + BusFault_interrupt + 1 + UsageFault_interrupt + 1);');
  626. end;
  627. end
  628. else
  629. if not (cs_link_nolink in current_settings.globalswitches) then
  630. internalerror(200902011);
  631. end;
  632. with linkres do
  633. begin
  634. Add('SECTIONS');
  635. Add('{');
  636. Add(' .text :');
  637. Add(' {');
  638. Add(' _text_start = .;');
  639. Add(' KEEP(*(.init .init.*))');
  640. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  641. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  642. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  643. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  644. begin
  645. Add(' . = 0x400;');
  646. Add(' KEEP(*(.flash_config *.flash_config.*))');
  647. end;
  648. Add(' *(.text .text.*)');
  649. Add(' *(.strings)');
  650. Add(' *(.rodata .rodata.*)');
  651. Add(' *(.comment)');
  652. Add(' . = ALIGN(4);');
  653. Add(' _etext = .;');
  654. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  655. begin
  656. Add(' } >flash');
  657. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  658. end
  659. else
  660. begin
  661. Add(' } >ram');
  662. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  663. end;
  664. Add(' .data :');
  665. Add(' {');
  666. Add(' _data = .;');
  667. Add(' *(.data .data.*)');
  668. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  669. Add(' _edata = .;');
  670. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  671. begin
  672. Add(' } >ram AT >flash');
  673. end
  674. else
  675. begin
  676. Add(' } >ram');
  677. end;
  678. Add(' .bss :');
  679. Add(' {');
  680. Add(' _bss_start = .;');
  681. Add(' *(.bss .bss.*)');
  682. Add(' *(COMMON)');
  683. Add(' } >ram');
  684. Add('. = ALIGN(4);');
  685. Add('_bss_end = . ;');
  686. Add('}');
  687. Add('_end = .;');
  688. end;
  689. {$endif ARM}
  690. {$ifdef i386}
  691. with linkres do
  692. begin
  693. Add('ENTRY(_START)');
  694. Add('SECTIONS');
  695. Add('{');
  696. Add(' . = 0x100000;');
  697. Add(' .text ALIGN (0x1000) :');
  698. Add(' {');
  699. Add(' _text = .;');
  700. Add(' KEEP(*(.init .init.*))');
  701. Add(' *(.text .text.*)');
  702. Add(' *(.strings)');
  703. Add(' *(.rodata .rodata.*)');
  704. Add(' *(.comment)');
  705. Add(' _etext = .;');
  706. Add(' }');
  707. Add(' .data ALIGN (0x1000) :');
  708. Add(' {');
  709. Add(' _data = .;');
  710. Add(' *(.data .data.*)');
  711. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  712. Add(' _edata = .;');
  713. Add(' }');
  714. Add(' . = ALIGN(4);');
  715. Add(' .bss :');
  716. Add(' {');
  717. Add(' _bss_start = .;');
  718. Add(' *(.bss .bss.*)');
  719. Add(' *(COMMON)');
  720. Add(' }');
  721. Add('_bss_end = . ;');
  722. Add('}');
  723. Add('_end = .;');
  724. end;
  725. {$endif i386}
  726. {$ifdef x86_64}
  727. with linkres do
  728. begin
  729. Add('ENTRY(_START)');
  730. Add('SECTIONS');
  731. Add('{');
  732. Add(' . = 0x100000;');
  733. Add(' .text ALIGN (0x1000) :');
  734. Add(' {');
  735. Add(' _text = .;');
  736. Add(' KEEP(*(.init .init.*))');
  737. Add(' *(.text .text.*)');
  738. Add(' *(.strings)');
  739. Add(' *(.rodata .rodata.*)');
  740. Add(' *(.comment)');
  741. Add(' _etext = .;');
  742. Add(' }');
  743. Add(' .data ALIGN (0x1000) :');
  744. Add(' {');
  745. Add(' _data = .;');
  746. Add(' *(.data .data.*)');
  747. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  748. Add(' _edata = .;');
  749. Add(' }');
  750. Add(' . = ALIGN(4);');
  751. Add(' .bss :');
  752. Add(' {');
  753. Add(' _bss_start = .;');
  754. Add(' *(.bss .bss.*)');
  755. Add(' *(COMMON)');
  756. Add(' }');
  757. Add('_bss_end = . ;');
  758. Add('}');
  759. Add('_end = .;');
  760. end;
  761. {$endif x86_64}
  762. {$ifdef AVR}
  763. with linkres do
  764. begin
  765. { linker script from ld 2.19 }
  766. Add('ENTRY(_START)');
  767. Add('OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")');
  768. case current_settings.cputype of
  769. cpu_avr1:
  770. Add('OUTPUT_ARCH(avr:1)');
  771. cpu_avr2:
  772. Add('OUTPUT_ARCH(avr:2)');
  773. cpu_avr25:
  774. Add('OUTPUT_ARCH(avr:25)');
  775. cpu_avr3:
  776. Add('OUTPUT_ARCH(avr:3)');
  777. cpu_avr31:
  778. Add('OUTPUT_ARCH(avr:31)');
  779. cpu_avr35:
  780. Add('OUTPUT_ARCH(avr:35)');
  781. cpu_avr4:
  782. Add('OUTPUT_ARCH(avr:4)');
  783. cpu_avr5:
  784. Add('OUTPUT_ARCH(avr:5)');
  785. cpu_avr51:
  786. Add('OUTPUT_ARCH(avr:51)');
  787. cpu_avr6:
  788. Add('OUTPUT_ARCH(avr:6)');
  789. cpu_avrxmega3:
  790. Add('OUTPUT_ARCH(avr:103)');
  791. cpu_avrtiny:
  792. Add('OUTPUT_ARCH(avr:100)');
  793. else
  794. Internalerror(2015072701);
  795. end;
  796. Add('MEMORY');
  797. with embedded_controllers[current_settings.controllertype] do
  798. begin
  799. Add('{');
  800. Add(' text (rx) : ORIGIN = 0, LENGTH = 0x'+IntToHex(flashsize,6));
  801. Add(' data (rw!x) : ORIGIN = 0x'+IntToHex($800000+srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  802. Add(' eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 0x'+IntToHex(eepromsize,6));
  803. Add(' fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K');
  804. Add(' lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K');
  805. Add(' signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K');
  806. Add('}');
  807. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  808. end;
  809. Add('SECTIONS');
  810. Add('{');
  811. Add(' /* Read-only sections, merged into text segment: */');
  812. Add(' .hash : { *(.hash) }');
  813. Add(' .dynsym : { *(.dynsym) }');
  814. Add(' .dynstr : { *(.dynstr) }');
  815. Add(' .gnu.version : { *(.gnu.version) }');
  816. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  817. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  818. Add(' .rel.init : { *(.rel.init) }');
  819. Add(' .rela.init : { *(.rela.init) }');
  820. Add(' .rel.text :');
  821. Add(' {');
  822. Add(' *(.rel.text)');
  823. Add(' *(.rel.text.*)');
  824. Add(' *(.rel.gnu.linkonce.t*)');
  825. Add(' }');
  826. Add(' .rela.text :');
  827. Add(' {');
  828. Add(' *(.rela.text)');
  829. Add(' *(.rela.text.*)');
  830. Add(' *(.rela.gnu.linkonce.t*)');
  831. Add(' }');
  832. Add(' .rel.fini : { *(.rel.fini) }');
  833. Add(' .rela.fini : { *(.rela.fini) }');
  834. Add(' .rel.rodata :');
  835. Add(' {');
  836. Add(' *(.rel.rodata)');
  837. Add(' *(.rel.rodata.*)');
  838. Add(' *(.rel.gnu.linkonce.r*)');
  839. Add(' }');
  840. Add(' .rela.rodata :');
  841. Add(' {');
  842. Add(' *(.rela.rodata)');
  843. Add(' *(.rela.rodata.*)');
  844. Add(' *(.rela.gnu.linkonce.r*)');
  845. Add(' }');
  846. Add(' .rel.data :');
  847. Add(' {');
  848. Add(' *(.rel.data)');
  849. Add(' *(.rel.data.*)');
  850. Add(' *(.rel.gnu.linkonce.d*)');
  851. Add(' }');
  852. Add(' .rela.data :');
  853. Add(' {');
  854. Add(' *(.rela.data)');
  855. Add(' *(.rela.data.*)');
  856. Add(' *(.rela.gnu.linkonce.d*)');
  857. Add(' }');
  858. Add(' .rel.ctors : { *(.rel.ctors) }');
  859. Add(' .rela.ctors : { *(.rela.ctors) }');
  860. Add(' .rel.dtors : { *(.rel.dtors) }');
  861. Add(' .rela.dtors : { *(.rela.dtors) }');
  862. Add(' .rel.got : { *(.rel.got) }');
  863. Add(' .rela.got : { *(.rela.got) }');
  864. Add(' .rel.bss : { *(.rel.bss) }');
  865. Add(' .rela.bss : { *(.rela.bss) }');
  866. Add(' .rel.plt : { *(.rel.plt) }');
  867. Add(' .rela.plt : { *(.rela.plt) }');
  868. Add(' /* Internal text space or external memory. */');
  869. Add(' .text :');
  870. Add(' {');
  871. Add(' KEEP(*(.init .init.*))');
  872. Add(' /* For data that needs to reside in the lower 64k of progmem. */');
  873. Add(' *(.progmem.gcc*)');
  874. Add(' *(.progmem*)');
  875. Add(' . = ALIGN(2);');
  876. Add(' __trampolines_start = . ;');
  877. Add(' /* The jump trampolines for the 16-bit limited relocs will reside here. */');
  878. Add(' *(.trampolines)');
  879. Add(' *(.trampolines*)');
  880. Add(' __trampolines_end = . ;');
  881. Add(' /* For future tablejump instruction arrays for 3 byte pc devices.');
  882. Add(' We don''t relax jump/call instructions within these sections. */');
  883. Add(' *(.jumptables)');
  884. Add(' *(.jumptables*)');
  885. Add(' /* For code that needs to reside in the lower 128k progmem. */');
  886. Add(' *(.lowtext)');
  887. Add(' *(.lowtext*)');
  888. Add(' __ctors_start = . ;');
  889. Add(' *(.ctors)');
  890. Add(' __ctors_end = . ;');
  891. Add(' __dtors_start = . ;');
  892. Add(' *(.dtors)');
  893. Add(' __dtors_end = . ;');
  894. Add(' KEEP(SORT(*)(.ctors))');
  895. Add(' KEEP(SORT(*)(.dtors))');
  896. Add(' /* From this point on, we don''t bother about wether the insns are');
  897. Add(' below or above the 16 bits boundary. */');
  898. Add(' *(.init0) /* Start here after reset. */');
  899. Add(' KEEP (*(.init0))');
  900. Add(' *(.init1)');
  901. Add(' KEEP (*(.init1))');
  902. Add(' *(.init2) /* Clear __zero_reg__, set up stack pointer. */');
  903. Add(' KEEP (*(.init2))');
  904. Add(' *(.init3)');
  905. Add(' KEEP (*(.init3))');
  906. Add(' *(.init4) /* Initialize data and BSS. */');
  907. Add(' KEEP (*(.init4))');
  908. Add(' *(.init5)');
  909. Add(' KEEP (*(.init5))');
  910. Add(' *(.init6) /* C++ constructors. */');
  911. Add(' KEEP (*(.init6))');
  912. Add(' *(.init7)');
  913. Add(' KEEP (*(.init7))');
  914. Add(' *(.init8)');
  915. Add(' KEEP (*(.init8))');
  916. Add(' *(.init9) /* Call main(). */');
  917. Add(' KEEP (*(.init9))');
  918. Add(' *(.text)');
  919. Add(' . = ALIGN(2);');
  920. Add(' *(.text.*)');
  921. Add(' . = ALIGN(2);');
  922. Add(' *(.fini9) /* _exit() starts here. */');
  923. Add(' KEEP (*(.fini9))');
  924. Add(' *(.fini8)');
  925. Add(' KEEP (*(.fini8))');
  926. Add(' *(.fini7)');
  927. Add(' KEEP (*(.fini7))');
  928. Add(' *(.fini6) /* C++ destructors. */');
  929. Add(' KEEP (*(.fini6))');
  930. Add(' *(.fini5)');
  931. Add(' KEEP (*(.fini5))');
  932. Add(' *(.fini4)');
  933. Add(' KEEP (*(.fini4))');
  934. Add(' *(.fini3)');
  935. Add(' KEEP (*(.fini3))');
  936. Add(' *(.fini2)');
  937. Add(' KEEP (*(.fini2))');
  938. Add(' *(.fini1)');
  939. Add(' KEEP (*(.fini1))');
  940. Add(' *(.fini0) /* Infinite loop after program termination. */');
  941. Add(' KEEP (*(.fini0))');
  942. Add(' _etext = . ;');
  943. Add(' } > text');
  944. Add(' .data : AT (ADDR (.text) + SIZEOF (.text))');
  945. Add(' {');
  946. Add(' PROVIDE (__data_start = .) ;');
  947. Add(' *(.data)');
  948. Add(' *(.data*)');
  949. Add(' *(.rodata) /* We need to include .rodata here if gcc is used */');
  950. Add(' *(.rodata*) /* with -fdata-sections. */');
  951. Add(' *(.gnu.linkonce.d*)');
  952. Add(' . = ALIGN(2);');
  953. Add(' _edata = . ;');
  954. Add(' PROVIDE (__data_end = .) ;');
  955. Add(' } > data');
  956. Add(' .bss : AT (ADDR (.bss))');
  957. Add(' {');
  958. Add(' PROVIDE (__bss_start = .) ;');
  959. Add(' *(.bss)');
  960. Add(' *(.bss*)');
  961. Add(' *(COMMON)');
  962. Add(' PROVIDE (__bss_end = .) ;');
  963. Add(' } > data');
  964. Add(' __data_load_start = LOADADDR(.data);');
  965. Add(' __data_load_end = __data_load_start + SIZEOF(.data);');
  966. Add(' /* Global data not cleared after reset. */');
  967. Add(' .noinit :');
  968. Add(' {');
  969. Add(' PROVIDE (__noinit_start = .) ;');
  970. Add(' *(.noinit*)');
  971. Add(' PROVIDE (__noinit_end = .) ;');
  972. Add(' _end = . ;');
  973. Add(' PROVIDE (__heap_start = .) ;');
  974. Add(' } > data');
  975. Add(' .eeprom :');
  976. Add(' {');
  977. Add(' *(.eeprom*)');
  978. Add(' __eeprom_end = . ;');
  979. Add(' } > eeprom');
  980. Add(' .fuse :');
  981. Add(' {');
  982. Add(' KEEP(*(.fuse))');
  983. Add(' KEEP(*(.lfuse))');
  984. Add(' KEEP(*(.hfuse))');
  985. Add(' KEEP(*(.efuse))');
  986. Add(' } > fuse');
  987. Add(' .lock :');
  988. Add(' {');
  989. Add(' KEEP(*(.lock*))');
  990. Add(' } > lock');
  991. Add(' .signature :');
  992. Add(' {');
  993. Add(' KEEP(*(.signature*))');
  994. Add(' } > signature');
  995. Add(' /* Stabs debugging sections. */');
  996. Add(' .stab 0 : { *(.stab) }');
  997. Add(' .stabstr 0 : { *(.stabstr) }');
  998. Add(' .stab.excl 0 : { *(.stab.excl) }');
  999. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1000. Add(' .stab.index 0 : { *(.stab.index) }');
  1001. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1002. Add(' .comment 0 : { *(.comment) }');
  1003. Add(' /* DWARF debug sections.');
  1004. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1005. Add(' of the section so we begin them at 0. */');
  1006. Add(' /* DWARF 1 */');
  1007. Add(' .debug 0 : { *(.debug) }');
  1008. Add(' .line 0 : { *(.line) }');
  1009. Add(' /* GNU DWARF 1 extensions */');
  1010. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1011. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1012. Add(' /* DWARF 1.1 and DWARF 2 */');
  1013. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1014. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1015. Add(' /* DWARF 2 */');
  1016. Add(' .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }');
  1017. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1018. Add(' .debug_line 0 : { *(.debug_line) }');
  1019. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1020. Add(' .debug_str 0 : { *(.debug_str) }');
  1021. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1022. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1023. Add(' /* DWARF 3 */');
  1024. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1025. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1026. Add(' /* DWARF Extension. */');
  1027. Add(' .debug_macro 0 : { *(.debug_macro) }');
  1028. Add('}');
  1029. end;
  1030. {$endif AVR}
  1031. {$ifdef MIPSEL}
  1032. case current_settings.controllertype of
  1033. ct_none:
  1034. begin
  1035. end;
  1036. ct_pic32mx110f016b,
  1037. ct_pic32mx110f016c,
  1038. ct_pic32mx110f016d,
  1039. ct_pic32mx120f032b,
  1040. ct_pic32mx120f032c,
  1041. ct_pic32mx120f032d,
  1042. ct_pic32mx130f064b,
  1043. ct_pic32mx130f064c,
  1044. ct_pic32mx130f064d,
  1045. ct_pic32mx150f128b,
  1046. ct_pic32mx150f128c,
  1047. ct_pic32mx150f128d,
  1048. ct_pic32mx210f016b,
  1049. ct_pic32mx210f016c,
  1050. ct_pic32mx210f016d,
  1051. ct_pic32mx220f032b,
  1052. ct_pic32mx220f032c,
  1053. ct_pic32mx220f032d,
  1054. ct_pic32mx230f064b,
  1055. ct_pic32mx230f064c,
  1056. ct_pic32mx230f064d,
  1057. ct_pic32mx250f128b,
  1058. ct_pic32mx250f128c,
  1059. ct_pic32mx250f128d,
  1060. ct_pic32mx775f256h,
  1061. ct_pic32mx775f256l,
  1062. ct_pic32mx775f512h,
  1063. ct_pic32mx775f512l,
  1064. ct_pic32mx795f512h,
  1065. ct_pic32mx795f512l:
  1066. begin
  1067. with embedded_controllers[current_settings.controllertype] do
  1068. with linkres do
  1069. begin
  1070. Add('OUTPUT_FORMAT("elf32-tradlittlemips")');
  1071. Add('OUTPUT_ARCH(pic32mx)');
  1072. Add('ENTRY(_reset)');
  1073. Add('PROVIDE(_vector_spacing = 0x00000001);');
  1074. Add('_ebase_address = 0x'+IntToHex(flashbase,8)+';');
  1075. Add('_RESET_ADDR = 0xBFC00000;');
  1076. Add('_BEV_EXCPT_ADDR = 0xBFC00380;');
  1077. Add('_DBG_EXCPT_ADDR = 0xBFC00480;');
  1078. Add('_GEN_EXCPT_ADDR = _ebase_address + 0x180;');
  1079. Add('MEMORY');
  1080. Add('{');
  1081. if flashsize<>0 then
  1082. begin
  1083. Add(' kseg0_program_mem : ORIGIN = 0x'+IntToHex(flashbase,8)+', LENGTH = 0x'+IntToHex(flashsize,8));
  1084. //TODO This should better be placed into the controllertype records
  1085. Add(' kseg1_boot_mem : ORIGIN = 0xBFC00000, LENGTH = 0xbef');
  1086. Add(' config3 : ORIGIN = 0xBFC00BF0, LENGTH = 0x4');
  1087. Add(' config2 : ORIGIN = 0xBFC00BF4, LENGTH = 0x4');
  1088. Add(' config1 : ORIGIN = 0xBFC00BF8, LENGTH = 0x4');
  1089. Add(' config0 : ORIGIN = 0xBFC00BFC, LENGTH = 0x4');
  1090. end;
  1091. Add(' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  1092. + ', LENGTH = 0x' + IntToHex(sramsize,8));
  1093. Add('}');
  1094. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  1095. end;
  1096. end
  1097. end;
  1098. with linkres do
  1099. begin
  1100. Add('SECTIONS');
  1101. Add('{');
  1102. Add(' .reset _RESET_ADDR :');
  1103. Add(' {');
  1104. Add(' KEEP(*(.reset .reset.*))');
  1105. Add(' KEEP(*(.startup .startup.*))');
  1106. Add(' } > kseg1_boot_mem');
  1107. Add(' .bev_excpt _BEV_EXCPT_ADDR :');
  1108. Add(' {');
  1109. Add(' KEEP(*(.bev_handler))');
  1110. Add(' } > kseg1_boot_mem');
  1111. Add(' .text :');
  1112. Add(' {');
  1113. Add(' _text_start = .;');
  1114. Add(' . = _text_start + 0x180;');
  1115. Add(' KEEP(*(.gen_handler))');
  1116. Add(' . = _text_start + 0x200;');
  1117. Add(' KEEP(*(.init .init.*))');
  1118. Add(' *(.text .text.*)');
  1119. Add(' *(.strings)');
  1120. Add(' *(.rodata .rodata.*)');
  1121. Add(' *(.comment)');
  1122. Add(' _etext = .;');
  1123. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1124. begin
  1125. Add(' } >kseg0_program_mem');
  1126. end
  1127. else
  1128. begin
  1129. Add(' } >ram');
  1130. end;
  1131. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1132. Add(' .data :');
  1133. Add(' {');
  1134. Add(' _data = .;');
  1135. Add(' *(.data .data.*)');
  1136. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1137. Add(' . = .;');
  1138. Add(' _gp = ALIGN(16) + 0x7ff0;');
  1139. Add(' _edata = .;');
  1140. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1141. begin
  1142. Add(' } >ram AT >kseg0_program_mem');
  1143. end
  1144. else
  1145. begin
  1146. Add(' } >ram');
  1147. end;
  1148. Add(' .config_BFC00BF0 : {');
  1149. Add(' KEEP(*(.config_BFC00BF0))');
  1150. Add(' } > config3');
  1151. Add(' .config_BFC00BF4 : {');
  1152. Add(' KEEP(*(.config_BFC00BF4))');
  1153. Add(' } > config2');
  1154. Add(' .config_BFC00BF8 : {');
  1155. Add(' KEEP(*(.config_BFC00BF8))');
  1156. Add(' } > config1');
  1157. Add(' .config_BFC00BFC : {');
  1158. Add(' KEEP(*(.config_BFC00BFC))');
  1159. Add(' } > config0');
  1160. Add(' .bss :');
  1161. Add(' {');
  1162. Add(' _bss_start = .;');
  1163. Add(' *(.bss .bss.*)');
  1164. Add(' *(COMMON)');
  1165. Add(' } >ram');
  1166. Add('. = ALIGN(4);');
  1167. Add('_bss_end = . ;');
  1168. Add(' .comment 0 : { *(.comment) }');
  1169. Add(' /* DWARF debug sections.');
  1170. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1171. Add(' of the section so we begin them at 0. */');
  1172. Add(' /* DWARF 1 */');
  1173. Add(' .debug 0 : { *(.debug) }');
  1174. Add(' .line 0 : { *(.line) }');
  1175. Add(' /* GNU DWARF 1 extensions */');
  1176. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1177. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1178. Add(' /* DWARF 1.1 and DWARF 2 */');
  1179. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1180. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1181. Add(' /* DWARF 2 */');
  1182. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1183. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1184. Add(' /DISCARD/ : { *(.debug_line) }');
  1185. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1186. Add(' .debug_str 0 : { *(.debug_str) }');
  1187. Add(' /DISCARD/ : { *(.debug_loc) }');
  1188. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1189. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1190. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1191. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1192. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1193. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1194. Add(' /* DWARF 3 */');
  1195. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1196. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1197. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1198. Add(' .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }');
  1199. Add(' .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }');
  1200. Add(' .mdebug.abi32 : { KEEP(*(.mdebug.abi32)) }');
  1201. Add(' .mdebug.abiN32 : { KEEP(*(.mdebug.abiN32)) }');
  1202. Add(' .mdebug.abi64 : { KEEP(*(.mdebug.abi64)) }');
  1203. Add(' .mdebug.abiO64 : { KEEP(*(.mdebug.abiO64)) }');
  1204. Add(' .mdebug.eabi32 : { KEEP(*(.mdebug.eabi32)) }');
  1205. Add(' .mdebug.eabi64 : { KEEP(*(.mdebug.eabi64)) }');
  1206. Add(' /DISCARD/ : { *(.rel.dyn) }');
  1207. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1208. Add('}');
  1209. Add('_end = .;');
  1210. end;
  1211. {$endif MIPSEL}
  1212. {$ifdef RISCV32}
  1213. with linkres do
  1214. begin
  1215. Add('OUTPUT_ARCH("riscv")');
  1216. Add('ENTRY(_START)');
  1217. Add('MEMORY');
  1218. with embedded_controllers[current_settings.controllertype] do
  1219. begin
  1220. Add('{');
  1221. Add(' flash (rx) : ORIGIN = 0x'+IntToHex(flashbase,6)+', LENGTH = 0x'+IntToHex(flashsize,6));
  1222. Add(' ram (rw!x) : ORIGIN = 0x'+IntToHex(srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  1223. Add('}');
  1224. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  1225. end;
  1226. Add('SECTIONS');
  1227. Add('{');
  1228. Add(' .text :');
  1229. Add(' {');
  1230. Add(' _text_start = .;');
  1231. Add(' KEEP(*(.init .init.*))');
  1232. Add(' *(.text .text.*)');
  1233. Add(' *(.strings)');
  1234. Add(' *(.rodata .rodata.*)');
  1235. Add(' *(.comment)');
  1236. Add(' . = ALIGN(4);');
  1237. Add(' _etext = .;');
  1238. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1239. begin
  1240. Add(' } >flash');
  1241. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  1242. end
  1243. else
  1244. begin
  1245. Add(' } >ram');
  1246. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  1247. end;
  1248. Add(' .data :');
  1249. Add(' {');
  1250. Add(' _data = .;');
  1251. Add(' *(.data .data.*)');
  1252. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1253. Add(' _edata = .;');
  1254. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1255. begin
  1256. Add(' } >ram AT >flash');
  1257. end
  1258. else
  1259. begin
  1260. Add(' } >ram');
  1261. end;
  1262. Add(' .bss :');
  1263. Add(' {');
  1264. Add(' _bss_start = .;');
  1265. Add(' *(.bss .bss.*)');
  1266. Add(' *(COMMON)');
  1267. Add(' } >ram');
  1268. Add(' . = ALIGN(4);');
  1269. Add(' _bss_end = . ;');
  1270. Add(' /* Stabs debugging sections. */');
  1271. Add(' .stab 0 : { *(.stab) }');
  1272. Add(' .stabstr 0 : { *(.stabstr) }');
  1273. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1274. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1275. Add(' .stab.index 0 : { *(.stab.index) }');
  1276. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1277. Add(' .comment 0 : { *(.comment) }');
  1278. Add(' /* DWARF debug sections.');
  1279. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1280. Add(' of the section so we begin them at 0. */');
  1281. Add(' /* DWARF 1 */');
  1282. Add(' .debug 0 : { *(.debug) }');
  1283. Add(' .line 0 : { *(.line) }');
  1284. Add(' /* GNU DWARF 1 extensions */');
  1285. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1286. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1287. Add(' /* DWARF 1.1 and DWARF 2 */');
  1288. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1289. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1290. Add(' /* DWARF 2 */');
  1291. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1292. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1293. Add(' .debug_line 0 : { *(.debug_line) }');
  1294. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1295. Add(' .debug_str 0 : { *(.debug_str) }');
  1296. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1297. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1298. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1299. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1300. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1301. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1302. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1303. Add(' /* DWARF 3 */');
  1304. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1305. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1306. Add('}');
  1307. Add('_end = .;');
  1308. end;
  1309. {$endif RISCV32}
  1310. {$ifdef XTENSA}
  1311. with linkres do
  1312. begin
  1313. Add('/* Script for -z combreloc: combine and sort reloc sections */');
  1314. Add('/* Copyright (C) 2014-2018 Free Software Foundation, Inc.');
  1315. Add(' Copying and distribution of this script, with or without modification,');
  1316. Add(' are permitted in any medium without royalty provided the copyright');
  1317. Add(' notice and this notice are preserved. */');
  1318. Add('ENTRY(_start)');
  1319. 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");');
  1320. Add('SECTIONS');
  1321. Add('{');
  1322. Add(' /* Read-only sections, merged into text segment: */');
  1323. Add(' PROVIDE (__executable_start = 0x400000); . = 0x400000 + SIZEOF_HEADERS;');
  1324. Add(' .interp : { *(.interp) }');
  1325. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1326. Add(' .hash : { *(.hash) }');
  1327. Add(' .gnu.hash : { *(.gnu.hash) }');
  1328. Add(' .dynsym : { *(.dynsym) }');
  1329. Add(' .dynstr : { *(.dynstr) }');
  1330. Add(' .gnu.version : { *(.gnu.version) }');
  1331. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  1332. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  1333. Add(' .rela.dyn :');
  1334. Add(' {');
  1335. Add(' *(.rela.init)');
  1336. Add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  1337. Add(' *(.rela.fini)');
  1338. Add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  1339. Add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  1340. Add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  1341. Add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  1342. Add(' *(.rela.ctors)');
  1343. Add(' *(.rela.dtors)');
  1344. Add(' *(.rela.got)');
  1345. Add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  1346. Add(' }');
  1347. Add(' .rela.plt : { *(.rela.plt) }');
  1348. Add(' /* .plt* sections are embedded in .text */');
  1349. Add(' .text :');
  1350. Add(' {');
  1351. Add(' *(.got.plt* .plt*)');
  1352. Add(' KEEP (*(.init.literal))');
  1353. Add(' KEEP (*(SORT_NONE(.init)))');
  1354. Add(' *(.literal .text .stub .literal.* .text.* .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)');
  1355. Add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  1356. Add(' *(.gnu.warning)');
  1357. Add(' KEEP (*(.fini.literal))');
  1358. Add(' KEEP (*(SORT_NONE(.fini)))');
  1359. Add(' } =0');
  1360. Add(' PROVIDE (__etext = .);');
  1361. Add(' PROVIDE (_etext = .);');
  1362. Add(' PROVIDE (etext = .);');
  1363. Add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
  1364. Add(' .rodata1 : { *(.rodata1) }');
  1365. Add(' .got.loc : { *(.got.loc) }');
  1366. Add(' .xt_except_table : ONLY_IF_RO { KEEP (*(.xt_except_table .xt_except_table.* .gnu.linkonce.e.*)) }');
  1367. Add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  1368. Add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  1369. Add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }');
  1370. Add(' /* Adjust the address for the data segment. We want to adjust up to');
  1371. Add(' the same address within the page on the next page up. */');
  1372. Add(' . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));');
  1373. Add(' /* Exception handling */');
  1374. Add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  1375. Add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  1376. Add(' /* Thread Local Storage sections */');
  1377. Add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  1378. Add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  1379. Add(' .preinit_array :');
  1380. Add(' {');
  1381. Add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
  1382. Add(' KEEP (*(.preinit_array))');
  1383. Add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
  1384. Add(' }');
  1385. Add(' .init_array :');
  1386. Add(' {');
  1387. Add(' PROVIDE_HIDDEN (__init_array_start = .);');
  1388. Add(' KEEP (*(SORT(.init_array.*)))');
  1389. Add(' KEEP (*(.init_array))');
  1390. Add(' PROVIDE_HIDDEN (__init_array_end = .);');
  1391. Add(' }');
  1392. Add(' .fini_array :');
  1393. Add(' {');
  1394. Add(' PROVIDE_HIDDEN (__fini_array_start = .);');
  1395. Add(' KEEP (*(SORT(.fini_array.*)))');
  1396. Add(' KEEP (*(.fini_array))');
  1397. Add(' PROVIDE_HIDDEN (__fini_array_end = .);');
  1398. Add(' }');
  1399. Add(' .ctors :');
  1400. Add(' {');
  1401. Add(' /* gcc uses crtbegin.o to find the start of');
  1402. Add(' the constructors, so we make sure it is');
  1403. Add(' first. Because this is a wildcard, it');
  1404. Add(' doesn''t matter if the user does not');
  1405. Add(' actually link against crtbegin.o; the');
  1406. Add(' linker won''t look for a file to match a');
  1407. Add(' wildcard. The wildcard also means that it');
  1408. Add(' doesn''t matter which directory crtbegin.o');
  1409. Add(' is in. */');
  1410. Add(' KEEP (*crtbegin.o(.ctors))');
  1411. Add(' KEEP (*crtbegin?.o(.ctors))');
  1412. Add(' /* We don''t want to include the .ctor section from');
  1413. Add(' the crtend.o file until after the sorted ctors.');
  1414. Add(' The .ctor section from the crtend file contains the');
  1415. Add(' end of ctors marker and it must be last */');
  1416. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
  1417. Add(' KEEP (*(SORT(.ctors.*)))');
  1418. Add(' KEEP (*(.ctors))');
  1419. Add(' }');
  1420. Add(' .dtors :');
  1421. Add(' {');
  1422. Add(' KEEP (*crtbegin.o(.dtors))');
  1423. Add(' KEEP (*crtbegin?.o(.dtors))');
  1424. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
  1425. Add(' KEEP (*(SORT(.dtors.*)))');
  1426. Add(' KEEP (*(.dtors))');
  1427. Add(' }');
  1428. Add(' .jcr : { KEEP (*(.jcr)) }');
  1429. 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.*) }');
  1430. Add(' .xt_except_table : ONLY_IF_RW { KEEP (*(.xt_except_table .xt_except_table.* .gnu.linkonce.e.*)) }');
  1431. Add(' .dynamic : { *(.dynamic) }');
  1432. Add(' .got : { *(.got) }');
  1433. Add(' .data :');
  1434. Add(' {');
  1435. Add(' *(.data .data.* .gnu.linkonce.d.*)');
  1436. Add(' SORT(CONSTRUCTORS)');
  1437. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1438. Add(' }');
  1439. Add(' .data1 : { *(.data1) }');
  1440. Add(' .xt_except_desc :');
  1441. Add(' {');
  1442. Add(' *(.xt_except_desc .xt_except_desc.* .gnu.linkonce.h.*)');
  1443. Add(' *(.xt_except_desc_end)');
  1444. Add(' }');
  1445. Add(' .lit4 :');
  1446. Add(' {');
  1447. Add(' PROVIDE (_lit4_start = .);');
  1448. Add(' *(.lit4 .lit4.* .gnu.linkonce.lit4.*)');
  1449. Add(' PROVIDE (_lit4_end = .);');
  1450. Add(' }');
  1451. Add(' _edata = .; PROVIDE (edata = .);');
  1452. Add(' __bss_start = .;');
  1453. Add(' .bss :');
  1454. Add(' {');
  1455. Add(' *(.dynbss)');
  1456. Add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  1457. Add(' *(COMMON)');
  1458. Add(' /* Align here to ensure that the .bss section occupies space up to');
  1459. Add(' _end. Align after .bss to ensure correct alignment even if the');
  1460. Add(' .bss section disappears because there are no input sections.');
  1461. Add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
  1462. Add(' pad the .data section. */');
  1463. Add(' . = ALIGN(. != 0 ? 32 / 8 : 1);');
  1464. Add(' }');
  1465. Add(' . = ALIGN(32 / 8);');
  1466. Add(' . = ALIGN(32 / 8);');
  1467. Add(' _end = .; PROVIDE (end = .);');
  1468. Add(' /* Stabs debugging sections. */');
  1469. Add(' .stab 0 : { *(.stab) }');
  1470. Add(' .stabstr 0 : { *(.stabstr) }');
  1471. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1472. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1473. Add(' .stab.index 0 : { *(.stab.index) }');
  1474. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1475. Add(' .comment 0 : { *(.comment) }');
  1476. Add(' /* DWARF debug sections.');
  1477. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1478. Add(' of the section so we begin them at 0. */');
  1479. Add(' /* DWARF 1 */');
  1480. Add(' .debug 0 : { *(.debug) }');
  1481. Add(' .line 0 : { *(.line) }');
  1482. Add(' /* GNU DWARF 1 extensions */');
  1483. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1484. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1485. Add(' /* DWARF 1.1 and DWARF 2 */');
  1486. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1487. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1488. Add(' /* DWARF 2 */');
  1489. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1490. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1491. Add(' .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }');
  1492. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1493. Add(' .debug_str 0 : { *(.debug_str) }');
  1494. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1495. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1496. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1497. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1498. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1499. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1500. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1501. Add(' /* DWARF 3 */');
  1502. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1503. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1504. Add(' /* DWARF Extension. */');
  1505. Add(' .debug_macro 0 : { *(.debug_macro) }');
  1506. Add(' .debug_addr 0 : { *(.debug_addr) }');
  1507. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1508. Add(' .xt.lit 0 : { KEEP (*(.xt.lit .xt.lit.* .gnu.linkonce.p.*)) }');
  1509. Add(' .xt.insn 0 : { KEEP (*(.xt.insn .gnu.linkonce.x.*)) }');
  1510. Add(' .xt.prop 0 : { KEEP (*(.xt.prop .xt.prop.* .gnu.linkonce.prop.*)) }');
  1511. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1512. Add('}');
  1513. end;
  1514. {$endif XTENSA}
  1515. { Write and Close response }
  1516. linkres.writetodisk;
  1517. linkres.free;
  1518. WriteResponseFile:=True;
  1519. end;
  1520. function TlinkerEmbedded.MakeExecutable:boolean;
  1521. var
  1522. binstr,
  1523. cmdstr,
  1524. mapstr: TCmdStr;
  1525. success : boolean;
  1526. StaticStr,
  1527. GCSectionsStr,
  1528. DynLinkStr,
  1529. StripStr,
  1530. FixedExeFileName: string;
  1531. begin
  1532. { for future use }
  1533. StaticStr:='';
  1534. StripStr:='';
  1535. mapstr:='';
  1536. DynLinkStr:='';
  1537. FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
  1538. GCSectionsStr:='--gc-sections';
  1539. //if not(cs_link_extern in current_settings.globalswitches) then
  1540. if not(cs_link_nolink in current_settings.globalswitches) then
  1541. Message1(exec_i_linking,current_module.exefilename);
  1542. if (cs_link_map in current_settings.globalswitches) then
  1543. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  1544. { Write used files and libraries }
  1545. WriteResponseFile();
  1546. { Call linker }
  1547. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1548. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1549. if not(cs_link_on_target in current_settings.globalswitches) then
  1550. begin
  1551. Replace(cmdstr,'$EXE',FixedExeFileName);
  1552. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  1553. Replace(cmdstr,'$STATIC',StaticStr);
  1554. Replace(cmdstr,'$STRIP',StripStr);
  1555. Replace(cmdstr,'$MAP',mapstr);
  1556. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1557. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1558. end
  1559. else
  1560. begin
  1561. Replace(cmdstr,'$EXE',FixedExeFileName);
  1562. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1563. Replace(cmdstr,'$STATIC',StaticStr);
  1564. Replace(cmdstr,'$STRIP',StripStr);
  1565. Replace(cmdstr,'$MAP',mapstr);
  1566. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1567. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1568. end;
  1569. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1570. { Remove ReponseFile }
  1571. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1572. DeleteFile(outputexedir+Info.ResName);
  1573. { Post process }
  1574. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1575. success:=PostProcessExecutable(FixedExeFileName,false);
  1576. if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded,system_xtensa_embedded]) then
  1577. begin
  1578. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  1579. FixedExeFileName+' '+
  1580. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
  1581. if success then
  1582. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  1583. FixedExeFileName+' '+
  1584. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  1585. if success and (target_info.system in systems_support_uf2) and (cs_generate_uf2 in current_settings.globalswitches) then
  1586. success := GenerateUF2(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),
  1587. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.uf2'))),
  1588. embedded_controllers[current_settings.controllertype].flashbase);
  1589. {$ifdef ARM}
  1590. if success and (current_settings.controllertype = ct_raspi2) then
  1591. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+ FixedExeFileName + ' kernel7.img',true,false);
  1592. {$endif ARM}
  1593. end;
  1594. MakeExecutable:=success; { otherwise a recursive call to link method }
  1595. end;
  1596. function TLinkerEmbedded.postprocessexecutable(const fn : string;isdll:boolean):boolean;
  1597. begin
  1598. Result:=PostProcessELFExecutable(fn,isdll);
  1599. end;
  1600. function TlinkerEmbedded.GenerateUF2(binFile,uf2File : string;baseAddress : longWord):boolean;
  1601. type
  1602. TFamilies= record
  1603. k : String;
  1604. v : longWord;
  1605. end;
  1606. tuf2Block = record
  1607. magicStart0,
  1608. magicStart1,
  1609. flags,
  1610. targetAddr,
  1611. payloadSize,
  1612. blockNo,
  1613. numBlocks,
  1614. familyid : longWord;
  1615. data : array[0..255] of byte;
  1616. padding : array[0..511-256-32-4] of byte;
  1617. magicEnd : longWord;
  1618. end;
  1619. const
  1620. Families : array of TFamilies = (
  1621. (k:'SAMD21'; v:$68ed2b88),
  1622. (k:'SAML21'; v:$1851780a),
  1623. (k:'SAMD51'; v:$55114460),
  1624. (k:'NRF52'; v:$1b57745f),
  1625. (k:'STM32F0';v:$647824b6),
  1626. (k:'STM32F1';v:$5ee21072),
  1627. (k:'STM32F2';v:$5d1a0a2e),
  1628. (k:'STM32F3';v:$6b846188),
  1629. (k:'STM32F4';v:$57755a57),
  1630. (k:'STM32F7';v:$53b80f00),
  1631. (k:'STM32G0';v:$300f5633),
  1632. (k:'STM32G4';v:$4c71240a),
  1633. (k:'STM32H7';v:$6db66082),
  1634. (k:'STM32L0';v:$202e3a91),
  1635. (k:'STM32L1';v:$1e1f432d),
  1636. (k:'STM32L4';v:$00ff6919),
  1637. (k:'STM32L5';v:$04240bdf),
  1638. (k:'STM32WB';v:$70d16653),
  1639. (k:'STM32WL';v:$21460ff0)
  1640. );
  1641. var
  1642. f,g : file;
  1643. uf2block : Tuf2Block;
  1644. totalRead,numRead : longWord;
  1645. familyId,i : longWord;
  1646. ExtraOptions : String;
  1647. begin
  1648. if pos('-Ttext=',Info.ExtraOptions) > 0 then
  1649. begin
  1650. ExtraOptions := copy(Info.ExtraOptions,pos('-Ttext=',Info.ExtraOptions)+7,length(Info.ExtraOptions));
  1651. for i := 1 to length(ExtraOptions) do
  1652. if pos(copy(ExtraOptions,i,1),'0123456789abcdefxABCDEFX') = 0 then
  1653. ExtraOptions := copy(ExtraOptions,1,i);
  1654. baseAddress := StrToIntDef(ExtraOptions,0);
  1655. end;
  1656. familyId := 0;
  1657. for i := 0 to length(Families)-1 do
  1658. begin
  1659. if pos(Families[i].k,embedded_controllers[current_settings.controllertype].controllerunitstr) = 1 then
  1660. familyId := Families[i].v;
  1661. end;
  1662. if (baseAddress and $07ffffff) <> 0 then
  1663. begin
  1664. totalRead := 0;
  1665. numRead := 0;
  1666. assign(f,binfile);
  1667. reset(f,1);
  1668. assign(g,uf2file);
  1669. rewrite(g,1);
  1670. repeat
  1671. fillchar(uf2block,sizeof(uf2block),0);
  1672. uf2block.magicStart0 := $0A324655; // "UF2\n"
  1673. uf2block.magicStart1 := $9E5D5157; // Randomly selected
  1674. if familyId = 0 then
  1675. uf2block.flags := 0
  1676. else
  1677. uf2block.flags := $2000;
  1678. uf2block.targetAddr := baseAddress + totalread;
  1679. uf2block.payloadSize := 256;
  1680. uf2block.blockNo := (totalRead div sizeOf(uf2block.data));
  1681. uf2block.numBlocks := (filesize(f) + 255) div 256;
  1682. uf2block.familyId := familyId;
  1683. uf2block.magicEnd := $0AB16F30; // Randomly selected
  1684. blockRead(f,uf2block.data,sizeof(uf2block.data),numRead);
  1685. blockwrite(g,uf2block,sizeof(uf2block));
  1686. inc(totalRead,numRead);
  1687. until (numRead=0) or (NumRead<>sizeOf(uf2block.data));
  1688. close(f);
  1689. close(g);
  1690. end;
  1691. Result := true;
  1692. end;
  1693. {*****************************************************************************
  1694. TlinkerEmbedded_SdccSdld
  1695. *****************************************************************************}
  1696. function TlinkerEmbedded_SdccSdld.WriteResponseFile: Boolean;
  1697. Var
  1698. linkres : TLinkRes;
  1699. //i : longint;
  1700. //HPath : TCmdStrListItem;
  1701. s{,s1,s2} : TCmdStr;
  1702. prtobj,
  1703. cprtobj : string[80];
  1704. linklibc : boolean;
  1705. //found1,
  1706. //found2 : boolean;
  1707. begin
  1708. WriteResponseFile:=False;
  1709. linklibc:=(SharedLibFiles.Find('c')<>nil);
  1710. prtobj:='prt0';
  1711. cprtobj:='cprt0';
  1712. if linklibc then
  1713. prtobj:=cprtobj;
  1714. { Open link.res file }
  1715. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  1716. { Write path to search libraries }
  1717. (* HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  1718. while assigned(HPath) do
  1719. begin
  1720. s:=HPath.Str;
  1721. if (cs_link_on_target in current_settings.globalswitches) then
  1722. s:=ScriptFixFileName(s);
  1723. LinkRes.Add('-L'+s);
  1724. HPath:=TCmdStrListItem(HPath.Next);
  1725. end;
  1726. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  1727. while assigned(HPath) do
  1728. begin
  1729. s:=HPath.Str;
  1730. if s<>'' then
  1731. LinkRes.Add('SEARCH_DIR("'+s+'")');
  1732. HPath:=TCmdStrListItem(HPath.Next);
  1733. end;
  1734. LinkRes.Add('INPUT (');
  1735. { add objectfiles, start with prt0 always }*)
  1736. //s:=FindObjectFile('prt0','',false);
  1737. if prtobj<>'' then
  1738. begin
  1739. s:=FindObjectFile(prtobj,'',false);
  1740. LinkRes.AddFileName(s);
  1741. end;
  1742. { try to add crti and crtbegin if linking to C }
  1743. if linklibc then
  1744. begin
  1745. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  1746. LinkRes.AddFileName(s);
  1747. if librarysearchpath.FindFile('crti.o',false,s) then
  1748. LinkRes.AddFileName(s);
  1749. end;
  1750. while not ObjectFiles.Empty do
  1751. begin
  1752. s:=ObjectFiles.GetFirst;
  1753. if s<>'' then
  1754. begin
  1755. { vlink doesn't use SEARCH_DIR for object files }
  1756. if not(cs_link_on_target in current_settings.globalswitches) then
  1757. s:=FindObjectFile(s,'',false);
  1758. LinkRes.AddFileName((maybequoted(s)));
  1759. end;
  1760. end;
  1761. { Write staticlibraries }
  1762. if not StaticLibFiles.Empty then
  1763. begin
  1764. { vlink doesn't need, and doesn't support GROUP }
  1765. { if (cs_link_on_target in current_settings.globalswitches) then
  1766. begin
  1767. LinkRes.Add(')');
  1768. LinkRes.Add('GROUP(');
  1769. end;}
  1770. while not StaticLibFiles.Empty do
  1771. begin
  1772. S:=StaticLibFiles.GetFirst;
  1773. LinkRes.Add('-l'+maybequoted(s));
  1774. end;
  1775. end;
  1776. (* if (cs_link_on_target in current_settings.globalswitches) then
  1777. begin
  1778. LinkRes.Add(')');
  1779. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  1780. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  1781. linklibc:=false;
  1782. while not SharedLibFiles.Empty do
  1783. begin
  1784. S:=SharedLibFiles.GetFirst;
  1785. if s<>'c' then
  1786. begin
  1787. i:=Pos(target_info.sharedlibext,S);
  1788. if i>0 then
  1789. Delete(S,i,255);
  1790. LinkRes.Add('-l'+s);
  1791. end
  1792. else
  1793. begin
  1794. LinkRes.Add('-l'+s);
  1795. linklibc:=true;
  1796. end;
  1797. end;
  1798. { be sure that libc&libgcc is the last lib }
  1799. if linklibc then
  1800. begin
  1801. LinkRes.Add('-lc');
  1802. LinkRes.Add('-lgcc');
  1803. end;
  1804. end
  1805. else
  1806. begin
  1807. while not SharedLibFiles.Empty do
  1808. begin
  1809. S:=SharedLibFiles.GetFirst;
  1810. LinkRes.Add('lib'+s+target_info.staticlibext);
  1811. end;
  1812. LinkRes.Add(')');
  1813. end;*)
  1814. { objects which must be at the end }
  1815. (*if linklibc then
  1816. begin
  1817. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  1818. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  1819. if found1 or found2 then
  1820. begin
  1821. LinkRes.Add('INPUT(');
  1822. if found1 then
  1823. LinkRes.AddFileName(s1);
  1824. if found2 then
  1825. LinkRes.AddFileName(s2);
  1826. LinkRes.Add(')');
  1827. end;
  1828. end;*)
  1829. { Write and Close response }
  1830. linkres.writetodisk;
  1831. linkres.free;
  1832. WriteResponseFile:=True;
  1833. end;
  1834. procedure TlinkerEmbedded_SdccSdld.SetDefaultInfo;
  1835. const
  1836. {$if defined(Z80)}
  1837. ExeName='sdldz80';
  1838. {$else}
  1839. ExeName='sdld';
  1840. {$endif}
  1841. begin
  1842. with Info do
  1843. begin
  1844. ExeCmd[1]:=ExeName+' -n $OPT -i $MAP $EXE -f $RES'
  1845. //-g '+platform_select+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE -T $RES';
  1846. end;
  1847. end;
  1848. function TlinkerEmbedded_SdccSdld.MakeExecutable: boolean;
  1849. var
  1850. binstr,
  1851. cmdstr,
  1852. mapstr: TCmdStr;
  1853. success : boolean;
  1854. StaticStr,
  1855. // GCSectionsStr,
  1856. DynLinkStr,
  1857. StripStr,
  1858. FixedExeFileName: string;
  1859. begin
  1860. { for future use }
  1861. StaticStr:='';
  1862. StripStr:='';
  1863. mapstr:='';
  1864. DynLinkStr:='';
  1865. FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.ihx')));
  1866. (* GCSectionsStr:='--gc-sections';
  1867. //if not(cs_link_extern in current_settings.globalswitches) then
  1868. if not(cs_link_nolink in current_settings.globalswitches) then
  1869. Message1(exec_i_linking,current_module.exefilename);*)
  1870. if (cs_link_map in current_settings.globalswitches) then
  1871. mapstr:='-mw';
  1872. { Write used files and libraries }
  1873. WriteResponseFile();
  1874. { Call linker }
  1875. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1876. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1877. if not(cs_link_on_target in current_settings.globalswitches) then
  1878. begin
  1879. Replace(cmdstr,'$EXE',FixedExeFileName);
  1880. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  1881. Replace(cmdstr,'$STATIC',StaticStr);
  1882. Replace(cmdstr,'$STRIP',StripStr);
  1883. Replace(cmdstr,'$MAP',mapstr);
  1884. // Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1885. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1886. end
  1887. else
  1888. begin
  1889. Replace(cmdstr,'$EXE',FixedExeFileName);
  1890. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1891. Replace(cmdstr,'$STATIC',StaticStr);
  1892. Replace(cmdstr,'$STRIP',StripStr);
  1893. Replace(cmdstr,'$MAP',mapstr);
  1894. // Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1895. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1896. end;
  1897. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1898. { Remove ReponseFile }
  1899. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1900. DeleteFile(outputexedir+Info.ResName);
  1901. (* { Post process }
  1902. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1903. success:=PostProcessExecutable(FixedExeFileName,false);
  1904. if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded,system_xtensa_embedded]) then
  1905. begin
  1906. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  1907. FixedExeFileName+' '+
  1908. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
  1909. if success then
  1910. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  1911. FixedExeFileName+' '+
  1912. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  1913. end;*)
  1914. MakeExecutable:=success; { otherwise a recursive call to link method }
  1915. end;
  1916. {*****************************************************************************
  1917. TlinkerEmbedded_Wasm
  1918. *****************************************************************************}
  1919. constructor TLinkerEmbedded_Wasm.Create;
  1920. begin
  1921. inherited Create;
  1922. end;
  1923. procedure TLinkerEmbedded_Wasm.SetDefaultInfo;
  1924. begin
  1925. Info.DllCmd[1] := 'wasm-ld $SONAME $GCSECTIONS -o $EXE';
  1926. //Info.DllCmd[2] := 'wasmtool --exportrename $INPUT $EXE';
  1927. end;
  1928. function TLinkerEmbedded_Wasm.MakeSharedLibrary: boolean;
  1929. var
  1930. GCSectionsStr : ansistring;
  1931. binstr, cmdstr : Tcmdstr;
  1932. InitStr,
  1933. FiniStr,
  1934. SoNameStr : string[80];
  1935. mapstr,ltostr : TCmdStr;
  1936. success : Boolean;
  1937. tmp : TCmdStrListItem;
  1938. tempFileName : ansistring;
  1939. begin
  1940. //Result := true;
  1941. //Result:=inherited MakeSharedLibrary;
  1942. if (cs_link_smart in current_settings.globalswitches) and
  1943. create_smartlink_sections then
  1944. GCSectionsStr:='--gc-sections'
  1945. else
  1946. GCSectionsStr:='';
  1947. SoNameStr:='';
  1948. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  1949. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  1950. tmp := TCmdStrListItem(ObjectFiles.First);
  1951. while Assigned(tmp) do begin
  1952. cmdstr := tmp.Str+ ' ' + cmdstr;
  1953. tmp := TCmdStrListItem(tmp.Next);
  1954. end;
  1955. if HasExports then
  1956. cmdstr := cmdstr + ' --export-dynamic'; //' --export-dynamic';
  1957. cmdstr := cmdstr + ' --no-entry --allow-undefined';
  1958. if (cs_link_strip in current_settings.globalswitches) then
  1959. begin
  1960. { only remove non global symbols and debugging info for a library }
  1961. cmdstr := cmdstr + ' --strip-all';
  1962. end;
  1963. //Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1964. //Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  1965. //Replace(cmdstr,'$INIT',InitStr);
  1966. //Replace(cmdstr,'$FINI',FiniStr);
  1967. Replace(cmdstr,'$SONAME',SoNameStr);
  1968. //Replace(cmdstr,'$MAP',mapstr);
  1969. //Replace(cmdstr,'$LTO',ltostr);
  1970. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1971. writeln(utilsprefix+binstr,' ',cmdstr);
  1972. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  1973. //SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  1974. //Replace(cmdstr,'$INPUT',current_module.objfilename );
  1975. //Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  1976. //DoExec(FindUtil(utilsprefix+binstr),cmdstr,false,false);
  1977. MakeSharedLibrary:=success;
  1978. end;
  1979. {*****************************************************************************
  1980. Initialize
  1981. *****************************************************************************}
  1982. initialization
  1983. {$ifdef arm}
  1984. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1985. RegisterTarget(system_arm_embedded_info);
  1986. {$endif arm}
  1987. {$ifdef avr}
  1988. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1989. RegisterTarget(system_avr_embedded_info);
  1990. {$endif avr}
  1991. {$ifdef i386}
  1992. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1993. RegisterTarget(system_i386_embedded_info);
  1994. {$endif i386}
  1995. {$ifdef x86_64}
  1996. RegisterLinker(ld_embedded,TLinkerEmbedded);
  1997. RegisterTarget(system_x86_64_embedded_info);
  1998. {$endif x86_64}
  1999. {$ifdef i8086}
  2000. { no need to register linker ld_embedded, because i8086_embedded uses the
  2001. regular msdos linker. In case a flat binary, relocated for a specific
  2002. segment address is needed (e.g. for a BIOS or a real mode bootloader), it
  2003. can be produced post-compilation with exe2bin or a similar tool. }
  2004. RegisterTarget(system_i8086_embedded_info);
  2005. {$endif i8086}
  2006. {$ifdef mipsel}
  2007. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2008. RegisterTarget(system_mipsel_embedded_info);
  2009. {$endif mipsel}
  2010. {$ifdef m68k}
  2011. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2012. RegisterTarget(system_m68k_embedded_info);
  2013. {$endif m68k}
  2014. {$ifdef riscv32}
  2015. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2016. RegisterTarget(system_riscv32_embedded_info);
  2017. {$endif riscv32}
  2018. {$ifdef riscv64}
  2019. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2020. RegisterTarget(system_riscv64_embedded_info);
  2021. {$endif riscv64}
  2022. {$ifdef xtensa}
  2023. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2024. RegisterTarget(system_xtensa_embedded_info);
  2025. {$endif xtensa}
  2026. {$ifdef z80}
  2027. RegisterLinker(ld_embedded,TlinkerEmbedded_SdccSdld);
  2028. RegisterTarget(system_z80_embedded_info);
  2029. {$endif z80}
  2030. {$ifdef wasm32}
  2031. RegisterTarget(system_wasm32_embedded_info);
  2032. RegisterImport(system_wasm32_embedded, timportlibwasi);
  2033. RegisterExport(system_wasm32_embedded, texportlibwasi);
  2034. RegisterLinker(ld_embedded, TLinkerEmbedded_Wasm);
  2035. {$endif wasm32}
  2036. end.