Add initX, finiX, ctors, dtors sections to respect C++ constructor/destructor.
[binutils.git] / ld / scripttempl / elf32msp430.sc
blobc3e78d32e6a24fa6d3fc209b0b307a0c00779713
1 cat <<EOF
2 OUTPUT_FORMAT("${OUTPUT_FORMAT}","${OUTPUT_FORMAT}","${OUTPUT_FORMAT}")
3 OUTPUT_ARCH(${ARCH})
5 MEMORY
7   text   (rx)           : ORIGIN = $ROM_START,  LENGTH = $ROM_SIZE
8   data   (rwx)          : ORIGIN = $RAM_START,  LENGTH = $RAM_SIZE
9   vectors (rw)          : ORIGIN = 0xffe0,      LENGTH = 0x20
10   bootloader(rx)        : ORIGIN = 0x0c00,      LENGTH = 1K
11   infomem(rx)           : ORIGIN = 0x1000,      LENGTH = 256
12   infomemnobits(rx)     : ORIGIN = 0x1000,      LENGTH = 256
15 SECTIONS
17   /* Read-only sections, merged into text segment.  */
18   ${TEXT_DYNAMIC+${DYNAMIC}}
19   .hash        ${RELOCATING-0} : { *(.hash)             }
20   .dynsym      ${RELOCATING-0} : { *(.dynsym)           }
21   .dynstr      ${RELOCATING-0} : { *(.dynstr)           }
22   .gnu.version ${RELOCATING-0} : { *(.gnu.version)      }
23   .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d)  }
24   .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r)  }
26   .rel.init    ${RELOCATING-0} : { *(.rel.init) }
27   .rela.init   ${RELOCATING-0} : { *(.rela.init) }
28   .rel.text    ${RELOCATING-0} :
29     {
30       *(.rel.text)
31       ${RELOCATING+*(.rel.text.*)}
32       ${RELOCATING+*(.rel.gnu.linkonce.t*)}
33     }
34   .rela.text   ${RELOCATING-0} :
35     {
36       *(.rela.text)
37       ${RELOCATING+*(.rela.text.*)}
38       ${RELOCATING+*(.rela.gnu.linkonce.t*)}
39     }
40   .rel.fini    ${RELOCATING-0} : { *(.rel.fini) }
41   .rela.fini   ${RELOCATING-0} : { *(.rela.fini) }
42   .rel.rodata  ${RELOCATING-0} :
43     {
44       *(.rel.rodata)
45       ${RELOCATING+*(.rel.rodata.*)}
46       ${RELOCATING+*(.rel.gnu.linkonce.r*)}
47     }
48   .rela.rodata ${RELOCATING-0} :
49     {
50       *(.rela.rodata)
51       ${RELOCATING+*(.rela.rodata.*)}
52       ${RELOCATING+*(.rela.gnu.linkonce.r*)}
53     }
54   .rel.data    ${RELOCATING-0} :
55     {
56       *(.rel.data)
57       ${RELOCATING+*(.rel.data.*)}
58       ${RELOCATING+*(.rel.gnu.linkonce.d*)}
59     }
60   .rela.data   ${RELOCATING-0} :
61     {
62       *(.rela.data)
63       ${RELOCATING+*(.rela.data.*)}
64       ${RELOCATING+*(.rela.gnu.linkonce.d*)}
65     }
66   .rel.ctors   ${RELOCATING-0} : { *(.rel.ctors)        }
67   .rela.ctors  ${RELOCATING-0} : { *(.rela.ctors)       }
68   .rel.dtors   ${RELOCATING-0} : { *(.rel.dtors)        }
69   .rela.dtors  ${RELOCATING-0} : { *(.rela.dtors)       }
70   .rel.got     ${RELOCATING-0} : { *(.rel.got)          }
71   .rela.got    ${RELOCATING-0} : { *(.rela.got)         }
72   .rel.bss     ${RELOCATING-0} : { *(.rel.bss)          }
73   .rela.bss    ${RELOCATING-0} : { *(.rela.bss)         }
74   .rel.plt     ${RELOCATING-0} : { *(.rel.plt)          }
75   .rela.plt    ${RELOCATING-0} : { *(.rela.plt)         }
77   /* Internal text space.  */
78   .text :
79   {
80     ${RELOCATING+. = ALIGN(2);}
81     *(.init)
82     *(.init0)  /* Start here after reset.  */
83     *(.init1)
84     *(.init2)  /* Copy data loop  */
85     *(.init3)
86     *(.init4)  /* Clear bss  */
87     *(.init5)
88     *(.init6)  /* C++ constructors.  */
89     *(.init7)
90     *(.init8)
91     *(.init9)  /* Call main().  */
93     ${CONSTRUCTING+ __ctors_start = . ; }
94     ${CONSTRUCTING+ *(.ctors) }
95     ${CONSTRUCTING+ __ctors_end = . ; }
96     ${CONSTRUCTING+ __dtors_start = . ; }
97     ${CONSTRUCTING+ *(.dtors) }
98     ${CONSTRUCTING+ __dtors_end = . ; }
100     ${RELOCATING+. = ALIGN(2);}
101     *(.text)
102     ${RELOCATING+. = ALIGN(2);}
103     *(.text.*)
105     ${RELOCATING+. = ALIGN(2);}
106     *(.fini9)  /*   */
107     *(.fini8)
108     *(.fini7)
109     *(.fini6)  /* C++ destructors.  */
110     *(.fini5)
111     *(.fini4)
112     *(.fini3)
113     *(.fini2)
114     *(.fini1)
115     *(.fini0)  /* Infinite loop after program termination.  */
116     *(.fini)
118     ${RELOCATING+ _etext = . ; }
119   } ${RELOCATING+ > text}
121   .data ${RELOCATING-0} : ${RELOCATING+AT (ADDR (.text) + SIZEOF (.text))}
122   {  
123     ${RELOCATING+ PROVIDE (__data_start = .) ; }
124     ${RELOCATING+. = ALIGN(2);}
125     *(.data)
126     ${RELOCATING+. = ALIGN(2);}
127     *(.gnu.linkonce.d*)
128     ${RELOCATING+. = ALIGN(2);}
129     ${RELOCATING+ _edata = . ; }
130   } ${RELOCATING+ > data}
131   
132   /* Bootloader.  */
133   .bootloader ${RELOCATING-0} :
134   {
135     ${RELOCATING+ PROVIDE (__boot_start = .) ; }
136     *(.bootloader)
137     ${RELOCATING+. = ALIGN(2);}
138     *(.bootloader.*)
139   } ${RELOCATING+ > bootloader}
140   
141   /* Information memory.  */
142   .infomem ${RELOCATING-0} :
143   {
144     *(.infomem)
145     ${RELOCATING+. = ALIGN(2);}
146     *(.infomem.*)
147   } ${RELOCATING+ > infomem}
149   /* Information memory (not loaded into MPU).  */
150   .infomemnobits ${RELOCATING-0} :
151   {
152     *(.infomemnobits)
153     ${RELOCATING+. = ALIGN(2);}
154     *(.infomemnobits.*)
155   } ${RELOCATING+ > infomemnobits}
157   .bss ${RELOCATING+ SIZEOF(.data) + ADDR(.data)} :
158   {
159     ${RELOCATING+ PROVIDE (__bss_start = .) ; }
160     *(.bss)
161     *(COMMON)
162     ${RELOCATING+ PROVIDE (__bss_end = .) ; }
163     ${RELOCATING+ _end = . ;  }
164   } ${RELOCATING+ > data}
166   .noinit ${RELOCATING+ SIZEOF(.bss) + ADDR(.bss)} :
167   {
168     ${RELOCATING+ PROVIDE (__noinit_start = .) ; }
169     *(.noinit)
170     *(COMMON)
171     ${RELOCATING+ PROVIDE (__noinit_end = .) ; }
172     ${RELOCATING+ _end = . ;  }
173   } ${RELOCATING+ > data}
175   .vectors ${RELOCATING-0}:
176   {
177     ${RELOCATING+ PROVIDE (__vectors_start = .) ; }
178     *(.vectors*)
179     ${RELOCATING+ _vectors_end = . ; }
180   } ${RELOCATING+ > vectors}
183   /* Stabs debugging sections.  */
184   .stab 0 : { *(.stab) } 
185   .stabstr 0 : { *(.stabstr) }
186   .stab.excl 0 : { *(.stab.excl) }
187   .stab.exclstr 0 : { *(.stab.exclstr) }
188   .stab.index 0 : { *(.stab.index) }
189   .stab.indexstr 0 : { *(.stab.indexstr) }
190   .comment 0 : { *(.comment) }
192   /* DWARF debug sections.
193      Symbols in the DWARF debugging sections are relative to the beginning
194      of the section so we begin them at 0.  */
196   /* DWARF 1 */
197   .debug          0 : { *(.debug) }
198   .line           0 : { *(.line) }
200   /* GNU DWARF 1 extensions */
201   .debug_srcinfo  0 : { *(.debug_srcinfo) }
202   .debug_sfnames  0 : { *(.debug_sfnames) }
204   /* DWARF 1.1 and DWARF 2 */
205   .debug_aranges  0 : { *(.debug_aranges) }
206   .debug_pubnames 0 : { *(.debug_pubnames) }
208   /* DWARF 2 */
209   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
210   .debug_abbrev   0 : { *(.debug_abbrev) }
211   .debug_line     0 : { *(.debug_line) }
212   .debug_frame    0 : { *(.debug_frame) }
213   .debug_str      0 : { *(.debug_str) }
214   .debug_loc      0 : { *(.debug_loc) }
215   .debug_macinfo  0 : { *(.debug_macinfo) }
217   PROVIDE (__stack = ${STACK}) ;
218   PROVIDE (__data_start_rom = _etext) ;
219   PROVIDE (__data_end_rom   = _etext + SIZEOF (.data)) ;
220   PROVIDE (__noinit_start_rom = _etext + SIZEOF (.data)) ;
221   PROVIDE (__noinit_end_rom = _etext + SIZEOF (.data) + SIZEOF (.noinit)) ;