vmlinux.lds.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * ld script for the x86 kernel
  4. *
  5. * Historic 32-bit version written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  6. *
  7. * Modernisation, unification and other changes and fixes:
  8. * Copyright (C) 2007-2009 Sam Ravnborg <sam@ravnborg.org>
  9. *
  10. *
  11. * Don't define absolute symbols until and unless you know that symbol
  12. * value is should remain constant even if kernel image is relocated
  13. * at run time. Absolute symbols are not relocated. If symbol value should
  14. * change if kernel is relocated, make the symbol section relative and
  15. * put it inside the section definition.
  16. */
  17. #ifdef CONFIG_X86_32
  18. #define LOAD_OFFSET __PAGE_OFFSET
  19. #else
  20. #define LOAD_OFFSET __START_KERNEL_map
  21. #endif
  22. #include <asm-generic/vmlinux.lds.h>
  23. #include <asm/asm-offsets.h>
  24. #include <asm/thread_info.h>
  25. #include <asm/page_types.h>
  26. #include <asm/orc_lookup.h>
  27. #include <asm/cache.h>
  28. #include <asm/boot.h>
  29. #undef i386 /* in case the preprocessor is a 32bit one */
  30. OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT)
  31. #ifdef CONFIG_X86_32
  32. OUTPUT_ARCH(i386)
  33. ENTRY(phys_startup_32)
  34. jiffies = jiffies_64;
  35. #else
  36. OUTPUT_ARCH(i386:x86-64)
  37. ENTRY(phys_startup_64)
  38. jiffies_64 = jiffies;
  39. #endif
  40. #if defined(CONFIG_X86_64)
  41. /*
  42. * On 64-bit, align RODATA to 2MB so we retain large page mappings for
  43. * boundaries spanning kernel text, rodata and data sections.
  44. *
  45. * However, kernel identity mappings will have different RWX permissions
  46. * to the pages mapping to text and to the pages padding (which are freed) the
  47. * text section. Hence kernel identity mappings will be broken to smaller
  48. * pages. For 64-bit, kernel text and kernel identity mappings are different,
  49. * so we can enable protection checks as well as retain 2MB large page
  50. * mappings for kernel text.
  51. */
  52. #define X86_ALIGN_RODATA_BEGIN . = ALIGN(HPAGE_SIZE);
  53. #define X86_ALIGN_RODATA_END \
  54. . = ALIGN(HPAGE_SIZE); \
  55. __end_rodata_hpage_align = .; \
  56. __end_rodata_aligned = .;
  57. #define ALIGN_ENTRY_TEXT_BEGIN . = ALIGN(PMD_SIZE);
  58. #define ALIGN_ENTRY_TEXT_END . = ALIGN(PMD_SIZE);
  59. /*
  60. * This section contains data which will be mapped as decrypted. Memory
  61. * encryption operates on a page basis. Make this section PMD-aligned
  62. * to avoid splitting the pages while mapping the section early.
  63. *
  64. * Note: We use a separate section so that only this section gets
  65. * decrypted to avoid exposing more than we wish.
  66. */
  67. #define BSS_DECRYPTED \
  68. . = ALIGN(PMD_SIZE); \
  69. __start_bss_decrypted = .; \
  70. *(.bss..decrypted); \
  71. . = ALIGN(PAGE_SIZE); \
  72. __start_bss_decrypted_unused = .; \
  73. . = ALIGN(PMD_SIZE); \
  74. __end_bss_decrypted = .; \
  75. #else
  76. #define X86_ALIGN_RODATA_BEGIN
  77. #define X86_ALIGN_RODATA_END \
  78. . = ALIGN(PAGE_SIZE); \
  79. __end_rodata_aligned = .;
  80. #define ALIGN_ENTRY_TEXT_BEGIN
  81. #define ALIGN_ENTRY_TEXT_END
  82. #define BSS_DECRYPTED
  83. #endif
  84. PHDRS {
  85. text PT_LOAD FLAGS(5); /* R_E */
  86. data PT_LOAD FLAGS(6); /* RW_ */
  87. #ifdef CONFIG_X86_64
  88. #ifdef CONFIG_SMP
  89. percpu PT_LOAD FLAGS(6); /* RW_ */
  90. #endif
  91. init PT_LOAD FLAGS(7); /* RWE */
  92. #endif
  93. note PT_NOTE FLAGS(0); /* ___ */
  94. }
  95. SECTIONS
  96. {
  97. #ifdef CONFIG_X86_32
  98. . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
  99. phys_startup_32 = ABSOLUTE(startup_32 - LOAD_OFFSET);
  100. #else
  101. . = __START_KERNEL;
  102. phys_startup_64 = ABSOLUTE(startup_64 - LOAD_OFFSET);
  103. #endif
  104. /* Text and read-only data */
  105. .text : AT(ADDR(.text) - LOAD_OFFSET) {
  106. _text = .;
  107. _stext = .;
  108. /* bootstrapping code */
  109. HEAD_TEXT
  110. TEXT_TEXT
  111. SCHED_TEXT
  112. CPUIDLE_TEXT
  113. LOCK_TEXT
  114. KPROBES_TEXT
  115. ALIGN_ENTRY_TEXT_BEGIN
  116. ENTRY_TEXT
  117. IRQENTRY_TEXT
  118. ALIGN_ENTRY_TEXT_END
  119. SOFTIRQENTRY_TEXT
  120. *(.fixup)
  121. *(.gnu.warning)
  122. #ifdef CONFIG_RETPOLINE
  123. __indirect_thunk_start = .;
  124. *(.text.__x86.indirect_thunk)
  125. __indirect_thunk_end = .;
  126. #endif
  127. /* End of text section */
  128. _etext = .;
  129. } :text = 0x9090
  130. NOTES :text :note
  131. EXCEPTION_TABLE(16) :text = 0x9090
  132. /* .text should occupy whole number of pages */
  133. . = ALIGN(PAGE_SIZE);
  134. X86_ALIGN_RODATA_BEGIN
  135. RO_DATA(PAGE_SIZE)
  136. X86_ALIGN_RODATA_END
  137. /* Data */
  138. .data : AT(ADDR(.data) - LOAD_OFFSET) {
  139. /* Start of data section */
  140. _sdata = .;
  141. /* init_task */
  142. INIT_TASK_DATA(THREAD_SIZE)
  143. #ifdef CONFIG_X86_32
  144. /* 32 bit has nosave before _edata */
  145. NOSAVE_DATA
  146. #endif
  147. PAGE_ALIGNED_DATA(PAGE_SIZE)
  148. CACHELINE_ALIGNED_DATA(L1_CACHE_BYTES)
  149. DATA_DATA
  150. CONSTRUCTORS
  151. /* rarely changed data like cpu maps */
  152. READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES)
  153. /* End of data section */
  154. _edata = .;
  155. } :data
  156. BUG_TABLE
  157. ORC_UNWIND_TABLE
  158. . = ALIGN(PAGE_SIZE);
  159. __vvar_page = .;
  160. .vvar : AT(ADDR(.vvar) - LOAD_OFFSET) {
  161. /* work around gold bug 13023 */
  162. __vvar_beginning_hack = .;
  163. /* Place all vvars at the offsets in asm/vvar.h. */
  164. #define EMIT_VVAR(name, offset) \
  165. . = __vvar_beginning_hack + offset; \
  166. *(.vvar_ ## name)
  167. #define __VVAR_KERNEL_LDS
  168. #include <asm/vvar.h>
  169. #undef __VVAR_KERNEL_LDS
  170. #undef EMIT_VVAR
  171. /*
  172. * Pad the rest of the page with zeros. Otherwise the loader
  173. * can leave garbage here.
  174. */
  175. . = __vvar_beginning_hack + PAGE_SIZE;
  176. } :data
  177. . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
  178. /* Init code and data - will be freed after init */
  179. . = ALIGN(PAGE_SIZE);
  180. .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
  181. __init_begin = .; /* paired with __init_end */
  182. }
  183. #if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
  184. /*
  185. * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
  186. * output PHDR, so the next output section - .init.text - should
  187. * start another segment - init.
  188. */
  189. PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
  190. ASSERT(SIZEOF(.data..percpu) < CONFIG_PHYSICAL_START,
  191. "per-CPU data too large - increase CONFIG_PHYSICAL_START")
  192. #endif
  193. INIT_TEXT_SECTION(PAGE_SIZE)
  194. #ifdef CONFIG_X86_64
  195. :init
  196. #endif
  197. /*
  198. * Section for code used exclusively before alternatives are run. All
  199. * references to such code must be patched out by alternatives, normally
  200. * by using X86_FEATURE_ALWAYS CPU feature bit.
  201. *
  202. * See static_cpu_has() for an example.
  203. */
  204. .altinstr_aux : AT(ADDR(.altinstr_aux) - LOAD_OFFSET) {
  205. *(.altinstr_aux)
  206. }
  207. INIT_DATA_SECTION(16)
  208. .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
  209. __x86_cpu_dev_start = .;
  210. *(.x86_cpu_dev.init)
  211. __x86_cpu_dev_end = .;
  212. }
  213. #ifdef CONFIG_X86_INTEL_MID
  214. .x86_intel_mid_dev.init : AT(ADDR(.x86_intel_mid_dev.init) - \
  215. LOAD_OFFSET) {
  216. __x86_intel_mid_dev_start = .;
  217. *(.x86_intel_mid_dev.init)
  218. __x86_intel_mid_dev_end = .;
  219. }
  220. #endif
  221. /*
  222. * start address and size of operations which during runtime
  223. * can be patched with virtualization friendly instructions or
  224. * baremetal native ones. Think page table operations.
  225. * Details in paravirt_types.h
  226. */
  227. . = ALIGN(8);
  228. .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
  229. __parainstructions = .;
  230. *(.parainstructions)
  231. __parainstructions_end = .;
  232. }
  233. /*
  234. * struct alt_inst entries. From the header (alternative.h):
  235. * "Alternative instructions for different CPU types or capabilities"
  236. * Think locking instructions on spinlocks.
  237. */
  238. . = ALIGN(8);
  239. .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
  240. __alt_instructions = .;
  241. *(.altinstructions)
  242. __alt_instructions_end = .;
  243. }
  244. /*
  245. * And here are the replacement instructions. The linker sticks
  246. * them as binary blobs. The .altinstructions has enough data to
  247. * get the address and the length of them to patch the kernel safely.
  248. */
  249. .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
  250. *(.altinstr_replacement)
  251. }
  252. /*
  253. * struct iommu_table_entry entries are injected in this section.
  254. * It is an array of IOMMUs which during run time gets sorted depending
  255. * on its dependency order. After rootfs_initcall is complete
  256. * this section can be safely removed.
  257. */
  258. .iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
  259. __iommu_table = .;
  260. *(.iommu_table)
  261. __iommu_table_end = .;
  262. }
  263. . = ALIGN(8);
  264. .apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
  265. __apicdrivers = .;
  266. *(.apicdrivers);
  267. __apicdrivers_end = .;
  268. }
  269. . = ALIGN(8);
  270. /*
  271. * .exit.text is discard at runtime, not link time, to deal with
  272. * references from .altinstructions and .eh_frame
  273. */
  274. .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
  275. EXIT_TEXT
  276. }
  277. .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
  278. EXIT_DATA
  279. }
  280. #if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
  281. PERCPU_SECTION(INTERNODE_CACHE_BYTES)
  282. #endif
  283. . = ALIGN(PAGE_SIZE);
  284. /* freed after init ends here */
  285. .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
  286. __init_end = .;
  287. }
  288. /*
  289. * smp_locks might be freed after init
  290. * start/end must be page aligned
  291. */
  292. . = ALIGN(PAGE_SIZE);
  293. .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
  294. __smp_locks = .;
  295. *(.smp_locks)
  296. . = ALIGN(PAGE_SIZE);
  297. __smp_locks_end = .;
  298. }
  299. #ifdef CONFIG_X86_64
  300. .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
  301. NOSAVE_DATA
  302. }
  303. #endif
  304. /* BSS */
  305. . = ALIGN(PAGE_SIZE);
  306. .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
  307. __bss_start = .;
  308. *(.bss..page_aligned)
  309. *(.bss)
  310. BSS_DECRYPTED
  311. . = ALIGN(PAGE_SIZE);
  312. __bss_stop = .;
  313. }
  314. . = ALIGN(PAGE_SIZE);
  315. .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
  316. __brk_base = .;
  317. . += 64 * 1024; /* 64k alignment slop space */
  318. *(.brk_reservation) /* areas brk users have reserved */
  319. __brk_limit = .;
  320. }
  321. . = ALIGN(PAGE_SIZE); /* keep VO_INIT_SIZE page aligned */
  322. _end = .;
  323. STABS_DEBUG
  324. DWARF_DEBUG
  325. /* Sections to be discarded */
  326. DISCARDS
  327. /DISCARD/ : {
  328. *(.eh_frame)
  329. }
  330. }
  331. #ifdef CONFIG_X86_32
  332. /*
  333. * The ASSERT() sink to . is intentional, for binutils 2.14 compatibility:
  334. */
  335. . = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
  336. "kernel image bigger than KERNEL_IMAGE_SIZE");
  337. #else
  338. /*
  339. * Per-cpu symbols which need to be offset from __per_cpu_load
  340. * for the boot processor.
  341. */
  342. #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
  343. INIT_PER_CPU(gdt_page);
  344. INIT_PER_CPU(irq_stack_union);
  345. /*
  346. * Build-time check on the image size:
  347. */
  348. . = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
  349. "kernel image bigger than KERNEL_IMAGE_SIZE");
  350. #ifdef CONFIG_SMP
  351. . = ASSERT((irq_stack_union == 0),
  352. "irq_stack_union is not at start of per-cpu area");
  353. #endif
  354. #endif /* CONFIG_X86_32 */
  355. #ifdef CONFIG_KEXEC_CORE
  356. #include <asm/kexec.h>
  357. . = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
  358. "kexec control code size is too big");
  359. #endif