t_gba.pas 21 KB

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