t_embed.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. {
  2. This unit implements support import,export,link routines
  3. for the (arm) GameBoy Advance target
  4. Copyright (c) 2001-2002 by Peter Vreman
  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,script,fmodule,i_embed,link,
  26. cpuinfo;
  27. type
  28. TlinkerEmbedded=class(texternallinker)
  29. private
  30. Function WriteResponseFile: Boolean;
  31. public
  32. constructor Create; override;
  33. procedure SetDefaultInfo; override;
  34. function MakeExecutable:boolean; override;
  35. end;
  36. {*****************************************************************************
  37. TlinkerEmbedded
  38. *****************************************************************************}
  39. Constructor TlinkerEmbedded.Create;
  40. begin
  41. Inherited Create;
  42. SharedLibFiles.doubles:=true;
  43. StaticLibFiles.doubles:=true;
  44. end;
  45. procedure TlinkerEmbedded.SetDefaultInfo;
  46. begin
  47. with Info do
  48. begin
  49. ExeCmd[1]:='ld -g $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE -T $RES';
  50. end;
  51. end;
  52. Function TlinkerEmbedded.WriteResponseFile: Boolean;
  53. Var
  54. linkres : TLinkRes;
  55. i : longint;
  56. HPath : TCmdStrListItem;
  57. s,s1,s2 : TCmdStr;
  58. prtobj,
  59. cprtobj : string[80];
  60. linklibc : boolean;
  61. found1,
  62. found2 : boolean;
  63. LinkStr : string;
  64. begin
  65. WriteResponseFile:=False;
  66. linklibc:=(SharedLibFiles.Find('c')<>nil);
  67. {$if defined(ARM) or defined(i386) or defined(AVR)}
  68. prtobj:='';
  69. {$else}
  70. prtobj:='prt0';
  71. {$endif}
  72. cprtobj:='cprt0';
  73. if linklibc then
  74. prtobj:=cprtobj;
  75. { Open link.res file }
  76. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  77. { Write path to search libraries }
  78. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  79. while assigned(HPath) do
  80. begin
  81. s:=HPath.Str;
  82. if (cs_link_on_target in current_settings.globalswitches) then
  83. s:=ScriptFixFileName(s);
  84. LinkRes.Add('-L'+s);
  85. HPath:=TCmdStrListItem(HPath.Next);
  86. end;
  87. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  88. while assigned(HPath) do
  89. begin
  90. s:=HPath.Str;
  91. if s<>'' then
  92. LinkRes.Add('SEARCH_DIR('+(maybequoted(s))+')');
  93. HPath:=TCmdStrListItem(HPath.Next);
  94. end;
  95. LinkRes.Add('INPUT (');
  96. { add objectfiles, start with prt0 always }
  97. //s:=FindObjectFile('prt0','',false);
  98. if prtobj<>'' then
  99. begin
  100. s:=FindObjectFile(prtobj,'',false);
  101. LinkRes.AddFileName(s);
  102. end;
  103. { try to add crti and crtbegin if linking to C }
  104. if linklibc then
  105. begin
  106. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  107. LinkRes.AddFileName(s);
  108. if librarysearchpath.FindFile('crti.o',false,s) then
  109. LinkRes.AddFileName(s);
  110. end;
  111. while not ObjectFiles.Empty do
  112. begin
  113. s:=ObjectFiles.GetFirst;
  114. if s<>'' then
  115. begin
  116. { vlink doesn't use SEARCH_DIR for object files }
  117. if not(cs_link_on_target in current_settings.globalswitches) then
  118. s:=FindObjectFile(s,'',false);
  119. LinkRes.AddFileName((maybequoted(s)));
  120. end;
  121. end;
  122. { Write staticlibraries }
  123. if not StaticLibFiles.Empty then
  124. begin
  125. { vlink doesn't need, and doesn't support GROUP }
  126. if (cs_link_on_target in current_settings.globalswitches) then
  127. begin
  128. LinkRes.Add(')');
  129. LinkRes.Add('GROUP(');
  130. end;
  131. while not StaticLibFiles.Empty do
  132. begin
  133. S:=StaticLibFiles.GetFirst;
  134. LinkRes.AddFileName((maybequoted(s)));
  135. end;
  136. end;
  137. if (cs_link_on_target in current_settings.globalswitches) then
  138. begin
  139. LinkRes.Add(')');
  140. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  141. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  142. linklibc:=false;
  143. while not SharedLibFiles.Empty do
  144. begin
  145. S:=SharedLibFiles.GetFirst;
  146. if s<>'c' then
  147. begin
  148. i:=Pos(target_info.sharedlibext,S);
  149. if i>0 then
  150. Delete(S,i,255);
  151. LinkRes.Add('-l'+s);
  152. end
  153. else
  154. begin
  155. LinkRes.Add('-l'+s);
  156. linklibc:=true;
  157. end;
  158. end;
  159. { be sure that libc&libgcc is the last lib }
  160. if linklibc then
  161. begin
  162. LinkRes.Add('-lc');
  163. LinkRes.Add('-lgcc');
  164. end;
  165. end
  166. else
  167. begin
  168. while not SharedLibFiles.Empty do
  169. begin
  170. S:=SharedLibFiles.GetFirst;
  171. LinkRes.Add('lib'+s+target_info.staticlibext);
  172. end;
  173. LinkRes.Add(')');
  174. end;
  175. { objects which must be at the end }
  176. if linklibc then
  177. begin
  178. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  179. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  180. if found1 or found2 then
  181. begin
  182. LinkRes.Add('INPUT(');
  183. if found1 then
  184. LinkRes.AddFileName(s1);
  185. if found2 then
  186. LinkRes.AddFileName(s2);
  187. LinkRes.Add(')');
  188. end;
  189. end;
  190. {$ifdef ARM}
  191. case current_settings.controllertype of
  192. ct_none:
  193. begin
  194. end;
  195. ct_lpc2114,
  196. ct_lpc2124,
  197. ct_lpc2194,
  198. ct_at91sam7s256,
  199. ct_at91sam7se256,
  200. ct_at91sam7x256,
  201. ct_at91sam7xc256,
  202. ct_stm32f103rb,
  203. ct_stm32f103re,
  204. { TI - 64 K Flash, 16 K SRAM Devices }
  205. ct_lm3s1110,
  206. ct_lm3s1133,
  207. ct_lm3s1138,
  208. ct_lm3s1150,
  209. ct_lm3s1162,
  210. ct_lm3s1165,
  211. ct_lm3s1166,
  212. ct_lm3s2110,
  213. ct_lm3s2139,
  214. ct_lm3s6100,
  215. ct_lm3s6110,
  216. { TI 128 K Flash, 32 K SRAM devices - Fury Class }
  217. ct_lm3s1601,
  218. ct_lm3s1608,
  219. ct_lm3s1620,
  220. ct_lm3s1635,
  221. ct_lm3s1636,
  222. ct_lm3s1637,
  223. ct_lm3s1651,
  224. ct_lm3s2601,
  225. ct_lm3s2608,
  226. ct_lm3s2620,
  227. ct_lm3s2637,
  228. ct_lm3s2651,
  229. ct_lm3s6610,
  230. ct_lm3s6611,
  231. ct_lm3s6618,
  232. ct_lm3s6633,
  233. ct_lm3s6637,
  234. ct_lm3s8630,
  235. { TI 256 K Flase, 32 K SRAM devices - Fury Class }
  236. ct_lm3s1911,
  237. ct_lm3s1918,
  238. ct_lm3s1937,
  239. ct_lm3s1958,
  240. ct_lm3s1960,
  241. ct_lm3s1968,
  242. ct_lm3s1969,
  243. ct_lm3s2911,
  244. ct_lm3s2918,
  245. ct_lm3s2919,
  246. ct_lm3s2939,
  247. ct_lm3s2948,
  248. ct_lm3s2950,
  249. ct_lm3s2965,
  250. ct_lm3s6911,
  251. ct_lm3s6918,
  252. ct_lm3s6938,
  253. ct_lm3s6950,
  254. ct_lm3s6952,
  255. ct_lm3s6965,
  256. ct_lm3s8930,
  257. ct_lm3s8933,
  258. ct_lm3s8938,
  259. ct_lm3s8962,
  260. ct_lm3s8970,
  261. ct_lm3s8971,
  262. { TI - Tempest Tempest - 256 K Flash, 64 K SRAM }
  263. ct_lm3s5951,
  264. ct_lm3s5956,
  265. ct_lm3s1b21,
  266. ct_lm3s2b93,
  267. ct_lm3s5b91,
  268. ct_lm3s9b81,
  269. ct_lm3s9b90,
  270. ct_lm3s9b92,
  271. ct_lm3s9b95,
  272. ct_lm3s9b96,
  273. ct_thumb2bare:
  274. begin
  275. with embedded_controllers[current_settings.controllertype] do
  276. with linkres do
  277. begin
  278. Add('ENTRY(_START)');
  279. Add('MEMORY');
  280. Add('{');
  281. LinkStr := ' flash : ORIGIN = 0x' + IntToHex(flashbase,8)
  282. + ', LENGTH = ' + IntToStr(flashsize div 1024)+'K';
  283. Add(LinkStr);
  284. LinkStr := ' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  285. + ', LENGTH = ' + IntToStr(sramsize div 1024)+'K';
  286. Add(LinkStr);
  287. Add('}');
  288. Add('_stack_top = 0x' + IntToHex(sramsize+srambase-4,8) + ';');
  289. end;
  290. end
  291. else
  292. if not (cs_link_nolink in current_settings.globalswitches) then
  293. internalerror(200902011);
  294. end;
  295. with linkres do
  296. begin
  297. Add('SECTIONS');
  298. Add('{');
  299. Add(' .text :');
  300. Add(' {');
  301. Add(' KEEP(*(.init, .init.*))');
  302. Add(' *(.text, .text.*)');
  303. Add(' *(.strings)');
  304. Add(' *(.rodata, .rodata.*)');
  305. Add(' *(.comment)');
  306. Add(' _etext = .;');
  307. Add(' } >flash');
  308. Add(' .data :');
  309. Add(' {');
  310. Add(' _data = .;');
  311. Add(' *(.data, .data.*)');
  312. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  313. Add(' _edata = .;');
  314. Add(' } >ram AT >flash');
  315. Add(' .bss :');
  316. Add(' {');
  317. Add(' _bss_start = .;');
  318. Add(' *(.bss, .bss.*)');
  319. Add(' *(COMMON)');
  320. Add(' } >ram');
  321. Add('. = ALIGN(4);');
  322. Add('_bss_end = . ;');
  323. Add('}');
  324. Add('_end = .;');
  325. end;
  326. {$endif ARM}
  327. {$ifdef i386}
  328. with linkres do
  329. begin
  330. Add('ENTRY(_START)');
  331. Add('SECTIONS');
  332. Add('{');
  333. Add(' . = 0x100000;');
  334. Add(' .text ALIGN (0x1000) :');
  335. Add(' {');
  336. Add(' KEEP(*(.init, .init.*))');
  337. Add(' *(.text, .text.*)');
  338. Add(' *(.strings)');
  339. Add(' *(.rodata, .rodata.*)');
  340. Add(' *(.comment)');
  341. Add(' _etext = .;');
  342. Add(' }');
  343. Add(' .data ALIGN (0x1000) :');
  344. Add(' {');
  345. Add(' _data = .;');
  346. Add(' *(.data, .data.*)');
  347. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  348. Add(' _edata = .;');
  349. Add(' }');
  350. Add(' . = ALIGN(4);');
  351. Add(' .bss :');
  352. Add(' {');
  353. Add(' _bss_start = .;');
  354. Add(' *(.bss, .bss.*)');
  355. Add(' *(COMMON)');
  356. Add(' }');
  357. Add('_bss_end = . ;');
  358. Add('}');
  359. Add('_end = .;');
  360. end;
  361. {$endif i386}
  362. {$ifdef AVR}
  363. with linkres do
  364. begin
  365. { linker script from ld 2.19 }
  366. Add('ENTRY(_START)');
  367. Add('OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")');
  368. Add('OUTPUT_ARCH(avr:2)');
  369. Add('MEMORY');
  370. Add('{');
  371. Add(' text (rx) : ORIGIN = 0, LENGTH = 8K');
  372. Add(' data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0');
  373. Add(' eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K');
  374. Add(' fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K');
  375. Add(' lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K');
  376. Add(' signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K');
  377. Add('}');
  378. Add('SECTIONS');
  379. Add('{');
  380. Add(' /* Read-only sections, merged into text segment: */');
  381. Add(' .hash : { *(.hash) }');
  382. Add(' .dynsym : { *(.dynsym) }');
  383. Add(' .dynstr : { *(.dynstr) }');
  384. Add(' .gnu.version : { *(.gnu.version) }');
  385. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  386. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  387. Add(' .rel.init : { *(.rel.init) }');
  388. Add(' .rela.init : { *(.rela.init) }');
  389. Add(' .rel.text :');
  390. Add(' {');
  391. Add(' *(.rel.text)');
  392. Add(' *(.rel.text.*)');
  393. Add(' *(.rel.gnu.linkonce.t*)');
  394. Add(' }');
  395. Add(' .rela.text :');
  396. Add(' {');
  397. Add(' *(.rela.text)');
  398. Add(' *(.rela.text.*)');
  399. Add(' *(.rela.gnu.linkonce.t*)');
  400. Add(' }');
  401. Add(' .rel.fini : { *(.rel.fini) }');
  402. Add(' .rela.fini : { *(.rela.fini) }');
  403. Add(' .rel.rodata :');
  404. Add(' {');
  405. Add(' *(.rel.rodata)');
  406. Add(' *(.rel.rodata.*)');
  407. Add(' *(.rel.gnu.linkonce.r*)');
  408. Add(' }');
  409. Add(' .rela.rodata :');
  410. Add(' {');
  411. Add(' *(.rela.rodata)');
  412. Add(' *(.rela.rodata.*)');
  413. Add(' *(.rela.gnu.linkonce.r*)');
  414. Add(' }');
  415. Add(' .rel.data :');
  416. Add(' {');
  417. Add(' *(.rel.data)');
  418. Add(' *(.rel.data.*)');
  419. Add(' *(.rel.gnu.linkonce.d*)');
  420. Add(' }');
  421. Add(' .rela.data :');
  422. Add(' {');
  423. Add(' *(.rela.data)');
  424. Add(' *(.rela.data.*)');
  425. Add(' *(.rela.gnu.linkonce.d*)');
  426. Add(' }');
  427. Add(' .rel.ctors : { *(.rel.ctors) }');
  428. Add(' .rela.ctors : { *(.rela.ctors) }');
  429. Add(' .rel.dtors : { *(.rel.dtors) }');
  430. Add(' .rela.dtors : { *(.rela.dtors) }');
  431. Add(' .rel.got : { *(.rel.got) }');
  432. Add(' .rela.got : { *(.rela.got) }');
  433. Add(' .rel.bss : { *(.rel.bss) }');
  434. Add(' .rela.bss : { *(.rela.bss) }');
  435. Add(' .rel.plt : { *(.rel.plt) }');
  436. Add(' .rela.plt : { *(.rela.plt) }');
  437. Add(' /* Internal text space or external memory. */');
  438. Add(' .text :');
  439. Add(' {');
  440. Add(' *(.vectors)');
  441. Add(' KEEP(*(.vectors))');
  442. Add(' /* For data that needs to reside in the lower 64k of progmem. */');
  443. Add(' *(.progmem.gcc*)');
  444. Add(' *(.progmem*)');
  445. Add(' . = ALIGN(2);');
  446. Add(' __trampolines_start = . ;');
  447. Add(' /* The jump trampolines for the 16-bit limited relocs will reside here. */');
  448. Add(' *(.trampolines)');
  449. Add(' *(.trampolines*)');
  450. Add(' __trampolines_end = . ;');
  451. Add(' /* For future tablejump instruction arrays for 3 byte pc devices.');
  452. Add(' We don''t relax jump/call instructions within these sections. */');
  453. Add(' *(.jumptables)');
  454. Add(' *(.jumptables*)');
  455. Add(' /* For code that needs to reside in the lower 128k progmem. */');
  456. Add(' *(.lowtext)');
  457. Add(' *(.lowtext*)');
  458. Add(' __ctors_start = . ;');
  459. Add(' *(.ctors)');
  460. Add(' __ctors_end = . ;');
  461. Add(' __dtors_start = . ;');
  462. Add(' *(.dtors)');
  463. Add(' __dtors_end = . ;');
  464. Add(' KEEP(SORT(*)(.ctors))');
  465. Add(' KEEP(SORT(*)(.dtors))');
  466. Add(' /* From this point on, we don''t bother about wether the insns are');
  467. Add(' below or above the 16 bits boundary. */');
  468. Add(' *(.init0) /* Start here after reset. */');
  469. Add(' KEEP (*(.init0))');
  470. Add(' *(.init1)');
  471. Add(' KEEP (*(.init1))');
  472. Add(' *(.init2) /* Clear __zero_reg__, set up stack pointer. */');
  473. Add(' KEEP (*(.init2))');
  474. Add(' *(.init3)');
  475. Add(' KEEP (*(.init3))');
  476. Add(' *(.init4) /* Initialize data and BSS. */');
  477. Add(' KEEP (*(.init4))');
  478. Add(' *(.init5)');
  479. Add(' KEEP (*(.init5))');
  480. Add(' *(.init6) /* C++ constructors. */');
  481. Add(' KEEP (*(.init6))');
  482. Add(' *(.init7)');
  483. Add(' KEEP (*(.init7))');
  484. Add(' *(.init8)');
  485. Add(' KEEP (*(.init8))');
  486. Add(' *(.init9) /* Call main(). */');
  487. Add(' KEEP (*(.init9))');
  488. Add(' *(.text)');
  489. Add(' . = ALIGN(2);');
  490. Add(' *(.text.*)');
  491. Add(' . = ALIGN(2);');
  492. Add(' *(.fini9) /* _exit() starts here. */');
  493. Add(' KEEP (*(.fini9))');
  494. Add(' *(.fini8)');
  495. Add(' KEEP (*(.fini8))');
  496. Add(' *(.fini7)');
  497. Add(' KEEP (*(.fini7))');
  498. Add(' *(.fini6) /* C++ destructors. */');
  499. Add(' KEEP (*(.fini6))');
  500. Add(' *(.fini5)');
  501. Add(' KEEP (*(.fini5))');
  502. Add(' *(.fini4)');
  503. Add(' KEEP (*(.fini4))');
  504. Add(' *(.fini3)');
  505. Add(' KEEP (*(.fini3))');
  506. Add(' *(.fini2)');
  507. Add(' KEEP (*(.fini2))');
  508. Add(' *(.fini1)');
  509. Add(' KEEP (*(.fini1))');
  510. Add(' *(.fini0) /* Infinite loop after program termination. */');
  511. Add(' KEEP (*(.fini0))');
  512. Add(' _etext = . ;');
  513. Add(' } > text');
  514. Add(' .data : AT (ADDR (.text) + SIZEOF (.text))');
  515. Add(' {');
  516. Add(' PROVIDE (__data_start = .) ;');
  517. Add(' *(.data)');
  518. Add(' *(.data*)');
  519. Add(' *(.rodata) /* We need to include .rodata here if gcc is used */');
  520. Add(' *(.rodata*) /* with -fdata-sections. */');
  521. Add(' *(.gnu.linkonce.d*)');
  522. Add(' . = ALIGN(2);');
  523. Add(' _edata = . ;');
  524. Add(' PROVIDE (__data_end = .) ;');
  525. Add(' } > data');
  526. Add(' .bss : AT (ADDR (.bss))');
  527. Add(' {');
  528. Add(' PROVIDE (__bss_start = .) ;');
  529. Add(' *(.bss)');
  530. Add(' *(.bss*)');
  531. Add(' *(COMMON)');
  532. Add(' PROVIDE (__bss_end = .) ;');
  533. Add(' } > data');
  534. Add(' __data_load_start = LOADADDR(.data);');
  535. Add(' __data_load_end = __data_load_start + SIZEOF(.data);');
  536. Add(' /* Global data not cleared after reset. */');
  537. Add(' .noinit :');
  538. Add(' {');
  539. Add(' PROVIDE (__noinit_start = .) ;');
  540. Add(' *(.noinit*)');
  541. Add(' PROVIDE (__noinit_end = .) ;');
  542. Add(' _end = . ;');
  543. Add(' PROVIDE (__heap_start = .) ;');
  544. Add(' } > data');
  545. Add(' .eeprom :');
  546. Add(' {');
  547. Add(' *(.eeprom*)');
  548. Add(' __eeprom_end = . ;');
  549. Add(' } > eeprom');
  550. Add(' .fuse :');
  551. Add(' {');
  552. Add(' KEEP(*(.fuse))');
  553. Add(' KEEP(*(.lfuse))');
  554. Add(' KEEP(*(.hfuse))');
  555. Add(' KEEP(*(.efuse))');
  556. Add(' } > fuse');
  557. Add(' .lock :');
  558. Add(' {');
  559. Add(' KEEP(*(.lock*))');
  560. Add(' } > lock');
  561. Add(' .signature :');
  562. Add(' {');
  563. Add(' KEEP(*(.signature*))');
  564. Add(' } > signature');
  565. Add(' /* Stabs debugging sections. */');
  566. Add(' .stab 0 : { *(.stab) }');
  567. Add(' .stabstr 0 : { *(.stabstr) }');
  568. Add(' .stab.excl 0 : { *(.stab.excl) }');
  569. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  570. Add(' .stab.index 0 : { *(.stab.index) }');
  571. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  572. Add(' .comment 0 : { *(.comment) }');
  573. Add(' /* DWARF debug sections.');
  574. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  575. Add(' of the section so we begin them at 0. */');
  576. Add(' /* DWARF 1 */');
  577. Add(' .debug 0 : { *(.debug) }');
  578. Add(' .line 0 : { *(.line) }');
  579. Add(' /* GNU DWARF 1 extensions */');
  580. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  581. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  582. Add(' /* DWARF 1.1 and DWARF 2 */');
  583. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  584. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  585. Add(' /* DWARF 2 */');
  586. Add(' .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }');
  587. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  588. Add(' .debug_line 0 : { *(.debug_line) }');
  589. Add(' .debug_frame 0 : { *(.debug_frame) }');
  590. Add(' .debug_str 0 : { *(.debug_str) }');
  591. Add(' .debug_loc 0 : { *(.debug_loc) }');
  592. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  593. Add('}');
  594. { last address of ram on an atmega128 }
  595. Add('_stack_top = 0x0fff;');
  596. end;
  597. {$endif AVR}
  598. { Write and Close response }
  599. linkres.writetodisk;
  600. linkres.free;
  601. WriteResponseFile:=True;
  602. end;
  603. function TlinkerEmbedded.MakeExecutable:boolean;
  604. var
  605. binstr,
  606. cmdstr : TCmdStr;
  607. success : boolean;
  608. StaticStr,
  609. GCSectionsStr,
  610. DynLinkStr,
  611. StripStr: string;
  612. begin
  613. { for future use }
  614. StaticStr:='';
  615. StripStr:='';
  616. DynLinkStr:='';
  617. GCSectionsStr:='--gc-sections';
  618. //if not(cs_link_extern in current_settings.globalswitches) then
  619. if not(cs_link_nolink in current_settings.globalswitches) then
  620. Message1(exec_i_linking,current_module.exefilename^);
  621. { Write used files and libraries }
  622. WriteResponseFile();
  623. { Call linker }
  624. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  625. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  626. if not(cs_link_on_target in current_settings.globalswitches) then
  627. begin
  628. Replace(cmdstr,'$EXE',(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename^,'.elf')))));
  629. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  630. Replace(cmdstr,'$STATIC',StaticStr);
  631. Replace(cmdstr,'$STRIP',StripStr);
  632. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  633. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  634. end
  635. else
  636. begin
  637. Replace(cmdstr,'$EXE',maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename^,'.elf'))));
  638. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  639. Replace(cmdstr,'$STATIC',StaticStr);
  640. Replace(cmdstr,'$STRIP',StripStr);
  641. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  642. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  643. end;
  644. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  645. { Remove ReponseFile }
  646. if success and not(cs_link_nolink in current_settings.globalswitches) then
  647. DeleteFile(outputexedir+Info.ResName);
  648. { Post process }
  649. if success and (target_info.system in [system_arm_embedded,system_avr_embedded]) then
  650. begin
  651. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  652. ChangeFileExt(current_module.exefilename^,'.elf')+' '+
  653. ChangeFileExt(current_module.exefilename^,'.hex'),true,false);
  654. end;
  655. MakeExecutable:=success; { otherwise a recursive call to link method }
  656. end;
  657. {*****************************************************************************
  658. Initialize
  659. *****************************************************************************}
  660. initialization
  661. {$ifdef arm}
  662. RegisterExternalLinker(system_arm_embedded_info,TlinkerEmbedded);
  663. RegisterTarget(system_arm_embedded_info);
  664. {$endif arm}
  665. {$ifdef avr}
  666. RegisterExternalLinker(system_avr_embedded_info,TlinkerEmbedded);
  667. RegisterTarget(system_avr_embedded_info);
  668. {$endif avr}
  669. {$ifdef i386}
  670. RegisterExternalLinker(system_i386_embedded_info,TlinkerEmbedded);
  671. RegisterTarget(system_i386_embedded_info);
  672. {$endif i386}
  673. end.