Minimal linker script
As per a comment in
include/asm-generic/vmlinux.lds.h
, a
minimal linker script has the following (sample) content (different architectures might have special requirements, however):
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. It may be freed after init.
__init_begin
and __init_end
should be page aligned, so that the whole .init
memory can be freed.
[_stext, _etext]
is the text section.
[_sdata, _edata]
is the data section.
x86
In my x86/64 environment, the head of the created file (i. e. arch/x86/kernel/vmlinux.lds
) looks like
OUTPUT_FORMAT("elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(phys_startup_64)
jiffies = jiffies_64;
PHDRS {
text PT_LOAD FLAGS(5);
data PT_LOAD FLAGS(6);
percpu PT_LOAD FLAGS(6);
init PT_LOAD FLAGS(7);
note PT_NOTE FLAGS(0);
}
SECTIONS
. = (0xffffffff80000000 + ALIGN(0x1000000, 0x200000));
phys_startup_64 = ABSOLUTE(startup_64 - 0xffffffff80000000);
The
ENTRY(…)
command specifies
phys_startup_64
as the
first instruction to be executed in the output file with this linker script.
Note that phys_startup_64
is defined to be ABSOLUTE(startup_64 - 0xffffffff80000000
).
The
PHDRS
command specifies the
program headers (which can be printed with
objdump -p
).