Link.ld 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. ENTRY( _start )
  2. __stack_size = 512;
  3. PROVIDE( _stack_size = __stack_size );
  4. MEMORY
  5. {
  6. /* CH32V002 */
  7. /*
  8. FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 16K
  9. RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 4K
  10. */
  11. /* CH32V004_CH32V005 */
  12. /*
  13. FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 32K
  14. RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 6K
  15. */
  16. /* CH32V006_CH32V007_CH32M007 */
  17. /**/
  18. FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 62K
  19. RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K
  20. }
  21. SECTIONS
  22. {
  23. .init :
  24. {
  25. _sinit = .;
  26. . = ALIGN(4);
  27. KEEP(*(SORT_NONE(.init)))
  28. . = ALIGN(4);
  29. _einit = .;
  30. } >FLASH AT>FLASH
  31. .text :
  32. {
  33. . = ALIGN(4);
  34. *(.text)
  35. *(.text.*)
  36. *(.rodata)
  37. *(.rodata*)
  38. *(.gnu.linkonce.t.*)
  39. . = ALIGN(4);
  40. } >FLASH AT>FLASH
  41. .fini :
  42. {
  43. KEEP(*(SORT_NONE(.fini)))
  44. . = ALIGN(4);
  45. } >FLASH AT>FLASH
  46. PROVIDE( _etext = . );
  47. PROVIDE( _eitcm = . );
  48. .preinit_array :
  49. {
  50. PROVIDE_HIDDEN (__preinit_array_start = .);
  51. KEEP (*(.preinit_array))
  52. PROVIDE_HIDDEN (__preinit_array_end = .);
  53. } >FLASH AT>FLASH
  54. .init_array :
  55. {
  56. PROVIDE_HIDDEN (__init_array_start = .);
  57. KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
  58. KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
  59. PROVIDE_HIDDEN (__init_array_end = .);
  60. } >FLASH AT>FLASH
  61. .fini_array :
  62. {
  63. PROVIDE_HIDDEN (__fini_array_start = .);
  64. KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
  65. KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
  66. PROVIDE_HIDDEN (__fini_array_end = .);
  67. } >FLASH AT>FLASH
  68. .ctors :
  69. {
  70. /* gcc uses crtbegin.o to find the start of
  71. the constructors, so we make sure it is
  72. first. Because this is a wildcard, it
  73. doesn't matter if the user does not
  74. actually link against crtbegin.o; the
  75. linker won't look for a file to match a
  76. wildcard. The wildcard also means that it
  77. doesn't matter which directory crtbegin.o
  78. is in. */
  79. KEEP (*crtbegin.o(.ctors))
  80. KEEP (*crtbegin?.o(.ctors))
  81. /* We don't want to include the .ctor section from
  82. the crtend.o file until after the sorted ctors.
  83. The .ctor section from the crtend file contains the
  84. end of ctors marker and it must be last */
  85. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
  86. KEEP (*(SORT(.ctors.*)))
  87. KEEP (*(.ctors))
  88. } >FLASH AT>FLASH
  89. .dtors :
  90. {
  91. KEEP (*crtbegin.o(.dtors))
  92. KEEP (*crtbegin?.o(.dtors))
  93. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
  94. KEEP (*(SORT(.dtors.*)))
  95. KEEP (*(.dtors))
  96. } >FLASH AT>FLASH
  97. .dalign :
  98. {
  99. . = ALIGN(4);
  100. PROVIDE(_data_vma = .);
  101. } >RAM AT>FLASH
  102. .dlalign :
  103. {
  104. . = ALIGN(4);
  105. PROVIDE(_data_lma = .);
  106. } >FLASH AT>FLASH
  107. .data :
  108. {
  109. . = ALIGN(4);
  110. *(.gnu.linkonce.r.*)
  111. *(.data .data.*)
  112. *(.gnu.linkonce.d.*)
  113. . = ALIGN(8);
  114. PROVIDE( __global_pointer$ = . + 0x800 );
  115. *(.sdata .sdata.*)
  116. *(.sdata2*)
  117. *(.gnu.linkonce.s.*)
  118. . = ALIGN(8);
  119. *(.srodata.cst16)
  120. *(.srodata.cst8)
  121. *(.srodata.cst4)
  122. *(.srodata.cst2)
  123. *(.srodata .srodata.*)
  124. . = ALIGN(4);
  125. PROVIDE( _edata = .);
  126. } >RAM AT>FLASH
  127. .bss :
  128. {
  129. . = ALIGN(4);
  130. PROVIDE( _sbss = .);
  131. *(.sbss*)
  132. *(.gnu.linkonce.sb.*)
  133. *(.bss*)
  134. *(.gnu.linkonce.b.*)
  135. *(COMMON*)
  136. . = ALIGN(4);
  137. PROVIDE( _ebss = .);
  138. } >RAM AT>FLASH
  139. PROVIDE( _end = _ebss);
  140. PROVIDE( end = . );
  141. .stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size :
  142. {
  143. PROVIDE( _heap_end = . );
  144. . = ALIGN(4);
  145. PROVIDE(_susrstack = . );
  146. . = . + __stack_size;
  147. PROVIDE( _eusrstack = .);
  148. } >RAM
  149. }