linux/include/asm-generic/vmlinux.lds.h

/*
 * 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
#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
#define NOTES_HEADERS_RESTORE
#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
#else
#define RO_EXCEPTION_TABLE
#endif

/* Align . function alignment. */
#define ALIGN_FUNCTION()

/*
 * 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.
 *
 * 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)
#define TEXT_MAIN
#define DATA_MAIN
#define SDATA_MAIN
#define RODATA_MAIN
#define BSS_MAIN
#define SBSS_MAIN
#else
#define TEXT_MAIN
#define DATA_MAIN
#define SDATA_MAIN
#define RODATA_MAIN
#define BSS_MAIN
#define SBSS_MAIN
#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
#define STRUCT_ALIGN()

/*
 * 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

/* 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
#define PATCHABLE_DISCARDS
#else
#define KEEP_PATCHABLE
#define PATCHABLE_DISCARDS
#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
#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()
#else
# ifdef CONFIG_FUNCTION_TRACER
#define MCOUNT_REC
# else
#define MCOUNT_REC
# endif
#endif

#define BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_)

#define BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_)

#define BOUNDED_SECTION_BY(_sec_, _label_)

#define BOUNDED_SECTION(_sec)

#define HEADERED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_)

#define HEADERED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_)

#define HEADERED_SECTION_BY(_sec_, _label_)

#define HEADERED_SECTION(_sec)

#ifdef CONFIG_TRACE_BRANCH_PROFILING
#define LIKELY_PROFILE
#else
#define LIKELY_PROFILE()
#endif

#ifdef CONFIG_PROFILE_ALL_BRANCHES
#define BRANCH_PROFILE
#else
#define BRANCH_PROFILE()
#endif

#ifdef CONFIG_KPROBES
#define KPROBE_BLACKLIST()
#else
#define KPROBE_BLACKLIST
#endif

#ifdef CONFIG_FUNCTION_ERROR_INJECTION
#define ERROR_INJECT_WHITELIST()
#else
#define ERROR_INJECT_WHITELIST
#endif

#ifdef CONFIG_EVENT_TRACING
#define FTRACE_EVENTS()
#else
#define FTRACE_EVENTS
#endif

#ifdef CONFIG_TRACING
#define TRACE_PRINTKS()
#define TRACEPOINT_STR()
#else
#define TRACE_PRINTKS
#define TRACEPOINT_STR
#endif

#ifdef CONFIG_FTRACE_SYSCALLS
#define TRACE_SYSCALLS()
#else
#define TRACE_SYSCALLS
#endif

#ifdef CONFIG_BPF_EVENTS
#define BPF_RAW_TP()
#else
#define BPF_RAW_TP
#endif

#ifdef CONFIG_SERIAL_EARLYCON
#define EARLYCON_TABLE()
#else
#define EARLYCON_TABLE
#endif

#ifdef CONFIG_SECURITY
#define LSM_TABLE()

#define EARLY_LSM_TABLE()
#else
#define LSM_TABLE
#define EARLY_LSM_TABLE
#endif

#define ___OF_TABLE(cfg, name)
#define __OF_TABLE(cfg, name)
#define OF_TABLE(cfg, name)
#define _OF_TABLE_0(name)
#define _OF_TABLE_1(name)

#define TIMER_OF_TABLES()
#define IRQCHIP_OF_MATCH_TABLE()
#define CLK_OF_TABLES()
#define RESERVEDMEM_OF_TABLES()
#define CPU_METHOD_OF_TABLES()
#define CPUIDLE_METHOD_OF_TABLES()

#ifdef CONFIG_ACPI
#define ACPI_PROBE_TABLE(name)
#else
#define ACPI_PROBE_TABLE
#endif

#ifdef CONFIG_THERMAL
#define THERMAL_TABLE(name)
#else
#define THERMAL_TABLE
#endif

#define KERNEL_DTB()

/*
 * .data section
 */
#define DATA_DATA

/*
 * Data section helpers
 */
#define NOSAVE_DATA

#define PAGE_ALIGNED_DATA(page_align)

#define READ_MOSTLY_DATA(align)

#define CACHELINE_ALIGNED_DATA(align)

#define INIT_TASK_DATA(align)

#define JUMP_TABLE_DATA

#ifdef CONFIG_HAVE_STATIC_CALL_INLINE
#define STATIC_CALL_DATA
#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
#endif

/*
 * .kcfi_traps contains a list KCFI trap locations.
 */
#ifndef KCFI_TRAPS
#ifdef CONFIG_ARCH_USES_CFI_TRAPS
#define KCFI_TRAPS
#else
#define KCFI_TRAPS
#endif
#endif

/*
 * Read only Data
 */
#define RO_DATA(align)


/*
 * Non-instrumentable text section
 */
#define NOINSTR_TEXT

/*
 * .text section. Map to function alignment to avoid address changes
 * during second ld run in second ld pass when generating System.map
 *
 * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead
 * code elimination is enabled, so these sections should be converted
 * to use ".." first.
 */
#define TEXT_TEXT


/* sched.text is aling to function alignment to secure we have same
 * address even at second ld pass when generating System.map */
#define SCHED_TEXT

/* spinlock.text is aling to function alignment to secure we have same
 * address even at second ld pass when generating System.map */
#define LOCK_TEXT

#define KPROBES_TEXT

#define ENTRY_TEXT

#define IRQENTRY_TEXT

#define SOFTIRQENTRY_TEXT

#define STATIC_CALL_TEXT

/* Section used for early init (in .S files) */
#define HEAD_TEXT

#define HEAD_TEXT_SECTION

/*
 * Exception table
 */
#define EXCEPTION_TABLE(align)

/*
 * .BTF
 */
#ifdef CONFIG_DEBUG_INFO_BTF
#define BTF
#else
#define BTF
#endif

/*
 * Init task
 */
#define INIT_TASK_DATA_SECTION(align)

#ifdef CONFIG_CONSTRUCTORS
#define KERNEL_CTORS()
#else
#define KERNEL_CTORS
#endif

/* init and exit section handling */
#define INIT_DATA

#define INIT_TEXT

#define EXIT_DATA						\

#define EXIT_TEXT							\

#define EXIT_CALL

/*
 * bss (Block Started by Symbol) - uninitialized data
 * zeroed during startup
 */
#define SBSS(sbss_align)

/*
 * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
 * sections to the front of bss.
 */
#ifndef BSS_FIRST_SECTIONS
#define BSS_FIRST_SECTIONS
#endif

#define BSS(bss_align)

/*
 * DWARF debug sections.
 * Symbols in the DWARF debugging sections are relative to
 * the beginning of the section so we begin them at 0.
 */
#define DWARF_DEBUG

/* Stabs debugging sections. */
#define STABS_DEBUG

/* Required sections not related to debugging. */
#define ELF_DETAILS

#ifdef CONFIG_GENERIC_BUG
#define BUG_TABLE
#else
#define BUG_TABLE
#endif

#ifdef CONFIG_UNWINDER_ORC
#define ORC_UNWIND_TABLE
#else
#define ORC_UNWIND_TABLE
#endif

/* Built-in firmware blobs */
#ifdef CONFIG_FW_LOADER
#define FW_LOADER_BUILT_IN_DATA
#else
#define FW_LOADER_BUILT_IN_DATA
#endif

#ifdef CONFIG_PM_TRACE
#define TRACEDATA
#else
#define TRACEDATA
#endif

#ifdef CONFIG_PRINTK_INDEX
#define PRINTK_INDEX
#else
#define PRINTK_INDEX
#endif

/*
 * Discard .note.GNU-stack, which is emitted as PROGBITS by the compiler.
 * Otherwise, the type of .notes section would become PROGBITS instead of NOTES.
 *
 * Also, discard .note.gnu.property, otherwise it forces the notes section to
 * be 8-byte aligned which causes alignment mismatches with the kernel's custom
 * 4-byte aligned notes.
 */
#define NOTES

#define INIT_SETUP(initsetup_align)

#define INIT_CALLS_LEVEL(level)			\

#define INIT_CALLS

#define CON_INITCALL

#define NAMED_SECTION(name)

#define RUNTIME_CONST(t,x)

#define RUNTIME_CONST_VARIABLES

/* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */
#define KUNIT_TABLE()

/* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */
#define KUNIT_INIT_TABLE()

#ifdef CONFIG_BLK_DEV_INITRD
#define INIT_RAM_FS
#else
#define INIT_RAM_FS
#endif

/*
 * Memory encryption operates on a page basis. Since we need to clear
 * the memory encryption mask for this section, it needs to be aligned
 * on a page boundary and be a page-size multiple in length.
 *
 * Note: We use a separate section so that only this section gets
 * decrypted to avoid exposing more than we wish.
 */
#ifdef CONFIG_AMD_MEM_ENCRYPT
#define PERCPU_DECRYPTED_SECTION
#else
#define PERCPU_DECRYPTED_SECTION
#endif


/*
 * Default discarded sections.
 *
 * Some archs want to discard exit text/data at runtime rather than
 * link time due to cross-section references such as alt instructions,
 * bug table, eh_frame, etc.  DISCARDS must be the last of output
 * section definitions so that such archs put those in earlier section
 * definitions.
 */
#ifdef RUNTIME_DISCARD_EXIT
#define EXIT_DISCARDS
#else
#define EXIT_DISCARDS
#endif

/*
 * Clang's -fprofile-arcs, -fsanitize=kernel-address, and
 * -fsanitize=thread produce unwanted sections (.eh_frame
 * and .init_array.*), but CONFIG_CONSTRUCTORS wants to
 * keep any .init_array.* sections.
 * https://llvm.org/pr46478
 */
#ifdef CONFIG_UNWIND_TABLES
#define DISCARD_EH_FRAME
#else
#define DISCARD_EH_FRAME
#endif
#if defined(CONFIG_GCOV_KERNEL) || defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KCSAN)
# ifdef CONFIG_CONSTRUCTORS
#define SANITIZER_DISCARDS
# else
#define SANITIZER_DISCARDS
# endif
#else
#define SANITIZER_DISCARDS
#endif

#define COMMON_DISCARDS						\

#define DISCARDS

/**
 * PERCPU_INPUT - the percpu input sections
 * @cacheline: cacheline size
 *
 * The core percpu section names and core symbols which do not rely
 * directly upon load addresses.
 *
 * @cacheline is used to align subsections to avoid false cacheline
 * sharing between subsections for different purposes.
 */
#define PERCPU_INPUT(cacheline)

/**
 * PERCPU_VADDR - define output section for percpu area
 * @cacheline: cacheline size
 * @vaddr: explicit base address (optional)
 * @phdr: destination PHDR (optional)
 *
 * Macro which expands to output section for percpu area.
 *
 * @cacheline is used to align subsections to avoid false cacheline
 * sharing between subsections for different purposes.
 *
 * If @vaddr is not blank, it specifies explicit base address and all
 * percpu symbols will be offset from the given address.  If blank,
 * @vaddr always equals @laddr + LOAD_OFFSET.
 *
 * @phdr defines the output PHDR to use if not blank.  Be warned that
 * output PHDR is sticky.  If @phdr is specified, the next output
 * section in the linker script will go there too.  @phdr should have
 * a leading colon.
 *
 * Note that this macros defines __per_cpu_load as an absolute symbol.
 * If there is no need to put the percpu section at a predetermined
 * address, use PERCPU_SECTION.
 */
#define PERCPU_VADDR(cacheline, vaddr, phdr)

/**
 * PERCPU_SECTION - define output section for percpu area, simple version
 * @cacheline: cacheline size
 *
 * Align to PAGE_SIZE and outputs output section for percpu area.  This
 * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and
 * __per_cpu_start will be identical.
 *
 * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,)
 * except that __per_cpu_load is defined as a relative symbol against
 * .data..percpu which is required for relocatable x86_32 configuration.
 */
#define PERCPU_SECTION(cacheline)


/*
 * Definition of the high level *_SECTION macros
 * They will fit only a subset of the architectures
 */


/*
 * Writeable data.
 * All sections are combined in a single .data section.
 * The sections following CONSTRUCTORS are arranged so their
 * typical alignment matches.
 * A cacheline is typical/always less than a PAGE_SIZE so
 * the sections that has this restriction (or similar)
 * is located before the ones requiring PAGE_SIZE alignment.
 * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which
 * matches the requirement of PAGE_ALIGNED_DATA.
 *
 * use 0 as page_align if page_aligned data is not used */
#define RW_DATA(cacheline, pagealigned, inittask)							\

#define INIT_TEXT_SECTION(inittext_align)

#define INIT_DATA_SECTION(initsetup_align)

#define BSS_SECTION(sbss_align, bss_align, stop_align)