1/* Copyright 2018 The Fuchsia Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6/*
7 * This is the linker script for the final load image of the kernel.  The
8 * entire thing was assembled into a single .text section in one .o file
9 * (see kernel/$ARCH/image.S).  The purpose of this link is to resolve
10 * symbols used in image.S but defined in the kernel proper.  That's made
11 * possible by using ld's --just-symbols switch to copy the symbols from
12 * the kernel proper into this link.  That's how the boot loader headers in
13 * image.S can encode things like the entry point address, the exact load
14 * image size including KASLR fixup code, and the "end of .bss" memory
15 * reservation size.
16 *
17 * Boot loaders use only the raw binary load image extracted from this
18 * link, not the ELF file itself; image.S encodes the platform-specific
19 * headers the boot loaders look for at the beginning of the raw binary.
20 * Setting the .text address to its physical address is nice for looking at
21 * the ELF file and debugging the boot sequence, but it has no effect on
22 * the load image.  However, other loaders (e.g. qemu) actually use the ELF
23 * file container of the load image to guide their loading.  So we need
24 * this linker script to produce a PT_LOAD with the right p_paddr.
25 */
26
27ENTRY(IMAGE_ELF_ENTRY)
28
29SECTIONS {
30    . = IMAGE_LOAD_START;
31
32    .load_image : {
33        KEEP(*(.text))
34    } :load_image
35
36    IMAGE_RESERVE_END = IMAGE_MEMORY_END +
37        (DEFINED(IMAGE_RESERVE_SIZE) ? IMAGE_RESERVE_SIZE : 0);
38
39    /*
40     * When a boot loader is actually using the ELF headers, it needs to
41     * know how much memory to reserve after the load image (p_filesz is
42     * the load image, and p_memsz > p_filesz to indicate the extra space
43     * to reserve).  This ensures that the segment has the right p_memsz.
44     */
45    .bss : {
46        . += ABSOLUTE(IMAGE_RESERVE_END) - ABSOLUTE(.);
47        ASSERT(ABSOLUTE(.) == ABSOLUTE(IMAGE_RESERVE_END), "image layout bad");
48    }
49}
50
51PHDRS {
52    load_image PT_LOAD FLAGS(7); /* PF_R|PF_W|PF_X */
53}
54