xref: /netbsd-src/external/gpl3/binutils/dist/ld/scripttempl/elf32msp430.sc (revision 867d70fc718005c0918b8b8b2f9d7f2d52d0a0db)
1# Copyright (C) 2014-2020 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
7HEAP_SECTION_MSP430=" "
8HEAP_MEMORY_MSP430=" "
9
10if test ${GOT_HEAP_MSP-0} -ne 0
11then
12HEAP_SECTION_MSP430=".heap ${RELOCATING-0} :
13  {
14    ${RELOCATING+ PROVIDE (__heap_data_start = .) ; }
15    *(.heap*)
16    ${RELOCATING+ PROVIDE (_heap_data_end = .) ; }
17    ${RELOCATING+. = ALIGN(2);}
18    ${RELOCATING+ PROVIDE (__heap_bottom = .) ; }
19    ${RELOCATING+ PROVIDE (__heap_top = ${HEAP_START} + ${HEAP_LENGTH}) ; }
20  } ${RELOCATING+ > heap}"
21HEAP_MEMORY_MSP430="heap(rwx)		: ORIGIN = $HEAP_START,	LENGTH = $HEAP_LENGTH"
22fi
23
24
25cat <<EOF
26/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
27
28   Copying and distribution of this script, with or without modification,
29   are permitted in any medium without royalty provided the copyright
30   notice and this notice are preserved.  */
31
32OUTPUT_FORMAT("${OUTPUT_FORMAT}","${OUTPUT_FORMAT}","${OUTPUT_FORMAT}")
33OUTPUT_ARCH(${ARCH})
34
35EOF
36
37test -n "${RELOCATING}" && cat <<EOF
38MEMORY
39{
40  text   (rx)		: ORIGIN = $ROM_START,  LENGTH = $ROM_SIZE
41  data   (rwx)		: ORIGIN = $RAM_START,	LENGTH = $RAM_SIZE
42  vectors (rw)		: ORIGIN = 0xffe0,      LENGTH = 0x20
43  bootloader(rx)	: ORIGIN = 0x0c00,	LENGTH = 1K
44  infomem(rx)		: ORIGIN = 0x1000,	LENGTH = 256
45  infomemnobits(rx)	: ORIGIN = 0x1000,      LENGTH = 256
46  ${HEAP_MEMORY_MSP430}
47}
48
49EOF
50
51cat <<EOF
52SECTIONS
53{
54  /* Bootloader.  */
55  .bootloader ${RELOCATING-0} :
56  {
57    ${RELOCATING+ PROVIDE (__boot_start = .) ; }
58    *(.bootloader)
59    ${RELOCATING+. = ALIGN(2);}
60    ${RELOCATING+*(.bootloader.*)}
61  } ${RELOCATING+ > bootloader}
62
63  /* Information memory.  */
64  .infomem ${RELOCATING-0} :
65  {
66    *(.infomem)
67    ${RELOCATING+. = ALIGN(2);}
68    ${RELOCATING+*(.infomem.*)}
69  } ${RELOCATING+ > infomem}
70
71  /* Information memory (not loaded into MPU).  */
72  .infomemnobits ${RELOCATING-0} :
73  {
74    *(.infomemnobits)
75    ${RELOCATING+. = ALIGN(2);}
76    ${RELOCATING+*(.infomemnobits.*)}
77  } ${RELOCATING+ > infomemnobits}
78
79  /* Read-only sections, merged into text segment.  */
80  ${TEXT_DYNAMIC+${DYNAMIC}}
81  .hash        ${RELOCATING-0} : { *(.hash)             }
82  .dynsym      ${RELOCATING-0} : { *(.dynsym)           }
83  .dynstr      ${RELOCATING-0} : { *(.dynstr)           }
84  .gnu.version ${RELOCATING-0} : { *(.gnu.version)      }
85  .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d)  }
86  .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r)  }
87
88  .rel.init    ${RELOCATING-0} : { *(.rel.init) }
89  .rela.init   ${RELOCATING-0} : { *(.rela.init) }
90  .rel.text    ${RELOCATING-0} :
91    {
92      *(.rel.text)
93      ${RELOCATING+*(.rel.text.*)}
94      ${RELOCATING+*(.rel.gnu.linkonce.t*)}
95    }
96  .rela.text   ${RELOCATING-0} :
97    {
98      *(.rela.text)
99      ${RELOCATING+*(.rela.text.*)}
100      ${RELOCATING+*(.rela.gnu.linkonce.t*)}
101    }
102  .rel.fini    ${RELOCATING-0} : { *(.rel.fini) }
103  .rela.fini   ${RELOCATING-0} : { *(.rela.fini) }
104  .rel.rodata  ${RELOCATING-0} :
105    {
106      *(.rel.rodata)
107      ${RELOCATING+*(.rel.rodata.*)}
108      ${RELOCATING+*(.rel.gnu.linkonce.r*)}
109    }
110  .rela.rodata ${RELOCATING-0} :
111    {
112      *(.rela.rodata)
113      ${RELOCATING+*(.rela.rodata.*)}
114      ${RELOCATING+*(.rela.gnu.linkonce.r*)}
115    }
116  .rel.data    ${RELOCATING-0} :
117    {
118      *(.rel.data)
119      ${RELOCATING+*(.rel.data.*)}
120      ${RELOCATING+*(.rel.gnu.linkonce.d*)}
121    }
122  .rela.data   ${RELOCATING-0} :
123    {
124      *(.rela.data)
125      ${RELOCATING+*(.rela.data.*)}
126      ${RELOCATING+*(.rela.gnu.linkonce.d*)}
127    }
128  .rel.ctors   ${RELOCATING-0} : { *(.rel.ctors)        }
129  .rela.ctors  ${RELOCATING-0} : { *(.rela.ctors)       }
130  .rel.dtors   ${RELOCATING-0} : { *(.rel.dtors)        }
131  .rela.dtors  ${RELOCATING-0} : { *(.rela.dtors)       }
132  .rel.got     ${RELOCATING-0} : { *(.rel.got)          }
133  .rela.got    ${RELOCATING-0} : { *(.rela.got)         }
134  .rel.bss     ${RELOCATING-0} : { *(.rel.bss)          }
135  .rela.bss    ${RELOCATING-0} : { *(.rela.bss)         }
136  .rel.plt     ${RELOCATING-0} : { *(.rel.plt)          }
137  .rela.plt    ${RELOCATING-0} : { *(.rela.plt)         }
138
139  /* Internal text space.  */
140  .text ${RELOCATING-0} :
141  {
142    ${RELOCATING+. = ALIGN(2);
143    *(SORT_NONE(.init))
144    *(SORT_NONE(.init0))  /* Start here after reset.  */
145    *(SORT_NONE(.init1))
146    *(SORT_NONE(.init2))  /* Copy data loop  */
147    *(SORT_NONE(.init3))
148    *(SORT_NONE(.init4))  /* Clear bss  */
149    *(SORT_NONE(.init5))
150    *(SORT_NONE(.init6))  /* C++ constructors.  */
151    *(SORT_NONE(.init7))
152    *(SORT_NONE(.init8))
153    *(SORT_NONE(.init9))  /* Call main().  */}
154
155    ${CONSTRUCTING+ __ctors_start = . ; }
156    ${CONSTRUCTING+ *(.ctors) }
157    ${CONSTRUCTING+ __ctors_end = . ; }
158    ${CONSTRUCTING+ __dtors_start = . ; }
159    ${CONSTRUCTING+ *(.dtors) }
160    ${CONSTRUCTING+ __dtors_end = . ; }
161
162    ${RELOCATING+. = ALIGN(2);
163    *(.lower.text.* .lower.text)
164
165    . = ALIGN(2);}
166    *(.text)
167    ${RELOCATING+. = ALIGN(2);
168    *(.text.*)
169    . = ALIGN(2);
170    *(.text:*)
171
172    *(.either.text.* .either.text)
173
174    *(.upper.text.* .upper.text)
175
176    . = ALIGN(2);
177    *(SORT_NONE(.fini9))
178    *(SORT_NONE(.fini8))
179    *(SORT_NONE(.fini7))
180    *(SORT_NONE(.fini6))  /* C++ destructors.  */
181    *(SORT_NONE(.fini5))
182    *(SORT_NONE(.fini4))
183    *(SORT_NONE(.fini3))
184    *(SORT_NONE(.fini2))
185    *(SORT_NONE(.fini1))
186    *(SORT_NONE(.fini0))  /* Infinite loop after program termination.  */
187    *(SORT_NONE(.fini))
188
189    _etext = .;}
190  } ${RELOCATING+ > text}
191
192  .rodata ${RELOCATING-0} :
193  {
194    ${RELOCATING+. = ALIGN(2);
195    *(.lower.rodata.* .lower.rodata)
196
197    . = ALIGN(2);
198    *(.plt)}
199    *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.* .const .const:*})
200    ${RELOCATING+*(.rodata1)
201
202    *(.either.rodata.*) *(.either.rodata)
203
204    *(.upper.rodata.* .upper.rodata)
205
206    *(.eh_frame_hdr)
207    KEEP (*(.eh_frame))
208
209    KEEP (*(.gcc_except_table)) *(.gcc_except_table.*)
210
211    PROVIDE (__preinit_array_start = .);
212    KEEP (*(.preinit_array))
213    PROVIDE (__preinit_array_end = .);
214
215    PROVIDE (__init_array_start = .);
216    KEEP (*(SORT(.init_array.*)))
217    KEEP (*(.init_array))
218    PROVIDE (__init_array_end = .);
219
220    PROVIDE (__fini_array_start = .);
221    KEEP (*(.fini_array))
222    KEEP (*(SORT(.fini_array.*)))
223    PROVIDE (__fini_array_end = .);
224
225    /* gcc uses crtbegin.o to find the start of the constructors, so
226       we make sure it is first.  Because this is a wildcard, it
227       doesn't matter if the user does not actually link against
228       crtbegin.o; the linker won't look for a file to match a
229       wildcard.  The wildcard also means that it doesn't matter which
230       directory crtbegin.o is in.  */
231    KEEP (*crtbegin*.o(.ctors))
232
233    /* We don't want to include the .ctor section from from the
234       crtend.o file until after the sorted ctors.  The .ctor section
235       from the crtend file contains the end of ctors marker and it
236       must be last */
237    KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
238    KEEP (*(SORT(.ctors.*)))
239    KEEP (*(.ctors))
240
241    KEEP (*crtbegin*.o(.dtors))
242    KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
243    KEEP (*(SORT(.dtors.*)))
244    KEEP (*(.dtors))}
245  } ${RELOCATING+ > text}
246
247  .vectors ${RELOCATING-0} :
248  {
249    ${RELOCATING+ PROVIDE (__vectors_start = .) ; }
250    *(.vectors${RELOCATING+*})
251    ${RELOCATING+ _vectors_end = . ; }
252  } ${RELOCATING+ > vectors}
253
254  .data ${RELOCATING-0} :
255  {
256    ${RELOCATING+ PROVIDE (__data_start = .) ; }
257    ${RELOCATING+ PROVIDE (__datastart = .) ; }
258    ${RELOCATING+. = ALIGN(2);
259
260    KEEP (*(.jcr))
261    *(.data.rel.ro.local) *(.data.rel.ro*)
262    *(.dynamic)
263
264    . = ALIGN(2);
265    *(.lower.data.* .lower.data)}
266
267    *(.data)
268    ${RELOCATING+*(.data.*)
269    *(.gnu.linkonce.d*)
270    KEEP (*(.gnu.linkonce.d.*personality*))
271    *(.data1)
272
273    *(.either.data.* .either.data)
274
275    *(.upper.data.* .upper.data)
276
277    *(.got.plt) *(.got)
278    . = ALIGN(2);
279    *(.sdata .sdata.* .gnu.linkonce.s.*)
280    . = ALIGN(2);
281    _edata = .;}
282  } ${RELOCATING+ > data AT> text}
283
284  ${RELOCATING+__romdatastart = LOADADDR(.data);
285  __romdatacopysize = SIZEOF(.data);}
286
287  .bss ${RELOCATING-0}${RELOCATING+SIZEOF(.data) + ADDR(.data)} :
288  {
289    ${RELOCATING+. = ALIGN(2);}
290    ${RELOCATING+ PROVIDE (__bss_start = .); }
291    ${RELOCATING+ PROVIDE (__bssstart = .);
292    *(.lower.bss.* .lower.bss)
293    . = ALIGN(2);}
294    *(.bss)
295    ${RELOCATING+*(.either.bss.* .either.bss)
296    *(.upper.bss.* .upper.bss)
297    *(COMMON)
298    PROVIDE (__bss_end = .);}
299  } ${RELOCATING+ > data}
300  ${RELOCATING+ PROVIDE (__bsssize = SIZEOF(.bss)); }
301
302  .noinit ${RELOCATING-0}${RELOCATING+SIZEOF(.bss) + ADDR(.bss)} :
303  {
304    ${RELOCATING+ PROVIDE (__noinit_start = .) ; }
305    *(.noinit)
306    ${RELOCATING+ PROVIDE (__noinit_end = .) ; }
307  } ${RELOCATING+ > data}
308
309  .persistent ${RELOCATING-0}${RELOCATING+SIZEOF(.noinit) + ADDR(.noinit)} :
310  {
311    ${RELOCATING+ PROVIDE (__persistent_start = .) ; }
312    *(.persistent)
313    ${RELOCATING+ PROVIDE (__persistent_end = .) ; }
314  } ${RELOCATING+ > data}
315
316  ${RELOCATING+ _end = . ;  }
317  ${HEAP_SECTION_MSP430}
318
319  /* Stabs for profiling information*/
320  .profiler 0 : { *(.profiler) }
321
322  /* Stabs debugging sections.  */
323  .stab 0 : { *(.stab) }
324  .stabstr 0 : { *(.stabstr) }
325  .stab.excl 0 : { *(.stab.excl) }
326  .stab.exclstr 0 : { *(.stab.exclstr) }
327  .stab.index 0 : { *(.stab.index) }
328  .stab.indexstr 0 : { *(.stab.indexstr) }
329  .comment 0 : { *(.comment) }
330EOF
331
332. $srcdir/scripttempl/DWARF.sc
333
334test -n "${RELOCATING}" && cat <<EOF
335  .MSP430.attributes 0 :
336  {
337    KEEP (*(.MSP430.attributes))
338    KEEP (*(.gnu.attributes))
339    KEEP (*(__TI_build_attributes))
340  }
341
342  PROVIDE (__stack = ${STACK}) ;
343  PROVIDE (__data_start_rom = _etext) ;
344  PROVIDE (__data_end_rom   = _etext + SIZEOF (.data)) ;
345  PROVIDE (__noinit_start_rom = _etext + SIZEOF (.data)) ;
346  PROVIDE (__noinit_end_rom = _etext + SIZEOF (.data) + SIZEOF (.noinit)) ;
347  PROVIDE (__subdevice_has_heap = ${GOT_HEAP_MSP-0}) ;
348EOF
349
350cat <<EOF
351}
352EOF
353