t_nds.pas 27 KB

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