-
Notifications
You must be signed in to change notification settings - Fork 8
/
gd32vf103.ld
218 lines (193 loc) · 6.42 KB
/
gd32vf103.ld
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* Copyright (c) 2019, Keith Packard
* Copyright (c) 2019-2020, Emil Renner Berthing
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*/
ENTRY(_start)
MEMORY
{
flash (rxai!w) : ORIGIN = 0x08000000 + __bootloader, LENGTH = __flash_size - __bootloader
ram (wxa!ri) : ORIGIN = 0x20000000, LENGTH = __ram_size
}
PHDRS
{
text PT_LOAD;
ram PT_LOAD;
ram_init PT_LOAD;
tls PT_TLS;
}
SECTIONS
{
PROVIDE(__stack = ORIGIN(ram) + LENGTH(ram));
.init : {
KEEP(*(.data.init.enter))
KEEP(*(.text.init.enter))
KEEP(*(SORT_BY_NAME(.init) SORT_BY_NAME(.init.*)))
} >flash AT>flash :text
.text : {
*(SORT_BY_ALIGNMENT(.text.unlikely) SORT_BY_ALIGNMENT(.text.unlikely.*))
*(.text.startup .text.startup.*)
*(.text .text.*)
*(.gnu.linkonce.t.*)
} >flash AT>flash :text
.fini : {
KEEP(*(.fini))
__text_end = .;
} >flash AT>flash :text
PROVIDE(__etext = __text_end);
PROVIDE(_etext = __text_end);
PROVIDE(etext = __text_end);
.rodata : {
*(.rdata)
*(.rodata .rodata.*)
*(.gnu.linkonce.r.*)
. = ALIGN(8);
*(.srodata.cst16)
*(.srodata.cst8)
*(.srodata.cst4)
*(.srodata.cst2)
*(.srodata .srodata.*)
*(.data.rel.ro .data.rel.ro.*)
*(.got .got.*)
} >flash AT>flash :text
. = ALIGN(8);
.preinit_array : {
PROVIDE_HIDDEN(__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN(__preinit_array_end = .);
} >flash AT>flash :text
.init_array : {
PROVIDE_HIDDEN(__init_array_start = .);
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP(*(.init_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o) .ctors))
PROVIDE_HIDDEN(__init_array_end = .);
} >flash AT>flash :text
.fini_array : {
PROVIDE_HIDDEN(__fini_array_start = .);
KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP(*(.fini_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o) .dtors))
PROVIDE_HIDDEN(__fini_array_end = .);
} >flash AT>flash :text
.ctors : {
KEEP(*crtbegin.o(.ctors))
KEEP(*crtbegin?.o(.ctors))
KEEP(*(EXCLUDE_FILE(*crtend.o *crtend?.o) .ctors))
KEEP(*(SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP(*(.ctors))
} >flash AT>flash :text
.dtors : {
KEEP(*crtbegin.o(.dtors))
KEEP(*crtbegin?.o(.dtors))
KEEP(*(EXCLUDE_FILE(*crtend.o *crtend?.o) .dtors))
KEEP(*(SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP(*(.dtors))
} >flash AT>flash :text
/*
* Data values which are preserved across reset
*/
.preserve (NOLOAD) : {
PROVIDE(__preserve_start__ = .);
KEEP(*(SORT_BY_NAME(.preserve.*)))
KEEP(*(.preserve))
PROVIDE(__preserve_end__ = .);
} >ram AT>ram :ram
. = ALIGN(4);
.data : ALIGN_WITH_INPUT {
PROVIDE(__data_start = .);
*(.ramtext .ramtext.*)
*(.data .data.*)
*(.gnu.linkonce.d.*)
. = ALIGN(8);
PROVIDE(__global_pointer$ = . + 0x800);
*(.sdata .sdata.* .sdata2.*)
*(.gnu.linkonce.s.*)
} >ram AT>flash :ram_init
PROVIDE(__data_source = LOADADDR(.data));
/* Thread local initialized data. This gets
* space allocated as it is expected to be placed
* in ram to be used as a template for TLS data blocks
* allocated at runtime. We're slightly abusing that
* by placing the data in flash where it will be copied
* into the allocate ram addresses by the existing
* data initialization code in crt0
*/
.tdata : ALIGN_WITH_INPUT {
PROVIDE(__tls_base = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
PROVIDE(__data_end = .);
} >ram AT>flash :tls :ram_init
PROVIDE(__tdata_source = LOADADDR(.tdata));
PROVIDE(__tdata_size = SIZEOF(.tdata));
PROVIDE(__edata = __data_end);
PROVIDE(_edata = __data_end);
PROVIDE(edata = __data_end);
PROVIDE(__data_size = __data_end - __data_start);
.tbss (NOLOAD) : {
PROVIDE(__bss_start = .);
*(.tbss .tbss.* .gnu.linkonce.tb.*)
*(.tcommon)
PROVIDE(__tls_end = .);
} >ram AT>ram :tls :ram
PROVIDE(__tbss_size = SIZEOF(.tbss));
PROVIDE(__tls_size = __tls_end - __tls_base);
/*
* The linker special cases .tbss segments which are
* identified as segments which are not loaded and are
* thread_local.
*
* For these segments, the linker does not advance 'dot'
* across them. We actually need memory allocated for tbss,
* so we create a special segment here just to make room
*/
.tbss_space (NOLOAD) : {
. = . + __tbss_size;
} >ram AT>ram :ram
.bss (NOLOAD) : {
*(.sbss*)
*(.gnu.linkonce.sb.*)
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(8);
__bss_end = .;
} >ram AT>ram :ram
PROVIDE(__end = __bss_end);
PROVIDE(_end = __bss_end);
PROVIDE(end = __bss_end);
PROVIDE(__bss_size = __bss_end - __bss_start);
/* Make the rest of memory available for heap storage */
PROVIDE(__heap_start = __end);
PROVIDE(__heap_end = __stack - (DEFINED(__stack_size) ? __stack_size : 0x800));
PROVIDE(__heap_size = __heap_end - __heap_start);
/* Define a stack region to make sure it fits in memory */
.stack __heap_end (NOLOAD) : {
. += (DEFINED(__stack_size) ? __stack_size : 0x800);
} >ram :ram
/* Throw away C++ exception handling information */
/DISCARD/ : {
*(.eh_frame .eh_frame.*)
*(.note .note.*)
}
}