vmlinux.lds.S 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. #else
  33. OUTPUT_ARCH(i386:x86-64)
  34. ENTRY(phys_startup_64)
  35. #endif
  36. #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
  37. /*
  38. * On 64-bit, align RODATA to 2MB so that even with CONFIG_DEBUG_RODATA
  39. * we retain large page mappings for boundaries spanning kernel text, rodata
  40. * and data sections.
  41. *
  42. * However, kernel identity mappings will have different RWX permissions
  43. * to the pages mapping to text and to the pages padding (which are freed) the
  44. * text section. Hence kernel identity mappings will be broken to smaller
  45. * pages. For 64-bit, kernel text and kernel identity mappings are different,
  46. * so we can enable protection checks that come with CONFIG_DEBUG_RODATA,
  47. * as well as retain 2MB large page mappings for kernel text.
  48. */
  49. #define X64_ALIGN_DEBUG_RODATA_BEGIN . = ALIGN(HPAGE_SIZE);
  50. #define X64_ALIGN_DEBUG_RODATA_END \
  51. . = ALIGN(HPAGE_SIZE); \
  52. __end_rodata_hpage_align = .;
  53. #else
  54. #define X64_ALIGN_DEBUG_RODATA_BEGIN
  55. #define X64_ALIGN_DEBUG_RODATA_END
  56. #endif
  57. PHDRS {
  58. text PT_LOAD FLAGS(5); /* R_E */
  59. data PT_LOAD FLAGS(6); /* RW_ */
  60. #ifdef CONFIG_X86_64
  61. user PT_LOAD FLAGS(5); /* R_E */
  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 = startup_32 - LOAD_OFFSET;
  74. #else
  75. . = __START_KERNEL;
  76. phys_startup_64 = 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. #ifdef CONFIG_X86_32
  84. . = ALIGN(PAGE_SIZE);
  85. *(.text..page_aligned)
  86. #endif
  87. . = ALIGN(8);
  88. _stext = .;
  89. TEXT_TEXT
  90. SCHED_TEXT
  91. LOCK_TEXT
  92. KPROBES_TEXT
  93. IRQENTRY_TEXT
  94. *(.fixup)
  95. *(.gnu.warning)
  96. /* End of text section */
  97. _etext = .;
  98. } :text = 0x9090
  99. NOTES :text :note
  100. EXCEPTION_TABLE(16) :text = 0x9090
  101. #if defined(CONFIG_DEBUG_RODATA)
  102. /* .text should occupy whole number of pages */
  103. . = ALIGN(PAGE_SIZE);
  104. #endif
  105. X64_ALIGN_DEBUG_RODATA_BEGIN
  106. RO_DATA(PAGE_SIZE)
  107. X64_ALIGN_DEBUG_RODATA_END
  108. /* Data */
  109. .data : AT(ADDR(.data) - LOAD_OFFSET) {
  110. /* Start of data section */
  111. _sdata = .;
  112. /* init_task */
  113. INIT_TASK_DATA(THREAD_SIZE)
  114. #ifdef CONFIG_X86_32
  115. /* 32 bit has nosave before _edata */
  116. NOSAVE_DATA
  117. #endif
  118. PAGE_ALIGNED_DATA(PAGE_SIZE)
  119. CACHELINE_ALIGNED_DATA(L1_CACHE_BYTES)
  120. DATA_DATA
  121. /*
  122. * Workaround a binutils (2.20.51.0.12 to 2.21.51.0.3) bug.
  123. * This makes jiffies relocatable in such binutils
  124. */
  125. #ifdef CONFIG_X86_32
  126. jiffies = jiffies_64;
  127. #else
  128. jiffies_64 = jiffies;
  129. #endif
  130. CONSTRUCTORS
  131. /* rarely changed data like cpu maps */
  132. READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES)
  133. /* End of data section */
  134. _edata = .;
  135. } :data
  136. #ifdef CONFIG_X86_64
  137. #define VSYSCALL_ADDR (-10*1024*1024)
  138. #define VLOAD_OFFSET (VSYSCALL_ADDR - __vsyscall_0 + LOAD_OFFSET)
  139. #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
  140. #define VVIRT_OFFSET (VSYSCALL_ADDR - __vsyscall_0)
  141. #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
  142. . = ALIGN(4096);
  143. __vsyscall_0 = .;
  144. . = VSYSCALL_ADDR;
  145. .vsyscall_0 : AT(VLOAD(.vsyscall_0)) {
  146. *(.vsyscall_0)
  147. } :user
  148. . = ALIGN(L1_CACHE_BYTES);
  149. .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) {
  150. *(.vsyscall_fn)
  151. }
  152. . = ALIGN(L1_CACHE_BYTES);
  153. .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) {
  154. *(.vsyscall_gtod_data)
  155. }
  156. vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
  157. .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) {
  158. *(.vsyscall_clock)
  159. }
  160. vsyscall_clock = VVIRT(.vsyscall_clock);
  161. .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) {
  162. *(.vsyscall_1)
  163. }
  164. .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) {
  165. *(.vsyscall_2)
  166. }
  167. .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) {
  168. *(.vgetcpu_mode)
  169. }
  170. vgetcpu_mode = VVIRT(.vgetcpu_mode);
  171. . = ALIGN(L1_CACHE_BYTES);
  172. .jiffies : AT(VLOAD(.jiffies)) {
  173. *(.jiffies)
  174. }
  175. jiffies = VVIRT(.jiffies);
  176. .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
  177. *(.vsyscall_3)
  178. }
  179. . = __vsyscall_0 + PAGE_SIZE;
  180. #undef VSYSCALL_ADDR
  181. #undef VLOAD_OFFSET
  182. #undef VLOAD
  183. #undef VVIRT_OFFSET
  184. #undef VVIRT
  185. #endif /* CONFIG_X86_64 */
  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(0, :percpu)
  198. #endif
  199. INIT_TEXT_SECTION(PAGE_SIZE)
  200. #ifdef CONFIG_X86_64
  201. :init
  202. #endif
  203. INIT_DATA_SECTION(16)
  204. .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
  205. __x86_cpu_dev_start = .;
  206. *(.x86_cpu_dev.init)
  207. __x86_cpu_dev_end = .;
  208. }
  209. /*
  210. * start address and size of operations which during runtime
  211. * can be patched with virtualization friendly instructions or
  212. * baremetal native ones. Think page table operations.
  213. * Details in paravirt_types.h
  214. */
  215. . = ALIGN(8);
  216. .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
  217. __parainstructions = .;
  218. *(.parainstructions)
  219. __parainstructions_end = .;
  220. }
  221. /*
  222. * struct alt_inst entries. From the header (alternative.h):
  223. * "Alternative instructions for different CPU types or capabilities"
  224. * Think locking instructions on spinlocks.
  225. */
  226. . = ALIGN(8);
  227. .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
  228. __alt_instructions = .;
  229. *(.altinstructions)
  230. __alt_instructions_end = .;
  231. }
  232. /*
  233. * And here are the replacement instructions. The linker sticks
  234. * them as binary blobs. The .altinstructions has enough data to
  235. * get the address and the length of them to patch the kernel safely.
  236. */
  237. .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
  238. *(.altinstr_replacement)
  239. }
  240. /*
  241. * struct iommu_table_entry entries are injected in this section.
  242. * It is an array of IOMMUs which during run time gets sorted depending
  243. * on its dependency order. After rootfs_initcall is complete
  244. * this section can be safely removed.
  245. */
  246. .iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
  247. __iommu_table = .;
  248. *(.iommu_table)
  249. __iommu_table_end = .;
  250. }
  251. . = ALIGN(8);
  252. /*
  253. * .exit.text is discard at runtime, not link time, to deal with
  254. * references from .altinstructions and .eh_frame
  255. */
  256. .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
  257. EXIT_TEXT
  258. }
  259. .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
  260. EXIT_DATA
  261. }
  262. #if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
  263. PERCPU(THREAD_SIZE)
  264. #endif
  265. . = ALIGN(PAGE_SIZE);
  266. /* freed after init ends here */
  267. .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
  268. __init_end = .;
  269. }
  270. /*
  271. * smp_locks might be freed after init
  272. * start/end must be page aligned
  273. */
  274. . = ALIGN(PAGE_SIZE);
  275. .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
  276. __smp_locks = .;
  277. *(.smp_locks)
  278. . = ALIGN(PAGE_SIZE);
  279. __smp_locks_end = .;
  280. }
  281. #ifdef CONFIG_X86_64
  282. .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
  283. NOSAVE_DATA
  284. }
  285. #endif
  286. /* BSS */
  287. . = ALIGN(PAGE_SIZE);
  288. .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
  289. __bss_start = .;
  290. *(.bss..page_aligned)
  291. *(.bss)
  292. . = ALIGN(PAGE_SIZE);
  293. __bss_stop = .;
  294. }
  295. . = ALIGN(PAGE_SIZE);
  296. .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
  297. __brk_base = .;
  298. . += 64 * 1024; /* 64k alignment slop space */
  299. *(.brk_reservation) /* areas brk users have reserved */
  300. __brk_limit = .;
  301. }
  302. _end = .;
  303. STABS_DEBUG
  304. DWARF_DEBUG
  305. /* Sections to be discarded */
  306. DISCARDS
  307. /DISCARD/ : { *(.eh_frame) }
  308. }
  309. #ifdef CONFIG_X86_32
  310. /*
  311. * The ASSERT() sink to . is intentional, for binutils 2.14 compatibility:
  312. */
  313. . = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
  314. "kernel image bigger than KERNEL_IMAGE_SIZE");
  315. #else
  316. /*
  317. * Per-cpu symbols which need to be offset from __per_cpu_load
  318. * for the boot processor.
  319. */
  320. #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
  321. INIT_PER_CPU(gdt_page);
  322. INIT_PER_CPU(irq_stack_union);
  323. /*
  324. * Build-time check on the image size:
  325. */
  326. . = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
  327. "kernel image bigger than KERNEL_IMAGE_SIZE");
  328. #ifdef CONFIG_SMP
  329. . = ASSERT((irq_stack_union == 0),
  330. "irq_stack_union is not at start of per-cpu area");
  331. #endif
  332. #endif /* CONFIG_X86_32 */
  333. #ifdef CONFIG_KEXEC
  334. #include <asm/kexec.h>
  335. . = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
  336. "kexec control code size is too big");
  337. #endif