vmlinux_64.lds.S 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /* ld script to make x86-64 Linux kernel
  2. * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>;
  3. */
  4. #define LOAD_OFFSET __START_KERNEL_map
  5. #include <asm-generic/vmlinux.lds.h>
  6. #include <asm/page.h>
  7. #undef i386 /* in case the preprocessor is a 32bit one */
  8. OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
  9. OUTPUT_ARCH(i386:x86-64)
  10. ENTRY(phys_startup_64)
  11. jiffies_64 = jiffies;
  12. _proxy_pda = 1;
  13. PHDRS {
  14. text PT_LOAD FLAGS(5); /* R_E */
  15. data PT_LOAD FLAGS(7); /* RWE */
  16. user PT_LOAD FLAGS(7); /* RWE */
  17. data.init PT_LOAD FLAGS(7); /* RWE */
  18. #ifdef CONFIG_SMP
  19. percpu PT_LOAD FLAGS(7); /* RWE */
  20. #endif
  21. note PT_NOTE FLAGS(0); /* ___ */
  22. }
  23. SECTIONS
  24. {
  25. . = __START_KERNEL;
  26. phys_startup_64 = startup_64 - LOAD_OFFSET;
  27. _text = .; /* Text and read-only data */
  28. .text : AT(ADDR(.text) - LOAD_OFFSET) {
  29. /* First the code that has to be first for bootstrapping */
  30. *(.text.head)
  31. _stext = .;
  32. /* Then the rest */
  33. TEXT_TEXT
  34. SCHED_TEXT
  35. LOCK_TEXT
  36. KPROBES_TEXT
  37. IRQENTRY_TEXT
  38. *(.fixup)
  39. *(.gnu.warning)
  40. _etext = .; /* End of text section */
  41. } :text = 0x9090
  42. NOTES :text :note
  43. . = ALIGN(16); /* Exception table */
  44. __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
  45. __start___ex_table = .;
  46. *(__ex_table)
  47. __stop___ex_table = .;
  48. } :text = 0x9090
  49. RODATA
  50. . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */
  51. /* Data */
  52. .data : AT(ADDR(.data) - LOAD_OFFSET) {
  53. DATA_DATA
  54. CONSTRUCTORS
  55. } :data
  56. _edata = .; /* End of data section */
  57. . = ALIGN(PAGE_SIZE);
  58. . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
  59. .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
  60. *(.data.cacheline_aligned)
  61. }
  62. . = ALIGN(CONFIG_X86_INTERNODE_CACHE_BYTES);
  63. .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
  64. *(.data.read_mostly)
  65. }
  66. #define VSYSCALL_ADDR (-10*1024*1024)
  67. #define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
  68. #define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
  69. #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
  70. #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
  71. #define VVIRT_OFFSET (VSYSCALL_ADDR - VSYSCALL_VIRT_ADDR)
  72. #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
  73. . = VSYSCALL_ADDR;
  74. .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) { *(.vsyscall_0) } :user
  75. __vsyscall_0 = VSYSCALL_VIRT_ADDR;
  76. . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
  77. .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) { *(.vsyscall_fn) }
  78. . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
  79. .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data))
  80. { *(.vsyscall_gtod_data) }
  81. vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
  82. .vsyscall_clock : AT(VLOAD(.vsyscall_clock))
  83. { *(.vsyscall_clock) }
  84. vsyscall_clock = VVIRT(.vsyscall_clock);
  85. .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1))
  86. { *(.vsyscall_1) }
  87. .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2))
  88. { *(.vsyscall_2) }
  89. .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) { *(.vgetcpu_mode) }
  90. vgetcpu_mode = VVIRT(.vgetcpu_mode);
  91. . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
  92. .jiffies : AT(VLOAD(.jiffies)) { *(.jiffies) }
  93. jiffies = VVIRT(.jiffies);
  94. .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3))
  95. { *(.vsyscall_3) }
  96. . = VSYSCALL_VIRT_ADDR + PAGE_SIZE;
  97. #undef VSYSCALL_ADDR
  98. #undef VSYSCALL_PHYS_ADDR
  99. #undef VSYSCALL_VIRT_ADDR
  100. #undef VLOAD_OFFSET
  101. #undef VLOAD
  102. #undef VVIRT_OFFSET
  103. #undef VVIRT
  104. . = ALIGN(THREAD_SIZE); /* init_task */
  105. .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
  106. *(.data.init_task)
  107. }:data.init
  108. . = ALIGN(PAGE_SIZE);
  109. .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
  110. *(.data.page_aligned)
  111. }
  112. /* might get freed after init */
  113. . = ALIGN(PAGE_SIZE);
  114. __smp_alt_begin = .;
  115. __smp_locks = .;
  116. .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
  117. *(.smp_locks)
  118. }
  119. __smp_locks_end = .;
  120. . = ALIGN(PAGE_SIZE);
  121. __smp_alt_end = .;
  122. . = ALIGN(PAGE_SIZE); /* Init code and data */
  123. __init_begin = .;
  124. .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
  125. _sinittext = .;
  126. INIT_TEXT
  127. _einittext = .;
  128. }
  129. .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
  130. __initdata_begin = .;
  131. INIT_DATA
  132. __initdata_end = .;
  133. }
  134. . = ALIGN(16);
  135. __setup_start = .;
  136. .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) { *(.init.setup) }
  137. __setup_end = .;
  138. __initcall_start = .;
  139. .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
  140. INITCALLS
  141. }
  142. __initcall_end = .;
  143. __con_initcall_start = .;
  144. .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
  145. *(.con_initcall.init)
  146. }
  147. __con_initcall_end = .;
  148. __x86_cpu_dev_start = .;
  149. .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
  150. *(.x86_cpu_dev.init)
  151. }
  152. __x86_cpu_dev_end = .;
  153. SECURITY_INIT
  154. . = ALIGN(8);
  155. .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
  156. __parainstructions = .;
  157. *(.parainstructions)
  158. __parainstructions_end = .;
  159. }
  160. . = ALIGN(8);
  161. __alt_instructions = .;
  162. .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
  163. *(.altinstructions)
  164. }
  165. __alt_instructions_end = .;
  166. .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
  167. *(.altinstr_replacement)
  168. }
  169. /* .exit.text is discard at runtime, not link time, to deal with references
  170. from .altinstructions and .eh_frame */
  171. .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
  172. EXIT_TEXT
  173. }
  174. .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
  175. EXIT_DATA
  176. }
  177. #ifdef CONFIG_BLK_DEV_INITRD
  178. . = ALIGN(PAGE_SIZE);
  179. __initramfs_start = .;
  180. .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) { *(.init.ramfs) }
  181. __initramfs_end = .;
  182. #endif
  183. #ifdef CONFIG_SMP
  184. /*
  185. * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
  186. * output PHDR, so the next output section - __data_nosave - should
  187. * switch it back to data.init.
  188. */
  189. . = ALIGN(PAGE_SIZE);
  190. PERCPU_VADDR(0, :percpu)
  191. #else
  192. PERCPU(PAGE_SIZE)
  193. #endif
  194. . = ALIGN(PAGE_SIZE);
  195. __init_end = .;
  196. . = ALIGN(PAGE_SIZE);
  197. __nosave_begin = .;
  198. .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
  199. *(.data.nosave)
  200. } :data.init /* switch back to data.init, see PERCPU_VADDR() above */
  201. . = ALIGN(PAGE_SIZE);
  202. __nosave_end = .;
  203. __bss_start = .; /* BSS */
  204. .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
  205. *(.bss.page_aligned)
  206. *(.bss)
  207. }
  208. __bss_stop = .;
  209. _end = . ;
  210. /* Sections to be discarded */
  211. /DISCARD/ : {
  212. *(.exitcall.exit)
  213. *(.eh_frame)
  214. }
  215. STABS_DEBUG
  216. DWARF_DEBUG
  217. }
  218. /*
  219. * Build-time check on the image size:
  220. */
  221. ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
  222. "kernel image bigger than KERNEL_IMAGE_SIZE")