blob: 8118363f1ef78218c4c3ebdad9ac3e4dbc02cf6f [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
63 /*
64 * Collect together the read-write data including .bss at the end which
65 * will be zero'd by the entry code. This is page aligned so it can be
66 * mapped as non-executable.
67 */
68 .data : ALIGN(4096) {
69 data_begin = .;
70 *(.data.*)
71 /*
72 * The entry point code assumes that .data is a multiple of 32
73 * bytes long.
74 */
75 . = ALIGN(32);
76 data_end = .;
77 } >writable_data AT>image
78 data_lma = LOADADDR(.data);
79
80 /* Everything beyond this point will not be included in the binary. */
Pierre-Clément Tosi3c6d4d42022-10-14 17:22:47 +010081 bin_end = data_lma + SIZEOF(.data);
Andrew Walbrana5b7af52022-07-06 15:06:20 +000082
83 /* The entry point code assumes that .bss is 16-byte aligned. */
84 .bss : ALIGN(16) {
85 bss_begin = .;
86 *(.bss.*)
87 *(COMMON)
88 . = ALIGN(16);
89 bss_end = .;
90 } >writable_data
91
Pierre-Clément Tosi23aba522023-04-21 17:03:50 +010092 init_stack_pointer = ORIGIN(writable_data) + LENGTH(writable_data);
Andrew Walbrana5b7af52022-07-06 15:06:20 +000093 .stack (NOLOAD) : ALIGN(4096) {
Pierre-Clément Tosi23aba522023-04-21 17:03:50 +010094 stack_limit = .;
95 . = init_stack_pointer;
Andrew Walbrana5b7af52022-07-06 15:06:20 +000096 } >writable_data
97
98 /*
99 * Remove unused sections from the image.
100 */
101 /DISCARD/ : {
102 /* The image loads itself so doesn't need these sections. */
103 *(.gnu.hash)
104 *(.hash)
105 *(.interp)
106 *(.eh_frame_hdr)
107 *(.eh_frame)
108 *(.note.gnu.build-id)
109 }
110}