blob: 86a233a7e6575d70eaea7332d92f6ec7b0a71b78 [file] [log] [blame]
Googleraf606d22022-10-26 21:40:12 -07001/*
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
Googlerb48fa912023-03-17 12:40:29 +053057#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
Googleraf606d22022-10-26 21:40:12 -070067/* 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.
Googler9398cc32022-12-02 17:21:52 +080075 *
Googler9398cc32022-12-02 17:21:52 +080076 * RODATA_MAIN is not used because existing code already defines .rodata.x
77 * sections to be brought in with rodata.
Googleraf606d22022-10-26 21:40:12 -070078 */
Googlerb48fa912023-03-17 12:40:29 +053079#ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
Googleraf606d22022-10-26 21:40:12 -070080#define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
Googlerb48fa912023-03-17 12:40:29 +053081#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..LPBX*
Googler9398cc32022-12-02 17:21:52 +080082#define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
Googlerb48fa912023-03-17 12:40:29 +053083#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]*
84#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]*
Googler9398cc32022-12-02 17:21:52 +080085#define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*
Googleraf606d22022-10-26 21:40:12 -070086#else
87#define TEXT_MAIN .text
Googleraf606d22022-10-26 21:40:12 -070088#define DATA_MAIN .data
Googler9398cc32022-12-02 17:21:52 +080089#define SDATA_MAIN .sdata
90#define RODATA_MAIN .rodata
Googleraf606d22022-10-26 21:40:12 -070091#define BSS_MAIN .bss
Googler9398cc32022-12-02 17:21:52 +080092#define SBSS_MAIN .sbss
Googleraf606d22022-10-26 21:40:12 -070093#endif
94
95/*
96 * Align to a 32 byte boundary equal to the
97 * alignment gcc 4.5 uses for a struct
98 */
99#define STRUCT_ALIGNMENT 32
100#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
101
102/* The actual configuration determine if the init/exit sections
103 * are handled as text/data or they can be discarded (which
104 * often happens at runtime)
105 */
106#ifdef CONFIG_HOTPLUG_CPU
107#define CPU_KEEP(sec) *(.cpu##sec)
108#define CPU_DISCARD(sec)
109#else
110#define CPU_KEEP(sec)
111#define CPU_DISCARD(sec) *(.cpu##sec)
112#endif
113
114#if defined(CONFIG_MEMORY_HOTPLUG)
115#define MEM_KEEP(sec) *(.mem##sec)
116#define MEM_DISCARD(sec)
117#else
118#define MEM_KEEP(sec)
119#define MEM_DISCARD(sec) *(.mem##sec)
120#endif
121
122#ifdef CONFIG_FTRACE_MCOUNT_RECORD
Googlerb48fa912023-03-17 12:40:29 +0530123#ifdef CC_USING_PATCHABLE_FUNCTION_ENTRY
124#define MCOUNT_REC() . = ALIGN(8); \
125 __start_mcount_loc = .; \
126 KEEP(*(__patchable_function_entries)) \
127 __stop_mcount_loc = .;
128#else
Googleraf606d22022-10-26 21:40:12 -0700129#define MCOUNT_REC() . = ALIGN(8); \
Googler9398cc32022-12-02 17:21:52 +0800130 __start_mcount_loc = .; \
Googleraf606d22022-10-26 21:40:12 -0700131 KEEP(*(__mcount_loc)) \
Googler9398cc32022-12-02 17:21:52 +0800132 __stop_mcount_loc = .;
Googlerb48fa912023-03-17 12:40:29 +0530133#endif
Googleraf606d22022-10-26 21:40:12 -0700134#else
135#define MCOUNT_REC()
136#endif
137
138#ifdef CONFIG_TRACE_BRANCH_PROFILING
Googler9398cc32022-12-02 17:21:52 +0800139#define LIKELY_PROFILE() __start_annotated_branch_profile = .; \
140 KEEP(*(_ftrace_annotated_branch)) \
141 __stop_annotated_branch_profile = .;
Googleraf606d22022-10-26 21:40:12 -0700142#else
143#define LIKELY_PROFILE()
144#endif
145
146#ifdef CONFIG_PROFILE_ALL_BRANCHES
Googler9398cc32022-12-02 17:21:52 +0800147#define BRANCH_PROFILE() __start_branch_profile = .; \
148 KEEP(*(_ftrace_branch)) \
149 __stop_branch_profile = .;
Googleraf606d22022-10-26 21:40:12 -0700150#else
151#define BRANCH_PROFILE()
152#endif
153
154#ifdef CONFIG_KPROBES
155#define KPROBE_BLACKLIST() . = ALIGN(8); \
Googler9398cc32022-12-02 17:21:52 +0800156 __start_kprobe_blacklist = .; \
157 KEEP(*(_kprobe_blacklist)) \
158 __stop_kprobe_blacklist = .;
Googleraf606d22022-10-26 21:40:12 -0700159#else
160#define KPROBE_BLACKLIST()
161#endif
162
Googler9398cc32022-12-02 17:21:52 +0800163#ifdef CONFIG_FUNCTION_ERROR_INJECTION
164#define ERROR_INJECT_WHITELIST() STRUCT_ALIGN(); \
165 __start_error_injection_whitelist = .; \
166 KEEP(*(_error_injection_whitelist)) \
167 __stop_error_injection_whitelist = .;
168#else
169#define ERROR_INJECT_WHITELIST()
170#endif
171
Googleraf606d22022-10-26 21:40:12 -0700172#ifdef CONFIG_EVENT_TRACING
173#define FTRACE_EVENTS() . = ALIGN(8); \
Googler9398cc32022-12-02 17:21:52 +0800174 __start_ftrace_events = .; \
Googleraf606d22022-10-26 21:40:12 -0700175 KEEP(*(_ftrace_events)) \
Googler9398cc32022-12-02 17:21:52 +0800176 __stop_ftrace_events = .; \
177 __start_ftrace_eval_maps = .; \
178 KEEP(*(_ftrace_eval_map)) \
179 __stop_ftrace_eval_maps = .;
Googleraf606d22022-10-26 21:40:12 -0700180#else
181#define FTRACE_EVENTS()
182#endif
183
184#ifdef CONFIG_TRACING
Googler9398cc32022-12-02 17:21:52 +0800185#define TRACE_PRINTKS() __start___trace_bprintk_fmt = .; \
186 KEEP(*(__trace_printk_fmt)) /* Trace_printk fmt' pointer */ \
187 __stop___trace_bprintk_fmt = .;
188#define TRACEPOINT_STR() __start___tracepoint_str = .; \
189 KEEP(*(__tracepoint_str)) /* Trace_printk fmt' pointer */ \
190 __stop___tracepoint_str = .;
Googleraf606d22022-10-26 21:40:12 -0700191#else
192#define TRACE_PRINTKS()
193#define TRACEPOINT_STR()
194#endif
195
196#ifdef CONFIG_FTRACE_SYSCALLS
197#define TRACE_SYSCALLS() . = ALIGN(8); \
Googler9398cc32022-12-02 17:21:52 +0800198 __start_syscalls_metadata = .; \
199 KEEP(*(__syscalls_metadata)) \
200 __stop_syscalls_metadata = .;
Googleraf606d22022-10-26 21:40:12 -0700201#else
202#define TRACE_SYSCALLS()
203#endif
204
Googler9398cc32022-12-02 17:21:52 +0800205#ifdef CONFIG_BPF_EVENTS
206#define BPF_RAW_TP() STRUCT_ALIGN(); \
207 __start__bpf_raw_tp = .; \
208 KEEP(*(__bpf_raw_tp_map)) \
209 __stop__bpf_raw_tp = .;
210#else
211#define BPF_RAW_TP()
212#endif
213
Googleraf606d22022-10-26 21:40:12 -0700214#ifdef CONFIG_SERIAL_EARLYCON
215#define EARLYCON_TABLE() . = ALIGN(8); \
Googler9398cc32022-12-02 17:21:52 +0800216 __earlycon_table = .; \
217 KEEP(*(__earlycon_table)) \
218 __earlycon_table_end = .;
Googleraf606d22022-10-26 21:40:12 -0700219#else
220#define EARLYCON_TABLE()
221#endif
222
Googler9398cc32022-12-02 17:21:52 +0800223#ifdef CONFIG_SECURITY
224#define LSM_TABLE() . = ALIGN(8); \
225 __start_lsm_info = .; \
226 KEEP(*(.lsm_info.init)) \
227 __end_lsm_info = .;
228#define EARLY_LSM_TABLE() . = ALIGN(8); \
229 __start_early_lsm_info = .; \
230 KEEP(*(.early_lsm_info.init)) \
231 __end_early_lsm_info = .;
232#else
233#define LSM_TABLE()
234#define EARLY_LSM_TABLE()
235#endif
236
Googleraf606d22022-10-26 21:40:12 -0700237#define ___OF_TABLE(cfg, name) _OF_TABLE_##cfg(name)
238#define __OF_TABLE(cfg, name) ___OF_TABLE(cfg, name)
239#define OF_TABLE(cfg, name) __OF_TABLE(IS_ENABLED(cfg), name)
240#define _OF_TABLE_0(name)
241#define _OF_TABLE_1(name) \
242 . = ALIGN(8); \
Googler9398cc32022-12-02 17:21:52 +0800243 __##name##_of_table = .; \
Googleraf606d22022-10-26 21:40:12 -0700244 KEEP(*(__##name##_of_table)) \
245 KEEP(*(__##name##_of_table_end))
246
Googler9398cc32022-12-02 17:21:52 +0800247#define TIMER_OF_TABLES() OF_TABLE(CONFIG_TIMER_OF, timer)
Googleraf606d22022-10-26 21:40:12 -0700248#define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip)
249#define CLK_OF_TABLES() OF_TABLE(CONFIG_COMMON_CLK, clk)
250#define RESERVEDMEM_OF_TABLES() OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem)
251#define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method)
252#define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method)
253
254#ifdef CONFIG_ACPI
255#define ACPI_PROBE_TABLE(name) \
256 . = ALIGN(8); \
Googler9398cc32022-12-02 17:21:52 +0800257 __##name##_acpi_probe_table = .; \
258 KEEP(*(__##name##_acpi_probe_table)) \
259 __##name##_acpi_probe_table_end = .;
Googleraf606d22022-10-26 21:40:12 -0700260#else
261#define ACPI_PROBE_TABLE(name)
262#endif
263
Googler9398cc32022-12-02 17:21:52 +0800264#ifdef CONFIG_THERMAL
265#define THERMAL_TABLE(name) \
266 . = ALIGN(8); \
267 __##name##_thermal_table = .; \
268 KEEP(*(__##name##_thermal_table)) \
269 __##name##_thermal_table_end = .;
270#else
271#define THERMAL_TABLE(name)
272#endif
273
Googleraf606d22022-10-26 21:40:12 -0700274#define KERNEL_DTB() \
275 STRUCT_ALIGN(); \
Googler9398cc32022-12-02 17:21:52 +0800276 __dtb_start = .; \
277 KEEP(*(.dtb.init.rodata)) \
278 __dtb_end = .;
Googleraf606d22022-10-26 21:40:12 -0700279
280/*
281 * .data section
282 */
283#define DATA_DATA \
Googler9398cc32022-12-02 17:21:52 +0800284 *(.xiptext) \
Googleraf606d22022-10-26 21:40:12 -0700285 *(DATA_MAIN) \
286 *(.ref.data) \
287 *(.data..shared_aligned) /* percpu related */ \
Googler9398cc32022-12-02 17:21:52 +0800288 MEM_KEEP(init.data*) \
289 MEM_KEEP(exit.data*) \
Googleraf606d22022-10-26 21:40:12 -0700290 *(.data.unlikely) \
Googler9398cc32022-12-02 17:21:52 +0800291 __start_once = .; \
292 *(.data.once) \
293 __end_once = .; \
Googleraf606d22022-10-26 21:40:12 -0700294 STRUCT_ALIGN(); \
295 *(__tracepoints) \
296 /* implement dynamic printk debug */ \
297 . = ALIGN(8); \
Googler9398cc32022-12-02 17:21:52 +0800298 __start___verbose = .; \
299 KEEP(*(__verbose)) \
300 __stop___verbose = .; \
Googleraf606d22022-10-26 21:40:12 -0700301 LIKELY_PROFILE() \
302 BRANCH_PROFILE() \
303 TRACE_PRINTKS() \
Googler9398cc32022-12-02 17:21:52 +0800304 BPF_RAW_TP() \
Googleraf606d22022-10-26 21:40:12 -0700305 TRACEPOINT_STR()
306
307/*
308 * Data section helpers
309 */
310#define NOSAVE_DATA \
311 . = ALIGN(PAGE_SIZE); \
Googler9398cc32022-12-02 17:21:52 +0800312 __nosave_begin = .; \
Googleraf606d22022-10-26 21:40:12 -0700313 *(.data..nosave) \
314 . = ALIGN(PAGE_SIZE); \
Googler9398cc32022-12-02 17:21:52 +0800315 __nosave_end = .;
Googleraf606d22022-10-26 21:40:12 -0700316
317#define PAGE_ALIGNED_DATA(page_align) \
318 . = ALIGN(page_align); \
319 *(.data..page_aligned) \
320 . = ALIGN(page_align);
321
322#define READ_MOSTLY_DATA(align) \
323 . = ALIGN(align); \
324 *(.data..read_mostly) \
325 . = ALIGN(align);
326
327#define CACHELINE_ALIGNED_DATA(align) \
328 . = ALIGN(align); \
329 *(.data..cacheline_aligned)
330
331#define INIT_TASK_DATA(align) \
332 . = ALIGN(align); \
Googler9398cc32022-12-02 17:21:52 +0800333 __start_init_task = .; \
334 init_thread_union = .; \
335 init_stack = .; \
336 KEEP(*(.data..init_task)) \
337 KEEP(*(.data..init_thread_info)) \
338 . = __start_init_task + THREAD_SIZE; \
339 __end_init_task = .;
340
341#define JUMP_TABLE_DATA \
342 . = ALIGN(8); \
343 __start___jump_table = .; \
344 KEEP(*(__jump_table)) \
345 __stop___jump_table = .;
Googleraf606d22022-10-26 21:40:12 -0700346
347/*
348 * Allow architectures to handle ro_after_init data on their
349 * own by defining an empty RO_AFTER_INIT_DATA.
350 */
351#ifndef RO_AFTER_INIT_DATA
352#define RO_AFTER_INIT_DATA \
Googler9398cc32022-12-02 17:21:52 +0800353 . = ALIGN(8); \
354 __start_ro_after_init = .; \
Googleraf606d22022-10-26 21:40:12 -0700355 *(.data..ro_after_init) \
Googler9398cc32022-12-02 17:21:52 +0800356 JUMP_TABLE_DATA \
357 __end_ro_after_init = .;
Googleraf606d22022-10-26 21:40:12 -0700358#endif
359
360/*
361 * Read only Data
362 */
363#define RO_DATA_SECTION(align) \
364 . = ALIGN((align)); \
365 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800366 __start_rodata = .; \
Googleraf606d22022-10-26 21:40:12 -0700367 *(.rodata) *(.rodata.*) \
368 RO_AFTER_INIT_DATA /* Read only after init */ \
369 . = ALIGN(8); \
Googler9398cc32022-12-02 17:21:52 +0800370 __start___tracepoints_ptrs = .; \
371 KEEP(*(__tracepoints_ptrs)) /* Tracepoints: pointer array */ \
372 __stop___tracepoints_ptrs = .; \
Googleraf606d22022-10-26 21:40:12 -0700373 *(__tracepoints_strings)/* Tracepoints: strings */ \
374 } \
375 \
376 .rodata1 : AT(ADDR(.rodata1) - LOAD_OFFSET) { \
377 *(.rodata1) \
378 } \
379 \
380 /* PCI quirks */ \
381 .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800382 __start_pci_fixups_early = .; \
Googleraf606d22022-10-26 21:40:12 -0700383 KEEP(*(.pci_fixup_early)) \
Googler9398cc32022-12-02 17:21:52 +0800384 __end_pci_fixups_early = .; \
385 __start_pci_fixups_header = .; \
Googleraf606d22022-10-26 21:40:12 -0700386 KEEP(*(.pci_fixup_header)) \
Googler9398cc32022-12-02 17:21:52 +0800387 __end_pci_fixups_header = .; \
388 __start_pci_fixups_final = .; \
Googleraf606d22022-10-26 21:40:12 -0700389 KEEP(*(.pci_fixup_final)) \
Googler9398cc32022-12-02 17:21:52 +0800390 __end_pci_fixups_final = .; \
391 __start_pci_fixups_enable = .; \
Googleraf606d22022-10-26 21:40:12 -0700392 KEEP(*(.pci_fixup_enable)) \
Googler9398cc32022-12-02 17:21:52 +0800393 __end_pci_fixups_enable = .; \
394 __start_pci_fixups_resume = .; \
Googleraf606d22022-10-26 21:40:12 -0700395 KEEP(*(.pci_fixup_resume)) \
Googler9398cc32022-12-02 17:21:52 +0800396 __end_pci_fixups_resume = .; \
397 __start_pci_fixups_resume_early = .; \
Googleraf606d22022-10-26 21:40:12 -0700398 KEEP(*(.pci_fixup_resume_early)) \
Googler9398cc32022-12-02 17:21:52 +0800399 __end_pci_fixups_resume_early = .; \
400 __start_pci_fixups_suspend = .; \
Googleraf606d22022-10-26 21:40:12 -0700401 KEEP(*(.pci_fixup_suspend)) \
Googler9398cc32022-12-02 17:21:52 +0800402 __end_pci_fixups_suspend = .; \
403 __start_pci_fixups_suspend_late = .; \
Googleraf606d22022-10-26 21:40:12 -0700404 KEEP(*(.pci_fixup_suspend_late)) \
Googler9398cc32022-12-02 17:21:52 +0800405 __end_pci_fixups_suspend_late = .; \
Googleraf606d22022-10-26 21:40:12 -0700406 } \
407 \
408 /* Built-in firmware blobs */ \
Googlerb48fa912023-03-17 12:40:29 +0530409 .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800410 __start_builtin_fw = .; \
411 KEEP(*(.builtin_fw)) \
412 __end_builtin_fw = .; \
Googleraf606d22022-10-26 21:40:12 -0700413 } \
414 \
415 TRACEDATA \
416 \
417 /* Kernel symbol table: Normal symbols */ \
418 __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800419 __start___ksymtab = .; \
Googlerb48fa912023-03-17 12:40:29 +0530420 SYMTAB_KEEP \
Googler9398cc32022-12-02 17:21:52 +0800421 __stop___ksymtab = .; \
Googleraf606d22022-10-26 21:40:12 -0700422 } \
423 \
424 /* Kernel symbol table: GPL-only symbols */ \
425 __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800426 __start___ksymtab_gpl = .; \
Googlerb48fa912023-03-17 12:40:29 +0530427 SYMTAB_KEEP_GPL \
Googler9398cc32022-12-02 17:21:52 +0800428 __stop___ksymtab_gpl = .; \
Googleraf606d22022-10-26 21:40:12 -0700429 } \
430 \
431 /* Kernel symbol table: Normal unused symbols */ \
432 __ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800433 __start___ksymtab_unused = .; \
Googleraf606d22022-10-26 21:40:12 -0700434 KEEP(*(SORT(___ksymtab_unused+*))) \
Googler9398cc32022-12-02 17:21:52 +0800435 __stop___ksymtab_unused = .; \
Googleraf606d22022-10-26 21:40:12 -0700436 } \
437 \
438 /* Kernel symbol table: GPL-only unused symbols */ \
439 __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800440 __start___ksymtab_unused_gpl = .; \
Googleraf606d22022-10-26 21:40:12 -0700441 KEEP(*(SORT(___ksymtab_unused_gpl+*))) \
Googler9398cc32022-12-02 17:21:52 +0800442 __stop___ksymtab_unused_gpl = .; \
Googleraf606d22022-10-26 21:40:12 -0700443 } \
444 \
445 /* Kernel symbol table: GPL-future-only symbols */ \
446 __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800447 __start___ksymtab_gpl_future = .; \
Googleraf606d22022-10-26 21:40:12 -0700448 KEEP(*(SORT(___ksymtab_gpl_future+*))) \
Googler9398cc32022-12-02 17:21:52 +0800449 __stop___ksymtab_gpl_future = .; \
Googleraf606d22022-10-26 21:40:12 -0700450 } \
451 \
452 /* Kernel symbol table: Normal symbols */ \
453 __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800454 __start___kcrctab = .; \
Googleraf606d22022-10-26 21:40:12 -0700455 KEEP(*(SORT(___kcrctab+*))) \
Googler9398cc32022-12-02 17:21:52 +0800456 __stop___kcrctab = .; \
Googleraf606d22022-10-26 21:40:12 -0700457 } \
458 \
459 /* Kernel symbol table: GPL-only symbols */ \
460 __kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800461 __start___kcrctab_gpl = .; \
Googleraf606d22022-10-26 21:40:12 -0700462 KEEP(*(SORT(___kcrctab_gpl+*))) \
Googler9398cc32022-12-02 17:21:52 +0800463 __stop___kcrctab_gpl = .; \
Googleraf606d22022-10-26 21:40:12 -0700464 } \
465 \
466 /* Kernel symbol table: Normal unused symbols */ \
467 __kcrctab_unused : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800468 __start___kcrctab_unused = .; \
Googleraf606d22022-10-26 21:40:12 -0700469 KEEP(*(SORT(___kcrctab_unused+*))) \
Googler9398cc32022-12-02 17:21:52 +0800470 __stop___kcrctab_unused = .; \
Googleraf606d22022-10-26 21:40:12 -0700471 } \
472 \
473 /* Kernel symbol table: GPL-only unused symbols */ \
474 __kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800475 __start___kcrctab_unused_gpl = .; \
Googleraf606d22022-10-26 21:40:12 -0700476 KEEP(*(SORT(___kcrctab_unused_gpl+*))) \
Googler9398cc32022-12-02 17:21:52 +0800477 __stop___kcrctab_unused_gpl = .; \
Googleraf606d22022-10-26 21:40:12 -0700478 } \
479 \
480 /* Kernel symbol table: GPL-future-only symbols */ \
481 __kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800482 __start___kcrctab_gpl_future = .; \
Googleraf606d22022-10-26 21:40:12 -0700483 KEEP(*(SORT(___kcrctab_gpl_future+*))) \
Googler9398cc32022-12-02 17:21:52 +0800484 __stop___kcrctab_gpl_future = .; \
Googleraf606d22022-10-26 21:40:12 -0700485 } \
486 \
487 /* Kernel symbol table: strings */ \
488 __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \
Googlerb48fa912023-03-17 12:40:29 +0530489 *(__ksymtab_strings+*) \
Googleraf606d22022-10-26 21:40:12 -0700490 } \
491 \
492 /* __*init sections */ \
493 __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \
494 *(.ref.rodata) \
495 MEM_KEEP(init.rodata) \
496 MEM_KEEP(exit.rodata) \
497 } \
498 \
499 /* Built-in module parameters. */ \
500 __param : AT(ADDR(__param) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800501 __start___param = .; \
Googleraf606d22022-10-26 21:40:12 -0700502 KEEP(*(__param)) \
Googler9398cc32022-12-02 17:21:52 +0800503 __stop___param = .; \
Googleraf606d22022-10-26 21:40:12 -0700504 } \
505 \
506 /* Built-in module versions. */ \
507 __modver : AT(ADDR(__modver) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800508 __start___modver = .; \
509 KEEP(*(__modver)) \
510 __stop___modver = .; \
Googleraf606d22022-10-26 21:40:12 -0700511 } \
Googler9398cc32022-12-02 17:21:52 +0800512 \
513 BTF \
514 \
515 . = ALIGN((align)); \
516 __end_rodata = .;
Googleraf606d22022-10-26 21:40:12 -0700517
518/* RODATA & RO_DATA provided for backward compatibility.
519 * All archs are supposed to use RO_DATA() */
520#define RODATA RO_DATA_SECTION(4096)
521#define RO_DATA(align) RO_DATA_SECTION(align)
522
Googler9398cc32022-12-02 17:21:52 +0800523/*
Googleraf606d22022-10-26 21:40:12 -0700524 * .text section. Map to function alignment to avoid address changes
525 * during second ld run in second ld pass when generating System.map
526 *
527 * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead
528 * code elimination is enabled, so these sections should be converted
529 * to use ".." first.
530 */
531#define TEXT_TEXT \
532 ALIGN_FUNCTION(); \
Googlerb48fa912023-03-17 12:40:29 +0530533 *(.text.hot TEXT_MAIN .text.fixup .text.unlikely) \
Googler9398cc32022-12-02 17:21:52 +0800534 *(.text..refcount) \
Googleraf606d22022-10-26 21:40:12 -0700535 *(.ref.text) \
Googler9398cc32022-12-02 17:21:52 +0800536 MEM_KEEP(init.text*) \
537 MEM_KEEP(exit.text*) \
Googleraf606d22022-10-26 21:40:12 -0700538
539
540/* sched.text is aling to function alignment to secure we have same
541 * address even at second ld pass when generating System.map */
542#define SCHED_TEXT \
543 ALIGN_FUNCTION(); \
Googler9398cc32022-12-02 17:21:52 +0800544 __sched_text_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700545 *(.sched.text) \
Googler9398cc32022-12-02 17:21:52 +0800546 __sched_text_end = .;
Googleraf606d22022-10-26 21:40:12 -0700547
548/* spinlock.text is aling to function alignment to secure we have same
549 * address even at second ld pass when generating System.map */
550#define LOCK_TEXT \
551 ALIGN_FUNCTION(); \
Googler9398cc32022-12-02 17:21:52 +0800552 __lock_text_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700553 *(.spinlock.text) \
Googler9398cc32022-12-02 17:21:52 +0800554 __lock_text_end = .;
Googleraf606d22022-10-26 21:40:12 -0700555
556#define CPUIDLE_TEXT \
557 ALIGN_FUNCTION(); \
Googler9398cc32022-12-02 17:21:52 +0800558 __cpuidle_text_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700559 *(.cpuidle.text) \
Googler9398cc32022-12-02 17:21:52 +0800560 __cpuidle_text_end = .;
Googleraf606d22022-10-26 21:40:12 -0700561
562#define KPROBES_TEXT \
563 ALIGN_FUNCTION(); \
Googler9398cc32022-12-02 17:21:52 +0800564 __kprobes_text_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700565 *(.kprobes.text) \
Googler9398cc32022-12-02 17:21:52 +0800566 __kprobes_text_end = .;
Googleraf606d22022-10-26 21:40:12 -0700567
568#define ENTRY_TEXT \
569 ALIGN_FUNCTION(); \
Googler9398cc32022-12-02 17:21:52 +0800570 __entry_text_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700571 *(.entry.text) \
Googler9398cc32022-12-02 17:21:52 +0800572 __entry_text_end = .;
Googleraf606d22022-10-26 21:40:12 -0700573
574#define IRQENTRY_TEXT \
575 ALIGN_FUNCTION(); \
Googler9398cc32022-12-02 17:21:52 +0800576 __irqentry_text_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700577 *(.irqentry.text) \
Googler9398cc32022-12-02 17:21:52 +0800578 __irqentry_text_end = .;
Googleraf606d22022-10-26 21:40:12 -0700579
580#define SOFTIRQENTRY_TEXT \
581 ALIGN_FUNCTION(); \
Googler9398cc32022-12-02 17:21:52 +0800582 __softirqentry_text_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700583 *(.softirqentry.text) \
Googler9398cc32022-12-02 17:21:52 +0800584 __softirqentry_text_end = .;
Googleraf606d22022-10-26 21:40:12 -0700585
586/* Section used for early init (in .S files) */
587#define HEAD_TEXT KEEP(*(.head.text))
588
589#define HEAD_TEXT_SECTION \
590 .head.text : AT(ADDR(.head.text) - LOAD_OFFSET) { \
591 HEAD_TEXT \
592 }
593
594/*
595 * Exception table
596 */
597#define EXCEPTION_TABLE(align) \
598 . = ALIGN(align); \
599 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800600 __start___ex_table = .; \
Googleraf606d22022-10-26 21:40:12 -0700601 KEEP(*(__ex_table)) \
Googler9398cc32022-12-02 17:21:52 +0800602 __stop___ex_table = .; \
Googleraf606d22022-10-26 21:40:12 -0700603 }
604
605/*
Googler9398cc32022-12-02 17:21:52 +0800606 * .BTF
607 */
608#ifdef CONFIG_DEBUG_INFO_BTF
609#define BTF \
610 .BTF : AT(ADDR(.BTF) - LOAD_OFFSET) { \
611 __start_BTF = .; \
612 KEEP(*(.BTF)) \
613 __stop_BTF = .; \
614 }
615#else
616#define BTF
617#endif
618
619/*
Googleraf606d22022-10-26 21:40:12 -0700620 * Init task
621 */
622#define INIT_TASK_DATA_SECTION(align) \
623 . = ALIGN(align); \
624 .data..init_task : AT(ADDR(.data..init_task) - LOAD_OFFSET) { \
625 INIT_TASK_DATA(align) \
626 }
627
628#ifdef CONFIG_CONSTRUCTORS
629#define KERNEL_CTORS() . = ALIGN(8); \
Googler9398cc32022-12-02 17:21:52 +0800630 __ctors_start = .; \
631 KEEP(*(.ctors)) \
632 KEEP(*(SORT(.init_array.*))) \
633 KEEP(*(.init_array)) \
634 __ctors_end = .;
Googleraf606d22022-10-26 21:40:12 -0700635#else
636#define KERNEL_CTORS()
637#endif
638
639/* init and exit section handling */
640#define INIT_DATA \
641 KEEP(*(SORT(___kentry+*))) \
Googler9398cc32022-12-02 17:21:52 +0800642 *(.init.data init.data.*) \
643 MEM_DISCARD(init.data*) \
Googleraf606d22022-10-26 21:40:12 -0700644 KERNEL_CTORS() \
645 MCOUNT_REC() \
646 *(.init.rodata .init.rodata.*) \
647 FTRACE_EVENTS() \
648 TRACE_SYSCALLS() \
649 KPROBE_BLACKLIST() \
Googler9398cc32022-12-02 17:21:52 +0800650 ERROR_INJECT_WHITELIST() \
Googleraf606d22022-10-26 21:40:12 -0700651 MEM_DISCARD(init.rodata) \
652 CLK_OF_TABLES() \
653 RESERVEDMEM_OF_TABLES() \
Googler9398cc32022-12-02 17:21:52 +0800654 TIMER_OF_TABLES() \
Googleraf606d22022-10-26 21:40:12 -0700655 CPU_METHOD_OF_TABLES() \
656 CPUIDLE_METHOD_OF_TABLES() \
657 KERNEL_DTB() \
658 IRQCHIP_OF_MATCH_TABLE() \
659 ACPI_PROBE_TABLE(irqchip) \
Googler9398cc32022-12-02 17:21:52 +0800660 ACPI_PROBE_TABLE(timer) \
661 THERMAL_TABLE(governor) \
662 EARLYCON_TABLE() \
663 LSM_TABLE() \
664 EARLY_LSM_TABLE()
Googleraf606d22022-10-26 21:40:12 -0700665
666#define INIT_TEXT \
667 *(.init.text .init.text.*) \
668 *(.text.startup) \
Googler9398cc32022-12-02 17:21:52 +0800669 MEM_DISCARD(init.text*)
Googleraf606d22022-10-26 21:40:12 -0700670
671#define EXIT_DATA \
Googler9398cc32022-12-02 17:21:52 +0800672 *(.exit.data .exit.data.*) \
673 *(.fini_array .fini_array.*) \
674 *(.dtors .dtors.*) \
675 MEM_DISCARD(exit.data*) \
676 MEM_DISCARD(exit.rodata*)
Googleraf606d22022-10-26 21:40:12 -0700677
678#define EXIT_TEXT \
679 *(.exit.text) \
680 *(.text.exit) \
681 MEM_DISCARD(exit.text)
682
683#define EXIT_CALL \
Googler9398cc32022-12-02 17:21:52 +0800684 *(.exitcall.exit)
Googleraf606d22022-10-26 21:40:12 -0700685
686/*
687 * bss (Block Started by Symbol) - uninitialized data
688 * zeroed during startup
689 */
690#define SBSS(sbss_align) \
691 . = ALIGN(sbss_align); \
692 .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800693 *(.dynsbss) \
694 *(SBSS_MAIN) \
Googleraf606d22022-10-26 21:40:12 -0700695 *(.scommon) \
696 }
697
698/*
699 * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
700 * sections to the front of bss.
701 */
702#ifndef BSS_FIRST_SECTIONS
703#define BSS_FIRST_SECTIONS
704#endif
705
706#define BSS(bss_align) \
707 . = ALIGN(bss_align); \
708 .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \
709 BSS_FIRST_SECTIONS \
710 . = ALIGN(PAGE_SIZE); \
711 *(.bss..page_aligned) \
712 . = ALIGN(PAGE_SIZE); \
713 *(.dynbss) \
714 *(BSS_MAIN) \
715 *(COMMON) \
716 }
717
718/*
719 * DWARF debug sections.
720 * Symbols in the DWARF debugging sections are relative to
721 * the beginning of the section so we begin them at 0.
722 */
723#define DWARF_DEBUG \
724 /* DWARF 1 */ \
725 .debug 0 : { *(.debug) } \
726 .line 0 : { *(.line) } \
727 /* GNU DWARF 1 extensions */ \
728 .debug_srcinfo 0 : { *(.debug_srcinfo) } \
729 .debug_sfnames 0 : { *(.debug_sfnames) } \
730 /* DWARF 1.1 and DWARF 2 */ \
731 .debug_aranges 0 : { *(.debug_aranges) } \
732 .debug_pubnames 0 : { *(.debug_pubnames) } \
733 /* DWARF 2 */ \
734 .debug_info 0 : { *(.debug_info \
735 .gnu.linkonce.wi.*) } \
736 .debug_abbrev 0 : { *(.debug_abbrev) } \
737 .debug_line 0 : { *(.debug_line) } \
738 .debug_frame 0 : { *(.debug_frame) } \
739 .debug_str 0 : { *(.debug_str) } \
740 .debug_loc 0 : { *(.debug_loc) } \
741 .debug_macinfo 0 : { *(.debug_macinfo) } \
Googler9398cc32022-12-02 17:21:52 +0800742 .debug_pubtypes 0 : { *(.debug_pubtypes) } \
743 /* DWARF 3 */ \
744 .debug_ranges 0 : { *(.debug_ranges) } \
Googleraf606d22022-10-26 21:40:12 -0700745 /* SGI/MIPS DWARF 2 extensions */ \
746 .debug_weaknames 0 : { *(.debug_weaknames) } \
747 .debug_funcnames 0 : { *(.debug_funcnames) } \
748 .debug_typenames 0 : { *(.debug_typenames) } \
749 .debug_varnames 0 : { *(.debug_varnames) } \
Googler9398cc32022-12-02 17:21:52 +0800750 /* GNU DWARF 2 extensions */ \
751 .debug_gnu_pubnames 0 : { *(.debug_gnu_pubnames) } \
752 .debug_gnu_pubtypes 0 : { *(.debug_gnu_pubtypes) } \
753 /* DWARF 4 */ \
754 .debug_types 0 : { *(.debug_types) } \
755 /* DWARF 5 */ \
Googler9398cc32022-12-02 17:21:52 +0800756 .debug_macro 0 : { *(.debug_macro) } \
Googlerb48fa912023-03-17 12:40:29 +0530757 .debug_addr 0 : { *(.debug_addr) }
Googleraf606d22022-10-26 21:40:12 -0700758
759 /* Stabs debugging sections. */
760#define STABS_DEBUG \
761 .stab 0 : { *(.stab) } \
762 .stabstr 0 : { *(.stabstr) } \
763 .stab.excl 0 : { *(.stab.excl) } \
764 .stab.exclstr 0 : { *(.stab.exclstr) } \
765 .stab.index 0 : { *(.stab.index) } \
766 .stab.indexstr 0 : { *(.stab.indexstr) } \
767 .comment 0 : { *(.comment) }
768
769#ifdef CONFIG_GENERIC_BUG
770#define BUG_TABLE \
771 . = ALIGN(8); \
772 __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800773 __start___bug_table = .; \
Googleraf606d22022-10-26 21:40:12 -0700774 KEEP(*(__bug_table)) \
Googler9398cc32022-12-02 17:21:52 +0800775 __stop___bug_table = .; \
Googleraf606d22022-10-26 21:40:12 -0700776 }
777#else
778#define BUG_TABLE
779#endif
780
Googler9398cc32022-12-02 17:21:52 +0800781#ifdef CONFIG_UNWINDER_ORC
782#define ORC_UNWIND_TABLE \
783 . = ALIGN(4); \
784 .orc_unwind_ip : AT(ADDR(.orc_unwind_ip) - LOAD_OFFSET) { \
785 __start_orc_unwind_ip = .; \
786 KEEP(*(.orc_unwind_ip)) \
787 __stop_orc_unwind_ip = .; \
788 } \
789 . = ALIGN(2); \
790 .orc_unwind : AT(ADDR(.orc_unwind) - LOAD_OFFSET) { \
791 __start_orc_unwind = .; \
792 KEEP(*(.orc_unwind)) \
793 __stop_orc_unwind = .; \
794 } \
795 . = ALIGN(4); \
796 .orc_lookup : AT(ADDR(.orc_lookup) - LOAD_OFFSET) { \
797 orc_lookup = .; \
798 . += (((SIZEOF(.text) + LOOKUP_BLOCK_SIZE - 1) / \
799 LOOKUP_BLOCK_SIZE) + 1) * 4; \
800 orc_lookup_end = .; \
801 }
802#else
803#define ORC_UNWIND_TABLE
804#endif
805
Googleraf606d22022-10-26 21:40:12 -0700806#ifdef CONFIG_PM_TRACE
807#define TRACEDATA \
808 . = ALIGN(4); \
809 .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800810 __tracedata_start = .; \
811 KEEP(*(.tracedata)) \
812 __tracedata_end = .; \
Googleraf606d22022-10-26 21:40:12 -0700813 }
814#else
815#define TRACEDATA
816#endif
817
818#define NOTES \
819 .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800820 __start_notes = .; \
821 KEEP(*(.note.*)) \
822 __stop_notes = .; \
Googleraf606d22022-10-26 21:40:12 -0700823 }
824
825#define INIT_SETUP(initsetup_align) \
826 . = ALIGN(initsetup_align); \
Googler9398cc32022-12-02 17:21:52 +0800827 __setup_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700828 KEEP(*(.init.setup)) \
Googler9398cc32022-12-02 17:21:52 +0800829 __setup_end = .;
Googleraf606d22022-10-26 21:40:12 -0700830
831#define INIT_CALLS_LEVEL(level) \
Googler9398cc32022-12-02 17:21:52 +0800832 __initcall##level##_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700833 KEEP(*(.initcall##level##.init)) \
834 KEEP(*(.initcall##level##s.init)) \
835
836#define INIT_CALLS \
Googler9398cc32022-12-02 17:21:52 +0800837 __initcall_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700838 KEEP(*(.initcallearly.init)) \
839 INIT_CALLS_LEVEL(0) \
840 INIT_CALLS_LEVEL(1) \
841 INIT_CALLS_LEVEL(2) \
842 INIT_CALLS_LEVEL(3) \
843 INIT_CALLS_LEVEL(4) \
844 INIT_CALLS_LEVEL(5) \
845 INIT_CALLS_LEVEL(rootfs) \
846 INIT_CALLS_LEVEL(6) \
847 INIT_CALLS_LEVEL(7) \
Googler9398cc32022-12-02 17:21:52 +0800848 __initcall_end = .;
Googleraf606d22022-10-26 21:40:12 -0700849
850#define CON_INITCALL \
Googler9398cc32022-12-02 17:21:52 +0800851 __con_initcall_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700852 KEEP(*(.con_initcall.init)) \
Googler9398cc32022-12-02 17:21:52 +0800853 __con_initcall_end = .;
Googleraf606d22022-10-26 21:40:12 -0700854
855#ifdef CONFIG_BLK_DEV_INITRD
856#define INIT_RAM_FS \
857 . = ALIGN(4); \
Googler9398cc32022-12-02 17:21:52 +0800858 __initramfs_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700859 KEEP(*(.init.ramfs)) \
860 . = ALIGN(8); \
861 KEEP(*(.init.ramfs.info))
862#else
863#define INIT_RAM_FS
864#endif
865
866/*
Googler9398cc32022-12-02 17:21:52 +0800867 * Memory encryption operates on a page basis. Since we need to clear
868 * the memory encryption mask for this section, it needs to be aligned
869 * on a page boundary and be a page-size multiple in length.
870 *
871 * Note: We use a separate section so that only this section gets
872 * decrypted to avoid exposing more than we wish.
873 */
874#ifdef CONFIG_AMD_MEM_ENCRYPT
875#define PERCPU_DECRYPTED_SECTION \
876 . = ALIGN(PAGE_SIZE); \
Googler9398cc32022-12-02 17:21:52 +0800877 *(.data..percpu..decrypted) \
878 . = ALIGN(PAGE_SIZE);
879#else
880#define PERCPU_DECRYPTED_SECTION
881#endif
882
883
884/*
Googleraf606d22022-10-26 21:40:12 -0700885 * Default discarded sections.
886 *
887 * Some archs want to discard exit text/data at runtime rather than
888 * link time due to cross-section references such as alt instructions,
889 * bug table, eh_frame, etc. DISCARDS must be the last of output
890 * section definitions so that such archs put those in earlier section
891 * definitions.
892 */
893#define DISCARDS \
894 /DISCARD/ : { \
895 EXIT_TEXT \
896 EXIT_DATA \
897 EXIT_CALL \
Googlerb48fa912023-03-17 12:40:29 +0530898 SYMTAB_DISCARD \
899 SYMTAB_DISCARD_GPL \
Googleraf606d22022-10-26 21:40:12 -0700900 *(.discard) \
901 *(.discard.*) \
Googler9398cc32022-12-02 17:21:52 +0800902 *(.modinfo) \
Googleraf606d22022-10-26 21:40:12 -0700903 }
904
905/**
906 * PERCPU_INPUT - the percpu input sections
907 * @cacheline: cacheline size
908 *
909 * The core percpu section names and core symbols which do not rely
910 * directly upon load addresses.
911 *
912 * @cacheline is used to align subsections to avoid false cacheline
913 * sharing between subsections for different purposes.
914 */
915#define PERCPU_INPUT(cacheline) \
Googler9398cc32022-12-02 17:21:52 +0800916 __per_cpu_start = .; \
Googleraf606d22022-10-26 21:40:12 -0700917 *(.data..percpu..first) \
918 . = ALIGN(PAGE_SIZE); \
919 *(.data..percpu..page_aligned) \
920 . = ALIGN(cacheline); \
921 *(.data..percpu..read_mostly) \
922 . = ALIGN(cacheline); \
923 *(.data..percpu) \
924 *(.data..percpu..shared_aligned) \
Googler9398cc32022-12-02 17:21:52 +0800925 PERCPU_DECRYPTED_SECTION \
926 __per_cpu_end = .;
Googleraf606d22022-10-26 21:40:12 -0700927
928/**
929 * PERCPU_VADDR - define output section for percpu area
930 * @cacheline: cacheline size
931 * @vaddr: explicit base address (optional)
932 * @phdr: destination PHDR (optional)
933 *
934 * Macro which expands to output section for percpu area.
935 *
936 * @cacheline is used to align subsections to avoid false cacheline
937 * sharing between subsections for different purposes.
938 *
939 * If @vaddr is not blank, it specifies explicit base address and all
940 * percpu symbols will be offset from the given address. If blank,
941 * @vaddr always equals @laddr + LOAD_OFFSET.
942 *
943 * @phdr defines the output PHDR to use if not blank. Be warned that
944 * output PHDR is sticky. If @phdr is specified, the next output
945 * section in the linker script will go there too. @phdr should have
946 * a leading colon.
947 *
948 * Note that this macros defines __per_cpu_load as an absolute symbol.
949 * If there is no need to put the percpu section at a predetermined
950 * address, use PERCPU_SECTION.
951 */
952#define PERCPU_VADDR(cacheline, vaddr, phdr) \
Googler9398cc32022-12-02 17:21:52 +0800953 __per_cpu_load = .; \
954 .data..percpu vaddr : AT(__per_cpu_load - LOAD_OFFSET) { \
Googleraf606d22022-10-26 21:40:12 -0700955 PERCPU_INPUT(cacheline) \
956 } phdr \
Googler9398cc32022-12-02 17:21:52 +0800957 . = __per_cpu_load + SIZEOF(.data..percpu);
Googleraf606d22022-10-26 21:40:12 -0700958
959/**
960 * PERCPU_SECTION - define output section for percpu area, simple version
961 * @cacheline: cacheline size
962 *
963 * Align to PAGE_SIZE and outputs output section for percpu area. This
964 * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and
965 * __per_cpu_start will be identical.
966 *
967 * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,)
968 * except that __per_cpu_load is defined as a relative symbol against
969 * .data..percpu which is required for relocatable x86_32 configuration.
970 */
971#define PERCPU_SECTION(cacheline) \
972 . = ALIGN(PAGE_SIZE); \
973 .data..percpu : AT(ADDR(.data..percpu) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +0800974 __per_cpu_load = .; \
Googleraf606d22022-10-26 21:40:12 -0700975 PERCPU_INPUT(cacheline) \
976 }
977
978
979/*
980 * Definition of the high level *_SECTION macros
981 * They will fit only a subset of the architectures
982 */
983
984
985/*
986 * Writeable data.
987 * All sections are combined in a single .data section.
988 * The sections following CONSTRUCTORS are arranged so their
989 * typical alignment matches.
990 * A cacheline is typical/always less than a PAGE_SIZE so
991 * the sections that has this restriction (or similar)
992 * is located before the ones requiring PAGE_SIZE alignment.
993 * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which
994 * matches the requirement of PAGE_ALIGNED_DATA.
995 *
996 * use 0 as page_align if page_aligned data is not used */
997#define RW_DATA_SECTION(cacheline, pagealigned, inittask) \
998 . = ALIGN(PAGE_SIZE); \
999 .data : AT(ADDR(.data) - LOAD_OFFSET) { \
1000 INIT_TASK_DATA(inittask) \
1001 NOSAVE_DATA \
1002 PAGE_ALIGNED_DATA(pagealigned) \
1003 CACHELINE_ALIGNED_DATA(cacheline) \
1004 READ_MOSTLY_DATA(cacheline) \
1005 DATA_DATA \
1006 CONSTRUCTORS \
Googler9398cc32022-12-02 17:21:52 +08001007 } \
1008 BUG_TABLE \
Googleraf606d22022-10-26 21:40:12 -07001009
1010#define INIT_TEXT_SECTION(inittext_align) \
1011 . = ALIGN(inittext_align); \
1012 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { \
Googler9398cc32022-12-02 17:21:52 +08001013 _sinittext = .; \
Googleraf606d22022-10-26 21:40:12 -07001014 INIT_TEXT \
Googler9398cc32022-12-02 17:21:52 +08001015 _einittext = .; \
Googleraf606d22022-10-26 21:40:12 -07001016 }
1017
1018#define INIT_DATA_SECTION(initsetup_align) \
1019 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \
1020 INIT_DATA \
1021 INIT_SETUP(initsetup_align) \
1022 INIT_CALLS \
1023 CON_INITCALL \
1024 INIT_RAM_FS \
1025 }
1026
1027#define BSS_SECTION(sbss_align, bss_align, stop_align) \
1028 . = ALIGN(sbss_align); \
Googler9398cc32022-12-02 17:21:52 +08001029 __bss_start = .; \
Googleraf606d22022-10-26 21:40:12 -07001030 SBSS(sbss_align) \
1031 BSS(bss_align) \
1032 . = ALIGN(stop_align); \
Googler9398cc32022-12-02 17:21:52 +08001033 __bss_stop = .;