vmlinux.lds.S 10 KB

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