vmlinux.lds.S 9.7 KB

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