t_embed.pas 78 KB

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