vmlinux.lds.S 9.5 KB

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