1/* Excerpts written by Martin Mares <mj@atrey.karlin.mff.cuni.cz> */
2/* Modified for i386/x86-64 Xen by Keir Fraser */
3
4#include <xen/cache.h>
5#include <asm/page.h>
6#undef ENTRY
7#undef ALIGN
8
9#ifdef EFI
10
11#define FORMAT "pei-x86-64"
12#undef __XEN_VIRT_START
13#define __XEN_VIRT_START __image_base__
14#define DECL_SECTION(x) x :
15
16ENTRY(efi_start)
17
18#else /* !EFI */
19
20#define FORMAT "elf64-x86-64"
21#define DECL_SECTION(x) x : AT(ADDR(x) - __XEN_VIRT_START)
22
23ENTRY(start_pa)
24
25#endif /* EFI */
26
27#if defined(CONFIG_XEN_ALIGN_2M) || defined(EFI)
28# define SECTION_ALIGN MB(2)
29#else
30# define SECTION_ALIGN PAGE_SIZE
31#endif
32
33OUTPUT_FORMAT(FORMAT, FORMAT, FORMAT)
34
35OUTPUT_ARCH(i386:x86-64)
36
37PHDRS
38{
39  text PT_LOAD ;
40#if (defined(BUILD_ID) || defined (CONFIG_PVH_GUEST)) && !defined(EFI)
41  note PT_NOTE ;
42#endif
43}
44SECTIONS
45{
46#if !defined(EFI)
47  . = __XEN_VIRT_START;
48  __image_base__ = .;
49#else
50  . = __image_base__;
51#endif
52
53#if 0
54/*
55 * We don't really use this symbol anywhere, and the way it would get defined
56 * here would result in it having a negative (wrapped to huge positive)
57 * offset relative to the .text section. That, in turn, causes an assembler
58 * truncation warning when including all symbols in the symbol table for Live
59 * Patching code.
60 */
61  __2M_text_start = .;         /* Start of 2M superpages, mapped RX. */
62#endif
63
64  start_pa = ABSOLUTE(start - __XEN_VIRT_START);
65
66  . = __XEN_VIRT_START + XEN_IMG_OFFSET;
67  _start = .;
68  DECL_SECTION(.text) {
69        _stext = .;            /* Text and read-only data */
70       *(.text)
71       *(.text.__x86_indirect_thunk_*)
72       *(.text.page_aligned)
73
74       . = ALIGN(PAGE_SIZE);
75       _stextentry = .;
76       *(.text.entry)
77       . = ALIGN(PAGE_SIZE);
78       _etextentry = .;
79
80       *(.text.cold)
81       *(.text.unlikely)
82       *(.fixup)
83       *(.text.kexec)
84       *(.gnu.warning)
85       _etext = .;             /* End of text section */
86  } :text = 0x9090
87
88  . = ALIGN(SECTION_ALIGN);
89  __2M_text_end = .;
90
91  __2M_rodata_start = .;       /* Start of 2M superpages, mapped RO. */
92  DECL_SECTION(.rodata) {
93       _srodata = .;
94       /* Bug frames table */
95       __start_bug_frames = .;
96       *(.bug_frames.0)
97       __stop_bug_frames_0 = .;
98       *(.bug_frames.1)
99       __stop_bug_frames_1 = .;
100       *(.bug_frames.2)
101       __stop_bug_frames_2 = .;
102       *(.bug_frames.3)
103       __stop_bug_frames_3 = .;
104
105       *(.rodata)
106       *(.rodata.*)
107       *(.data.rel.ro)
108       *(.data.rel.ro.*)
109
110#if defined(BUILD_ID) && defined(EFI) && !defined(BUILD_ID_EFI)
111/*
112 * No mechanism to put an PT_NOTE in the EFI file - so put
113 * it in .rodata section. (notes.o supplies us with .note.gnu.build-id).
114 */
115       . = ALIGN(4);
116       __note_gnu_build_id_start = .;
117       *(.note.gnu.build-id)
118       __note_gnu_build_id_end = .;
119#endif
120       . = ALIGN(8);
121       /* Exception table */
122       __start___ex_table = .;
123       *(.ex_table)
124       __stop___ex_table = .;
125
126       /* Pre-exception table */
127       __start___pre_ex_table = .;
128       *(.ex_table.pre)
129       __stop___pre_ex_table = .;
130
131#if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM)
132       . = ALIGN(POINTER_ALIGN);
133       __start_vpci_array = .;
134       *(SORT(.data.vpci.*))
135       __end_vpci_array = .;
136#endif
137  } :text
138
139#if defined(CONFIG_PVH_GUEST) && !defined(EFI)
140  DECL_SECTION(.note.Xen) {
141      *(.note.Xen)
142  } :note :text
143#endif
144
145#if defined(BUILD_ID)
146#if !defined(EFI)
147/*
148 * What a strange section name. The reason is that on ELF builds this section
149 * is extracted to notes.o (which then is ingested in the EFI file). But the
150 * compiler may want to inject other things in the .note which we don't care
151 * about - hence this unique name.
152 */
153  DECL_SECTION(.note.gnu.build-id) {
154       __note_gnu_build_id_start = .;
155       *(.note.gnu.build-id)
156       __note_gnu_build_id_end = .;
157  } :note :text
158#elif defined(BUILD_ID_EFI)
159  DECL_SECTION(.buildid) {
160       __note_gnu_build_id_start = .;
161       *(.buildid)
162       __note_gnu_build_id_end = .;
163  } :text
164#endif
165#endif
166
167/*
168 * ELF builds are linked to a fixed virtual address, and in principle
169 * shouldn't have a .reloc section.  However, due to the way EFI support is
170 * currently implemented, retaining the .reloc section is necessary.
171 */
172#if defined(XEN_BUILD_EFI) && !defined(EFI)
173  . = ALIGN(4);
174  DECL_SECTION(.reloc) {
175    *(.reloc)
176  } :text
177#endif
178
179  _erodata = .;
180
181  . = ALIGN(SECTION_ALIGN);
182  __2M_rodata_end = .;
183
184  __2M_init_start = .;         /* Start of 2M superpages, mapped RWX (boot only). */
185  . = ALIGN(PAGE_SIZE);             /* Init code and data */
186  __init_begin = .;
187#ifdef EFI /* EFI wants to merge all of .init.*  ELF doesn't. */
188  DECL_SECTION(.init) {
189#else
190  DECL_SECTION(.init.text) {
191#endif
192       _sinittext = .;
193       *(.init.text)
194       /*
195        * Here are the replacement instructions. The linker sticks them
196        * as binary blobs. The .altinstructions has enough data to get
197        * the address and the length of them to patch the kernel safely.
198        */
199       *(.altinstr_replacement)
200       _einittext = .;
201
202#ifdef EFI /* EFI wants to merge all of .init.*  ELF doesn't. */
203       . = ALIGN(SMP_CACHE_BYTES);
204#else
205  } :text
206  DECL_SECTION(.init.data) {
207#endif
208
209       *(.init.rodata)
210       *(.init.rodata.*)
211
212       . = ALIGN(POINTER_ALIGN);
213       __setup_start = .;
214       *(.init.setup)
215       __setup_end = .;
216
217       __initcall_start = .;
218       *(.initcallpresmp.init)
219       __presmp_initcall_end = .;
220       *(.initcall1.init)
221       __initcall_end = .;
222
223       *(.init.data)
224       *(.init.data.rel)
225       *(.init.data.rel.*)
226       . = ALIGN(4);
227       __trampoline_rel_start = .;
228       *(.trampoline_rel)
229       __trampoline_rel_stop = .;
230       __trampoline_seg_start = .;
231       *(.trampoline_seg)
232       __trampoline_seg_stop = .;
233       /*
234        * struct alt_inst entries. From the header (alternative.h):
235        * "Alternative instructions for different CPU types or capabilities"
236        * Think locking instructions on spinlocks.
237        */
238       . = ALIGN(8);
239        __alt_instructions = .;
240        *(.altinstructions)
241        __alt_instructions_end = .;
242
243#ifdef CONFIG_DEBUG_LOCK_PROFILE
244       . = ALIGN(POINTER_ALIGN);
245       __lock_profile_start = .;
246       *(.lockprofile.data)
247       __lock_profile_end = .;
248#endif
249
250       . = ALIGN(8);
251       __ctors_start = .;
252       *(.ctors)
253       *(.init_array)
254       *(SORT(.init_array.*))
255       __ctors_end = .;
256
257#if defined(CONFIG_HAS_VPCI) && !defined(CONFIG_LATE_HWDOM)
258       . = ALIGN(POINTER_ALIGN);
259       __start_vpci_array = .;
260       *(SORT(.data.vpci.*))
261       __end_vpci_array = .;
262#endif
263  } :text
264
265  . = ALIGN(SECTION_ALIGN);
266  __init_end = .;
267  __2M_init_end = .;
268
269  __2M_rwdata_start = .;       /* Start of 2M superpages, mapped RW. */
270  . = ALIGN(SMP_CACHE_BYTES);
271  DECL_SECTION(.data.read_mostly) {
272       *(.data.read_mostly)
273       . = ALIGN(8);
274       __start_schedulers_array = .;
275       *(.data.schedulers)
276       __end_schedulers_array = .;
277
278#ifdef CONFIG_HYPFS
279       . = ALIGN(8);
280       __paramhypfs_start = .;
281       *(.data.paramhypfs)
282       __paramhypfs_end = .;
283#endif
284  } :text
285
286  DECL_SECTION(.data) {
287       *(.data.page_aligned)
288       *(.data)
289       *(.data.rel)
290       *(.data.rel.*)
291       CONSTRUCTORS
292  } :text
293
294  DECL_SECTION(.bss) {
295       __bss_start = .;
296       *(.bss.stack_aligned)
297       *(.bss.page_aligned*)
298       . = ALIGN(PAGE_SIZE);
299       __per_cpu_start = .;
300       *(.bss.percpu.page_aligned)
301       *(.bss.percpu)
302       . = ALIGN(SMP_CACHE_BYTES);
303       *(.bss.percpu.read_mostly)
304       . = ALIGN(SMP_CACHE_BYTES);
305       __per_cpu_data_end = .;
306       *(.bss)
307       . = ALIGN(POINTER_ALIGN);
308       __bss_end = .;
309  } :text
310  _end = . ;
311
312  . = ALIGN(SECTION_ALIGN);
313  __2M_rwdata_end = .;
314
315#ifdef EFI
316  . = ALIGN(4);
317  DECL_SECTION(.reloc) {
318    *(.reloc)
319  } :text
320  /* Trick the linker into setting the image size to exactly 16Mb. */
321  . = ALIGN(__section_alignment__);
322  DECL_SECTION(.pad) {
323    . = ALIGN(MB(16));
324  } :text
325#endif
326
327#ifndef XEN_BUILD_EFI
328  efi = .;
329#endif
330
331#ifdef CONFIG_HYPERV_GUEST
332  hv_hcall_page = ABSOLUTE(HV_HCALL_PAGE - XEN_VIRT_START + __XEN_VIRT_START);
333#endif
334
335  /* Sections to be discarded */
336  /DISCARD/ : {
337       *(.exit.text)
338       *(.exit.data)
339       *(.exitcall.exit)
340       *(.discard)
341       *(.discard.*)
342       *(.eh_frame)
343#ifdef EFI
344       *(.comment)
345       *(.comment.*)
346       *(.note.Xen)
347#endif
348  }
349
350  /* Stabs debugging sections.  */
351  .stab 0 : { *(.stab) }
352  .stabstr 0 : { *(.stabstr) }
353  .stab.excl 0 : { *(.stab.excl) }
354  .stab.exclstr 0 : { *(.stab.exclstr) }
355  .stab.index 0 : { *(.stab.index) }
356  .stab.indexstr 0 : { *(.stab.indexstr) }
357  .comment 0 : { *(.comment) }
358}
359
360ASSERT(__2M_rwdata_end <= XEN_VIRT_END - XEN_VIRT_START + __XEN_VIRT_START -
361                          FIXADDR_X_SIZE -
362                          NR_CPUS * PAGE_SIZE,
363       "Xen image overlaps stubs area")
364
365#ifdef CONFIG_KEXEC
366ASSERT(kexec_reloc_size - kexec_reloc <= PAGE_SIZE, "kexec_reloc is too large")
367#endif
368
369/* The Multiboot setup paths relies on this to simplify superpage PTE creation. */
370ASSERT(IS_ALIGNED(_start,            MB(2)), "_start misaligned")
371
372ASSERT(IS_ALIGNED(__2M_text_end,     SECTION_ALIGN), "__2M_text_end misaligned")
373ASSERT(IS_ALIGNED(__2M_rodata_start, SECTION_ALIGN), "__2M_rodata_start misaligned")
374ASSERT(IS_ALIGNED(__2M_rodata_end,   SECTION_ALIGN), "__2M_rodata_end misaligned")
375ASSERT(IS_ALIGNED(__2M_init_start,   SECTION_ALIGN), "__2M_init_start misaligned")
376ASSERT(IS_ALIGNED(__2M_init_end,     SECTION_ALIGN), "__2M_init_end misaligned")
377ASSERT(IS_ALIGNED(__2M_rwdata_start, SECTION_ALIGN), "__2M_rwdata_start misaligned")
378ASSERT(IS_ALIGNED(__2M_rwdata_end,   SECTION_ALIGN), "__2M_rwdata_end misaligned")
379
380ASSERT(IS_ALIGNED(cpu0_stack, STACK_SIZE), "cpu0_stack misaligned")
381
382ASSERT(IS_ALIGNED(__init_begin, PAGE_SIZE), "__init_begin misaligned")
383ASSERT(IS_ALIGNED(__init_end,   PAGE_SIZE), "__init_end misaligned")
384
385ASSERT(IS_ALIGNED(trampoline_start, 4), "trampoline_start misaligned")
386ASSERT(IS_ALIGNED(trampoline_end,   4), "trampoline_end misaligned")
387ASSERT(IS_ALIGNED(__bss_start,      8), "__bss_start misaligned")
388ASSERT(IS_ALIGNED(__bss_end,        8), "__bss_end misaligned")
389
390ASSERT((trampoline_end - trampoline_start) < TRAMPOLINE_SPACE - MBI_SPACE_MIN,
391    "not enough room for trampoline and mbi data")
392ASSERT((wakeup_stack - wakeup_stack_start) >= WAKEUP_STACK_MIN,
393    "wakeup stack too small")
394
395/* Plenty of boot code assumes that Xen isn't larger than 16M. */
396ASSERT(_end - _start <= MB(16), "Xen too large for early-boot assumptions")
397