blob: 01b7e3951a41978fefa6072536f4beb7e47f1485 [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) {
Andrew Walbrana5b7af52022-07-06 15:06:20 +000037 text_begin = .;
38 *(.init.entry)
39 *(.init.*)
Andrew Walbrana5b7af52022-07-06 15:06:20 +000040 *(.text.*)
41 } >image
42 text_end = .;
43
44 /*
45 * Collect together read-only data. This is page aligned so it can be
46 * mapped as read-only and non-executable.
47 */
48 .rodata : ALIGN(4096) {
49 rodata_begin = .;
50 *(.rodata.*)
51 } >image
52 .got : {
53 *(.got)
54 } >image
55 rodata_end = .;
56
Pierre-Clément Tosiccc11382023-04-21 16:44:53 +010057 .eh_stack (NOLOAD) : ALIGN(4096) {
58 /*
59 * Get stack overflow guard from the previous page being from
60 * .rodata and mapped read-only or left unmapped.
61 */
62 eh_stack_limit = .;
63 . += 4096;
64 . = ALIGN(4096);
65 init_eh_stack_pointer = .;
66 } >writable_data
67
Andrew Walbrana5b7af52022-07-06 15:06:20 +000068 /*
69 * Collect together the read-write data including .bss at the end which
70 * will be zero'd by the entry code. This is page aligned so it can be
71 * mapped as non-executable.
72 */
73 .data : ALIGN(4096) {
74 data_begin = .;
75 *(.data.*)
76 /*
77 * The entry point code assumes that .data is a multiple of 32
78 * bytes long.
79 */
80 . = ALIGN(32);
81 data_end = .;
82 } >writable_data AT>image
83 data_lma = LOADADDR(.data);
84
85 /* Everything beyond this point will not be included in the binary. */
Pierre-Clément Tosi3c6d4d42022-10-14 17:22:47 +010086 bin_end = data_lma + SIZEOF(.data);
Andrew Walbrana5b7af52022-07-06 15:06:20 +000087
88 /* The entry point code assumes that .bss is 16-byte aligned. */
89 .bss : ALIGN(16) {
90 bss_begin = .;
91 *(.bss.*)
92 *(COMMON)
93 . = ALIGN(16);
94 bss_end = .;
95 } >writable_data
96
Pierre-Clément Tosi23aba522023-04-21 17:03:50 +010097 init_stack_pointer = ORIGIN(writable_data) + LENGTH(writable_data);
Andrew Walbrana5b7af52022-07-06 15:06:20 +000098 .stack (NOLOAD) : ALIGN(4096) {
Pierre-Clément Tosiccc11382023-04-21 16:44:53 +010099 . += 4096; /* Ensure we have one guard page for overflow. */
Pierre-Clément Tosi23aba522023-04-21 17:03:50 +0100100 stack_limit = .;
101 . = init_stack_pointer;
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000102 } >writable_data
103
Pierre-Clément Tosi67108c32023-06-30 11:04:02 +0000104 /* Make our Bionic stack protector compatible with mainline LLVM */
105 __stack_chk_guard = __bionic_tls + 40;
106
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000107 /*
108 * Remove unused sections from the image.
109 */
110 /DISCARD/ : {
111 /* The image loads itself so doesn't need these sections. */
112 *(.gnu.hash)
113 *(.hash)
114 *(.interp)
115 *(.eh_frame_hdr)
116 *(.eh_frame)
117 *(.note.gnu.build-id)
118 }
119}