forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/arch/arm64/kernel/vmlinux.lds.S
....@@ -5,48 +5,83 @@
55 * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
66 */
77
8
-#include <asm-generic/vmlinux.lds.h>
9
-#include <asm/cache.h>
10
-#include <asm/kernel-pgtable.h>
11
-#include <asm/thread_info.h>
12
-#include <asm/memory.h>
13
-#include <asm/page.h>
14
-#include <asm/pgtable.h>
15
-
16
-#include "image.h"
17
-
18
-/* .exit.text needed in case of alternative patching */
19
-#define ARM_EXIT_KEEP(x) x
20
-#define ARM_EXIT_DISCARD(x)
21
-
22
-OUTPUT_ARCH(aarch64)
23
-ENTRY(_text)
24
-
25
-jiffies = jiffies_64;
26
-
27
-
8
+#include <asm/hyp_image.h>
9
+#ifdef CONFIG_KVM
2810 #define HYPERVISOR_EXTABLE \
2911 . = ALIGN(SZ_8); \
3012 __start___kvm_ex_table = .; \
3113 *(__kvm_ex_table) \
3214 __stop___kvm_ex_table = .;
3315
16
+#define HYPERVISOR_DATA_SECTIONS \
17
+ HYP_SECTION_NAME(.rodata) : { \
18
+ . = ALIGN(PAGE_SIZE); \
19
+ __hyp_rodata_start = .; \
20
+ *(HYP_SECTION_NAME(.data..ro_after_init)) \
21
+ *(HYP_SECTION_NAME(.rodata)) \
22
+ . = ALIGN(PAGE_SIZE); \
23
+ __hyp_rodata_end = .; \
24
+ }
25
+
26
+#define HYPERVISOR_PERCPU_SECTION \
27
+ . = ALIGN(PAGE_SIZE); \
28
+ HYP_SECTION_NAME(.data..percpu) : { \
29
+ *(HYP_SECTION_NAME(.data..percpu)) \
30
+ }
31
+
32
+#define HYPERVISOR_RELOC_SECTION \
33
+ .hyp.reloc : ALIGN(4) { \
34
+ __hyp_reloc_begin = .; \
35
+ *(.hyp.reloc) \
36
+ __hyp_reloc_end = .; \
37
+ }
38
+
39
+#define BSS_FIRST_SECTIONS \
40
+ __hyp_bss_start = .; \
41
+ *(HYP_SECTION_NAME(.bss)) \
42
+ . = ALIGN(PAGE_SIZE); \
43
+ __hyp_bss_end = .;
44
+
45
+/*
46
+ * We require that __hyp_bss_start and __bss_start are aligned, and enforce it
47
+ * with an assertion. But the BSS_SECTION macro places an empty .sbss section
48
+ * between them, which can in some cases cause the linker to misalign them. To
49
+ * work around the issue, force a page alignment for __bss_start.
50
+ */
51
+#define SBSS_ALIGN PAGE_SIZE
52
+#else /* CONFIG_KVM */
53
+#define HYPERVISOR_EXTABLE
54
+#define HYPERVISOR_DATA_SECTIONS
55
+#define HYPERVISOR_PERCPU_SECTION
56
+#define HYPERVISOR_RELOC_SECTION
57
+#define SBSS_ALIGN 0
58
+#endif
59
+
60
+#define RO_EXCEPTION_TABLE_ALIGN 8
61
+#define RUNTIME_DISCARD_EXIT
62
+
63
+#include <asm-generic/vmlinux.lds.h>
64
+#include <asm/cache.h>
65
+#include <asm/kernel-pgtable.h>
66
+#include <asm/memory.h>
67
+#include <asm/page.h>
68
+
69
+#include "image.h"
70
+
71
+OUTPUT_ARCH(aarch64)
72
+ENTRY(_text)
73
+
74
+jiffies = jiffies_64;
75
+
3476 #define HYPERVISOR_TEXT \
35
- /* \
36
- * Align to 4 KB so that \
37
- * a) the HYP vector table is at its minimum \
38
- * alignment of 2048 bytes \
39
- * b) the HYP init code will not cross a page \
40
- * boundary if its size does not exceed \
41
- * 4 KB (see related ASSERT() below) \
42
- */ \
43
- . = ALIGN(SZ_4K); \
77
+ . = ALIGN(PAGE_SIZE); \
4478 __hyp_idmap_text_start = .; \
4579 *(.hyp.idmap.text) \
4680 __hyp_idmap_text_end = .; \
4781 __hyp_text_start = .; \
4882 *(.hyp.text) \
4983 HYPERVISOR_EXTABLE \
84
+ . = ALIGN(PAGE_SIZE); \
5085 __hyp_text_end = .;
5186
5287 #define IDMAP_TEXT \
....@@ -78,8 +113,8 @@
78113
79114 /*
80115 * The size of the PE/COFF section that covers the kernel image, which
81
- * runs from stext to _edata, must be a round multiple of the PE/COFF
82
- * FileAlignment, which we set to its minimum value of 0x200. 'stext'
116
+ * runs from _stext to _edata, must be a round multiple of the PE/COFF
117
+ * FileAlignment, which we set to its minimum value of 0x200. '_stext'
83118 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
84119 * boundary should be sufficient.
85120 */
....@@ -100,18 +135,13 @@
100135 * matching the same input section name. There is no documented
101136 * order of matching.
102137 */
138
+ DISCARDS
103139 /DISCARD/ : {
104
- ARM_EXIT_DISCARD(EXIT_TEXT)
105
- ARM_EXIT_DISCARD(EXIT_DATA)
106
- EXIT_CALL
107
- *(.discard)
108
- *(.discard.*)
109140 *(.interp .dynamic)
110141 *(.dynsym .dynstr .hash .gnu.hash)
111
- *(.eh_frame)
112142 }
113143
114
- . = KIMAGE_VADDR + TEXT_OFFSET;
144
+ . = KIMAGE_VADDR;
115145
116146 .head.text : {
117147 _text = .;
....@@ -119,9 +149,6 @@
119149 }
120150 .text : { /* Real text segment */
121151 _stext = .; /* Text and read-only data */
122
- __exception_text_start = .;
123
- *(.exception.text)
124
- __exception_text_end = .;
125152 IRQENTRY_TEXT
126153 SOFTIRQENTRY_TEXT
127154 ENTRY_TEXT
....@@ -140,21 +167,48 @@
140167 *(.got) /* Global offset table */
141168 }
142169
170
+ /*
171
+ * Make sure that the .got.plt is either completely empty or it
172
+ * contains only the lazy dispatch entries.
173
+ */
174
+ .got.plt : { *(.got.plt) }
175
+ ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
176
+ "Unexpected GOT/PLT entries detected!")
177
+
143178 . = ALIGN(SEGMENT_ALIGN);
144179 _etext = .; /* End of text section */
145180
146
- RO_DATA(PAGE_SIZE) /* everything from this point to */
147
- EXCEPTION_TABLE(8) /* __init_begin will be marked RO NX */
148
- NOTES
181
+ /* everything from this point to __init_begin will be marked RO NX */
182
+ RO_DATA(PAGE_SIZE)
183
+
184
+ HYPERVISOR_DATA_SECTIONS
185
+
186
+ idmap_pg_dir = .;
187
+ . += IDMAP_DIR_SIZE;
188
+ idmap_pg_end = .;
189
+
190
+#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
191
+ tramp_pg_dir = .;
192
+ . += PAGE_SIZE;
193
+#endif
194
+
195
+ reserved_pg_dir = .;
196
+ . += PAGE_SIZE;
197
+
198
+ swapper_pg_dir = .;
199
+ . += PAGE_SIZE;
149200
150201 . = ALIGN(SEGMENT_ALIGN);
151202 __init_begin = .;
152203 __inittext_begin = .;
153204
154205 INIT_TEXT_SECTION(8)
206
+
207
+ __exittext_begin = .;
155208 .exit.text : {
156
- ARM_EXIT_KEEP(EXIT_TEXT)
209
+ EXIT_TEXT
157210 }
211
+ __exittext_end = .;
158212
159213 . = ALIGN(4);
160214 .altinstructions : {
....@@ -162,11 +216,8 @@
162216 *(.altinstructions)
163217 __alt_instructions_end = .;
164218 }
165
- .altinstr_replacement : {
166
- *(.altinstr_replacement)
167
- }
168219
169
- . = ALIGN(PAGE_SIZE);
220
+ . = ALIGN(SEGMENT_ALIGN);
170221 __inittext_end = .;
171222 __initdata_begin = .;
172223
....@@ -175,15 +226,17 @@
175226 INIT_SETUP(16)
176227 INIT_CALLS
177228 CON_INITCALL
178
- SECURITY_INITCALL
179229 INIT_RAM_FS
180
- *(.init.rodata.* .init.bss) /* from the EFI stub */
230
+ *(.init.altinstructions .init.rodata.* .init.bss) /* from the EFI stub */
181231 }
182232 .exit.data : {
183
- ARM_EXIT_KEEP(EXIT_DATA)
233
+ EXIT_DATA
184234 }
185235
186236 PERCPU_SECTION(L1_CACHE_BYTES)
237
+ HYPERVISOR_PERCPU_SECTION
238
+
239
+ HYPERVISOR_RELOC_SECTION
187240
188241 .rela.dyn : ALIGN(8) {
189242 *(.rela .rela*)
....@@ -207,7 +260,7 @@
207260
208261 _data = .;
209262 _sdata = .;
210
- RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
263
+ RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
211264
212265 /*
213266 * Data written with the MMU off but read with the MMU on requires
....@@ -231,39 +284,45 @@
231284 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
232285 _edata = .;
233286
234
- BSS_SECTION(0, 0, 0)
287
+ BSS_SECTION(SBSS_ALIGN, 0, 0)
235288
236289 . = ALIGN(PAGE_SIZE);
237
- idmap_pg_dir = .;
238
- . += IDMAP_DIR_SIZE;
290
+ init_pg_dir = .;
291
+ . += INIT_DIR_SIZE;
292
+ init_pg_end = .;
239293
240
-#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
241
- tramp_pg_dir = .;
242
- . += PAGE_SIZE;
243
-#endif
244
-
245
-#ifdef CONFIG_ARM64_SW_TTBR0_PAN
246
- reserved_ttbr0 = .;
247
- . += RESERVED_TTBR0_SIZE;
248
-#endif
249
- swapper_pg_dir = .;
250
- . += SWAPPER_DIR_SIZE;
251
- swapper_pg_end = .;
252
-
294
+ . = ALIGN(SEGMENT_ALIGN);
253295 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
254296 _end = .;
255297
256298 STABS_DEBUG
299
+ DWARF_DEBUG
300
+ ELF_DETAILS
257301
258302 HEAD_SYMBOLS
303
+
304
+ /*
305
+ * Sections that should stay zero sized, which is safer to
306
+ * explicitly check instead of blindly discarding.
307
+ */
308
+ .plt : {
309
+ *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
310
+ }
311
+ ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
312
+
313
+ .data.rel.ro : { *(.data.rel.ro) }
314
+ ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
259315 }
260316
317
+#include "image-vars.h"
318
+
261319 /*
262
- * The HYP init code and ID map text can't be longer than a page each,
263
- * and should not cross a page boundary.
320
+ * The HYP init code and ID map text can't be longer than a page each. The
321
+ * former is page-aligned, but the latter may not be with 16K or 64K pages, so
322
+ * it should also not cross a page boundary.
264323 */
265
-ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
266
- "HYP init code too big or misaligned")
324
+ASSERT(__hyp_idmap_text_end - __hyp_idmap_text_start <= PAGE_SIZE,
325
+ "HYP init code too big")
267326 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
268327 "ID map text too big or misaligned")
269328 #ifdef CONFIG_HIBERNATION
....@@ -271,10 +330,13 @@
271330 <= SZ_4K, "Hibernate exit text too big or misaligned")
272331 #endif
273332 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
274
-ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
333
+ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE,
275334 "Entry trampoline text too big")
335
+#endif
336
+#ifdef CONFIG_KVM
337
+ASSERT(__hyp_bss_start == __bss_start, "HYP and Host BSS are misaligned")
276338 #endif
277339 /*
278340 * If padding is applied before .head.text, virt<->phys conversions will fail.
279341 */
280
-ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")
342
+ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")