blob: 5232d30b35e9cf0182fbf6021892df65b0864e72 [file] [log] [blame]
Andrew Walbrana5b7af52022-07-06 15:06:20 +00001/*
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 */
21ENTRY(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
30SECTIONS
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 */
Pierre-Clément Tosicbbb8492023-04-21 15:19:32 +010042 .text : ALIGN(4096) {
Andrew Walbrana5b7af52022-07-06 15:06:20 +000043 text_begin = .;
44 *(.init.entry)
45 *(.init.*)
Andrew Walbrana5b7af52022-07-06 15:06:20 +000046 *(.text.*)
47 } >image
48 text_end = .;
49
50 /*
51 * Collect together read-only data. This is page aligned so it can be
52 * mapped as read-only and non-executable.
53 */
54 .rodata : ALIGN(4096) {
55 rodata_begin = .;
56 *(.rodata.*)
57 } >image
58 .got : {
59 *(.got)
60 } >image
61 rodata_end = .;
62
Pierre-Clément Tosiccc11382023-04-21 16:44:53 +010063 .eh_stack (NOLOAD) : ALIGN(4096) {
64 /*
65 * Get stack overflow guard from the previous page being from
66 * .rodata and mapped read-only or left unmapped.
67 */
68 eh_stack_limit = .;
69 . += 4096;
70 . = ALIGN(4096);
71 init_eh_stack_pointer = .;
72 } >writable_data
73
Andrew Walbrana5b7af52022-07-06 15:06:20 +000074 /*
75 * Collect together the read-write data including .bss at the end which
76 * will be zero'd by the entry code. This is page aligned so it can be
77 * mapped as non-executable.
78 */
79 .data : ALIGN(4096) {
80 data_begin = .;
81 *(.data.*)
82 /*
83 * The entry point code assumes that .data is a multiple of 32
84 * bytes long.
85 */
86 . = ALIGN(32);
87 data_end = .;
88 } >writable_data AT>image
89 data_lma = LOADADDR(.data);
90
91 /* Everything beyond this point will not be included in the binary. */
Pierre-Clément Tosi3c6d4d42022-10-14 17:22:47 +010092 bin_end = data_lma + SIZEOF(.data);
Andrew Walbrana5b7af52022-07-06 15:06:20 +000093
94 /* The entry point code assumes that .bss is 16-byte aligned. */
95 .bss : ALIGN(16) {
96 bss_begin = .;
97 *(.bss.*)
98 *(COMMON)
99 . = ALIGN(16);
100 bss_end = .;
101 } >writable_data
102
Pierre-Clément Tosi23aba522023-04-21 17:03:50 +0100103 init_stack_pointer = ORIGIN(writable_data) + LENGTH(writable_data);
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000104 .stack (NOLOAD) : ALIGN(4096) {
Pierre-Clément Tosiccc11382023-04-21 16:44:53 +0100105 . += 4096; /* Ensure we have one guard page for overflow. */
Pierre-Clément Tosi23aba522023-04-21 17:03:50 +0100106 stack_limit = .;
107 . = init_stack_pointer;
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000108 } >writable_data
109
110 /*
111 * Remove unused sections from the image.
112 */
113 /DISCARD/ : {
114 /* The image loads itself so doesn't need these sections. */
115 *(.gnu.hash)
116 *(.hash)
117 *(.interp)
118 *(.eh_frame_hdr)
119 *(.eh_frame)
120 *(.note.gnu.build-id)
121 }
122}