GNU Linux-libre 4.9.337-gnu1
[releases.git] / include / asm-generic / vmlinux.lds.h
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                                 *(_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                         *(_ftrace_events)                               \
143                         VMLINUX_SYMBOL(__stop_ftrace_events) = .;       \
144                         VMLINUX_SYMBOL(__start_ftrace_enum_maps) = .;   \
145                         *(_ftrace_enum_map)                             \
146                         VMLINUX_SYMBOL(__stop_ftrace_enum_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                          *(__trace_printk_fmt) /* Trace_printk fmt' pointer */ \
154                          VMLINUX_SYMBOL(__stop___trace_bprintk_fmt) = .;
155 #define TRACEPOINT_STR() VMLINUX_SYMBOL(__start___tracepoint_str) = .;  \
156                          *(__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                          *(__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() . = ALIGN(8);                          \
174                          VMLINUX_SYMBOL(__earlycon_table) = .;  \
175                          *(__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         *(__##name##_of_table)                                          \
189         *(__##name##_of_table_end)
190
191 #define CLKSRC_OF_TABLES()      OF_TABLE(CONFIG_CLKSRC_OF, clksrc)
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         *(__##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         *(.dtb.init.rodata)                                             \
213         VMLINUX_SYMBOL(__dtb_end) = .;
214
215 /*
216  * .data section
217  */
218 #define DATA_DATA                                                       \
219         *(DATA_MAIN)                                                    \
220         *(.ref.data)                                                    \
221         *(.data..shared_aligned) /* percpu related */                   \
222         MEM_KEEP(init.data)                                             \
223         MEM_KEEP(exit.data)                                             \
224         *(.data.unlikely)                                               \
225         STRUCT_ALIGN();                                                 \
226         *(__tracepoints)                                                \
227         /* implement dynamic printk debug */                            \
228         . = ALIGN(8);                                                   \
229         VMLINUX_SYMBOL(__start___jump_table) = .;                       \
230         *(__jump_table)                                                 \
231         VMLINUX_SYMBOL(__stop___jump_table) = .;                        \
232         . = ALIGN(8);                                                   \
233         VMLINUX_SYMBOL(__start___verbose) = .;                          \
234         *(__verbose)                                                    \
235         VMLINUX_SYMBOL(__stop___verbose) = .;                           \
236         LIKELY_PROFILE()                                                \
237         BRANCH_PROFILE()                                                \
238         TRACE_PRINTKS()                                                 \
239         TRACEPOINT_STR()
240
241 /*
242  * Data section helpers
243  */
244 #define NOSAVE_DATA                                                     \
245         . = ALIGN(PAGE_SIZE);                                           \
246         VMLINUX_SYMBOL(__nosave_begin) = .;                             \
247         *(.data..nosave)                                                \
248         . = ALIGN(PAGE_SIZE);                                           \
249         VMLINUX_SYMBOL(__nosave_end) = .;
250
251 #define PAGE_ALIGNED_DATA(page_align)                                   \
252         . = ALIGN(page_align);                                          \
253         *(.data..page_aligned)                                          \
254         . = ALIGN(page_align);
255
256 #define READ_MOSTLY_DATA(align)                                         \
257         . = ALIGN(align);                                               \
258         *(.data..read_mostly)                                           \
259         . = ALIGN(align);
260
261 #define CACHELINE_ALIGNED_DATA(align)                                   \
262         . = ALIGN(align);                                               \
263         *(.data..cacheline_aligned)
264
265 #define INIT_TASK_DATA(align)                                           \
266         . = ALIGN(align);                                               \
267         VMLINUX_SYMBOL(__start_init_task) = .;                          \
268         *(.data..init_task)                                             \
269         VMLINUX_SYMBOL(__end_init_task) = .;
270
271 /*
272  * Allow architectures to handle ro_after_init data on their
273  * own by defining an empty RO_AFTER_INIT_DATA.
274  */
275 #ifndef RO_AFTER_INIT_DATA
276 #define RO_AFTER_INIT_DATA                                              \
277         __start_data_ro_after_init = .;                                 \
278         *(.data..ro_after_init)                                         \
279         __end_data_ro_after_init = .;
280 #endif
281
282 /*
283  * Read only Data
284  */
285 #define RO_DATA_SECTION(align)                                          \
286         . = ALIGN((align));                                             \
287         .rodata           : AT(ADDR(.rodata) - LOAD_OFFSET) {           \
288                 VMLINUX_SYMBOL(__start_rodata) = .;                     \
289                 *(.rodata) *(.rodata.*)                                 \
290                 RO_AFTER_INIT_DATA      /* Read only after init */      \
291                 *(__vermagic)           /* Kernel version magic */      \
292                 . = ALIGN(8);                                           \
293                 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .;         \
294                 *(__tracepoints_ptrs)   /* Tracepoints: pointer array */\
295                 VMLINUX_SYMBOL(__stop___tracepoints_ptrs) = .;          \
296                 *(__tracepoints_strings)/* Tracepoints: strings */      \
297         }                                                               \
298                                                                         \
299         .rodata1          : AT(ADDR(.rodata1) - LOAD_OFFSET) {          \
300                 *(.rodata1)                                             \
301         }                                                               \
302                                                                         \
303         BUG_TABLE                                                       \
304                                                                         \
305         /* PCI quirks */                                                \
306         .pci_fixup        : AT(ADDR(.pci_fixup) - LOAD_OFFSET) {        \
307                 VMLINUX_SYMBOL(__start_pci_fixups_early) = .;           \
308                 *(.pci_fixup_early)                                     \
309                 VMLINUX_SYMBOL(__end_pci_fixups_early) = .;             \
310                 VMLINUX_SYMBOL(__start_pci_fixups_header) = .;          \
311                 *(.pci_fixup_header)                                    \
312                 VMLINUX_SYMBOL(__end_pci_fixups_header) = .;            \
313                 VMLINUX_SYMBOL(__start_pci_fixups_final) = .;           \
314                 *(.pci_fixup_final)                                     \
315                 VMLINUX_SYMBOL(__end_pci_fixups_final) = .;             \
316                 VMLINUX_SYMBOL(__start_pci_fixups_enable) = .;          \
317                 *(.pci_fixup_enable)                                    \
318                 VMLINUX_SYMBOL(__end_pci_fixups_enable) = .;            \
319                 VMLINUX_SYMBOL(__start_pci_fixups_resume) = .;          \
320                 *(.pci_fixup_resume)                                    \
321                 VMLINUX_SYMBOL(__end_pci_fixups_resume) = .;            \
322                 VMLINUX_SYMBOL(__start_pci_fixups_resume_early) = .;    \
323                 *(.pci_fixup_resume_early)                              \
324                 VMLINUX_SYMBOL(__end_pci_fixups_resume_early) = .;      \
325                 VMLINUX_SYMBOL(__start_pci_fixups_suspend) = .;         \
326                 *(.pci_fixup_suspend)                                   \
327                 VMLINUX_SYMBOL(__end_pci_fixups_suspend) = .;           \
328                 VMLINUX_SYMBOL(__start_pci_fixups_suspend_late) = .;    \
329                 *(.pci_fixup_suspend_late)                              \
330                 VMLINUX_SYMBOL(__end_pci_fixups_suspend_late) = .;      \
331         }                                                               \
332                                                                         \
333         /* Built-in firmware blobs */                                   \
334         .builtin_fw        : AT(ADDR(.builtin_fw) - LOAD_OFFSET) {      \
335                 VMLINUX_SYMBOL(__start_builtin_fw) = .;                 \
336                 *(.builtin_fw)                                          \
337                 VMLINUX_SYMBOL(__end_builtin_fw) = .;                   \
338         }                                                               \
339                                                                         \
340         TRACEDATA                                                       \
341                                                                         \
342         /* Kernel symbol table: Normal symbols */                       \
343         __ksymtab         : AT(ADDR(__ksymtab) - LOAD_OFFSET) {         \
344                 VMLINUX_SYMBOL(__start___ksymtab) = .;                  \
345                 KEEP(*(SORT(___ksymtab+*)))                             \
346                 VMLINUX_SYMBOL(__stop___ksymtab) = .;                   \
347         }                                                               \
348                                                                         \
349         /* Kernel symbol table: GPL-only symbols */                     \
350         __ksymtab_gpl     : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) {     \
351                 VMLINUX_SYMBOL(__start___ksymtab_gpl) = .;              \
352                 KEEP(*(SORT(___ksymtab_gpl+*)))                         \
353                 VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .;               \
354         }                                                               \
355                                                                         \
356         /* Kernel symbol table: Normal unused symbols */                \
357         __ksymtab_unused  : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) {  \
358                 VMLINUX_SYMBOL(__start___ksymtab_unused) = .;           \
359                 KEEP(*(SORT(___ksymtab_unused+*)))                      \
360                 VMLINUX_SYMBOL(__stop___ksymtab_unused) = .;            \
361         }                                                               \
362                                                                         \
363         /* Kernel symbol table: GPL-only unused symbols */              \
364         __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \
365                 VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .;       \
366                 KEEP(*(SORT(___ksymtab_unused_gpl+*)))                  \
367                 VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .;        \
368         }                                                               \
369                                                                         \
370         /* Kernel symbol table: GPL-future-only symbols */              \
371         __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
372                 VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .;       \
373                 KEEP(*(SORT(___ksymtab_gpl_future+*)))                  \
374                 VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .;        \
375         }                                                               \
376                                                                         \
377         /* Kernel symbol table: Normal symbols */                       \
378         __kcrctab         : AT(ADDR(__kcrctab) - LOAD_OFFSET) {         \
379                 VMLINUX_SYMBOL(__start___kcrctab) = .;                  \
380                 KEEP(*(SORT(___kcrctab+*)))                             \
381                 VMLINUX_SYMBOL(__stop___kcrctab) = .;                   \
382         }                                                               \
383                                                                         \
384         /* Kernel symbol table: GPL-only symbols */                     \
385         __kcrctab_gpl     : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) {     \
386                 VMLINUX_SYMBOL(__start___kcrctab_gpl) = .;              \
387                 KEEP(*(SORT(___kcrctab_gpl+*)))                         \
388                 VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .;               \
389         }                                                               \
390                                                                         \
391         /* Kernel symbol table: Normal unused symbols */                \
392         __kcrctab_unused  : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) {  \
393                 VMLINUX_SYMBOL(__start___kcrctab_unused) = .;           \
394                 KEEP(*(SORT(___kcrctab_unused+*)))                      \
395                 VMLINUX_SYMBOL(__stop___kcrctab_unused) = .;            \
396         }                                                               \
397                                                                         \
398         /* Kernel symbol table: GPL-only unused symbols */              \
399         __kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \
400                 VMLINUX_SYMBOL(__start___kcrctab_unused_gpl) = .;       \
401                 KEEP(*(SORT(___kcrctab_unused_gpl+*)))                  \
402                 VMLINUX_SYMBOL(__stop___kcrctab_unused_gpl) = .;        \
403         }                                                               \
404                                                                         \
405         /* Kernel symbol table: GPL-future-only symbols */              \
406         __kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \
407                 VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .;       \
408                 KEEP(*(SORT(___kcrctab_gpl_future+*)))                  \
409                 VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .;        \
410         }                                                               \
411                                                                         \
412         /* Kernel symbol table: strings */                              \
413         __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \
414                 KEEP(*(__ksymtab_strings))                              \
415         }                                                               \
416                                                                         \
417         /* __*init sections */                                          \
418         __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) {         \
419                 *(.ref.rodata)                                          \
420                 MEM_KEEP(init.rodata)                                   \
421                 MEM_KEEP(exit.rodata)                                   \
422         }                                                               \
423                                                                         \
424         /* Built-in module parameters. */                               \
425         __param : AT(ADDR(__param) - LOAD_OFFSET) {                     \
426                 VMLINUX_SYMBOL(__start___param) = .;                    \
427                 *(__param)                                              \
428                 VMLINUX_SYMBOL(__stop___param) = .;                     \
429         }                                                               \
430                                                                         \
431         /* Built-in module versions. */                                 \
432         __modver : AT(ADDR(__modver) - LOAD_OFFSET) {                   \
433                 VMLINUX_SYMBOL(__start___modver) = .;                   \
434                 *(__modver)                                             \
435                 VMLINUX_SYMBOL(__stop___modver) = .;                    \
436                 . = ALIGN((align));                                     \
437                 VMLINUX_SYMBOL(__end_rodata) = .;                       \
438         }                                                               \
439         . = ALIGN((align));
440
441 /* RODATA & RO_DATA provided for backward compatibility.
442  * All archs are supposed to use RO_DATA() */
443 #define RODATA          RO_DATA_SECTION(4096)
444 #define RO_DATA(align)  RO_DATA_SECTION(align)
445
446 #define SECURITY_INIT                                                   \
447         .security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \
448                 VMLINUX_SYMBOL(__security_initcall_start) = .;          \
449                 KEEP(*(.security_initcall.init))                        \
450                 VMLINUX_SYMBOL(__security_initcall_end) = .;            \
451         }
452
453 /*
454  * .text section. Map to function alignment to avoid address changes
455  * during second ld run in second ld pass when generating System.map
456  *
457  * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead
458  * code elimination is enabled, so these sections should be converted
459  * to use ".." first.
460  */
461 #define TEXT_TEXT                                                       \
462                 ALIGN_FUNCTION();                                       \
463                 *(.text.hot .text.hot.*)                                \
464                 *(TEXT_MAIN .text.fixup)                                \
465                 *(.text.unlikely .text.unlikely.*)                      \
466                 *(.text.unknown .text.unknown.*)                        \
467                 *(.ref.text)                                            \
468                 *(.text.asan.* .text.tsan.*)                            \
469         MEM_KEEP(init.text)                                             \
470         MEM_KEEP(exit.text)                                             \
471
472
473 /* sched.text is aling to function alignment to secure we have same
474  * address even at second ld pass when generating System.map */
475 #define SCHED_TEXT                                                      \
476                 ALIGN_FUNCTION();                                       \
477                 VMLINUX_SYMBOL(__sched_text_start) = .;                 \
478                 *(.sched.text)                                          \
479                 VMLINUX_SYMBOL(__sched_text_end) = .;
480
481 /* spinlock.text is aling to function alignment to secure we have same
482  * address even at second ld pass when generating System.map */
483 #define LOCK_TEXT                                                       \
484                 ALIGN_FUNCTION();                                       \
485                 VMLINUX_SYMBOL(__lock_text_start) = .;                  \
486                 *(.spinlock.text)                                       \
487                 VMLINUX_SYMBOL(__lock_text_end) = .;
488
489 #define CPUIDLE_TEXT                                                    \
490                 ALIGN_FUNCTION();                                       \
491                 VMLINUX_SYMBOL(__cpuidle_text_start) = .;               \
492                 *(.cpuidle.text)                                        \
493                 VMLINUX_SYMBOL(__cpuidle_text_end) = .;
494
495 #define KPROBES_TEXT                                                    \
496                 ALIGN_FUNCTION();                                       \
497                 VMLINUX_SYMBOL(__kprobes_text_start) = .;               \
498                 *(.kprobes.text)                                        \
499                 VMLINUX_SYMBOL(__kprobes_text_end) = .;
500
501 #define ENTRY_TEXT                                                      \
502                 ALIGN_FUNCTION();                                       \
503                 VMLINUX_SYMBOL(__entry_text_start) = .;                 \
504                 *(.entry.text)                                          \
505                 VMLINUX_SYMBOL(__entry_text_end) = .;
506
507 #if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
508 #define IRQENTRY_TEXT                                                   \
509                 ALIGN_FUNCTION();                                       \
510                 VMLINUX_SYMBOL(__irqentry_text_start) = .;              \
511                 *(.irqentry.text)                                       \
512                 VMLINUX_SYMBOL(__irqentry_text_end) = .;
513 #else
514 #define IRQENTRY_TEXT
515 #endif
516
517 #if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
518 #define SOFTIRQENTRY_TEXT                                               \
519                 ALIGN_FUNCTION();                                       \
520                 VMLINUX_SYMBOL(__softirqentry_text_start) = .;          \
521                 *(.softirqentry.text)                                   \
522                 VMLINUX_SYMBOL(__softirqentry_text_end) = .;
523 #else
524 #define SOFTIRQENTRY_TEXT
525 #endif
526
527 /* Section used for early init (in .S files) */
528 #define HEAD_TEXT  *(.head.text)
529
530 #define HEAD_TEXT_SECTION                                                       \
531         .head.text : AT(ADDR(.head.text) - LOAD_OFFSET) {               \
532                 HEAD_TEXT                                               \
533         }
534
535 /*
536  * Exception table
537  */
538 #define EXCEPTION_TABLE(align)                                          \
539         . = ALIGN(align);                                               \
540         __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {               \
541                 VMLINUX_SYMBOL(__start___ex_table) = .;                 \
542                 *(__ex_table)                                           \
543                 VMLINUX_SYMBOL(__stop___ex_table) = .;                  \
544         }
545
546 /*
547  * Init task
548  */
549 #define INIT_TASK_DATA_SECTION(align)                                   \
550         . = ALIGN(align);                                               \
551         .data..init_task :  AT(ADDR(.data..init_task) - LOAD_OFFSET) {  \
552                 INIT_TASK_DATA(align)                                   \
553         }
554
555 #ifdef CONFIG_CONSTRUCTORS
556 #define KERNEL_CTORS()  . = ALIGN(8);                      \
557                         VMLINUX_SYMBOL(__ctors_start) = .; \
558                         *(.ctors)                          \
559                         *(SORT(.init_array.*))             \
560                         *(.init_array)                     \
561                         VMLINUX_SYMBOL(__ctors_end) = .;
562 #else
563 #define KERNEL_CTORS()
564 #endif
565
566 /* init and exit section handling */
567 #define INIT_DATA                                                       \
568         KEEP(*(SORT(___kentry+*)))                                      \
569         *(.init.data)                                                   \
570         MEM_DISCARD(init.data)                                          \
571         KERNEL_CTORS()                                                  \
572         MCOUNT_REC()                                                    \
573         *(.init.rodata)                                                 \
574         FTRACE_EVENTS()                                                 \
575         TRACE_SYSCALLS()                                                \
576         KPROBE_BLACKLIST()                                              \
577         MEM_DISCARD(init.rodata)                                        \
578         CLK_OF_TABLES()                                                 \
579         RESERVEDMEM_OF_TABLES()                                         \
580         CLKSRC_OF_TABLES()                                              \
581         IOMMU_OF_TABLES()                                               \
582         CPU_METHOD_OF_TABLES()                                          \
583         CPUIDLE_METHOD_OF_TABLES()                                      \
584         KERNEL_DTB()                                                    \
585         IRQCHIP_OF_MATCH_TABLE()                                        \
586         ACPI_PROBE_TABLE(irqchip)                                       \
587         ACPI_PROBE_TABLE(clksrc)                                        \
588         EARLYCON_TABLE()
589
590 #define INIT_TEXT                                                       \
591         *(.init.text)                                                   \
592         *(.text.startup)                                                \
593         MEM_DISCARD(init.text)
594
595 #define EXIT_DATA                                                       \
596         *(.exit.data)                                                   \
597         *(.fini_array)                                                  \
598         *(.dtors)                                                       \
599         MEM_DISCARD(exit.data)                                          \
600         MEM_DISCARD(exit.rodata)
601
602 #define EXIT_TEXT                                                       \
603         *(.exit.text)                                                   \
604         *(.text.exit)                                                   \
605         MEM_DISCARD(exit.text)
606
607 #define EXIT_CALL                                                       \
608         *(.exitcall.exit)
609
610 /*
611  * bss (Block Started by Symbol) - uninitialized data
612  * zeroed during startup
613  */
614 #define SBSS(sbss_align)                                                \
615         . = ALIGN(sbss_align);                                          \
616         .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) {                         \
617                 *(.sbss)                                                \
618                 *(.scommon)                                             \
619         }
620
621 /*
622  * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
623  * sections to the front of bss.
624  */
625 #ifndef BSS_FIRST_SECTIONS
626 #define BSS_FIRST_SECTIONS
627 #endif
628
629 #define BSS(bss_align)                                                  \
630         . = ALIGN(bss_align);                                           \
631         .bss : AT(ADDR(.bss) - LOAD_OFFSET) {                           \
632                 BSS_FIRST_SECTIONS                                      \
633                 . = ALIGN(PAGE_SIZE);                                   \
634                 *(.bss..page_aligned)                                   \
635                 . = ALIGN(PAGE_SIZE);                                   \
636                 *(.dynbss)                                              \
637                 *(BSS_MAIN)                                             \
638                 *(COMMON)                                               \
639         }
640
641 /*
642  * DWARF debug sections.
643  * Symbols in the DWARF debugging sections are relative to
644  * the beginning of the section so we begin them at 0.
645  */
646 #define DWARF_DEBUG                                                     \
647                 /* DWARF 1 */                                           \
648                 .debug          0 : { *(.debug) }                       \
649                 .line           0 : { *(.line) }                        \
650                 /* GNU DWARF 1 extensions */                            \
651                 .debug_srcinfo  0 : { *(.debug_srcinfo) }               \
652                 .debug_sfnames  0 : { *(.debug_sfnames) }               \
653                 /* DWARF 1.1 and DWARF 2 */                             \
654                 .debug_aranges  0 : { *(.debug_aranges) }               \
655                 .debug_pubnames 0 : { *(.debug_pubnames) }              \
656                 /* DWARF 2 */                                           \
657                 .debug_info     0 : { *(.debug_info                     \
658                                 .gnu.linkonce.wi.*) }                   \
659                 .debug_abbrev   0 : { *(.debug_abbrev) }                \
660                 .debug_line     0 : { *(.debug_line) }                  \
661                 .debug_frame    0 : { *(.debug_frame) }                 \
662                 .debug_str      0 : { *(.debug_str) }                   \
663                 .debug_loc      0 : { *(.debug_loc) }                   \
664                 .debug_macinfo  0 : { *(.debug_macinfo) }               \
665                 /* SGI/MIPS DWARF 2 extensions */                       \
666                 .debug_weaknames 0 : { *(.debug_weaknames) }            \
667                 .debug_funcnames 0 : { *(.debug_funcnames) }            \
668                 .debug_typenames 0 : { *(.debug_typenames) }            \
669                 .debug_varnames  0 : { *(.debug_varnames) }             \
670
671                 /* Stabs debugging sections.  */
672 #define STABS_DEBUG                                                     \
673                 .stab 0 : { *(.stab) }                                  \
674                 .stabstr 0 : { *(.stabstr) }                            \
675                 .stab.excl 0 : { *(.stab.excl) }                        \
676                 .stab.exclstr 0 : { *(.stab.exclstr) }                  \
677                 .stab.index 0 : { *(.stab.index) }                      \
678                 .stab.indexstr 0 : { *(.stab.indexstr) }                \
679                 .comment 0 : { *(.comment) }
680
681 #ifdef CONFIG_GENERIC_BUG
682 #define BUG_TABLE                                                       \
683         . = ALIGN(8);                                                   \
684         __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) {             \
685                 VMLINUX_SYMBOL(__start___bug_table) = .;                \
686                 *(__bug_table)                                          \
687                 VMLINUX_SYMBOL(__stop___bug_table) = .;                 \
688         }
689 #else
690 #define BUG_TABLE
691 #endif
692
693 #ifdef CONFIG_PM_TRACE
694 #define TRACEDATA                                                       \
695         . = ALIGN(4);                                                   \
696         .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) {               \
697                 VMLINUX_SYMBOL(__tracedata_start) = .;                  \
698                 *(.tracedata)                                           \
699                 VMLINUX_SYMBOL(__tracedata_end) = .;                    \
700         }
701 #else
702 #define TRACEDATA
703 #endif
704
705 #define NOTES                                                           \
706         .notes : AT(ADDR(.notes) - LOAD_OFFSET) {                       \
707                 VMLINUX_SYMBOL(__start_notes) = .;                      \
708                 *(.note.*)                                              \
709                 VMLINUX_SYMBOL(__stop_notes) = .;                       \
710         }
711
712 #define INIT_SETUP(initsetup_align)                                     \
713                 . = ALIGN(initsetup_align);                             \
714                 VMLINUX_SYMBOL(__setup_start) = .;                      \
715                 *(.init.setup)                                          \
716                 VMLINUX_SYMBOL(__setup_end) = .;
717
718 #define INIT_CALLS_LEVEL(level)                                         \
719                 VMLINUX_SYMBOL(__initcall##level##_start) = .;          \
720                 KEEP(*(.initcall##level##.init))                        \
721                 KEEP(*(.initcall##level##s.init))                       \
722
723 #define INIT_CALLS                                                      \
724                 VMLINUX_SYMBOL(__initcall_start) = .;                   \
725                 KEEP(*(.initcallearly.init))                            \
726                 INIT_CALLS_LEVEL(0)                                     \
727                 INIT_CALLS_LEVEL(1)                                     \
728                 INIT_CALLS_LEVEL(2)                                     \
729                 INIT_CALLS_LEVEL(3)                                     \
730                 INIT_CALLS_LEVEL(4)                                     \
731                 INIT_CALLS_LEVEL(5)                                     \
732                 INIT_CALLS_LEVEL(rootfs)                                \
733                 INIT_CALLS_LEVEL(6)                                     \
734                 INIT_CALLS_LEVEL(7)                                     \
735                 VMLINUX_SYMBOL(__initcall_end) = .;
736
737 #define CON_INITCALL                                                    \
738                 VMLINUX_SYMBOL(__con_initcall_start) = .;               \
739                 KEEP(*(.con_initcall.init))                             \
740                 VMLINUX_SYMBOL(__con_initcall_end) = .;
741
742 #define SECURITY_INITCALL                                               \
743                 VMLINUX_SYMBOL(__security_initcall_start) = .;          \
744                 KEEP(*(.security_initcall.init))                        \
745                 VMLINUX_SYMBOL(__security_initcall_end) = .;
746
747 #ifdef CONFIG_BLK_DEV_INITRD
748 #define INIT_RAM_FS                                                     \
749         . = ALIGN(4);                                                   \
750         VMLINUX_SYMBOL(__initramfs_start) = .;                          \
751         KEEP(*(.init.ramfs))                                            \
752         . = ALIGN(8);                                                   \
753         KEEP(*(.init.ramfs.info))
754 #else
755 #define INIT_RAM_FS
756 #endif
757
758 /*
759  * Default discarded sections.
760  *
761  * Some archs want to discard exit text/data at runtime rather than
762  * link time due to cross-section references such as alt instructions,
763  * bug table, eh_frame, etc.  DISCARDS must be the last of output
764  * section definitions so that such archs put those in earlier section
765  * definitions.
766  */
767 #define DISCARDS                                                        \
768         /DISCARD/ : {                                                   \
769         EXIT_TEXT                                                       \
770         EXIT_DATA                                                       \
771         EXIT_CALL                                                       \
772         *(.discard)                                                     \
773         *(.discard.*)                                                   \
774         }
775
776 /**
777  * PERCPU_INPUT - the percpu input sections
778  * @cacheline: cacheline size
779  *
780  * The core percpu section names and core symbols which do not rely
781  * directly upon load addresses.
782  *
783  * @cacheline is used to align subsections to avoid false cacheline
784  * sharing between subsections for different purposes.
785  */
786 #define PERCPU_INPUT(cacheline)                                         \
787         VMLINUX_SYMBOL(__per_cpu_start) = .;                            \
788         VMLINUX_SYMBOL(__per_cpu_user_mapped_start) = .;                \
789         *(.data..percpu..first)                                         \
790         . = ALIGN(cacheline);                                           \
791         *(.data..percpu..user_mapped)                                   \
792         *(.data..percpu..user_mapped..shared_aligned)                   \
793         . = ALIGN(PAGE_SIZE);                                           \
794         *(.data..percpu..user_mapped..page_aligned)                     \
795         VMLINUX_SYMBOL(__per_cpu_user_mapped_end) = .;                  \
796         . = ALIGN(PAGE_SIZE);                                           \
797         *(.data..percpu..page_aligned)                                  \
798         . = ALIGN(cacheline);                                           \
799         *(.data..percpu..read_mostly)                                   \
800         . = ALIGN(cacheline);                                           \
801         *(.data..percpu)                                                \
802         *(.data..percpu..shared_aligned)                                \
803         VMLINUX_SYMBOL(__per_cpu_end) = .;
804
805 /**
806  * PERCPU_VADDR - define output section for percpu area
807  * @cacheline: cacheline size
808  * @vaddr: explicit base address (optional)
809  * @phdr: destination PHDR (optional)
810  *
811  * Macro which expands to output section for percpu area.
812  *
813  * @cacheline is used to align subsections to avoid false cacheline
814  * sharing between subsections for different purposes.
815  *
816  * If @vaddr is not blank, it specifies explicit base address and all
817  * percpu symbols will be offset from the given address.  If blank,
818  * @vaddr always equals @laddr + LOAD_OFFSET.
819  *
820  * @phdr defines the output PHDR to use if not blank.  Be warned that
821  * output PHDR is sticky.  If @phdr is specified, the next output
822  * section in the linker script will go there too.  @phdr should have
823  * a leading colon.
824  *
825  * Note that this macros defines __per_cpu_load as an absolute symbol.
826  * If there is no need to put the percpu section at a predetermined
827  * address, use PERCPU_SECTION.
828  */
829 #define PERCPU_VADDR(cacheline, vaddr, phdr)                            \
830         VMLINUX_SYMBOL(__per_cpu_load) = .;                             \
831         .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load)         \
832                                 - LOAD_OFFSET) {                        \
833                 PERCPU_INPUT(cacheline)                                 \
834         } phdr                                                          \
835         . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
836
837 /**
838  * PERCPU_SECTION - define output section for percpu area, simple version
839  * @cacheline: cacheline size
840  *
841  * Align to PAGE_SIZE and outputs output section for percpu area.  This
842  * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and
843  * __per_cpu_start will be identical.
844  *
845  * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,)
846  * except that __per_cpu_load is defined as a relative symbol against
847  * .data..percpu which is required for relocatable x86_32 configuration.
848  */
849 #define PERCPU_SECTION(cacheline)                                       \
850         . = ALIGN(PAGE_SIZE);                                           \
851         .data..percpu   : AT(ADDR(.data..percpu) - LOAD_OFFSET) {       \
852                 VMLINUX_SYMBOL(__per_cpu_load) = .;                     \
853                 PERCPU_INPUT(cacheline)                                 \
854         }
855
856
857 /*
858  * Definition of the high level *_SECTION macros
859  * They will fit only a subset of the architectures
860  */
861
862
863 /*
864  * Writeable data.
865  * All sections are combined in a single .data section.
866  * The sections following CONSTRUCTORS are arranged so their
867  * typical alignment matches.
868  * A cacheline is typical/always less than a PAGE_SIZE so
869  * the sections that has this restriction (or similar)
870  * is located before the ones requiring PAGE_SIZE alignment.
871  * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which
872  * matches the requirement of PAGE_ALIGNED_DATA.
873  *
874  * use 0 as page_align if page_aligned data is not used */
875 #define RW_DATA_SECTION(cacheline, pagealigned, inittask)               \
876         . = ALIGN(PAGE_SIZE);                                           \
877         .data : AT(ADDR(.data) - LOAD_OFFSET) {                         \
878                 INIT_TASK_DATA(inittask)                                \
879                 NOSAVE_DATA                                             \
880                 PAGE_ALIGNED_DATA(pagealigned)                          \
881                 CACHELINE_ALIGNED_DATA(cacheline)                       \
882                 READ_MOSTLY_DATA(cacheline)                             \
883                 DATA_DATA                                               \
884                 CONSTRUCTORS                                            \
885         }
886
887 #define INIT_TEXT_SECTION(inittext_align)                               \
888         . = ALIGN(inittext_align);                                      \
889         .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {               \
890                 VMLINUX_SYMBOL(_sinittext) = .;                         \
891                 INIT_TEXT                                               \
892                 VMLINUX_SYMBOL(_einittext) = .;                         \
893         }
894
895 #define INIT_DATA_SECTION(initsetup_align)                              \
896         .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {               \
897                 INIT_DATA                                               \
898                 INIT_SETUP(initsetup_align)                             \
899                 INIT_CALLS                                              \
900                 CON_INITCALL                                            \
901                 SECURITY_INITCALL                                       \
902                 INIT_RAM_FS                                             \
903         }
904
905 #define BSS_SECTION(sbss_align, bss_align, stop_align)                  \
906         . = ALIGN(sbss_align);                                          \
907         VMLINUX_SYMBOL(__bss_start) = .;                                \
908         SBSS(sbss_align)                                                \
909         BSS(bss_align)                                                  \
910         . = ALIGN(stop_align);                                          \
911         VMLINUX_SYMBOL(__bss_stop) = .;