vmlinux.lds.S 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. PHDRS {
  39. text PT_LOAD FLAGS(5); /* R_E */
  40. data PT_LOAD FLAGS(7); /* RWE */
  41. #ifdef CONFIG_X86_64
  42. user PT_LOAD FLAGS(5); /* R_E */
  43. #ifdef CONFIG_SMP
  44. percpu PT_LOAD FLAGS(6); /* RW_ */
  45. #endif
  46. init PT_LOAD FLAGS(7); /* RWE */
  47. #endif
  48. note PT_NOTE FLAGS(0); /* ___ */
  49. }
  50. SECTIONS
  51. {
  52. #ifdef CONFIG_X86_32
  53. . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
  54. phys_startup_32 = startup_32 - LOAD_OFFSET;
  55. #else
  56. . = __START_KERNEL;
  57. phys_startup_64 = startup_64 - LOAD_OFFSET;
  58. #endif
  59. /* Text and read-only data */
  60. /* bootstrapping code */
  61. .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) {
  62. _text = .;
  63. *(.text.head)
  64. } :text = 0x9090
  65. /* The rest of the text */
  66. .text : AT(ADDR(.text) - LOAD_OFFSET) {
  67. #ifdef CONFIG_X86_32
  68. /* not really needed, already page aligned */
  69. . = ALIGN(PAGE_SIZE);
  70. *(.text.page_aligned)
  71. #endif
  72. . = ALIGN(8);
  73. _stext = .;
  74. TEXT_TEXT
  75. SCHED_TEXT
  76. LOCK_TEXT
  77. KPROBES_TEXT
  78. IRQENTRY_TEXT
  79. *(.fixup)
  80. *(.gnu.warning)
  81. /* End of text section */
  82. _etext = .;
  83. } :text = 0x9090
  84. NOTES :text :note
  85. /* Exception table */
  86. . = ALIGN(16);
  87. __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
  88. __start___ex_table = .;
  89. *(__ex_table)
  90. __stop___ex_table = .;
  91. } :text = 0x9090
  92. RO_DATA(PAGE_SIZE)
  93. /* Data */
  94. .data : AT(ADDR(.data) - LOAD_OFFSET) {
  95. /* Start of data section */
  96. _sdata = .;
  97. /* init_task */
  98. INIT_TASK_DATA(THREAD_SIZE)
  99. #ifdef CONFIG_X86_32
  100. /* 32 bit has nosave before _edata */
  101. NOSAVE_DATA
  102. #endif
  103. PAGE_ALIGNED_DATA(PAGE_SIZE)
  104. *(.data.idt)
  105. CACHELINE_ALIGNED_DATA(CONFIG_X86_L1_CACHE_BYTES)
  106. DATA_DATA
  107. CONSTRUCTORS
  108. /* rarely changed data like cpu maps */
  109. READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
  110. /* End of data section */
  111. _edata = .;
  112. } :data
  113. #ifdef CONFIG_X86_64
  114. #define VSYSCALL_ADDR (-10*1024*1024)
  115. #define VSYSCALL_PHYS_ADDR ((LOADADDR(.data) + SIZEOF(.data) + \
  116. PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  117. #define VSYSCALL_VIRT_ADDR ((ADDR(.data) + SIZEOF(.data) + \
  118. PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  119. #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
  120. #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
  121. #define VVIRT_OFFSET (VSYSCALL_ADDR - VSYSCALL_VIRT_ADDR)
  122. #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
  123. . = VSYSCALL_ADDR;
  124. .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) {
  125. *(.vsyscall_0)
  126. } :user
  127. __vsyscall_0 = VSYSCALL_VIRT_ADDR;
  128. . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
  129. .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) {
  130. *(.vsyscall_fn)
  131. }
  132. . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
  133. .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) {
  134. *(.vsyscall_gtod_data)
  135. }
  136. vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
  137. .vsyscall_clock : AT(VLOAD(.vsyscall_clock)) {
  138. *(.vsyscall_clock)
  139. }
  140. vsyscall_clock = VVIRT(.vsyscall_clock);
  141. .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) {
  142. *(.vsyscall_1)
  143. }
  144. .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) {
  145. *(.vsyscall_2)
  146. }
  147. .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) {
  148. *(.vgetcpu_mode)
  149. }
  150. vgetcpu_mode = VVIRT(.vgetcpu_mode);
  151. . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
  152. .jiffies : AT(VLOAD(.jiffies)) {
  153. *(.jiffies)
  154. }
  155. jiffies = VVIRT(.jiffies);
  156. .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
  157. *(.vsyscall_3)
  158. }
  159. . = VSYSCALL_VIRT_ADDR + PAGE_SIZE;
  160. #undef VSYSCALL_ADDR
  161. #undef VSYSCALL_PHYS_ADDR
  162. #undef VSYSCALL_VIRT_ADDR
  163. #undef VLOAD_OFFSET
  164. #undef VLOAD
  165. #undef VVIRT_OFFSET
  166. #undef VVIRT
  167. #endif /* CONFIG_X86_64 */
  168. /* Init code and data - will be freed after init */
  169. . = ALIGN(PAGE_SIZE);
  170. .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
  171. __init_begin = .; /* paired with __init_end */
  172. }
  173. #if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
  174. /*
  175. * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
  176. * output PHDR, so the next output section - .init.text - should
  177. * start another segment - init.
  178. */
  179. PERCPU_VADDR(0, :percpu)
  180. #endif
  181. .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
  182. _sinittext = .;
  183. INIT_TEXT
  184. _einittext = .;
  185. }
  186. #ifdef CONFIG_X86_64
  187. :init
  188. #endif
  189. .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
  190. INIT_DATA
  191. }
  192. . = ALIGN(16);
  193. .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) {
  194. __setup_start = .;
  195. *(.init.setup)
  196. __setup_end = .;
  197. }
  198. .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
  199. __initcall_start = .;
  200. INITCALLS
  201. __initcall_end = .;
  202. }
  203. .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
  204. __con_initcall_start = .;
  205. *(.con_initcall.init)
  206. __con_initcall_end = .;
  207. }
  208. .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
  209. __x86_cpu_dev_start = .;
  210. *(.x86_cpu_dev.init)
  211. __x86_cpu_dev_end = .;
  212. }
  213. SECURITY_INIT
  214. . = ALIGN(8);
  215. .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
  216. __parainstructions = .;
  217. *(.parainstructions)
  218. __parainstructions_end = .;
  219. }
  220. . = ALIGN(8);
  221. .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
  222. __alt_instructions = .;
  223. *(.altinstructions)
  224. __alt_instructions_end = .;
  225. }
  226. .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
  227. *(.altinstr_replacement)
  228. }
  229. /*
  230. * .exit.text is discard at runtime, not link time, to deal with
  231. * references from .altinstructions and .eh_frame
  232. */
  233. .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
  234. EXIT_TEXT
  235. }
  236. .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
  237. EXIT_DATA
  238. }
  239. #ifdef CONFIG_BLK_DEV_INITRD
  240. . = ALIGN(PAGE_SIZE);
  241. .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
  242. __initramfs_start = .;
  243. *(.init.ramfs)
  244. __initramfs_end = .;
  245. }
  246. #endif
  247. #if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
  248. PERCPU(PAGE_SIZE)
  249. #endif
  250. . = ALIGN(PAGE_SIZE);
  251. /* freed after init ends here */
  252. .init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
  253. __init_end = .;
  254. }
  255. /*
  256. * smp_locks might be freed after init
  257. * start/end must be page aligned
  258. */
  259. . = ALIGN(PAGE_SIZE);
  260. .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
  261. __smp_locks = .;
  262. *(.smp_locks)
  263. __smp_locks_end = .;
  264. . = ALIGN(PAGE_SIZE);
  265. }
  266. #ifdef CONFIG_X86_64
  267. .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
  268. NOSAVE_DATA
  269. }
  270. #endif
  271. /* BSS */
  272. . = ALIGN(PAGE_SIZE);
  273. .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
  274. __bss_start = .;
  275. *(.bss.page_aligned)
  276. *(.bss)
  277. . = ALIGN(4);
  278. __bss_stop = .;
  279. }
  280. . = ALIGN(PAGE_SIZE);
  281. .brk : AT(ADDR(.brk) - LOAD_OFFSET) {
  282. __brk_base = .;
  283. . += 64 * 1024; /* 64k alignment slop space */
  284. *(.brk_reservation) /* areas brk users have reserved */
  285. __brk_limit = .;
  286. }
  287. .end : AT(ADDR(.end) - LOAD_OFFSET) {
  288. _end = .;
  289. }
  290. STABS_DEBUG
  291. DWARF_DEBUG
  292. /* Sections to be discarded */
  293. DISCARDS
  294. /DISCARD/ : { *(.eh_frame) }
  295. }
  296. #ifdef CONFIG_X86_32
  297. . = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
  298. "kernel image bigger than KERNEL_IMAGE_SIZE");
  299. #else
  300. /*
  301. * Per-cpu symbols which need to be offset from __per_cpu_load
  302. * for the boot processor.
  303. */
  304. #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
  305. INIT_PER_CPU(gdt_page);
  306. INIT_PER_CPU(irq_stack_union);
  307. /*
  308. * Build-time check on the image size:
  309. */
  310. . = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
  311. "kernel image bigger than KERNEL_IMAGE_SIZE");
  312. #ifdef CONFIG_SMP
  313. . = ASSERT((per_cpu__irq_stack_union == 0),
  314. "irq_stack_union is not at start of per-cpu area");
  315. #endif
  316. #endif /* CONFIG_X86_32 */
  317. #ifdef CONFIG_KEXEC
  318. #include <asm/kexec.h>
  319. . = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
  320. "kexec control code size is too big");
  321. #endif