vmlinux.lds.S 6.5 KB

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