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