• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17#ifdef CONFIG_X86_32
18#define LOAD_OFFSET __PAGE_OFFSET
19#else
20#define LOAD_OFFSET __START_KERNEL_map
21#endif
22
23#include <asm-generic/vmlinux.lds.h>
24#include <asm/asm-offsets.h>
25#include <asm/thread_info.h>
26#include <asm/page_types.h>
27#include <asm/cache.h>
28#include <asm/boot.h>
29
30#undef i386     /* in case the preprocessor is a 32bit one */
31
32OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT)
33
34#ifdef CONFIG_X86_32
35OUTPUT_ARCH(i386)
36ENTRY(phys_startup_32)
37jiffies = jiffies_64;
38#else
39OUTPUT_ARCH(i386:x86-64)
40ENTRY(phys_startup_64)
41jiffies_64 = jiffies;
42#endif
43
44#if defined(CONFIG_X86_64)
45/*
46 * On 64-bit, align RODATA to 2MB so we retain large page mappings for
47 * boundaries spanning kernel text, rodata and data sections.
48 *
49 * However, kernel identity mappings will have different RWX permissions
50 * to the pages mapping to text and to the pages padding (which are freed) the
51 * text section. Hence kernel identity mappings will be broken to smaller
52 * pages. For 64-bit, kernel text and kernel identity mappings are different,
53 * so we can enable protection checks as well as retain 2MB large page
54 * mappings for kernel text.
55 */
56#define X64_ALIGN_RODATA_BEGIN	. = ALIGN(HPAGE_SIZE);
57
58#define X64_ALIGN_RODATA_END					\
59		. = ALIGN(HPAGE_SIZE);				\
60		__end_rodata_hpage_align = .;
61
62#else
63
64#define X64_ALIGN_RODATA_BEGIN
65#define X64_ALIGN_RODATA_END
66
67#endif
68
69PHDRS {
70	text PT_LOAD FLAGS(5);          /* R_E */
71	data PT_LOAD FLAGS(6);          /* RW_ */
72#ifdef CONFIG_X86_64
73#ifdef CONFIG_SMP
74	percpu PT_LOAD FLAGS(6);        /* RW_ */
75#endif
76	init PT_LOAD FLAGS(7);          /* RWE */
77#endif
78	note PT_NOTE FLAGS(0);          /* ___ */
79}
80
81SECTIONS
82{
83#ifdef CONFIG_X86_32
84        . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
85        phys_startup_32 = startup_32 - LOAD_OFFSET;
86#else
87        . = __START_KERNEL;
88        phys_startup_64 = startup_64 - LOAD_OFFSET;
89#endif
90
91	/* Text and read-only data */
92	.text :  AT(ADDR(.text) - LOAD_OFFSET) {
93		_text = .;
94		/* bootstrapping code */
95		HEAD_TEXT
96		. = ALIGN(8);
97		_stext = .;
98		TEXT_TEXT
99		SCHED_TEXT
100		LOCK_TEXT
101		KPROBES_TEXT
102		ENTRY_TEXT
103		IRQENTRY_TEXT
104		*(.fixup)
105		*(.gnu.warning)
106		/* End of text section */
107		_etext = .;
108	} :text = 0x9090
109
110	NOTES :text :note
111
112	EXCEPTION_TABLE(16) :text = 0x9090
113
114	/* .text should occupy whole number of pages */
115	. = ALIGN(PAGE_SIZE);
116	X64_ALIGN_RODATA_BEGIN
117	RO_DATA(PAGE_SIZE)
118	X64_ALIGN_RODATA_END
119
120	/* Data */
121	.data : AT(ADDR(.data) - LOAD_OFFSET) {
122		/* Start of data section */
123		_sdata = .;
124
125		/* init_task */
126		INIT_TASK_DATA(THREAD_SIZE)
127
128#ifdef CONFIG_X86_32
129		/* 32 bit has nosave before _edata */
130		NOSAVE_DATA
131#endif
132
133		PAGE_ALIGNED_DATA(PAGE_SIZE)
134
135		CACHELINE_ALIGNED_DATA(L1_CACHE_BYTES)
136
137		DATA_DATA
138		CONSTRUCTORS
139
140		/* rarely changed data like cpu maps */
141		READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES)
142
143		/* End of data section */
144		_edata = .;
145	} :data
146
147
148	. = ALIGN(PAGE_SIZE);
149	__vvar_page = .;
150
151	.vvar : AT(ADDR(.vvar) - LOAD_OFFSET) {
152		/* work around gold bug 13023 */
153		__vvar_beginning_hack = .;
154
155		/* Place all vvars at the offsets in asm/vvar.h. */
156#define EMIT_VVAR(name, offset) 			\
157		. = __vvar_beginning_hack + offset;	\
158		*(.vvar_ ## name)
159#define __VVAR_KERNEL_LDS
160#include <asm/vvar.h>
161#undef __VVAR_KERNEL_LDS
162#undef EMIT_VVAR
163
164		/*
165		 * Pad the rest of the page with zeros.  Otherwise the loader
166		 * can leave garbage here.
167		 */
168		. = __vvar_beginning_hack + PAGE_SIZE;
169	} :data
170
171       . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
172
173	/* Init code and data - will be freed after init */
174	. = ALIGN(PAGE_SIZE);
175	.init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
176		__init_begin = .; /* paired with __init_end */
177	}
178
179#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
180	/*
181	 * percpu offsets are zero-based on SMP.  PERCPU_VADDR() changes the
182	 * output PHDR, so the next output section - .init.text - should
183	 * start another segment - init.
184	 */
185	PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
186#endif
187
188	INIT_TEXT_SECTION(PAGE_SIZE)
189#ifdef CONFIG_X86_64
190	:init
191#endif
192
193	INIT_DATA_SECTION(16)
194
195	.x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
196		__x86_cpu_dev_start = .;
197		*(.x86_cpu_dev.init)
198		__x86_cpu_dev_end = .;
199	}
200
201#ifdef CONFIG_X86_INTEL_MID
202	.x86_intel_mid_dev.init : AT(ADDR(.x86_intel_mid_dev.init) - \
203								LOAD_OFFSET) {
204		__x86_intel_mid_dev_start = .;
205		*(.x86_intel_mid_dev.init)
206		__x86_intel_mid_dev_end = .;
207	}
208#endif
209
210	/*
211	 * start address and size of operations which during runtime
212	 * can be patched with virtualization friendly instructions or
213	 * baremetal native ones. Think page table operations.
214	 * Details in paravirt_types.h
215	 */
216	. = ALIGN(8);
217	.parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
218		__parainstructions = .;
219		*(.parainstructions)
220		__parainstructions_end = .;
221	}
222
223	/*
224	 * struct alt_inst entries. From the header (alternative.h):
225	 * "Alternative instructions for different CPU types or capabilities"
226	 * Think locking instructions on spinlocks.
227	 */
228	. = ALIGN(8);
229	.altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
230		__alt_instructions = .;
231		*(.altinstructions)
232		__alt_instructions_end = .;
233	}
234
235	/*
236	 * And here are the replacement instructions. The linker sticks
237	 * them as binary blobs. The .altinstructions has enough data to
238	 * get the address and the length of them to patch the kernel safely.
239	 */
240	.altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
241		*(.altinstr_replacement)
242	}
243
244	/*
245	 * struct iommu_table_entry entries are injected in this section.
246	 * It is an array of IOMMUs which during run time gets sorted depending
247	 * on its dependency order. After rootfs_initcall is complete
248	 * this section can be safely removed.
249	 */
250	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
251		__iommu_table = .;
252		*(.iommu_table)
253		__iommu_table_end = .;
254	}
255
256	. = ALIGN(8);
257	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
258		__apicdrivers = .;
259		*(.apicdrivers);
260		__apicdrivers_end = .;
261	}
262
263	. = ALIGN(8);
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
272	.exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
273		EXIT_DATA
274	}
275
276#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
277	PERCPU_SECTION(INTERNODE_CACHE_BYTES)
278#endif
279
280	. = ALIGN(PAGE_SIZE);
281
282	/* freed after init ends here */
283	.init.end : AT(ADDR(.init.end) - LOAD_OFFSET) {
284		__init_end = .;
285	}
286
287	/*
288	 * smp_locks might be freed after init
289	 * start/end must be page aligned
290	 */
291	. = ALIGN(PAGE_SIZE);
292	.smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
293		__smp_locks = .;
294		*(.smp_locks)
295		. = ALIGN(PAGE_SIZE);
296		__smp_locks_end = .;
297	}
298
299#ifdef CONFIG_X86_64
300	.data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
301		NOSAVE_DATA
302	}
303#endif
304
305	/* BSS */
306	. = ALIGN(PAGE_SIZE);
307	.bss : AT(ADDR(.bss) - LOAD_OFFSET) {
308		__bss_start = .;
309		*(.bss..page_aligned)
310		*(.bss)
311		. = ALIGN(PAGE_SIZE);
312		__bss_stop = .;
313	}
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
323	_end = .;
324
325        STABS_DEBUG
326        DWARF_DEBUG
327
328	/* Sections to be discarded */
329	DISCARDS
330	/DISCARD/ : { *(.eh_frame) }
331}
332
333
334#ifdef CONFIG_X86_32
335/*
336 * The ASSERT() sink to . is intentional, for binutils 2.14 compatibility:
337 */
338. = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE),
339	   "kernel image bigger than KERNEL_IMAGE_SIZE");
340#else
341/*
342 * Per-cpu symbols which need to be offset from __per_cpu_load
343 * for the boot processor.
344 */
345#define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
346INIT_PER_CPU(gdt_page);
347INIT_PER_CPU(irq_stack_union);
348
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
355#ifdef CONFIG_SMP
356. = ASSERT((irq_stack_union == 0),
357           "irq_stack_union is not at start of per-cpu area");
358#endif
359
360#endif /* CONFIG_X86_32 */
361
362#ifdef CONFIG_KEXEC
363#include <asm/kexec.h>
364
365. = ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE,
366           "kexec control code size is too big");
367#endif
368
369