xref: /linux/include/asm-generic/vmlinux.lds.h (revision da6f8320d58623eae9b6fa2f09b1b4f60a772ce9)
1 /*
2  * Helper macros to support writing architecture specific
3  * linker scripts.
4  *
5  * A minimal linker scripts has following content:
6  * [This is a sample, architectures may have special requiriements]
7  *
8  * OUTPUT_FORMAT(...)
9  * OUTPUT_ARCH(...)
10  * ENTRY(...)
11  * SECTIONS
12  * {
13  *	. = START;
14  *	__init_begin = .;
15  *	HEAD_TEXT_SECTION
16  *	INIT_TEXT_SECTION(PAGE_SIZE)
17  *	INIT_DATA_SECTION(...)
18  *	PERCPU_SECTION(CACHELINE_SIZE)
19  *	__init_end = .;
20  *
21  *	_stext = .;
22  *	TEXT_SECTION = 0
23  *	_etext = .;
24  *
25  *      _sdata = .;
26  *	RO_DATA_SECTION(PAGE_SIZE)
27  *	RW_DATA_SECTION(...)
28  *	_edata = .;
29  *
30  *	EXCEPTION_TABLE(...)
31  *	NOTES
32  *
33  *	BSS_SECTION(0, 0, 0)
34  *	_end = .;
35  *
36  *	STABS_DEBUG
37  *	DWARF_DEBUG
38  *
39  *	DISCARDS		// must be the last
40  * }
41  *
42  * [__init_begin, __init_end] is the init section that may be freed after init
43  * 	// __init_begin and __init_end should be page aligned, so that we can
44  *	// free the whole .init memory
45  * [_stext, _etext] is the text section
46  * [_sdata, _edata] is the data section
47  *
48  * Some of the included output section have their own set of constants.
49  * Examples are: [__initramfs_start, __initramfs_end] for initramfs and
50  *               [__nosave_begin, __nosave_end] for the nosave data
51  */
52 
53 #ifndef LOAD_OFFSET
54 #define LOAD_OFFSET 0
55 #endif
56 
57 #include <linux/export.h>
58 
59 /* Align . to a 8 byte boundary equals to maximum function alignment. */
60 #define ALIGN_FUNCTION()  . = ALIGN(8)
61 
62 /*
63  * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which
64  * generates .data.identifier sections, which need to be pulled in with
65  * .data. We don't want to pull in .data..other sections, which Linux
66  * has defined. Same for text and bss.
67  */
68 #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
69 #define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
70 #define DATA_MAIN .data .data.[0-9a-zA-Z_]*
71 #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]*
72 #else
73 #define TEXT_MAIN .text
74 #define DATA_MAIN .data
75 #define BSS_MAIN .bss
76 #endif
77 
78 /*
79  * Align to a 32 byte boundary equal to the
80  * alignment gcc 4.5 uses for a struct
81  */
82 #define STRUCT_ALIGNMENT 32
83 #define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
84 
85 /* The actual configuration determine if the init/exit sections
86  * are handled as text/data or they can be discarded (which
87  * often happens at runtime)
88  */
89 #ifdef CONFIG_HOTPLUG_CPU
90 #define CPU_KEEP(sec)    *(.cpu##sec)
91 #define CPU_DISCARD(sec)
92 #else
93 #define CPU_KEEP(sec)
94 #define CPU_DISCARD(sec) *(.cpu##sec)
95 #endif
96 
97 #if defined(CONFIG_MEMORY_HOTPLUG)
98 #define MEM_KEEP(sec)    *(.mem##sec)
99 #define MEM_DISCARD(sec)
100 #else
101 #define MEM_KEEP(sec)
102 #define MEM_DISCARD(sec) *(.mem##sec)
103 #endif
104 
105 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
106 #define MCOUNT_REC()	. = ALIGN(8);				\
107 			VMLINUX_SYMBOL(__start_mcount_loc) = .; \
108 			*(__mcount_loc)				\
109 			VMLINUX_SYMBOL(__stop_mcount_loc) = .;
110 #else
111 #define MCOUNT_REC()
112 #endif
113 
114 #ifdef CONFIG_TRACE_BRANCH_PROFILING
115 #define LIKELY_PROFILE()	VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \
116 				*(_ftrace_annotated_branch)			      \
117 				VMLINUX_SYMBOL(__stop_annotated_branch_profile) = .;
118 #else
119 #define LIKELY_PROFILE()
120 #endif
121 
122 #ifdef CONFIG_PROFILE_ALL_BRANCHES
123 #define BRANCH_PROFILE()	VMLINUX_SYMBOL(__start_branch_profile) = .;   \
124 				*(_ftrace_branch)			      \
125 				VMLINUX_SYMBOL(__stop_branch_profile) = .;
126 #else
127 #define BRANCH_PROFILE()
128 #endif
129 
130 #ifdef CONFIG_KPROBES
131 #define KPROBE_BLACKLIST()	. = ALIGN(8);				      \
132 				VMLINUX_SYMBOL(__start_kprobe_blacklist) = .; \
133 				KEEP(*(_kprobe_blacklist))		      \
134 				VMLINUX_SYMBOL(__stop_kprobe_blacklist) = .;
135 #else
136 #define KPROBE_BLACKLIST()
137 #endif
138 
139 #ifdef CONFIG_EVENT_TRACING
140 #define FTRACE_EVENTS()	. = ALIGN(8);					\
141 			VMLINUX_SYMBOL(__start_ftrace_events) = .;	\
142 			KEEP(*(_ftrace_events))				\
143 			VMLINUX_SYMBOL(__stop_ftrace_events) = .;	\
144 			VMLINUX_SYMBOL(__start_ftrace_eval_maps) = .;	\
145 			KEEP(*(_ftrace_eval_map))			\
146 			VMLINUX_SYMBOL(__stop_ftrace_eval_maps) = .;
147 #else
148 #define FTRACE_EVENTS()
149 #endif
150 
151 #ifdef CONFIG_TRACING
152 #define TRACE_PRINTKS() VMLINUX_SYMBOL(__start___trace_bprintk_fmt) = .;      \
153 			 KEEP(*(__trace_printk_fmt)) /* Trace_printk fmt' pointer */ \
154 			 VMLINUX_SYMBOL(__stop___trace_bprintk_fmt) = .;
155 #define TRACEPOINT_STR() VMLINUX_SYMBOL(__start___tracepoint_str) = .;	\
156 			 KEEP(*(__tracepoint_str)) /* Trace_printk fmt' pointer */ \
157 			 VMLINUX_SYMBOL(__stop___tracepoint_str) = .;
158 #else
159 #define TRACE_PRINTKS()
160 #define TRACEPOINT_STR()
161 #endif
162 
163 #ifdef CONFIG_FTRACE_SYSCALLS
164 #define TRACE_SYSCALLS() . = ALIGN(8);					\
165 			 VMLINUX_SYMBOL(__start_syscalls_metadata) = .;	\
166 			 KEEP(*(__syscalls_metadata))			\
167 			 VMLINUX_SYMBOL(__stop_syscalls_metadata) = .;
168 #else
169 #define TRACE_SYSCALLS()
170 #endif
171 
172 #ifdef CONFIG_SERIAL_EARLYCON
173 #define EARLYCON_TABLE() STRUCT_ALIGN();			\
174 			 VMLINUX_SYMBOL(__earlycon_table) = .;	\
175 			 KEEP(*(__earlycon_table))		\
176 			 VMLINUX_SYMBOL(__earlycon_table_end) = .;
177 #else
178 #define EARLYCON_TABLE()
179 #endif
180 
181 #define ___OF_TABLE(cfg, name)	_OF_TABLE_##cfg(name)
182 #define __OF_TABLE(cfg, name)	___OF_TABLE(cfg, name)
183 #define OF_TABLE(cfg, name)	__OF_TABLE(IS_ENABLED(cfg), name)
184 #define _OF_TABLE_0(name)
185 #define _OF_TABLE_1(name)						\
186 	. = ALIGN(8);							\
187 	VMLINUX_SYMBOL(__##name##_of_table) = .;			\
188 	KEEP(*(__##name##_of_table))					\
189 	KEEP(*(__##name##_of_table_end))
190 
191 #define TIMER_OF_TABLES()	OF_TABLE(CONFIG_TIMER_OF, timer)
192 #define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip)
193 #define CLK_OF_TABLES()		OF_TABLE(CONFIG_COMMON_CLK, clk)
194 #define IOMMU_OF_TABLES()	OF_TABLE(CONFIG_OF_IOMMU, iommu)
195 #define RESERVEDMEM_OF_TABLES()	OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem)
196 #define CPU_METHOD_OF_TABLES()	OF_TABLE(CONFIG_SMP, cpu_method)
197 #define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method)
198 
199 #ifdef CONFIG_ACPI
200 #define ACPI_PROBE_TABLE(name)						\
201 	. = ALIGN(8);							\
202 	VMLINUX_SYMBOL(__##name##_acpi_probe_table) = .;		\
203 	KEEP(*(__##name##_acpi_probe_table))				\
204 	VMLINUX_SYMBOL(__##name##_acpi_probe_table_end) = .;
205 #else
206 #define ACPI_PROBE_TABLE(name)
207 #endif
208 
209 #define KERNEL_DTB()							\
210 	STRUCT_ALIGN();							\
211 	VMLINUX_SYMBOL(__dtb_start) = .;				\
212 	KEEP(*(.dtb.init.rodata))					\
213 	VMLINUX_SYMBOL(__dtb_end) = .;
214 
215 /*
216  * .data section
217  */
218 #define DATA_DATA							\
219 	*(.xiptext)							\
220 	*(DATA_MAIN)							\
221 	*(.ref.data)							\
222 	*(.data..shared_aligned) /* percpu related */			\
223 	MEM_KEEP(init.data)						\
224 	MEM_KEEP(exit.data)						\
225 	*(.data.unlikely)						\
226 	VMLINUX_SYMBOL(__start_once) = .;				\
227 	*(.data.once)							\
228 	VMLINUX_SYMBOL(__end_once) = .;					\
229 	STRUCT_ALIGN();							\
230 	*(__tracepoints)						\
231 	/* implement dynamic printk debug */				\
232 	. = ALIGN(8);                                                   \
233 	VMLINUX_SYMBOL(__start___jump_table) = .;                       \
234 	KEEP(*(__jump_table))                                           \
235 	VMLINUX_SYMBOL(__stop___jump_table) = .;                        \
236 	. = ALIGN(8);							\
237 	VMLINUX_SYMBOL(__start___verbose) = .;                          \
238 	KEEP(*(__verbose))                                              \
239 	VMLINUX_SYMBOL(__stop___verbose) = .;				\
240 	LIKELY_PROFILE()		       				\
241 	BRANCH_PROFILE()						\
242 	TRACE_PRINTKS()							\
243 	TRACEPOINT_STR()
244 
245 /*
246  * Data section helpers
247  */
248 #define NOSAVE_DATA							\
249 	. = ALIGN(PAGE_SIZE);						\
250 	VMLINUX_SYMBOL(__nosave_begin) = .;				\
251 	*(.data..nosave)						\
252 	. = ALIGN(PAGE_SIZE);						\
253 	VMLINUX_SYMBOL(__nosave_end) = .;
254 
255 #define PAGE_ALIGNED_DATA(page_align)					\
256 	. = ALIGN(page_align);						\
257 	*(.data..page_aligned)
258 
259 #define READ_MOSTLY_DATA(align)						\
260 	. = ALIGN(align);						\
261 	*(.data..read_mostly)						\
262 	. = ALIGN(align);
263 
264 #define CACHELINE_ALIGNED_DATA(align)					\
265 	. = ALIGN(align);						\
266 	*(.data..cacheline_aligned)
267 
268 #define INIT_TASK_DATA(align)						\
269 	. = ALIGN(align);						\
270 	VMLINUX_SYMBOL(__start_init_task) = .;				\
271 	VMLINUX_SYMBOL(init_thread_union) = .;				\
272 	VMLINUX_SYMBOL(init_stack) = .;					\
273 	*(.data..init_task)						\
274 	*(.data..init_thread_info)					\
275 	. = VMLINUX_SYMBOL(__start_init_task) + THREAD_SIZE;		\
276 	VMLINUX_SYMBOL(__end_init_task) = .;
277 
278 /*
279  * Allow architectures to handle ro_after_init data on their
280  * own by defining an empty RO_AFTER_INIT_DATA.
281  */
282 #ifndef RO_AFTER_INIT_DATA
283 #define RO_AFTER_INIT_DATA						\
284 	VMLINUX_SYMBOL(__start_ro_after_init) = .;			\
285 	*(.data..ro_after_init)						\
286 	VMLINUX_SYMBOL(__end_ro_after_init) = .;
287 #endif
288 
289 /*
290  * Read only Data
291  */
292 #define RO_DATA_SECTION(align)						\
293 	. = ALIGN((align));						\
294 	.rodata           : AT(ADDR(.rodata) - LOAD_OFFSET) {		\
295 		VMLINUX_SYMBOL(__start_rodata) = .;			\
296 		*(.rodata) *(.rodata.*)					\
297 		RO_AFTER_INIT_DATA	/* Read only after init */	\
298 		KEEP(*(__vermagic))	/* Kernel version magic */	\
299 		. = ALIGN(8);						\
300 		VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .;		\
301 		KEEP(*(__tracepoints_ptrs)) /* Tracepoints: pointer array */ \
302 		VMLINUX_SYMBOL(__stop___tracepoints_ptrs) = .;		\
303 		*(__tracepoints_strings)/* Tracepoints: strings */	\
304 	}								\
305 									\
306 	.rodata1          : AT(ADDR(.rodata1) - LOAD_OFFSET) {		\
307 		*(.rodata1)						\
308 	}								\
309 									\
310 	/* PCI quirks */						\
311 	.pci_fixup        : AT(ADDR(.pci_fixup) - LOAD_OFFSET) {	\
312 		VMLINUX_SYMBOL(__start_pci_fixups_early) = .;		\
313 		KEEP(*(.pci_fixup_early))				\
314 		VMLINUX_SYMBOL(__end_pci_fixups_early) = .;		\
315 		VMLINUX_SYMBOL(__start_pci_fixups_header) = .;		\
316 		KEEP(*(.pci_fixup_header))				\
317 		VMLINUX_SYMBOL(__end_pci_fixups_header) = .;		\
318 		VMLINUX_SYMBOL(__start_pci_fixups_final) = .;		\
319 		KEEP(*(.pci_fixup_final))				\
320 		VMLINUX_SYMBOL(__end_pci_fixups_final) = .;		\
321 		VMLINUX_SYMBOL(__start_pci_fixups_enable) = .;		\
322 		KEEP(*(.pci_fixup_enable))				\
323 		VMLINUX_SYMBOL(__end_pci_fixups_enable) = .;		\
324 		VMLINUX_SYMBOL(__start_pci_fixups_resume) = .;		\
325 		KEEP(*(.pci_fixup_resume))				\
326 		VMLINUX_SYMBOL(__end_pci_fixups_resume) = .;		\
327 		VMLINUX_SYMBOL(__start_pci_fixups_resume_early) = .;	\
328 		KEEP(*(.pci_fixup_resume_early))			\
329 		VMLINUX_SYMBOL(__end_pci_fixups_resume_early) = .;	\
330 		VMLINUX_SYMBOL(__start_pci_fixups_suspend) = .;		\
331 		KEEP(*(.pci_fixup_suspend))				\
332 		VMLINUX_SYMBOL(__end_pci_fixups_suspend) = .;		\
333 		VMLINUX_SYMBOL(__start_pci_fixups_suspend_late) = .;	\
334 		KEEP(*(.pci_fixup_suspend_late))			\
335 		VMLINUX_SYMBOL(__end_pci_fixups_suspend_late) = .;	\
336 	}								\
337 									\
338 	/* Built-in firmware blobs */					\
339 	.builtin_fw        : AT(ADDR(.builtin_fw) - LOAD_OFFSET) {	\
340 		VMLINUX_SYMBOL(__start_builtin_fw) = .;			\
341 		KEEP(*(.builtin_fw))					\
342 		VMLINUX_SYMBOL(__end_builtin_fw) = .;			\
343 	}								\
344 									\
345 	TRACEDATA							\
346 									\
347 	/* Kernel symbol table: Normal symbols */			\
348 	__ksymtab         : AT(ADDR(__ksymtab) - LOAD_OFFSET) {		\
349 		VMLINUX_SYMBOL(__start___ksymtab) = .;			\
350 		KEEP(*(SORT(___ksymtab+*)))				\
351 		VMLINUX_SYMBOL(__stop___ksymtab) = .;			\
352 	}								\
353 									\
354 	/* Kernel symbol table: GPL-only symbols */			\
355 	__ksymtab_gpl     : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) {	\
356 		VMLINUX_SYMBOL(__start___ksymtab_gpl) = .;		\
357 		KEEP(*(SORT(___ksymtab_gpl+*)))				\
358 		VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .;		\
359 	}								\
360 									\
361 	/* Kernel symbol table: Normal unused symbols */		\
362 	__ksymtab_unused  : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) {	\
363 		VMLINUX_SYMBOL(__start___ksymtab_unused) = .;		\
364 		KEEP(*(SORT(___ksymtab_unused+*)))			\
365 		VMLINUX_SYMBOL(__stop___ksymtab_unused) = .;		\
366 	}								\
367 									\
368 	/* Kernel symbol table: GPL-only unused symbols */		\
369 	__ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \
370 		VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .;	\
371 		KEEP(*(SORT(___ksymtab_unused_gpl+*)))			\
372 		VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .;	\
373 	}								\
374 									\
375 	/* Kernel symbol table: GPL-future-only symbols */		\
376 	__ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
377 		VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .;	\
378 		KEEP(*(SORT(___ksymtab_gpl_future+*)))			\
379 		VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .;	\
380 	}								\
381 									\
382 	/* Kernel symbol table: Normal symbols */			\
383 	__kcrctab         : AT(ADDR(__kcrctab) - LOAD_OFFSET) {		\
384 		VMLINUX_SYMBOL(__start___kcrctab) = .;			\
385 		KEEP(*(SORT(___kcrctab+*)))				\
386 		VMLINUX_SYMBOL(__stop___kcrctab) = .;			\
387 	}								\
388 									\
389 	/* Kernel symbol table: GPL-only symbols */			\
390 	__kcrctab_gpl     : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) {	\
391 		VMLINUX_SYMBOL(__start___kcrctab_gpl) = .;		\
392 		KEEP(*(SORT(___kcrctab_gpl+*)))				\
393 		VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .;		\
394 	}								\
395 									\
396 	/* Kernel symbol table: Normal unused symbols */		\
397 	__kcrctab_unused  : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) {	\
398 		VMLINUX_SYMBOL(__start___kcrctab_unused) = .;		\
399 		KEEP(*(SORT(___kcrctab_unused+*)))			\
400 		VMLINUX_SYMBOL(__stop___kcrctab_unused) = .;		\
401 	}								\
402 									\
403 	/* Kernel symbol table: GPL-only unused symbols */		\
404 	__kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \
405 		VMLINUX_SYMBOL(__start___kcrctab_unused_gpl) = .;	\
406 		KEEP(*(SORT(___kcrctab_unused_gpl+*)))			\
407 		VMLINUX_SYMBOL(__stop___kcrctab_unused_gpl) = .;	\
408 	}								\
409 									\
410 	/* Kernel symbol table: GPL-future-only symbols */		\
411 	__kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \
412 		VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .;	\
413 		KEEP(*(SORT(___kcrctab_gpl_future+*)))			\
414 		VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .;	\
415 	}								\
416 									\
417 	/* Kernel symbol table: strings */				\
418         __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) {	\
419 		*(__ksymtab_strings)					\
420 	}								\
421 									\
422 	/* __*init sections */						\
423 	__init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) {		\
424 		*(.ref.rodata)						\
425 		MEM_KEEP(init.rodata)					\
426 		MEM_KEEP(exit.rodata)					\
427 	}								\
428 									\
429 	/* Built-in module parameters. */				\
430 	__param : AT(ADDR(__param) - LOAD_OFFSET) {			\
431 		VMLINUX_SYMBOL(__start___param) = .;			\
432 		KEEP(*(__param))					\
433 		VMLINUX_SYMBOL(__stop___param) = .;			\
434 	}								\
435 									\
436 	/* Built-in module versions. */					\
437 	__modver : AT(ADDR(__modver) - LOAD_OFFSET) {			\
438 		VMLINUX_SYMBOL(__start___modver) = .;			\
439 		KEEP(*(__modver))					\
440 		VMLINUX_SYMBOL(__stop___modver) = .;			\
441 		. = ALIGN((align));					\
442 		VMLINUX_SYMBOL(__end_rodata) = .;			\
443 	}								\
444 	. = ALIGN((align));
445 
446 /* RODATA & RO_DATA provided for backward compatibility.
447  * All archs are supposed to use RO_DATA() */
448 #define RODATA          RO_DATA_SECTION(4096)
449 #define RO_DATA(align)  RO_DATA_SECTION(align)
450 
451 #define SECURITY_INIT							\
452 	.security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \
453 		VMLINUX_SYMBOL(__security_initcall_start) = .;		\
454 		KEEP(*(.security_initcall.init))			\
455 		VMLINUX_SYMBOL(__security_initcall_end) = .;		\
456 	}
457 
458 /*
459  * .text section. Map to function alignment to avoid address changes
460  * during second ld run in second ld pass when generating System.map
461  *
462  * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead
463  * code elimination is enabled, so these sections should be converted
464  * to use ".." first.
465  */
466 #define TEXT_TEXT							\
467 		ALIGN_FUNCTION();					\
468 		*(.text.hot TEXT_MAIN .text.fixup .text.unlikely)	\
469 		*(.text..refcount)					\
470 		*(.ref.text)						\
471 	MEM_KEEP(init.text)						\
472 	MEM_KEEP(exit.text)						\
473 
474 
475 /* sched.text is aling to function alignment to secure we have same
476  * address even at second ld pass when generating System.map */
477 #define SCHED_TEXT							\
478 		ALIGN_FUNCTION();					\
479 		VMLINUX_SYMBOL(__sched_text_start) = .;			\
480 		*(.sched.text)						\
481 		VMLINUX_SYMBOL(__sched_text_end) = .;
482 
483 /* spinlock.text is aling to function alignment to secure we have same
484  * address even at second ld pass when generating System.map */
485 #define LOCK_TEXT							\
486 		ALIGN_FUNCTION();					\
487 		VMLINUX_SYMBOL(__lock_text_start) = .;			\
488 		*(.spinlock.text)					\
489 		VMLINUX_SYMBOL(__lock_text_end) = .;
490 
491 #define CPUIDLE_TEXT							\
492 		ALIGN_FUNCTION();					\
493 		VMLINUX_SYMBOL(__cpuidle_text_start) = .;		\
494 		*(.cpuidle.text)					\
495 		VMLINUX_SYMBOL(__cpuidle_text_end) = .;
496 
497 #define KPROBES_TEXT							\
498 		ALIGN_FUNCTION();					\
499 		VMLINUX_SYMBOL(__kprobes_text_start) = .;		\
500 		*(.kprobes.text)					\
501 		VMLINUX_SYMBOL(__kprobes_text_end) = .;
502 
503 #define ENTRY_TEXT							\
504 		ALIGN_FUNCTION();					\
505 		VMLINUX_SYMBOL(__entry_text_start) = .;			\
506 		*(.entry.text)						\
507 		VMLINUX_SYMBOL(__entry_text_end) = .;
508 
509 #define IRQENTRY_TEXT							\
510 		ALIGN_FUNCTION();					\
511 		VMLINUX_SYMBOL(__irqentry_text_start) = .;		\
512 		*(.irqentry.text)					\
513 		VMLINUX_SYMBOL(__irqentry_text_end) = .;
514 
515 #define SOFTIRQENTRY_TEXT						\
516 		ALIGN_FUNCTION();					\
517 		VMLINUX_SYMBOL(__softirqentry_text_start) = .;		\
518 		*(.softirqentry.text)					\
519 		VMLINUX_SYMBOL(__softirqentry_text_end) = .;
520 
521 /* Section used for early init (in .S files) */
522 #define HEAD_TEXT  *(.head.text)
523 
524 #define HEAD_TEXT_SECTION							\
525 	.head.text : AT(ADDR(.head.text) - LOAD_OFFSET) {		\
526 		HEAD_TEXT						\
527 	}
528 
529 /*
530  * Exception table
531  */
532 #define EXCEPTION_TABLE(align)						\
533 	. = ALIGN(align);						\
534 	__ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {		\
535 		VMLINUX_SYMBOL(__start___ex_table) = .;			\
536 		KEEP(*(__ex_table))					\
537 		VMLINUX_SYMBOL(__stop___ex_table) = .;			\
538 	}
539 
540 /*
541  * Init task
542  */
543 #define INIT_TASK_DATA_SECTION(align)					\
544 	. = ALIGN(align);						\
545 	.data..init_task :  AT(ADDR(.data..init_task) - LOAD_OFFSET) {	\
546 		INIT_TASK_DATA(align)					\
547 	}
548 
549 #ifdef CONFIG_CONSTRUCTORS
550 #define KERNEL_CTORS()	. = ALIGN(8);			   \
551 			VMLINUX_SYMBOL(__ctors_start) = .; \
552 			KEEP(*(.ctors))			   \
553 			KEEP(*(SORT(.init_array.*)))	   \
554 			KEEP(*(.init_array))		   \
555 			VMLINUX_SYMBOL(__ctors_end) = .;
556 #else
557 #define KERNEL_CTORS()
558 #endif
559 
560 /* init and exit section handling */
561 #define INIT_DATA							\
562 	KEEP(*(SORT(___kentry+*)))					\
563 	*(.init.data)							\
564 	MEM_DISCARD(init.data)						\
565 	KERNEL_CTORS()							\
566 	MCOUNT_REC()							\
567 	*(.init.rodata)							\
568 	FTRACE_EVENTS()							\
569 	TRACE_SYSCALLS()						\
570 	KPROBE_BLACKLIST()						\
571 	MEM_DISCARD(init.rodata)					\
572 	CLK_OF_TABLES()							\
573 	RESERVEDMEM_OF_TABLES()						\
574 	TIMER_OF_TABLES()						\
575 	IOMMU_OF_TABLES()						\
576 	CPU_METHOD_OF_TABLES()						\
577 	CPUIDLE_METHOD_OF_TABLES()					\
578 	KERNEL_DTB()							\
579 	IRQCHIP_OF_MATCH_TABLE()					\
580 	ACPI_PROBE_TABLE(irqchip)					\
581 	ACPI_PROBE_TABLE(timer)						\
582 	ACPI_PROBE_TABLE(iort)						\
583 	EARLYCON_TABLE()
584 
585 #define INIT_TEXT							\
586 	*(.init.text)							\
587 	*(.text.startup)						\
588 	MEM_DISCARD(init.text)
589 
590 #define EXIT_DATA							\
591 	*(.exit.data)							\
592 	*(.fini_array)							\
593 	*(.dtors)							\
594 	MEM_DISCARD(exit.data)						\
595 	MEM_DISCARD(exit.rodata)
596 
597 #define EXIT_TEXT							\
598 	*(.exit.text)							\
599 	*(.text.exit)							\
600 	MEM_DISCARD(exit.text)
601 
602 #define EXIT_CALL							\
603 	*(.exitcall.exit)
604 
605 /*
606  * bss (Block Started by Symbol) - uninitialized data
607  * zeroed during startup
608  */
609 #define SBSS(sbss_align)						\
610 	. = ALIGN(sbss_align);						\
611 	.sbss : AT(ADDR(.sbss) - LOAD_OFFSET) {				\
612 		*(.dynsbss)						\
613 		*(.sbss)						\
614 		*(.scommon)						\
615 	}
616 
617 /*
618  * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
619  * sections to the front of bss.
620  */
621 #ifndef BSS_FIRST_SECTIONS
622 #define BSS_FIRST_SECTIONS
623 #endif
624 
625 #define BSS(bss_align)							\
626 	. = ALIGN(bss_align);						\
627 	.bss : AT(ADDR(.bss) - LOAD_OFFSET) {				\
628 		BSS_FIRST_SECTIONS					\
629 		*(.bss..page_aligned)					\
630 		*(.dynbss)						\
631 		*(BSS_MAIN)						\
632 		*(COMMON)						\
633 	}
634 
635 /*
636  * DWARF debug sections.
637  * Symbols in the DWARF debugging sections are relative to
638  * the beginning of the section so we begin them at 0.
639  */
640 #define DWARF_DEBUG							\
641 		/* DWARF 1 */						\
642 		.debug          0 : { *(.debug) }			\
643 		.line           0 : { *(.line) }			\
644 		/* GNU DWARF 1 extensions */				\
645 		.debug_srcinfo  0 : { *(.debug_srcinfo) }		\
646 		.debug_sfnames  0 : { *(.debug_sfnames) }		\
647 		/* DWARF 1.1 and DWARF 2 */				\
648 		.debug_aranges  0 : { *(.debug_aranges) }		\
649 		.debug_pubnames 0 : { *(.debug_pubnames) }		\
650 		/* DWARF 2 */						\
651 		.debug_info     0 : { *(.debug_info			\
652 				.gnu.linkonce.wi.*) }			\
653 		.debug_abbrev   0 : { *(.debug_abbrev) }		\
654 		.debug_line     0 : { *(.debug_line) }			\
655 		.debug_frame    0 : { *(.debug_frame) }			\
656 		.debug_str      0 : { *(.debug_str) }			\
657 		.debug_loc      0 : { *(.debug_loc) }			\
658 		.debug_macinfo  0 : { *(.debug_macinfo) }		\
659 		.debug_pubtypes 0 : { *(.debug_pubtypes) }		\
660 		/* DWARF 3 */						\
661 		.debug_ranges	0 : { *(.debug_ranges) }		\
662 		/* SGI/MIPS DWARF 2 extensions */			\
663 		.debug_weaknames 0 : { *(.debug_weaknames) }		\
664 		.debug_funcnames 0 : { *(.debug_funcnames) }		\
665 		.debug_typenames 0 : { *(.debug_typenames) }		\
666 		.debug_varnames  0 : { *(.debug_varnames) }		\
667 		/* GNU DWARF 2 extensions */				\
668 		.debug_gnu_pubnames 0 : { *(.debug_gnu_pubnames) }	\
669 		.debug_gnu_pubtypes 0 : { *(.debug_gnu_pubtypes) }	\
670 		/* DWARF 4 */						\
671 		.debug_types	0 : { *(.debug_types) }			\
672 		/* DWARF 5 */						\
673 		.debug_macro	0 : { *(.debug_macro) }			\
674 		.debug_addr	0 : { *(.debug_addr) }
675 
676 		/* Stabs debugging sections.  */
677 #define STABS_DEBUG							\
678 		.stab 0 : { *(.stab) }					\
679 		.stabstr 0 : { *(.stabstr) }				\
680 		.stab.excl 0 : { *(.stab.excl) }			\
681 		.stab.exclstr 0 : { *(.stab.exclstr) }			\
682 		.stab.index 0 : { *(.stab.index) }			\
683 		.stab.indexstr 0 : { *(.stab.indexstr) }		\
684 		.comment 0 : { *(.comment) }
685 
686 #ifdef CONFIG_GENERIC_BUG
687 #define BUG_TABLE							\
688 	. = ALIGN(8);							\
689 	__bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) {		\
690 		VMLINUX_SYMBOL(__start___bug_table) = .;		\
691 		KEEP(*(__bug_table))					\
692 		VMLINUX_SYMBOL(__stop___bug_table) = .;			\
693 	}
694 #else
695 #define BUG_TABLE
696 #endif
697 
698 #ifdef CONFIG_UNWINDER_ORC
699 #define ORC_UNWIND_TABLE						\
700 	. = ALIGN(4);							\
701 	.orc_unwind_ip : AT(ADDR(.orc_unwind_ip) - LOAD_OFFSET) {	\
702 		VMLINUX_SYMBOL(__start_orc_unwind_ip) = .;		\
703 		KEEP(*(.orc_unwind_ip))					\
704 		VMLINUX_SYMBOL(__stop_orc_unwind_ip) = .;		\
705 	}								\
706 	. = ALIGN(6);							\
707 	.orc_unwind : AT(ADDR(.orc_unwind) - LOAD_OFFSET) {		\
708 		VMLINUX_SYMBOL(__start_orc_unwind) = .;			\
709 		KEEP(*(.orc_unwind))					\
710 		VMLINUX_SYMBOL(__stop_orc_unwind) = .;			\
711 	}								\
712 	. = ALIGN(4);							\
713 	.orc_lookup : AT(ADDR(.orc_lookup) - LOAD_OFFSET) {		\
714 		VMLINUX_SYMBOL(orc_lookup) = .;				\
715 		. += (((SIZEOF(.text) + LOOKUP_BLOCK_SIZE - 1) /	\
716 			LOOKUP_BLOCK_SIZE) + 1) * 4;			\
717 		VMLINUX_SYMBOL(orc_lookup_end) = .;			\
718 	}
719 #else
720 #define ORC_UNWIND_TABLE
721 #endif
722 
723 #ifdef CONFIG_PM_TRACE
724 #define TRACEDATA							\
725 	. = ALIGN(4);							\
726 	.tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) {		\
727 		VMLINUX_SYMBOL(__tracedata_start) = .;			\
728 		KEEP(*(.tracedata))					\
729 		VMLINUX_SYMBOL(__tracedata_end) = .;			\
730 	}
731 #else
732 #define TRACEDATA
733 #endif
734 
735 #define NOTES								\
736 	.notes : AT(ADDR(.notes) - LOAD_OFFSET) {			\
737 		VMLINUX_SYMBOL(__start_notes) = .;			\
738 		*(.note.*)						\
739 		VMLINUX_SYMBOL(__stop_notes) = .;			\
740 	}
741 
742 #define INIT_SETUP(initsetup_align)					\
743 		. = ALIGN(initsetup_align);				\
744 		VMLINUX_SYMBOL(__setup_start) = .;			\
745 		KEEP(*(.init.setup))					\
746 		VMLINUX_SYMBOL(__setup_end) = .;
747 
748 #define INIT_CALLS_LEVEL(level)						\
749 		VMLINUX_SYMBOL(__initcall##level##_start) = .;		\
750 		KEEP(*(.initcall##level##.init))			\
751 		KEEP(*(.initcall##level##s.init))			\
752 
753 #define INIT_CALLS							\
754 		VMLINUX_SYMBOL(__initcall_start) = .;			\
755 		KEEP(*(.initcallearly.init))				\
756 		INIT_CALLS_LEVEL(0)					\
757 		INIT_CALLS_LEVEL(1)					\
758 		INIT_CALLS_LEVEL(2)					\
759 		INIT_CALLS_LEVEL(3)					\
760 		INIT_CALLS_LEVEL(4)					\
761 		INIT_CALLS_LEVEL(5)					\
762 		INIT_CALLS_LEVEL(rootfs)				\
763 		INIT_CALLS_LEVEL(6)					\
764 		INIT_CALLS_LEVEL(7)					\
765 		VMLINUX_SYMBOL(__initcall_end) = .;
766 
767 #define CON_INITCALL							\
768 		VMLINUX_SYMBOL(__con_initcall_start) = .;		\
769 		KEEP(*(.con_initcall.init))				\
770 		VMLINUX_SYMBOL(__con_initcall_end) = .;
771 
772 #define SECURITY_INITCALL						\
773 		VMLINUX_SYMBOL(__security_initcall_start) = .;		\
774 		KEEP(*(.security_initcall.init))			\
775 		VMLINUX_SYMBOL(__security_initcall_end) = .;
776 
777 #ifdef CONFIG_BLK_DEV_INITRD
778 #define INIT_RAM_FS							\
779 	. = ALIGN(4);							\
780 	VMLINUX_SYMBOL(__initramfs_start) = .;				\
781 	KEEP(*(.init.ramfs))						\
782 	. = ALIGN(8);							\
783 	KEEP(*(.init.ramfs.info))
784 #else
785 #define INIT_RAM_FS
786 #endif
787 
788 /*
789  * Memory encryption operates on a page basis. Since we need to clear
790  * the memory encryption mask for this section, it needs to be aligned
791  * on a page boundary and be a page-size multiple in length.
792  *
793  * Note: We use a separate section so that only this section gets
794  * decrypted to avoid exposing more than we wish.
795  */
796 #ifdef CONFIG_AMD_MEM_ENCRYPT
797 #define PERCPU_DECRYPTED_SECTION					\
798 	. = ALIGN(PAGE_SIZE);						\
799 	*(.data..percpu..decrypted)					\
800 	. = ALIGN(PAGE_SIZE);
801 #else
802 #define PERCPU_DECRYPTED_SECTION
803 #endif
804 
805 
806 /*
807  * Default discarded sections.
808  *
809  * Some archs want to discard exit text/data at runtime rather than
810  * link time due to cross-section references such as alt instructions,
811  * bug table, eh_frame, etc.  DISCARDS must be the last of output
812  * section definitions so that such archs put those in earlier section
813  * definitions.
814  */
815 #define DISCARDS							\
816 	/DISCARD/ : {							\
817 	EXIT_TEXT							\
818 	EXIT_DATA							\
819 	EXIT_CALL							\
820 	*(.discard)							\
821 	*(.discard.*)							\
822 	}
823 
824 /**
825  * PERCPU_INPUT - the percpu input sections
826  * @cacheline: cacheline size
827  *
828  * The core percpu section names and core symbols which do not rely
829  * directly upon load addresses.
830  *
831  * @cacheline is used to align subsections to avoid false cacheline
832  * sharing between subsections for different purposes.
833  */
834 #define PERCPU_INPUT(cacheline)						\
835 	VMLINUX_SYMBOL(__per_cpu_start) = .;				\
836 	*(.data..percpu..first)						\
837 	. = ALIGN(PAGE_SIZE);						\
838 	*(.data..percpu..page_aligned)					\
839 	. = ALIGN(cacheline);						\
840 	*(.data..percpu..read_mostly)					\
841 	. = ALIGN(cacheline);						\
842 	*(.data..percpu)						\
843 	*(.data..percpu..shared_aligned)				\
844 	PERCPU_DECRYPTED_SECTION					\
845 	VMLINUX_SYMBOL(__per_cpu_end) = .;
846 
847 /**
848  * PERCPU_VADDR - define output section for percpu area
849  * @cacheline: cacheline size
850  * @vaddr: explicit base address (optional)
851  * @phdr: destination PHDR (optional)
852  *
853  * Macro which expands to output section for percpu area.
854  *
855  * @cacheline is used to align subsections to avoid false cacheline
856  * sharing between subsections for different purposes.
857  *
858  * If @vaddr is not blank, it specifies explicit base address and all
859  * percpu symbols will be offset from the given address.  If blank,
860  * @vaddr always equals @laddr + LOAD_OFFSET.
861  *
862  * @phdr defines the output PHDR to use if not blank.  Be warned that
863  * output PHDR is sticky.  If @phdr is specified, the next output
864  * section in the linker script will go there too.  @phdr should have
865  * a leading colon.
866  *
867  * Note that this macros defines __per_cpu_load as an absolute symbol.
868  * If there is no need to put the percpu section at a predetermined
869  * address, use PERCPU_SECTION.
870  */
871 #define PERCPU_VADDR(cacheline, vaddr, phdr)				\
872 	VMLINUX_SYMBOL(__per_cpu_load) = .;				\
873 	.data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load)		\
874 				- LOAD_OFFSET) {			\
875 		PERCPU_INPUT(cacheline)					\
876 	} phdr								\
877 	. = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
878 
879 /**
880  * PERCPU_SECTION - define output section for percpu area, simple version
881  * @cacheline: cacheline size
882  *
883  * Align to PAGE_SIZE and outputs output section for percpu area.  This
884  * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and
885  * __per_cpu_start will be identical.
886  *
887  * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,)
888  * except that __per_cpu_load is defined as a relative symbol against
889  * .data..percpu which is required for relocatable x86_32 configuration.
890  */
891 #define PERCPU_SECTION(cacheline)					\
892 	. = ALIGN(PAGE_SIZE);						\
893 	.data..percpu	: AT(ADDR(.data..percpu) - LOAD_OFFSET) {	\
894 		VMLINUX_SYMBOL(__per_cpu_load) = .;			\
895 		PERCPU_INPUT(cacheline)					\
896 	}
897 
898 
899 /*
900  * Definition of the high level *_SECTION macros
901  * They will fit only a subset of the architectures
902  */
903 
904 
905 /*
906  * Writeable data.
907  * All sections are combined in a single .data section.
908  * The sections following CONSTRUCTORS are arranged so their
909  * typical alignment matches.
910  * A cacheline is typical/always less than a PAGE_SIZE so
911  * the sections that has this restriction (or similar)
912  * is located before the ones requiring PAGE_SIZE alignment.
913  * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which
914  * matches the requirement of PAGE_ALIGNED_DATA.
915  *
916  * use 0 as page_align if page_aligned data is not used */
917 #define RW_DATA_SECTION(cacheline, pagealigned, inittask)		\
918 	. = ALIGN(PAGE_SIZE);						\
919 	.data : AT(ADDR(.data) - LOAD_OFFSET) {				\
920 		INIT_TASK_DATA(inittask)				\
921 		NOSAVE_DATA						\
922 		PAGE_ALIGNED_DATA(pagealigned)				\
923 		CACHELINE_ALIGNED_DATA(cacheline)			\
924 		READ_MOSTLY_DATA(cacheline)				\
925 		DATA_DATA						\
926 		CONSTRUCTORS						\
927 	}								\
928 	BUG_TABLE							\
929 
930 #define INIT_TEXT_SECTION(inittext_align)				\
931 	. = ALIGN(inittext_align);					\
932 	.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {		\
933 		VMLINUX_SYMBOL(_sinittext) = .;				\
934 		INIT_TEXT						\
935 		VMLINUX_SYMBOL(_einittext) = .;				\
936 	}
937 
938 #define INIT_DATA_SECTION(initsetup_align)				\
939 	.init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {		\
940 		INIT_DATA						\
941 		INIT_SETUP(initsetup_align)				\
942 		INIT_CALLS						\
943 		CON_INITCALL						\
944 		SECURITY_INITCALL					\
945 		INIT_RAM_FS						\
946 	}
947 
948 #define BSS_SECTION(sbss_align, bss_align, stop_align)			\
949 	. = ALIGN(sbss_align);						\
950 	VMLINUX_SYMBOL(__bss_start) = .;				\
951 	SBSS(sbss_align)						\
952 	BSS(bss_align)							\
953 	. = ALIGN(stop_align);						\
954 	VMLINUX_SYMBOL(__bss_stop) = .;
955