2
0

max80.ld 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* -*- ld-script -*-
  2. *
  3. * Linker script for MAX80 firmware
  4. */
  5. #include "sys.h"
  6. OUTPUT_FORMAT("elf32-littleriscv", "elf32-littleriscv",
  7. "elf32-littleriscv")
  8. OUTPUT_ARCH(riscv)
  9. ENTRY(_start)
  10. MEMORY
  11. {
  12. SRAM : org = SRAM_ADDR, len = SRAM_SIZE
  13. DRAM : org = SDRAM_ADDR, len = SDRAM_SIZE
  14. }
  15. SECTIONS
  16. {
  17. /*
  18. * Sections we do not need. This program cannot exit, so
  19. * fini/destructors are never needed. Exception handling
  20. * is not supported.
  21. */
  22. /DISCARD/ : {
  23. *(.note.GNU-stack)
  24. *(.gnu_debuglink)
  25. *(.gnu.lto_*)
  26. *(.discard)
  27. *(.discard.*)
  28. *(.dtors.*)
  29. *(.dtors)
  30. *(.fini_array)
  31. *(.fini_array.*)
  32. *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*)
  33. *(.eh_frame) *(.eh_frame.*)
  34. *(.gcc_except_table .gcc_except_table.*)
  35. *(.gnu_extab*)
  36. *(.exception_ranges*)
  37. *crtbegin.o(*)
  38. }
  39. PROVIDE (__executable_start = _PC_RESET);
  40. .init.reset _PC_RESET : ALIGN(4) {
  41. PROVIDE (___reset = .);
  42. KEEP (*(SORT_NONE(.init.reset)))
  43. } >SRAM
  44. .init.irq _PC_IRQ : ALIGN(4) {
  45. PROVIDE (___irq = .);
  46. KEEP (*(SORT_NONE(.init.irq)))
  47. }
  48. .text : ALIGN(4) {
  49. KEEP (*(SORT_NONE(.init)))
  50. *(.text.unlikely .text.*_unlikely .text.unlikely.*)
  51. *(.text.exit .text.exit.*)
  52. *(.text.startup .text.startup.*)
  53. *(.text.hot .text.hot.*)
  54. *(SORT(.text.sorted.*))
  55. *(.text .stub .text.* .gnu.linkonce.t.*)
  56. /* .gnu.warning sections are handled specially by elf.em. */
  57. *(.gnu.warning)
  58. }
  59. PROVIDE (__etext = .);
  60. PROVIDE (_etext = .);
  61. . = ALIGN(4);
  62. .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
  63. .rodata1 : { *(.rodata1) }
  64. .sdata2 : {
  65. *(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
  66. }
  67. .sbss2 : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) }
  68. /* Thread Local Storage sections */
  69. .tdata : {
  70. PROVIDE_HIDDEN (__tdata_start = .);
  71. *(.tdata .tdata.* .gnu.linkonce.td.*)
  72. }
  73. .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
  74. .preinit_array : {
  75. PROVIDE_HIDDEN (__preinit_array_start = .);
  76. KEEP (*(.preinit_array))
  77. PROVIDE_HIDDEN (__preinit_array_end = .);
  78. }
  79. .init_array : {
  80. PROVIDE_HIDDEN (__init_array_start = .);
  81. KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)
  82. SORT_BY_INIT_PRIORITY(.ctors.*)))
  83. KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  84. PROVIDE_HIDDEN (__init_array_end = .);
  85. }
  86. /* Are these necessary/supportable? */
  87. .jcr : { KEEP (*(.jcr)) }
  88. .data.rel.ro : {
  89. *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*)
  90. }
  91. .data : {
  92. __DATA_BEGIN__ = .;
  93. *(.data .data.* .gnu.linkonce.d.*)
  94. SORT(CONSTRUCTORS)
  95. }
  96. .data1 : { *(.data1) }
  97. /* We want the small data sections together, so single-instruction offsets
  98. can access them all, and initialized data all before uninitialized, so
  99. we can shorten the on-disk segment size. */
  100. .sdata : {
  101. __SDATA_BEGIN__ = .;
  102. *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4)
  103. *(.srodata.cst2) *(.srodata .srodata.*)
  104. *(.sdata .sdata.* .gnu.linkonce.s.*)
  105. }
  106. _edata = .;
  107. . = ALIGN(16);
  108. __bss_start = .;
  109. .sbss : {
  110. *(.dynsbss)
  111. *(.sbss .sbss.* .gnu.linkonce.sb.*)
  112. *(.scommon)
  113. }
  114. .bss : {
  115. *(.dynbss)
  116. *(.bss .bss.* .gnu.linkonce.b.*)
  117. *(COMMON)
  118. /* Align here to ensure that the .bss section occupies space up to
  119. _end. Align after .bss to ensure correct alignment even if the
  120. .bss section disappears because there are no input sections.
  121. FIXME: Why do we need it? When there is no .bss section, we do not
  122. pad the .data section. */
  123. . = ALIGN(16);
  124. }
  125. . = SEGMENT_START("ldata-segment", .);
  126. . = ALIGN(16);
  127. __BSS_END__ = .;
  128. .stack STACK_BOTTOM : {
  129. KEEP (*(.stack))
  130. }
  131. __global_pointer$ = MIN(__SDATA_BEGIN__ + 0x800,
  132. MAX(__DATA_BEGIN__ + 0x800, __BSS_END__ - 0x800));
  133. _end = .;
  134. }