vmlinux.lds.S 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * ld script to make ARM Linux kernel
  4. * taken from the i386 version by Russell King
  5. * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  6. */
  7. #include <asm-generic/vmlinux.lds.h>
  8. #include <asm/cache.h>
  9. #include <asm/kernel-pgtable.h>
  10. #include <asm/thread_info.h>
  11. #include <asm/memory.h>
  12. #include <asm/page.h>
  13. #include <asm/pgtable.h>
  14. #include "image.h"
  15. /* .exit.text needed in case of alternative patching */
  16. #define ARM_EXIT_KEEP(x) x
  17. #define ARM_EXIT_DISCARD(x)
  18. OUTPUT_ARCH(aarch64)
  19. ENTRY(_text)
  20. jiffies = jiffies_64;
  21. #define HYPERVISOR_TEXT \
  22. /* \
  23. * Align to 4 KB so that \
  24. * a) the HYP vector table is at its minimum \
  25. * alignment of 2048 bytes \
  26. * b) the HYP init code will not cross a page \
  27. * boundary if its size does not exceed \
  28. * 4 KB (see related ASSERT() below) \
  29. */ \
  30. . = ALIGN(SZ_4K); \
  31. __hyp_idmap_text_start = .; \
  32. *(.hyp.idmap.text) \
  33. __hyp_idmap_text_end = .; \
  34. __hyp_text_start = .; \
  35. *(.hyp.text) \
  36. __hyp_text_end = .;
  37. #define IDMAP_TEXT \
  38. . = ALIGN(SZ_4K); \
  39. __idmap_text_start = .; \
  40. *(.idmap.text) \
  41. __idmap_text_end = .;
  42. #ifdef CONFIG_HIBERNATION
  43. #define HIBERNATE_TEXT \
  44. . = ALIGN(SZ_4K); \
  45. __hibernate_exit_text_start = .; \
  46. *(.hibernate_exit.text) \
  47. __hibernate_exit_text_end = .;
  48. #else
  49. #define HIBERNATE_TEXT
  50. #endif
  51. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  52. #define TRAMP_TEXT \
  53. . = ALIGN(PAGE_SIZE); \
  54. __entry_tramp_text_start = .; \
  55. *(.entry.tramp.text) \
  56. . = ALIGN(PAGE_SIZE); \
  57. __entry_tramp_text_end = .;
  58. #else
  59. #define TRAMP_TEXT
  60. #endif
  61. /*
  62. * The size of the PE/COFF section that covers the kernel image, which
  63. * runs from stext to _edata, must be a round multiple of the PE/COFF
  64. * FileAlignment, which we set to its minimum value of 0x200. 'stext'
  65. * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
  66. * boundary should be sufficient.
  67. */
  68. PECOFF_FILE_ALIGNMENT = 0x200;
  69. #ifdef CONFIG_EFI
  70. #define PECOFF_EDATA_PADDING \
  71. .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
  72. #else
  73. #define PECOFF_EDATA_PADDING
  74. #endif
  75. SECTIONS
  76. {
  77. /*
  78. * XXX: The linker does not define how output sections are
  79. * assigned to input sections when there are multiple statements
  80. * matching the same input section name. There is no documented
  81. * order of matching.
  82. */
  83. /DISCARD/ : {
  84. ARM_EXIT_DISCARD(EXIT_TEXT)
  85. ARM_EXIT_DISCARD(EXIT_DATA)
  86. EXIT_CALL
  87. *(.discard)
  88. *(.discard.*)
  89. *(.interp .dynamic)
  90. *(.dynsym .dynstr .hash)
  91. }
  92. . = KIMAGE_VADDR + TEXT_OFFSET;
  93. .head.text : {
  94. _text = .;
  95. HEAD_TEXT
  96. }
  97. .text : { /* Real text segment */
  98. _stext = .; /* Text and read-only data */
  99. __exception_text_start = .;
  100. *(.exception.text)
  101. __exception_text_end = .;
  102. IRQENTRY_TEXT
  103. SOFTIRQENTRY_TEXT
  104. ENTRY_TEXT
  105. TEXT_TEXT
  106. SCHED_TEXT
  107. CPUIDLE_TEXT
  108. LOCK_TEXT
  109. KPROBES_TEXT
  110. HYPERVISOR_TEXT
  111. IDMAP_TEXT
  112. HIBERNATE_TEXT
  113. TRAMP_TEXT
  114. *(.fixup)
  115. *(.gnu.warning)
  116. . = ALIGN(16);
  117. *(.got) /* Global offset table */
  118. }
  119. . = ALIGN(SEGMENT_ALIGN);
  120. _etext = .; /* End of text section */
  121. RO_DATA(PAGE_SIZE) /* everything from this point to */
  122. EXCEPTION_TABLE(8) /* __init_begin will be marked RO NX */
  123. NOTES
  124. . = ALIGN(PAGE_SIZE);
  125. idmap_pg_dir = .;
  126. . += IDMAP_DIR_SIZE;
  127. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  128. tramp_pg_dir = .;
  129. . += PAGE_SIZE;
  130. #endif
  131. #ifdef CONFIG_ARM64_SW_TTBR0_PAN
  132. reserved_ttbr0 = .;
  133. . += RESERVED_TTBR0_SIZE;
  134. #endif
  135. swapper_pg_dir = .;
  136. . += PAGE_SIZE;
  137. swapper_pg_end = .;
  138. . = ALIGN(SEGMENT_ALIGN);
  139. __init_begin = .;
  140. __inittext_begin = .;
  141. INIT_TEXT_SECTION(8)
  142. .exit.text : {
  143. ARM_EXIT_KEEP(EXIT_TEXT)
  144. }
  145. . = ALIGN(4);
  146. .altinstructions : {
  147. __alt_instructions = .;
  148. *(.altinstructions)
  149. __alt_instructions_end = .;
  150. }
  151. .altinstr_replacement : {
  152. *(.altinstr_replacement)
  153. }
  154. . = ALIGN(PAGE_SIZE);
  155. __inittext_end = .;
  156. __initdata_begin = .;
  157. .init.data : {
  158. INIT_DATA
  159. INIT_SETUP(16)
  160. INIT_CALLS
  161. CON_INITCALL
  162. INIT_RAM_FS
  163. *(.init.rodata.* .init.bss) /* from the EFI stub */
  164. }
  165. .exit.data : {
  166. ARM_EXIT_KEEP(EXIT_DATA)
  167. }
  168. PERCPU_SECTION(L1_CACHE_BYTES)
  169. .rela : ALIGN(8) {
  170. *(.rela .rela*)
  171. }
  172. __rela_offset = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR);
  173. __rela_size = SIZEOF(.rela);
  174. . = ALIGN(SEGMENT_ALIGN);
  175. __initdata_end = .;
  176. __init_end = .;
  177. _data = .;
  178. _sdata = .;
  179. RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
  180. /*
  181. * Data written with the MMU off but read with the MMU on requires
  182. * cache lines to be invalidated, discarding up to a Cache Writeback
  183. * Granule (CWG) of data from the cache. Keep the section that
  184. * requires this type of maintenance to be in its own Cache Writeback
  185. * Granule (CWG) area so the cache maintenance operations don't
  186. * interfere with adjacent data.
  187. */
  188. .mmuoff.data.write : ALIGN(SZ_2K) {
  189. __mmuoff_data_start = .;
  190. *(.mmuoff.data.write)
  191. }
  192. . = ALIGN(SZ_2K);
  193. .mmuoff.data.read : {
  194. *(.mmuoff.data.read)
  195. __mmuoff_data_end = .;
  196. }
  197. PECOFF_EDATA_PADDING
  198. __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
  199. _edata = .;
  200. BSS_SECTION(0, 0, 0)
  201. . = ALIGN(PAGE_SIZE);
  202. init_pg_dir = .;
  203. . += INIT_DIR_SIZE;
  204. init_pg_end = .;
  205. __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
  206. _end = .;
  207. STABS_DEBUG
  208. HEAD_SYMBOLS
  209. }
  210. /*
  211. * The HYP init code and ID map text can't be longer than a page each,
  212. * and should not cross a page boundary.
  213. */
  214. ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
  215. "HYP init code too big or misaligned")
  216. ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
  217. "ID map text too big or misaligned")
  218. #ifdef CONFIG_HIBERNATION
  219. ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
  220. <= SZ_4K, "Hibernate exit text too big or misaligned")
  221. #endif
  222. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  223. ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
  224. "Entry trampoline text too big")
  225. #endif
  226. /*
  227. * If padding is applied before .head.text, virt<->phys conversions will fail.
  228. */
  229. ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")