t_nds.pas 26 KB

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