vmlinux.lds.S 8.1 KB

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