link.lds.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Date Author Notes
  7. * 2017-5-30 bernard first version
  8. */
  9. #include "rtconfig.h"
  10. OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
  11. OUTPUT_ARCH(aarch64)
  12. #ifndef ARCH_TEXT_OFFSET
  13. #define ARCH_TEXT_OFFSET 0x200000 /* We always boot in address where is 2MB aligned */
  14. #endif
  15. #ifndef ARCH_RAM_OFFSET
  16. #define ARCH_RAM_OFFSET 0
  17. #endif
  18. PHDRS
  19. {
  20. text PT_LOAD FLAGS(5); /* PF_R(4) | PF_X(1) = 0x5 (RX) */
  21. data PT_LOAD FLAGS(6); /* PF_R(4) | PF_W(2) = 0x6 (RW) */
  22. stack PT_LOAD FLAGS(6); /* PF_R | PF_W */
  23. }
  24. SECTIONS
  25. {
  26. _text_offset = ARCH_TEXT_OFFSET;
  27. #ifdef RT_USING_SMART
  28. . = KERNEL_VADDR_START + _text_offset;
  29. #else
  30. . = ARCH_RAM_OFFSET + _text_offset;
  31. #endif
  32. .text :
  33. {
  34. PROVIDE(__text_start = .);
  35. KEEP(*(.text.entrypoint)) /* The entry point */
  36. *(.vectors)
  37. *(.text) /* remaining code */
  38. *(.text.*) /* remaining code */
  39. *(.rodata) /* read-only data (constants) */
  40. *(.rodata*)
  41. *(.glue_7)
  42. *(.glue_7t)
  43. *(.gnu.linkonce.t*)
  44. /* section information for utest */
  45. . = ALIGN(8);
  46. PROVIDE(__rt_utest_tc_tab_start = .);
  47. KEEP(*(UtestTcTab))
  48. PROVIDE(__rt_utest_tc_tab_end = .);
  49. /* section information for finsh shell */
  50. . = ALIGN(8);
  51. PROVIDE(__fsymtab_start = .);
  52. KEEP(*(FSymTab))
  53. PROVIDE(__fsymtab_end = .);
  54. . = ALIGN(8);
  55. PROVIDE(__vsymtab_start = .);
  56. KEEP(*(VSymTab))
  57. PROVIDE(__vsymtab_end = .);
  58. . = ALIGN(8);
  59. /* section information for modules */
  60. . = ALIGN(8);
  61. PROVIDE(__rtmsymtab_start = .);
  62. KEEP(*(RTMSymTab))
  63. PROVIDE(__rtmsymtab_end = .);
  64. /* section information for initialization */
  65. . = ALIGN(8);
  66. PROVIDE(__rt_init_start = .);
  67. KEEP(*(SORT(.rti_fn*)))
  68. PROVIDE(__rt_init_end = .);
  69. /* section information for rt_ofw. */
  70. . = ALIGN(16);
  71. PROVIDE(__rt_ofw_data_start = .);
  72. KEEP(*(SORT(.rt_ofw_data.*)))
  73. PROVIDE(__rt_ofw_data_end = .);
  74. . = ALIGN(16);
  75. /* section information for usb usbh_class_info */
  76. . = ALIGN(4);
  77. __usbh_class_info_start__ = .;
  78. KEEP(*(.usbh_class_info))
  79. . = ALIGN(4);
  80. __usbh_class_info_end__ = .;
  81. PROVIDE(__text_end = .);
  82. } :text
  83. .eh_frame_hdr :
  84. {
  85. *(.eh_frame_hdr)
  86. *(.eh_frame_entry)
  87. }
  88. .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }
  89. . = ALIGN(8);
  90. .data :
  91. {
  92. *(.data)
  93. *(.data.*)
  94. *(.data1)
  95. *(.data1.*)
  96. . = ALIGN(16);
  97. _gp = ABSOLUTE(.); /* Base of small data */
  98. *(.sdata)
  99. *(.sdata.*)
  100. *(.rel.local)
  101. } :data
  102. . = ALIGN(8);
  103. .ctors :
  104. {
  105. PROVIDE(__ctors_start__ = .);
  106. /* new GCC version uses .init_array */
  107. KEEP(*(SORT(.init_array.*)))
  108. KEEP(*(.init_array))
  109. PROVIDE(__ctors_end__ = .);
  110. }
  111. .dtors :
  112. {
  113. PROVIDE(__dtors_start__ = .);
  114. KEEP(*(SORT(.dtors.*)))
  115. KEEP(*(.dtors))
  116. PROVIDE(__dtors_end__ = .);
  117. }
  118. . = ALIGN(16);
  119. .bss :
  120. {
  121. /*
  122. * We need some free space to page or cpu stack, move .bss.noclean.*
  123. * to optimize size.
  124. */
  125. PROVIDE(__bss_noclean_start = .);
  126. *(.bss.noclean.*)
  127. PROVIDE(__bss_noclean_end = .);
  128. . = ALIGN(8);
  129. PROVIDE(__bss_start = .);
  130. *(.bss)
  131. *(.bss.*)
  132. *(.dynbss)
  133. *(COMMON)
  134. . = ALIGN(8);
  135. PROVIDE(__bss_end = .);
  136. }
  137. /*
  138. * We should make the bootloader know the size of memory we need,
  139. * so we MUST calc the image's size with section '.bss'.
  140. */
  141. _end = .;
  142. /* Stabs debugging sections. */
  143. .stab 0 : { *(.stab) }
  144. .stabstr 0 : { *(.stabstr) }
  145. .stab.excl 0 : { *(.stab.excl) }
  146. .stab.exclstr 0 : { *(.stab.exclstr) }
  147. .stab.index 0 : { *(.stab.index) }
  148. .stab.indexstr 0 : { *(.stab.indexstr) }
  149. .comment 0 : { *(.comment) }
  150. /* DWARF debug sections.
  151. * Symbols in the DWARF debugging sections are relative to the beginning
  152. * of the section so we begin them at 0. */
  153. /* DWARF 1 */
  154. .debug 0 : { *(.debug) }
  155. .line 0 : { *(.line) }
  156. /* GNU DWARF 1 extensions */
  157. .debug_srcinfo 0 : { *(.debug_srcinfo) }
  158. .debug_sfnames 0 : { *(.debug_sfnames) }
  159. /* DWARF 1.1 and DWARF 2 */
  160. .debug_aranges 0 : { *(.debug_aranges) }
  161. .debug_pubnames 0 : { *(.debug_pubnames) }
  162. /* DWARF 2 */
  163. .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
  164. .debug_abbrev 0 : { *(.debug_abbrev) }
  165. .debug_line 0 : { *(.debug_line) }
  166. .debug_frame 0 : { *(.debug_frame) }
  167. .debug_str 0 : { *(.debug_str) }
  168. .debug_loc 0 : { *(.debug_loc) }
  169. .debug_macinfo 0 : { *(.debug_macinfo) }
  170. /* SGI/MIPS DWARF 2 extensions */
  171. .debug_weaknames 0 : { *(.debug_weaknames) }
  172. .debug_funcnames 0 : { *(.debug_funcnames) }
  173. .debug_typenames 0 : { *(.debug_typenames) }
  174. .debug_varnames 0 : { *(.debug_varnames) }
  175. __data_size = SIZEOF(.data);
  176. __bss_size = SIZEOF(.bss);
  177. }