blob: ce9b6513a5627652285b24e4f41d791f680f092f [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 */
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
Pierre-Clément Tosibfe48312023-04-21 16:44:53 +010065 .eh_stack (NOLOAD) : ALIGN(4096) {
66 /*
67 * Get stack overflow guard from the previous page being from
68 * .rodata and mapped read-only or left unmapped.
69 */
70 eh_stack_limit = .;
71 . += 4096;
72 . = ALIGN(4096);
73 init_eh_stack_pointer = .;
74 } >writable_data
75
Andrew Walbrana5b7af52022-07-06 15:06:20 +000076 /*
77 * Collect together the read-write data including .bss at the end which
78 * will be zero'd by the entry code. This is page aligned so it can be
79 * mapped as non-executable.
80 */
81 .data : ALIGN(4096) {
82 data_begin = .;
83 *(.data.*)
84 /*
85 * The entry point code assumes that .data is a multiple of 32
86 * bytes long.
87 */
88 . = ALIGN(32);
89 data_end = .;
90 } >writable_data AT>image
91 data_lma = LOADADDR(.data);
92
93 /* Everything beyond this point will not be included in the binary. */
Pierre-Clément Tosi3c6d4d42022-10-14 17:22:47 +010094 bin_end = data_lma + SIZEOF(.data);
Andrew Walbrana5b7af52022-07-06 15:06:20 +000095
96 /* The entry point code assumes that .bss is 16-byte aligned. */
97 .bss : ALIGN(16) {
98 bss_begin = .;
99 *(.bss.*)
100 *(COMMON)
101 . = ALIGN(16);
102 bss_end = .;
103 } >writable_data
104
Pierre-Clément Tosi150ebc92023-04-21 17:03:50 +0100105 init_stack_pointer = ORIGIN(writable_data) + LENGTH(writable_data);
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000106 .stack (NOLOAD) : ALIGN(4096) {
Pierre-Clément Tosibfe48312023-04-21 16:44:53 +0100107 . += 4096; /* Ensure we have one guard page for overflow. */
Pierre-Clément Tosi150ebc92023-04-21 17:03:50 +0100108 stack_limit = .;
109 . = init_stack_pointer;
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000110 } >writable_data
111
112 /*
113 * Remove unused sections from the image.
114 */
115 /DISCARD/ : {
116 /* The image loads itself so doesn't need these sections. */
117 *(.gnu.hash)
118 *(.hash)
119 *(.interp)
120 *(.eh_frame_hdr)
121 *(.eh_frame)
122 *(.note.gnu.build-id)
123 }
124}