1 # Copyright (C) 2014-2025 Free Software Foundation, Inc.
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.
8 # If empty and not HAVE_FLMAP, .rodata sections will be part of .data.
9 # This is for devices where it is not possible to use LD* instructions
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).
19 # The .rodata section is located in program memory. Devices from
20 # the AVR64* and AVR128* families (from avrxmega2 and avrxmega4)
21 # see a 32k segment of their program memory in their RAM address
22 # space. Which 32k segment is visible is determined by the
23 # bit-field NVMCTRL_CTRLB.FLMAP.
24 # Output section .rodata is placed in MEMORY region rodata.
25 # The LMA of the .rodata section can be set by means of:
26 # * __RODATA_FLASH_START__ specifies the byte address of the
28 # * __flmap specifies which 32k block is visible in RAM provided
29 # __RODATA_FLASH_START__ is undefined
30 # * When __flmap and __RODATA_FLASH_START__ are undefined, then an
31 # emulation-specific default is used (the last 32k block).
34 # For devices from avrxmega2 and avrxmega4: The user can chose whether
35 # or not .rodata is located in flash (if HAVE_FLMAP) or located in
36 # in RAM (if not HAVE_FLMAP by means of -mrodata-in-ram). This is
37 # achieved by new emulations avrxmega2_flmap and avrxmega4_flmap that
38 # are selected by compiler option -mno-rodata-in-ram.
40 # In order to facilitate initialization of NVMCTRL_CTRLB.FLMAP and
41 # NVMCTRL_CTRLB.FLMAPLOCK in the startup code irrespective of
42 # HAVE_FLMAP, the following symbols are used / defined in order to
43 # communicate with the startup code.
44 # Notice that the hardware default for FLMAP is the last 32k block,
45 # so that explicit initialization of FLMAP is only required when the
46 # user wants to deviate from the defaults.
48 # __flmap = HAVE_FLMAP
49 # ? given by __flmap resp. __RODATA_FLASH_START__ >> 15
52 # __flmap_value = __flmap << __flmap_bpos;
54 # __flmap_value_with_lock = __flmap__value | __flmap_lock_mask;
56 # __flmap_init_label = HAVE_FLMAP
57 # ? __flmap_init_start
58 # : __flmap_noinit_start;
59 # Supposed to be used as a jump target for RJMP so that the code
60 # can initialize FLMAP / skip initialization of FLMAP depending
61 # on the chosen emulation, and without the need to support two code
62 # versions of crt<mcu>.o for the two possible emulations.
64 # __flmap_lock is a bool provided by the user when FLMAP should be
65 # protected from any further changes.
67 # __flmap_lock_mask is an 8-bit mask like NVMCTRL_FLMAPLOCK_bm
68 # provided by the user which is set in __flmap_value_with_lock
69 # when __flmap_lock is on.
71 # __do_init_flmap = HAVE_FLMAP ? 1 : 0;
72 # Whether or not FLMAP is supposed to be initialized according
73 # to, and for the purpose of, .rodata in flash.
75 # Apart from that, the compiler (device-specs actually) defines the
79 # Defined if a device has the NVMCTRL_CTRLB.FLMAP bitfield
80 # *AND* if it's unknown at compile-time / assembler-time whether
81 # emulation avrxmega* is used or avrxmega*_flmap.
84 /* Copyright (C) 2014-2025 Free Software Foundation, Inc.
86 Copying and distribution of this script, with or without modification,
87 are permitted in any medium without royalty provided the copyright
88 notice and this notice are preserved. */
90 OUTPUT_FORMAT("${OUTPUT_FORMAT}","${OUTPUT_FORMAT}","${OUTPUT_FORMAT}")
94 test -n "${RELOCATING}" && cat <<EOF
95 __TEXT_REGION_ORIGIN__ = DEFINED(__TEXT_REGION_ORIGIN__) ? __TEXT_REGION_ORIGIN__ : 0;
96 __TEXT_REGION_LENGTH__ = DEFINED(__TEXT_REGION_LENGTH__) ? __TEXT_REGION_LENGTH__ : $TEXT_LENGTH;
97 __DATA_REGION_ORIGIN__ = DEFINED(__DATA_REGION_ORIGIN__) ? __DATA_REGION_ORIGIN__ : $DATA_ORIGIN;
98 __DATA_REGION_LENGTH__ = DEFINED(__DATA_REGION_LENGTH__) ? __DATA_REGION_LENGTH__ : $DATA_LENGTH;
100 ${EEPROM_LENGTH+__EEPROM_REGION_LENGTH__ = DEFINED(__EEPROM_REGION_LENGTH__) ? __EEPROM_REGION_LENGTH__ : $EEPROM_LENGTH;}
101 __FUSE_REGION_LENGTH__ = DEFINED(__FUSE_REGION_LENGTH__) ? __FUSE_REGION_LENGTH__ : $FUSE_LENGTH;
102 __LOCK_REGION_LENGTH__ = DEFINED(__LOCK_REGION_LENGTH__) ? __LOCK_REGION_LENGTH__ : $LOCK_LENGTH;
103 __SIGNATURE_REGION_LENGTH__ = DEFINED(__SIGNATURE_REGION_LENGTH__) ? __SIGNATURE_REGION_LENGTH__ : $SIGNATURE_LENGTH;
104 ${USER_SIGNATURE_LENGTH+__USER_SIGNATURE_REGION_LENGTH__ = DEFINED(__USER_SIGNATURE_REGION_LENGTH__) ? __USER_SIGNATURE_REGION_LENGTH__ : $USER_SIGNATURE_LENGTH;}
105 ${RODATA_PM_OFFSET+__RODATA_PM_OFFSET__ = DEFINED(__RODATA_PM_OFFSET__) ? __RODATA_PM_OFFSET__ : $RODATA_PM_OFFSET;}
106 ${HAVE_FLMAP+__RODATA_VMA__ = ${RODATA_VMA};}
107 ${HAVE_FLMAP+__RODATA_LDS_OFFSET__ = DEFINED(__RODATA_LDS_OFFSET__) ? __RODATA_LDS_OFFSET__ : ${RODATA_LDS_OFFSET};}
108 ${HAVE_FLMAP+__RODATA_REGION_LENGTH__ = DEFINED(__RODATA_REGION_LENGTH__) ? __RODATA_REGION_LENGTH__ : ${RODATA_LENGTH};}
109 ${HAVE_FLMAP+__RODATA_ORIGIN__ = __RODATA_VMA__ + __RODATA_LDS_OFFSET__;}
112 text (rx) : ORIGIN = __TEXT_REGION_ORIGIN__, LENGTH = __TEXT_REGION_LENGTH__
113 data (rw!x) : ORIGIN = __DATA_REGION_ORIGIN__, LENGTH = __DATA_REGION_LENGTH__
114 ${EEPROM_LENGTH+ eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = __EEPROM_REGION_LENGTH__}
115 $FUSE_NAME (rw!x) : ORIGIN = 0x820000, LENGTH = __FUSE_REGION_LENGTH__
116 lock (rw!x) : ORIGIN = 0x830000, LENGTH = __LOCK_REGION_LENGTH__
117 signature (rw!x) : ORIGIN = 0x840000, LENGTH = __SIGNATURE_REGION_LENGTH__
118 ${USER_SIGNATURE_LENGTH+ user_signatures (rw!x) : ORIGIN = 0x850000, LENGTH = __USER_SIGNATURE_REGION_LENGTH__}
119 ${HAVE_FLMAP+ rodata (r!x) : ORIGIN = __RODATA_ORIGIN__, LENGTH = __RODATA_REGION_LENGTH__}
126 /* Read-only sections, merged into text segment: */
127 ${TEXT_DYNAMIC+${DYNAMIC}}
128 .hash ${RELOCATING-0} : { *(.hash) }
129 .dynsym ${RELOCATING-0} : { *(.dynsym) }
130 .dynstr ${RELOCATING-0} : { *(.dynstr) }
131 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
132 .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) }
133 .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) }
135 .rel.init ${RELOCATING-0} : { *(.rel.init) }
136 .rela.init ${RELOCATING-0} : { *(.rela.init) }
137 .rel.text ${RELOCATING-0} :
140 ${RELOCATING+*(.rel.text.*)}
141 ${RELOCATING+*(.rel.gnu.linkonce.t*)}
143 .rela.text ${RELOCATING-0} :
146 ${RELOCATING+*(.rela.text.*)}
147 ${RELOCATING+*(.rela.gnu.linkonce.t*)}
149 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
150 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
151 .rel.rodata ${RELOCATING-0} :
154 ${RELOCATING+*(.rel.rodata.*)}
155 ${RELOCATING+*(.rel.gnu.linkonce.r*)}
157 .rela.rodata ${RELOCATING-0} :
160 ${RELOCATING+*(.rela.rodata.*)}
161 ${RELOCATING+*(.rela.gnu.linkonce.r*)}
163 .rel.data ${RELOCATING-0} :
166 ${RELOCATING+*(.rel.data.*)}
167 ${RELOCATING+*(.rel.gnu.linkonce.d*)}
169 .rela.data ${RELOCATING-0} :
172 ${RELOCATING+*(.rela.data.*)}
173 ${RELOCATING+*(.rela.gnu.linkonce.d*)}
175 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
176 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
177 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
178 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
179 .rel.got ${RELOCATING-0} : { *(.rel.got) }
180 .rela.got ${RELOCATING-0} : { *(.rela.got) }
181 .rel.bss ${RELOCATING-0} : { *(.rel.bss) }
182 .rela.bss ${RELOCATING-0} : { *(.rela.bss) }
183 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
184 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
186 /* Internal text space or external memory. */
187 .text ${RELOCATING-0} :
189 ${RELOCATING+*(.vectors)
192 /* For data that needs to reside in the lower 64k of progmem. */
195 /* PR 13812: Placing the trampolines here gives a better chance
196 that they will be in range of the code that uses them. */
198 __trampolines_start = . ;
199 /* The jump trampolines for the 16-bit limited relocs will reside here. */
202 __trampolines_end = . ;
204 /* avr-libc expects these data to reside in lower 64K. */
205 *libprintf_flt.a:*(.progmem.data)
206 *libc.a:*(.progmem.data)
212 /* For code that needs to reside in the lower 128k progmem. */
216 ${CONSTRUCTING+ __ctors_start = . ; }
217 ${CONSTRUCTING+ *(.ctors) }
218 ${CONSTRUCTING+ __ctors_end = . ; }
219 ${CONSTRUCTING+ __dtors_start = . ; }
220 ${CONSTRUCTING+ *(.dtors) }
221 ${CONSTRUCTING+ __dtors_end = . ; }
222 ${RELOCATING+KEEP(SORT(*)(.ctors))
223 KEEP(SORT(*)(.dtors))
225 /* From this point on, we do not bother about whether the insns are
226 below or above the 16 bits boundary. */
227 *(.init0) /* Start here after reset. */
231 *(.init2) /* Clear __zero_reg__, set up stack pointer. */
235 *(.init4) /* Initialize data and BSS. */
239 *(.init6) /* C++ constructors. */
245 *(.init9) /* Call main(). */
248 ${RELOCATING+. = ALIGN(2);
251 *(.fini9) /* _exit() starts here. */
257 *(.fini6) /* C++ destructors. */
269 *(.fini0) /* Infinite loop after program termination. */
272 /* For code that needs not to reside in the lower progmem. */
280 /* For tablejump instruction arrays. We do not relax
281 JMP / CALL instructions within these sections. */
286 } ${RELOCATING+ > text}
289 # Devices like ATtiny816 allow to read from flash memory by means of LD*
290 # instructions provided we add an offset of __RODATA_PM_OFFSET__ to the
293 if test -n "$RODATA_PM_OFFSET"; then
295 .rodata ${RELOCATING+ ADDR(.text) + SIZEOF (.text) + __RODATA_PM_OFFSET__ } ${RELOCATING-0} :
298 ${RELOCATING+ *(.rodata*)
300 } ${RELOCATING+AT> text}
305 .data ${RELOCATING-0} :
307 ${RELOCATING+ PROVIDE (__data_start = .) ; }
309 ${RELOCATING+ *(.data*)
313 # Classical devices that don't show flash memory in the SRAM address space
314 # need .rodata to be part of .data because the compiler will use LD*
315 # instructions and LD* cannot access flash.
317 if test -z "$RODATA_PM_OFFSET" && test -z "${HAVE_FLMAP}" && test -n "${RELOCATING}"; then
319 *(.rodata) /* We need to include .rodata here if gcc is used */
320 *(.rodata*) /* with -fdata-sections. */
326 ${RELOCATING+. = ALIGN(2);}
327 ${RELOCATING+ _edata = . ; }
328 ${RELOCATING+ PROVIDE (__data_end = .) ; }
329 } ${RELOCATING+ > data ${RELOCATING+AT> text}}
331 .bss ${RELOCATING+ ADDR(.data) + SIZEOF (.data)} ${RELOCATING-0} :${RELOCATING+ AT (ADDR (.bss))}
333 ${RELOCATING+ PROVIDE (__bss_start = .) ; }
335 ${RELOCATING+ *(.bss*)}
336 ${RELOCATING+ *(COMMON)}
337 ${RELOCATING+ PROVIDE (__bss_end = .) ; }
338 } ${RELOCATING+ > data}
340 ${RELOCATING+ __data_load_start = LOADADDR(.data); }
341 ${RELOCATING+ __data_load_end = __data_load_start + SIZEOF(.data); }
343 /* Global data not cleared after reset. */
344 .noinit ${RELOCATING+ ADDR(.bss) + SIZEOF (.bss)} ${RELOCATING-0}: ${RELOCATING+ AT (ADDR (.noinit))}
346 ${RELOCATING+ PROVIDE (__noinit_start = .) ; }
347 *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*})
348 ${RELOCATING+ PROVIDE (__noinit_end = .) ; }
349 ${RELOCATING+ _end = . ; }
350 ${RELOCATING+ PROVIDE (__heap_start = .) ; }
351 } ${RELOCATING+ > data}
354 # Devices like AVR128DA32 and AVR64DA32 see a 32 KiB block of their program
355 # memory at 0x8000 (RODATA_LDS_OFFSET). Which portion will be determined by
356 # bitfield NVMCTRL_CTRLB.FLMAP.
358 if test -z "${HAVE_FLMAP}" && test -n "${RELOCATING}"; then
361 __flmap_init_label = DEFINED(__flmap_noinit_start) ? __flmap_noinit_start : 0 ;
362 __flmap = DEFINED(__flmap) ? __flmap : 0 ;
367 if test -n "${HAVE_FLMAP}"; then
371 __flmap_init_label = DEFINED(__flmap_init_start) ? __flmap_init_start : 0 ;
372 /* User can specify position of .rodata in flash (LMA) by supplying
373 __RODATA_FLASH_START__ or __flmap, where the former takes precedence. */
374 __RODATA_FLASH_START__ = DEFINED(__RODATA_FLASH_START__)
375 ? __RODATA_FLASH_START__
376 : DEFINED(__flmap) ? __flmap * 32K : ${RODATA_FLASH_START};
377 ASSERT (__RODATA_FLASH_START__ % 32K == 0, \"__RODATA_FLASH_START__ must be a multiple of 32 KiB\")
378 __flmap = ${FLMAP_MASK} & (__RODATA_FLASH_START__ >> 15);
379 __RODATA_FLASH_START__ = __flmap << 15;
380 __rodata_load_start = MAX (__data_load_end, __RODATA_FLASH_START__);
381 __rodata_start = __RODATA_ORIGIN__ + __rodata_load_start - __RODATA_FLASH_START__;}
383 .rodata ${RELOCATING+ __rodata_start} ${RELOCATING-0} : ${RELOCATING+ AT (__rodata_load_start)}
386 ${RELOCATING+ *(.rodata*)}
387 ${RELOCATING+ *(.gnu.linkonce.r*)}
388 ${RELOCATING+ __rodata_end = ABSOLUTE(.) ;}
389 } ${RELOCATING+ > rodata}
391 ${RELOCATING+ __rodata_load_end = __rodata_load_start + __rodata_end - __rodata_start;}
396 if test -n "${MAYBE_FLMAP}" && test -n "${RELOCATING}"; then
399 __do_init_flmap = ${HAVE_FLMAP-0};
400 __flmap_value = __flmap << (DEFINED(__flmap_bpos) ? __flmap_bpos : 4);
401 __flmap_value_with_lock =
402 __flmap_value | (DEFINED(__flmap_lock) && DEFINED(__flmap_lock_mask)
403 ? (__flmap_lock && __do_init_flmap ? __flmap_lock_mask : 0)
409 if test -n "${EEPROM_LENGTH}"; then
412 .eeprom ${RELOCATING-0}:
414 /* See .data above... */
416 ${RELOCATING+ __eeprom_end = . ; }
417 } ${RELOCATING+ > eeprom}
421 if test "$FUSE_NAME" = "fuse" ; then
424 .fuse ${RELOCATING-0}:
427 ${RELOCATING+KEEP(*(.lfuse))
430 } ${RELOCATING+ > fuse}
436 .lock ${RELOCATING-0}:
439 } ${RELOCATING+ > lock}
441 .signature ${RELOCATING-0}:
444 } ${RELOCATING+ > signature}
447 if test "$FUSE_NAME" = "config" ; then
450 .config ${RELOCATING-0}:
453 } ${RELOCATING+ > config}
457 source_sh $srcdir/scripttempl/misc-sections.sc
460 .note.gnu.build-id ${RELOCATING-0} : { *(.note.gnu.build-id) }
463 source_sh $srcdir/scripttempl/DWARF.sc