1/* Default linker script, for normal executables */
2/* Copyright (C) 2014-2018 Free Software Foundation, Inc.
3   Copying and distribution of this script, with or without modification,
4   are permitted in any medium without royalty provided the copyright
5   notice and this notice are preserved.  */
6
7/* source, modified:
8 *  /opt/CodeSourcery/Sourcery_G++_Lite/mips-sde-elf/lib/ldscripts/elf32ltsmip.x
9 */
10#ifdef __mips64
11OUTPUT_FORMAT("elf64-tradlittlemips", "elf64-tradbigmips",
12              "elf64-tradlittlemips")
13#else
14OUTPUT_FORMAT("elf32-tradlittlemips", "elf32-tradbigmips",
15              "elf32-tradlittlemips")
16#endif
17OUTPUT_ARCH(mips)
18ENTRY(__start)
19
20PHDRS
21{
22  phdr PT_PHDR PHDRS;
23  interp PT_INTERP;
24  ro PT_LOAD FILEHDR PHDRS;
25  rw PT_LOAD;
26  dyn PT_DYNAMIC;
27  tls PT_TLS;
28  ehf PT_GNU_EH_FRAME;
29  L4_DEFINE_L4PHDRS
30}
31
32SECTIONS
33{
34  /* Read-only sections, merged into text segment: */
35  PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x0400000)); . = SEGMENT_START("text-segment", 0x0400000) + SIZEOF_HEADERS;
36  .interp         : { *(.interp) } :ro :interp
37  .MIPS.abiflags   : { *(.MIPS.abiflags) } :ro
38  .MIPS.options : { *(.MIPS.options) }
39  .reginfo        : { *(.reginfo) }
40  .note.gnu.build-id : { *(.note.gnu.build-id) }
41  .dynamic        : { *(.dynamic) } :dyn :ro
42  .hash           : { *(.hash) } :ro
43  .gnu.hash       : { *(.gnu.hash) }
44  .dynsym         : { *(.dynsym) }
45  .dynstr         : { *(.dynstr) }
46  .gnu.version    : { *(.gnu.version) }
47  .gnu.version_d  : { *(.gnu.version_d) }
48  .gnu.version_r  : { *(.gnu.version_r) }
49  .rel.init       : { *(.rel.init) }
50  .rela.init      : { *(.rela.init) }
51  .rel.text       : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) }
52  .rela.text      : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) }
53  .rel.fini       : { *(.rel.fini) }
54  .rela.fini      : { *(.rela.fini) }
55  .rel.rodata     : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) }
56  .rela.rodata    : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) }
57  .rel.data.rel.ro   : { *(.rel.data.rel.ro .rel.data.rel.ro.* .rel.gnu.linkonce.d.rel.ro.*) }
58  .rela.data.rel.ro   : { *(.rela.data.rel.ro .rela.data.rel.ro.* .rela.gnu.linkonce.d.rel.ro.*) }
59  .rel.data       : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) }
60  .rela.data      : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) }
61  .rel.tdata	  : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) }
62  .rela.tdata	  : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) }
63  .rel.tbss	  : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) }
64  .rela.tbss	  : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) }
65  .rel.ctors      : { *(.rel.ctors) }
66  .rela.ctors     : { *(.rela.ctors) }
67  .rel.dtors      : { *(.rel.dtors) }
68  .rela.dtors     : { *(.rela.dtors) }
69  .rel.got        : { *(.rel.got) }
70  .rela.got       : { *(.rela.got) }
71  .rel.dyn        : { *(.rel.dyn) }
72  .rel.sdata      : { *(.rel.sdata .rel.sdata.* .rel.gnu.linkonce.s.*) }
73  .rela.sdata     : { *(.rela.sdata .rela.sdata.* .rela.gnu.linkonce.s.*) }
74  .rel.sbss       : { *(.rel.sbss .rel.sbss.* .rel.gnu.linkonce.sb.*) }
75  .rela.sbss      : { *(.rela.sbss .rela.sbss.* .rela.gnu.linkonce.sb.*) }
76  .rel.sdata2     : { *(.rel.sdata2 .rel.sdata2.* .rel.gnu.linkonce.s2.*) }
77  .rela.sdata2    : { *(.rela.sdata2 .rela.sdata2.* .rela.gnu.linkonce.s2.*) }
78  .rel.sbss2      : { *(.rel.sbss2 .rel.sbss2.* .rel.gnu.linkonce.sb2.*) }
79  .rela.sbss2     : { *(.rela.sbss2 .rela.sbss2.* .rela.gnu.linkonce.sb2.*) }
80  .rel.bss        : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) }
81  .rela.bss       : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) }
82  .rel.iplt       :
83    {
84      PROVIDE_HIDDEN (__rel_iplt_start = .);
85      *(.rel.iplt)
86      PROVIDE_HIDDEN (__rel_iplt_end = .);
87    }
88  .rela.iplt      :
89    {
90      PROVIDE_HIDDEN (__rela_iplt_start = .);
91      *(.rela.iplt)
92      PROVIDE_HIDDEN (__rela_iplt_end = .);
93    }
94  .rel.plt        :
95    {
96      *(.rel.plt)
97    }
98  .rela.plt       :
99    {
100      *(.rela.plt)
101    }
102  .init           :
103  {
104    KEEP (*(SORT_NONE(.init)))
105  }
106  .text           :
107  {
108    _ftext = . ;
109    *(.text.unlikely .text.*_unlikely .text.unlikely.*)
110    *(.text.exit .text.exit.*)
111    *(.text.startup .text.startup.*)
112    *(.text.hot .text.hot.*)
113    *(.text .stub .text.* .gnu.linkonce.t.*)
114    /* .gnu.warning sections are handled specially by elf32.em.  */
115    *(.gnu.warning)
116    *(.mips16.fn.*) *(.mips16.call.*)
117  }
118  .fini           :
119  {
120    KEEP (*(SORT_NONE(.fini)))
121  }
122  PROVIDE (__etext = .);
123  PROVIDE (_etext = .);
124  PROVIDE (etext = .);
125  .rol4re_elf_aux : {
126    KEEP (*(.rol4re_elf_aux))
127  } : ro : l4re_aux
128  .rodata         : { *(.rodata .rodata.* .gnu.linkonce.r.*) } : ro
129  .rodata1        : { *(.rodata1) }
130  .sdata2         :
131  {
132    *(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
133  }
134  .sbss2          : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) }
135  .eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) } :ehf :ro
136  .eh_frame       : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) } :ro
137  .gcc_except_table   : ONLY_IF_RO { *(.gcc_except_table
138  .gcc_except_table.*) } :ro
139  .gnu_extab   : ONLY_IF_RO { *(.gnu_extab*) } :ro
140  /* These sections are generated by the Sun/Oracle C++ compiler.  */
141  .exception_ranges   : ONLY_IF_RO { *(.exception_ranges
142  .exception_ranges*) } :ro
143  .plt            : { *(.plt) } :ro
144  .iplt           : { *(.iplt) }
145  /* Adjust the address for the data segment.  We want to adjust up to
146     the same address within the page on the next page up.  */
147  . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
148  /* Exception handling  */
149  .eh_frame       : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) } :rw
150  .gnu_extab      : ONLY_IF_RW { *(.gnu_extab) } :rw
151  .gcc_except_table   : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } :rw
152  .exception_ranges   : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) } :rw
153  /* Thread Local Storage sections  */
154  .tdata	  : { *(.tdata .tdata.* .gnu.linkonce.td.*) } :rw : tls
155  .tbss		  : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
156  .preinit_array     :
157  {
158    PROVIDE_HIDDEN (__preinit_array_start = .);
159    KEEP (*(.preinit_array))
160    PROVIDE_HIDDEN (__preinit_array_end = .);
161  } : rw
162  .init_array     :
163  {
164    PROVIDE_HIDDEN (__init_array_start = .);
165    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
166    KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
167    PROVIDE_HIDDEN (__init_array_end = .);
168  }
169  .fini_array     :
170  {
171    PROVIDE_HIDDEN (__fini_array_start = .);
172    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
173    KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
174    PROVIDE_HIDDEN (__fini_array_end = .);
175  }
176  .ctors          :
177  {
178    /* gcc uses crtbegin.o to find the start of
179       the constructors, so we make sure it is
180       first.  Because this is a wildcard, it
181       doesn't matter if the user does not
182       actually link against crtbegin.o; the
183       linker won't look for a file to match a
184       wildcard.  The wildcard also means that it
185       doesn't matter which directory crtbegin.o
186       is in.  */
187    KEEP (*crtbegin.o(.ctors))
188    KEEP (*crtbegin?.o(.ctors))
189    /* We don't want to include the .ctor section from
190       the crtend.o file until after the sorted ctors.
191       The .ctor section from the crtend file contains the
192       end of ctors marker and it must be last */
193    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
194    KEEP (*(SORT(.ctors.*)))
195    KEEP (*(.ctors))
196  }
197  .dtors          :
198  {
199    KEEP (*crtbegin.o(.dtors))
200    KEEP (*crtbegin?.o(.dtors))
201    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
202    KEEP (*(SORT(.dtors.*)))
203    KEEP (*(.dtors))
204  }
205  .jcr            : { KEEP (*(.jcr)) }
206  .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
207  . = DATA_SEGMENT_RELRO_END (0, .);
208  .data           :
209  {
210    _fdata = . ;
211    *(.data .data.* .gnu.linkonce.d.*)
212    SORT(CONSTRUCTORS)
213  } :rw
214  .data1          : { *(.data1) }
215  .got.plt        : { *(.got.plt) }
216  . = .;
217  . = .;
218  HIDDEN (_gp = ALIGN (16) + 0x7ff0);
219  .got            : { *(.got) }
220  /* We want the small data sections together, so single-instruction offsets
221     can access them all, and initialized data all before uninitialized, so
222     we can shorten the on-disk segment size.  */
223  .sdata          :
224  {
225    *(.sdata .sdata.* .gnu.linkonce.s.*)
226  }
227  .lit8           : { *(.lit8) }
228  .lit4           : { *(.lit4) }
229  .srdata         : { *(.srdata) }
230  _edata = .; PROVIDE (edata = .);
231  . = .;
232  __bss_start = .;
233  _fbss = .;
234  .sbss           :
235  {
236    *(.dynsbss)
237    *(.sbss .sbss.* .gnu.linkonce.sb.*)
238    *(.scommon)
239  }
240  .bss            :
241  {
242   *(.dynbss)
243   *(.bss .bss.* .gnu.linkonce.b.*)
244   *(COMMON)
245   /* Align here to ensure that the .bss section occupies space up to
246      _end.  Align after .bss to ensure correct alignment even if the
247      .bss section disappears because there are no input sections.
248      FIXME: Why do we need it? When there is no .bss section, we don't
249      pad the .data section.  */
250   . = ALIGN(. != 0 ? __SIZEOF_LONG__ : 1);
251  }
252  . = ALIGN(__SIZEOF_LONG__);
253  . = SEGMENT_START("ldata-segment", .);
254  . = ALIGN(__SIZEOF_LONG__);
255  _end = .; PROVIDE (end = .);
256  . = DATA_SEGMENT_END (.);
257  /* Stabs debugging sections.  */
258  .stab          0 : { *(.stab) }
259  .stabstr       0 : { *(.stabstr) }
260  .stab.excl     0 : { *(.stab.excl) }
261  .stab.exclstr  0 : { *(.stab.exclstr) }
262  .stab.index    0 : { *(.stab.index) }
263  .stab.indexstr 0 : { *(.stab.indexstr) }
264  .comment       0 : { *(.comment) }
265  /* DWARF debug sections.
266     Symbols in the DWARF debugging sections are relative to the beginning
267     of the section so we begin them at 0.  */
268  /* DWARF 1 */
269  .debug          0 : { *(.debug) }
270  .line           0 : { *(.line) }
271  /* GNU DWARF 1 extensions */
272  .debug_srcinfo  0 : { *(.debug_srcinfo) }
273  .debug_sfnames  0 : { *(.debug_sfnames) }
274  /* DWARF 1.1 and DWARF 2 */
275  .debug_aranges  0 : { *(.debug_aranges) }
276  .debug_pubnames 0 : { *(.debug_pubnames) }
277  /* DWARF 2 */
278  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
279  .debug_abbrev   0 : { *(.debug_abbrev) }
280  .debug_line     0 : { *(.debug_line .debug_line.* .debug_line_end ) }
281  .debug_frame    0 : { *(.debug_frame) }
282  .debug_str      0 : { *(.debug_str) }
283  .debug_loc      0 : { *(.debug_loc) }
284  .debug_macinfo  0 : { *(.debug_macinfo) }
285  /* SGI/MIPS DWARF 2 extensions */
286  .debug_weaknames 0 : { *(.debug_weaknames) }
287  .debug_funcnames 0 : { *(.debug_funcnames) }
288  .debug_typenames 0 : { *(.debug_typenames) }
289  .debug_varnames  0 : { *(.debug_varnames) }
290  /* DWARF 3 */
291  .debug_pubtypes 0 : { *(.debug_pubtypes) }
292  .debug_ranges   0 : { *(.debug_ranges) }
293  /* DWARF Extension.  */
294  .debug_macro    0 : { *(.debug_macro) }
295  .debug_addr     0 : { *(.debug_addr) }
296  .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
297  .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
298  .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
299  .mdebug.abi32 0 : { KEEP(*(.mdebug.abi32)) }
300  .mdebug.abiN32 0 : { KEEP(*(.mdebug.abiN32)) }
301  .mdebug.abi64 0 : { KEEP(*(.mdebug.abi64)) }
302  .mdebug.abiO64 0 : { KEEP(*(.mdebug.abiO64)) }
303  .mdebug.eabi32 0 : { KEEP(*(.mdebug.eabi32)) }
304  .mdebug.eabi64 0 : { KEEP(*(.mdebug.eabi64)) }
305  .gcc_compiled_long32 0 : { KEEP(*(.gcc_compiled_long32)) }
306  .gcc_compiled_long64 0 : { KEEP(*(.gcc_compiled_long64)) }
307  /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
308}
309