t_gba.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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_gba;
  19. {$i fpcdefs.inc}
  20. interface
  21. implementation
  22. uses
  23. aasmbase,
  24. SysUtils,
  25. cutils,cfileutl,cclasses,
  26. globtype,globals,systems,verbose,cscript,fmodule,i_gba,link;
  27. type
  28. TlinkerGBA=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. TLINKERGBA
  38. *****************************************************************************}
  39. Constructor TLinkerGba.Create;
  40. begin
  41. Inherited Create;
  42. SharedLibFiles.doubles:=true;
  43. StaticLibFiles.doubles:=true;
  44. end;
  45. procedure TLinkerGba.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 TLinkerGba.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,
  61. linklibgcc : boolean;
  62. found1,
  63. found2 : boolean;
  64. begin
  65. s:='';
  66. WriteResponseFile:=False;
  67. linklibc:=(SharedLibFiles.Find('c')<>nil);
  68. linklibgcc:=(SharedLibFiles.Find('gcc')<>nil);
  69. prtobj:='prt0';
  70. cprtobj:='cprt0';
  71. if (linklibc or linklibgcc) then
  72. prtobj:=cprtobj;
  73. { Open link.res file }
  74. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  75. { Write path to search libraries }
  76. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  77. while assigned(HPath) do
  78. begin
  79. s:=HPath.Str;
  80. if (cs_link_on_target in current_settings.globalswitches) then
  81. s:=ScriptFixFileName(s);
  82. LinkRes.Add('-L'+s);
  83. HPath:=TCmdStrListItem(HPath.Next);
  84. end;
  85. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  86. while assigned(HPath) do
  87. begin
  88. s:=HPath.Str;
  89. if s<>'' then
  90. LinkRes.Add('SEARCH_DIR("'+s+'")');
  91. HPath:=TCmdStrListItem(HPath.Next);
  92. end;
  93. LinkRes.Add('INPUT (');
  94. { add objectfiles, start with prt0 always }
  95. //s:=FindObjectFile('prt0','',false);
  96. if prtobj<>'' then
  97. s:=FindObjectFile(prtobj,'',false);
  98. LinkRes.AddFileName(s);
  99. { try to add crti and crtbegin if linking to C }
  100. if linklibc then
  101. begin
  102. if librarysearchpath.FindFile('crti.o',false,s) then
  103. LinkRes.AddFileName(s);
  104. end;
  105. if linklibgcc then
  106. begin
  107. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  108. LinkRes.AddFileName(s);
  109. end;
  110. while not ObjectFiles.Empty do
  111. begin
  112. s:=ObjectFiles.GetFirst;
  113. if s<>'' then
  114. begin
  115. { vlink doesn't use SEARCH_DIR for object files }
  116. if not(cs_link_on_target in current_settings.globalswitches) then
  117. s:=FindObjectFile(s,'',false);
  118. LinkRes.AddFileName((maybequoted(s)));
  119. end;
  120. end;
  121. { Write staticlibraries }
  122. if not StaticLibFiles.Empty then
  123. begin
  124. { vlink doesn't need, and doesn't support GROUP }
  125. if (cs_link_on_target in current_settings.globalswitches) then
  126. begin
  127. LinkRes.Add(')');
  128. LinkRes.Add('GROUP(');
  129. end;
  130. while not StaticLibFiles.Empty do
  131. begin
  132. S:=StaticLibFiles.GetFirst;
  133. LinkRes.AddFileName((maybequoted(s)));
  134. end;
  135. end;
  136. if (cs_link_on_target in current_settings.globalswitches) then
  137. begin
  138. LinkRes.Add(')');
  139. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  140. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  141. linklibc:=false;
  142. linklibgcc:=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. linklibgcc:=true;
  158. end;
  159. end;
  160. { be sure that libc&libgcc is the last lib }
  161. if linklibgcc then
  162. begin
  163. LinkRes.Add('-lgcc');
  164. end;
  165. if linklibc then
  166. begin
  167. LinkRes.Add('-lc');
  168. end;
  169. end
  170. else
  171. begin
  172. while not SharedLibFiles.Empty do
  173. begin
  174. S:=SharedLibFiles.GetFirst;
  175. LinkRes.Add('lib'+s+target_info.staticlibext);
  176. end;
  177. LinkRes.Add(')');
  178. end;
  179. { objects which must be at the end }
  180. if linklibgcc then
  181. begin
  182. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  183. if found1 then
  184. begin
  185. LinkRes.Add('INPUT(');
  186. if found1 then
  187. LinkRes.AddFileName(s1);
  188. LinkRes.Add(')');
  189. end;
  190. end;
  191. if linklibc then
  192. begin
  193. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  194. if found2 then
  195. begin
  196. LinkRes.Add('INPUT(');
  197. if found2 then
  198. LinkRes.AddFileName(s2);
  199. LinkRes.Add(')');
  200. end;
  201. end;
  202. with linkres do
  203. begin
  204. add('/* Linker Script Original v1.3 by Jeff Frohwein */');
  205. add('/* v1.0 - Original release */');
  206. add('/* v1.1 - Added proper .data section support */');
  207. add('/* v1.2 - Added support for c++ & iwram overlays */');
  208. add('/* - Major contributions by Jason Wilkins. */');
  209. add('/* v1.3 - .ewram section now can be used when */');
  210. add('/* compiling for MULTIBOOT mode. This fixes */');
  211. add('/* malloc() in DevKitAdvance which depends */');
  212. add('/* on __eheap_start instead of end to define*/');
  213. add('/* the starting location of heap space. */');
  214. add('/* External global variable __gba_iwram_heap*/');
  215. add('/* support added to allow labels end, _end, */');
  216. add('/* & __end__ to point to end of iwram or */');
  217. add('/* the end of ewram. */');
  218. add('/* Additions by WinterMute */');
  219. add('/* v1.4 - .sbss section added for unitialised */');
  220. add('/* data in ewram */');
  221. add('/* v1.5 - padding section added to stop EZF */');
  222. add('/* stripping important data */');
  223. add('/* v1.6 - added memory sections */');
  224. add('');
  225. add('/* This file is released into the public domain */');
  226. add('/* for commercial or non-commercial use with no */');
  227. add('/* restrictions placed upon it. */');
  228. add('');
  229. add('/* NOTE!!!: This linker script defines the RAM & */');
  230. add('/* ROM start addresses. In order for it to work */');
  231. add('/* properly, remove -Ttext and -Tbss linker */');
  232. add('/* options from your makefile if they are */');
  233. add('/* present. */');
  234. add('');
  235. add('/* You can use the following to view section */');
  236. add('/* addresses in your .elf file: */');
  237. add('/* objdump -h file.elf */');
  238. add('/* Please note that empty sections may incorrectly*/');
  239. add('/* list the lma address as the vma address for */');
  240. add('/* some versions of objdump. */');
  241. add('');
  242. add('OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")');
  243. add('OUTPUT_ARCH(arm)');
  244. add('ENTRY(_start)');
  245. add('');
  246. add('MEMORY {');
  247. add('');
  248. add(' rom : ORIGIN = 0x08000000, LENGTH = 32M');
  249. add(' iwram : ORIGIN = 0x03000000, LENGTH = 32K');
  250. add(' ewram : ORIGIN = 0x02000000, LENGTH = 256K');
  251. add('}');
  252. add('');
  253. add('');
  254. add('');
  255. add('__text_start = ORIGIN(ewram);');
  256. add('__eheap_end = ORIGIN(ewram) + LENGTH(ewram);');
  257. add('__iwram_start = ORIGIN(iwram);');
  258. add('__iwram_top = ORIGIN(iwram) + LENGTH(iwram);;');
  259. add('');
  260. add('__sp_irq = __iwram_top - 0x060;');
  261. add('__sp_usr = __sp_irq - 0x0a0;');
  262. add('__irq_flags = 0x03007ff8;');
  263. add('');
  264. add('SECTIONS');
  265. add('{');
  266. add(' . = __text_start;');
  267. add(' . = __text_start;');
  268. add(' .crt0 :');
  269. add(' {');
  270. add(' KEEP (*(.crt0))');
  271. add(' . = ALIGN(4);');
  272. add(' } >ewram =0xff');
  273. add('');
  274. add(' .init :');
  275. add(' {');
  276. add(' KEEP (*(SORT_NONE(.init)))');
  277. add(' } >ewram');
  278. add('');
  279. add(' .plt :');
  280. add(' {');
  281. add(' *(.plt)');
  282. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  283. add(' } >ewram');
  284. add('');
  285. add('');
  286. add(' .text ALIGN (4):');
  287. add(' {');
  288. add(' *(EXCLUDE_FILE (*.iwram*) .text)');
  289. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  290. add(' KEEP (*(.text.*personality*))');
  291. add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  292. add(' *(.gnu.warning)');
  293. add(' *(.glue_7t) *(.glue_7) *(.vfp11_veneer)');
  294. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  295. add(' } >ewram = 0xff');
  296. add('');
  297. add(' __text_end = .;');
  298. add(' .fini :');
  299. add(' {');
  300. add(' KEEP (*(.fini))');
  301. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  302. add(' } >ewram =0');
  303. add('');
  304. add(' .rodata :');
  305. add(' {');
  306. add(' *(.rodata)');
  307. add(' *all.rodata*(*)');
  308. add(' *(.roda)');
  309. add(' *(.rodata.*)');
  310. add(' *(.gnu.linkonce.r*)');
  311. add(' SORT(CONSTRUCTORS)');
  312. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  313. add(' } >ewram = 0xff');
  314. add('');
  315. add(' .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >ewram');
  316. add(' __exidx_start = .;');
  317. add(' .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >ewram');
  318. add(' __exidx_end = .;');
  319. add(' /* Ensure the __preinit_array_start label is properly aligned. We');
  320. add(' could instead move the label definition inside the section, but');
  321. add(' the linker would then create the section even if it turns out to');
  322. add(' be empty, which isn''t pretty. */');
  323. add(' . = ALIGN(32 / 8);');
  324. add(' PROVIDE (__preinit_array_start = .);');
  325. add(' .preinit_array : { KEEP (*(.preinit_array)) } >ewram = 0xff');
  326. add(' PROVIDE (__preinit_array_end = .);');
  327. add(' PROVIDE (__init_array_start = .);');
  328. add(' .init_array : { KEEP (*(.init_array)) } >ewram = 0xff');
  329. add(' PROVIDE (__init_array_end = .);');
  330. add(' PROVIDE (__fini_array_start = .);');
  331. add(' .fini_array : { KEEP (*(.fini_array)) } >ewram = 0xff');
  332. add(' PROVIDE (__fini_array_end = .);');
  333. add(' .ctors :');
  334. add(' {');
  335. add(' /* gcc uses crtbegin.o to find the start of the constructors, so');
  336. add(' we make sure it is first. Because this is a wildcard, it');
  337. add(' doesn''t matter if the user does not actually link against');
  338. add(' crtbegin.o; the linker won''t look for a file to match a');
  339. add(' wildcard. The wildcard also means that it doesn''t matter which');
  340. add(' directory crtbegin.o is in. */');
  341. add(' KEEP (*crtbegin.o(.ctors))');
  342. add(' KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))');
  343. add(' KEEP (*(SORT(.ctors.*)))');
  344. add(' KEEP (*(.ctors))');
  345. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  346. add(' } >ewram = 0');
  347. add('');
  348. add(' .dtors :');
  349. add(' {');
  350. add(' KEEP (*crtbegin.o(.dtors))');
  351. add(' KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))');
  352. add(' KEEP (*(SORT(.dtors.*)))');
  353. add(' KEEP (*(.dtors))');
  354. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  355. add(' } >ewram = 0');
  356. add('');
  357. add(' .jcr : { KEEP (*(.jcr)) } >ewram');
  358. add(' .eh_frame :');
  359. add(' {');
  360. add(' KEEP (*(.eh_frame))');
  361. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  362. add(' } >ewram = 0');
  363. add('');
  364. add(' .gcc_except_table :');
  365. add(' {');
  366. add(' *(.gcc_except_table)');
  367. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  368. add(' } >ewram = 0');
  369. add('');
  370. add(' __iwram_lma = .;');
  371. add('');
  372. add(' .iwram __iwram_start : AT (__iwram_lma)');
  373. add(' {');
  374. add(' __iwram_start__ = ABSOLUTE(.) ;');
  375. add(' *(.iwram)');
  376. add(' *iwram.*(.text)');
  377. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  378. add(' __iwram_end__ = ABSOLUTE(.) ;');
  379. add(' } >iwram = 0xff');
  380. add('');
  381. add(' __data_lma = __iwram_lma + SIZEOF(.iwram) ;');
  382. add('');
  383. add(' .bss ALIGN(4) (NOLOAD):');
  384. add(' {');
  385. add(' __bss_start__ = ABSOLUTE(.);');
  386. add(' *(.dynbss)');
  387. add(' *(.gnu.linkonce.b*)');
  388. add(' *(.bss*)');
  389. add(' *(COMMON)');
  390. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  391. add(' __bss_end__ = ABSOLUTE(.) ;');
  392. add(' }');
  393. add('');
  394. add(' .data ALIGN(4) : AT (__data_lma)');
  395. add(' {');
  396. add(' __data_start__ = ABSOLUTE(.);');
  397. add(' *(.data)');
  398. add(' *(.data.*)');
  399. add(' *(.gnu.linkonce.d*)');
  400. add(' CONSTRUCTORS');
  401. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  402. add(' __data_end__ = ABSOLUTE(.);');
  403. add(' } >iwram = 0xff');
  404. add('');
  405. add(' __iwram_overlay_lma = __data_lma + SIZEOF(.data);');
  406. add('');
  407. add(' PROVIDE (edata = .);');
  408. add(' __iwram_overlay_start = . ;');
  409. add('');
  410. add(' OVERLAY ALIGN(4) : NOCROSSREFS AT (__iwram_overlay_lma)');
  411. add(' {');
  412. add(' .iwram0 { *(.iwram0) . = ALIGN(4);}');
  413. add(' .iwram1 { *(.iwram1) . = ALIGN(4);}');
  414. add(' .iwram2 { *(.iwram2) . = ALIGN(4);}');
  415. add(' .iwram3 { *(.iwram3) . = ALIGN(4);}');
  416. add(' .iwram4 { *(.iwram4) . = ALIGN(4);}');
  417. add(' .iwram5 { *(.iwram5) . = ALIGN(4);}');
  418. add(' .iwram6 { *(.iwram6) . = ALIGN(4);}');
  419. add(' .iwram7 { *(.iwram7) . = ALIGN(4);}');
  420. add(' .iwram8 { *(.iwram8) . = ALIGN(4);}');
  421. add(' .iwram9 { *(.iwram9) . = ALIGN(4);}');
  422. add(' } >iwram = 0xff');
  423. add('');
  424. add(' __ewram_lma = LOADADDR(.iwram0) + SIZEOF(.iwram0)+SIZEOF(.iwram1)+SIZEOF(.iwram2)+SIZEOF(.iwram3)+SIZEOF(.iwram4)+SIZEOF(.iwram5)+SIZEOF(.iwram6)+SIZEOF(.iwram7)+SIZEOF(.iwram8)+SIZEOF(.iwram9);');
  425. add('');
  426. add(' __iwram_overlay_end = __ewram_lma ;');
  427. add('');
  428. add(' /* v1.3 */');
  429. add(' __ewram_start = __ewram_lma ;');
  430. add('');
  431. add(' .ewram __ewram_start : AT (__ewram_lma)');
  432. add(' {');
  433. add(' *(.ewram)');
  434. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  435. add(' __ewram_end = ABSOLUTE(.);');
  436. add(' } >ewram = 0xff');
  437. add('');
  438. add(' __ewram_overlay_lma = __ewram_lma + SIZEOF(.ewram);');
  439. add('');
  440. add(' .sbss ALIGN(4)(NOLOAD):');
  441. add(' {');
  442. add(' __sbss_start__ = ABSOLUTE(.);');
  443. add(' *(.sbss)');
  444. add(' . = ALIGN(4);');
  445. add(' __sbss_end__ = ABSOLUTE(.);');
  446. add(' __end__ = ABSOLUTE(.);');
  447. add(' __eheap_start = ABSOLUTE(.);');
  448. add(' }');
  449. add('');
  450. add(' OVERLAY ALIGN(4): NOCROSSREFS AT (__ewram_overlay_lma)');
  451. add(' {');
  452. add(' .ewram0 { *(.ewram0) . = ALIGN(4);}');
  453. add(' .ewram1 { *(.ewram1) . = ALIGN(4);}');
  454. add(' .ewram2 { *(.ewram2) . = ALIGN(4);}');
  455. add(' .ewram3 { *(.ewram3) . = ALIGN(4);}');
  456. add(' .ewram4 { *(.ewram4) . = ALIGN(4);}');
  457. add(' .ewram5 { *(.ewram5) . = ALIGN(4);}');
  458. add(' .ewram6 { *(.ewram6) . = ALIGN(4);}');
  459. add(' .ewram7 { *(.ewram7) . = ALIGN(4);}');
  460. add(' .ewram8 { *(.ewram8) . = ALIGN(4);}');
  461. add(' .ewram9 { *(.ewram9) . = ALIGN(4);}');
  462. add(' } >ewram = 0xff');
  463. add(' __ewram_overlay_end = ABSOLUTE(.);');
  464. add('');
  465. add(' __eheap_start = __ewram_overlay_end ;');
  466. add('');
  467. add(' _end = __ewram_overlay_end;');
  468. add(' __end__ = __ewram_overlay_end;');
  469. add(' __rom_end__ = __ewram_overlay_end;');
  470. add('');
  471. add(' /* Stabs debugging sections. */');
  472. add(' .stab 0 : { *(.stab) }');
  473. add(' .stabstr 0 : { *(.stabstr) }');
  474. add(' .stab.excl 0 : { *(.stab.excl) }');
  475. add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  476. add(' .stab.index 0 : { *(.stab.index) }');
  477. add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  478. add(' .comment 0 : { *(.comment) }');
  479. add(' /* DWARF debug sections.');
  480. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  481. add(' of the section so we begin them at 0. */');
  482. add(' /* DWARF 1 */');
  483. add(' .debug 0 : { *(.debug) }');
  484. add(' .line 0 : { *(.line) }');
  485. add(' /* GNU DWARF 1 extensions */');
  486. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  487. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  488. add(' /* DWARF 1.1 and DWARF 2 */');
  489. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  490. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  491. add(' /* DWARF 2 */');
  492. add(' .debug_info 0 : { *(.debug_info) }');
  493. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  494. add(' .debug_line 0 : { *(.debug_line) }');
  495. add(' .debug_frame 0 : { *(.debug_frame) }');
  496. add(' .debug_str 0 : { *(.debug_str) }');
  497. add(' .debug_loc 0 : { *(.debug_loc) }');
  498. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  499. add(' /* SGI/MIPS DWARF 2 extensions */');
  500. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  501. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  502. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  503. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  504. add(' .stack 0x80000 : { _stack = .; *(.stack) }');
  505. add(' /* These must appear regardless of . */');
  506. add('}');
  507. end;
  508. { Write and Close response }
  509. linkres.writetodisk;
  510. linkres.free;
  511. WriteResponseFile:=True;
  512. end;
  513. function TLinkerGba.MakeExecutable:boolean;
  514. var
  515. binstr,
  516. cmdstr : TCmdStr;
  517. success : boolean;
  518. StaticStr,
  519. GCSectionsStr,
  520. DynLinkStr,
  521. MapStr,
  522. StripStr: string;
  523. begin
  524. { for future use }
  525. StaticStr:='';
  526. StripStr:='';
  527. DynLinkStr:='';
  528. MapStr:='';
  529. GCSectionsStr:='';
  530. if (cs_link_strip in current_settings.globalswitches) and
  531. not(cs_link_separate_dbg_file in current_settings.globalswitches) then
  532. StripStr:='-s';
  533. if (cs_link_map in current_settings.globalswitches) then
  534. StripStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  535. if create_smartlink_sections then
  536. GCSectionsStr:='--gc-sections';
  537. //if not(cs_link_extern in current_settings.globalswitches) then
  538. if not(cs_link_nolink in current_settings.globalswitches) then
  539. Message1(exec_i_linking,current_module.exefilename);
  540. { Write used files and libraries }
  541. WriteResponseFile();
  542. { Call linker }
  543. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  544. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  545. Replace(cmdstr,'$EXE',(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')))));
  546. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  547. Replace(cmdstr,'$STATIC',StaticStr);
  548. Replace(cmdstr,'$STRIP',StripStr);
  549. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  550. Replace(cmdstr,'$MAP',MapStr);
  551. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  552. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  553. { Remove ReponseFile }
  554. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  555. DeleteFile(outputexedir+Info.ResName);
  556. { Post process }
  557. if success then
  558. begin
  559. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  560. ChangeFileExt(current_module.exefilename,'.elf')+' '+
  561. current_module.exefilename,true,false);
  562. end;
  563. if success then
  564. begin
  565. success:=DoExec(FindUtil('gbafix'), current_module.exefilename,true,false);
  566. end;
  567. MakeExecutable:=success; { otherwise a recursive call to link method }
  568. end;
  569. {*****************************************************************************
  570. Initialize
  571. *****************************************************************************}
  572. initialization
  573. RegisterLinker(ld_gba,TLinkerGba);
  574. RegisterTarget(system_arm_gba_info);
  575. end.