Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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 = .; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 26 | * RO_DATA(PAGE_SIZE) |
| 27 | * RW_DATA(...) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 28 | * _edata = .; |
| 29 | * |
| 30 | * EXCEPTION_TABLE(...) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 31 | * |
| 32 | * BSS_SECTION(0, 0, 0) |
| 33 | * _end = .; |
| 34 | * |
| 35 | * STABS_DEBUG |
| 36 | * DWARF_DEBUG |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 37 | * ELF_DETAILS |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 57 | /* |
| 58 | * Only some architectures want to have the .notes segment visible in |
| 59 | * a separate PT_NOTE ELF Program Header. When this happens, it needs |
| 60 | * to be visible in both the kernel text's PT_LOAD and the PT_NOTE |
| 61 | * Program Headers. In this case, though, the PT_LOAD needs to be made |
| 62 | * the default again so that all the following sections don't also end |
| 63 | * up in the PT_NOTE Program Header. |
| 64 | */ |
| 65 | #ifdef EMITS_PT_NOTE |
| 66 | #define NOTES_HEADERS :text :note |
| 67 | #define NOTES_HEADERS_RESTORE __restore_ph : { *(.__restore_ph) } :text |
| 68 | #else |
| 69 | #define NOTES_HEADERS |
| 70 | #define NOTES_HEADERS_RESTORE |
| 71 | #endif |
| 72 | |
| 73 | /* |
| 74 | * Some architectures have non-executable read-only exception tables. |
| 75 | * They can be added to the RO_DATA segment by specifying their desired |
| 76 | * alignment. |
| 77 | */ |
| 78 | #ifdef RO_EXCEPTION_TABLE_ALIGN |
| 79 | #define RO_EXCEPTION_TABLE EXCEPTION_TABLE(RO_EXCEPTION_TABLE_ALIGN) |
| 80 | #else |
| 81 | #define RO_EXCEPTION_TABLE |
| 82 | #endif |
| 83 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 84 | /* Align . to a 8 byte boundary equals to maximum function alignment. */ |
| 85 | #define ALIGN_FUNCTION() . = ALIGN(8) |
| 86 | |
| 87 | /* |
| 88 | * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which |
| 89 | * generates .data.identifier sections, which need to be pulled in with |
| 90 | * .data. We don't want to pull in .data..other sections, which Linux |
| 91 | * has defined. Same for text and bss. |
| 92 | * |
| 93 | * RODATA_MAIN is not used because existing code already defines .rodata.x |
| 94 | * sections to be brought in with rodata. |
| 95 | */ |
| 96 | #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION |
| 97 | #define TEXT_MAIN .text .text.[0-9a-zA-Z_]* |
| 98 | #define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..LPBX* |
| 99 | #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]* |
| 100 | #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* |
| 101 | #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* |
| 102 | #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]* |
| 103 | #else |
| 104 | #define TEXT_MAIN .text |
| 105 | #define DATA_MAIN .data |
| 106 | #define SDATA_MAIN .sdata |
| 107 | #define RODATA_MAIN .rodata |
| 108 | #define BSS_MAIN .bss |
| 109 | #define SBSS_MAIN .sbss |
| 110 | #endif |
| 111 | |
| 112 | /* |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 113 | * GCC 4.5 and later have a 32 bytes section alignment for structures. |
| 114 | * Except GCC 4.9, that feels the need to align on 64 bytes. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 115 | */ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 116 | #if __GNUC__ == 4 && __GNUC_MINOR__ == 9 |
| 117 | #define STRUCT_ALIGNMENT 64 |
| 118 | #else |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 119 | #define STRUCT_ALIGNMENT 32 |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 120 | #endif |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 121 | #define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT) |
| 122 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 123 | /* |
| 124 | * The order of the sched class addresses are important, as they are |
| 125 | * used to determine the order of the priority of each sched class in |
| 126 | * relation to each other. |
| 127 | */ |
| 128 | #define SCHED_DATA \ |
| 129 | STRUCT_ALIGN(); \ |
| 130 | __begin_sched_classes = .; \ |
| 131 | *(__idle_sched_class) \ |
| 132 | *(__fair_sched_class) \ |
| 133 | *(__rt_sched_class) \ |
| 134 | *(__dl_sched_class) \ |
| 135 | *(__stop_sched_class) \ |
| 136 | __end_sched_classes = .; |
| 137 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 138 | /* The actual configuration determine if the init/exit sections |
| 139 | * are handled as text/data or they can be discarded (which |
| 140 | * often happens at runtime) |
| 141 | */ |
| 142 | #ifdef CONFIG_HOTPLUG_CPU |
| 143 | #define CPU_KEEP(sec) *(.cpu##sec) |
| 144 | #define CPU_DISCARD(sec) |
| 145 | #else |
| 146 | #define CPU_KEEP(sec) |
| 147 | #define CPU_DISCARD(sec) *(.cpu##sec) |
| 148 | #endif |
| 149 | |
| 150 | #if defined(CONFIG_MEMORY_HOTPLUG) |
| 151 | #define MEM_KEEP(sec) *(.mem##sec) |
| 152 | #define MEM_DISCARD(sec) |
| 153 | #else |
| 154 | #define MEM_KEEP(sec) |
| 155 | #define MEM_DISCARD(sec) *(.mem##sec) |
| 156 | #endif |
| 157 | |
| 158 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 159 | /* |
| 160 | * The ftrace call sites are logged to a section whose name depends on the |
| 161 | * compiler option used. A given kernel image will only use one, AKA |
| 162 | * FTRACE_CALLSITE_SECTION. We capture all of them here to avoid header |
| 163 | * dependencies for FTRACE_CALLSITE_SECTION's definition. |
| 164 | * |
| 165 | * Need to also make ftrace_stub_graph point to ftrace_stub |
| 166 | * so that the same stub location may have different protocols |
| 167 | * and not mess up with C verifiers. |
| 168 | */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 169 | #define MCOUNT_REC() . = ALIGN(8); \ |
| 170 | __start_mcount_loc = .; \ |
| 171 | KEEP(*(__mcount_loc)) \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 172 | KEEP(*(__patchable_function_entries)) \ |
| 173 | __stop_mcount_loc = .; \ |
| 174 | ftrace_stub_graph = ftrace_stub; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 175 | #else |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 176 | # ifdef CONFIG_FUNCTION_TRACER |
| 177 | # define MCOUNT_REC() ftrace_stub_graph = ftrace_stub; |
| 178 | # else |
| 179 | # define MCOUNT_REC() |
| 180 | # endif |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 181 | #endif |
| 182 | |
| 183 | #ifdef CONFIG_TRACE_BRANCH_PROFILING |
| 184 | #define LIKELY_PROFILE() __start_annotated_branch_profile = .; \ |
| 185 | KEEP(*(_ftrace_annotated_branch)) \ |
| 186 | __stop_annotated_branch_profile = .; |
| 187 | #else |
| 188 | #define LIKELY_PROFILE() |
| 189 | #endif |
| 190 | |
| 191 | #ifdef CONFIG_PROFILE_ALL_BRANCHES |
| 192 | #define BRANCH_PROFILE() __start_branch_profile = .; \ |
| 193 | KEEP(*(_ftrace_branch)) \ |
| 194 | __stop_branch_profile = .; |
| 195 | #else |
| 196 | #define BRANCH_PROFILE() |
| 197 | #endif |
| 198 | |
| 199 | #ifdef CONFIG_KPROBES |
| 200 | #define KPROBE_BLACKLIST() . = ALIGN(8); \ |
| 201 | __start_kprobe_blacklist = .; \ |
| 202 | KEEP(*(_kprobe_blacklist)) \ |
| 203 | __stop_kprobe_blacklist = .; |
| 204 | #else |
| 205 | #define KPROBE_BLACKLIST() |
| 206 | #endif |
| 207 | |
| 208 | #ifdef CONFIG_FUNCTION_ERROR_INJECTION |
| 209 | #define ERROR_INJECT_WHITELIST() STRUCT_ALIGN(); \ |
| 210 | __start_error_injection_whitelist = .; \ |
| 211 | KEEP(*(_error_injection_whitelist)) \ |
| 212 | __stop_error_injection_whitelist = .; |
| 213 | #else |
| 214 | #define ERROR_INJECT_WHITELIST() |
| 215 | #endif |
| 216 | |
| 217 | #ifdef CONFIG_EVENT_TRACING |
| 218 | #define FTRACE_EVENTS() . = ALIGN(8); \ |
| 219 | __start_ftrace_events = .; \ |
| 220 | KEEP(*(_ftrace_events)) \ |
| 221 | __stop_ftrace_events = .; \ |
| 222 | __start_ftrace_eval_maps = .; \ |
| 223 | KEEP(*(_ftrace_eval_map)) \ |
| 224 | __stop_ftrace_eval_maps = .; |
| 225 | #else |
| 226 | #define FTRACE_EVENTS() |
| 227 | #endif |
| 228 | |
| 229 | #ifdef CONFIG_TRACING |
| 230 | #define TRACE_PRINTKS() __start___trace_bprintk_fmt = .; \ |
| 231 | KEEP(*(__trace_printk_fmt)) /* Trace_printk fmt' pointer */ \ |
| 232 | __stop___trace_bprintk_fmt = .; |
| 233 | #define TRACEPOINT_STR() __start___tracepoint_str = .; \ |
| 234 | KEEP(*(__tracepoint_str)) /* Trace_printk fmt' pointer */ \ |
| 235 | __stop___tracepoint_str = .; |
| 236 | #else |
| 237 | #define TRACE_PRINTKS() |
| 238 | #define TRACEPOINT_STR() |
| 239 | #endif |
| 240 | |
| 241 | #ifdef CONFIG_FTRACE_SYSCALLS |
| 242 | #define TRACE_SYSCALLS() . = ALIGN(8); \ |
| 243 | __start_syscalls_metadata = .; \ |
| 244 | KEEP(*(__syscalls_metadata)) \ |
| 245 | __stop_syscalls_metadata = .; |
| 246 | #else |
| 247 | #define TRACE_SYSCALLS() |
| 248 | #endif |
| 249 | |
| 250 | #ifdef CONFIG_BPF_EVENTS |
| 251 | #define BPF_RAW_TP() STRUCT_ALIGN(); \ |
| 252 | __start__bpf_raw_tp = .; \ |
| 253 | KEEP(*(__bpf_raw_tp_map)) \ |
| 254 | __stop__bpf_raw_tp = .; |
| 255 | #else |
| 256 | #define BPF_RAW_TP() |
| 257 | #endif |
| 258 | |
| 259 | #ifdef CONFIG_SERIAL_EARLYCON |
| 260 | #define EARLYCON_TABLE() . = ALIGN(8); \ |
| 261 | __earlycon_table = .; \ |
| 262 | KEEP(*(__earlycon_table)) \ |
| 263 | __earlycon_table_end = .; |
| 264 | #else |
| 265 | #define EARLYCON_TABLE() |
| 266 | #endif |
| 267 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 268 | #ifdef CONFIG_SECURITY |
| 269 | #define LSM_TABLE() . = ALIGN(8); \ |
| 270 | __start_lsm_info = .; \ |
| 271 | KEEP(*(.lsm_info.init)) \ |
| 272 | __end_lsm_info = .; |
| 273 | #define EARLY_LSM_TABLE() . = ALIGN(8); \ |
| 274 | __start_early_lsm_info = .; \ |
| 275 | KEEP(*(.early_lsm_info.init)) \ |
| 276 | __end_early_lsm_info = .; |
| 277 | #else |
| 278 | #define LSM_TABLE() |
| 279 | #define EARLY_LSM_TABLE() |
| 280 | #endif |
| 281 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 282 | #define ___OF_TABLE(cfg, name) _OF_TABLE_##cfg(name) |
| 283 | #define __OF_TABLE(cfg, name) ___OF_TABLE(cfg, name) |
| 284 | #define OF_TABLE(cfg, name) __OF_TABLE(IS_ENABLED(cfg), name) |
| 285 | #define _OF_TABLE_0(name) |
| 286 | #define _OF_TABLE_1(name) \ |
| 287 | . = ALIGN(8); \ |
| 288 | __##name##_of_table = .; \ |
| 289 | KEEP(*(__##name##_of_table)) \ |
| 290 | KEEP(*(__##name##_of_table_end)) |
| 291 | |
| 292 | #define TIMER_OF_TABLES() OF_TABLE(CONFIG_TIMER_OF, timer) |
| 293 | #define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip) |
| 294 | #define CLK_OF_TABLES() OF_TABLE(CONFIG_COMMON_CLK, clk) |
| 295 | #define RESERVEDMEM_OF_TABLES() OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem) |
| 296 | #define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method) |
| 297 | #define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method) |
| 298 | |
| 299 | #ifdef CONFIG_ACPI |
| 300 | #define ACPI_PROBE_TABLE(name) \ |
| 301 | . = ALIGN(8); \ |
| 302 | __##name##_acpi_probe_table = .; \ |
| 303 | KEEP(*(__##name##_acpi_probe_table)) \ |
| 304 | __##name##_acpi_probe_table_end = .; |
| 305 | #else |
| 306 | #define ACPI_PROBE_TABLE(name) |
| 307 | #endif |
| 308 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 309 | #ifdef CONFIG_THERMAL |
| 310 | #define THERMAL_TABLE(name) \ |
| 311 | . = ALIGN(8); \ |
| 312 | __##name##_thermal_table = .; \ |
| 313 | KEEP(*(__##name##_thermal_table)) \ |
| 314 | __##name##_thermal_table_end = .; |
| 315 | #else |
| 316 | #define THERMAL_TABLE(name) |
| 317 | #endif |
| 318 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 319 | #define KERNEL_DTB() \ |
| 320 | STRUCT_ALIGN(); \ |
| 321 | __dtb_start = .; \ |
| 322 | KEEP(*(.dtb.init.rodata)) \ |
| 323 | __dtb_end = .; |
| 324 | |
| 325 | /* |
| 326 | * .data section |
| 327 | */ |
| 328 | #define DATA_DATA \ |
| 329 | *(.xiptext) \ |
| 330 | *(DATA_MAIN) \ |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 331 | *(.data..decrypted) \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 332 | *(.ref.data) \ |
| 333 | *(.data..shared_aligned) /* percpu related */ \ |
| 334 | MEM_KEEP(init.data*) \ |
| 335 | MEM_KEEP(exit.data*) \ |
| 336 | *(.data.unlikely) \ |
| 337 | __start_once = .; \ |
| 338 | *(.data.once) \ |
| 339 | __end_once = .; \ |
| 340 | STRUCT_ALIGN(); \ |
| 341 | *(__tracepoints) \ |
| 342 | /* implement dynamic printk debug */ \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 343 | . = ALIGN(8); \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 344 | __start___dyndbg = .; \ |
| 345 | KEEP(*(__dyndbg)) \ |
| 346 | __stop___dyndbg = .; \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 347 | LIKELY_PROFILE() \ |
| 348 | BRANCH_PROFILE() \ |
| 349 | TRACE_PRINTKS() \ |
| 350 | BPF_RAW_TP() \ |
| 351 | TRACEPOINT_STR() |
| 352 | |
| 353 | /* |
| 354 | * Data section helpers |
| 355 | */ |
| 356 | #define NOSAVE_DATA \ |
| 357 | . = ALIGN(PAGE_SIZE); \ |
| 358 | __nosave_begin = .; \ |
| 359 | *(.data..nosave) \ |
| 360 | . = ALIGN(PAGE_SIZE); \ |
| 361 | __nosave_end = .; |
| 362 | |
| 363 | #define PAGE_ALIGNED_DATA(page_align) \ |
| 364 | . = ALIGN(page_align); \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 365 | *(.data..page_aligned) \ |
| 366 | . = ALIGN(page_align); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 367 | |
| 368 | #define READ_MOSTLY_DATA(align) \ |
| 369 | . = ALIGN(align); \ |
| 370 | *(.data..read_mostly) \ |
| 371 | . = ALIGN(align); |
| 372 | |
| 373 | #define CACHELINE_ALIGNED_DATA(align) \ |
| 374 | . = ALIGN(align); \ |
| 375 | *(.data..cacheline_aligned) |
| 376 | |
| 377 | #define INIT_TASK_DATA(align) \ |
| 378 | . = ALIGN(align); \ |
| 379 | __start_init_task = .; \ |
| 380 | init_thread_union = .; \ |
| 381 | init_stack = .; \ |
| 382 | KEEP(*(.data..init_task)) \ |
| 383 | KEEP(*(.data..init_thread_info)) \ |
| 384 | . = __start_init_task + THREAD_SIZE; \ |
| 385 | __end_init_task = .; |
| 386 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 387 | #define JUMP_TABLE_DATA \ |
| 388 | . = ALIGN(8); \ |
| 389 | __start___jump_table = .; \ |
| 390 | KEEP(*(__jump_table)) \ |
| 391 | __stop___jump_table = .; |
| 392 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 393 | #define STATIC_CALL_DATA \ |
| 394 | . = ALIGN(8); \ |
| 395 | __start_static_call_sites = .; \ |
| 396 | KEEP(*(.static_call_sites)) \ |
| 397 | __stop_static_call_sites = .; \ |
| 398 | __start_static_call_tramp_key = .; \ |
| 399 | KEEP(*(.static_call_tramp_key)) \ |
| 400 | __stop_static_call_tramp_key = .; |
| 401 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 402 | /* |
| 403 | * Allow architectures to handle ro_after_init data on their |
| 404 | * own by defining an empty RO_AFTER_INIT_DATA. |
| 405 | */ |
| 406 | #ifndef RO_AFTER_INIT_DATA |
| 407 | #define RO_AFTER_INIT_DATA \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 408 | . = ALIGN(8); \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 409 | __start_ro_after_init = .; \ |
| 410 | *(.data..ro_after_init) \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 411 | JUMP_TABLE_DATA \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 412 | STATIC_CALL_DATA \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 413 | __end_ro_after_init = .; |
| 414 | #endif |
| 415 | |
| 416 | /* |
| 417 | * Read only Data |
| 418 | */ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 419 | #define RO_DATA(align) \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 420 | . = ALIGN((align)); \ |
| 421 | .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ |
| 422 | __start_rodata = .; \ |
| 423 | *(.rodata) *(.rodata.*) \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 424 | SCHED_DATA \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 425 | RO_AFTER_INIT_DATA /* Read only after init */ \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 426 | . = ALIGN(8); \ |
| 427 | __start___tracepoints_ptrs = .; \ |
| 428 | KEEP(*(__tracepoints_ptrs)) /* Tracepoints: pointer array */ \ |
| 429 | __stop___tracepoints_ptrs = .; \ |
| 430 | *(__tracepoints_strings)/* Tracepoints: strings */ \ |
| 431 | } \ |
| 432 | \ |
| 433 | .rodata1 : AT(ADDR(.rodata1) - LOAD_OFFSET) { \ |
| 434 | *(.rodata1) \ |
| 435 | } \ |
| 436 | \ |
| 437 | /* PCI quirks */ \ |
| 438 | .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \ |
| 439 | __start_pci_fixups_early = .; \ |
| 440 | KEEP(*(.pci_fixup_early)) \ |
| 441 | __end_pci_fixups_early = .; \ |
| 442 | __start_pci_fixups_header = .; \ |
| 443 | KEEP(*(.pci_fixup_header)) \ |
| 444 | __end_pci_fixups_header = .; \ |
| 445 | __start_pci_fixups_final = .; \ |
| 446 | KEEP(*(.pci_fixup_final)) \ |
| 447 | __end_pci_fixups_final = .; \ |
| 448 | __start_pci_fixups_enable = .; \ |
| 449 | KEEP(*(.pci_fixup_enable)) \ |
| 450 | __end_pci_fixups_enable = .; \ |
| 451 | __start_pci_fixups_resume = .; \ |
| 452 | KEEP(*(.pci_fixup_resume)) \ |
| 453 | __end_pci_fixups_resume = .; \ |
| 454 | __start_pci_fixups_resume_early = .; \ |
| 455 | KEEP(*(.pci_fixup_resume_early)) \ |
| 456 | __end_pci_fixups_resume_early = .; \ |
| 457 | __start_pci_fixups_suspend = .; \ |
| 458 | KEEP(*(.pci_fixup_suspend)) \ |
| 459 | __end_pci_fixups_suspend = .; \ |
| 460 | __start_pci_fixups_suspend_late = .; \ |
| 461 | KEEP(*(.pci_fixup_suspend_late)) \ |
| 462 | __end_pci_fixups_suspend_late = .; \ |
| 463 | } \ |
| 464 | \ |
| 465 | /* Built-in firmware blobs */ \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 466 | .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) ALIGN(8) { \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 467 | __start_builtin_fw = .; \ |
| 468 | KEEP(*(.builtin_fw)) \ |
| 469 | __end_builtin_fw = .; \ |
| 470 | } \ |
| 471 | \ |
| 472 | TRACEDATA \ |
| 473 | \ |
| 474 | /* Kernel symbol table: Normal symbols */ \ |
| 475 | __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \ |
| 476 | __start___ksymtab = .; \ |
| 477 | KEEP(*(SORT(___ksymtab+*))) \ |
| 478 | __stop___ksymtab = .; \ |
| 479 | } \ |
| 480 | \ |
| 481 | /* Kernel symbol table: GPL-only symbols */ \ |
| 482 | __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \ |
| 483 | __start___ksymtab_gpl = .; \ |
| 484 | KEEP(*(SORT(___ksymtab_gpl+*))) \ |
| 485 | __stop___ksymtab_gpl = .; \ |
| 486 | } \ |
| 487 | \ |
| 488 | /* Kernel symbol table: Normal unused symbols */ \ |
| 489 | __ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \ |
| 490 | __start___ksymtab_unused = .; \ |
| 491 | KEEP(*(SORT(___ksymtab_unused+*))) \ |
| 492 | __stop___ksymtab_unused = .; \ |
| 493 | } \ |
| 494 | \ |
| 495 | /* Kernel symbol table: GPL-only unused symbols */ \ |
| 496 | __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \ |
| 497 | __start___ksymtab_unused_gpl = .; \ |
| 498 | KEEP(*(SORT(___ksymtab_unused_gpl+*))) \ |
| 499 | __stop___ksymtab_unused_gpl = .; \ |
| 500 | } \ |
| 501 | \ |
| 502 | /* Kernel symbol table: GPL-future-only symbols */ \ |
| 503 | __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \ |
| 504 | __start___ksymtab_gpl_future = .; \ |
| 505 | KEEP(*(SORT(___ksymtab_gpl_future+*))) \ |
| 506 | __stop___ksymtab_gpl_future = .; \ |
| 507 | } \ |
| 508 | \ |
| 509 | /* Kernel symbol table: Normal symbols */ \ |
| 510 | __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \ |
| 511 | __start___kcrctab = .; \ |
| 512 | KEEP(*(SORT(___kcrctab+*))) \ |
| 513 | __stop___kcrctab = .; \ |
| 514 | } \ |
| 515 | \ |
| 516 | /* Kernel symbol table: GPL-only symbols */ \ |
| 517 | __kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \ |
| 518 | __start___kcrctab_gpl = .; \ |
| 519 | KEEP(*(SORT(___kcrctab_gpl+*))) \ |
| 520 | __stop___kcrctab_gpl = .; \ |
| 521 | } \ |
| 522 | \ |
| 523 | /* Kernel symbol table: Normal unused symbols */ \ |
| 524 | __kcrctab_unused : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) { \ |
| 525 | __start___kcrctab_unused = .; \ |
| 526 | KEEP(*(SORT(___kcrctab_unused+*))) \ |
| 527 | __stop___kcrctab_unused = .; \ |
| 528 | } \ |
| 529 | \ |
| 530 | /* Kernel symbol table: GPL-only unused symbols */ \ |
| 531 | __kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \ |
| 532 | __start___kcrctab_unused_gpl = .; \ |
| 533 | KEEP(*(SORT(___kcrctab_unused_gpl+*))) \ |
| 534 | __stop___kcrctab_unused_gpl = .; \ |
| 535 | } \ |
| 536 | \ |
| 537 | /* Kernel symbol table: GPL-future-only symbols */ \ |
| 538 | __kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \ |
| 539 | __start___kcrctab_gpl_future = .; \ |
| 540 | KEEP(*(SORT(___kcrctab_gpl_future+*))) \ |
| 541 | __stop___kcrctab_gpl_future = .; \ |
| 542 | } \ |
| 543 | \ |
| 544 | /* Kernel symbol table: strings */ \ |
| 545 | __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \ |
| 546 | *(__ksymtab_strings) \ |
| 547 | } \ |
| 548 | \ |
| 549 | /* __*init sections */ \ |
| 550 | __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \ |
| 551 | *(.ref.rodata) \ |
| 552 | MEM_KEEP(init.rodata) \ |
| 553 | MEM_KEEP(exit.rodata) \ |
| 554 | } \ |
| 555 | \ |
| 556 | /* Built-in module parameters. */ \ |
| 557 | __param : AT(ADDR(__param) - LOAD_OFFSET) { \ |
| 558 | __start___param = .; \ |
| 559 | KEEP(*(__param)) \ |
| 560 | __stop___param = .; \ |
| 561 | } \ |
| 562 | \ |
| 563 | /* Built-in module versions. */ \ |
| 564 | __modver : AT(ADDR(__modver) - LOAD_OFFSET) { \ |
| 565 | __start___modver = .; \ |
| 566 | KEEP(*(__modver)) \ |
| 567 | __stop___modver = .; \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 568 | } \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 569 | \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 570 | RO_EXCEPTION_TABLE \ |
| 571 | NOTES \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 572 | BTF \ |
| 573 | \ |
| 574 | . = ALIGN((align)); \ |
| 575 | __end_rodata = .; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 576 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 577 | /* |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 578 | * Non-instrumentable text section |
| 579 | */ |
| 580 | #define NOINSTR_TEXT \ |
| 581 | ALIGN_FUNCTION(); \ |
| 582 | __noinstr_text_start = .; \ |
| 583 | *(.noinstr.text) \ |
| 584 | __noinstr_text_end = .; |
| 585 | |
| 586 | /* |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 587 | * .text section. Map to function alignment to avoid address changes |
| 588 | * during second ld run in second ld pass when generating System.map |
| 589 | * |
| 590 | * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead |
| 591 | * code elimination is enabled, so these sections should be converted |
| 592 | * to use ".." first. |
| 593 | */ |
| 594 | #define TEXT_TEXT \ |
| 595 | ALIGN_FUNCTION(); \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 596 | *(.text.hot .text.hot.*) \ |
| 597 | *(TEXT_MAIN .text.fixup) \ |
| 598 | *(.text.unlikely .text.unlikely.*) \ |
| 599 | *(.text.unknown .text.unknown.*) \ |
| 600 | NOINSTR_TEXT \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 601 | *(.text..refcount) \ |
| 602 | *(.ref.text) \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 603 | *(.text.asan.* .text.tsan.*) \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 604 | MEM_KEEP(init.text*) \ |
| 605 | MEM_KEEP(exit.text*) \ |
| 606 | |
| 607 | |
| 608 | /* sched.text is aling to function alignment to secure we have same |
| 609 | * address even at second ld pass when generating System.map */ |
| 610 | #define SCHED_TEXT \ |
| 611 | ALIGN_FUNCTION(); \ |
| 612 | __sched_text_start = .; \ |
| 613 | *(.sched.text) \ |
| 614 | __sched_text_end = .; |
| 615 | |
| 616 | /* spinlock.text is aling to function alignment to secure we have same |
| 617 | * address even at second ld pass when generating System.map */ |
| 618 | #define LOCK_TEXT \ |
| 619 | ALIGN_FUNCTION(); \ |
| 620 | __lock_text_start = .; \ |
| 621 | *(.spinlock.text) \ |
| 622 | __lock_text_end = .; |
| 623 | |
| 624 | #define CPUIDLE_TEXT \ |
| 625 | ALIGN_FUNCTION(); \ |
| 626 | __cpuidle_text_start = .; \ |
| 627 | *(.cpuidle.text) \ |
| 628 | __cpuidle_text_end = .; |
| 629 | |
| 630 | #define KPROBES_TEXT \ |
| 631 | ALIGN_FUNCTION(); \ |
| 632 | __kprobes_text_start = .; \ |
| 633 | *(.kprobes.text) \ |
| 634 | __kprobes_text_end = .; |
| 635 | |
| 636 | #define ENTRY_TEXT \ |
| 637 | ALIGN_FUNCTION(); \ |
| 638 | __entry_text_start = .; \ |
| 639 | *(.entry.text) \ |
| 640 | __entry_text_end = .; |
| 641 | |
| 642 | #define IRQENTRY_TEXT \ |
| 643 | ALIGN_FUNCTION(); \ |
| 644 | __irqentry_text_start = .; \ |
| 645 | *(.irqentry.text) \ |
| 646 | __irqentry_text_end = .; |
| 647 | |
| 648 | #define SOFTIRQENTRY_TEXT \ |
| 649 | ALIGN_FUNCTION(); \ |
| 650 | __softirqentry_text_start = .; \ |
| 651 | *(.softirqentry.text) \ |
| 652 | __softirqentry_text_end = .; |
| 653 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 654 | #define STATIC_CALL_TEXT \ |
| 655 | ALIGN_FUNCTION(); \ |
| 656 | __static_call_text_start = .; \ |
| 657 | *(.static_call.text) \ |
| 658 | __static_call_text_end = .; |
| 659 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 660 | /* Section used for early init (in .S files) */ |
| 661 | #define HEAD_TEXT KEEP(*(.head.text)) |
| 662 | |
| 663 | #define HEAD_TEXT_SECTION \ |
| 664 | .head.text : AT(ADDR(.head.text) - LOAD_OFFSET) { \ |
| 665 | HEAD_TEXT \ |
| 666 | } |
| 667 | |
| 668 | /* |
| 669 | * Exception table |
| 670 | */ |
| 671 | #define EXCEPTION_TABLE(align) \ |
| 672 | . = ALIGN(align); \ |
| 673 | __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \ |
| 674 | __start___ex_table = .; \ |
| 675 | KEEP(*(__ex_table)) \ |
| 676 | __stop___ex_table = .; \ |
| 677 | } |
| 678 | |
| 679 | /* |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 680 | * .BTF |
| 681 | */ |
| 682 | #ifdef CONFIG_DEBUG_INFO_BTF |
| 683 | #define BTF \ |
| 684 | .BTF : AT(ADDR(.BTF) - LOAD_OFFSET) { \ |
| 685 | __start_BTF = .; \ |
| 686 | KEEP(*(.BTF)) \ |
| 687 | __stop_BTF = .; \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 688 | } \ |
| 689 | . = ALIGN(4); \ |
| 690 | .BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) { \ |
| 691 | *(.BTF_ids) \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 692 | } |
| 693 | #else |
| 694 | #define BTF |
| 695 | #endif |
| 696 | |
| 697 | /* |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 698 | * Init task |
| 699 | */ |
| 700 | #define INIT_TASK_DATA_SECTION(align) \ |
| 701 | . = ALIGN(align); \ |
| 702 | .data..init_task : AT(ADDR(.data..init_task) - LOAD_OFFSET) { \ |
| 703 | INIT_TASK_DATA(align) \ |
| 704 | } |
| 705 | |
| 706 | #ifdef CONFIG_CONSTRUCTORS |
| 707 | #define KERNEL_CTORS() . = ALIGN(8); \ |
| 708 | __ctors_start = .; \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 709 | KEEP(*(SORT(.ctors.*))) \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 710 | KEEP(*(.ctors)) \ |
| 711 | KEEP(*(SORT(.init_array.*))) \ |
| 712 | KEEP(*(.init_array)) \ |
| 713 | __ctors_end = .; |
| 714 | #else |
| 715 | #define KERNEL_CTORS() |
| 716 | #endif |
| 717 | |
| 718 | /* init and exit section handling */ |
| 719 | #define INIT_DATA \ |
| 720 | KEEP(*(SORT(___kentry+*))) \ |
| 721 | *(.init.data init.data.*) \ |
| 722 | MEM_DISCARD(init.data*) \ |
| 723 | KERNEL_CTORS() \ |
| 724 | MCOUNT_REC() \ |
| 725 | *(.init.rodata .init.rodata.*) \ |
| 726 | FTRACE_EVENTS() \ |
| 727 | TRACE_SYSCALLS() \ |
| 728 | KPROBE_BLACKLIST() \ |
| 729 | ERROR_INJECT_WHITELIST() \ |
| 730 | MEM_DISCARD(init.rodata) \ |
| 731 | CLK_OF_TABLES() \ |
| 732 | RESERVEDMEM_OF_TABLES() \ |
| 733 | TIMER_OF_TABLES() \ |
| 734 | CPU_METHOD_OF_TABLES() \ |
| 735 | CPUIDLE_METHOD_OF_TABLES() \ |
| 736 | KERNEL_DTB() \ |
| 737 | IRQCHIP_OF_MATCH_TABLE() \ |
| 738 | ACPI_PROBE_TABLE(irqchip) \ |
| 739 | ACPI_PROBE_TABLE(timer) \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 740 | THERMAL_TABLE(governor) \ |
| 741 | EARLYCON_TABLE() \ |
| 742 | LSM_TABLE() \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 743 | EARLY_LSM_TABLE() \ |
| 744 | KUNIT_TABLE() |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 745 | |
| 746 | #define INIT_TEXT \ |
| 747 | *(.init.text .init.text.*) \ |
| 748 | *(.text.startup) \ |
| 749 | MEM_DISCARD(init.text*) |
| 750 | |
| 751 | #define EXIT_DATA \ |
| 752 | *(.exit.data .exit.data.*) \ |
| 753 | *(.fini_array .fini_array.*) \ |
| 754 | *(.dtors .dtors.*) \ |
| 755 | MEM_DISCARD(exit.data*) \ |
| 756 | MEM_DISCARD(exit.rodata*) |
| 757 | |
| 758 | #define EXIT_TEXT \ |
| 759 | *(.exit.text) \ |
| 760 | *(.text.exit) \ |
| 761 | MEM_DISCARD(exit.text) |
| 762 | |
| 763 | #define EXIT_CALL \ |
| 764 | *(.exitcall.exit) |
| 765 | |
| 766 | /* |
| 767 | * bss (Block Started by Symbol) - uninitialized data |
| 768 | * zeroed during startup |
| 769 | */ |
| 770 | #define SBSS(sbss_align) \ |
| 771 | . = ALIGN(sbss_align); \ |
| 772 | .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) { \ |
| 773 | *(.dynsbss) \ |
| 774 | *(SBSS_MAIN) \ |
| 775 | *(.scommon) \ |
| 776 | } |
| 777 | |
| 778 | /* |
| 779 | * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra |
| 780 | * sections to the front of bss. |
| 781 | */ |
| 782 | #ifndef BSS_FIRST_SECTIONS |
| 783 | #define BSS_FIRST_SECTIONS |
| 784 | #endif |
| 785 | |
| 786 | #define BSS(bss_align) \ |
| 787 | . = ALIGN(bss_align); \ |
| 788 | .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \ |
| 789 | BSS_FIRST_SECTIONS \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 790 | . = ALIGN(PAGE_SIZE); \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 791 | *(.bss..page_aligned) \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 792 | . = ALIGN(PAGE_SIZE); \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 793 | *(.dynbss) \ |
| 794 | *(BSS_MAIN) \ |
| 795 | *(COMMON) \ |
| 796 | } |
| 797 | |
| 798 | /* |
| 799 | * DWARF debug sections. |
| 800 | * Symbols in the DWARF debugging sections are relative to |
| 801 | * the beginning of the section so we begin them at 0. |
| 802 | */ |
| 803 | #define DWARF_DEBUG \ |
| 804 | /* DWARF 1 */ \ |
| 805 | .debug 0 : { *(.debug) } \ |
| 806 | .line 0 : { *(.line) } \ |
| 807 | /* GNU DWARF 1 extensions */ \ |
| 808 | .debug_srcinfo 0 : { *(.debug_srcinfo) } \ |
| 809 | .debug_sfnames 0 : { *(.debug_sfnames) } \ |
| 810 | /* DWARF 1.1 and DWARF 2 */ \ |
| 811 | .debug_aranges 0 : { *(.debug_aranges) } \ |
| 812 | .debug_pubnames 0 : { *(.debug_pubnames) } \ |
| 813 | /* DWARF 2 */ \ |
| 814 | .debug_info 0 : { *(.debug_info \ |
| 815 | .gnu.linkonce.wi.*) } \ |
| 816 | .debug_abbrev 0 : { *(.debug_abbrev) } \ |
| 817 | .debug_line 0 : { *(.debug_line) } \ |
| 818 | .debug_frame 0 : { *(.debug_frame) } \ |
| 819 | .debug_str 0 : { *(.debug_str) } \ |
| 820 | .debug_loc 0 : { *(.debug_loc) } \ |
| 821 | .debug_macinfo 0 : { *(.debug_macinfo) } \ |
| 822 | .debug_pubtypes 0 : { *(.debug_pubtypes) } \ |
| 823 | /* DWARF 3 */ \ |
| 824 | .debug_ranges 0 : { *(.debug_ranges) } \ |
| 825 | /* SGI/MIPS DWARF 2 extensions */ \ |
| 826 | .debug_weaknames 0 : { *(.debug_weaknames) } \ |
| 827 | .debug_funcnames 0 : { *(.debug_funcnames) } \ |
| 828 | .debug_typenames 0 : { *(.debug_typenames) } \ |
| 829 | .debug_varnames 0 : { *(.debug_varnames) } \ |
| 830 | /* GNU DWARF 2 extensions */ \ |
| 831 | .debug_gnu_pubnames 0 : { *(.debug_gnu_pubnames) } \ |
| 832 | .debug_gnu_pubtypes 0 : { *(.debug_gnu_pubtypes) } \ |
| 833 | /* DWARF 4 */ \ |
| 834 | .debug_types 0 : { *(.debug_types) } \ |
| 835 | /* DWARF 5 */ \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 836 | .debug_addr 0 : { *(.debug_addr) } \ |
| 837 | .debug_line_str 0 : { *(.debug_line_str) } \ |
| 838 | .debug_loclists 0 : { *(.debug_loclists) } \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 839 | .debug_macro 0 : { *(.debug_macro) } \ |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 840 | .debug_names 0 : { *(.debug_names) } \ |
| 841 | .debug_rnglists 0 : { *(.debug_rnglists) } \ |
| 842 | .debug_str_offsets 0 : { *(.debug_str_offsets) } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 843 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 844 | /* Stabs debugging sections. */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 845 | #define STABS_DEBUG \ |
| 846 | .stab 0 : { *(.stab) } \ |
| 847 | .stabstr 0 : { *(.stabstr) } \ |
| 848 | .stab.excl 0 : { *(.stab.excl) } \ |
| 849 | .stab.exclstr 0 : { *(.stab.exclstr) } \ |
| 850 | .stab.index 0 : { *(.stab.index) } \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 851 | .stab.indexstr 0 : { *(.stab.indexstr) } |
| 852 | |
| 853 | /* Required sections not related to debugging. */ |
| 854 | #define ELF_DETAILS \ |
| 855 | .comment 0 : { *(.comment) } \ |
| 856 | .symtab 0 : { *(.symtab) } \ |
| 857 | .strtab 0 : { *(.strtab) } \ |
| 858 | .shstrtab 0 : { *(.shstrtab) } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 859 | |
| 860 | #ifdef CONFIG_GENERIC_BUG |
| 861 | #define BUG_TABLE \ |
| 862 | . = ALIGN(8); \ |
| 863 | __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) { \ |
| 864 | __start___bug_table = .; \ |
| 865 | KEEP(*(__bug_table)) \ |
| 866 | __stop___bug_table = .; \ |
| 867 | } |
| 868 | #else |
| 869 | #define BUG_TABLE |
| 870 | #endif |
| 871 | |
| 872 | #ifdef CONFIG_UNWINDER_ORC |
| 873 | #define ORC_UNWIND_TABLE \ |
| 874 | . = ALIGN(4); \ |
| 875 | .orc_unwind_ip : AT(ADDR(.orc_unwind_ip) - LOAD_OFFSET) { \ |
| 876 | __start_orc_unwind_ip = .; \ |
| 877 | KEEP(*(.orc_unwind_ip)) \ |
| 878 | __stop_orc_unwind_ip = .; \ |
| 879 | } \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 880 | . = ALIGN(2); \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 881 | .orc_unwind : AT(ADDR(.orc_unwind) - LOAD_OFFSET) { \ |
| 882 | __start_orc_unwind = .; \ |
| 883 | KEEP(*(.orc_unwind)) \ |
| 884 | __stop_orc_unwind = .; \ |
| 885 | } \ |
| 886 | . = ALIGN(4); \ |
| 887 | .orc_lookup : AT(ADDR(.orc_lookup) - LOAD_OFFSET) { \ |
| 888 | orc_lookup = .; \ |
| 889 | . += (((SIZEOF(.text) + LOOKUP_BLOCK_SIZE - 1) / \ |
| 890 | LOOKUP_BLOCK_SIZE) + 1) * 4; \ |
| 891 | orc_lookup_end = .; \ |
| 892 | } |
| 893 | #else |
| 894 | #define ORC_UNWIND_TABLE |
| 895 | #endif |
| 896 | |
| 897 | #ifdef CONFIG_PM_TRACE |
| 898 | #define TRACEDATA \ |
| 899 | . = ALIGN(4); \ |
| 900 | .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) { \ |
| 901 | __tracedata_start = .; \ |
| 902 | KEEP(*(.tracedata)) \ |
| 903 | __tracedata_end = .; \ |
| 904 | } |
| 905 | #else |
| 906 | #define TRACEDATA |
| 907 | #endif |
| 908 | |
| 909 | #define NOTES \ |
| 910 | .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \ |
| 911 | __start_notes = .; \ |
| 912 | KEEP(*(.note.*)) \ |
| 913 | __stop_notes = .; \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 914 | } NOTES_HEADERS \ |
| 915 | NOTES_HEADERS_RESTORE |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 916 | |
| 917 | #define INIT_SETUP(initsetup_align) \ |
| 918 | . = ALIGN(initsetup_align); \ |
| 919 | __setup_start = .; \ |
| 920 | KEEP(*(.init.setup)) \ |
| 921 | __setup_end = .; |
| 922 | |
| 923 | #define INIT_CALLS_LEVEL(level) \ |
| 924 | __initcall##level##_start = .; \ |
| 925 | KEEP(*(.initcall##level##.init)) \ |
| 926 | KEEP(*(.initcall##level##s.init)) \ |
| 927 | |
| 928 | #define INIT_CALLS \ |
| 929 | __initcall_start = .; \ |
| 930 | KEEP(*(.initcallearly.init)) \ |
| 931 | INIT_CALLS_LEVEL(0) \ |
| 932 | INIT_CALLS_LEVEL(1) \ |
| 933 | INIT_CALLS_LEVEL(2) \ |
| 934 | INIT_CALLS_LEVEL(3) \ |
| 935 | INIT_CALLS_LEVEL(4) \ |
| 936 | INIT_CALLS_LEVEL(5) \ |
| 937 | INIT_CALLS_LEVEL(rootfs) \ |
| 938 | INIT_CALLS_LEVEL(6) \ |
| 939 | INIT_CALLS_LEVEL(7) \ |
| 940 | __initcall_end = .; |
| 941 | |
| 942 | #define CON_INITCALL \ |
| 943 | __con_initcall_start = .; \ |
| 944 | KEEP(*(.con_initcall.init)) \ |
| 945 | __con_initcall_end = .; |
| 946 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 947 | /* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */ |
| 948 | #define KUNIT_TABLE() \ |
| 949 | . = ALIGN(8); \ |
| 950 | __kunit_suites_start = .; \ |
| 951 | KEEP(*(.kunit_test_suites)) \ |
| 952 | __kunit_suites_end = .; |
| 953 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 954 | #ifdef CONFIG_BLK_DEV_INITRD |
| 955 | #define INIT_RAM_FS \ |
| 956 | . = ALIGN(4); \ |
| 957 | __initramfs_start = .; \ |
| 958 | KEEP(*(.init.ramfs)) \ |
| 959 | . = ALIGN(8); \ |
| 960 | KEEP(*(.init.ramfs.info)) |
| 961 | #else |
| 962 | #define INIT_RAM_FS |
| 963 | #endif |
| 964 | |
| 965 | /* |
| 966 | * Memory encryption operates on a page basis. Since we need to clear |
| 967 | * the memory encryption mask for this section, it needs to be aligned |
| 968 | * on a page boundary and be a page-size multiple in length. |
| 969 | * |
| 970 | * Note: We use a separate section so that only this section gets |
| 971 | * decrypted to avoid exposing more than we wish. |
| 972 | */ |
| 973 | #ifdef CONFIG_AMD_MEM_ENCRYPT |
| 974 | #define PERCPU_DECRYPTED_SECTION \ |
| 975 | . = ALIGN(PAGE_SIZE); \ |
| 976 | *(.data..percpu..decrypted) \ |
| 977 | . = ALIGN(PAGE_SIZE); |
| 978 | #else |
| 979 | #define PERCPU_DECRYPTED_SECTION |
| 980 | #endif |
| 981 | |
| 982 | |
| 983 | /* |
| 984 | * Default discarded sections. |
| 985 | * |
| 986 | * Some archs want to discard exit text/data at runtime rather than |
| 987 | * link time due to cross-section references such as alt instructions, |
| 988 | * bug table, eh_frame, etc. DISCARDS must be the last of output |
| 989 | * section definitions so that such archs put those in earlier section |
| 990 | * definitions. |
| 991 | */ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 992 | #ifdef RUNTIME_DISCARD_EXIT |
| 993 | #define EXIT_DISCARDS |
| 994 | #else |
| 995 | #define EXIT_DISCARDS \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 996 | EXIT_TEXT \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 997 | EXIT_DATA |
| 998 | #endif |
| 999 | |
| 1000 | /* |
| 1001 | * Clang's -fprofile-arcs, -fsanitize=kernel-address, and |
| 1002 | * -fsanitize=thread produce unwanted sections (.eh_frame |
| 1003 | * and .init_array.*), but CONFIG_CONSTRUCTORS wants to |
| 1004 | * keep any .init_array.* sections. |
| 1005 | * https://bugs.llvm.org/show_bug.cgi?id=46478 |
| 1006 | */ |
| 1007 | #if defined(CONFIG_GCOV_KERNEL) || defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KCSAN) |
| 1008 | # ifdef CONFIG_CONSTRUCTORS |
| 1009 | # define SANITIZER_DISCARDS \ |
| 1010 | *(.eh_frame) |
| 1011 | # else |
| 1012 | # define SANITIZER_DISCARDS \ |
| 1013 | *(.init_array) *(.init_array.*) \ |
| 1014 | *(.eh_frame) |
| 1015 | # endif |
| 1016 | #else |
| 1017 | # define SANITIZER_DISCARDS |
| 1018 | #endif |
| 1019 | |
| 1020 | #define COMMON_DISCARDS \ |
| 1021 | SANITIZER_DISCARDS \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1022 | *(.discard) \ |
| 1023 | *(.discard.*) \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1024 | *(.modinfo) \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 1025 | /* ld.bfd warns about .gnu.version* even when not emitted */ \ |
| 1026 | *(.gnu.version*) \ |
| 1027 | |
| 1028 | #define DISCARDS \ |
| 1029 | /DISCARD/ : { \ |
| 1030 | EXIT_DISCARDS \ |
| 1031 | EXIT_CALL \ |
| 1032 | COMMON_DISCARDS \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * PERCPU_INPUT - the percpu input sections |
| 1037 | * @cacheline: cacheline size |
| 1038 | * |
| 1039 | * The core percpu section names and core symbols which do not rely |
| 1040 | * directly upon load addresses. |
| 1041 | * |
| 1042 | * @cacheline is used to align subsections to avoid false cacheline |
| 1043 | * sharing between subsections for different purposes. |
| 1044 | */ |
| 1045 | #define PERCPU_INPUT(cacheline) \ |
| 1046 | __per_cpu_start = .; \ |
| 1047 | *(.data..percpu..first) \ |
| 1048 | . = ALIGN(PAGE_SIZE); \ |
| 1049 | *(.data..percpu..page_aligned) \ |
| 1050 | . = ALIGN(cacheline); \ |
| 1051 | *(.data..percpu..read_mostly) \ |
| 1052 | . = ALIGN(cacheline); \ |
| 1053 | *(.data..percpu) \ |
| 1054 | *(.data..percpu..shared_aligned) \ |
| 1055 | PERCPU_DECRYPTED_SECTION \ |
| 1056 | __per_cpu_end = .; |
| 1057 | |
| 1058 | /** |
| 1059 | * PERCPU_VADDR - define output section for percpu area |
| 1060 | * @cacheline: cacheline size |
| 1061 | * @vaddr: explicit base address (optional) |
| 1062 | * @phdr: destination PHDR (optional) |
| 1063 | * |
| 1064 | * Macro which expands to output section for percpu area. |
| 1065 | * |
| 1066 | * @cacheline is used to align subsections to avoid false cacheline |
| 1067 | * sharing between subsections for different purposes. |
| 1068 | * |
| 1069 | * If @vaddr is not blank, it specifies explicit base address and all |
| 1070 | * percpu symbols will be offset from the given address. If blank, |
| 1071 | * @vaddr always equals @laddr + LOAD_OFFSET. |
| 1072 | * |
| 1073 | * @phdr defines the output PHDR to use if not blank. Be warned that |
| 1074 | * output PHDR is sticky. If @phdr is specified, the next output |
| 1075 | * section in the linker script will go there too. @phdr should have |
| 1076 | * a leading colon. |
| 1077 | * |
| 1078 | * Note that this macros defines __per_cpu_load as an absolute symbol. |
| 1079 | * If there is no need to put the percpu section at a predetermined |
| 1080 | * address, use PERCPU_SECTION. |
| 1081 | */ |
| 1082 | #define PERCPU_VADDR(cacheline, vaddr, phdr) \ |
| 1083 | __per_cpu_load = .; \ |
| 1084 | .data..percpu vaddr : AT(__per_cpu_load - LOAD_OFFSET) { \ |
| 1085 | PERCPU_INPUT(cacheline) \ |
| 1086 | } phdr \ |
| 1087 | . = __per_cpu_load + SIZEOF(.data..percpu); |
| 1088 | |
| 1089 | /** |
| 1090 | * PERCPU_SECTION - define output section for percpu area, simple version |
| 1091 | * @cacheline: cacheline size |
| 1092 | * |
| 1093 | * Align to PAGE_SIZE and outputs output section for percpu area. This |
| 1094 | * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and |
| 1095 | * __per_cpu_start will be identical. |
| 1096 | * |
| 1097 | * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,) |
| 1098 | * except that __per_cpu_load is defined as a relative symbol against |
| 1099 | * .data..percpu which is required for relocatable x86_32 configuration. |
| 1100 | */ |
| 1101 | #define PERCPU_SECTION(cacheline) \ |
| 1102 | . = ALIGN(PAGE_SIZE); \ |
| 1103 | .data..percpu : AT(ADDR(.data..percpu) - LOAD_OFFSET) { \ |
| 1104 | __per_cpu_load = .; \ |
| 1105 | PERCPU_INPUT(cacheline) \ |
| 1106 | } |
| 1107 | |
| 1108 | |
| 1109 | /* |
| 1110 | * Definition of the high level *_SECTION macros |
| 1111 | * They will fit only a subset of the architectures |
| 1112 | */ |
| 1113 | |
| 1114 | |
| 1115 | /* |
| 1116 | * Writeable data. |
| 1117 | * All sections are combined in a single .data section. |
| 1118 | * The sections following CONSTRUCTORS are arranged so their |
| 1119 | * typical alignment matches. |
| 1120 | * A cacheline is typical/always less than a PAGE_SIZE so |
| 1121 | * the sections that has this restriction (or similar) |
| 1122 | * is located before the ones requiring PAGE_SIZE alignment. |
| 1123 | * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which |
| 1124 | * matches the requirement of PAGE_ALIGNED_DATA. |
| 1125 | * |
| 1126 | * use 0 as page_align if page_aligned data is not used */ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 1127 | #define RW_DATA(cacheline, pagealigned, inittask) \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1128 | . = ALIGN(PAGE_SIZE); \ |
| 1129 | .data : AT(ADDR(.data) - LOAD_OFFSET) { \ |
| 1130 | INIT_TASK_DATA(inittask) \ |
| 1131 | NOSAVE_DATA \ |
| 1132 | PAGE_ALIGNED_DATA(pagealigned) \ |
| 1133 | CACHELINE_ALIGNED_DATA(cacheline) \ |
| 1134 | READ_MOSTLY_DATA(cacheline) \ |
| 1135 | DATA_DATA \ |
| 1136 | CONSTRUCTORS \ |
| 1137 | } \ |
| 1138 | BUG_TABLE \ |
| 1139 | |
| 1140 | #define INIT_TEXT_SECTION(inittext_align) \ |
| 1141 | . = ALIGN(inittext_align); \ |
| 1142 | .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { \ |
| 1143 | _sinittext = .; \ |
| 1144 | INIT_TEXT \ |
| 1145 | _einittext = .; \ |
| 1146 | } |
| 1147 | |
| 1148 | #define INIT_DATA_SECTION(initsetup_align) \ |
| 1149 | .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \ |
| 1150 | INIT_DATA \ |
| 1151 | INIT_SETUP(initsetup_align) \ |
| 1152 | INIT_CALLS \ |
| 1153 | CON_INITCALL \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1154 | INIT_RAM_FS \ |
| 1155 | } |
| 1156 | |
| 1157 | #define BSS_SECTION(sbss_align, bss_align, stop_align) \ |
| 1158 | . = ALIGN(sbss_align); \ |
| 1159 | __bss_start = .; \ |
| 1160 | SBSS(sbss_align) \ |
| 1161 | BSS(bss_align) \ |
| 1162 | . = ALIGN(stop_align); \ |
| 1163 | __bss_stop = .; |