]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/scripttempl/avr.sc
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / scripttempl / avr.sc
1 # Copyright (C) 2014-2023 Free Software Foundation, Inc.
2 #
3 # Copying and distribution of this file, with or without modification,
4 # are permitted in any medium without royalty provided the copyright
5 # notice and this notice are preserved.
6
7 # RODATA_PM_OFFSET
8 # If empty, .rodata sections will be part of .data. This is for
9 # devices where it is not possible to use LD* instructions to read
10 # from flash.
11 #
12 # If non-empty, .rodata is not part of .data and the .rodata
13 # objects are assigned addresses at an offest of RODATA_PM_OFFSET.
14 # This is for devices that feature reading from flash by means of
15 # LD* instructions, provided the addresses are offset by
16 # __RODATA_PM_OFFSET__ (which defaults to RODATA_PM_OFFSET).
17
18 cat <<EOF
19 /* Copyright (C) 2014-2023 Free Software Foundation, Inc.
20
21 Copying and distribution of this script, with or without modification,
22 are permitted in any medium without royalty provided the copyright
23 notice and this notice are preserved. */
24
25 OUTPUT_FORMAT("${OUTPUT_FORMAT}","${OUTPUT_FORMAT}","${OUTPUT_FORMAT}")
26 OUTPUT_ARCH(${ARCH})
27 EOF
28
29 test -n "${RELOCATING}" && cat <<EOF
30 __TEXT_REGION_LENGTH__ = DEFINED(__TEXT_REGION_LENGTH__) ? __TEXT_REGION_LENGTH__ : $TEXT_LENGTH;
31 __DATA_REGION_ORIGIN__ = DEFINED(__DATA_REGION_ORIGIN__) ? __DATA_REGION_ORIGIN__ : $DATA_ORIGIN;
32 __DATA_REGION_LENGTH__ = DEFINED(__DATA_REGION_LENGTH__) ? __DATA_REGION_LENGTH__ : $DATA_LENGTH;
33
34 ${EEPROM_LENGTH+__EEPROM_REGION_LENGTH__ = DEFINED(__EEPROM_REGION_LENGTH__) ? __EEPROM_REGION_LENGTH__ : $EEPROM_LENGTH;}
35 __FUSE_REGION_LENGTH__ = DEFINED(__FUSE_REGION_LENGTH__) ? __FUSE_REGION_LENGTH__ : $FUSE_LENGTH;
36 __LOCK_REGION_LENGTH__ = DEFINED(__LOCK_REGION_LENGTH__) ? __LOCK_REGION_LENGTH__ : $LOCK_LENGTH;
37 __SIGNATURE_REGION_LENGTH__ = DEFINED(__SIGNATURE_REGION_LENGTH__) ? __SIGNATURE_REGION_LENGTH__ : $SIGNATURE_LENGTH;
38 ${USER_SIGNATURE_LENGTH+__USER_SIGNATURE_REGION_LENGTH__ = DEFINED(__USER_SIGNATURE_REGION_LENGTH__) ? __USER_SIGNATURE_REGION_LENGTH__ : $USER_SIGNATURE_LENGTH;}
39 ${RODATA_PM_OFFSET+__RODATA_PM_OFFSET__ = DEFINED(__RODATA_PM_OFFSET__) ? __RODATA_PM_OFFSET__ : $RODATA_PM_OFFSET;}
40 MEMORY
41 {
42 text (rx) : ORIGIN = 0, LENGTH = __TEXT_REGION_LENGTH__
43 data (rw!x) : ORIGIN = __DATA_REGION_ORIGIN__, LENGTH = __DATA_REGION_LENGTH__
44 ${EEPROM_LENGTH+ eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = __EEPROM_REGION_LENGTH__}
45 $FUSE_NAME (rw!x) : ORIGIN = 0x820000, LENGTH = __FUSE_REGION_LENGTH__
46 lock (rw!x) : ORIGIN = 0x830000, LENGTH = __LOCK_REGION_LENGTH__
47 signature (rw!x) : ORIGIN = 0x840000, LENGTH = __SIGNATURE_REGION_LENGTH__
48 ${USER_SIGNATURE_LENGTH+ user_signatures (rw!x) : ORIGIN = 0x850000, LENGTH = __USER_SIGNATURE_REGION_LENGTH__}
49 }
50 EOF
51
52 cat <<EOF
53 SECTIONS
54 {
55 /* Read-only sections, merged into text segment: */
56 ${TEXT_DYNAMIC+${DYNAMIC}}
57 .hash ${RELOCATING-0} : { *(.hash) }
58 .dynsym ${RELOCATING-0} : { *(.dynsym) }
59 .dynstr ${RELOCATING-0} : { *(.dynstr) }
60 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
61 .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) }
62 .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) }
63
64 .rel.init ${RELOCATING-0} : { *(.rel.init) }
65 .rela.init ${RELOCATING-0} : { *(.rela.init) }
66 .rel.text ${RELOCATING-0} :
67 {
68 *(.rel.text)
69 ${RELOCATING+*(.rel.text.*)}
70 ${RELOCATING+*(.rel.gnu.linkonce.t*)}
71 }
72 .rela.text ${RELOCATING-0} :
73 {
74 *(.rela.text)
75 ${RELOCATING+*(.rela.text.*)}
76 ${RELOCATING+*(.rela.gnu.linkonce.t*)}
77 }
78 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
79 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
80 .rel.rodata ${RELOCATING-0} :
81 {
82 *(.rel.rodata)
83 ${RELOCATING+*(.rel.rodata.*)}
84 ${RELOCATING+*(.rel.gnu.linkonce.r*)}
85 }
86 .rela.rodata ${RELOCATING-0} :
87 {
88 *(.rela.rodata)
89 ${RELOCATING+*(.rela.rodata.*)}
90 ${RELOCATING+*(.rela.gnu.linkonce.r*)}
91 }
92 .rel.data ${RELOCATING-0} :
93 {
94 *(.rel.data)
95 ${RELOCATING+*(.rel.data.*)}
96 ${RELOCATING+*(.rel.gnu.linkonce.d*)}
97 }
98 .rela.data ${RELOCATING-0} :
99 {
100 *(.rela.data)
101 ${RELOCATING+*(.rela.data.*)}
102 ${RELOCATING+*(.rela.gnu.linkonce.d*)}
103 }
104 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
105 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
106 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
107 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
108 .rel.got ${RELOCATING-0} : { *(.rel.got) }
109 .rela.got ${RELOCATING-0} : { *(.rela.got) }
110 .rel.bss ${RELOCATING-0} : { *(.rel.bss) }
111 .rela.bss ${RELOCATING-0} : { *(.rela.bss) }
112 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
113 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
114
115 /* Internal text space or external memory. */
116 .text ${RELOCATING-0} :
117 {
118 ${RELOCATING+*(.vectors)
119 KEEP(*(.vectors))
120
121 /* For data that needs to reside in the lower 64k of progmem. */
122 *(.progmem.gcc*)
123
124 /* PR 13812: Placing the trampolines here gives a better chance
125 that they will be in range of the code that uses them. */
126 . = ALIGN(2);
127 __trampolines_start = . ;
128 /* The jump trampolines for the 16-bit limited relocs will reside here. */
129 *(.trampolines)
130 *(.trampolines*)
131 __trampolines_end = . ;
132
133 /* avr-libc expects these data to reside in lower 64K. */
134 *libprintf_flt.a:*(.progmem.data)
135 *libc.a:*(.progmem.data)
136
137 *(.progmem.*)
138
139 . = ALIGN(2);
140
141 /* For code that needs to reside in the lower 128k progmem. */
142 *(.lowtext)
143 *(.lowtext*)}
144
145 ${CONSTRUCTING+ __ctors_start = . ; }
146 ${CONSTRUCTING+ *(.ctors) }
147 ${CONSTRUCTING+ __ctors_end = . ; }
148 ${CONSTRUCTING+ __dtors_start = . ; }
149 ${CONSTRUCTING+ *(.dtors) }
150 ${CONSTRUCTING+ __dtors_end = . ; }
151 ${RELOCATING+KEEP(SORT(*)(.ctors))
152 KEEP(SORT(*)(.dtors))
153
154 /* From this point on, we do not bother about whether the insns are
155 below or above the 16 bits boundary. */
156 *(.init0) /* Start here after reset. */
157 KEEP (*(.init0))
158 *(.init1)
159 KEEP (*(.init1))
160 *(.init2) /* Clear __zero_reg__, set up stack pointer. */
161 KEEP (*(.init2))
162 *(.init3)
163 KEEP (*(.init3))
164 *(.init4) /* Initialize data and BSS. */
165 KEEP (*(.init4))
166 *(.init5)
167 KEEP (*(.init5))
168 *(.init6) /* C++ constructors. */
169 KEEP (*(.init6))
170 *(.init7)
171 KEEP (*(.init7))
172 *(.init8)
173 KEEP (*(.init8))
174 *(.init9) /* Call main(). */
175 KEEP (*(.init9))}
176 *(.text)
177 ${RELOCATING+. = ALIGN(2);
178 *(.text.*)
179 . = ALIGN(2);
180 *(.fini9) /* _exit() starts here. */
181 KEEP (*(.fini9))
182 *(.fini8)
183 KEEP (*(.fini8))
184 *(.fini7)
185 KEEP (*(.fini7))
186 *(.fini6) /* C++ destructors. */
187 KEEP (*(.fini6))
188 *(.fini5)
189 KEEP (*(.fini5))
190 *(.fini4)
191 KEEP (*(.fini4))
192 *(.fini3)
193 KEEP (*(.fini3))
194 *(.fini2)
195 KEEP (*(.fini2))
196 *(.fini1)
197 KEEP (*(.fini1))
198 *(.fini0) /* Infinite loop after program termination. */
199 KEEP (*(.fini0))
200
201 /* For code that needs not to reside in the lower progmem. */
202 *(.hightext)
203 *(.hightext*)
204
205 *(.progmemx.*)
206
207 . = ALIGN(2);
208
209 /* For tablejump instruction arrays. We do not relax
210 JMP / CALL instructions within these sections. */
211 *(.jumptables)
212 *(.jumptables*)
213
214 _etext = . ;}
215 } ${RELOCATING+ > text}
216 EOF
217
218 # Devices like ATtiny816 allow to read from flash memory by means of LD*
219 # instructions provided we add an offset of __RODATA_PM_OFFSET__ to the
220 # flash addresses.
221
222 if test -n "$RODATA_PM_OFFSET"; then
223 cat <<EOF
224 .rodata ${RELOCATING+ ADDR(.text) + SIZEOF (.text) + __RODATA_PM_OFFSET__ } ${RELOCATING-0} :
225 {
226 *(.rodata)
227 ${RELOCATING+ *(.rodata*)
228 *(.gnu.linkonce.r*)}
229 } ${RELOCATING+AT> text}
230 EOF
231 fi
232
233 cat <<EOF
234 .data ${RELOCATING-0} :
235 {
236 ${RELOCATING+ PROVIDE (__data_start = .) ; }
237 *(.data)
238 ${RELOCATING+ *(.data*)
239 *(.gnu.linkonce.d*)}
240 EOF
241
242 # Classical devices that don't show flash memory in the SRAM address space
243 # need .rodata to be part of .data because the compiler will use LD*
244 # instructions and LD* cannot access flash.
245
246 if test -z "$RODATA_PM_OFFSET" && test -n "${RELOCATING}"; then
247 cat <<EOF
248 *(.rodata) /* We need to include .rodata here if gcc is used */
249 *(.rodata*) /* with -fdata-sections. */
250 *(.gnu.linkonce.r*)
251 EOF
252 fi
253
254 cat <<EOF
255 ${RELOCATING+. = ALIGN(2);}
256 ${RELOCATING+ _edata = . ; }
257 ${RELOCATING+ PROVIDE (__data_end = .) ; }
258 } ${RELOCATING+ > data ${RELOCATING+AT> text}}
259
260 .bss ${RELOCATING+ ADDR(.data) + SIZEOF (.data)} ${RELOCATING-0} :${RELOCATING+ AT (ADDR (.bss))}
261 {
262 ${RELOCATING+ PROVIDE (__bss_start = .) ; }
263 *(.bss)
264 ${RELOCATING+ *(.bss*)}
265 ${RELOCATING+ *(COMMON)}
266 ${RELOCATING+ PROVIDE (__bss_end = .) ; }
267 } ${RELOCATING+ > data}
268
269 ${RELOCATING+ __data_load_start = LOADADDR(.data); }
270 ${RELOCATING+ __data_load_end = __data_load_start + SIZEOF(.data); }
271
272 /* Global data not cleared after reset. */
273 .noinit ${RELOCATING+ ADDR(.bss) + SIZEOF (.bss)} ${RELOCATING-0}: ${RELOCATING+ AT (ADDR (.noinit))}
274 {
275 ${RELOCATING+ PROVIDE (__noinit_start = .) ; }
276 *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*})
277 ${RELOCATING+ PROVIDE (__noinit_end = .) ; }
278 ${RELOCATING+ _end = . ; }
279 ${RELOCATING+ PROVIDE (__heap_start = .) ; }
280 } ${RELOCATING+ > data}
281 EOF
282
283 if test -n "${EEPROM_LENGTH}"; then
284 cat <<EOF
285
286 .eeprom ${RELOCATING-0}:
287 {
288 /* See .data above... */
289 KEEP(*(.eeprom*))
290 ${RELOCATING+ __eeprom_end = . ; }
291 } ${RELOCATING+ > eeprom}
292 EOF
293 fi
294
295 if test "$FUSE_NAME" = "fuse" ; then
296 cat <<EOF
297
298 .fuse ${RELOCATING-0}:
299 {
300 KEEP(*(.fuse))
301 ${RELOCATING+KEEP(*(.lfuse))
302 KEEP(*(.hfuse))
303 KEEP(*(.efuse))}
304 } ${RELOCATING+ > fuse}
305 EOF
306 fi
307
308 cat <<EOF
309
310 .lock ${RELOCATING-0}:
311 {
312 KEEP(*(.lock*))
313 } ${RELOCATING+ > lock}
314
315 .signature ${RELOCATING-0}:
316 {
317 KEEP(*(.signature*))
318 } ${RELOCATING+ > signature}
319 EOF
320
321 if test "$FUSE_NAME" = "config" ; then
322 cat <<EOF
323
324 .config ${RELOCATING-0}:
325 {
326 KEEP(*(.config*))
327 } ${RELOCATING+ > config}
328 EOF
329 fi
330
331 cat <<EOF
332
333 /* Stabs debugging sections. */
334 .stab 0 : { *(.stab) }
335 .stabstr 0 : { *(.stabstr) }
336 .stab.excl 0 : { *(.stab.excl) }
337 .stab.exclstr 0 : { *(.stab.exclstr) }
338 .stab.index 0 : { *(.stab.index) }
339 .stab.indexstr 0 : { *(.stab.indexstr) }
340 .comment 0 : { *(.comment) }
341 .note.gnu.build-id ${RELOCATING-0} : { *(.note.gnu.build-id) }
342 EOF
343
344 . $srcdir/scripttempl/DWARF.sc
345
346 cat <<EOF
347 }
348 EOF