xref: /netbsd-src/external/gpl3/binutils.old/dist/ld/scripttempl/avr.sc (revision e992f068c547fd6e84b3f104dc2340adcc955732)
1*e992f068Schristos# Copyright (C) 2014-2022 Free Software Foundation, Inc.
216dce513Schristos#
316dce513Schristos# Copying and distribution of this file, with or without modification,
416dce513Schristos# are permitted in any medium without royalty provided the copyright
516dce513Schristos# notice and this notice are preserved.
616dce513Schristos
7ede78133Schristos# RODATA_PM_OFFSET
8ede78133Schristos#         If empty, .rodata sections will be part of .data.  This is for
9ede78133Schristos#         devices where it is not possible to use LD* instructions to read
10ede78133Schristos#         from flash.
11ede78133Schristos#
12ede78133Schristos#         If non-empty, .rodata is not part of .data and the .rodata
13ede78133Schristos#         objects are assigned addresses at an offest of RODATA_PM_OFFSET.
14ede78133Schristos#         This is for devices that feature reading from flash by means of
15ede78133Schristos#         LD* instructions, provided the addresses are offset by
16ede78133Schristos#         __RODATA_PM_OFFSET__ (which defaults to RODATA_PM_OFFSET).
17ede78133Schristos
1816dce513Schristoscat <<EOF
19*e992f068Schristos/* Copyright (C) 2014-2022 Free Software Foundation, Inc.
2016dce513Schristos
2116dce513Schristos   Copying and distribution of this script, with or without modification,
2216dce513Schristos   are permitted in any medium without royalty provided the copyright
2316dce513Schristos   notice and this notice are preserved.  */
2416dce513Schristos
2516dce513SchristosOUTPUT_FORMAT("${OUTPUT_FORMAT}","${OUTPUT_FORMAT}","${OUTPUT_FORMAT}")
2616dce513SchristosOUTPUT_ARCH(${ARCH})
27012573ebSchristosEOF
2816dce513Schristos
29012573ebSchristostest -n "${RELOCATING}" && cat <<EOF
3016dce513Schristos__TEXT_REGION_LENGTH__ = DEFINED(__TEXT_REGION_LENGTH__) ? __TEXT_REGION_LENGTH__ : $TEXT_LENGTH;
3116dce513Schristos__DATA_REGION_LENGTH__ = DEFINED(__DATA_REGION_LENGTH__) ? __DATA_REGION_LENGTH__ : $DATA_LENGTH;
32ede78133Schristos${EEPROM_LENGTH+__EEPROM_REGION_LENGTH__ = DEFINED(__EEPROM_REGION_LENGTH__) ? __EEPROM_REGION_LENGTH__ : $EEPROM_LENGTH;}
33ede78133Schristos__FUSE_REGION_LENGTH__ = DEFINED(__FUSE_REGION_LENGTH__) ? __FUSE_REGION_LENGTH__ : $FUSE_LENGTH;
34ede78133Schristos__LOCK_REGION_LENGTH__ = DEFINED(__LOCK_REGION_LENGTH__) ? __LOCK_REGION_LENGTH__ : $LOCK_LENGTH;
35ede78133Schristos__SIGNATURE_REGION_LENGTH__ = DEFINED(__SIGNATURE_REGION_LENGTH__) ? __SIGNATURE_REGION_LENGTH__ : $SIGNATURE_LENGTH;
36ede78133Schristos${USER_SIGNATURE_LENGTH+__USER_SIGNATURE_REGION_LENGTH__ = DEFINED(__USER_SIGNATURE_REGION_LENGTH__) ? __USER_SIGNATURE_REGION_LENGTH__ : $USER_SIGNATURE_LENGTH;}
37ede78133Schristos${RODATA_PM_OFFSET+__RODATA_PM_OFFSET__ = DEFINED(__RODATA_PM_OFFSET__) ? __RODATA_PM_OFFSET__ : $RODATA_PM_OFFSET;}
3816dce513SchristosMEMORY
3916dce513Schristos{
4016dce513Schristos  text   (rx)   : ORIGIN = 0, LENGTH = __TEXT_REGION_LENGTH__
4116dce513Schristos  data   (rw!x) : ORIGIN = $DATA_ORIGIN, LENGTH = __DATA_REGION_LENGTH__
42ede78133Schristos${EEPROM_LENGTH+  eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = __EEPROM_REGION_LENGTH__}
43ede78133Schristos  $FUSE_NAME      (rw!x) : ORIGIN = 0x820000, LENGTH = __FUSE_REGION_LENGTH__
4416dce513Schristos  lock      (rw!x) : ORIGIN = 0x830000, LENGTH = __LOCK_REGION_LENGTH__
4516dce513Schristos  signature (rw!x) : ORIGIN = 0x840000, LENGTH = __SIGNATURE_REGION_LENGTH__
46ede78133Schristos${USER_SIGNATURE_LENGTH+  user_signatures (rw!x) : ORIGIN = 0x850000, LENGTH = __USER_SIGNATURE_REGION_LENGTH__}
4716dce513Schristos}
48012573ebSchristosEOF
4916dce513Schristos
50012573ebSchristoscat <<EOF
5116dce513SchristosSECTIONS
5216dce513Schristos{
5316dce513Schristos  /* Read-only sections, merged into text segment: */
5416dce513Schristos  ${TEXT_DYNAMIC+${DYNAMIC}}
5516dce513Schristos  .hash        ${RELOCATING-0} : { *(.hash)		}
5616dce513Schristos  .dynsym      ${RELOCATING-0} : { *(.dynsym)		}
5716dce513Schristos  .dynstr      ${RELOCATING-0} : { *(.dynstr)		}
5816dce513Schristos  .gnu.version ${RELOCATING-0} : { *(.gnu.version)	}
5916dce513Schristos  .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d)	}
6016dce513Schristos  .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r)	}
6116dce513Schristos
6216dce513Schristos  .rel.init    ${RELOCATING-0} : { *(.rel.init)		}
6316dce513Schristos  .rela.init   ${RELOCATING-0} : { *(.rela.init)	}
6416dce513Schristos  .rel.text    ${RELOCATING-0} :
6516dce513Schristos    {
6616dce513Schristos      *(.rel.text)
6716dce513Schristos      ${RELOCATING+*(.rel.text.*)}
6816dce513Schristos      ${RELOCATING+*(.rel.gnu.linkonce.t*)}
6916dce513Schristos    }
7016dce513Schristos  .rela.text   ${RELOCATING-0} :
7116dce513Schristos    {
7216dce513Schristos      *(.rela.text)
7316dce513Schristos      ${RELOCATING+*(.rela.text.*)}
7416dce513Schristos      ${RELOCATING+*(.rela.gnu.linkonce.t*)}
7516dce513Schristos    }
7616dce513Schristos  .rel.fini    ${RELOCATING-0} : { *(.rel.fini)		}
7716dce513Schristos  .rela.fini   ${RELOCATING-0} : { *(.rela.fini)	}
7816dce513Schristos  .rel.rodata  ${RELOCATING-0} :
7916dce513Schristos    {
8016dce513Schristos      *(.rel.rodata)
8116dce513Schristos      ${RELOCATING+*(.rel.rodata.*)}
8216dce513Schristos      ${RELOCATING+*(.rel.gnu.linkonce.r*)}
8316dce513Schristos    }
8416dce513Schristos  .rela.rodata ${RELOCATING-0} :
8516dce513Schristos    {
8616dce513Schristos      *(.rela.rodata)
8716dce513Schristos      ${RELOCATING+*(.rela.rodata.*)}
8816dce513Schristos      ${RELOCATING+*(.rela.gnu.linkonce.r*)}
8916dce513Schristos    }
9016dce513Schristos  .rel.data    ${RELOCATING-0} :
9116dce513Schristos    {
9216dce513Schristos      *(.rel.data)
9316dce513Schristos      ${RELOCATING+*(.rel.data.*)}
9416dce513Schristos      ${RELOCATING+*(.rel.gnu.linkonce.d*)}
9516dce513Schristos    }
9616dce513Schristos  .rela.data   ${RELOCATING-0} :
9716dce513Schristos    {
9816dce513Schristos      *(.rela.data)
9916dce513Schristos      ${RELOCATING+*(.rela.data.*)}
10016dce513Schristos      ${RELOCATING+*(.rela.gnu.linkonce.d*)}
10116dce513Schristos    }
10216dce513Schristos  .rel.ctors   ${RELOCATING-0} : { *(.rel.ctors)	}
10316dce513Schristos  .rela.ctors  ${RELOCATING-0} : { *(.rela.ctors)	}
10416dce513Schristos  .rel.dtors   ${RELOCATING-0} : { *(.rel.dtors)	}
10516dce513Schristos  .rela.dtors  ${RELOCATING-0} : { *(.rela.dtors)	}
10616dce513Schristos  .rel.got     ${RELOCATING-0} : { *(.rel.got)		}
10716dce513Schristos  .rela.got    ${RELOCATING-0} : { *(.rela.got)		}
10816dce513Schristos  .rel.bss     ${RELOCATING-0} : { *(.rel.bss)		}
10916dce513Schristos  .rela.bss    ${RELOCATING-0} : { *(.rela.bss)		}
11016dce513Schristos  .rel.plt     ${RELOCATING-0} : { *(.rel.plt)		}
11116dce513Schristos  .rela.plt    ${RELOCATING-0} : { *(.rela.plt)		}
11216dce513Schristos
11316dce513Schristos  /* Internal text space or external memory.  */
11416dce513Schristos  .text ${RELOCATING-0} :
11516dce513Schristos  {
116012573ebSchristos    ${RELOCATING+*(.vectors)
11716dce513Schristos    KEEP(*(.vectors))
11816dce513Schristos
11916dce513Schristos    /* For data that needs to reside in the lower 64k of progmem.  */
120012573ebSchristos    *(.progmem.gcc*)
12116dce513Schristos
12216dce513Schristos    /* PR 13812: Placing the trampolines here gives a better chance
12316dce513Schristos       that they will be in range of the code that uses them.  */
124012573ebSchristos    . = ALIGN(2);
125012573ebSchristos    __trampolines_start = . ;
12616dce513Schristos    /* The jump trampolines for the 16-bit limited relocs will reside here.  */
12716dce513Schristos    *(.trampolines)
128012573ebSchristos    *(.trampolines*)
129012573ebSchristos    __trampolines_end = . ;
13016dce513Schristos
13116dce513Schristos    /* avr-libc expects these data to reside in lower 64K. */
132012573ebSchristos    *libprintf_flt.a:*(.progmem.data)
133012573ebSchristos    *libc.a:*(.progmem.data)
13416dce513Schristos
135012573ebSchristos    *(.progmem.*)
13616dce513Schristos
137012573ebSchristos    . = ALIGN(2);
13816dce513Schristos
13916dce513Schristos    /* For code that needs to reside in the lower 128k progmem.  */
14016dce513Schristos    *(.lowtext)
141012573ebSchristos    *(.lowtext*)}
14216dce513Schristos
14316dce513Schristos    ${CONSTRUCTING+ __ctors_start = . ; }
14416dce513Schristos    ${CONSTRUCTING+ *(.ctors) }
14516dce513Schristos    ${CONSTRUCTING+ __ctors_end = . ; }
14616dce513Schristos    ${CONSTRUCTING+ __dtors_start = . ; }
14716dce513Schristos    ${CONSTRUCTING+ *(.dtors) }
14816dce513Schristos    ${CONSTRUCTING+ __dtors_end = . ; }
149012573ebSchristos    ${RELOCATING+KEEP(SORT(*)(.ctors))
15016dce513Schristos    KEEP(SORT(*)(.dtors))
15116dce513Schristos
152012573ebSchristos    /* From this point on, we do not bother about whether the insns are
15316dce513Schristos       below or above the 16 bits boundary.  */
15416dce513Schristos    *(.init0)  /* Start here after reset.  */
15516dce513Schristos    KEEP (*(.init0))
15616dce513Schristos    *(.init1)
15716dce513Schristos    KEEP (*(.init1))
15816dce513Schristos    *(.init2)  /* Clear __zero_reg__, set up stack pointer.  */
15916dce513Schristos    KEEP (*(.init2))
16016dce513Schristos    *(.init3)
16116dce513Schristos    KEEP (*(.init3))
16216dce513Schristos    *(.init4)  /* Initialize data and BSS.  */
16316dce513Schristos    KEEP (*(.init4))
16416dce513Schristos    *(.init5)
16516dce513Schristos    KEEP (*(.init5))
16616dce513Schristos    *(.init6)  /* C++ constructors.  */
16716dce513Schristos    KEEP (*(.init6))
16816dce513Schristos    *(.init7)
16916dce513Schristos    KEEP (*(.init7))
17016dce513Schristos    *(.init8)
17116dce513Schristos    KEEP (*(.init8))
17216dce513Schristos    *(.init9)  /* Call main().  */
173012573ebSchristos    KEEP (*(.init9))}
17416dce513Schristos    *(.text)
175012573ebSchristos    ${RELOCATING+. = ALIGN(2);
176012573ebSchristos    *(.text.*)
177012573ebSchristos    . = ALIGN(2);
17816dce513Schristos    *(.fini9)  /* _exit() starts here.  */
17916dce513Schristos    KEEP (*(.fini9))
18016dce513Schristos    *(.fini8)
18116dce513Schristos    KEEP (*(.fini8))
18216dce513Schristos    *(.fini7)
18316dce513Schristos    KEEP (*(.fini7))
18416dce513Schristos    *(.fini6)  /* C++ destructors.  */
18516dce513Schristos    KEEP (*(.fini6))
18616dce513Schristos    *(.fini5)
18716dce513Schristos    KEEP (*(.fini5))
18816dce513Schristos    *(.fini4)
18916dce513Schristos    KEEP (*(.fini4))
19016dce513Schristos    *(.fini3)
19116dce513Schristos    KEEP (*(.fini3))
19216dce513Schristos    *(.fini2)
19316dce513Schristos    KEEP (*(.fini2))
19416dce513Schristos    *(.fini1)
19516dce513Schristos    KEEP (*(.fini1))
19616dce513Schristos    *(.fini0)  /* Infinite loop after program termination.  */
19716dce513Schristos    KEEP (*(.fini0))
198ede78133Schristos
199ede78133Schristos    /* For code that needs not to reside in the lower progmem.  */
200ede78133Schristos    *(.hightext)
201012573ebSchristos    *(.hightext*)
202ede78133Schristos
203012573ebSchristos    *(.progmemx.*)
204ede78133Schristos
205012573ebSchristos    . = ALIGN(2);
206ede78133Schristos
207012573ebSchristos    /* For tablejump instruction arrays.  We do not relax
208ede78133Schristos       JMP / CALL instructions within these sections.  */
209ede78133Schristos    *(.jumptables)
210012573ebSchristos    *(.jumptables*)
211ede78133Schristos
212012573ebSchristos    _etext = . ;}
21316dce513Schristos  } ${RELOCATING+ > text}
214ede78133SchristosEOF
21516dce513Schristos
216ede78133Schristos# Devices like ATtiny816 allow to read from flash memory by means of LD*
217ede78133Schristos# instructions provided we add an offset of __RODATA_PM_OFFSET__ to the
218ede78133Schristos# flash addresses.
219ede78133Schristos
220ede78133Schristosif test -n "$RODATA_PM_OFFSET"; then
221ede78133Schristos    cat <<EOF
222ede78133Schristos  .rodata ${RELOCATING+ ADDR(.text) + SIZEOF (.text) + __RODATA_PM_OFFSET__ } ${RELOCATING-0} :
223ede78133Schristos  {
224ede78133Schristos    *(.rodata)
225012573ebSchristos    ${RELOCATING+ *(.rodata*)
226012573ebSchristos    *(.gnu.linkonce.r*)}
227ede78133Schristos  } ${RELOCATING+AT> text}
228ede78133SchristosEOF
229ede78133Schristosfi
230ede78133Schristos
231ede78133Schristoscat <<EOF
23216dce513Schristos  .data        ${RELOCATING-0} :
23316dce513Schristos  {
23416dce513Schristos    ${RELOCATING+ PROVIDE (__data_start = .) ; }
23516dce513Schristos    *(.data)
236012573ebSchristos    ${RELOCATING+ *(.data*)
237012573ebSchristos    *(.gnu.linkonce.d*)}
238ede78133SchristosEOF
239ede78133Schristos
240ede78133Schristos# Classical devices that don't show flash memory in the SRAM address space
241ede78133Schristos# need .rodata to be part of .data because the compiler will use LD*
242ede78133Schristos# instructions and LD* cannot access flash.
243ede78133Schristos
244012573ebSchristosif test -z "$RODATA_PM_OFFSET" && test -n "${RELOCATING}"; then
245ede78133Schristos    cat <<EOF
24616dce513Schristos    *(.rodata)  /* We need to include .rodata here if gcc is used */
247012573ebSchristos    *(.rodata*) /* with -fdata-sections.  */
248ede78133Schristos    *(.gnu.linkonce.r*)
249ede78133SchristosEOF
250ede78133Schristosfi
251ede78133Schristos
252ede78133Schristoscat <<EOF
25316dce513Schristos    ${RELOCATING+. = ALIGN(2);}
25416dce513Schristos    ${RELOCATING+ _edata = . ; }
25516dce513Schristos    ${RELOCATING+ PROVIDE (__data_end = .) ; }
25616dce513Schristos  } ${RELOCATING+ > data ${RELOCATING+AT> text}}
25716dce513Schristos
25816dce513Schristos  .bss ${RELOCATING+ ADDR(.data) + SIZEOF (.data)} ${RELOCATING-0} :${RELOCATING+ AT (ADDR (.bss))}
25916dce513Schristos  {
26016dce513Schristos    ${RELOCATING+ PROVIDE (__bss_start = .) ; }
26116dce513Schristos    *(.bss)
26216dce513Schristos    ${RELOCATING+ *(.bss*)}
263012573ebSchristos    ${RELOCATING+ *(COMMON)}
26416dce513Schristos    ${RELOCATING+ PROVIDE (__bss_end = .) ; }
26516dce513Schristos  } ${RELOCATING+ > data}
26616dce513Schristos
26716dce513Schristos  ${RELOCATING+ __data_load_start = LOADADDR(.data); }
26816dce513Schristos  ${RELOCATING+ __data_load_end = __data_load_start + SIZEOF(.data); }
26916dce513Schristos
27016dce513Schristos  /* Global data not cleared after reset.  */
27116dce513Schristos  .noinit ${RELOCATING+ ADDR(.bss) + SIZEOF (.bss)} ${RELOCATING-0}: ${RELOCATING+ AT (ADDR (.noinit))}
27216dce513Schristos  {
27316dce513Schristos    ${RELOCATING+ PROVIDE (__noinit_start = .) ; }
274*e992f068Schristos    *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*})
27516dce513Schristos    ${RELOCATING+ PROVIDE (__noinit_end = .) ; }
27616dce513Schristos    ${RELOCATING+ _end = . ;  }
27716dce513Schristos    ${RELOCATING+ PROVIDE (__heap_start = .) ; }
27816dce513Schristos  } ${RELOCATING+ > data}
279ede78133SchristosEOF
280ede78133Schristos
281ede78133Schristosif test -n "${EEPROM_LENGTH}"; then
282ede78133Schristoscat <<EOF
28316dce513Schristos
28416dce513Schristos  .eeprom ${RELOCATING-0}:
28516dce513Schristos  {
28616dce513Schristos    /* See .data above...  */
28716dce513Schristos    KEEP(*(.eeprom*))
28816dce513Schristos    ${RELOCATING+ __eeprom_end = . ; }
28916dce513Schristos  } ${RELOCATING+ > eeprom}
290ede78133SchristosEOF
291ede78133Schristosfi
292ede78133Schristos
293ede78133Schristosif test "$FUSE_NAME" = "fuse" ; then
294ede78133Schristoscat <<EOF
29516dce513Schristos
29616dce513Schristos  .fuse ${RELOCATING-0}:
29716dce513Schristos  {
29816dce513Schristos    KEEP(*(.fuse))
299012573ebSchristos    ${RELOCATING+KEEP(*(.lfuse))
30016dce513Schristos    KEEP(*(.hfuse))
301012573ebSchristos    KEEP(*(.efuse))}
30216dce513Schristos  } ${RELOCATING+ > fuse}
303ede78133SchristosEOF
304ede78133Schristosfi
305ede78133Schristos
306ede78133Schristoscat <<EOF
30716dce513Schristos
30816dce513Schristos  .lock ${RELOCATING-0}:
30916dce513Schristos  {
31016dce513Schristos    KEEP(*(.lock*))
31116dce513Schristos  } ${RELOCATING+ > lock}
31216dce513Schristos
31316dce513Schristos  .signature ${RELOCATING-0}:
31416dce513Schristos  {
31516dce513Schristos    KEEP(*(.signature*))
31616dce513Schristos  } ${RELOCATING+ > signature}
317ede78133SchristosEOF
318ede78133Schristos
319ede78133Schristosif test "$FUSE_NAME" = "config" ; then
320ede78133Schristoscat <<EOF
321ede78133Schristos
322ede78133Schristos  .config ${RELOCATING-0}:
323ede78133Schristos  {
324ede78133Schristos    KEEP(*(.config*))
325ede78133Schristos  } ${RELOCATING+ > config}
326ede78133SchristosEOF
327ede78133Schristosfi
328ede78133Schristos
329ede78133Schristoscat <<EOF
33016dce513Schristos
33116dce513Schristos  /* Stabs debugging sections.  */
33216dce513Schristos  .stab 0 : { *(.stab) }
33316dce513Schristos  .stabstr 0 : { *(.stabstr) }
33416dce513Schristos  .stab.excl 0 : { *(.stab.excl) }
33516dce513Schristos  .stab.exclstr 0 : { *(.stab.exclstr) }
33616dce513Schristos  .stab.index 0 : { *(.stab.index) }
33716dce513Schristos  .stab.indexstr 0 : { *(.stab.indexstr) }
33816dce513Schristos  .comment 0 : { *(.comment) }
339012573ebSchristos  .note.gnu.build-id ${RELOCATING-0} : { *(.note.gnu.build-id) }
34016dce513SchristosEOF
34116dce513Schristos
34216dce513Schristos. $srcdir/scripttempl/DWARF.sc
34316dce513Schristos
34416dce513Schristoscat <<EOF
34516dce513Schristos}
34616dce513SchristosEOF
347