vmlinux.lds.S 9.4 KB

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