vmlinux.lds.S 8.1 KB

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