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