Andrew Walbran | a5b7af5 | 2022-07-06 15:06:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * Code will start running at this symbol which is placed at the start of the |
| 19 | * image. |
| 20 | */ |
| 21 | ENTRY(entry) |
| 22 | |
| 23 | /* |
| 24 | * The following would be useful to check that .init code is not called back |
| 25 | * into once it has completed but it isn't supported by ld.lld. |
| 26 | * |
| 27 | * NOCROSSREFS_TO(.init .text) |
| 28 | */ |
| 29 | |
| 30 | SECTIONS |
| 31 | { |
| 32 | .dtb (NOLOAD) : { |
| 33 | dtb_begin = .; |
| 34 | . += LENGTH(dtb_region); |
| 35 | dtb_end = .; |
| 36 | } >dtb_region |
| 37 | |
| 38 | /* |
| 39 | * Collect together the code. This is page aligned so it can be mapped |
| 40 | * as executable-only. |
| 41 | */ |
| 42 | .init : ALIGN(4096) { |
| 43 | text_begin = .; |
| 44 | *(.init.entry) |
| 45 | *(.init.*) |
| 46 | } >image |
| 47 | .text : { |
| 48 | *(.text.*) |
| 49 | } >image |
| 50 | text_end = .; |
| 51 | |
| 52 | /* |
| 53 | * Collect together read-only data. This is page aligned so it can be |
| 54 | * mapped as read-only and non-executable. |
| 55 | */ |
| 56 | .rodata : ALIGN(4096) { |
| 57 | rodata_begin = .; |
| 58 | *(.rodata.*) |
| 59 | } >image |
| 60 | .got : { |
| 61 | *(.got) |
| 62 | } >image |
| 63 | rodata_end = .; |
| 64 | |
| 65 | /* |
| 66 | * Collect together the read-write data including .bss at the end which |
| 67 | * will be zero'd by the entry code. This is page aligned so it can be |
| 68 | * mapped as non-executable. |
| 69 | */ |
| 70 | .data : ALIGN(4096) { |
| 71 | data_begin = .; |
| 72 | *(.data.*) |
| 73 | /* |
| 74 | * The entry point code assumes that .data is a multiple of 32 |
| 75 | * bytes long. |
| 76 | */ |
| 77 | . = ALIGN(32); |
| 78 | data_end = .; |
| 79 | } >writable_data AT>image |
| 80 | data_lma = LOADADDR(.data); |
| 81 | |
| 82 | /* Everything beyond this point will not be included in the binary. */ |
Pierre-Clément Tosi | 3c6d4d4 | 2022-10-14 17:22:47 +0100 | [diff] [blame] | 83 | bin_end = data_lma + SIZEOF(.data); |
Andrew Walbran | a5b7af5 | 2022-07-06 15:06:20 +0000 | [diff] [blame] | 84 | |
| 85 | /* The entry point code assumes that .bss is 16-byte aligned. */ |
| 86 | .bss : ALIGN(16) { |
| 87 | bss_begin = .; |
| 88 | *(.bss.*) |
| 89 | *(COMMON) |
| 90 | . = ALIGN(16); |
| 91 | bss_end = .; |
| 92 | } >writable_data |
| 93 | |
| 94 | .stack (NOLOAD) : ALIGN(4096) { |
| 95 | boot_stack_begin = .; |
| 96 | . += 40 * 4096; |
| 97 | . = ALIGN(4096); |
| 98 | boot_stack_end = .; |
| 99 | } >writable_data |
| 100 | |
| 101 | /* |
| 102 | * Remove unused sections from the image. |
| 103 | */ |
| 104 | /DISCARD/ : { |
| 105 | /* The image loads itself so doesn't need these sections. */ |
| 106 | *(.gnu.hash) |
| 107 | *(.hash) |
| 108 | *(.interp) |
| 109 | *(.eh_frame_hdr) |
| 110 | *(.eh_frame) |
| 111 | *(.note.gnu.build-id) |
| 112 | } |
| 113 | } |