t_embed.pas 75 KB

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