t_embed.pas 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298
  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(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1049. Add(' . = ALIGN(2);');
  1050. Add(' _edata = . ;');
  1051. Add(' PROVIDE (__data_end = .) ;');
  1052. Add(' } > data');
  1053. Add(' .bss : AT (ADDR (.bss))');
  1054. Add(' {');
  1055. Add(' PROVIDE (__bss_start = .) ;');
  1056. Add(' *(.bss)');
  1057. Add(' *(.bss*)');
  1058. Add(' *(COMMON)');
  1059. Add(' PROVIDE (__bss_end = .) ;');
  1060. Add(' } > data');
  1061. Add(' __data_load_start = LOADADDR(.data);');
  1062. Add(' __data_load_end = __data_load_start + SIZEOF(.data);');
  1063. Add(' /* Global data not cleared after reset. */');
  1064. Add(' .noinit :');
  1065. Add(' {');
  1066. Add(' PROVIDE (__noinit_start = .) ;');
  1067. Add(' *(.noinit*)');
  1068. Add(' PROVIDE (__noinit_end = .) ;');
  1069. Add(' _end = . ;');
  1070. Add(' PROVIDE (__heap_start = .) ;');
  1071. Add(' } > data');
  1072. Add(' .eeprom :');
  1073. Add(' {');
  1074. Add(' *(.eeprom*)');
  1075. Add(' __eeprom_end = . ;');
  1076. Add(' } > eeprom');
  1077. Add(' .fuse :');
  1078. Add(' {');
  1079. Add(' KEEP(*(.fuse))');
  1080. Add(' KEEP(*(.lfuse))');
  1081. Add(' KEEP(*(.hfuse))');
  1082. Add(' KEEP(*(.efuse))');
  1083. Add(' } > fuse');
  1084. Add(' .lock :');
  1085. Add(' {');
  1086. Add(' KEEP(*(.lock*))');
  1087. Add(' } > lock');
  1088. Add(' .signature :');
  1089. Add(' {');
  1090. Add(' KEEP(*(.signature*))');
  1091. Add(' } > signature');
  1092. Add(' /* Stabs debugging sections. */');
  1093. Add(' .stab 0 : { *(.stab) }');
  1094. Add(' .stabstr 0 : { *(.stabstr) }');
  1095. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1096. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1097. Add(' .stab.index 0 : { *(.stab.index) }');
  1098. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1099. Add(' .comment 0 : { *(.comment) }');
  1100. Add(' /* DWARF debug sections.');
  1101. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1102. Add(' of the section so we begin them at 0. */');
  1103. Add(' /* DWARF 1 */');
  1104. Add(' .debug 0 : { *(.debug) }');
  1105. Add(' .line 0 : { *(.line) }');
  1106. Add(' /* GNU DWARF 1 extensions */');
  1107. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1108. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1109. Add(' /* DWARF 1.1 and DWARF 2 */');
  1110. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1111. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1112. Add(' /* DWARF 2 */');
  1113. Add(' .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }');
  1114. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1115. Add(' .debug_line 0 : { *(.debug_line) }');
  1116. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1117. Add(' .debug_str 0 : { *(.debug_str) }');
  1118. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1119. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1120. Add(' /* DWARF 3 */');
  1121. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1122. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1123. Add(' /* DWARF Extension. */');
  1124. Add(' .debug_macro 0 : { *(.debug_macro) }');
  1125. Add('}');
  1126. end;
  1127. {$endif AVR}
  1128. {$ifdef MIPSEL}
  1129. case current_settings.controllertype of
  1130. ct_none:
  1131. begin
  1132. end;
  1133. ct_pic32mx110f016b,
  1134. ct_pic32mx110f016c,
  1135. ct_pic32mx110f016d,
  1136. ct_pic32mx120f032b,
  1137. ct_pic32mx120f032c,
  1138. ct_pic32mx120f032d,
  1139. ct_pic32mx130f064b,
  1140. ct_pic32mx130f064c,
  1141. ct_pic32mx130f064d,
  1142. ct_pic32mx150f128b,
  1143. ct_pic32mx150f128c,
  1144. ct_pic32mx150f128d,
  1145. ct_pic32mx210f016b,
  1146. ct_pic32mx210f016c,
  1147. ct_pic32mx210f016d,
  1148. ct_pic32mx220f032b,
  1149. ct_pic32mx220f032c,
  1150. ct_pic32mx220f032d,
  1151. ct_pic32mx230f064b,
  1152. ct_pic32mx230f064c,
  1153. ct_pic32mx230f064d,
  1154. ct_pic32mx250f128b,
  1155. ct_pic32mx250f128c,
  1156. ct_pic32mx250f128d,
  1157. ct_pic32mx775f256h,
  1158. ct_pic32mx775f256l,
  1159. ct_pic32mx775f512h,
  1160. ct_pic32mx775f512l,
  1161. ct_pic32mx795f512h,
  1162. ct_pic32mx795f512l:
  1163. begin
  1164. with embedded_controllers[current_settings.controllertype] do
  1165. with linkres do
  1166. begin
  1167. Add('OUTPUT_FORMAT("elf32-tradlittlemips")');
  1168. Add('OUTPUT_ARCH(pic32mx)');
  1169. Add('ENTRY(_reset)');
  1170. Add('PROVIDE(_vector_spacing = 0x00000001);');
  1171. Add('_ebase_address = 0x'+IntToHex(flashbase,8)+';');
  1172. Add('_RESET_ADDR = 0xBFC00000;');
  1173. Add('_BEV_EXCPT_ADDR = 0xBFC00380;');
  1174. Add('_DBG_EXCPT_ADDR = 0xBFC00480;');
  1175. Add('_GEN_EXCPT_ADDR = _ebase_address + 0x180;');
  1176. Add('MEMORY');
  1177. Add('{');
  1178. if flashsize<>0 then
  1179. begin
  1180. Add(' kseg0_program_mem : ORIGIN = 0x'+IntToHex(flashbase,8)+', LENGTH = 0x'+IntToHex(flashsize,8));
  1181. //TODO This should better be placed into the controllertype records
  1182. Add(' kseg1_boot_mem : ORIGIN = 0xBFC00000, LENGTH = 0xbef');
  1183. Add(' config3 : ORIGIN = 0xBFC00BF0, LENGTH = 0x4');
  1184. Add(' config2 : ORIGIN = 0xBFC00BF4, LENGTH = 0x4');
  1185. Add(' config1 : ORIGIN = 0xBFC00BF8, LENGTH = 0x4');
  1186. Add(' config0 : ORIGIN = 0xBFC00BFC, LENGTH = 0x4');
  1187. end;
  1188. Add(' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  1189. + ', LENGTH = 0x' + IntToHex(sramsize,8));
  1190. Add('}');
  1191. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  1192. end;
  1193. end
  1194. end;
  1195. with linkres do
  1196. begin
  1197. Add('SECTIONS');
  1198. Add('{');
  1199. Add(' .reset _RESET_ADDR :');
  1200. Add(' {');
  1201. Add(' KEEP(*(.reset .reset.*))');
  1202. Add(' KEEP(*(.startup .startup.*))');
  1203. Add(' } > kseg1_boot_mem');
  1204. Add(' .bev_excpt _BEV_EXCPT_ADDR :');
  1205. Add(' {');
  1206. Add(' KEEP(*(.bev_handler))');
  1207. Add(' } > kseg1_boot_mem');
  1208. Add(' .text :');
  1209. Add(' {');
  1210. Add(' _text_start = .;');
  1211. Add(' . = _text_start + 0x180;');
  1212. Add(' KEEP(*(.gen_handler))');
  1213. Add(' . = _text_start + 0x200;');
  1214. Add(' KEEP(*(.init .init.*))');
  1215. Add(' *(.text .text.*)');
  1216. Add(' *(.strings)');
  1217. Add(' *(.rodata .rodata.*)');
  1218. Add(' *(.comment)');
  1219. Add(' _etext = .;');
  1220. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1221. begin
  1222. Add(' } >kseg0_program_mem');
  1223. end
  1224. else
  1225. begin
  1226. Add(' } >ram');
  1227. end;
  1228. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1229. Add(' .data :');
  1230. Add(' {');
  1231. Add(' _data = .;');
  1232. Add(' *(.data .data.*)');
  1233. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1234. Add(' . = .;');
  1235. Add(' _gp = ALIGN(16) + 0x7ff0;');
  1236. Add(' _edata = .;');
  1237. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1238. begin
  1239. Add(' } >ram AT >kseg0_program_mem');
  1240. end
  1241. else
  1242. begin
  1243. Add(' } >ram');
  1244. end;
  1245. Add(' .config_BFC00BF0 : {');
  1246. Add(' KEEP(*(.config_BFC00BF0))');
  1247. Add(' } > config3');
  1248. Add(' .config_BFC00BF4 : {');
  1249. Add(' KEEP(*(.config_BFC00BF4))');
  1250. Add(' } > config2');
  1251. Add(' .config_BFC00BF8 : {');
  1252. Add(' KEEP(*(.config_BFC00BF8))');
  1253. Add(' } > config1');
  1254. Add(' .config_BFC00BFC : {');
  1255. Add(' KEEP(*(.config_BFC00BFC))');
  1256. Add(' } > config0');
  1257. Add(' .bss :');
  1258. Add(' {');
  1259. Add(' _bss_start = .;');
  1260. Add(' *(.bss .bss.*)');
  1261. Add(' *(COMMON)');
  1262. Add(' } >ram');
  1263. Add('. = ALIGN(4);');
  1264. Add('_bss_end = . ;');
  1265. Add(' .comment 0 : { *(.comment) }');
  1266. Add(' /* DWARF debug sections.');
  1267. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1268. Add(' of the section so we begin them at 0. */');
  1269. Add(' /* DWARF 1 */');
  1270. Add(' .debug 0 : { *(.debug) }');
  1271. Add(' .line 0 : { *(.line) }');
  1272. Add(' /* GNU DWARF 1 extensions */');
  1273. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1274. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1275. Add(' /* DWARF 1.1 and DWARF 2 */');
  1276. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1277. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1278. Add(' /* DWARF 2 */');
  1279. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1280. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1281. Add(' /DISCARD/ : { *(.debug_line) }');
  1282. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1283. Add(' .debug_str 0 : { *(.debug_str) }');
  1284. Add(' /DISCARD/ : { *(.debug_loc) }');
  1285. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1286. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1287. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1288. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1289. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1290. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1291. Add(' /* DWARF 3 */');
  1292. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1293. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1294. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1295. Add(' .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }');
  1296. Add(' .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }');
  1297. Add(' .mdebug.abi32 : { KEEP(*(.mdebug.abi32)) }');
  1298. Add(' .mdebug.abiN32 : { KEEP(*(.mdebug.abiN32)) }');
  1299. Add(' .mdebug.abi64 : { KEEP(*(.mdebug.abi64)) }');
  1300. Add(' .mdebug.abiO64 : { KEEP(*(.mdebug.abiO64)) }');
  1301. Add(' .mdebug.eabi32 : { KEEP(*(.mdebug.eabi32)) }');
  1302. Add(' .mdebug.eabi64 : { KEEP(*(.mdebug.eabi64)) }');
  1303. Add(' /DISCARD/ : { *(.rel.dyn) }');
  1304. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1305. Add('}');
  1306. Add('_end = .;');
  1307. end;
  1308. {$endif MIPSEL}
  1309. {$ifdef RISCV32}
  1310. with linkres do
  1311. begin
  1312. Add('OUTPUT_ARCH("riscv")');
  1313. Add('ENTRY(_START)');
  1314. Add('MEMORY');
  1315. with embedded_controllers[current_settings.controllertype] do
  1316. begin
  1317. Add('{');
  1318. Add(' flash (rx) : ORIGIN = 0x'+IntToHex(flashbase,6)+', LENGTH = 0x'+IntToHex(flashsize,6));
  1319. Add(' ram (rw!x) : ORIGIN = 0x'+IntToHex(srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  1320. Add('}');
  1321. Add('_stack_top = 0x' + IntToHex(srambase+sramsize,4) + ';');
  1322. end;
  1323. Add('SECTIONS');
  1324. Add('{');
  1325. Add(' .text :');
  1326. Add(' {');
  1327. Add(' _text_start = .;');
  1328. Add(' KEEP(*(.init .init.*))');
  1329. Add(' *(.text .text.*)');
  1330. Add(' *(.strings)');
  1331. Add(' *(.rodata .rodata.*)');
  1332. Add(' *(.comment)');
  1333. Add(' . = ALIGN(4);');
  1334. Add(' _etext = .;');
  1335. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1336. begin
  1337. Add(' } >flash');
  1338. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  1339. end
  1340. else
  1341. begin
  1342. Add(' } >ram');
  1343. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  1344. end;
  1345. Add(' .data :');
  1346. Add(' {');
  1347. Add(' _data = .;');
  1348. Add(' *(.data .data.*)');
  1349. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1350. Add(' _edata = .;');
  1351. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1352. begin
  1353. Add(' } >ram AT >flash');
  1354. end
  1355. else
  1356. begin
  1357. Add(' } >ram');
  1358. end;
  1359. Add(' .bss :');
  1360. Add(' {');
  1361. Add(' _bss_start = .;');
  1362. Add(' *(.bss .bss.*)');
  1363. Add(' *(COMMON)');
  1364. Add(' } >ram');
  1365. Add(' . = ALIGN(4);');
  1366. Add(' _bss_end = . ;');
  1367. Add(' /* Stabs debugging sections. */');
  1368. Add(' .stab 0 : { *(.stab) }');
  1369. Add(' .stabstr 0 : { *(.stabstr) }');
  1370. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1371. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1372. Add(' .stab.index 0 : { *(.stab.index) }');
  1373. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1374. Add(' .comment 0 : { *(.comment) }');
  1375. Add(' /* DWARF debug sections.');
  1376. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1377. Add(' of the section so we begin them at 0. */');
  1378. Add(' /* DWARF 1 */');
  1379. Add(' .debug 0 : { *(.debug) }');
  1380. Add(' .line 0 : { *(.line) }');
  1381. Add(' /* GNU DWARF 1 extensions */');
  1382. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1383. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1384. Add(' /* DWARF 1.1 and DWARF 2 */');
  1385. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1386. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1387. Add(' /* DWARF 2 */');
  1388. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1389. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1390. Add(' .debug_line 0 : { *(.debug_line) }');
  1391. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1392. Add(' .debug_str 0 : { *(.debug_str) }');
  1393. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1394. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1395. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1396. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1397. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1398. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1399. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1400. Add(' /* DWARF 3 */');
  1401. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1402. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1403. Add('}');
  1404. Add('_end = .;');
  1405. end;
  1406. {$endif RISCV32}
  1407. {$ifdef XTENSA}
  1408. with linkres do
  1409. begin
  1410. Add('/* Script for -z combreloc: combine and sort reloc sections */');
  1411. Add('/* Copyright (C) 2014-2018 Free Software Foundation, Inc.');
  1412. Add(' Copying and distribution of this script, with or without modification,');
  1413. Add(' are permitted in any medium without royalty provided the copyright');
  1414. Add(' notice and this notice are preserved. */');
  1415. Add('ENTRY(_start)');
  1416. 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");');
  1417. Add('SECTIONS');
  1418. Add('{');
  1419. Add(' /* Read-only sections, merged into text segment: */');
  1420. Add(' PROVIDE (__executable_start = 0x400000); . = 0x400000 + SIZEOF_HEADERS;');
  1421. Add(' .interp : { *(.interp) }');
  1422. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1423. Add(' .hash : { *(.hash) }');
  1424. Add(' .gnu.hash : { *(.gnu.hash) }');
  1425. Add(' .dynsym : { *(.dynsym) }');
  1426. Add(' .dynstr : { *(.dynstr) }');
  1427. Add(' .gnu.version : { *(.gnu.version) }');
  1428. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  1429. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  1430. Add(' .rela.dyn :');
  1431. Add(' {');
  1432. Add(' *(.rela.init)');
  1433. Add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
  1434. Add(' *(.rela.fini)');
  1435. Add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
  1436. Add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
  1437. Add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
  1438. Add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
  1439. Add(' *(.rela.ctors)');
  1440. Add(' *(.rela.dtors)');
  1441. Add(' *(.rela.got)');
  1442. Add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
  1443. Add(' }');
  1444. Add(' .rela.plt : { *(.rela.plt) }');
  1445. Add(' /* .plt* sections are embedded in .text */');
  1446. Add(' .text :');
  1447. Add(' {');
  1448. Add(' *(.got.plt* .plt*)');
  1449. Add(' KEEP (*(.init.literal))');
  1450. Add(' KEEP (*(SORT_NONE(.init)))');
  1451. Add(' *(.literal .text .stub .literal.* .text.* .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)');
  1452. Add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  1453. Add(' *(.gnu.warning)');
  1454. Add(' KEEP (*(.fini.literal))');
  1455. Add(' KEEP (*(SORT_NONE(.fini)))');
  1456. Add(' } =0');
  1457. Add(' PROVIDE (__etext = .);');
  1458. Add(' PROVIDE (_etext = .);');
  1459. Add(' PROVIDE (etext = .);');
  1460. Add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
  1461. Add(' .rodata1 : { *(.rodata1) }');
  1462. Add(' .got.loc : { *(.got.loc) }');
  1463. Add(' .xt_except_table : ONLY_IF_RO { KEEP (*(.xt_except_table .xt_except_table.* .gnu.linkonce.e.*)) }');
  1464. Add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
  1465. Add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
  1466. Add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }');
  1467. Add(' /* Adjust the address for the data segment. We want to adjust up to');
  1468. Add(' the same address within the page on the next page up. */');
  1469. Add(' . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));');
  1470. Add(' /* Exception handling */');
  1471. Add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
  1472. Add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
  1473. Add(' /* Thread Local Storage sections */');
  1474. Add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
  1475. Add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
  1476. Add(' .preinit_array :');
  1477. Add(' {');
  1478. Add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
  1479. Add(' KEEP (*(.preinit_array))');
  1480. Add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
  1481. Add(' }');
  1482. Add(' .init_array :');
  1483. Add(' {');
  1484. Add(' PROVIDE_HIDDEN (__init_array_start = .);');
  1485. Add(' KEEP (*(SORT(.init_array.*)))');
  1486. Add(' KEEP (*(.init_array))');
  1487. Add(' PROVIDE_HIDDEN (__init_array_end = .);');
  1488. Add(' }');
  1489. Add(' .fini_array :');
  1490. Add(' {');
  1491. Add(' PROVIDE_HIDDEN (__fini_array_start = .);');
  1492. Add(' KEEP (*(SORT(.fini_array.*)))');
  1493. Add(' KEEP (*(.fini_array))');
  1494. Add(' PROVIDE_HIDDEN (__fini_array_end = .);');
  1495. Add(' }');
  1496. Add(' .ctors :');
  1497. Add(' {');
  1498. Add(' /* gcc uses crtbegin.o to find the start of');
  1499. Add(' the constructors, so we make sure it is');
  1500. Add(' first. Because this is a wildcard, it');
  1501. Add(' doesn''t matter if the user does not');
  1502. Add(' actually link against crtbegin.o; the');
  1503. Add(' linker won''t look for a file to match a');
  1504. Add(' wildcard. The wildcard also means that it');
  1505. Add(' doesn''t matter which directory crtbegin.o');
  1506. Add(' is in. */');
  1507. Add(' KEEP (*crtbegin.o(.ctors))');
  1508. Add(' KEEP (*crtbegin?.o(.ctors))');
  1509. Add(' /* We don''t want to include the .ctor section from');
  1510. Add(' the crtend.o file until after the sorted ctors.');
  1511. Add(' The .ctor section from the crtend file contains the');
  1512. Add(' end of ctors marker and it must be last */');
  1513. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
  1514. Add(' KEEP (*(SORT(.ctors.*)))');
  1515. Add(' KEEP (*(.ctors))');
  1516. Add(' }');
  1517. Add(' .dtors :');
  1518. Add(' {');
  1519. Add(' KEEP (*crtbegin.o(.dtors))');
  1520. Add(' KEEP (*crtbegin?.o(.dtors))');
  1521. Add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
  1522. Add(' KEEP (*(SORT(.dtors.*)))');
  1523. Add(' KEEP (*(.dtors))');
  1524. Add(' }');
  1525. Add(' .jcr : { KEEP (*(.jcr)) }');
  1526. 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.*) }');
  1527. Add(' .xt_except_table : ONLY_IF_RW { KEEP (*(.xt_except_table .xt_except_table.* .gnu.linkonce.e.*)) }');
  1528. Add(' .dynamic : { *(.dynamic) }');
  1529. Add(' .got : { *(.got) }');
  1530. Add(' .data :');
  1531. Add(' {');
  1532. Add(' *(.data .data.* .gnu.linkonce.d.*)');
  1533. Add(' SORT(CONSTRUCTORS)');
  1534. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1535. Add(' }');
  1536. Add(' .data1 : { *(.data1) }');
  1537. Add(' .xt_except_desc :');
  1538. Add(' {');
  1539. Add(' *(.xt_except_desc .xt_except_desc.* .gnu.linkonce.h.*)');
  1540. Add(' *(.xt_except_desc_end)');
  1541. Add(' }');
  1542. Add(' .lit4 :');
  1543. Add(' {');
  1544. Add(' PROVIDE (_lit4_start = .);');
  1545. Add(' *(.lit4 .lit4.* .gnu.linkonce.lit4.*)');
  1546. Add(' PROVIDE (_lit4_end = .);');
  1547. Add(' }');
  1548. Add(' _edata = .; PROVIDE (edata = .);');
  1549. Add(' __bss_start = .;');
  1550. Add(' .bss :');
  1551. Add(' {');
  1552. Add(' *(.dynbss)');
  1553. Add(' *(.bss .bss.* .gnu.linkonce.b.*)');
  1554. Add(' *(COMMON)');
  1555. Add(' /* Align here to ensure that the .bss section occupies space up to');
  1556. Add(' _end. Align after .bss to ensure correct alignment even if the');
  1557. Add(' .bss section disappears because there are no input sections.');
  1558. Add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
  1559. Add(' pad the .data section. */');
  1560. Add(' . = ALIGN(. != 0 ? 32 / 8 : 1);');
  1561. Add(' }');
  1562. Add(' . = ALIGN(32 / 8);');
  1563. Add(' . = ALIGN(32 / 8);');
  1564. Add(' _end = .; PROVIDE (end = .);');
  1565. Add(' /* Stabs debugging sections. */');
  1566. Add(' .stab 0 : { *(.stab) }');
  1567. Add(' .stabstr 0 : { *(.stabstr) }');
  1568. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1569. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1570. Add(' .stab.index 0 : { *(.stab.index) }');
  1571. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1572. Add(' .comment 0 : { *(.comment) }');
  1573. Add(' /* DWARF debug sections.');
  1574. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1575. Add(' of the section so we begin them at 0. */');
  1576. Add(' /* DWARF 1 */');
  1577. Add(' .debug 0 : { *(.debug) }');
  1578. Add(' .line 0 : { *(.line) }');
  1579. Add(' /* GNU DWARF 1 extensions */');
  1580. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1581. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1582. Add(' /* DWARF 1.1 and DWARF 2 */');
  1583. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1584. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1585. Add(' /* DWARF 2 */');
  1586. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1587. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1588. Add(' .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }');
  1589. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1590. Add(' .debug_str 0 : { *(.debug_str) }');
  1591. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1592. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1593. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1594. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1595. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1596. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1597. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1598. Add(' /* DWARF 3 */');
  1599. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1600. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1601. Add(' /* DWARF Extension. */');
  1602. Add(' .debug_macro 0 : { *(.debug_macro) }');
  1603. Add(' .debug_addr 0 : { *(.debug_addr) }');
  1604. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1605. Add(' .xt.lit 0 : { KEEP (*(.xt.lit .xt.lit.* .gnu.linkonce.p.*)) }');
  1606. Add(' .xt.insn 0 : { KEEP (*(.xt.insn .gnu.linkonce.x.*)) }');
  1607. Add(' .xt.prop 0 : { KEEP (*(.xt.prop .xt.prop.* .gnu.linkonce.prop.*)) }');
  1608. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1609. Add('}');
  1610. end;
  1611. {$endif XTENSA}
  1612. { Write and Close response }
  1613. linkres.writetodisk;
  1614. linkres.free;
  1615. WriteResponseFile:=True;
  1616. end;
  1617. function TlinkerEmbedded.MakeExecutable:boolean;
  1618. var
  1619. binstr,
  1620. cmdstr,
  1621. mapstr: TCmdStr;
  1622. success : boolean;
  1623. StaticStr,
  1624. GCSectionsStr,
  1625. DynLinkStr,
  1626. StripStr,
  1627. FixedExeFileName: string;
  1628. begin
  1629. { for future use }
  1630. StaticStr:='';
  1631. StripStr:='';
  1632. mapstr:='';
  1633. DynLinkStr:='';
  1634. FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
  1635. GCSectionsStr:='--gc-sections';
  1636. //if not(cs_link_extern in current_settings.globalswitches) then
  1637. if not(cs_link_nolink in current_settings.globalswitches) then
  1638. Message1(exec_i_linking,current_module.exefilename);
  1639. if (cs_link_map in current_settings.globalswitches) then
  1640. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  1641. { Write used files and libraries }
  1642. WriteResponseFile();
  1643. { Call linker }
  1644. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1645. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1646. if not(cs_link_on_target in current_settings.globalswitches) then
  1647. begin
  1648. Replace(cmdstr,'$EXE',FixedExeFileName);
  1649. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  1650. Replace(cmdstr,'$STATIC',StaticStr);
  1651. Replace(cmdstr,'$STRIP',StripStr);
  1652. Replace(cmdstr,'$MAP',mapstr);
  1653. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1654. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1655. end
  1656. else
  1657. begin
  1658. Replace(cmdstr,'$EXE',FixedExeFileName);
  1659. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1660. Replace(cmdstr,'$STATIC',StaticStr);
  1661. Replace(cmdstr,'$STRIP',StripStr);
  1662. Replace(cmdstr,'$MAP',mapstr);
  1663. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1664. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1665. end;
  1666. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1667. { Remove ReponseFile }
  1668. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1669. DeleteFile(outputexedir+Info.ResName);
  1670. { Post process }
  1671. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1672. success:=PostProcessExecutable(FixedExeFileName,false);
  1673. if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded,system_xtensa_embedded]) then
  1674. begin
  1675. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  1676. FixedExeFileName+' '+
  1677. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
  1678. if success then
  1679. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  1680. FixedExeFileName+' '+
  1681. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  1682. if success and (target_info.system in systems_support_uf2) and (cs_generate_uf2 in current_settings.globalswitches) then
  1683. success := GenerateUF2(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),
  1684. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.uf2'))),
  1685. embedded_controllers[current_settings.controllertype].flashbase);
  1686. {$ifdef ARM}
  1687. if success and (current_settings.controllertype = ct_raspi2) then
  1688. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+ FixedExeFileName + ' kernel7.img',true,false);
  1689. {$endif ARM}
  1690. end;
  1691. MakeExecutable:=success; { otherwise a recursive call to link method }
  1692. end;
  1693. function TLinkerEmbedded.postprocessexecutable(const fn : string;isdll:boolean):boolean;
  1694. begin
  1695. Result:=PostProcessELFExecutable(fn,isdll);
  1696. end;
  1697. function TlinkerEmbedded.GenerateUF2(binFile,uf2File : string;baseAddress : longWord):boolean;
  1698. type
  1699. TFamilies= record
  1700. k : String;
  1701. v : longWord;
  1702. end;
  1703. tuf2Block = record
  1704. magicStart0,
  1705. magicStart1,
  1706. flags,
  1707. targetAddr,
  1708. payloadSize,
  1709. blockNo,
  1710. numBlocks,
  1711. familyid : longWord;
  1712. data : array[0..255] of byte;
  1713. padding : array[0..511-256-32-4] of byte;
  1714. magicEnd : longWord;
  1715. end;
  1716. const
  1717. Families : array of TFamilies = (
  1718. (k:'SAMD21'; v:$68ed2b88),
  1719. (k:'SAML21'; v:$1851780a),
  1720. (k:'SAMD51'; v:$55114460),
  1721. (k:'NRF52'; v:$1b57745f),
  1722. (k:'STM32F0';v:$647824b6),
  1723. (k:'STM32F1';v:$5ee21072),
  1724. (k:'STM32F2';v:$5d1a0a2e),
  1725. (k:'STM32F3';v:$6b846188),
  1726. (k:'STM32F4';v:$57755a57),
  1727. (k:'STM32F7';v:$53b80f00),
  1728. (k:'STM32G0';v:$300f5633),
  1729. (k:'STM32G4';v:$4c71240a),
  1730. (k:'STM32H7';v:$6db66082),
  1731. (k:'STM32L0';v:$202e3a91),
  1732. (k:'STM32L1';v:$1e1f432d),
  1733. (k:'STM32L4';v:$00ff6919),
  1734. (k:'STM32L5';v:$04240bdf),
  1735. (k:'STM32WB';v:$70d16653),
  1736. (k:'STM32WL';v:$21460ff0)
  1737. );
  1738. var
  1739. f,g : file;
  1740. uf2block : Tuf2Block;
  1741. totalRead,numRead : longWord;
  1742. familyId,i : longWord;
  1743. ExtraOptions : String;
  1744. begin
  1745. if pos('-Ttext=',Info.ExtraOptions) > 0 then
  1746. begin
  1747. ExtraOptions := copy(Info.ExtraOptions,pos('-Ttext=',Info.ExtraOptions)+7,length(Info.ExtraOptions));
  1748. for i := 1 to length(ExtraOptions) do
  1749. if pos(copy(ExtraOptions,i,1),'0123456789abcdefxABCDEFX') = 0 then
  1750. ExtraOptions := copy(ExtraOptions,1,i);
  1751. baseAddress := StrToIntDef(ExtraOptions,0);
  1752. end;
  1753. familyId := 0;
  1754. for i := 0 to length(Families)-1 do
  1755. begin
  1756. if pos(Families[i].k,embedded_controllers[current_settings.controllertype].controllerunitstr) = 1 then
  1757. familyId := Families[i].v;
  1758. end;
  1759. if (baseAddress and $07ffffff) <> 0 then
  1760. begin
  1761. totalRead := 0;
  1762. numRead := 0;
  1763. assign(f,binfile);
  1764. reset(f,1);
  1765. assign(g,uf2file);
  1766. rewrite(g,1);
  1767. repeat
  1768. fillchar(uf2block,sizeof(uf2block),0);
  1769. uf2block.magicStart0 := $0A324655; // "UF2\n"
  1770. uf2block.magicStart1 := $9E5D5157; // Randomly selected
  1771. if familyId = 0 then
  1772. uf2block.flags := 0
  1773. else
  1774. uf2block.flags := $2000;
  1775. uf2block.targetAddr := baseAddress + totalread;
  1776. uf2block.payloadSize := 256;
  1777. uf2block.blockNo := (totalRead div sizeOf(uf2block.data));
  1778. uf2block.numBlocks := (filesize(f) + 255) div 256;
  1779. uf2block.familyId := familyId;
  1780. uf2block.magicEnd := $0AB16F30; // Randomly selected
  1781. blockRead(f,uf2block.data,sizeof(uf2block.data),numRead);
  1782. blockwrite(g,uf2block,sizeof(uf2block));
  1783. inc(totalRead,numRead);
  1784. until (numRead=0) or (NumRead<>sizeOf(uf2block.data));
  1785. close(f);
  1786. close(g);
  1787. end;
  1788. Result := true;
  1789. end;
  1790. {*****************************************************************************
  1791. TlinkerEmbedded_SdccSdld
  1792. *****************************************************************************}
  1793. function TlinkerEmbedded_SdccSdld.WriteResponseFile: Boolean;
  1794. Var
  1795. linkres : TLinkRes;
  1796. //i : longint;
  1797. //HPath : TCmdStrListItem;
  1798. s{,s1,s2} : TCmdStr;
  1799. prtobj,
  1800. cprtobj : string[80];
  1801. linklibc : boolean;
  1802. //found1,
  1803. //found2 : boolean;
  1804. begin
  1805. WriteResponseFile:=False;
  1806. linklibc:=(SharedLibFiles.Find('c')<>nil);
  1807. prtobj:='prt0';
  1808. cprtobj:='cprt0';
  1809. if linklibc then
  1810. prtobj:=cprtobj;
  1811. { Open link.res file }
  1812. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  1813. { Write path to search libraries }
  1814. (* HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  1815. while assigned(HPath) do
  1816. begin
  1817. s:=HPath.Str;
  1818. if (cs_link_on_target in current_settings.globalswitches) then
  1819. s:=ScriptFixFileName(s);
  1820. LinkRes.Add('-L'+s);
  1821. HPath:=TCmdStrListItem(HPath.Next);
  1822. end;
  1823. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  1824. while assigned(HPath) do
  1825. begin
  1826. s:=HPath.Str;
  1827. if s<>'' then
  1828. LinkRes.Add('SEARCH_DIR("'+s+'")');
  1829. HPath:=TCmdStrListItem(HPath.Next);
  1830. end;
  1831. LinkRes.Add('INPUT (');
  1832. { add objectfiles, start with prt0 always }*)
  1833. //s:=FindObjectFile('prt0','',false);
  1834. if prtobj<>'' then
  1835. begin
  1836. s:=FindObjectFile(prtobj,'',false);
  1837. LinkRes.AddFileName(s);
  1838. end;
  1839. { try to add crti and crtbegin if linking to C }
  1840. if linklibc then
  1841. begin
  1842. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  1843. LinkRes.AddFileName(s);
  1844. if librarysearchpath.FindFile('crti.o',false,s) then
  1845. LinkRes.AddFileName(s);
  1846. end;
  1847. while not ObjectFiles.Empty do
  1848. begin
  1849. s:=ObjectFiles.GetFirst;
  1850. if s<>'' then
  1851. begin
  1852. { vlink doesn't use SEARCH_DIR for object files }
  1853. if not(cs_link_on_target in current_settings.globalswitches) then
  1854. s:=FindObjectFile(s,'',false);
  1855. LinkRes.AddFileName((maybequoted(s)));
  1856. end;
  1857. end;
  1858. { Write staticlibraries }
  1859. if not StaticLibFiles.Empty then
  1860. begin
  1861. { vlink doesn't need, and doesn't support GROUP }
  1862. { if (cs_link_on_target in current_settings.globalswitches) then
  1863. begin
  1864. LinkRes.Add(')');
  1865. LinkRes.Add('GROUP(');
  1866. end;}
  1867. while not StaticLibFiles.Empty do
  1868. begin
  1869. S:=StaticLibFiles.GetFirst;
  1870. LinkRes.Add('-l'+maybequoted(s));
  1871. end;
  1872. end;
  1873. (* if (cs_link_on_target in current_settings.globalswitches) then
  1874. begin
  1875. LinkRes.Add(')');
  1876. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  1877. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  1878. linklibc:=false;
  1879. while not SharedLibFiles.Empty do
  1880. begin
  1881. S:=SharedLibFiles.GetFirst;
  1882. if s<>'c' then
  1883. begin
  1884. i:=Pos(target_info.sharedlibext,S);
  1885. if i>0 then
  1886. Delete(S,i,255);
  1887. LinkRes.Add('-l'+s);
  1888. end
  1889. else
  1890. begin
  1891. LinkRes.Add('-l'+s);
  1892. linklibc:=true;
  1893. end;
  1894. end;
  1895. { be sure that libc&libgcc is the last lib }
  1896. if linklibc then
  1897. begin
  1898. LinkRes.Add('-lc');
  1899. LinkRes.Add('-lgcc');
  1900. end;
  1901. end
  1902. else
  1903. begin
  1904. while not SharedLibFiles.Empty do
  1905. begin
  1906. S:=SharedLibFiles.GetFirst;
  1907. LinkRes.Add('lib'+s+target_info.staticlibext);
  1908. end;
  1909. LinkRes.Add(')');
  1910. end;*)
  1911. { objects which must be at the end }
  1912. (*if linklibc then
  1913. begin
  1914. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  1915. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  1916. if found1 or found2 then
  1917. begin
  1918. LinkRes.Add('INPUT(');
  1919. if found1 then
  1920. LinkRes.AddFileName(s1);
  1921. if found2 then
  1922. LinkRes.AddFileName(s2);
  1923. LinkRes.Add(')');
  1924. end;
  1925. end;*)
  1926. { Write and Close response }
  1927. linkres.writetodisk;
  1928. linkres.free;
  1929. WriteResponseFile:=True;
  1930. end;
  1931. procedure TlinkerEmbedded_SdccSdld.SetDefaultInfo;
  1932. const
  1933. {$if defined(Z80)}
  1934. ExeName='sdldz80';
  1935. {$else}
  1936. ExeName='sdld';
  1937. {$endif}
  1938. begin
  1939. with Info do
  1940. begin
  1941. ExeCmd[1]:=ExeName+' -n $OPT -i $MAP $EXE -f $RES'
  1942. //-g '+platform_select+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE -T $RES';
  1943. end;
  1944. end;
  1945. function TlinkerEmbedded_SdccSdld.MakeExecutable: boolean;
  1946. var
  1947. binstr,
  1948. cmdstr,
  1949. mapstr: TCmdStr;
  1950. success : boolean;
  1951. StaticStr,
  1952. // GCSectionsStr,
  1953. DynLinkStr,
  1954. StripStr,
  1955. FixedExeFileName: string;
  1956. begin
  1957. { for future use }
  1958. StaticStr:='';
  1959. StripStr:='';
  1960. mapstr:='';
  1961. DynLinkStr:='';
  1962. FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.ihx')));
  1963. (* GCSectionsStr:='--gc-sections';
  1964. //if not(cs_link_extern in current_settings.globalswitches) then
  1965. if not(cs_link_nolink in current_settings.globalswitches) then
  1966. Message1(exec_i_linking,current_module.exefilename);*)
  1967. if (cs_link_map in current_settings.globalswitches) then
  1968. mapstr:='-mw';
  1969. { Write used files and libraries }
  1970. WriteResponseFile();
  1971. { Call linker }
  1972. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1973. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1974. if not(cs_link_on_target in current_settings.globalswitches) then
  1975. begin
  1976. Replace(cmdstr,'$EXE',FixedExeFileName);
  1977. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  1978. Replace(cmdstr,'$STATIC',StaticStr);
  1979. Replace(cmdstr,'$STRIP',StripStr);
  1980. Replace(cmdstr,'$MAP',mapstr);
  1981. // Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1982. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1983. end
  1984. else
  1985. begin
  1986. Replace(cmdstr,'$EXE',FixedExeFileName);
  1987. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1988. Replace(cmdstr,'$STATIC',StaticStr);
  1989. Replace(cmdstr,'$STRIP',StripStr);
  1990. Replace(cmdstr,'$MAP',mapstr);
  1991. // Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1992. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1993. end;
  1994. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1995. { Remove ReponseFile }
  1996. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1997. DeleteFile(outputexedir+Info.ResName);
  1998. (* { Post process }
  1999. if success and not(cs_link_nolink in current_settings.globalswitches) then
  2000. success:=PostProcessExecutable(FixedExeFileName,false);
  2001. if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded,system_xtensa_embedded]) then
  2002. begin
  2003. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  2004. FixedExeFileName+' '+
  2005. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
  2006. if success then
  2007. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  2008. FixedExeFileName+' '+
  2009. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  2010. end;*)
  2011. MakeExecutable:=success; { otherwise a recursive call to link method }
  2012. end;
  2013. {*****************************************************************************
  2014. TlinkerEmbedded_Wasm
  2015. *****************************************************************************}
  2016. constructor TLinkerEmbedded_Wasm.Create;
  2017. begin
  2018. inherited Create;
  2019. end;
  2020. procedure TLinkerEmbedded_Wasm.SetDefaultInfo;
  2021. begin
  2022. Info.DllCmd[1] := 'wasm-ld $SONAME $GCSECTIONS -o $EXE';
  2023. //Info.DllCmd[2] := 'wasmtool --exportrename $INPUT $EXE';
  2024. end;
  2025. function TLinkerEmbedded_Wasm.MakeSharedLibrary: boolean;
  2026. var
  2027. GCSectionsStr : ansistring;
  2028. binstr, cmdstr : Tcmdstr;
  2029. InitStr,
  2030. FiniStr,
  2031. SoNameStr : string[80];
  2032. mapstr,ltostr : TCmdStr;
  2033. success : Boolean;
  2034. tmp : TCmdStrListItem;
  2035. tempFileName : ansistring;
  2036. begin
  2037. //Result := true;
  2038. //Result:=inherited MakeSharedLibrary;
  2039. if (cs_link_smart in current_settings.globalswitches) and
  2040. create_smartlink_sections then
  2041. GCSectionsStr:='--gc-sections'
  2042. else
  2043. GCSectionsStr:='';
  2044. SoNameStr:='';
  2045. SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
  2046. Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  2047. tmp := TCmdStrListItem(ObjectFiles.First);
  2048. while Assigned(tmp) do begin
  2049. cmdstr := tmp.Str+ ' ' + cmdstr;
  2050. tmp := TCmdStrListItem(tmp.Next);
  2051. end;
  2052. if HasExports then
  2053. cmdstr := cmdstr + ' --export-dynamic'; //' --export-dynamic';
  2054. cmdstr := cmdstr + ' --no-entry --allow-undefined';
  2055. if (cs_link_strip in current_settings.globalswitches) then
  2056. begin
  2057. { only remove non global symbols and debugging info for a library }
  2058. cmdstr := cmdstr + ' --strip-all';
  2059. end;
  2060. //Replace(cmdstr,'$OPT',Info.ExtraOptions);
  2061. //Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
  2062. //Replace(cmdstr,'$INIT',InitStr);
  2063. //Replace(cmdstr,'$FINI',FiniStr);
  2064. Replace(cmdstr,'$SONAME',SoNameStr);
  2065. //Replace(cmdstr,'$MAP',mapstr);
  2066. //Replace(cmdstr,'$LTO',ltostr);
  2067. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  2068. writeln(utilsprefix+binstr,' ',cmdstr);
  2069. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
  2070. //SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
  2071. //Replace(cmdstr,'$INPUT',current_module.objfilename );
  2072. //Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
  2073. //DoExec(FindUtil(utilsprefix+binstr),cmdstr,false,false);
  2074. MakeSharedLibrary:=success;
  2075. end;
  2076. {*****************************************************************************
  2077. Initialize
  2078. *****************************************************************************}
  2079. initialization
  2080. {$ifdef aarch64}
  2081. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2082. RegisterTarget(system_aarch64_embedded_info);
  2083. {$endif aarch64}
  2084. {$ifdef arm}
  2085. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2086. RegisterTarget(system_arm_embedded_info);
  2087. {$endif arm}
  2088. {$ifdef avr}
  2089. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2090. RegisterTarget(system_avr_embedded_info);
  2091. {$endif avr}
  2092. {$ifdef i386}
  2093. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2094. RegisterTarget(system_i386_embedded_info);
  2095. {$endif i386}
  2096. {$ifdef x86_64}
  2097. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2098. RegisterTarget(system_x86_64_embedded_info);
  2099. {$endif x86_64}
  2100. {$ifdef i8086}
  2101. { no need to register linker ld_embedded, because i8086_embedded uses the
  2102. regular msdos linker. In case a flat binary, relocated for a specific
  2103. segment address is needed (e.g. for a BIOS or a real mode bootloader), it
  2104. can be produced post-compilation with exe2bin or a similar tool. }
  2105. RegisterTarget(system_i8086_embedded_info);
  2106. {$endif i8086}
  2107. {$ifdef mipsel}
  2108. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2109. RegisterTarget(system_mipsel_embedded_info);
  2110. {$endif mipsel}
  2111. {$ifdef m68k}
  2112. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2113. RegisterTarget(system_m68k_embedded_info);
  2114. {$endif m68k}
  2115. {$ifdef riscv32}
  2116. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2117. RegisterTarget(system_riscv32_embedded_info);
  2118. {$endif riscv32}
  2119. {$ifdef riscv64}
  2120. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2121. RegisterTarget(system_riscv64_embedded_info);
  2122. {$endif riscv64}
  2123. {$ifdef xtensa}
  2124. RegisterLinker(ld_embedded,TLinkerEmbedded);
  2125. RegisterTarget(system_xtensa_embedded_info);
  2126. {$endif xtensa}
  2127. {$ifdef z80}
  2128. RegisterLinker(ld_embedded,TlinkerEmbedded_SdccSdld);
  2129. RegisterTarget(system_z80_embedded_info);
  2130. {$endif z80}
  2131. {$ifdef wasm32}
  2132. RegisterTarget(system_wasm32_embedded_info);
  2133. RegisterImport(system_wasm32_embedded, timportlibwasi);
  2134. RegisterExport(system_wasm32_embedded, texportlibwasi);
  2135. RegisterLinker(ld_embedded, TLinkerEmbedded_Wasm);
  2136. {$endif wasm32}
  2137. end.