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