brintos

brintos / linux-shallow public Read only

0
0
Text · 32.7 KiB · 9419e39 Raw
1155 lines · c
1/*2 * Helper macros to support writing architecture specific3 * linker scripts.4 *5 * A minimal linker scripts has following content:6 * [This is a sample, architectures may have special requirements]7 *8 * OUTPUT_FORMAT(...)9 * OUTPUT_ARCH(...)10 * ENTRY(...)11 * SECTIONS12 * {13 *	. = START;14 *	__init_begin = .;15 *	HEAD_TEXT_SECTION16 *	INIT_TEXT_SECTION(PAGE_SIZE)17 *	INIT_DATA_SECTION(...)18 *	PERCPU_SECTION(CACHELINE_SIZE)19 *	__init_end = .;20 *21 *	_stext = .;22 *	TEXT_SECTION = 023 *	_etext = .;24 *25 *      _sdata = .;26 *	RO_DATA(PAGE_SIZE)27 *	RW_DATA(...)28 *	_edata = .;29 *30 *	EXCEPTION_TABLE(...)31 *32 *	BSS_SECTION(0, 0, 0)33 *	_end = .;34 *35 *	STABS_DEBUG36 *	DWARF_DEBUG37 *	ELF_DETAILS38 *39 *	DISCARDS		// must be the last40 * }41 *42 * [__init_begin, __init_end] is the init section that may be freed after init43 * 	// __init_begin and __init_end should be page aligned, so that we can44 *	// free the whole .init memory45 * [_stext, _etext] is the text section46 * [_sdata, _edata] is the data section47 *48 * Some of the included output section have their own set of constants.49 * Examples are: [__initramfs_start, __initramfs_end] for initramfs and50 *               [__nosave_begin, __nosave_end] for the nosave data51 */52 53#include <asm-generic/codetag.lds.h>54 55#ifndef LOAD_OFFSET56#define LOAD_OFFSET 057#endif58 59/*60 * Only some architectures want to have the .notes segment visible in61 * a separate PT_NOTE ELF Program Header. When this happens, it needs62 * to be visible in both the kernel text's PT_LOAD and the PT_NOTE63 * Program Headers. In this case, though, the PT_LOAD needs to be made64 * the default again so that all the following sections don't also end65 * up in the PT_NOTE Program Header.66 */67#ifdef EMITS_PT_NOTE68#define NOTES_HEADERS		:text :note69#define NOTES_HEADERS_RESTORE	__restore_ph : { *(.__restore_ph) } :text70#else71#define NOTES_HEADERS72#define NOTES_HEADERS_RESTORE73#endif74 75/*76 * Some architectures have non-executable read-only exception tables.77 * They can be added to the RO_DATA segment by specifying their desired78 * alignment.79 */80#ifdef RO_EXCEPTION_TABLE_ALIGN81#define RO_EXCEPTION_TABLE	EXCEPTION_TABLE(RO_EXCEPTION_TABLE_ALIGN)82#else83#define RO_EXCEPTION_TABLE84#endif85 86/* Align . function alignment. */87#define ALIGN_FUNCTION()  . = ALIGN(CONFIG_FUNCTION_ALIGNMENT)88 89/*90 * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which91 * generates .data.identifier sections, which need to be pulled in with92 * .data. We don't want to pull in .data..other sections, which Linux93 * has defined. Same for text and bss.94 *95 * With LTO_CLANG, the linker also splits sections by default, so we need96 * these macros to combine the sections during the final link.97 *98 * RODATA_MAIN is not used because existing code already defines .rodata.x99 * sections to be brought in with rodata.100 */101#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG)102#define TEXT_MAIN .text .text.[0-9a-zA-Z_]*103#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral* .data.$__unnamed_* .data.$L*104#define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*105#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L*106#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..L* .bss..compoundliteral*107#define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*108#else109#define TEXT_MAIN .text110#define DATA_MAIN .data111#define SDATA_MAIN .sdata112#define RODATA_MAIN .rodata113#define BSS_MAIN .bss114#define SBSS_MAIN .sbss115#endif116 117/*118 * GCC 4.5 and later have a 32 bytes section alignment for structures.119 * Except GCC 4.9, that feels the need to align on 64 bytes.120 */121#define STRUCT_ALIGNMENT 32122#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)123 124/*125 * The order of the sched class addresses are important, as they are126 * used to determine the order of the priority of each sched class in127 * relation to each other.128 */129#define SCHED_DATA				\130	STRUCT_ALIGN();				\131	__sched_class_highest = .;		\132	*(__wasm_sched_class)			\133	*(__stop_sched_class)			\134	*(__dl_sched_class)			\135	*(__rt_sched_class)			\136	*(__fair_sched_class)			\137	*(__ext_sched_class)			\138	*(__idle_sched_class)			\139	__sched_class_lowest = .;140 141/* The actual configuration determine if the init/exit sections142 * are handled as text/data or they can be discarded (which143 * often happens at runtime)144 */145 146#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE147#define KEEP_PATCHABLE		KEEP(*(__patchable_function_entries))148#define PATCHABLE_DISCARDS149#else150#define KEEP_PATCHABLE151#define PATCHABLE_DISCARDS	*(__patchable_function_entries)152#endif153 154#ifndef CONFIG_ARCH_SUPPORTS_CFI_CLANG155/*156 * Simply points to ftrace_stub, but with the proper protocol.157 * Defined by the linker script in linux/vmlinux.lds.h158 */159#define	FTRACE_STUB_HACK	ftrace_stub_graph = ftrace_stub;160#else161#define FTRACE_STUB_HACK162#endif163 164#ifdef CONFIG_FTRACE_MCOUNT_RECORD165/*166 * The ftrace call sites are logged to a section whose name depends on the167 * compiler option used. A given kernel image will only use one, AKA168 * FTRACE_CALLSITE_SECTION. We capture all of them here to avoid header169 * dependencies for FTRACE_CALLSITE_SECTION's definition.170 *171 * ftrace_ops_list_func will be defined as arch_ftrace_ops_list_func172 * as some archs will have a different prototype for that function173 * but ftrace_ops_list_func() will have a single prototype.174 */175#define MCOUNT_REC()	. = ALIGN(8);				\176			__start_mcount_loc = .;			\177			KEEP(*(__mcount_loc))			\178			KEEP_PATCHABLE				\179			__stop_mcount_loc = .;			\180			FTRACE_STUB_HACK			\181			ftrace_ops_list_func = arch_ftrace_ops_list_func;182#else183# ifdef CONFIG_FUNCTION_TRACER184#  define MCOUNT_REC()	FTRACE_STUB_HACK			\185			ftrace_ops_list_func = arch_ftrace_ops_list_func;186# else187#  define MCOUNT_REC()188# endif189#endif190 191#define BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_)	\192	_BEGIN_##_label_ = .;						\193	KEEP(*(_sec_))							\194	_END_##_label_ = .;195 196#define BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_)	\197	_label_##_BEGIN_ = .;						\198	KEEP(*(_sec_))							\199	_label_##_END_ = .;200 201#define BOUNDED_SECTION_BY(_sec_, _label_)				\202	BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop)203 204#define BOUNDED_SECTION(_sec)	 BOUNDED_SECTION_BY(_sec, _sec)205 206#define HEADERED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_) \207	_HDR_##_label_	= .;						\208	KEEP(*(.gnu.linkonce.##_sec_))					\209	BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_)210 211#define HEADERED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_) \212	_label_##_HDR_ = .;						\213	KEEP(*(.gnu.linkonce.##_sec_))					\214	BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_)215 216#define HEADERED_SECTION_BY(_sec_, _label_)				\217	HEADERED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop)218 219#define HEADERED_SECTION(_sec)	 HEADERED_SECTION_BY(_sec, _sec)220 221#ifdef CONFIG_TRACE_BRANCH_PROFILING222#define LIKELY_PROFILE()						\223	BOUNDED_SECTION_BY(_ftrace_annotated_branch, _annotated_branch_profile)224#else225#define LIKELY_PROFILE()226#endif227 228#ifdef CONFIG_PROFILE_ALL_BRANCHES229#define BRANCH_PROFILE()					\230	BOUNDED_SECTION_BY(_ftrace_branch, _branch_profile)231#else232#define BRANCH_PROFILE()233#endif234 235#ifdef CONFIG_KPROBES236#define KPROBE_BLACKLIST()				\237	. = ALIGN(8);					\238	BOUNDED_SECTION(_kprobe_blacklist)239#else240#define KPROBE_BLACKLIST()241#endif242 243#ifdef CONFIG_FUNCTION_ERROR_INJECTION244#define ERROR_INJECT_WHITELIST()			\245	STRUCT_ALIGN();					\246	BOUNDED_SECTION(_error_injection_whitelist)247#else248#define ERROR_INJECT_WHITELIST()249#endif250 251#ifdef CONFIG_EVENT_TRACING252#define FTRACE_EVENTS()							\253	. = ALIGN(8);							\254	BOUNDED_SECTION(_ftrace_events)					\255	BOUNDED_SECTION_BY(_ftrace_eval_map, _ftrace_eval_maps)256#else257#define FTRACE_EVENTS()258#endif259 260#ifdef CONFIG_TRACING261#define TRACE_PRINTKS()		BOUNDED_SECTION_BY(__trace_printk_fmt, ___trace_bprintk_fmt)262#define TRACEPOINT_STR()	BOUNDED_SECTION_BY(__tracepoint_str, ___tracepoint_str)263#else264#define TRACE_PRINTKS()265#define TRACEPOINT_STR()266#endif267 268#ifdef CONFIG_FTRACE_SYSCALLS269#define TRACE_SYSCALLS()			\270	. = ALIGN(8);				\271	BOUNDED_SECTION_BY(__syscalls_metadata, _syscalls_metadata)272#else273#define TRACE_SYSCALLS()274#endif275 276#ifdef CONFIG_BPF_EVENTS277#define BPF_RAW_TP() STRUCT_ALIGN();				\278	BOUNDED_SECTION_BY(__bpf_raw_tp_map, __bpf_raw_tp)279#else280#define BPF_RAW_TP()281#endif282 283#ifdef CONFIG_SERIAL_EARLYCON284#define EARLYCON_TABLE()						\285	. = ALIGN(8);							\286	BOUNDED_SECTION_POST_LABEL(__earlycon_table, __earlycon_table, , _end)287#else288#define EARLYCON_TABLE()289#endif290 291#ifdef CONFIG_SECURITY292#define LSM_TABLE()					\293	. = ALIGN(8);					\294	BOUNDED_SECTION_PRE_LABEL(.lsm_info.init, _lsm_info, __start, __end)295 296#define EARLY_LSM_TABLE()						\297	. = ALIGN(8);							\298	BOUNDED_SECTION_PRE_LABEL(.early_lsm_info.init, _early_lsm_info, __start, __end)299#else300#define LSM_TABLE()301#define EARLY_LSM_TABLE()302#endif303 304#define ___OF_TABLE(cfg, name)	_OF_TABLE_##cfg(name)305#define __OF_TABLE(cfg, name)	___OF_TABLE(cfg, name)306#define OF_TABLE(cfg, name)	__OF_TABLE(IS_ENABLED(cfg), name)307#define _OF_TABLE_0(name)308#define _OF_TABLE_1(name)						\309	. = ALIGN(8);							\310	__##name##_of_table = .;					\311	KEEP(*(__##name##_of_table))					\312	KEEP(*(__##name##_of_table_end))313 314#define TIMER_OF_TABLES()	OF_TABLE(CONFIG_TIMER_OF, timer)315#define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip)316#define CLK_OF_TABLES()		OF_TABLE(CONFIG_COMMON_CLK, clk)317#define RESERVEDMEM_OF_TABLES()	OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem)318#define CPU_METHOD_OF_TABLES()	OF_TABLE(CONFIG_SMP, cpu_method)319#define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method)320 321#ifdef CONFIG_ACPI322#define ACPI_PROBE_TABLE(name)						\323	. = ALIGN(8);							\324	BOUNDED_SECTION_POST_LABEL(__##name##_acpi_probe_table,		\325				   __##name##_acpi_probe_table,, _end)326#else327#define ACPI_PROBE_TABLE(name)328#endif329 330#ifdef CONFIG_THERMAL331#define THERMAL_TABLE(name)						\332	. = ALIGN(8);							\333	BOUNDED_SECTION_POST_LABEL(__##name##_thermal_table,		\334				   __##name##_thermal_table,, _end)335#else336#define THERMAL_TABLE(name)337#endif338 339#define KERNEL_DTB()							\340	STRUCT_ALIGN();							\341	__dtb_start = .;						\342	KEEP(*(.dtb.init.rodata))					\343	__dtb_end = .;344 345/*346 * .data section347 */348#define DATA_DATA							\349	*(.xiptext)							\350	*(DATA_MAIN)							\351	*(.data..decrypted)						\352	*(.ref.data)							\353	*(.data..shared_aligned) /* percpu related */			\354	*(.data.unlikely)						\355	__start_once = .;						\356	*(.data.once)							\357	__end_once = .;							\358	STRUCT_ALIGN();							\359	*(__tracepoints)						\360	/* implement dynamic printk debug */				\361	. = ALIGN(8);							\362	BOUNDED_SECTION_BY(__dyndbg_classes, ___dyndbg_classes)		\363	BOUNDED_SECTION_BY(__dyndbg, ___dyndbg)				\364	CODETAG_SECTIONS()						\365	LIKELY_PROFILE()		       				\366	BRANCH_PROFILE()						\367	TRACE_PRINTKS()							\368	BPF_RAW_TP()							\369	TRACEPOINT_STR()						\370	KUNIT_TABLE()371 372/*373 * Data section helpers374 */375#define NOSAVE_DATA							\376	. = ALIGN(PAGE_SIZE);						\377	__nosave_begin = .;						\378	*(.data..nosave)						\379	. = ALIGN(PAGE_SIZE);						\380	__nosave_end = .;381 382#define PAGE_ALIGNED_DATA(page_align)					\383	. = ALIGN(page_align);						\384	*(.data..page_aligned)						\385	. = ALIGN(page_align);386 387#define READ_MOSTLY_DATA(align)						\388	. = ALIGN(align);						\389	*(.data..read_mostly)						\390	. = ALIGN(align);391 392#define CACHELINE_ALIGNED_DATA(align)					\393	. = ALIGN(align);						\394	*(.data..cacheline_aligned)395 396#define INIT_TASK_DATA(align)						\397	. = ALIGN(align);						\398	__start_init_stack = .;						\399	init_thread_union = .;						\400	init_stack = .;							\401	KEEP(*(.data..init_task))					\402	KEEP(*(.data..init_thread_info))				\403	. = __start_init_stack + THREAD_SIZE;				\404	__end_init_stack = .;405 406#define JUMP_TABLE_DATA							\407	. = ALIGN(8);							\408	BOUNDED_SECTION_BY(__jump_table, ___jump_table)409 410#ifdef CONFIG_HAVE_STATIC_CALL_INLINE411#define STATIC_CALL_DATA						\412	. = ALIGN(8);							\413	BOUNDED_SECTION_BY(.static_call_sites, _static_call_sites)	\414	BOUNDED_SECTION_BY(.static_call_tramp_key, _static_call_tramp_key)415#else416#define STATIC_CALL_DATA417#endif418 419/*420 * Allow architectures to handle ro_after_init data on their421 * own by defining an empty RO_AFTER_INIT_DATA.422 */423#ifndef RO_AFTER_INIT_DATA424#define RO_AFTER_INIT_DATA						\425	. = ALIGN(8);							\426	__start_ro_after_init = .;					\427	*(.data..ro_after_init)						\428	JUMP_TABLE_DATA							\429	STATIC_CALL_DATA						\430	__end_ro_after_init = .;431#endif432 433/*434 * .kcfi_traps contains a list KCFI trap locations.435 */436#ifndef KCFI_TRAPS437#ifdef CONFIG_ARCH_USES_CFI_TRAPS438#define KCFI_TRAPS							\439	__kcfi_traps : AT(ADDR(__kcfi_traps) - LOAD_OFFSET) {		\440		BOUNDED_SECTION_BY(.kcfi_traps, ___kcfi_traps)		\441	}442#else443#define KCFI_TRAPS444#endif445#endif446 447/*448 * Read only Data449 */450#define RO_DATA(align)							\451	. = ALIGN((align));						\452	.rodata           : AT(ADDR(.rodata) - LOAD_OFFSET) {		\453		__start_rodata = .;					\454		*(.rodata) *(.rodata.*)					\455		SCHED_DATA						\456		RO_AFTER_INIT_DATA	/* Read only after init */	\457		. = ALIGN(8);						\458		BOUNDED_SECTION_BY(__tracepoints_ptrs, ___tracepoints_ptrs) \459		*(__tracepoints_strings)/* Tracepoints: strings */	\460	}								\461									\462	.rodata1          : AT(ADDR(.rodata1) - LOAD_OFFSET) {		\463		*(.rodata1)						\464	}								\465									\466	/* PCI quirks */						\467	.pci_fixup        : AT(ADDR(.pci_fixup) - LOAD_OFFSET) {	\468		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_early,  _pci_fixups_early,  __start, __end) \469		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_header, _pci_fixups_header, __start, __end) \470		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_final,  _pci_fixups_final,  __start, __end) \471		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_enable, _pci_fixups_enable, __start, __end) \472		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_resume, _pci_fixups_resume, __start, __end) \473		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_suspend, _pci_fixups_suspend, __start, __end) \474		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_resume_early, _pci_fixups_resume_early, __start, __end) \475		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_suspend_late, _pci_fixups_suspend_late, __start, __end) \476	}								\477									\478	FW_LOADER_BUILT_IN_DATA						\479	TRACEDATA							\480									\481	PRINTK_INDEX							\482									\483	/* Kernel symbol table: Normal symbols */			\484	__ksymtab         : AT(ADDR(__ksymtab) - LOAD_OFFSET) {		\485		__start___ksymtab = .;					\486		KEEP(*(SORT(___ksymtab+*)))				\487		__stop___ksymtab = .;					\488	}								\489									\490	/* Kernel symbol table: GPL-only symbols */			\491	__ksymtab_gpl     : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) {	\492		__start___ksymtab_gpl = .;				\493		KEEP(*(SORT(___ksymtab_gpl+*)))				\494		__stop___ksymtab_gpl = .;				\495	}								\496									\497	/* Kernel symbol table: Normal symbols */			\498	__kcrctab         : AT(ADDR(__kcrctab) - LOAD_OFFSET) {		\499		__start___kcrctab = .;					\500		KEEP(*(SORT(___kcrctab+*)))				\501		__stop___kcrctab = .;					\502	}								\503									\504	/* Kernel symbol table: GPL-only symbols */			\505	__kcrctab_gpl     : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) {	\506		__start___kcrctab_gpl = .;				\507		KEEP(*(SORT(___kcrctab_gpl+*)))				\508		__stop___kcrctab_gpl = .;				\509	}								\510									\511	/* Kernel symbol table: strings */				\512        __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) {	\513		*(__ksymtab_strings)					\514	}								\515									\516	/* __*init sections */						\517	__init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) {		\518		*(.ref.rodata)						\519	}								\520									\521	/* Built-in module parameters. */				\522	__param : AT(ADDR(__param) - LOAD_OFFSET) {			\523		BOUNDED_SECTION_BY(__param, ___param)			\524	}								\525									\526	/* Built-in module versions. */					\527	__modver : AT(ADDR(__modver) - LOAD_OFFSET) {			\528		BOUNDED_SECTION_BY(__modver, ___modver)			\529	}								\530									\531	KCFI_TRAPS							\532									\533	RO_EXCEPTION_TABLE						\534	NOTES								\535	BTF								\536									\537	. = ALIGN((align));						\538	__end_rodata = .;539 540 541/*542 * Non-instrumentable text section543 */544#define NOINSTR_TEXT							\545		ALIGN_FUNCTION();					\546		__noinstr_text_start = .;				\547		*(.noinstr.text)					\548		__cpuidle_text_start = .;				\549		*(.cpuidle.text)					\550		__cpuidle_text_end = .;					\551		__noinstr_text_end = .;552 553/*554 * .text section. Map to function alignment to avoid address changes555 * during second ld run in second ld pass when generating System.map556 *557 * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead558 * code elimination is enabled, so these sections should be converted559 * to use ".." first.560 */561#define TEXT_TEXT							\562		ALIGN_FUNCTION();					\563		*(.text.hot .text.hot.*)				\564		*(TEXT_MAIN .text.fixup)				\565		*(.text.unlikely .text.unlikely.*)			\566		*(.text.unknown .text.unknown.*)			\567		NOINSTR_TEXT						\568		*(.ref.text)						\569		*(.text.asan.* .text.tsan.*)570 571 572/* sched.text is aling to function alignment to secure we have same573 * address even at second ld pass when generating System.map */574#define SCHED_TEXT							\575		ALIGN_FUNCTION();					\576		__sched_text_start = .;					\577		*(.sched.text)						\578		__sched_text_end = .;579 580/* spinlock.text is aling to function alignment to secure we have same581 * address even at second ld pass when generating System.map */582#define LOCK_TEXT							\583		ALIGN_FUNCTION();					\584		__lock_text_start = .;					\585		*(.spinlock.text)					\586		__lock_text_end = .;587 588#define KPROBES_TEXT							\589		ALIGN_FUNCTION();					\590		__kprobes_text_start = .;				\591		*(.kprobes.text)					\592		__kprobes_text_end = .;593 594#define ENTRY_TEXT							\595		ALIGN_FUNCTION();					\596		__entry_text_start = .;					\597		*(.entry.text)						\598		__entry_text_end = .;599 600#define IRQENTRY_TEXT							\601		ALIGN_FUNCTION();					\602		__irqentry_text_start = .;				\603		*(.irqentry.text)					\604		__irqentry_text_end = .;605 606#define SOFTIRQENTRY_TEXT						\607		ALIGN_FUNCTION();					\608		__softirqentry_text_start = .;				\609		*(.softirqentry.text)					\610		__softirqentry_text_end = .;611 612#define STATIC_CALL_TEXT						\613		ALIGN_FUNCTION();					\614		__static_call_text_start = .;				\615		*(.static_call.text)					\616		__static_call_text_end = .;617 618/* Section used for early init (in .S files) */619#define HEAD_TEXT  KEEP(*(.head.text))620 621#define HEAD_TEXT_SECTION							\622	.head.text : AT(ADDR(.head.text) - LOAD_OFFSET) {		\623		HEAD_TEXT						\624	}625 626/*627 * Exception table628 */629#define EXCEPTION_TABLE(align)						\630	. = ALIGN(align);						\631	__ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {		\632		BOUNDED_SECTION_BY(__ex_table, ___ex_table)		\633	}634 635/*636 * .BTF637 */638#ifdef CONFIG_DEBUG_INFO_BTF639#define BTF								\640	.BTF : AT(ADDR(.BTF) - LOAD_OFFSET) {				\641		BOUNDED_SECTION_BY(.BTF, _BTF)				\642	}								\643	. = ALIGN(4);							\644	.BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) {			\645		*(.BTF_ids)						\646	}647#else648#define BTF649#endif650 651/*652 * Init task653 */654#define INIT_TASK_DATA_SECTION(align)					\655	. = ALIGN(align);						\656	.data..init_task :  AT(ADDR(.data..init_task) - LOAD_OFFSET) {	\657		INIT_TASK_DATA(align)					\658	}659 660#ifdef CONFIG_CONSTRUCTORS661#define KERNEL_CTORS()	. = ALIGN(8);			   \662			__ctors_start = .;		   \663			KEEP(*(SORT(.ctors.*)))		   \664			KEEP(*(.ctors))			   \665			KEEP(*(SORT(.init_array.*)))	   \666			KEEP(*(.init_array))		   \667			__ctors_end = .;668#else669#define KERNEL_CTORS()670#endif671 672/* init and exit section handling */673#define INIT_DATA							\674	KEEP(*(SORT(___kentry+*)))					\675	*(.init.data .init.data.*)					\676	KERNEL_CTORS()							\677	MCOUNT_REC()							\678	*(.init.rodata .init.rodata.*)					\679	FTRACE_EVENTS()							\680	TRACE_SYSCALLS()						\681	KPROBE_BLACKLIST()						\682	ERROR_INJECT_WHITELIST()					\683	CLK_OF_TABLES()							\684	RESERVEDMEM_OF_TABLES()						\685	TIMER_OF_TABLES()						\686	CPU_METHOD_OF_TABLES()						\687	CPUIDLE_METHOD_OF_TABLES()					\688	KERNEL_DTB()							\689	IRQCHIP_OF_MATCH_TABLE()					\690	ACPI_PROBE_TABLE(irqchip)					\691	ACPI_PROBE_TABLE(timer)						\692	THERMAL_TABLE(governor)						\693	EARLYCON_TABLE()						\694	LSM_TABLE()							\695	EARLY_LSM_TABLE()						\696	KUNIT_INIT_TABLE()697 698#define INIT_TEXT							\699	*(.init.text .init.text.*)					\700	*(.text.startup)701 702#define EXIT_DATA							\703	*(.exit.data .exit.data.*)					\704	*(.fini_array .fini_array.*)					\705	*(.dtors .dtors.*)						\706 707#define EXIT_TEXT							\708	*(.exit.text)							\709	*(.text.exit)							\710 711#define EXIT_CALL							\712	*(.exitcall.exit)713 714/*715 * bss (Block Started by Symbol) - uninitialized data716 * zeroed during startup717 */718#define SBSS(sbss_align)						\719	. = ALIGN(sbss_align);						\720	.sbss : AT(ADDR(.sbss) - LOAD_OFFSET) {				\721		*(.dynsbss)						\722		*(SBSS_MAIN)						\723		*(.scommon)						\724	}725 726/*727 * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra728 * sections to the front of bss.729 */730#ifndef BSS_FIRST_SECTIONS731#define BSS_FIRST_SECTIONS732#endif733 734#define BSS(bss_align)							\735	. = ALIGN(bss_align);						\736	.bss : AT(ADDR(.bss) - LOAD_OFFSET) {				\737		BSS_FIRST_SECTIONS					\738		. = ALIGN(PAGE_SIZE);					\739		*(.bss..page_aligned)					\740		. = ALIGN(PAGE_SIZE);					\741		*(.dynbss)						\742		*(BSS_MAIN)						\743		*(COMMON)						\744	}745 746/*747 * DWARF debug sections.748 * Symbols in the DWARF debugging sections are relative to749 * the beginning of the section so we begin them at 0.750 */751#define DWARF_DEBUG							\752		/* DWARF 1 */						\753		.debug          0 : { *(.debug) }			\754		.line           0 : { *(.line) }			\755		/* GNU DWARF 1 extensions */				\756		.debug_srcinfo  0 : { *(.debug_srcinfo) }		\757		.debug_sfnames  0 : { *(.debug_sfnames) }		\758		/* DWARF 1.1 and DWARF 2 */				\759		.debug_aranges  0 : { *(.debug_aranges) }		\760		.debug_pubnames 0 : { *(.debug_pubnames) }		\761		/* DWARF 2 */						\762		.debug_info     0 : { *(.debug_info			\763				.gnu.linkonce.wi.*) }			\764		.debug_abbrev   0 : { *(.debug_abbrev) }		\765		.debug_line     0 : { *(.debug_line) }			\766		.debug_frame    0 : { *(.debug_frame) }			\767		.debug_str      0 : { *(.debug_str) }			\768		.debug_loc      0 : { *(.debug_loc) }			\769		.debug_macinfo  0 : { *(.debug_macinfo) }		\770		.debug_pubtypes 0 : { *(.debug_pubtypes) }		\771		/* DWARF 3 */						\772		.debug_ranges	0 : { *(.debug_ranges) }		\773		/* SGI/MIPS DWARF 2 extensions */			\774		.debug_weaknames 0 : { *(.debug_weaknames) }		\775		.debug_funcnames 0 : { *(.debug_funcnames) }		\776		.debug_typenames 0 : { *(.debug_typenames) }		\777		.debug_varnames  0 : { *(.debug_varnames) }		\778		/* GNU DWARF 2 extensions */				\779		.debug_gnu_pubnames 0 : { *(.debug_gnu_pubnames) }	\780		.debug_gnu_pubtypes 0 : { *(.debug_gnu_pubtypes) }	\781		/* DWARF 4 */						\782		.debug_types	0 : { *(.debug_types) }			\783		/* DWARF 5 */						\784		.debug_addr	0 : { *(.debug_addr) }			\785		.debug_line_str	0 : { *(.debug_line_str) }		\786		.debug_loclists	0 : { *(.debug_loclists) }		\787		.debug_macro	0 : { *(.debug_macro) }			\788		.debug_names	0 : { *(.debug_names) }			\789		.debug_rnglists	0 : { *(.debug_rnglists) }		\790		.debug_str_offsets	0 : { *(.debug_str_offsets) }791 792/* Stabs debugging sections. */793#define STABS_DEBUG							\794		.stab 0 : { *(.stab) }					\795		.stabstr 0 : { *(.stabstr) }				\796		.stab.excl 0 : { *(.stab.excl) }			\797		.stab.exclstr 0 : { *(.stab.exclstr) }			\798		.stab.index 0 : { *(.stab.index) }			\799		.stab.indexstr 0 : { *(.stab.indexstr) }800 801/* Required sections not related to debugging. */802#define ELF_DETAILS							\803		.comment 0 : { *(.comment) }				\804		.symtab 0 : { *(.symtab) }				\805		.strtab 0 : { *(.strtab) }				\806		.shstrtab 0 : { *(.shstrtab) }807 808#ifdef CONFIG_GENERIC_BUG809#define BUG_TABLE							\810	. = ALIGN(8);							\811	__bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) {		\812		BOUNDED_SECTION_BY(__bug_table, ___bug_table)		\813	}814#else815#define BUG_TABLE816#endif817 818#ifdef CONFIG_UNWINDER_ORC819#define ORC_UNWIND_TABLE						\820	.orc_header : AT(ADDR(.orc_header) - LOAD_OFFSET) {		\821		BOUNDED_SECTION_BY(.orc_header, _orc_header)		\822	}								\823	. = ALIGN(4);							\824	.orc_unwind_ip : AT(ADDR(.orc_unwind_ip) - LOAD_OFFSET) {	\825		BOUNDED_SECTION_BY(.orc_unwind_ip, _orc_unwind_ip)	\826	}								\827	. = ALIGN(2);							\828	.orc_unwind : AT(ADDR(.orc_unwind) - LOAD_OFFSET) {		\829		BOUNDED_SECTION_BY(.orc_unwind, _orc_unwind)		\830	}								\831	text_size = _etext - _stext;					\832	. = ALIGN(4);							\833	.orc_lookup : AT(ADDR(.orc_lookup) - LOAD_OFFSET) {		\834		orc_lookup = .;						\835		. += (((text_size + LOOKUP_BLOCK_SIZE - 1) /		\836			LOOKUP_BLOCK_SIZE) + 1) * 4;			\837		orc_lookup_end = .;					\838	}839#else840#define ORC_UNWIND_TABLE841#endif842 843/* Built-in firmware blobs */844#ifdef CONFIG_FW_LOADER845#define FW_LOADER_BUILT_IN_DATA						\846	.builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) ALIGN(8) {	\847		BOUNDED_SECTION_PRE_LABEL(.builtin_fw, _builtin_fw, __start, __end) \848	}849#else850#define FW_LOADER_BUILT_IN_DATA851#endif852 853#ifdef CONFIG_PM_TRACE854#define TRACEDATA							\855	. = ALIGN(4);							\856	.tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) {		\857		BOUNDED_SECTION_POST_LABEL(.tracedata, __tracedata, _start, _end) \858	}859#else860#define TRACEDATA861#endif862 863#ifdef CONFIG_PRINTK_INDEX864#define PRINTK_INDEX							\865	.printk_index : AT(ADDR(.printk_index) - LOAD_OFFSET) {		\866		BOUNDED_SECTION_BY(.printk_index, _printk_index)	\867	}868#else869#define PRINTK_INDEX870#endif871 872/*873 * Discard .note.GNU-stack, which is emitted as PROGBITS by the compiler.874 * Otherwise, the type of .notes section would become PROGBITS instead of NOTES.875 *876 * Also, discard .note.gnu.property, otherwise it forces the notes section to877 * be 8-byte aligned which causes alignment mismatches with the kernel's custom878 * 4-byte aligned notes.879 */880#define NOTES								\881	/DISCARD/ : {							\882		*(.note.GNU-stack)					\883		*(.note.gnu.property)					\884	}								\885	.notes : AT(ADDR(.notes) - LOAD_OFFSET) {			\886		BOUNDED_SECTION_BY(.note.*, _notes)			\887	} NOTES_HEADERS							\888	NOTES_HEADERS_RESTORE889 890#define INIT_SETUP(initsetup_align)					\891		. = ALIGN(initsetup_align);				\892		BOUNDED_SECTION_POST_LABEL(.init.setup, __setup, _start, _end)893 894#define INIT_CALLS_LEVEL(level)						\895		__initcall##level##_start = .;				\896		KEEP(*(.initcall##level##.init))			\897		KEEP(*(.initcall##level##s.init))			\898 899#define INIT_CALLS							\900		__initcall_start = .;					\901		KEEP(*(.initcallearly.init))				\902		INIT_CALLS_LEVEL(0)					\903		INIT_CALLS_LEVEL(1)					\904		INIT_CALLS_LEVEL(2)					\905		INIT_CALLS_LEVEL(3)					\906		INIT_CALLS_LEVEL(4)					\907		INIT_CALLS_LEVEL(5)					\908		INIT_CALLS_LEVEL(rootfs)				\909		INIT_CALLS_LEVEL(6)					\910		INIT_CALLS_LEVEL(7)					\911		__initcall_end = .;912 913#define CON_INITCALL							\914	BOUNDED_SECTION_POST_LABEL(.con_initcall.init, __con_initcall, _start, _end)915 916#define NAMED_SECTION(name) \917	. = ALIGN(8); \918	name : AT(ADDR(name) - LOAD_OFFSET) \919	{ BOUNDED_SECTION_PRE_LABEL(name, name, __start_, __stop_) }920 921#define RUNTIME_CONST(t,x) NAMED_SECTION(runtime_##t##_##x)922 923#define RUNTIME_CONST_VARIABLES						\924		RUNTIME_CONST(shift, d_hash_shift)			\925		RUNTIME_CONST(ptr, dentry_hashtable)926 927/* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */928#define KUNIT_TABLE()							\929		. = ALIGN(8);						\930		BOUNDED_SECTION_POST_LABEL(.kunit_test_suites, __kunit_suites, _start, _end)931 932/* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */933#define KUNIT_INIT_TABLE()						\934		. = ALIGN(8);						\935		BOUNDED_SECTION_POST_LABEL(.kunit_init_test_suites, \936				__kunit_init_suites, _start, _end)937 938#ifdef CONFIG_BLK_DEV_INITRD939#define INIT_RAM_FS							\940	. = ALIGN(4);							\941	__initramfs_start = .;						\942	KEEP(*(.init.ramfs))						\943	. = ALIGN(8);							\944	KEEP(*(.init.ramfs.info))945#else946#define INIT_RAM_FS947#endif948 949/*950 * Memory encryption operates on a page basis. Since we need to clear951 * the memory encryption mask for this section, it needs to be aligned952 * on a page boundary and be a page-size multiple in length.953 *954 * Note: We use a separate section so that only this section gets955 * decrypted to avoid exposing more than we wish.956 */957#ifdef CONFIG_AMD_MEM_ENCRYPT958#define PERCPU_DECRYPTED_SECTION					\959	. = ALIGN(PAGE_SIZE);						\960	*(.data..percpu..decrypted)					\961	. = ALIGN(PAGE_SIZE);962#else963#define PERCPU_DECRYPTED_SECTION964#endif965 966 967/*968 * Default discarded sections.969 *970 * Some archs want to discard exit text/data at runtime rather than971 * link time due to cross-section references such as alt instructions,972 * bug table, eh_frame, etc.  DISCARDS must be the last of output973 * section definitions so that such archs put those in earlier section974 * definitions.975 */976#ifdef RUNTIME_DISCARD_EXIT977#define EXIT_DISCARDS978#else979#define EXIT_DISCARDS							\980	EXIT_TEXT							\981	EXIT_DATA982#endif983 984/*985 * Clang's -fprofile-arcs, -fsanitize=kernel-address, and986 * -fsanitize=thread produce unwanted sections (.eh_frame987 * and .init_array.*), but CONFIG_CONSTRUCTORS wants to988 * keep any .init_array.* sections.989 * https://llvm.org/pr46478990 */991#ifdef CONFIG_UNWIND_TABLES992#define DISCARD_EH_FRAME993#else994#define DISCARD_EH_FRAME	*(.eh_frame)995#endif996#if defined(CONFIG_GCOV_KERNEL) || defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KCSAN)997# ifdef CONFIG_CONSTRUCTORS998#  define SANITIZER_DISCARDS						\999	DISCARD_EH_FRAME1000# else1001#  define SANITIZER_DISCARDS						\1002	*(.init_array) *(.init_array.*)					\1003	DISCARD_EH_FRAME1004# endif1005#else1006# define SANITIZER_DISCARDS1007#endif1008 1009#define COMMON_DISCARDS							\1010	SANITIZER_DISCARDS						\1011	PATCHABLE_DISCARDS						\1012	*(.discard)							\1013	*(.discard.*)							\1014	*(.export_symbol)						\1015	*(.modinfo)							\1016	/* ld.bfd warns about .gnu.version* even when not emitted */	\1017	*(.gnu.version*)						\1018 1019#define DISCARDS							\1020	/DISCARD/ : {							\1021	EXIT_DISCARDS							\1022	EXIT_CALL							\1023	COMMON_DISCARDS							\1024	}1025 1026/**1027 * PERCPU_INPUT - the percpu input sections1028 * @cacheline: cacheline size1029 *1030 * The core percpu section names and core symbols which do not rely1031 * directly upon load addresses.1032 *1033 * @cacheline is used to align subsections to avoid false cacheline1034 * sharing between subsections for different purposes.1035 */1036#define PERCPU_INPUT(cacheline)						\1037	__per_cpu_start = .;						\1038	*(.data..percpu..first)						\1039	. = ALIGN(PAGE_SIZE);						\1040	*(.data..percpu..page_aligned)					\1041	. = ALIGN(cacheline);						\1042	*(.data..percpu..read_mostly)					\1043	. = ALIGN(cacheline);						\1044	*(.data..percpu)						\1045	*(.data..percpu..shared_aligned)				\1046	PERCPU_DECRYPTED_SECTION					\1047	__per_cpu_end = .;1048 1049/**1050 * PERCPU_VADDR - define output section for percpu area1051 * @cacheline: cacheline size1052 * @vaddr: explicit base address (optional)1053 * @phdr: destination PHDR (optional)1054 *1055 * Macro which expands to output section for percpu area.1056 *1057 * @cacheline is used to align subsections to avoid false cacheline1058 * sharing between subsections for different purposes.1059 *1060 * If @vaddr is not blank, it specifies explicit base address and all1061 * percpu symbols will be offset from the given address.  If blank,1062 * @vaddr always equals @laddr + LOAD_OFFSET.1063 *1064 * @phdr defines the output PHDR to use if not blank.  Be warned that1065 * output PHDR is sticky.  If @phdr is specified, the next output1066 * section in the linker script will go there too.  @phdr should have1067 * a leading colon.1068 *1069 * Note that this macros defines __per_cpu_load as an absolute symbol.1070 * If there is no need to put the percpu section at a predetermined1071 * address, use PERCPU_SECTION.1072 */1073#define PERCPU_VADDR(cacheline, vaddr, phdr)				\1074	__per_cpu_load = .;						\1075	.data..percpu vaddr : AT(__per_cpu_load - LOAD_OFFSET) {	\1076		PERCPU_INPUT(cacheline)					\1077	} phdr								\1078	. = __per_cpu_load + SIZEOF(.data..percpu);1079 1080/**1081 * PERCPU_SECTION - define output section for percpu area, simple version1082 * @cacheline: cacheline size1083 *1084 * Align to PAGE_SIZE and outputs output section for percpu area.  This1085 * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and1086 * __per_cpu_start will be identical.1087 *1088 * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,)1089 * except that __per_cpu_load is defined as a relative symbol against1090 * .data..percpu which is required for relocatable x86_32 configuration.1091 */1092#define PERCPU_SECTION(cacheline)					\1093	. = ALIGN(PAGE_SIZE);						\1094	.data..percpu	: AT(ADDR(.data..percpu) - LOAD_OFFSET) {	\1095		__per_cpu_load = .;					\1096		PERCPU_INPUT(cacheline)					\1097	}1098 1099 1100/*1101 * Definition of the high level *_SECTION macros1102 * They will fit only a subset of the architectures1103 */1104 1105 1106/*1107 * Writeable data.1108 * All sections are combined in a single .data section.1109 * The sections following CONSTRUCTORS are arranged so their1110 * typical alignment matches.1111 * A cacheline is typical/always less than a PAGE_SIZE so1112 * the sections that has this restriction (or similar)1113 * is located before the ones requiring PAGE_SIZE alignment.1114 * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which1115 * matches the requirement of PAGE_ALIGNED_DATA.1116 *1117 * use 0 as page_align if page_aligned data is not used */1118#define RW_DATA(cacheline, pagealigned, inittask)			\1119	. = ALIGN(PAGE_SIZE);						\1120	.data : AT(ADDR(.data) - LOAD_OFFSET) {				\1121		INIT_TASK_DATA(inittask)				\1122		NOSAVE_DATA						\1123		PAGE_ALIGNED_DATA(pagealigned)				\1124		CACHELINE_ALIGNED_DATA(cacheline)			\1125		READ_MOSTLY_DATA(cacheline)				\1126		DATA_DATA						\1127		CONSTRUCTORS						\1128	}								\1129	BUG_TABLE							\1130 1131#define INIT_TEXT_SECTION(inittext_align)				\1132	. = ALIGN(inittext_align);					\1133	.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {		\1134		_sinittext = .;						\1135		INIT_TEXT						\1136		_einittext = .;						\1137	}1138 1139#define INIT_DATA_SECTION(initsetup_align)				\1140	.init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {		\1141		INIT_DATA						\1142		INIT_SETUP(initsetup_align)				\1143		INIT_CALLS						\1144		CON_INITCALL						\1145		INIT_RAM_FS						\1146	}1147 1148#define BSS_SECTION(sbss_align, bss_align, stop_align)			\1149	. = ALIGN(sbss_align);						\1150	__bss_start = .;						\1151	SBSS(sbss_align)						\1152	BSS(bss_align)							\1153	. = ALIGN(stop_align);						\1154	__bss_stop = .;1155