t_nds.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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_nds;
  19. {$i fpcdefs.inc}
  20. interface
  21. implementation
  22. uses
  23. SysUtils,
  24. cutils,cfileutl,cclasses,
  25. globtype,globals,systems,verbose,script,fmodule,i_nds,link;
  26. type
  27. TlinkerNDS=class(texternallinker)
  28. private
  29. Function WriteResponseFile: Boolean;
  30. public
  31. constructor Create; override;
  32. procedure SetDefaultInfo; override;
  33. function MakeExecutable:boolean; override;
  34. end;
  35. {*****************************************************************************
  36. TLINKERNDS
  37. *****************************************************************************}
  38. Constructor TLinkerNDS.Create;
  39. begin
  40. Inherited Create;
  41. SharedLibFiles.doubles:=true;
  42. StaticLibFiles.doubles:=true;
  43. // set arm9 as default apptype
  44. if (apptype <> app_arm9) or (apptype <> app_arm7) then
  45. apptype := app_arm9;
  46. end;
  47. procedure TLinkerNDS.SetDefaultInfo;
  48. begin
  49. with Info do
  50. begin
  51. ExeCmd[1]:='ld -g $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE -T $RES';
  52. end;
  53. end;
  54. Function TLinkerNDS.WriteResponseFile: Boolean;
  55. Var
  56. linkres : TLinkRes;
  57. i : longint;
  58. HPath : TCmdStrListItem;
  59. s,s1,s2 : TCmdStr;
  60. prtobj,
  61. cprtobj : string[80];
  62. linklibc,
  63. linklibgcc : boolean;
  64. found1,
  65. found2 : boolean;
  66. begin
  67. WriteResponseFile:=False;
  68. linklibc:=(SharedLibFiles.Find('c')<>nil);
  69. linklibgcc:=(SharedLibFiles.Find('gcc')<>nil);
  70. case apptype of
  71. app_arm9:
  72. begin
  73. prtobj:='prt09';
  74. cprtobj:='cprt09';
  75. end;
  76. app_arm7:
  77. begin
  78. prtobj:='prt07';
  79. cprtobj:='cprt07';
  80. end;
  81. end;
  82. if (linklibc or linklibgcc) then
  83. prtobj:=cprtobj;
  84. { Open link.res file }
  85. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName);
  86. { Write path to search libraries }
  87. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  88. while assigned(HPath) do
  89. begin
  90. s:=HPath.Str;
  91. if (cs_link_on_target in current_settings.globalswitches) then
  92. s:=ScriptFixFileName(s);
  93. LinkRes.Add('-L'+s);
  94. HPath:=TCmdStrListItem(HPath.Next);
  95. end;
  96. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  97. while assigned(HPath) do
  98. begin
  99. s:=HPath.Str;
  100. if s<>'' then
  101. LinkRes.Add('SEARCH_DIR('+(maybequoted(s))+')');
  102. HPath:=TCmdStrListItem(HPath.Next);
  103. end;
  104. LinkRes.Add('INPUT (');
  105. { add objectfiles, start with prt0 always }
  106. if prtobj<>'' then
  107. s:=FindObjectFile(prtobj,'',false);
  108. LinkRes.AddFileName(s);
  109. { try to add crti and crtbegin if linking to C }
  110. if linklibc then
  111. begin
  112. if librarysearchpath.FindFile('crti.o',false,s) then
  113. LinkRes.AddFileName(s);
  114. end;
  115. if linklibgcc then
  116. begin
  117. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  118. LinkRes.AddFileName(s);
  119. end;
  120. while not ObjectFiles.Empty do
  121. begin
  122. s:=ObjectFiles.GetFirst;
  123. if s<>'' then
  124. begin
  125. { vlink doesn't use SEARCH_DIR for object files }
  126. if not(cs_link_on_target in current_settings.globalswitches) then
  127. s:=FindObjectFile(s,'',false);
  128. LinkRes.AddFileName((maybequoted(s)));
  129. end;
  130. end;
  131. { Write staticlibraries }
  132. if not StaticLibFiles.Empty then
  133. begin
  134. { vlink doesn't need, and doesn't support GROUP }
  135. if (cs_link_on_target in current_settings.globalswitches) then
  136. begin
  137. LinkRes.Add(')');
  138. LinkRes.Add('GROUP(');
  139. end;
  140. while not StaticLibFiles.Empty do
  141. begin
  142. S:=StaticLibFiles.GetFirst;
  143. LinkRes.AddFileName((maybequoted(s)));
  144. end;
  145. end;
  146. if (cs_link_on_target in current_settings.globalswitches) then
  147. begin
  148. LinkRes.Add(')');
  149. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  150. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  151. linklibc:=false;
  152. linklibgcc:=false;
  153. while not SharedLibFiles.Empty do
  154. begin
  155. S:=SharedLibFiles.GetFirst;
  156. if s<>'c' then
  157. begin
  158. i:=Pos(target_info.sharedlibext,S);
  159. if i>0 then
  160. Delete(S,i,255);
  161. LinkRes.Add('-l'+s);
  162. end
  163. else
  164. begin
  165. LinkRes.Add('-l'+s);
  166. linklibc:=true;
  167. linklibgcc:=true;
  168. end;
  169. end;
  170. { be sure that libc&libgcc is the last lib }
  171. if linklibgcc then
  172. begin
  173. LinkRes.Add('-lgcc');
  174. end;
  175. if linklibc then
  176. begin
  177. LinkRes.Add('-lc');
  178. end;
  179. end
  180. else
  181. begin
  182. while not SharedLibFiles.Empty do
  183. begin
  184. S:=SharedLibFiles.GetFirst;
  185. LinkRes.Add('lib'+s+target_info.staticlibext);
  186. end;
  187. LinkRes.Add(')');
  188. end;
  189. { objects which must be at the end }
  190. if linklibgcc then
  191. begin
  192. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  193. if found1 then
  194. begin
  195. LinkRes.Add('INPUT(');
  196. if found1 then
  197. LinkRes.AddFileName(s1);
  198. LinkRes.Add(')');
  199. end;
  200. end;
  201. if linklibc then
  202. begin
  203. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  204. if found2 then
  205. begin
  206. LinkRes.Add('INPUT(');
  207. if found2 then
  208. LinkRes.AddFileName(s2);
  209. LinkRes.Add(')');
  210. end;
  211. end;
  212. with linkres do
  213. begin
  214. if apptype=app_arm9 then //ARM9
  215. begin
  216. add('OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")');
  217. add('OUTPUT_ARCH(arm)');
  218. add('ENTRY(_start)');
  219. add('');
  220. add('MEMORY {');
  221. add('');
  222. add(' rom : ORIGIN = 0x08000000, LENGTH = 32M');
  223. add(' ewram : ORIGIN = 0x02000000, LENGTH = 4M - 4k');
  224. add(' dtcm : ORIGIN = 0x0b000000, LENGTH = 16K');
  225. add(' vectors : ORIGIN = 0x00000000, LENGTH = 256');
  226. add(' itcm : ORIGIN = 0x01000100, LENGTH = 32K - 256');
  227. add('}');
  228. add('');
  229. add('__vectors_start = ORIGIN(vectors);');
  230. add('__itcm_start = ORIGIN(itcm);');
  231. add('__ewram_end = ORIGIN(ewram) + LENGTH(ewram);');
  232. add('__eheap_end = ORIGIN(ewram) + LENGTH(ewram);');
  233. add('__dtcm_start = ORIGIN(dtcm);');
  234. add('__dtcm_top = ORIGIN(dtcm) + LENGTH(dtcm);');
  235. add('__irq_flags = __dtcm_top - 0x08;');
  236. add('__irq_vector = __dtcm_top - 0x04;');
  237. add('');
  238. add('__sp_svc = __dtcm_top - 0x100;');
  239. add('__sp_irq = __sp_svc - 0x100;');
  240. add('__sp_usr = __sp_irq - 0x100;');
  241. add('');
  242. add('SECTIONS');
  243. add('{');
  244. add(' .init :');
  245. add(' {');
  246. add(' __text_start = . ;');
  247. add(' KEEP (*(.init))');
  248. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  249. add(' } >ewram = 0xff');
  250. add('');
  251. add(' .plt : { *(.plt) } >ewram = 0xff');
  252. add('');
  253. add(' .text : /* ALIGN (4): */');
  254. add(' {');
  255. add(' *(EXCLUDE_FILE (*.itcm*) .text)');
  256. add('');
  257. add(' *(.text.*)');
  258. add(' *(.stub)');
  259. add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  260. add(' *(.gnu.warning)');
  261. add(' *(.gnu.linkonce.t*)');
  262. add(' *(.glue_7)');
  263. add(' *(.glue_7t)');
  264. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  265. add(' } >ewram = 0xff');
  266. add('');
  267. add(' .fini :');
  268. add(' {');
  269. add(' KEEP (*(.fini))');
  270. add(' } >ewram =0xff');
  271. add('');
  272. add(' __text_end = . ;');
  273. add('');
  274. add(' .rodata :');
  275. add(' {');
  276. add(' *(.rodata)');
  277. add(' *all.rodata*(*)');
  278. add(' *(.roda)');
  279. add(' *(.rodata.*)');
  280. add(' *(.gnu.linkonce.r*)');
  281. add(' SORT(CONSTRUCTORS)');
  282. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  283. add(' } >ewram = 0xff');
  284. add('');
  285. add(' .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >ewram');
  286. add(' __exidx_start = .;');
  287. add(' .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >ewram');
  288. add(' __exidx_end = .;');
  289. add(' /* Ensure the __preinit_array_start label is properly aligned. We');
  290. add(' could instead move the label definition inside the section, but');
  291. add(' the linker would then create the section even if it turns out to');
  292. add(' be empty, which isn''t pretty. */');
  293. add(' . = ALIGN(32 / 8);');
  294. add(' PROVIDE (__preinit_array_start = .);');
  295. add(' .preinit_array : { KEEP (*(.preinit_array)) } >ewram = 0xff');
  296. add(' PROVIDE (__preinit_array_end = .);');
  297. add(' PROVIDE (__init_array_start = .);');
  298. add(' .init_array : { KEEP (*(.init_array)) } >ewram = 0xff');
  299. add(' PROVIDE (__init_array_end = .);');
  300. add(' PROVIDE (__fini_array_start = .);');
  301. add(' .fini_array : { KEEP (*(.fini_array)) } >ewram = 0xff');
  302. add(' PROVIDE (__fini_array_end = .);');
  303. add('');
  304. add(' .ctors :');
  305. add(' {');
  306. add(' /* gcc uses crtbegin.o to find the start of the constructors, so');
  307. add(' we make sure it is first. Because this is a wildcard, it');
  308. add(' doesn''t matter if the user does not actually link against');
  309. add(' crtbegin.o; the linker won''t look for a file to match a');
  310. add(' wildcard. The wildcard also means that it doesn''t matter which');
  311. add(' directory crtbegin.o is in. */');
  312. add(' KEEP (*crtbegin.o(.ctors))');
  313. add(' KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))');
  314. add(' KEEP (*(SORT(.ctors.*)))');
  315. add(' KEEP (*(.ctors))');
  316. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  317. add(' } >ewram = 0xff');
  318. add('');
  319. add(' .dtors :');
  320. add(' {');
  321. add(' KEEP (*crtbegin.o(.dtors))');
  322. add(' KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))');
  323. add(' KEEP (*(SORT(.dtors.*)))');
  324. add(' KEEP (*(.dtors))');
  325. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  326. add(' } >ewram = 0xff');
  327. add('');
  328. add(' .eh_frame :');
  329. add(' {');
  330. add(' KEEP (*(.eh_frame))');
  331. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  332. add(' } >ewram = 0xff');
  333. add('');
  334. add(' .gcc_except_table :');
  335. add(' {');
  336. add(' *(.gcc_except_table)');
  337. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  338. add(' } >ewram = 0xff');
  339. add(' .jcr : { KEEP (*(.jcr)) } >ewram = 0');
  340. add(' .got : { *(.got.plt) *(.got) *(.rel.got) } >ewram = 0');
  341. add('');
  342. add(' .ewram ALIGN(4) : ');
  343. add(' {');
  344. add(' __ewram_start = ABSOLUTE(.) ;');
  345. add(' *(.ewram)');
  346. add(' *ewram.*(.text)');
  347. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  348. add(' } >ewram = 0xff');
  349. add('');
  350. add('');
  351. add(' .data ALIGN(4) :');
  352. add(' {');
  353. add(' __data_start = ABSOLUTE(.);');
  354. add(' *(.data)');
  355. add(' *(.data.*)');
  356. add(' *(.gnu.linkonce.d*)');
  357. add(' *(.fpc*)');
  358. add(' CONSTRUCTORS');
  359. add(' . = ALIGN(4);');
  360. add(' __data_end = ABSOLUTE(.) ;');
  361. add(' } >ewram = 0xff');
  362. add('');
  363. add('');
  364. add(' __dtcm_lma = . ;');
  365. add(' __bss_vma = . ;');
  366. add('');
  367. add(' .dtcm __dtcm_start : AT (__dtcm_lma)');
  368. add(' {');
  369. add(' *(.dtcm)');
  370. add(' *(.dtcm.*)');
  371. add(' . = ALIGN(4);');
  372. add(' __dtcm_end = ABSOLUTE(.);');
  373. add(' } >dtcm = 0xff');
  374. add('');
  375. add('');
  376. add(' __itcm_lma = __dtcm_lma + SIZEOF(.dtcm);');
  377. add('');
  378. add(' .itcm __itcm_start : AT (__itcm_lma)');
  379. add(' {');
  380. add(' *(.itcm)');
  381. add(' *itcm.*(.text)');
  382. add(' . = ALIGN(4);');
  383. add(' __itcm_end = ABSOLUTE(.);');
  384. add(' } >itcm = 0xff');
  385. add('');
  386. add(' __vectors_lma = __itcm_lma + SIZEOF(.itcm);');
  387. add(' .vectors __vectors_start : AT (__vectors_lma)');
  388. add(' {');
  389. add(' *(.vectors)');
  390. add(' *vectors.*(.text)');
  391. add(' . = ALIGN(4);');
  392. add(' __vectors_end = ABSOLUTE(.);');
  393. add(' } >vectors = 0xff');
  394. add('');
  395. add(' .sbss __dtcm_end (NOLOAD):');
  396. add(' {');
  397. add(' __sbss_start = ABSOLUTE(.);');
  398. add(' __sbss_start__ = ABSOLUTE(.);');
  399. add(' *(.sbss)');
  400. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  401. add(' __sbss_end = ABSOLUTE(.);');
  402. add(' } >dtcm');
  403. add('');
  404. add('');
  405. add('');
  406. add(' .bss __bss_vma (NOLOAD):');
  407. add(' {');
  408. add(' __bss_start = ABSOLUTE(.);');
  409. add(' __bss_start__ = ABSOLUTE(.);');
  410. add(' *(.dynbss)');
  411. add(' *(.gnu.linkonce.b*)');
  412. add(' *(.bss*)');
  413. add(' *(COMMON)');
  414. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  415. add(' __bss_end = ABSOLUTE(.) ;');
  416. add(' __bss_end__ = __bss_end ;');
  417. add(' } AT>ewram');
  418. add('');
  419. add('');
  420. add(' _end = __bss_end__ ;');
  421. add(' __end__ = __bss_end__ ;');
  422. add('');
  423. add('');
  424. add('');
  425. add(' /* Stabs debugging sections. */');
  426. add(' .stab 0 : { *(.stab) }');
  427. add(' .stabstr 0 : { *(.stabstr) }');
  428. add(' .stab.excl 0 : { *(.stab.excl) }');
  429. add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  430. add(' .stab.index 0 : { *(.stab.index) }');
  431. add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  432. add(' .comment 0 : { *(.comment) }');
  433. add(' /* DWARF debug sections.');
  434. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  435. add(' of the section so we begin them at 0. */');
  436. add(' /* DWARF 1 */');
  437. add(' .debug 0 : { *(.debug) }');
  438. add(' .line 0 : { *(.line) }');
  439. add(' /* GNU DWARF 1 extensions */');
  440. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  441. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  442. add(' /* DWARF 1.1 and DWARF 2 */');
  443. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  444. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  445. add(' /* DWARF 2 */');
  446. add(' .debug_info 0 : { *(.debug_info) }');
  447. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  448. add(' .debug_line 0 : { *(.debug_line) }');
  449. add(' .debug_frame 0 : { *(.debug_frame) }');
  450. add(' .debug_str 0 : { *(.debug_str) }');
  451. add(' .debug_loc 0 : { *(.debug_loc) }');
  452. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  453. add(' /* SGI/MIPS DWARF 2 extensions */');
  454. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  455. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  456. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  457. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  458. add(' .stack 0x80000 : { _stack = .; *(.stack) }');
  459. add(' /* These must appear regardless of . */');
  460. add('}');
  461. end;
  462. if apptype=app_arm7 then
  463. begin
  464. add('OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")');
  465. add('OUTPUT_ARCH(arm)');
  466. add('ENTRY(_start)');
  467. add('');
  468. add('MEMORY {');
  469. add('');
  470. add(' rom : ORIGIN = 0x08000000, LENGTH = 32M');
  471. add(' iwram : ORIGIN = 0x037f8000, LENGTH = 96K');
  472. add('}');
  473. add('');
  474. add('__iwram_start = ORIGIN(iwram);');
  475. add('__iwram_top = ORIGIN(iwram)+ LENGTH(iwram);');
  476. add('__sp_irq = __iwram_top - 0x60;');
  477. add('__sp_svc = __sp_irq - 0x100;');
  478. add('__sp_usr = __sp_svc - 0x100;');
  479. add('');
  480. add('__irq_flags = __iwram_top - 8;');
  481. add('__irq_vector = __iwram_top - 4;');
  482. add('');
  483. add('SECTIONS');
  484. add('{');
  485. add(' .init :');
  486. add(' {');
  487. add(' __text_start = . ;');
  488. add(' KEEP (*(.init))');
  489. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  490. add(' } >iwram = 0xff');
  491. add(' .plt : { *(.plt) } >iwram = 0xff');
  492. add('');
  493. add(' .text : /* ALIGN (4): */');
  494. add(' {');
  495. add('');
  496. add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
  497. add(' KEEP (*(.text.*personality*))');
  498. add(' /* .gnu.warning sections are handled specially by elf32.em. */');
  499. add(' *(.gnu.warning)');
  500. add(' *(.glue_7t) *(.glue_7) *(.vfp11_veneer)');
  501. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  502. add(' } >iwram = 0xff');
  503. add('');
  504. add(' .fini :');
  505. add(' {');
  506. add(' KEEP (*(.fini))');
  507. add(' } >iwram =0xff');
  508. add('');
  509. add(' __text_end = . ;');
  510. add('');
  511. add(' .rodata :');
  512. add(' {');
  513. add(' *(.rodata)');
  514. add(' *all.rodata*(*)');
  515. add(' *(.roda)');
  516. add(' *(.rodata.*)');
  517. add(' *(.gnu.linkonce.r*)');
  518. add(' SORT(CONSTRUCTORS)');
  519. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  520. add(' } >iwram = 0xff');
  521. add('');
  522. add(' .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >iwram');
  523. add(' __exidx_start = .;');
  524. add(' .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >iwram');
  525. add(' __exidx_end = .;');
  526. add('');
  527. add('/* Ensure the __preinit_array_start label is properly aligned. We');
  528. add(' could instead move the label definition inside the section, but');
  529. add(' the linker would then create the section even if it turns out to');
  530. add(' be empty, which isn''t pretty. */');
  531. add(' . = ALIGN(32 / 8);');
  532. add(' PROVIDE (__preinit_array_start = .);');
  533. add(' .preinit_array : { KEEP (*(.preinit_array)) } >iwram = 0xff');
  534. add(' PROVIDE (__preinit_array_end = .);');
  535. add(' PROVIDE (__init_array_start = .);');
  536. add(' .init_array : { KEEP (*(.init_array)) } >iwram = 0xff');
  537. add(' PROVIDE (__init_array_end = .);');
  538. add(' PROVIDE (__fini_array_start = .);');
  539. add(' .fini_array : { KEEP (*(.fini_array)) } >iwram = 0xff');
  540. add(' PROVIDE (__fini_array_end = .);');
  541. add('');
  542. add(' .ctors :');
  543. add(' {');
  544. add(' /* gcc uses crtbegin.o to find the start of the constructors, so');
  545. add(' we make sure it is first. Because this is a wildcard, it');
  546. add(' doesn''t matter if the user does not actually link against');
  547. add(' crtbegin.o; the linker won''t look for a file to match a');
  548. add(' wildcard. The wildcard also means that it doesn''t matter which');
  549. add(' directory crtbegin.o is in. */');
  550. add(' KEEP (*crtbegin.o(.ctors))');
  551. add(' KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))');
  552. add(' KEEP (*(SORT(.ctors.*)))');
  553. add(' KEEP (*(.ctors))');
  554. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  555. add(' } >iwram = 0xff');
  556. add('');
  557. add(' .dtors :');
  558. add(' {');
  559. add(' KEEP (*crtbegin.o(.dtors))');
  560. add(' KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))');
  561. add(' KEEP (*(SORT(.dtors.*)))');
  562. add(' KEEP (*(.dtors))');
  563. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  564. add(' } >iwram = 0xff');
  565. add('');
  566. add(' .eh_frame :');
  567. add(' {');
  568. add(' KEEP (*(.eh_frame))');
  569. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  570. add(' } >iwram = 0xff');
  571. add('');
  572. add(' .gcc_except_table :');
  573. add(' {');
  574. add(' *(.gcc_except_table)');
  575. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  576. add(' } >iwram = 0xff');
  577. add(' .jcr : { KEEP (*(.jcr)) } >iwram = 0');
  578. add(' .got : { *(.got.plt) *(.got) } >iwram = 0');
  579. add('');
  580. add('');
  581. add(' .iwram ALIGN(4) :');
  582. add(' {');
  583. add(' __iwram_start = ABSOLUTE(.) ;');
  584. add(' *(.iwram)');
  585. add(' *iwram.*(.text)');
  586. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  587. add(' __iwram_end = ABSOLUTE(.) ;');
  588. add(' } >iwram = 0xff');
  589. add('');
  590. add('');
  591. add(' .data ALIGN(4) : {');
  592. add(' __data_start = ABSOLUTE(.);');
  593. add(' *(.data)');
  594. add(' *(.data.*)');
  595. add(' *(.gnu.linkonce.d*)');
  596. add(' *(.fpc*)');
  597. add(' CONSTRUCTORS');
  598. add(' . = ALIGN(4);');
  599. add(' __data_end = ABSOLUTE(.) ;');
  600. add(' } >iwram = 0xff');
  601. add('');
  602. add('');
  603. add('');
  604. add(' .bss ALIGN(4) :');
  605. add(' {');
  606. add(' __bss_start = ABSOLUTE(.);');
  607. add(' __bss_start__ = ABSOLUTE(.);');
  608. add(' *(.dynbss)');
  609. add(' *(.gnu.linkonce.b*)');
  610. add(' *(.bss*)');
  611. add(' *(COMMON)');
  612. add(' . = ALIGN(4); /* REQUIRED. LD is flaky without it. */');
  613. add(' } >iwram');
  614. add('');
  615. add(' __bss_end = . ;');
  616. add(' __bss_end__ = . ;');
  617. add('');
  618. add(' _end = . ;');
  619. add(' __end__ = . ;');
  620. add(' PROVIDE (end = _end);');
  621. add('');
  622. add(' /* Stabs debugging sections. */');
  623. add(' .stab 0 : { *(.stab) }');
  624. add(' .stabstr 0 : { *(.stabstr) }');
  625. add(' .stab.excl 0 : { *(.stab.excl) }');
  626. add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  627. add(' .stab.index 0 : { *(.stab.index) }');
  628. add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  629. add(' .comment 0 : { *(.comment) }');
  630. add(' /* DWARF debug sections.');
  631. add(' Symbols in the DWARF debugging sections are relative to the beginning');
  632. add(' of the section so we begin them at 0. */');
  633. add(' /* DWARF 1 */');
  634. add(' .debug 0 : { *(.debug) }');
  635. add(' .line 0 : { *(.line) }');
  636. add(' /* GNU DWARF 1 extensions */');
  637. add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  638. add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  639. add(' /* DWARF 1.1 and DWARF 2 */');
  640. add(' .debug_aranges 0 : { *(.debug_aranges) }');
  641. add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  642. add(' /* DWARF 2 */');
  643. add(' .debug_info 0 : { *(.debug_info) }');
  644. add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  645. add(' .debug_line 0 : { *(.debug_line) }');
  646. add(' .debug_frame 0 : { *(.debug_frame) }');
  647. add(' .debug_str 0 : { *(.debug_str) }');
  648. add(' .debug_loc 0 : { *(.debug_loc) }');
  649. add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  650. add(' /* SGI/MIPS DWARF 2 extensions */');
  651. add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  652. add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  653. add(' .debug_typenames 0 : { *(.debug_typenames) }');
  654. add(' .debug_varnames 0 : { *(.debug_varnames) }');
  655. add(' .stack 0x80000 : { _stack = .; *(.stack) }');
  656. add(' /* These must appear regardless of . */');
  657. add('}');
  658. end;
  659. end;
  660. { Write and Close response }
  661. linkres.writetodisk;
  662. linkres.free;
  663. WriteResponseFile:=True;
  664. end;
  665. function TLinkerNDS.MakeExecutable:boolean;
  666. var
  667. binstr,
  668. cmdstr : TCmdStr;
  669. success : boolean;
  670. StaticStr,
  671. GCSectionsStr,
  672. DynLinkStr,
  673. StripStr: string;
  674. preName: string;
  675. begin
  676. { for future use }
  677. StaticStr:='';
  678. StripStr:='';
  679. DynLinkStr:='';
  680. case apptype of
  681. app_arm9: preName:='.nef';
  682. app_arm7: preName:='.nlf';
  683. end;
  684. if (cs_link_map in current_settings.globalswitches) then
  685. StripStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename^,'.map'));
  686. GCSectionsStr:='--gc-sections';
  687. if not(cs_link_nolink in current_settings.globalswitches) then
  688. Message1(exec_i_linking,current_module.exefilename^);
  689. { Write used files and libraries }
  690. WriteResponseFile();
  691. { Call linker }
  692. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  693. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  694. Replace(cmdstr,'$EXE',(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename^,preName)))));
  695. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  696. Replace(cmdstr,'$STATIC',StaticStr);
  697. Replace(cmdstr,'$STRIP',StripStr);
  698. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  699. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  700. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  701. { Remove ReponseFile }
  702. if (success) and not(cs_link_nolink in current_settings.globalswitches) then
  703. DeleteFile(outputexedir+Info.ResName);
  704. { Post process }
  705. if success then
  706. begin
  707. success:=DoExec(FindUtil(utilsprefix + 'objcopy'), '-O binary '+
  708. ChangeFileExt(current_module.exefilename^, preName) + ' ' +
  709. ChangeFileExt(current_module.exefilename^, preName+target_info.exeext),
  710. true,false);
  711. end;
  712. if success and (apptype=app_arm9) then
  713. begin
  714. success:=DoExec(FindUtil('ndstool'), '-c ' +
  715. ChangeFileExt(current_module.exefilename^, '.nds') + ' -9 ' +
  716. ChangeFileExt(current_module.exefilename^, preName+target_info.exeext),
  717. true,false);
  718. end;
  719. MakeExecutable:=success; { otherwise a recursive call to link method }
  720. end;
  721. {*****************************************************************************
  722. Initialize
  723. *****************************************************************************}
  724. initialization
  725. RegisterExternalLinker(system_arm_nds_info,TLinkerNDS);
  726. RegisterTarget(system_arm_nds_info);
  727. end.