vmlinux.lds.S 9.2 KB

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