Merge tag 'kvmarm-5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmar...
[linux-2.6-microblaze.git] / arch / arm64 / kernel / vmlinux.lds.S
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * ld script to make ARM Linux kernel
4  * taken from the i386 version by Russell King
5  * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
6  */
7
8 #define RO_EXCEPTION_TABLE_ALIGN        8
9
10 #include <asm-generic/vmlinux.lds.h>
11 #include <asm/cache.h>
12 #include <asm/hyp_image.h>
13 #include <asm/kernel-pgtable.h>
14 #include <asm/memory.h>
15 #include <asm/page.h>
16
17 #include "image.h"
18
19 OUTPUT_ARCH(aarch64)
20 ENTRY(_text)
21
22 jiffies = jiffies_64;
23
24
25 #ifdef CONFIG_KVM
26 #define HYPERVISOR_EXTABLE                                      \
27         . = ALIGN(SZ_8);                                        \
28         __start___kvm_ex_table = .;                             \
29         *(__kvm_ex_table)                                       \
30         __stop___kvm_ex_table = .;
31
32 #define HYPERVISOR_PERCPU_SECTION                               \
33         . = ALIGN(PAGE_SIZE);                                   \
34         HYP_SECTION_NAME(.data..percpu) : {                     \
35                 *(HYP_SECTION_NAME(.data..percpu))              \
36         }
37 #else /* CONFIG_KVM */
38 #define HYPERVISOR_EXTABLE
39 #define HYPERVISOR_PERCPU_SECTION
40 #endif
41
42 #define HYPERVISOR_TEXT                                 \
43         /*                                              \
44          * Align to 4 KB so that                        \
45          * a) the HYP vector table is at its minimum    \
46          *    alignment of 2048 bytes                   \
47          * b) the HYP init code will not cross a page   \
48          *    boundary if its size does not exceed      \
49          *    4 KB (see related ASSERT() below)         \
50          */                                             \
51         . = ALIGN(SZ_4K);                               \
52         __hyp_idmap_text_start = .;                     \
53         *(.hyp.idmap.text)                              \
54         __hyp_idmap_text_end = .;                       \
55         __hyp_text_start = .;                           \
56         *(.hyp.text)                                    \
57         HYPERVISOR_EXTABLE                              \
58         __hyp_text_end = .;
59
60 #define IDMAP_TEXT                                      \
61         . = ALIGN(SZ_4K);                               \
62         __idmap_text_start = .;                         \
63         *(.idmap.text)                                  \
64         __idmap_text_end = .;
65
66 #ifdef CONFIG_HIBERNATION
67 #define HIBERNATE_TEXT                                  \
68         . = ALIGN(SZ_4K);                               \
69         __hibernate_exit_text_start = .;                \
70         *(.hibernate_exit.text)                         \
71         __hibernate_exit_text_end = .;
72 #else
73 #define HIBERNATE_TEXT
74 #endif
75
76 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
77 #define TRAMP_TEXT                                      \
78         . = ALIGN(PAGE_SIZE);                           \
79         __entry_tramp_text_start = .;                   \
80         *(.entry.tramp.text)                            \
81         . = ALIGN(PAGE_SIZE);                           \
82         __entry_tramp_text_end = .;
83 #else
84 #define TRAMP_TEXT
85 #endif
86
87 /*
88  * The size of the PE/COFF section that covers the kernel image, which
89  * runs from _stext to _edata, must be a round multiple of the PE/COFF
90  * FileAlignment, which we set to its minimum value of 0x200. '_stext'
91  * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
92  * boundary should be sufficient.
93  */
94 PECOFF_FILE_ALIGNMENT = 0x200;
95
96 #ifdef CONFIG_EFI
97 #define PECOFF_EDATA_PADDING    \
98         .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
99 #else
100 #define PECOFF_EDATA_PADDING
101 #endif
102
103 SECTIONS
104 {
105         /*
106          * XXX: The linker does not define how output sections are
107          * assigned to input sections when there are multiple statements
108          * matching the same input section name.  There is no documented
109          * order of matching.
110          */
111         /DISCARD/ : {
112                 EXIT_CALL
113                 *(.discard)
114                 *(.discard.*)
115                 *(.interp .dynamic)
116                 *(.dynsym .dynstr .hash .gnu.hash)
117                 *(.eh_frame)
118         }
119
120         . = KIMAGE_VADDR + TEXT_OFFSET;
121
122         .head.text : {
123                 _text = .;
124                 HEAD_TEXT
125         }
126         .text : {                       /* Real text segment            */
127                 _stext = .;             /* Text and read-only data      */
128                         IRQENTRY_TEXT
129                         SOFTIRQENTRY_TEXT
130                         ENTRY_TEXT
131                         TEXT_TEXT
132                         SCHED_TEXT
133                         CPUIDLE_TEXT
134                         LOCK_TEXT
135                         KPROBES_TEXT
136                         HYPERVISOR_TEXT
137                         IDMAP_TEXT
138                         HIBERNATE_TEXT
139                         TRAMP_TEXT
140                         *(.fixup)
141                         *(.gnu.warning)
142                 . = ALIGN(16);
143                 *(.got)                 /* Global offset table          */
144         }
145
146         . = ALIGN(SEGMENT_ALIGN);
147         _etext = .;                     /* End of text section */
148
149         /* everything from this point to __init_begin will be marked RO NX */
150         RO_DATA(PAGE_SIZE)
151
152         idmap_pg_dir = .;
153         . += IDMAP_DIR_SIZE;
154         idmap_pg_end = .;
155
156 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
157         tramp_pg_dir = .;
158         . += PAGE_SIZE;
159 #endif
160
161 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
162         reserved_ttbr0 = .;
163         . += RESERVED_TTBR0_SIZE;
164 #endif
165         swapper_pg_dir = .;
166         . += PAGE_SIZE;
167         swapper_pg_end = .;
168
169         . = ALIGN(SEGMENT_ALIGN);
170         __init_begin = .;
171         __inittext_begin = .;
172
173         INIT_TEXT_SECTION(8)
174
175         __exittext_begin = .;
176         .exit.text : {
177                 EXIT_TEXT
178         }
179         __exittext_end = .;
180
181         . = ALIGN(4);
182         .altinstructions : {
183                 __alt_instructions = .;
184                 *(.altinstructions)
185                 __alt_instructions_end = .;
186         }
187
188         . = ALIGN(SEGMENT_ALIGN);
189         __inittext_end = .;
190         __initdata_begin = .;
191
192         .init.data : {
193                 INIT_DATA
194                 INIT_SETUP(16)
195                 INIT_CALLS
196                 CON_INITCALL
197                 INIT_RAM_FS
198                 *(.init.rodata.* .init.bss)     /* from the EFI stub */
199         }
200         .exit.data : {
201                 EXIT_DATA
202         }
203
204         PERCPU_SECTION(L1_CACHE_BYTES)
205         HYPERVISOR_PERCPU_SECTION
206
207         .rela.dyn : ALIGN(8) {
208                 *(.rela .rela*)
209         }
210
211         __rela_offset   = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
212         __rela_size     = SIZEOF(.rela.dyn);
213
214 #ifdef CONFIG_RELR
215         .relr.dyn : ALIGN(8) {
216                 *(.relr.dyn)
217         }
218
219         __relr_offset   = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR);
220         __relr_size     = SIZEOF(.relr.dyn);
221 #endif
222
223         . = ALIGN(SEGMENT_ALIGN);
224         __initdata_end = .;
225         __init_end = .;
226
227         _data = .;
228         _sdata = .;
229         RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
230
231         /*
232          * Data written with the MMU off but read with the MMU on requires
233          * cache lines to be invalidated, discarding up to a Cache Writeback
234          * Granule (CWG) of data from the cache. Keep the section that
235          * requires this type of maintenance to be in its own Cache Writeback
236          * Granule (CWG) area so the cache maintenance operations don't
237          * interfere with adjacent data.
238          */
239         .mmuoff.data.write : ALIGN(SZ_2K) {
240                 __mmuoff_data_start = .;
241                 *(.mmuoff.data.write)
242         }
243         . = ALIGN(SZ_2K);
244         .mmuoff.data.read : {
245                 *(.mmuoff.data.read)
246                 __mmuoff_data_end = .;
247         }
248
249         PECOFF_EDATA_PADDING
250         __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
251         _edata = .;
252
253         BSS_SECTION(0, 0, 0)
254
255         . = ALIGN(PAGE_SIZE);
256         init_pg_dir = .;
257         . += INIT_DIR_SIZE;
258         init_pg_end = .;
259
260         . = ALIGN(SEGMENT_ALIGN);
261         __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
262         _end = .;
263
264         STABS_DEBUG
265
266         HEAD_SYMBOLS
267 }
268
269 #include "image-vars.h"
270
271 /*
272  * The HYP init code and ID map text can't be longer than a page each,
273  * and should not cross a page boundary.
274  */
275 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
276         "HYP init code too big or misaligned")
277 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
278         "ID map text too big or misaligned")
279 #ifdef CONFIG_HIBERNATION
280 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
281         <= SZ_4K, "Hibernate exit text too big or misaligned")
282 #endif
283 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
284 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
285         "Entry trampoline text too big")
286 #endif
287 /*
288  * If padding is applied before .head.text, virt<->phys conversions will fail.
289  */
290 ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")