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