vmlinux.lds.S 9.8 KB

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