1180 lines · 33.5 KB · C
RawDownload
/* * Helper macros to support writing architecture specific * linker scripts. * * A minimal linker scripts has following content: * [This is a sample, architectures may have special requirements] * * OUTPUT_FORMAT(...) * OUTPUT_ARCH(...) * ENTRY(...) * SECTIONS * { *	. = START; *	__init_begin = .; *	HEAD_TEXT_SECTION *	INIT_TEXT_SECTION(PAGE_SIZE) *	INIT_DATA_SECTION(...) *	PERCPU_SECTION(CACHELINE_SIZE) *	__init_end = .; * *	_stext = .; *	TEXT_SECTION = 0 *	_etext = .; * *      _sdata = .; *	RO_DATA(PAGE_SIZE) *	RW_DATA(...) *	_edata = .; * *	EXCEPTION_TABLE(...) * *	BSS_SECTION(0, 0, 0) *	_end = .; * *	STABS_DEBUG *	DWARF_DEBUG *	ELF_DETAILS * *	DISCARDS		// must be the last * } * * [__init_begin, __init_end] is the init section that may be freed after init * 	// __init_begin and __init_end should be page aligned, so that we can *	// free the whole .init memory * [_stext, _etext] is the text section * [_sdata, _edata] is the data section * * Some of the included output section have their own set of constants. * Examples are: [__initramfs_start, __initramfs_end] for initramfs and *               [__nosave_begin, __nosave_end] for the nosave data */ #include <asm-generic/codetag.lds.h> #ifndef LOAD_OFFSET#define LOAD_OFFSET 0#endif /* * Only some architectures want to have the .notes segment visible in * a separate PT_NOTE ELF Program Header. When this happens, it needs * to be visible in both the kernel text's PT_LOAD and the PT_NOTE * Program Headers. In this case, though, the PT_LOAD needs to be made * the default again so that all the following sections don't also end * up in the PT_NOTE Program Header. */#ifdef EMITS_PT_NOTE#define NOTES_HEADERS		:text :note#define NOTES_HEADERS_RESTORE	__restore_ph : { *(.__restore_ph) } :text#else#define NOTES_HEADERS#define NOTES_HEADERS_RESTORE#endif /* * Some architectures have non-executable read-only exception tables. * They can be added to the RO_DATA segment by specifying their desired * alignment. */#ifdef RO_EXCEPTION_TABLE_ALIGN#define RO_EXCEPTION_TABLE	EXCEPTION_TABLE(RO_EXCEPTION_TABLE_ALIGN)#else#define RO_EXCEPTION_TABLE#endif /* Align . function alignment. */#define ALIGN_FUNCTION()  . = ALIGN(CONFIG_FUNCTION_ALIGNMENT) /* * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which * generates .data.identifier sections, which need to be pulled in with * .data. We don't want to pull in .data..other sections, which Linux * has defined. Same for text and bss. * * With LTO_CLANG, the linker also splits sections by default, so we need * these macros to combine the sections during the final link. * * With AUTOFDO_CLANG and PROPELLER_CLANG, by default, the linker splits * text sections and regroups functions into subsections. * * RODATA_MAIN is not used because existing code already defines .rodata.x * sections to be brought in with rodata. */#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG) || \defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)#define TEXT_MAIN .text .text.[0-9a-zA-Z_]*#else#define TEXT_MAIN .text#endif#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG)#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral* .data.$__unnamed_* .data.$L*#define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L*#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..L* .bss..compoundliteral*#define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*#else#define DATA_MAIN .data#define SDATA_MAIN .sdata#define RODATA_MAIN .rodata#define BSS_MAIN .bss#define SBSS_MAIN .sbss#endif /* * GCC 4.5 and later have a 32 bytes section alignment for structures. * Except GCC 4.9, that feels the need to align on 64 bytes. */#define STRUCT_ALIGNMENT 32#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT) /* * The order of the sched class addresses are important, as they are * used to determine the order of the priority of each sched class in * relation to each other. */#define SCHED_DATA				\	STRUCT_ALIGN();				\	__sched_class_highest = .;		\	*(__stop_sched_class)			\	*(__dl_sched_class)			\	*(__rt_sched_class)			\	*(__fair_sched_class)			\	*(__ext_sched_class)			\	*(__idle_sched_class)			\	__sched_class_lowest = .; /* The actual configuration determine if the init/exit sections * are handled as text/data or they can be discarded (which * often happens at runtime) */ #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE#define KEEP_PATCHABLE		KEEP(*(__patchable_function_entries))#define PATCHABLE_DISCARDS#else#define KEEP_PATCHABLE#define PATCHABLE_DISCARDS	*(__patchable_function_entries)#endif #ifndef CONFIG_ARCH_SUPPORTS_CFI_CLANG/* * Simply points to ftrace_stub, but with the proper protocol. * Defined by the linker script in linux/vmlinux.lds.h */#define	FTRACE_STUB_HACK	ftrace_stub_graph = ftrace_stub;#else#define FTRACE_STUB_HACK#endif #ifdef CONFIG_FTRACE_MCOUNT_RECORD/* * The ftrace call sites are logged to a section whose name depends on the * compiler option used. A given kernel image will only use one, AKA * FTRACE_CALLSITE_SECTION. We capture all of them here to avoid header * dependencies for FTRACE_CALLSITE_SECTION's definition. * * ftrace_ops_list_func will be defined as arch_ftrace_ops_list_func * as some archs will have a different prototype for that function * but ftrace_ops_list_func() will have a single prototype. */#define MCOUNT_REC()	. = ALIGN(8);				\			__start_mcount_loc = .;			\			KEEP(*(__mcount_loc))			\			KEEP_PATCHABLE				\			__stop_mcount_loc = .;			\			FTRACE_STUB_HACK			\			ftrace_ops_list_func = arch_ftrace_ops_list_func;#else# ifdef CONFIG_FUNCTION_TRACER#  define MCOUNT_REC()	FTRACE_STUB_HACK			\			ftrace_ops_list_func = arch_ftrace_ops_list_func;# else#  define MCOUNT_REC()# endif#endif #define BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_)	\	_BEGIN_##_label_ = .;						\	KEEP(*(_sec_))							\	_END_##_label_ = .; #define BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_)	\	_label_##_BEGIN_ = .;						\	KEEP(*(_sec_))							\	_label_##_END_ = .; #define BOUNDED_SECTION_BY(_sec_, _label_)				\	BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop) #define BOUNDED_SECTION(_sec)	 BOUNDED_SECTION_BY(_sec, _sec) #define HEADERED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_) \	_HDR_##_label_	= .;						\	KEEP(*(.gnu.linkonce.##_sec_))					\	BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_) #define HEADERED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_) \	_label_##_HDR_ = .;						\	KEEP(*(.gnu.linkonce.##_sec_))					\	BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_) #define HEADERED_SECTION_BY(_sec_, _label_)				\	HEADERED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop) #define HEADERED_SECTION(_sec)	 HEADERED_SECTION_BY(_sec, _sec) #ifdef CONFIG_TRACE_BRANCH_PROFILING#define LIKELY_PROFILE()						\	BOUNDED_SECTION_BY(_ftrace_annotated_branch, _annotated_branch_profile)#else#define LIKELY_PROFILE()#endif #ifdef CONFIG_PROFILE_ALL_BRANCHES#define BRANCH_PROFILE()					\	BOUNDED_SECTION_BY(_ftrace_branch, _branch_profile)#else#define BRANCH_PROFILE()#endif #ifdef CONFIG_KPROBES#define KPROBE_BLACKLIST()				\	. = ALIGN(8);					\	BOUNDED_SECTION(_kprobe_blacklist)#else#define KPROBE_BLACKLIST()#endif #ifdef CONFIG_FUNCTION_ERROR_INJECTION#define ERROR_INJECT_WHITELIST()			\	STRUCT_ALIGN();					\	BOUNDED_SECTION(_error_injection_whitelist)#else#define ERROR_INJECT_WHITELIST()#endif #ifdef CONFIG_EVENT_TRACING#define FTRACE_EVENTS()							\	. = ALIGN(8);							\	BOUNDED_SECTION(_ftrace_events)					\	BOUNDED_SECTION_BY(_ftrace_eval_map, _ftrace_eval_maps)#else#define FTRACE_EVENTS()#endif #ifdef CONFIG_TRACING#define TRACE_PRINTKS()		BOUNDED_SECTION_BY(__trace_printk_fmt, ___trace_bprintk_fmt)#define TRACEPOINT_STR()	BOUNDED_SECTION_BY(__tracepoint_str, ___tracepoint_str)#else#define TRACE_PRINTKS()#define TRACEPOINT_STR()#endif #ifdef CONFIG_FTRACE_SYSCALLS#define TRACE_SYSCALLS()			\	. = ALIGN(8);				\	BOUNDED_SECTION_BY(__syscalls_metadata, _syscalls_metadata)#else#define TRACE_SYSCALLS()#endif #ifdef CONFIG_BPF_EVENTS#define BPF_RAW_TP() STRUCT_ALIGN();				\	BOUNDED_SECTION_BY(__bpf_raw_tp_map, __bpf_raw_tp)#else#define BPF_RAW_TP()#endif #ifdef CONFIG_SERIAL_EARLYCON#define EARLYCON_TABLE()						\	. = ALIGN(8);							\	BOUNDED_SECTION_POST_LABEL(__earlycon_table, __earlycon_table, , _end)#else#define EARLYCON_TABLE()#endif #ifdef CONFIG_SECURITY#define LSM_TABLE()					\	. = ALIGN(8);					\	BOUNDED_SECTION_PRE_LABEL(.lsm_info.init, _lsm_info, __start, __end) #define EARLY_LSM_TABLE()						\	. = ALIGN(8);							\	BOUNDED_SECTION_PRE_LABEL(.early_lsm_info.init, _early_lsm_info, __start, __end)#else#define LSM_TABLE()#define EARLY_LSM_TABLE()#endif #define ___OF_TABLE(cfg, name)	_OF_TABLE_##cfg(name)#define __OF_TABLE(cfg, name)	___OF_TABLE(cfg, name)#define OF_TABLE(cfg, name)	__OF_TABLE(IS_ENABLED(cfg), name)#define _OF_TABLE_0(name)#define _OF_TABLE_1(name)						\	. = ALIGN(8);							\	__##name##_of_table = .;					\	KEEP(*(__##name##_of_table))					\	KEEP(*(__##name##_of_table_end)) #define TIMER_OF_TABLES()	OF_TABLE(CONFIG_TIMER_OF, timer)#define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip)#define CLK_OF_TABLES()		OF_TABLE(CONFIG_COMMON_CLK, clk)#define RESERVEDMEM_OF_TABLES()	OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem)#define CPU_METHOD_OF_TABLES()	OF_TABLE(CONFIG_SMP, cpu_method)#define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method) #ifdef CONFIG_ACPI#define ACPI_PROBE_TABLE(name)						\	. = ALIGN(8);							\	BOUNDED_SECTION_POST_LABEL(__##name##_acpi_probe_table,		\				   __##name##_acpi_probe_table,, _end)#else#define ACPI_PROBE_TABLE(name)#endif #ifdef CONFIG_THERMAL#define THERMAL_TABLE(name)						\	. = ALIGN(8);							\	BOUNDED_SECTION_POST_LABEL(__##name##_thermal_table,		\				   __##name##_thermal_table,, _end)#else#define THERMAL_TABLE(name)#endif #define KERNEL_DTB()							\	STRUCT_ALIGN();							\	__dtb_start = .;						\	KEEP(*(.dtb.init.rodata))					\	__dtb_end = .; /* * .data section */#define DATA_DATA							\	*(.xiptext)							\	*(DATA_MAIN)							\	*(.data..decrypted)						\	*(.ref.data)							\	*(.data..shared_aligned) /* percpu related */			\	*(.data..unlikely)						\	__start_once = .;						\	*(.data..once)							\	__end_once = .;							\	STRUCT_ALIGN();							\	*(__tracepoints)						\	/* implement dynamic printk debug */				\	. = ALIGN(8);							\	BOUNDED_SECTION_BY(__dyndbg_classes, ___dyndbg_classes)		\	BOUNDED_SECTION_BY(__dyndbg, ___dyndbg)				\	CODETAG_SECTIONS()						\	LIKELY_PROFILE()		       				\	BRANCH_PROFILE()						\	TRACE_PRINTKS()							\	BPF_RAW_TP()							\	TRACEPOINT_STR()						\	KUNIT_TABLE() /* * Data section helpers */#define NOSAVE_DATA							\	. = ALIGN(PAGE_SIZE);						\	__nosave_begin = .;						\	*(.data..nosave)						\	. = ALIGN(PAGE_SIZE);						\	__nosave_end = .; #define PAGE_ALIGNED_DATA(page_align)					\	. = ALIGN(page_align);						\	*(.data..page_aligned)						\	. = ALIGN(page_align); #define READ_MOSTLY_DATA(align)						\	. = ALIGN(align);						\	*(.data..read_mostly)						\	. = ALIGN(align); #define CACHELINE_ALIGNED_DATA(align)					\	. = ALIGN(align);						\	*(.data..cacheline_aligned) #define INIT_TASK_DATA(align)						\	. = ALIGN(align);						\	__start_init_stack = .;						\	init_thread_union = .;						\	init_stack = .;							\	KEEP(*(.data..init_task))					\	KEEP(*(.data..init_thread_info))				\	. = __start_init_stack + THREAD_SIZE;				\	__end_init_stack = .; #define JUMP_TABLE_DATA							\	. = ALIGN(8);							\	BOUNDED_SECTION_BY(__jump_table, ___jump_table) #ifdef CONFIG_HAVE_STATIC_CALL_INLINE#define STATIC_CALL_DATA						\	. = ALIGN(8);							\	BOUNDED_SECTION_BY(.static_call_sites, _static_call_sites)	\	BOUNDED_SECTION_BY(.static_call_tramp_key, _static_call_tramp_key)#else#define STATIC_CALL_DATA#endif /* * Allow architectures to handle ro_after_init data on their * own by defining an empty RO_AFTER_INIT_DATA. */#ifndef RO_AFTER_INIT_DATA#define RO_AFTER_INIT_DATA						\	. = ALIGN(8);							\	__start_ro_after_init = .;					\	*(.data..ro_after_init)						\	JUMP_TABLE_DATA							\	STATIC_CALL_DATA						\	__end_ro_after_init = .;#endif /* * .kcfi_traps contains a list KCFI trap locations. */#ifndef KCFI_TRAPS#ifdef CONFIG_ARCH_USES_CFI_TRAPS#define KCFI_TRAPS							\	__kcfi_traps : AT(ADDR(__kcfi_traps) - LOAD_OFFSET) {		\		BOUNDED_SECTION_BY(.kcfi_traps, ___kcfi_traps)		\	}#else#define KCFI_TRAPS#endif#endif /* * Read only Data */#define RO_DATA(align)							\	. = ALIGN((align));						\	.rodata           : AT(ADDR(.rodata) - LOAD_OFFSET) {		\		__start_rodata = .;					\		*(.rodata) *(.rodata.*)					\		SCHED_DATA						\		RO_AFTER_INIT_DATA	/* Read only after init */	\		. = ALIGN(8);						\		BOUNDED_SECTION_BY(__tracepoints_ptrs, ___tracepoints_ptrs) \		*(__tracepoints_strings)/* Tracepoints: strings */	\	}								\									\	.rodata1          : AT(ADDR(.rodata1) - LOAD_OFFSET) {		\		*(.rodata1)						\	}								\									\	/* PCI quirks */						\	.pci_fixup        : AT(ADDR(.pci_fixup) - LOAD_OFFSET) {	\		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_early,  _pci_fixups_early,  __start, __end) \		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_header, _pci_fixups_header, __start, __end) \		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_final,  _pci_fixups_final,  __start, __end) \		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_enable, _pci_fixups_enable, __start, __end) \		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_resume, _pci_fixups_resume, __start, __end) \		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_suspend, _pci_fixups_suspend, __start, __end) \		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_resume_early, _pci_fixups_resume_early, __start, __end) \		BOUNDED_SECTION_PRE_LABEL(.pci_fixup_suspend_late, _pci_fixups_suspend_late, __start, __end) \	}								\									\	FW_LOADER_BUILT_IN_DATA						\	TRACEDATA							\									\	PRINTK_INDEX							\									\	/* Kernel symbol table: Normal symbols */			\	__ksymtab         : AT(ADDR(__ksymtab) - LOAD_OFFSET) {		\		__start___ksymtab = .;					\		KEEP(*(SORT(___ksymtab+*)))				\		__stop___ksymtab = .;					\	}								\									\	/* Kernel symbol table: GPL-only symbols */			\	__ksymtab_gpl     : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) {	\		__start___ksymtab_gpl = .;				\		KEEP(*(SORT(___ksymtab_gpl+*)))				\		__stop___ksymtab_gpl = .;				\

Lines 1–500 of 1180.