t_embed.pas 78 KB

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