RustForge

foundry

Foundry OS: the operating system built on the Rustbelt kernel

foundry / rust / link.ld
1332 bytes ยท raw
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
/* Linker script for user programs: a static executable loaded at 4 MiB into
   user space (USER_START = 0x80_0000_0000, see src/memory.rs). Each part
   starts on its own page so it can get its own page permissions:
   code = read+execute, rodata = read-only, data/bss = read+write.
   The `large` code model (see build.rs) names its sections .ltext, .lrodata,
   .ldata and .lbss, so those must be listed too -- otherwise the linker
   places them wherever it likes (e.g. code in a non-executable segment). */
ENTRY(_start)

PHDRS {
    text   PT_LOAD FLAGS(5);  /* R-X */
    rodata PT_LOAD FLAGS(4);  /* R-- */
    data   PT_LOAD FLAGS(6);  /* RW- */
}

SECTIONS {
    . = 0x8000400000;
    .text   : ALIGN(4K) { *(.text .text.* .ltext .ltext.*) } :text
    .rodata : ALIGN(4K) { *(.rodata .rodata.* .lrodata .lrodata.*) } :rodata
    /* Align the location counter itself, not just .data: a program with no
       .data at all (e.g. sleep) would otherwise get its .bss on the
       read-only .rodata page (the linker drops empty sections, alignment
       included) and crash on its first write to a static. */
    . = ALIGN(4K);
    .data   : { *(.data .data.* .ldata .ldata.* .got .got.*) } :data
    .bss    : ALIGN(8)  { *(.bss .bss.* .lbss .lbss.* COMMON) } :data
    /DISCARD/ : { *(.comment) *(.eh_frame*) *(.note*) }
}