blob: 61af60fd0126e39647683efa42fbacd80a9cd309 [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{
Andrew Walbrana5b7af52022-07-06 15:06:20 +000032 /*
33 * Collect together the code. This is page aligned so it can be mapped
34 * as executable-only.
35 */
Pierre-Clément Tosicbbb8492023-04-21 15:19:32 +010036 .text : ALIGN(4096) {
Pierre-Clément Tosi1f7c5232024-08-13 19:51:25 +010037 KEEP(*(.init.head));
38 *(.init.head)
Andrew Walbrana5b7af52022-07-06 15:06:20 +000039 text_begin = .;
40 *(.init.entry)
41 *(.init.*)
Andrew Walbrana5b7af52022-07-06 15:06:20 +000042 *(.text.*)
43 } >image
44 text_end = .;
45
46 /*
47 * Collect together read-only data. This is page aligned so it can be
48 * mapped as read-only and non-executable.
49 */
50 .rodata : ALIGN(4096) {
51 rodata_begin = .;
52 *(.rodata.*)
53 } >image
54 .got : {
55 *(.got)
56 } >image
57 rodata_end = .;
58
59 /*
60 * Collect together the read-write data including .bss at the end which
61 * will be zero'd by the entry code. This is page aligned so it can be
62 * mapped as non-executable.
63 */
64 .data : ALIGN(4096) {
65 data_begin = .;
66 *(.data.*)
67 /*
68 * The entry point code assumes that .data is a multiple of 32
69 * bytes long.
70 */
71 . = ALIGN(32);
72 data_end = .;
73 } >writable_data AT>image
74 data_lma = LOADADDR(.data);
75
76 /* Everything beyond this point will not be included in the binary. */
Pierre-Clément Tosi3c6d4d42022-10-14 17:22:47 +010077 bin_end = data_lma + SIZEOF(.data);
Andrew Walbrana5b7af52022-07-06 15:06:20 +000078
79 /* The entry point code assumes that .bss is 16-byte aligned. */
80 .bss : ALIGN(16) {
81 bss_begin = .;
82 *(.bss.*)
83 *(COMMON)
84 . = ALIGN(16);
85 bss_end = .;
86 } >writable_data
87
Pierre-Clément Tosibb657012024-11-28 22:06:32 +000088 /* Left unmapped, to catch overflows of the exception handler stack. */
89 .eh_stack_guard_page (NOLOAD) : ALIGN(4096) {
90 . += 4096;
91 } >writable_data
92
93 /* Exception handler stack, mapped read-write. */
94 .eh_stack (NOLOAD) : ALIGN(4096) {
95 eh_stack_limit = .;
96 . += 4096;
97 init_eh_stack_pointer = .;
98 } >writable_data
99
Pierre-Clément Tosi0d5434d2024-11-28 21:50:56 +0000100 /* Left unmapped, to catch overflows of the stack. */
101 .stack_guard_page (NOLOAD) : ALIGN(4096) {
102 . += 4096;
103 } >writable_data
104
105 /* Stack, mapped read-write (possibly partially). */
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000106 .stack (NOLOAD) : ALIGN(4096) {
Pierre-Clément Tosi23aba522023-04-21 17:03:50 +0100107 stack_limit = .;
Pierre-Clément Tosi0d5434d2024-11-28 21:50:56 +0000108 . = ALIGN(LENGTH(writable_data));
109 init_stack_pointer = .;
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000110 } >writable_data
111
Pierre-Clément Tosi67108c32023-06-30 11:04:02 +0000112 /* Make our Bionic stack protector compatible with mainline LLVM */
113 __stack_chk_guard = __bionic_tls + 40;
114
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000115 /*
116 * Remove unused sections from the image.
117 */
118 /DISCARD/ : {
119 /* The image loads itself so doesn't need these sections. */
120 *(.gnu.hash)
121 *(.hash)
122 *(.interp)
123 *(.eh_frame_hdr)
124 *(.eh_frame)
125 *(.note.gnu.build-id)
126 }
127}