xref: /netbsd-src/external/gpl3/binutils.old/dist/ld/scripttempl/elfarcv2.sc (revision 9fd8799cb5ceb66c69f2eb1a6d26a1d587ba1f1e)
1#
2# Unusual variables checked by this code:
3#	NOP - four byte opcode for no-op (defaults to 0)
4#	NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not
5#		empty.
6#	OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
7#		(e.g., .PARISC.milli)
8# When adding sections, do note that the names of some sections are used
9# when specifying the start address of the next.
10#
11test -z "$ENTRY" && ENTRY=start
12test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
13test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
14# If we request a big endian toolchain, give a big endian linker
15test -z "$GOT" && GOT=".got          ${RELOCATING-0} : { *(.got.plt) *(.got) } ${RELOCATING+ > ${DATA_MEMORY}}"
16test "${ARC_ENDIAN}" == "big" && OUTPUT_FORMAT=${BIG_OUTPUT_FORMAT}
17if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
18test -z "${ELFSIZE}" && ELFSIZE=32
19test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
20test "$LD_FLAG" = "N" && DATA_ADDR=.
21
22CTOR=".ctors        ${CONSTRUCTING-0} :
23  {
24    ${CONSTRUCTING+${CTOR_START}}
25    /* gcc uses crtbegin.o to find the start of
26       the constructors, so we make sure it is
27       first.  Because this is a wildcard, it
28       doesn't matter if the user does not
29       actually link against crtbegin.o; the
30       linker won't look for a file to match a
31       wildcard.  The wildcard also means that it
32       doesn't matter which directory crtbegin.o
33       is in.  */
34
35    KEEP (*crtbegin*.o(.ctors))
36
37    /* We don't want to include the .ctor section from
38       from the crtend.o file until after the sorted ctors.
39       The .ctor section from the crtend file contains the
40       end of ctors marker and it must be last */
41
42    KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors))
43    KEEP (*(SORT(.ctors.*)))
44    KEEP (*(.ctors))
45    ${CONSTRUCTING+${CTOR_END}}
46  } ${RELOCATING+ > ${DATA_MEMORY}}"
47DTOR=".dtors        ${CONSTRUCTING-0} :
48  {
49    ${CONSTRUCTING+${DTOR_START}}
50    KEEP (*crtbegin*.o(.dtors))
51    KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors))
52    KEEP (*(SORT(.dtors.*)))
53    KEEP (*(.dtors))
54    ${CONSTRUCTING+${DTOR_END}}
55  } ${RELOCATING+ > ${DATA_MEMORY}}"
56
57if test -z "${NO_SMALL_DATA}"; then
58  SBSS=".sbss         ${RELOCATING-0} :
59  {
60    ${RELOCATING+PROVIDE (__sbss_start = .);}
61    ${RELOCATING+PROVIDE (___sbss_start = .);}
62    *(.dynsbss)
63    *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
64    *(.scommon)
65    ${RELOCATING+PROVIDE (__sbss_end = .);}
66    ${RELOCATING+PROVIDE (___sbss_end = .);}
67  } ${RELOCATING+ > ${SDATA_MEMORY}}"
68  SBSS2=".sbss2        ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) } ${RELOCATING+ > ${SDATA_MEMORY}}"
69  SDATA="/* We want the small data sections together, so single-instruction offsets
70     can access them all, and initialized data all before uninitialized, so
71     we can shorten the on-disk segment size.  */
72  .sdata        ${RELOCATING-0} :
73  {
74    ${RELOCATING+${SDATA_START_SYMBOLS}}
75    *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
76
77    ${RELOCATING+_edata  =  .;}
78    ${RELOCATING+PROVIDE (edata = .);}
79  } ${RELOCATING+ > ${SDATA_MEMORY}}"
80  SDATA2=".sdata2       ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) } ${RELOCATING+ > ${SDATA_MEMORY}}"
81  REL_SDATA=".rel.sdata    ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
82  .rela.sdata   ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
83  REL_SBSS=".rel.sbss     ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
84  .rela.sbss    ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
85  REL_SDATA2=".rel.sdata2   ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
86  .rela.sdata2  ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
87  REL_SBSS2=".rel.sbss2    ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
88  .rela.sbss2   ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
89fi
90
91#
92# We provide two emulations: a fixed on that defines some memory banks
93# and a configurable one that includes a user provided memory definition.
94#
95case $GENERIC_BOARD in
96  yes|1|YES)
97	MEMORY_DEF="
98/* Get memory banks definition from some user configuration file.
99   This file must be located in some linker directory (search path
100   with -L<dir>). See fixed memory banks emulation script.  */
101INCLUDE memory.x;
102"
103	;;
104  *)
105MEMORY_DEF="
106/* Fixed definition of the available memory banks.
107   See generic emulation script for a user defined configuration.  */
108MEMORY
109{
110    ICCM : ORIGIN = 0x00000000, LENGTH = ${ICCM_SIZE}
111    DCCM : ORIGIN = ${RAM_START_ADDR}, LENGTH = ${RAM_SIZE}
112}
113
114/* Setup the stack on the top of the data memory bank.  */
115PROVIDE (__stack_top = (${RAM_START_ADDR} + ${RAM_SIZE} - 1) & -4);
116PROVIDE (__end_heap = ${RAM_START_ADDR} + ${RAM_SIZE} - 1);
117"
118	;;
119esac
120
121cat <<EOF
122OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}", "${LITTLE_OUTPUT_FORMAT}")
123OUTPUT_ARCH(${OUTPUT_ARCH})
124${RELOCATING+ENTRY(${ENTRY})}
125
126${RELOCATING+${LIB_SEARCH_DIRS}}
127${RELOCATING+${EXECUTABLE_SYMBOLS}}
128${RELOCATING+${MEMORY_DEF}}
129
130SECTIONS
131{
132  .ivt 0x00 :
133  {
134   KEEP (*(.ivt));
135  } ${RELOCATING+ > ${STARTUP_MEMORY}}
136
137  .startup 0x100:
138  {
139    KEEP (*crt0.o(.text.__startup))
140  } ${RELOCATING+ > ${STARTUP_MEMORY}}
141
142  /* Read-only sections, merged into text segment: */
143  ${TEXT_DYNAMIC+${DYNAMIC}}
144  .hash        ${RELOCATING-0} : { *(.hash)		}
145  .dynsym      ${RELOCATING-0} : { *(.dynsym)		}
146  .dynstr      ${RELOCATING-0} : { *(.dynstr)		}
147  .gnu.version ${RELOCATING-0} : { *(.gnu.version)	}
148  .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d)	}
149  .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r)	}
150
151  .rel.init     ${RELOCATING-0} : { *(.rel.init) }
152  .rela.init    ${RELOCATING-0} : { *(.rela.init) }
153  .rel.text     ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
154  .rela.text    ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
155  .rel.fini     ${RELOCATING-0} : { *(.rel.fini) }
156  .rela.fini    ${RELOCATING-0} : { *(.rela.fini) }
157  .rel.rodata   ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
158  .rela.rodata  ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
159  .rel.data     ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
160  .rela.data    ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
161  .rel.tdata	${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
162  .rela.tdata	${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
163  .rel.tbss	${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
164  .rela.tbss	${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
165  .rel.ctors    ${RELOCATING-0} : { *(.rel.ctors) }
166  .rela.ctors   ${RELOCATING-0} : { *(.rela.ctors) }
167  .rel.dtors    ${RELOCATING-0} : { *(.rel.dtors) }
168  .rela.dtors   ${RELOCATING-0} : { *(.rela.dtors) }
169  .rel.got      ${RELOCATING-0} : { *(.rel.got) }
170  .rela.got     ${RELOCATING-0} : { *(.rela.got) }
171  ${REL_SDATA}
172  ${REL_SBSS}
173  ${REL_SDATA2}
174  ${REL_SBSS2}
175  .rel.bss      ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
176  .rela.bss     ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
177
178  .jcr : { KEEP (*(.jcr)) } ${RELOCATING+> ${TEXT_MEMORY}}
179  .eh_frame : { KEEP (*(.eh_frame)) } ${RELOCATING+> ${TEXT_MEMORY}}
180  .gcc_except_table : { *(.gcc_except_table) *(.gcc_except_table.*) } ${RELOCATING+> ${TEXT_MEMORY}}
181  .plt : { *(.plt) } ${RELOCATING+> ${TEXT_MEMORY}}
182  .jlitab :
183  {
184    ${RELOCATING+${JLI_START_TABLE}}
185     jlitab*.o:(.jlitab*) *(.jlitab*)
186  } ${RELOCATING+> ${TEXT_MEMORY}}
187
188  .rodata ${RELOCATING-0} :
189  {
190    *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r.*)}
191  } ${RELOCATING+> ${TEXT_MEMORY}}
192
193  .rodata1      ${RELOCATING-0} : { *(.rodata1) } ${RELOCATING+> ${TEXT_MEMORY}}
194
195  .init         ${RELOCATING-0} :
196  {
197    ${RELOCATING+${INIT_START}}
198    KEEP (*(.init))
199    ${RELOCATING+${INIT_END}}
200  } ${RELOCATING+ > ${TEXT_MEMORY}}  =${NOP-0}
201
202  .text         ${RELOCATING-0} :
203  {
204    ${RELOCATING+${TEXT_START_SYMBOLS}}
205
206    *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
207    /* .gnu.warning sections are handled specially by elf32.em.  */
208    *(.gnu.warning)
209
210    ${RELOCATING+${OTHER_TEXT_SECTIONS}}
211
212  } ${RELOCATING+ > ${TEXT_MEMORY}} =${NOP-0}
213
214  .fini         ${RELOCATING-0} :
215  {
216    ${RELOCATING+${FINI_START}}
217    KEEP (*(.fini))
218    ${RELOCATING+${FINI_END}}
219
220    ${RELOCATING+PROVIDE (__etext = .);}
221    ${RELOCATING+PROVIDE (_etext = .);}
222    ${RELOCATING+PROVIDE (etext = .);}
223  } ${RELOCATING+ > ${TEXT_MEMORY}} =${NOP-0}
224
225  ${RELOCATING+${OTHER_READONLY_SECTIONS}}
226
227  /* Start of the data section image in ROM.  */
228  ${RELOCATING+__data_image = .;}
229  ${RELOCATING+PROVIDE (__data_image = .);}
230
231  .data	${RELOCATING-0} :
232  {
233    ${RELOCATING+ PROVIDE (__data_start = .) ; }
234    /* --gc-sections will delete empty .data. This leads to wrong start
235       addresses for subsequent sections because -Tdata= from the command
236       line will have no effect, see PR13697.  Thus, keep .data  */
237    KEEP (*(.data))
238    ${RELOCATING+${DATA_START_SYMBOLS}}
239    *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
240    ${CONSTRUCTING+SORT(CONSTRUCTORS)}
241
242  } ${RELOCATING+ > ${DATA_MEMORY}}
243
244  ${GOT}
245  ${RELOCATING+${CTOR}}
246  ${RELOCATING+${DTOR}}
247
248  ${RELOCATING+${SDATA}}
249  ${RELOCATING+${SDATA2}}
250  ${RELOCATING+${SBSS}}
251  ${RELOCATING+${SBSS2}}
252  .bss          ${RELOCATING-0} :
253  {
254   *(.dynbss)
255   *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
256   *(COMMON)
257   /* Align here to ensure that the .bss section occupies space up to
258      _end.  Align after .bss to ensure correct alignment even if the
259      .bss section disappears because there are no input sections.  */
260   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
261   ${RELOCATING+_end = .;}
262   ${RELOCATING+PROVIDE (end = .);}
263  } ${RELOCATING+ > ${DATA_MEMORY}}
264
265  /* Global data not cleared after reset.  */
266  .noinit ${RELOCATING-0}:
267  {
268    *(.noinit*)
269    ${RELOCATING+. = ALIGN(${ALIGNMENT});}
270    ${RELOCATING+ PROVIDE (__start_heap = .) ; }
271  } ${RELOCATING+ > ${DATA_MEMORY}}
272
273
274  /* Stabs debugging sections.  */
275  .stab          0 : { *(.stab) }
276  .stabstr       0 : { *(.stabstr) }
277  .stab.excl     0 : { *(.stab.excl) }
278  .stab.exclstr  0 : { *(.stab.exclstr) }
279  .stab.index    0 : { *(.stab.index) }
280  .stab.indexstr 0 : { *(.stab.indexstr) }
281
282  .comment       0 : { *(.comment) }
283
284  /* DWARF debug sections.
285     Symbols in the DWARF debugging sections are relative to the beginning
286     of the section so we begin them at 0.  */
287
288  /* DWARF 1 */
289  .debug          0 : { *(.debug) }
290  .line           0 : { *(.line) }
291
292  /* GNU DWARF 1 extensions */
293  .debug_srcinfo  0 : { *(.debug_srcinfo) }
294  .debug_sfnames  0 : { *(.debug_sfnames) }
295
296  /* DWARF 1.1 and DWARF 2 */
297  .debug_aranges  0 : { *(.debug_aranges) }
298  .debug_pubnames 0 : { *(.debug_pubnames) }
299
300  /* DWARF 2 */
301  .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
302  .debug_abbrev   0 : { *(.debug_abbrev) }
303  .debug_line     0 : { *(.debug_line) }
304  .debug_frame    0 : { *(.debug_frame) }
305  .debug_str      0 : { *(.debug_str) }
306  .debug_loc      0 : { *(.debug_loc) }
307  .debug_macinfo  0 : { *(.debug_macinfo) }
308
309  /* DWARF 3 */
310  .debug_pubtypes 0 : { *(.debug_pubtypes) }
311  .debug_ranges   0 : { *(.debug_ranges) }
312
313  /* DWARF Extension.  */
314  .debug_macro    0 : { *(.debug_macro) }
315
316  /* ARC Extension Sections */
317  .arcextmap	  0 : { *(.gnu.linkonce.arcextmap.*) }
318}
319EOF
320