aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/arch/x86_64/linker.ld
blob: 5724ecf260f14712cac495de8852fa57073afb89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
OUTPUT_FORMAT(elf64-x86-64)
OUTPUT_ARCH(i386:x86-64)

/* Excecution entry point symbol */
ENTRY(_start)

PHDRS
{
    requests    PT_LOAD     FLAGS((1 << 1) | (1 << 2)); /* Write + Read */
    text        PT_LOAD     FLAGS((1 << 0) | (1 << 2)); /* Execute + Read */
    rodata      PT_LOAD     FLAGS((1 << 2));            /* Read only */
    data        PT_LOAD     FLAGS((1 << 1) | (1 << 2)); /* Write + Read */
    dynamic     PT_DYNAMIC  FLAGS((1 << 1) | (1 << 2)); /* Dynamic PHDR for relocations */
}

SECTIONS
{
    /* Places kernel in the top 2GiB of the address space */
    . = 0xffffffff80000000;

    /* Used to get the beginning and end address of the kernel */
    __kernel_begin = .;

    .requests : {
        KEEP(*(.requests_start_marker))
        KEEP(*(.requests))
        KEEP(*(.requests_end_marker))
    } :requests

    . += CONSTANT(MAXPAGESIZE);

    /* code. multiboot header comes first */
    .text : {
        *(.text .text.*)
    } :text

    . += CONSTANT(MAXPAGESIZE);

    /* read only data */
    .rodata : {
        *(. .rodata.*)
    } :rodata

    /* init array symbols used to get start and end address of the array */
    .init_array : {
        __init_array = .;
        *(.init_array .init_array.*)
        __init_array_end = .;
    } :rodata

    . += CONSTANT(MAXPAGESIZE);

    /* read write data (initialized) */
    .data : {
        *(.data .data.*)
    } :data

    /* Dynamic section for relocations, both in its own PHDR and inside data PHDR */
    .dynamic : {
        *(.dynamic)
    } :data :dynamic

    . += CONSTANT(MAXPAGESIZE);

    /* read write data (uninitialized) and stack */
    .bss : {
        *(.bss .bss.*)
        *(COMMON)
    } :data

    /* Discard .note.* and .eh_frame since they may cause issues on some hosts */
    /DISCARD/ : {
        *(.eh_frame)
        *(.note .note.*)
    }

    __kernel_end = .;
}