vmlinux.lds.S 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 4
  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/kexec.h>
  59. #include <asm/memory.h>
  60. #include <asm/page.h>
  61. #include "image.h"
  62. OUTPUT_ARCH(aarch64)
  63. ENTRY(_text)
  64. jiffies = jiffies_64;
  65. #define HYPERVISOR_TEXT \
  66. . = ALIGN(PAGE_SIZE); \
  67. __hyp_idmap_text_start = .; \
  68. *(.hyp.idmap.text) \
  69. __hyp_idmap_text_end = .; \
  70. __hyp_text_start = .; \
  71. *(.hyp.text) \
  72. HYPERVISOR_EXTABLE \
  73. . = ALIGN(PAGE_SIZE); \
  74. __hyp_text_end = .;
  75. #define IDMAP_TEXT \
  76. . = ALIGN(SZ_4K); \
  77. __idmap_text_start = .; \
  78. *(.idmap.text) \
  79. __idmap_text_end = .;
  80. #ifdef CONFIG_HIBERNATION
  81. #define HIBERNATE_TEXT \
  82. ALIGN_FUNCTION(); \
  83. __hibernate_exit_text_start = .; \
  84. *(.hibernate_exit.text) \
  85. __hibernate_exit_text_end = .;
  86. #else
  87. #define HIBERNATE_TEXT
  88. #endif
  89. #ifdef CONFIG_KEXEC_CORE
  90. #define KEXEC_TEXT \
  91. ALIGN_FUNCTION(); \
  92. __relocate_new_kernel_start = .; \
  93. *(.kexec_relocate.text) \
  94. __relocate_new_kernel_end = .;
  95. #else
  96. #define KEXEC_TEXT
  97. #endif
  98. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  99. #define TRAMP_TEXT \
  100. . = ALIGN(PAGE_SIZE); \
  101. __entry_tramp_text_start = .; \
  102. *(.entry.tramp.text) \
  103. . = ALIGN(PAGE_SIZE); \
  104. __entry_tramp_text_end = .; \
  105. *(.entry.tramp.rodata)
  106. #else
  107. #define TRAMP_TEXT
  108. #endif
  109. #ifdef CONFIG_UNWIND_TABLES
  110. #define UNWIND_DATA_SECTIONS \
  111. .eh_frame : { \
  112. __pi___eh_frame_start = .; \
  113. *(.eh_frame) \
  114. __pi___eh_frame_end = .; \
  115. }
  116. #else
  117. #define UNWIND_DATA_SECTIONS
  118. #endif
  119. /*
  120. * The size of the PE/COFF section that covers the kernel image, which
  121. * runs from _stext to _edata, must be a round multiple of the PE/COFF
  122. * FileAlignment, which we set to its minimum value of 0x200. '_stext'
  123. * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
  124. * boundary should be sufficient.
  125. */
  126. PECOFF_FILE_ALIGNMENT = 0x200;
  127. #ifdef CONFIG_EFI
  128. #define PECOFF_EDATA_PADDING \
  129. .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
  130. #else
  131. #define PECOFF_EDATA_PADDING
  132. #endif
  133. SECTIONS
  134. {
  135. /*
  136. * XXX: The linker does not define how output sections are
  137. * assigned to input sections when there are multiple statements
  138. * matching the same input section name. There is no documented
  139. * order of matching.
  140. */
  141. DISCARDS
  142. /DISCARD/ : {
  143. *(.interp .dynamic)
  144. *(.dynsym .dynstr .hash .gnu.hash)
  145. *(.ARM.attributes)
  146. }
  147. . = KIMAGE_VADDR;
  148. .head.text : {
  149. _text = .;
  150. HEAD_TEXT
  151. }
  152. .text : ALIGN(SEGMENT_ALIGN) { /* Real text segment */
  153. _stext = .; /* Text and read-only data */
  154. IRQENTRY_TEXT
  155. SOFTIRQENTRY_TEXT
  156. ENTRY_TEXT
  157. TEXT_TEXT
  158. SCHED_TEXT
  159. LOCK_TEXT
  160. KPROBES_TEXT
  161. HYPERVISOR_TEXT
  162. *(.gnu.warning)
  163. }
  164. . = ALIGN(SEGMENT_ALIGN);
  165. _etext = .; /* End of text section */
  166. /* everything from this point to __init_begin will be marked RO NX */
  167. RO_DATA(PAGE_SIZE)
  168. HYPERVISOR_DATA_SECTIONS
  169. .got : { *(.got) }
  170. /*
  171. * Make sure that the .got.plt is either completely empty or it
  172. * contains only the lazy dispatch entries.
  173. */
  174. .got.plt : { *(.got.plt) }
  175. ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
  176. "Unexpected GOT/PLT entries detected!")
  177. /* code sections that are never executed via the kernel mapping */
  178. .rodata.text : {
  179. TRAMP_TEXT
  180. HIBERNATE_TEXT
  181. KEXEC_TEXT
  182. IDMAP_TEXT
  183. . = ALIGN(PAGE_SIZE);
  184. }
  185. idmap_pg_dir = .;
  186. . += PAGE_SIZE;
  187. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  188. tramp_pg_dir = .;
  189. . += PAGE_SIZE;
  190. #endif
  191. reserved_pg_dir = .;
  192. . += PAGE_SIZE;
  193. swapper_pg_dir = .;
  194. . += PAGE_SIZE;
  195. . = ALIGN(SEGMENT_ALIGN);
  196. __init_begin = .;
  197. __inittext_begin = .;
  198. INIT_TEXT_SECTION(8)
  199. __exittext_begin = .;
  200. .exit.text : {
  201. EXIT_TEXT
  202. }
  203. __exittext_end = .;
  204. . = ALIGN(4);
  205. .altinstructions : {
  206. __alt_instructions = .;
  207. *(.altinstructions)
  208. __alt_instructions_end = .;
  209. }
  210. UNWIND_DATA_SECTIONS
  211. . = ALIGN(SEGMENT_ALIGN);
  212. __inittext_end = .;
  213. __initdata_begin = .;
  214. init_idmap_pg_dir = .;
  215. . += INIT_IDMAP_DIR_SIZE;
  216. init_idmap_pg_end = .;
  217. .init.data : {
  218. INIT_DATA
  219. INIT_SETUP(16)
  220. INIT_CALLS
  221. CON_INITCALL
  222. INIT_RAM_FS
  223. *(.init.altinstructions .init.bss) /* from the EFI stub */
  224. }
  225. .exit.data : {
  226. EXIT_DATA
  227. }
  228. RUNTIME_CONST_VARIABLES
  229. PERCPU_SECTION(L1_CACHE_BYTES)
  230. HYPERVISOR_PERCPU_SECTION
  231. HYPERVISOR_RELOC_SECTION
  232. .rela.dyn : ALIGN(8) {
  233. __pi_rela_start = .;
  234. *(.rela .rela*)
  235. __pi_rela_end = .;
  236. }
  237. .relr.dyn : ALIGN(8) {
  238. __pi_relr_start = .;
  239. *(.relr.dyn)
  240. __pi_relr_end = .;
  241. }
  242. . = ALIGN(SEGMENT_ALIGN);
  243. __initdata_end = .;
  244. __init_end = .;
  245. .data.rel.ro : { *(.data.rel.ro) }
  246. ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
  247. _data = .;
  248. _sdata = .;
  249. RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
  250. /*
  251. * Data written with the MMU off but read with the MMU on requires
  252. * cache lines to be invalidated, discarding up to a Cache Writeback
  253. * Granule (CWG) of data from the cache. Keep the section that
  254. * requires this type of maintenance to be in its own Cache Writeback
  255. * Granule (CWG) area so the cache maintenance operations don't
  256. * interfere with adjacent data.
  257. */
  258. .mmuoff.data.write : ALIGN(SZ_2K) {
  259. __mmuoff_data_start = .;
  260. *(.mmuoff.data.write)
  261. }
  262. . = ALIGN(SZ_2K);
  263. .mmuoff.data.read : {
  264. *(.mmuoff.data.read)
  265. __mmuoff_data_end = .;
  266. }
  267. PECOFF_EDATA_PADDING
  268. __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
  269. _edata = .;
  270. /* start of zero-init region */
  271. BSS_SECTION(SBSS_ALIGN, 0, 0)
  272. . = ALIGN(PAGE_SIZE);
  273. init_pg_dir = .;
  274. . += INIT_DIR_SIZE;
  275. init_pg_end = .;
  276. /* end of zero-init region */
  277. . += SZ_4K; /* stack for the early C runtime */
  278. early_init_stack = .;
  279. . = ALIGN(SEGMENT_ALIGN);
  280. __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
  281. _end = .;
  282. STABS_DEBUG
  283. DWARF_DEBUG
  284. ELF_DETAILS
  285. HEAD_SYMBOLS
  286. /*
  287. * Sections that should stay zero sized, which is safer to
  288. * explicitly check instead of blindly discarding.
  289. */
  290. .plt : {
  291. *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
  292. }
  293. ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
  294. }
  295. #include "image-vars.h"
  296. /*
  297. * The HYP init code and ID map text can't be longer than a page each. The
  298. * former is page-aligned, but the latter may not be with 16K or 64K pages, so
  299. * it should also not cross a page boundary.
  300. */
  301. ASSERT(__hyp_idmap_text_end - __hyp_idmap_text_start <= PAGE_SIZE,
  302. "HYP init code too big")
  303. ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
  304. "ID map text too big or misaligned")
  305. #ifdef CONFIG_HIBERNATION
  306. ASSERT(__hibernate_exit_text_end - __hibernate_exit_text_start <= SZ_4K,
  307. "Hibernate exit text is bigger than 4 KiB")
  308. ASSERT(__hibernate_exit_text_start == swsusp_arch_suspend_exit,
  309. "Hibernate exit text does not start with swsusp_arch_suspend_exit")
  310. #endif
  311. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  312. ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE,
  313. "Entry trampoline text too big")
  314. #endif
  315. #ifdef CONFIG_KVM
  316. ASSERT(__hyp_bss_start == __bss_start, "HYP and Host BSS are misaligned")
  317. #endif
  318. /*
  319. * If padding is applied before .head.text, virt<->phys conversions will fail.
  320. */
  321. ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")
  322. ASSERT(swapper_pg_dir - reserved_pg_dir == RESERVED_SWAPPER_OFFSET,
  323. "RESERVED_SWAPPER_OFFSET is wrong!")
  324. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  325. ASSERT(swapper_pg_dir - tramp_pg_dir == TRAMP_SWAPPER_OFFSET,
  326. "TRAMP_SWAPPER_OFFSET is wrong!")
  327. #endif
  328. #ifdef CONFIG_KEXEC_CORE
  329. /* kexec relocation code should fit into one KEXEC_CONTROL_PAGE_SIZE */
  330. ASSERT(__relocate_new_kernel_end - __relocate_new_kernel_start <= SZ_4K,
  331. "kexec relocation code is bigger than 4 KiB")
  332. ASSERT(KEXEC_CONTROL_PAGE_SIZE >= SZ_4K, "KEXEC_CONTROL_PAGE_SIZE is broken")
  333. ASSERT(__relocate_new_kernel_start == arm64_relocate_new_kernel,
  334. "kexec control page does not start with arm64_relocate_new_kernel")
  335. #endif