vmlinux.lds.S 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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/hyp_image.h>
  8. #ifdef CONFIG_KVM
  9. #define HYPERVISOR_EXTABLE \
  10. . = ALIGN(SZ_8); \
  11. __start___kvm_ex_table = .; \
  12. *(__kvm_ex_table) \
  13. __stop___kvm_ex_table = .;
  14. #define HYPERVISOR_DATA_SECTIONS \
  15. HYP_SECTION_NAME(.rodata) : { \
  16. . = ALIGN(PAGE_SIZE); \
  17. __hyp_rodata_start = .; \
  18. *(HYP_SECTION_NAME(.data..ro_after_init)) \
  19. *(HYP_SECTION_NAME(.rodata)) \
  20. . = ALIGN(PAGE_SIZE); \
  21. __hyp_rodata_end = .; \
  22. }
  23. #define HYPERVISOR_PERCPU_SECTION \
  24. . = ALIGN(PAGE_SIZE); \
  25. HYP_SECTION_NAME(.data..percpu) : { \
  26. *(HYP_SECTION_NAME(.data..percpu)) \
  27. }
  28. #define HYPERVISOR_RELOC_SECTION \
  29. .hyp.reloc : ALIGN(4) { \
  30. __hyp_reloc_begin = .; \
  31. *(.hyp.reloc) \
  32. __hyp_reloc_end = .; \
  33. }
  34. #define BSS_FIRST_SECTIONS \
  35. __hyp_bss_start = .; \
  36. *(HYP_SECTION_NAME(.bss)) \
  37. . = ALIGN(PAGE_SIZE); \
  38. __hyp_bss_end = .;
  39. /*
  40. * We require that __hyp_bss_start and __bss_start are aligned, and enforce it
  41. * with an assertion. But the BSS_SECTION macro places an empty .sbss section
  42. * between them, which can in some cases cause the linker to misalign them. To
  43. * work around the issue, force a page alignment for __bss_start.
  44. */
  45. #define SBSS_ALIGN PAGE_SIZE
  46. #else /* CONFIG_KVM */
  47. #define HYPERVISOR_EXTABLE
  48. #define HYPERVISOR_DATA_SECTIONS
  49. #define HYPERVISOR_PERCPU_SECTION
  50. #define HYPERVISOR_RELOC_SECTION
  51. #define SBSS_ALIGN 0
  52. #endif
  53. #define RO_EXCEPTION_TABLE_ALIGN 8
  54. #define RUNTIME_DISCARD_EXIT
  55. #include <asm-generic/vmlinux.lds.h>
  56. #include <asm/cache.h>
  57. #include <asm/kernel-pgtable.h>
  58. #include <asm/memory.h>
  59. #include <asm/page.h>
  60. #include "image.h"
  61. OUTPUT_ARCH(aarch64)
  62. ENTRY(_text)
  63. jiffies = jiffies_64;
  64. #define HYPERVISOR_TEXT \
  65. . = ALIGN(PAGE_SIZE); \
  66. __hyp_idmap_text_start = .; \
  67. *(.hyp.idmap.text) \
  68. __hyp_idmap_text_end = .; \
  69. __hyp_text_start = .; \
  70. *(.hyp.text) \
  71. HYPERVISOR_EXTABLE \
  72. . = ALIGN(PAGE_SIZE); \
  73. __hyp_text_end = .;
  74. #define IDMAP_TEXT \
  75. . = ALIGN(SZ_4K); \
  76. __idmap_text_start = .; \
  77. *(.idmap.text) \
  78. __idmap_text_end = .;
  79. #ifdef CONFIG_HIBERNATION
  80. #define HIBERNATE_TEXT \
  81. . = ALIGN(SZ_4K); \
  82. __hibernate_exit_text_start = .; \
  83. *(.hibernate_exit.text) \
  84. __hibernate_exit_text_end = .;
  85. #else
  86. #define HIBERNATE_TEXT
  87. #endif
  88. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  89. #define TRAMP_TEXT \
  90. . = ALIGN(PAGE_SIZE); \
  91. __entry_tramp_text_start = .; \
  92. *(.entry.tramp.text) \
  93. . = ALIGN(PAGE_SIZE); \
  94. __entry_tramp_text_end = .;
  95. #else
  96. #define TRAMP_TEXT
  97. #endif
  98. /*
  99. * The size of the PE/COFF section that covers the kernel image, which
  100. * runs from _stext to _edata, must be a round multiple of the PE/COFF
  101. * FileAlignment, which we set to its minimum value of 0x200. '_stext'
  102. * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
  103. * boundary should be sufficient.
  104. */
  105. PECOFF_FILE_ALIGNMENT = 0x200;
  106. #ifdef CONFIG_EFI
  107. #define PECOFF_EDATA_PADDING \
  108. .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
  109. #else
  110. #define PECOFF_EDATA_PADDING
  111. #endif
  112. SECTIONS
  113. {
  114. /*
  115. * XXX: The linker does not define how output sections are
  116. * assigned to input sections when there are multiple statements
  117. * matching the same input section name. There is no documented
  118. * order of matching.
  119. */
  120. DISCARDS
  121. /DISCARD/ : {
  122. *(.interp .dynamic)
  123. *(.dynsym .dynstr .hash .gnu.hash)
  124. }
  125. . = KIMAGE_VADDR;
  126. .head.text : {
  127. _text = .;
  128. HEAD_TEXT
  129. }
  130. .text : { /* Real text segment */
  131. _stext = .; /* Text and read-only data */
  132. IRQENTRY_TEXT
  133. SOFTIRQENTRY_TEXT
  134. ENTRY_TEXT
  135. TEXT_TEXT
  136. SCHED_TEXT
  137. CPUIDLE_TEXT
  138. LOCK_TEXT
  139. KPROBES_TEXT
  140. HYPERVISOR_TEXT
  141. IDMAP_TEXT
  142. HIBERNATE_TEXT
  143. TRAMP_TEXT
  144. *(.fixup)
  145. *(.gnu.warning)
  146. . = ALIGN(16);
  147. *(.got) /* Global offset table */
  148. }
  149. /*
  150. * Make sure that the .got.plt is either completely empty or it
  151. * contains only the lazy dispatch entries.
  152. */
  153. .got.plt : { *(.got.plt) }
  154. ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
  155. "Unexpected GOT/PLT entries detected!")
  156. . = ALIGN(SEGMENT_ALIGN);
  157. _etext = .; /* End of text section */
  158. /* everything from this point to __init_begin will be marked RO NX */
  159. RO_DATA(PAGE_SIZE)
  160. HYPERVISOR_DATA_SECTIONS
  161. idmap_pg_dir = .;
  162. . += IDMAP_DIR_SIZE;
  163. idmap_pg_end = .;
  164. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  165. tramp_pg_dir = .;
  166. . += PAGE_SIZE;
  167. #endif
  168. reserved_pg_dir = .;
  169. . += PAGE_SIZE;
  170. swapper_pg_dir = .;
  171. . += PAGE_SIZE;
  172. . = ALIGN(SEGMENT_ALIGN);
  173. __init_begin = .;
  174. __inittext_begin = .;
  175. INIT_TEXT_SECTION(8)
  176. __exittext_begin = .;
  177. .exit.text : {
  178. EXIT_TEXT
  179. }
  180. __exittext_end = .;
  181. . = ALIGN(4);
  182. .altinstructions : {
  183. __alt_instructions = .;
  184. *(.altinstructions)
  185. __alt_instructions_end = .;
  186. }
  187. . = ALIGN(SEGMENT_ALIGN);
  188. __inittext_end = .;
  189. __initdata_begin = .;
  190. .init.data : {
  191. INIT_DATA
  192. INIT_SETUP(16)
  193. INIT_CALLS
  194. CON_INITCALL
  195. INIT_RAM_FS
  196. *(.init.altinstructions .init.rodata.* .init.bss) /* from the EFI stub */
  197. }
  198. .exit.data : {
  199. EXIT_DATA
  200. }
  201. PERCPU_SECTION(L1_CACHE_BYTES)
  202. HYPERVISOR_PERCPU_SECTION
  203. HYPERVISOR_RELOC_SECTION
  204. .rela.dyn : ALIGN(8) {
  205. *(.rela .rela*)
  206. }
  207. __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
  208. __rela_size = SIZEOF(.rela.dyn);
  209. #ifdef CONFIG_RELR
  210. .relr.dyn : ALIGN(8) {
  211. *(.relr.dyn)
  212. }
  213. __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
  214. __relr_size = SIZEOF(.relr.dyn);
  215. #endif
  216. . = ALIGN(SEGMENT_ALIGN);
  217. __initdata_end = .;
  218. __init_end = .;
  219. _data = .;
  220. _sdata = .;
  221. RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
  222. /*
  223. * Data written with the MMU off but read with the MMU on requires
  224. * cache lines to be invalidated, discarding up to a Cache Writeback
  225. * Granule (CWG) of data from the cache. Keep the section that
  226. * requires this type of maintenance to be in its own Cache Writeback
  227. * Granule (CWG) area so the cache maintenance operations don't
  228. * interfere with adjacent data.
  229. */
  230. .mmuoff.data.write : ALIGN(SZ_2K) {
  231. __mmuoff_data_start = .;
  232. *(.mmuoff.data.write)
  233. }
  234. . = ALIGN(SZ_2K);
  235. .mmuoff.data.read : {
  236. *(.mmuoff.data.read)
  237. __mmuoff_data_end = .;
  238. }
  239. PECOFF_EDATA_PADDING
  240. __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
  241. _edata = .;
  242. BSS_SECTION(SBSS_ALIGN, 0, 0)
  243. . = ALIGN(PAGE_SIZE);
  244. init_pg_dir = .;
  245. . += INIT_DIR_SIZE;
  246. init_pg_end = .;
  247. . = ALIGN(SEGMENT_ALIGN);
  248. __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
  249. _end = .;
  250. STABS_DEBUG
  251. DWARF_DEBUG
  252. ELF_DETAILS
  253. HEAD_SYMBOLS
  254. /*
  255. * Sections that should stay zero sized, which is safer to
  256. * explicitly check instead of blindly discarding.
  257. */
  258. .plt : {
  259. *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
  260. }
  261. ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
  262. .data.rel.ro : { *(.data.rel.ro) }
  263. ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
  264. }
  265. #include "image-vars.h"
  266. /*
  267. * The HYP init code and ID map text can't be longer than a page each. The
  268. * former is page-aligned, but the latter may not be with 16K or 64K pages, so
  269. * it should also not cross a page boundary.
  270. */
  271. ASSERT(__hyp_idmap_text_end - __hyp_idmap_text_start <= PAGE_SIZE,
  272. "HYP init code too big")
  273. ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
  274. "ID map text too big or misaligned")
  275. #ifdef CONFIG_HIBERNATION
  276. ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
  277. <= SZ_4K, "Hibernate exit text too big or misaligned")
  278. #endif
  279. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  280. ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE,
  281. "Entry trampoline text too big")
  282. #endif
  283. #ifdef CONFIG_KVM
  284. ASSERT(__hyp_bss_start == __bss_start, "HYP and Host BSS are misaligned")
  285. #endif
  286. /*
  287. * If padding is applied before .head.text, virt<->phys conversions will fail.
  288. */
  289. ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")