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