1 /* ld script to make x86-64 Linux kernel
2 * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>;
5 #define LOAD_OFFSET __START_KERNEL_map
7 #include <asm-generic/vmlinux.lds.h>
8 #include <asm/asm-offsets.h>
11 #undef i386 /* in case the preprocessor is a 32bit one */
13 OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
14 OUTPUT_ARCH(i386:x86-64)
15 ENTRY(phys_startup_64)
18 text PT_LOAD FLAGS(5); /* R_E */
19 data PT_LOAD FLAGS(7); /* RWE */
20 user PT_LOAD FLAGS(7); /* RWE */
21 data.init PT_LOAD FLAGS(7); /* RWE */
23 percpu PT_LOAD FLAGS(7); /* RWE */
25 note PT_NOTE FLAGS(0); /* ___ */
30 phys_startup_64 = startup_64 - LOAD_OFFSET;
31 _text = .; /* Text and read-only data */
32 .text : AT(ADDR(.text) - LOAD_OFFSET) {
33 /* First the code that has to be first for bootstrapping */
44 _etext = .; /* End of text section */
49 . = ALIGN(16); /* Exception table */
50 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
51 __start___ex_table = .;
53 __stop___ex_table = .;
58 . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */
60 .data : AT(ADDR(.data) - LOAD_OFFSET) {
65 _edata = .; /* End of data section */
68 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
69 .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
70 *(.data.cacheline_aligned)
72 . = ALIGN(CONFIG_X86_INTERNODE_CACHE_BYTES);
73 .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
77 #define VSYSCALL_ADDR (-10*1024*1024)
78 #define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
79 #define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
81 #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
82 #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
84 #define VVIRT_OFFSET (VSYSCALL_ADDR - VSYSCALL_VIRT_ADDR)
85 #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
88 .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) { *(.vsyscall_0) } :user
89 __vsyscall_0 = VSYSCALL_VIRT_ADDR;
91 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
92 .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) { *(.vsyscall_fn) }
93 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
94 .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data))
95 { *(.vsyscall_gtod_data) }
96 vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
97 .vsyscall_clock : AT(VLOAD(.vsyscall_clock))
98 { *(.vsyscall_clock) }
99 vsyscall_clock = VVIRT(.vsyscall_clock);
102 .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1))
104 .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2))
107 .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) { *(.vgetcpu_mode) }
108 vgetcpu_mode = VVIRT(.vgetcpu_mode);
110 . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
111 .jiffies : AT(VLOAD(.jiffies)) { *(.jiffies) }
112 jiffies = VVIRT(.jiffies);
114 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3))
117 . = VSYSCALL_VIRT_ADDR + PAGE_SIZE;
120 #undef VSYSCALL_PHYS_ADDR
121 #undef VSYSCALL_VIRT_ADDR
127 . = ALIGN(THREAD_SIZE); /* init_task */
128 .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
132 . = ALIGN(PAGE_SIZE);
133 .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
134 *(.data.page_aligned)
137 /* might get freed after init */
138 . = ALIGN(PAGE_SIZE);
141 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
145 . = ALIGN(PAGE_SIZE);
148 . = ALIGN(PAGE_SIZE); /* Init code and data */
150 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
155 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
156 __initdata_begin = .;
163 .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) { *(.init.setup) }
165 __initcall_start = .;
166 .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
170 __con_initcall_start = .;
171 .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
172 *(.con_initcall.init)
174 __con_initcall_end = .;
175 __x86_cpu_dev_start = .;
176 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
179 __x86_cpu_dev_end = .;
183 .parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
184 __parainstructions = .;
186 __parainstructions_end = .;
190 __alt_instructions = .;
191 .altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
194 __alt_instructions_end = .;
195 .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
196 *(.altinstr_replacement)
198 /* .exit.text is discard at runtime, not link time, to deal with references
199 from .altinstructions and .eh_frame */
200 .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
203 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
207 #ifdef CONFIG_BLK_DEV_INITRD
208 . = ALIGN(PAGE_SIZE);
209 __initramfs_start = .;
210 .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) { *(.init.ramfs) }
216 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
217 * output PHDR, so the next output section - __data_nosave - should
218 * switch it back to data.init. Also, pda should be at the head of
219 * percpu area. Preallocate it and define the percpu offset symbol
220 * so that it can be accessed as a percpu variable.
222 . = ALIGN(PAGE_SIZE);
223 PERCPU_VADDR(0, :percpu)
228 . = ALIGN(PAGE_SIZE);
231 . = ALIGN(PAGE_SIZE);
233 .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
235 } :data.init /* switch back to data.init, see PERCPU_VADDR() above */
236 . = ALIGN(PAGE_SIZE);
239 __bss_start = .; /* BSS */
240 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
248 /* Sections to be discarded */
260 * Build-time check on the image size:
262 ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
263 "kernel image bigger than KERNEL_IMAGE_SIZE")
266 ASSERT((per_cpu__irq_stack_union == 0),
267 "irq_stack_union is not at start of per-cpu area");