t_embed.pas 75 KB

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