link.ld 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * linker script for GD32E230x with GNU ld
  3. * Adapted from GD32E50x version.
  4. * Corrected by Gemini to fix oversized .bin file and subsequent linker errors.
  5. */
  6. MEMORY
  7. {
  8. /*
  9. * IMPORTANT: Please check your specific chip's datasheet for correct memory sizes.
  10. * The following values are for a GD32E230 with 64KB Flash and 8KB SRAM.
  11. */
  12. CODE (rx) : ORIGIN = 0x08000000, LENGTH = 64k /* MODIFIED: 64KB flash */
  13. DATA (rw) : ORIGIN = 0x20000000, LENGTH = 8k /* MODIFIED: 8KB sram */
  14. }
  15. /* Program Entry, set to mark it as "used" and avoid gc */
  16. ENTRY(Reset_Handler)
  17. /*
  18. * Define the size of the stack used by the system.
  19. * This is for the main stack pointer (MSP), used before RT-Thread scheduler starts and in interrupts.
  20. * Increased to 1KB for safety.
  21. */
  22. _system_stack_size = 0x400; /* MODIFIED: 1024 bytes */
  23. SECTIONS
  24. {
  25. .text :
  26. {
  27. . = ALIGN(4);
  28. _stext = .;
  29. KEEP(*(.isr_vector)) /* Startup code */
  30. . = ALIGN(4);
  31. *(.text) /* remaining code */
  32. *(.text.*) /* remaining code */
  33. *(.rodata) /* read-only data (constants) */
  34. *(.rodata*)
  35. *(.glue_7)
  36. *(.glue_7t)
  37. *(.gnu.linkonce.t*)
  38. /* section information for finsh shell */
  39. . = ALIGN(4);
  40. __fsymtab_start = .;
  41. KEEP(*(FSymTab))
  42. __fsymtab_end = .;
  43. . = ALIGN(4);
  44. __vsymtab_start = .;
  45. KEEP(*(VSymTab))
  46. __vsymtab_end = .;
  47. . = ALIGN(4);
  48. /* section information for initial. */
  49. . = ALIGN(4);
  50. __rt_init_start = .;
  51. KEEP(*(SORT(.rti_fn*)))
  52. __rt_init_end = .;
  53. . = ALIGN(4);
  54. . = ALIGN(4);
  55. _etext = .;
  56. } > CODE
  57. /*
  58. * The .ARM.exidx section is needed for exception handling and stack unwinding.
  59. * It should be placed in a loadable region like CODE.
  60. */
  61. .ARM.exidx :
  62. {
  63. __exidx_start = .;
  64. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  65. __exidx_end = .;
  66. } > CODE
  67. /*
  68. * Define the load address for the .data section.
  69. * It should immediately follow the .ARM.exidx section in Flash.
  70. */
  71. _sidata = __exidx_end;
  72. /* .data section which is used for initialized data */
  73. .data : AT (_sidata)
  74. {
  75. . = ALIGN(4);
  76. _sdata = . ;
  77. *(.data)
  78. *(.data.*)
  79. *(.gnu.linkonce.d*)
  80. . = ALIGN(4);
  81. _edata = . ;
  82. } > DATA
  83. /* Main stack, located at the top of the RAM region */
  84. .stack (NOLOAD):
  85. {
  86. . = ALIGN(8);
  87. _sstack = .;
  88. . = . + _system_stack_size;
  89. . = ALIGN(8);
  90. _estack = .;
  91. } > DATA
  92. /* .bss section which is used for uninitialized data */
  93. .bss :
  94. {
  95. . = ALIGN(4);
  96. _sbss = .;
  97. *(.bss)
  98. *(.bss.*)
  99. *(COMMON)
  100. . = ALIGN(4);
  101. _ebss = . ;
  102. } > DATA
  103. /* Define __bss_end for C code to find the heap start. */
  104. __bss_end = _ebss;
  105. _end = .;
  106. /******************************************************************************
  107. * Corrected section to discard unwanted information from the final binary. *
  108. ******************************************************************************/
  109. /DISCARD/ :
  110. {
  111. libc.a ( * )
  112. libm.a ( * )
  113. libgcc.a ( * )
  114. /* Discard all debugging and comment sections using the correct wildcard syntax */
  115. *(.comment)
  116. *(.note.gnu.build-id)
  117. *(.ARM.attributes)
  118. }
  119. }