1# Adapted from mips.sc
2#
3# Copyright (C) 2014-2016 Free Software Foundation, Inc.
4#
5# Copying and distribution of this file, with or without modification,
6# are permitted in any medium without royalty provided the copyright
7# notice and this notice are preserved.
8#
9# These variables may be overridden by the emulation file.  The
10# defaults are appropriate for a DECstation running Ultrix.
11
12test -z "$ENTRY" && ENTRY=_start
13
14#test -z "$TEXT_START_ADDR" && TEXT_START_ADDR="0x0"
15
16CTOR=".ctors ${CONSTRUCTING-0} :
17  {
18    ${CONSTRUCTING+${CTOR_START}}
19    /* gcc uses crtbegin.o to find the start of
20       the constructors, so we make sure it is
21       first.  Because this is a wildcard, it
22       doesn't matter if the user does not
23       actually link against crtbegin.o; the
24       linker won't look for a file to match a
25       wildcard.  The wildcard also means that it
26       doesn't matter which directory crtbegin.o
27       is in.  */
28
29    KEEP (*crtbegin.o(.ctors))
30
31    /* We don't want to include the .ctor section from
32       from the crtend.o file until after the sorted ctors.
33       The .ctor section from the crtend file contains the
34       end of ctors marker and it must be last */
35
36    KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
37    KEEP (*(SORT(.ctors.*)))
38    KEEP (*(.ctors))
39    ${CONSTRUCTING+${CTOR_END}}
40  }"
41
42DTOR=" .dtors       ${CONSTRUCTING-0} :
43  {
44    ${CONSTRUCTING+${DTOR_START}}
45    KEEP (*crtbegin.o(.dtors))
46    KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
47    KEEP (*(SORT(.dtors.*)))
48    KEEP (*(.dtors))
49    ${CONSTRUCTING+${DTOR_END}}
50  }"
51
52cat <<EOF
53/* Copyright (C) 2014-2016 Free Software Foundation, Inc.
54
55   Copying and distribution of this script, with or without modification,
56   are permitted in any medium without royalty provided the copyright
57   notice and this notice are preserved.  */
58
59OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
60	      "${LITTLE_OUTPUT_FORMAT}")
61/*${LIB_SEARCH_DIRS}*/
62${RELOCATING+${LIB_SEARCH_DIRS}}
63
64${RELOCATING+ENTRY (${ENTRY})}
65
66_TEXT_START_ADDR = DEFINED(_TEXT_START_ADDR) ? _TEXT_START_ADDR : 0x50;
67_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x0;
68_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x400;
69
70SECTIONS
71{
72  .vectors.reset 0x0 : { KEEP (*(.vectors.reset)) } = 0
73  .vectors.sw_exception 0x8 : { KEEP (*(.vectors.sw_exception)) } = 0
74  .vectors.interrupt 0x10 : { KEEP (*(.vectors.interrupt)) } = 0
75  .vectors.debug_sw_break 0x18 : { KEEP (*(.vectors.debug_sw_break)) } = 0
76  .vectors.hw_exception 0x20 : { KEEP (*(.vectors.hw_exception)) } = 0
77
78  ${RELOCATING+. = _TEXT_START_ADDR;}
79
80  ${RELOCATING+ _ftext  =  .;}
81  .text : {
82    ${RELOCATING+*(.text)}
83    ${RELOCATING+*(.text.*)}
84    ${RELOCATING+*(.gnu.linkonce.t.*)}
85  }
86  ${RELOCATING+ _etext  =  .;}
87
88  .init : { KEEP (*(.init))	} =0
89  .fini : { KEEP (*(.fini))	} =0
90
91  ${RELOCATING+PROVIDE (__CTOR_LIST__ = .);}
92  ${RELOCATING+PROVIDE (___CTOR_LIST__ = .);}
93  ${RELOCATING+${CTOR}}
94  ${RELOCATING+PROVIDE (__CTOR_END__ = .);}
95  ${RELOCATING+PROVIDE (___CTOR_END__ = .);}
96
97  ${RELOCATING+PROVIDE (__DTOR_LIST__ = .);}
98  ${RELOCATING+PROVIDE (___DTOR_LIST__ = .);}
99  ${RELOCATING+${DTOR}}
100  ${RELOCATING+PROVIDE (__DTOR_END__ = .);}
101  ${RELOCATING+PROVIDE (___DTOR_END__ = .);}
102
103  ${RELOCATING+ . = ALIGN(4);}
104   ${RELOCATING+ _frodata = . ;}
105  .rodata : {
106    ${RELOCATING+*(.rodata)}
107    ${RELOCATING+*(.rodata.*)}
108    ${RELOCATING+*(.gnu.linkonce.r.*)}
109    ${CONSTRUCTING+CONSTRUCTORS}; /* Is this needed? */
110  }
111  ${RELOCATING+ _erodata = .;}
112
113  /* Alignments by 8 to ensure that _SDA2_BASE_ on a word boundary */
114  /* Note that .sdata2 and .sbss2 must be contiguous */
115  ${RELOCATING+. = ALIGN(8);}
116  ${RELOCATING+ _ssrw = .;}
117  .sdata2 : {
118    ${RELOCATING+*(.sdata2)}
119    ${RELOCATING+*(.sdata2.*)}
120    ${RELOCATING+*(.gnu.linkonce.s2.*)}
121  }
122  ${RELOCATING+. = ALIGN(4);}
123  .sbss2 : {
124    ${RELOCATING+PROVIDE (__sbss2_start = .);}
125    ${RELOCATING+*(.sbss2)}
126    ${RELOCATING+*(.sbss2.*)}
127    ${RELOCATING+*(.gnu.linkonce.sb2.*)}
128    ${RELOCATING+PROVIDE (__sbss2_end = .);}
129  }
130  ${RELOCATING+. = ALIGN(8);}
131  ${RELOCATING+ _essrw = .;}
132  ${RELOCATING+ _ssrw_size = _essrw - _ssrw;}
133  ${RELOCATING+ PROVIDE (_SDA2_BASE_ = _ssrw + (_ssrw_size / 2 ));}
134
135  ${RELOCATING+ . = ALIGN(4);}
136  ${RELOCATING+ _fdata = .;}
137  .data : {
138    ${RELOCATING+*(.data)}
139    ${RELOCATING+*(.gnu.linkonce.d.*)}
140    ${CONSTRUCTING+CONSTRUCTORS}; /* Is this needed? */
141  }
142  ${RELOCATING+ _edata = . ;}
143
144   /* Added to handle pic code */
145  .got : {
146    ${RELOCATING+*(.got)}
147  }
148
149  .got1 : {
150    ${RELOCATING+*(.got1)}
151  }
152
153  .got2 : {
154    ${RELOCATING+*(.got2)}
155  }
156
157  /* Added by Sathya to handle C++ exceptions */
158  .eh_frame : {
159    ${RELOCATING+*(.eh_frame)}
160  }
161
162  .jcr : {
163    ${RELOCATING+*(.jcr)}
164  }
165
166  .gcc_except_table : {
167    ${RELOCATING+*(.gcc_except_table)}
168  }
169
170  /* Alignments by 8 to ensure that _SDA_BASE_ on a word boundary */
171  /* Note that .sdata and .sbss must be contiguous */
172  ${RELOCATING+. = ALIGN(8);}
173  ${RELOCATING+ _ssro = .;}
174  .sdata : {
175    ${RELOCATING+*(.sdata)}
176    ${RELOCATING+*(.sdata.*)}
177    ${RELOCATING+*(.gnu.linkonce.s.*)}
178  }
179  ${RELOCATING+. = ALIGN(4);}
180  .sbss : {
181    ${RELOCATING+PROVIDE (__sbss_start = .);}
182    ${RELOCATING+*(.sbss)}
183    ${RELOCATING+*(.sbss.*)}
184    ${RELOCATING+*(.gnu.linkonce.sb.*)}
185    ${RELOCATING+PROVIDE (__sbss_end = .);}
186  }
187  ${RELOCATING+. = ALIGN(8);}
188  ${RELOCATING+ _essro = .;}
189  ${RELOCATING+ _ssro_size = _essro - _ssro;}
190  ${RELOCATING+PROVIDE (_SDA_BASE_ = _ssro + (_ssro_size / 2 ));}
191
192  ${RELOCATING+ . = ALIGN(4);}
193  ${RELOCATING+ _fbss = .;}
194  .bss : {
195    ${RELOCATING+PROVIDE (__bss_start = .);}
196    ${RELOCATING+*(.bss)}
197    ${RELOCATING+*(.bss.*)}
198    ${RELOCATING+*(.gnu.linkonce.b.*)}
199    ${RELOCATING+*(COMMON)}
200    ${RELOCATING+. = ALIGN(. != 0 ? 4 : 1);}
201
202    ${RELOCATING+PROVIDE (__bss_end = .);}
203
204  }
205
206  ${RELOCATING+ . = ALIGN(4);}
207
208  .heap : {
209    ${RELOCATING+ _heap = .;}
210    ${RELOCATING+ _heap_start = .;}
211    ${RELOCATING+ . += _HEAP_SIZE;}
212    ${RELOCATING+ _heap_end = .;}
213  }
214
215  ${RELOCATING+ . = ALIGN(4);}
216
217  .stack : {
218    ${RELOCATING+ _stack_end = .;}
219    ${RELOCATING+ . += _STACK_SIZE;}
220    ${RELOCATING+ . = ALIGN(. != 0 ? 8 : 1);}
221    ${RELOCATING+ _stack = .;}
222    ${RELOCATING+ _end = .;}
223  }
224
225  .tdata : {
226    ${RELOCATING+*(.tdata)}
227    ${RELOCATING+*(.tdata.*)}
228    ${RELOCATING+*(.gnu.linkonce.td.*)}
229  }
230  .tbss : {
231    ${RELOCATING+*(.tbss)}
232    ${RELOCATING+*(.tbss.*)}
233    ${RELOCATING+*(.gnu.linkonce.tb.*)}
234  }
235}
236EOF
237