vmlinux.lds.S 8.7 KB

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