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