blob: 338ddfd61a7acc7c5a27c9f2ba89a69a6af0a8ce [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/* 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#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
22OUTPUT_ARCH(aarch64)
23ENTRY(_text)
24
25jiffies = jiffies_64;
26
27
28#define HYPERVISOR_EXTABLE \
29 . = ALIGN(SZ_8); \
30 __start___kvm_ex_table = .; \
31 *(__kvm_ex_table) \
32 __stop___kvm_ex_table = .;
33
34#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); \
44 __hyp_idmap_text_start = .; \
45 *(.hyp.idmap.text) \
46 __hyp_idmap_text_end = .; \
47 __hyp_text_start = .; \
48 *(.hyp.text) \
49 HYPERVISOR_EXTABLE \
50 __hyp_text_end = .;
51
52#define IDMAP_TEXT \
53 . = ALIGN(SZ_4K); \
54 __idmap_text_start = .; \
55 *(.idmap.text) \
56 __idmap_text_end = .;
57
58#ifdef CONFIG_HIBERNATION
59#define HIBERNATE_TEXT \
60 . = ALIGN(SZ_4K); \
61 __hibernate_exit_text_start = .; \
62 *(.hibernate_exit.text) \
63 __hibernate_exit_text_end = .;
64#else
65#define HIBERNATE_TEXT
66#endif
67
68#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
69#define TRAMP_TEXT \
70 . = ALIGN(PAGE_SIZE); \
71 __entry_tramp_text_start = .; \
72 *(.entry.tramp.text) \
73 . = ALIGN(PAGE_SIZE); \
74 __entry_tramp_text_end = .;
75#else
76#define TRAMP_TEXT
77#endif
78
79/*
80 * 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'
83 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
84 * boundary should be sufficient.
85 */
86PECOFF_FILE_ALIGNMENT = 0x200;
87
88#ifdef CONFIG_EFI
89#define PECOFF_EDATA_PADDING \
90 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
91#else
92#define PECOFF_EDATA_PADDING
93#endif
94
95SECTIONS
96{
97 /*
98 * XXX: The linker does not define how output sections are
99 * assigned to input sections when there are multiple statements
100 * matching the same input section name. There is no documented
101 * order of matching.
102 */
103 /DISCARD/ : {
104 ARM_EXIT_DISCARD(EXIT_TEXT)
105 ARM_EXIT_DISCARD(EXIT_DATA)
106 EXIT_CALL
107 *(.discard)
108 *(.discard.*)
109 *(.interp .dynamic)
110 *(.dynsym .dynstr .hash .gnu.hash)
111 *(.eh_frame)
112 }
113
114 . = KIMAGE_VADDR + TEXT_OFFSET;
115
116 .head.text : {
117 _text = .;
118 HEAD_TEXT
119 }
120 .text : { /* Real text segment */
121 _stext = .; /* Text and read-only data */
122 __exception_text_start = .;
123 *(.exception.text)
124 __exception_text_end = .;
125 IRQENTRY_TEXT
126 SOFTIRQENTRY_TEXT
127 ENTRY_TEXT
128 TEXT_TEXT
129 SCHED_TEXT
130 CPUIDLE_TEXT
131 LOCK_TEXT
132 KPROBES_TEXT
133 HYPERVISOR_TEXT
134 IDMAP_TEXT
135 HIBERNATE_TEXT
136 TRAMP_TEXT
137 *(.text..L.cfi.jumptable .text..L.cfi.jumptable.*)
138 *(.fixup)
139 *(.gnu.warning)
140 . = ALIGN(16);
141 *(.got) /* Global offset table */
142 }
143
144 . = ALIGN(SEGMENT_ALIGN);
145 _etext = .; /* End of text section */
146
147 RO_DATA(PAGE_SIZE) /* everything from this point to */
148 EXCEPTION_TABLE(8) /* __init_begin will be marked RO NX */
149 NOTES
150
151 . = ALIGN(PAGE_SIZE);
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 reserved_pg_dir = .;
162 . += PAGE_SIZE;
163
164 swapper_pg_dir = .;
165 . += PAGE_SIZE;
166
167 . = ALIGN(SEGMENT_ALIGN);
168 __init_begin = .;
169 __inittext_begin = .;
170
171 INIT_TEXT_SECTION(8)
172
173 __exittext_begin = .;
174 .exit.text : {
175 ARM_EXIT_KEEP(EXIT_TEXT)
176 }
177 __exittext_end = .;
178
179 . = ALIGN(4);
180 .altinstructions : {
181 __alt_instructions = .;
182 *(.altinstructions)
183 __alt_instructions_end = .;
184 }
185 .altinstr_replacement : {
186 *(.altinstr_replacement)
187 }
188
189 . = ALIGN(PAGE_SIZE);
190 __inittext_end = .;
191 __initdata_begin = .;
192
193 .init.data : {
194 INIT_DATA
195 INIT_SETUP(16)
196 INIT_CALLS
197 CON_INITCALL
198 INIT_RAM_FS
199 *(.init.rodata.* .init.bss) /* from the EFI stub */
200 }
201 .exit.data : {
202 ARM_EXIT_KEEP(EXIT_DATA)
203 }
204
205 PERCPU_SECTION(L1_CACHE_BYTES)
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_SECTION(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 __pecoff_data_size = ABSOLUTE(. - __initdata_begin);
261 _end = .;
262
263 STABS_DEBUG
264
265 HEAD_SYMBOLS
266}
267
268#include "image-vars.h"
269
270/*
271 * The HYP init code and ID map text can't be longer than a page each,
272 * and should not cross a page boundary.
273 */
274ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
275 "HYP init code too big or misaligned")
276ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
277 "ID map text too big or misaligned")
278#ifdef CONFIG_HIBERNATION
279ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
280 <= SZ_4K, "Hibernate exit text too big or misaligned")
281#endif
282#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
283ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE,
284 "Entry trampoline text too big")
285#endif
286/*
287 * If padding is applied before .head.text, virt<->phys conversions will fail.
288 */
289ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")