vmlinux.lds.S 9.6 KB

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