1OUTPUT_FORMAT("elf%BITS%-littleriscv")
2/*
3 * LK linker script for single segment binaries.
4 */
5PHDRS
6{
7    code PT_LOAD FLAGS(5);   /* PF_R|PF_X */
8    rodata PT_LOAD FLAGS(4); /* PF_R */
9    data PT_LOAD FLAGS(6);   /* PF_R|PF_W */
10}
11
12ENTRY(_start)
13SECTIONS
14{
15    . = %KERNEL_BASE% + %KERNEL_LOAD_OFFSET%;
16
17    _start = .;
18    __rom_start = .;
19
20    /* text/read-only data */
21    /* set the load address to physical MEMBASE */
22    .text : AT(%MEMBASE% + %KERNEL_LOAD_OFFSET%) {
23        KEEP(*(.text.boot))
24        *(.text .text*)
25        *(.gnu.linkonce.t.*)
26    } :code
27
28    . = ALIGN(CONSTANT(MAXPAGESIZE));
29
30    .rodata : {
31        __rodata_start = .;
32        *(.rodata .rodata.* .gnu.linkonce.r.*)
33    } :rodata
34
35    /* trick to force any extra sections to be emitted here */
36    . = .;
37
38    __rodata_end = .;
39    __rom_end = . ;
40    . = ALIGN(CONSTANT(MAXPAGESIZE));
41    __data_start_rom = .;
42
43    .data : {
44        __data_start = .;
45        *(.data .data.* .gnu.linkonce.d.*)
46        __ctor_list = .;
47        KEEP(*(.ctors .init_array))
48        __ctor_end = .;
49        __dtor_list = .;
50        KEEP(*(.dtors .fini_array))
51        __dtor_end = .;
52        *(.got*)
53        *(.dynamic)
54    } :data
55
56    /* Try to put sdata and sbss near each other by putting sdata at the end of the data segment
57     * and sbss at the start of the bss segment. This maximizes reach of things referenced off of
58     * the global pointer. */
59    .sdata : {
60        __global_pointer$ = . + (4K / 2);
61        *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*)
62        *(.sdata .sdata.* .gnu.linkonce.s.*)
63    }
64
65    . = ALIGN(%BITS% / 8);
66    __data_end = .;
67    __bss_start = .;
68
69    .sbss : {
70        *(.dynsbss)
71        *(.sbss .sbss.* .gnu.linkonce.sb.*)
72        *(.scommon)
73    }
74
75    /* uninitialized data (in same segment as writable data) */
76    .bss : {
77        /* regular bss */
78        *(.bss .bss.*)
79        *(.gnu.linkonce.b.*)
80    }
81
82    . = ALIGN(%BITS% / 8);
83    __bss_end = .;
84
85    /* Align the end to ensure anything after the kernel ends up on its own pages */
86    . = ALIGN(CONSTANT(MAXPAGESIZE));
87    _end = .;
88
89    . = %KERNEL_BASE% + %MEMSIZE%;
90    _end_of_ram = .;
91
92    /* Strip unnecessary stuff */
93    /DISCARD/ : { *(.comment .note .eh_frame) }
94}
95
96