* Makefile.am (ALL_EMULATIONS): Add eelf32iq2000.o.
[external/binutils.git] / ld / scripttempl / iq2000.sc
1 #
2 # Unusual variables checked by this code:
3 #       NOP - four byte opcode for no-op (defaults to 0)
4 #       DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
5 #       INITIAL_READONLY_SECTIONS - at start of data segment
6 #       OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
7 #               (e.g., .PARISC.milli)
8 #       OTHER_TEXT_SECTIONS - these get put in .text when relocating
9 #       OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
10 #               (e.g., .PARISC.global)
11 #       OTHER_BSS_SECTIONS - other than .bss .sbss ...
12 #       OTHER_SECTIONS - at the end
13 #       EXECUTABLE_SYMBOLS - symbols that must be defined for an
14 #               executable (e.g., _DYNAMIC_LINK)
15 #       TEXT_START_SYMBOLS - symbols that appear at the start of the
16 #               .text section.
17 #       DATA_START_SYMBOLS - symbols that appear at the start of the
18 #               .data section.
19 #       OTHER_GOT_SYMBOLS - symbols defined just before .got.
20 #       OTHER_GOT_SECTIONS - sections just after .got.
21 #       OTHER_SDATA_SECTIONS - sections just after .sdata.
22 #       OTHER_BSS_SYMBOLS - symbols that appear at the start of the
23 #               .bss section besides __bss_start.
24 #       DATA_PLT - .plt should be in data segment, not text segment.
25 #       BSS_PLT - .plt should be in bss segment
26 #       TEXT_DYNAMIC - .dynamic in text segment, not data segment.
27 #       EMBEDDED - whether this is for an embedded system. 
28 #       SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
29 #               start address of shared library.
30 #       INPUT_FILES - INPUT command of files to always include
31 #       WRITABLE_RODATA - if set, the .rodata section should be writable
32 #       INIT_START, INIT_END -  statements just before and just after
33 #       combination of .init sections.
34 #       FINI_START, FINI_END - statements just before and just after
35 #       combination of .fini sections.
36 #
37 # When adding sections, do note that the names of some sections are used
38 # when specifying the start address of the next.
39 #
40
41 #  Many sections come in three flavours.  There is the 'real' section,
42 #  like ".data".  Then there are the per-procedure or per-variable
43 #  sections, generated by -ffunction-sections and -fdata-sections in GCC,
44 #  and useful for --gc-sections, which for a variable "foo" might be
45 #  ".data.foo".  Then there are the linkonce sections, for which the linker
46 #  eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
47 #  The exact correspondences are:
48 #
49 #  Section      Linkonce section
50 #  .text        .gnu.linkonce.t.foo
51 #  .rodata      .gnu.linkonce.r.foo
52 #  .data        .gnu.linkonce.d.foo
53 #  .bss         .gnu.linkonce.b.foo
54 #  .sdata       .gnu.linkonce.s.foo
55 #  .sbss        .gnu.linkonce.sb.foo
56 #  .sdata2      .gnu.linkonce.s2.foo
57 #  .sbss2       .gnu.linkonce.sb2.foo
58 #
59 #  Each of these can also have corresponding .rel.* and .rela.* sections.
60
61 test -z "$ENTRY" && ENTRY=_start
62 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
63 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
64 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
65 test -z "${ELFSIZE}" && ELFSIZE=32
66 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
67 test "$LD_FLAG" = "N" && DATA_ADDR=.
68 INTERP=".interp   ${RELOCATING-0} : { *(.interp)        }"
69 PLT=".plt    ${RELOCATING-0} : { *(.plt)        }"
70 DYNAMIC=".dynamic     ${RELOCATING-0} : { *(.dynamic) }"
71 RODATA=".rodata ${RELOCATING-0} : { *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r.*)} }"
72 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2) ${RELOCATING+*(.sbss2.*)} ${RELOCATING+*(.gnu.linkonce.sb2.*)} }"
73 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2) ${RELOCATING+*(.sdata2.*)} ${RELOCATING+*(.gnu.linkonce.s2.*)} }"
74 CTOR=".ctors ${CONSTRUCTING-0} : 
75   {
76     ${CONSTRUCTING+${CTOR_START}}
77     /* gcc uses crtbegin.o to find the start of
78        the constructors, so we make sure it is
79        first.  Because this is a wildcard, it
80        doesn't matter if the user does not
81        actually link against crtbegin.o; the
82        linker won't look for a file to match a
83        wildcard.  The wildcard also means that it
84        doesn't matter which directory crtbegin.o
85        is in.  */
86
87     KEEP (*crtbegin.o(.ctors))
88
89     /* We don't want to include the .ctor section from
90        from the crtend.o file until after the sorted ctors.
91        The .ctor section from the crtend file contains the
92        end of ctors marker and it must be last */
93
94     KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .ctors))
95     KEEP (*(SORT(.ctors.*)))
96     KEEP (*(.ctors))
97     ${CONSTRUCTING+${CTOR_END}}
98   }"
99
100 DTOR=" .dtors       ${CONSTRUCTING-0} :
101   {
102     ${CONSTRUCTING+${DTOR_START}}
103     KEEP (*crtbegin.o(.dtors))
104     KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .dtors))
105     KEEP (*(SORT(.dtors.*)))
106     KEEP (*(.dtors))
107     ${CONSTRUCTING+${DTOR_END}}
108   }"
109
110 # if this is for an embedded system, don't add SIZEOF_HEADERS.
111 if [ -z "$EMBEDDED" ]; then
112    test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
113 else
114    test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
115 fi
116
117 cat <<EOF
118 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
119               "${LITTLE_OUTPUT_FORMAT}")
120 OUTPUT_ARCH(${OUTPUT_ARCH})
121 ENTRY(${ENTRY})
122
123 ${RELOCATING+${LIB_SEARCH_DIRS}}
124 ${RELOCATING+/* Do we need any of these for elf?
125    __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}}  */}
126 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
127 ${RELOCATING+${INPUT_FILES}}
128 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
129   if gld -r is used and the intermediate file has sections starting
130   at non-zero addresses.  Could be a Solaris ld bug, could be a GNU ld
131   bug.  But for now assigning the zero vmas works.  */}
132
133 SECTIONS
134 {
135   ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
136   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
137   ${CREATE_SHLIB-${INTERP}}
138   ${TEXT_DYNAMIC+${DYNAMIC}}
139
140 EOF
141 if [ "x$COMBRELOC" = x ]; then
142   COMBRELOCCAT=cat
143 else
144   COMBRELOCCAT="cat > $COMBRELOC"
145 fi
146 eval $COMBRELOCCAT <<EOF
147   .rel.init    ${RELOCATING-0} : { *(.rel.init) }
148   .rela.init   ${RELOCATING-0} : { *(.rela.init)        }
149   .rel.text    ${RELOCATING-0} :
150     {
151       *(.rel.text)
152       ${RELOCATING+*(.rel.text.*)}
153       ${RELOCATING+*(.rel.gnu.linkonce.t.*)}
154     }
155   .rela.text   ${RELOCATING-0} :
156     {
157       *(.rela.text)
158       ${RELOCATING+*(.rela.text.*)}
159       ${RELOCATING+*(.rela.gnu.linkonce.t.*)}
160     }
161   .rel.fini    ${RELOCATING-0} : { *(.rel.fini) }
162   .rela.fini   ${RELOCATING-0} : { *(.rela.fini)        }
163   .rel.rodata  ${RELOCATING-0} :
164     {
165       *(.rel.rodata)
166       ${RELOCATING+*(.rel.rodata.*)}
167       ${RELOCATING+*(.rel.gnu.linkonce.r.*)}
168     }
169   .rela.rodata ${RELOCATING-0} :
170     {
171       *(.rela.rodata)
172       ${RELOCATING+*(.rela.rodata.*)}
173       ${RELOCATING+*(.rela.gnu.linkonce.r.*)}
174     }
175   ${OTHER_READONLY_RELOC_SECTIONS}
176   .rel.data    ${RELOCATING-0} :
177     {
178       *(.rel.data)
179       ${RELOCATING+*(.rel.data.*)}
180       ${RELOCATING+*(.rel.gnu.linkonce.d.*)}
181     }
182   .rela.data   ${RELOCATING-0} :
183     {
184       *(.rela.data)
185       ${RELOCATING+*(.rela.data.*)}
186       ${RELOCATING+*(.rela.gnu.linkonce.d.*)}
187     }
188   .rel.ctors   ${RELOCATING-0} : { *(.rel.ctors)        }
189   .rela.ctors  ${RELOCATING-0} : { *(.rela.ctors)       }
190   .rel.dtors   ${RELOCATING-0} : { *(.rel.dtors)        }
191   .rela.dtors  ${RELOCATING-0} : { *(.rela.dtors)       }
192   .rel.got     ${RELOCATING-0} : { *(.rel.got)          }
193   .rela.got    ${RELOCATING-0} : { *(.rela.got)         }
194   ${OTHER_GOT_RELOC_SECTIONS}
195   .rel.sdata   ${RELOCATING-0} :
196     {
197       *(.rel.sdata)
198       ${RELOCATING+*(.rel.sdata.*)}
199       ${RELOCATING+*(.rel.gnu.linkonce.s.*)}
200     }
201   .rela.sdata   ${RELOCATING-0} :
202     {
203       *(.rela.sdata)
204       ${RELOCATING+*(.rela.sdata.*)}
205       ${RELOCATING+*(.rela.gnu.linkonce.s.*)}
206     }
207   .rel.sbss    ${RELOCATING-0} :
208     { 
209       *(.rel.sbss)
210       ${RELOCATING+*(.rel.sbss.*)}
211       ${RELOCATING+*(.rel.gnu.linkonce.sb.*)}
212     }
213   .rela.sbss   ${RELOCATING-0} :
214     {
215       *(.rela.sbss)
216       ${RELOCATING+*(.rela.sbss.*)}
217       ${RELOCATING+*(.rela.gnu.linkonce.sb.*)}
218     }
219   .rel.sdata2  ${RELOCATING-0} : 
220     { 
221       *(.rel.sdata2)
222       ${RELOCATING+*(.rel.sdata2.*)}
223       ${RELOCATING+*(.rel.gnu.linkonce.s2.*)}
224     }
225   .rela.sdata2 ${RELOCATING-0} : 
226     {
227       *(.rela.sdata2)
228       ${RELOCATING+*(.rela.sdata2.*)}
229       ${RELOCATING+*(.rela.gnu.linkonce.s2.*)}
230     }
231   .rel.sbss2   ${RELOCATING-0} : 
232     { 
233       *(.rel.sbss2)     
234       ${RELOCATING+*(.rel.sbss2.*)}
235       ${RELOCATING+*(.rel.gnu.linkonce.sb2.*)}
236     }
237   .rela.sbss2  ${RELOCATING-0} : 
238     { 
239       *(.rela.sbss2)    
240       ${RELOCATING+*(.rela.sbss2.*)}
241       ${RELOCATING+*(.rela.gnu.linkonce.sb2.*)}
242     }
243   .rel.bss     ${RELOCATING-0} : 
244     { 
245       *(.rel.bss)
246       ${RELOCATING+*(.rel.bss.*)}
247       ${RELOCATING+*(.rel.gnu.linkonce.b.*)}
248     }
249   .rela.bss    ${RELOCATING-0} : 
250     { 
251       *(.rela.bss)
252       ${RELOCATING+*(.rela.bss.*)}
253       ${RELOCATING+*(.rela.gnu.linkonce.b.*)}
254     }
255 EOF
256 if [ -n "$COMBRELOC" ]; then
257 cat <<EOF
258   .rel.dyn       :
259     {
260 EOF
261 sed -e '/^[     ]*[{}][         ]*$/d;/:[       ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/      \1/' $COMBRELOC
262 cat <<EOF
263     }
264   .rela.dyn      :
265     {
266 EOF
267 sed -e '/^[     ]*[{}][         ]*$/d;/:[       ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/      \1/' $COMBRELOC
268 cat <<EOF
269     }
270 EOF
271 fi
272 cat <<EOF
273   .rel.plt     ${RELOCATING-0} : { *(.rel.plt)          }
274   .rela.plt    ${RELOCATING-0} : { *(.rela.plt)         }
275   ${OTHER_PLT_RELOC_SECTIONS}
276
277   .init        ${RELOCATING-0} : 
278   { 
279     ${RELOCATING+${INIT_START}}
280     KEEP (*(.init))
281     ${RELOCATING+${INIT_END}}
282   } =${NOP-0}
283
284   ${DATA_PLT-${BSS_PLT-${PLT}}}
285   .text    ${RELOCATING-0} :
286   {
287     ${RELOCATING+${TEXT_START_SYMBOLS}}
288     *(.text)
289     ${RELOCATING+*(.text.*)}
290     *(.stub)
291     /* .gnu.warning sections are handled specially by elf32.em.  */
292     *(.gnu.warning)
293     ${RELOCATING+*(.gnu.linkonce.t.*)}
294     ${RELOCATING+${OTHER_TEXT_SECTIONS}}
295   } =${NOP-0}
296   .fini    ${RELOCATING-0} :
297   {
298     ${RELOCATING+${FINI_START}}
299     KEEP (*(.fini))
300     ${RELOCATING+${FINI_END}}
301   } =${NOP-0}
302   ${RELOCATING+PROVIDE (__etext = .);}
303   ${RELOCATING+PROVIDE (_etext = .);}
304   ${RELOCATING+PROVIDE (etext = .);}
305
306   /* Adjust the address for the data segment.  We want to adjust up to
307      the same address within the page on the next page up.  */
308   ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
309   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
310
311   .data  ${RELOCATING-0} :
312   {
313     ${RELOCATING+${DATA_START_SYMBOLS}}
314     *(.data)
315     ${RELOCATING+*(.data.*)}
316     ${RELOCATING+*(.gnu.linkonce.d.*)}
317     ${CONSTRUCTING+SORT(CONSTRUCTORS)}
318   }
319   .data1 ${RELOCATING-0} : { *(.data1) }
320   .eh_frame ${RELOCATING-0} : 
321   { 
322     ${RELOCATING+PROVIDE (__eh_frame_begin = .);}
323     *(.eh_frame) 
324     LONG (0);
325     ${RELOCATING+PROVIDE (__eh_frame_end = .);}
326   } ${RELOCATING+}
327   .gcc_except_table : { *(.gcc_except_table) }
328   ${INITIAL_READONLY_SECTIONS}
329   .hash        ${RELOCATING-0} : { *(.hash)             }
330   .dynsym      ${RELOCATING-0} : { *(.dynsym)           }
331   .dynstr      ${RELOCATING-0} : { *(.dynstr)           }
332   .gnu.version ${RELOCATING-0} : { *(.gnu.version)      }
333   .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d)  }
334   .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r)  }
335   ${RODATA}
336   .rodata1 ${RELOCATING-0} : { *(.rodata1) }
337   ${CREATE_SHLIB-${SDATA2}}
338   ${CREATE_SHLIB-${SBSS2}}
339   ${RELOCATING+${OTHER_READONLY_SECTIONS}}
340   ${RELOCATING+${OTHER_READWRITE_SECTIONS}}
341   ${TEXT_DYNAMIC-${DYNAMIC}}
342   ${RELOCATING+${CTOR}}
343   ${RELOCATING+${DTOR}}
344   .jcr : { KEEP (*(.jcr)) }
345   ${DATA_PLT+${PLT}}
346   ${RELOCATING+${OTHER_GOT_SYMBOLS}}
347   .got          ${RELOCATING-0} : { *(.got.plt) *(.got) }
348   ${RELOCATING+${OTHER_GOT_SECTIONS}}
349   ${CREATE_SHLIB+${SDATA2}}
350   ${CREATE_SHLIB+${SBSS2}}
351   /* We want the small data sections together, so single-instruction offsets
352      can access them all, and initialized data all before uninitialized, so
353      we can shorten the on-disk segment size.  */
354   .sdata   ${RELOCATING-0} : 
355   {
356     ${RELOCATING+${SDATA_START_SYMBOLS}}
357     *(.sdata) 
358     ${RELOCATING+*(.sdata.*)}
359     ${RELOCATING+*(.gnu.linkonce.s.*)}
360   }
361   ${RELOCATING+${OTHER_SDATA_SECTIONS}}
362   ${RELOCATING+_edata = .;}
363   ${RELOCATING+PROVIDE (edata = .);}
364   ${RELOCATING+__bss_start = .;}
365   ${RELOCATING+${OTHER_BSS_SYMBOLS}}
366   .sbss    ${RELOCATING-0} :
367   {
368     ${RELOCATING+PROVIDE (__sbss_start = .);}
369     ${RELOCATING+PROVIDE (___sbss_start = .);}
370     *(.dynsbss)
371     *(.sbss)
372     ${RELOCATING+*(.sbss.*)}
373     ${RELOCATING+*(.gnu.linkonce.sb.*)}
374     *(.scommon)
375     ${RELOCATING+PROVIDE (__sbss_end = .);}
376     ${RELOCATING+PROVIDE (___sbss_end = .);}
377   }
378   ${BSS_PLT+${PLT}}
379   .bss     ${RELOCATING-0} :
380   {
381    *(.dynbss)
382    *(.bss)
383    ${RELOCATING+*(.bss.*)}
384    ${RELOCATING+*(.gnu.linkonce.b.*)}
385    *(COMMON)
386    /* Align here to ensure that the .bss section occupies space up to
387       _end.  Align after .bss to ensure correct alignment even if the
388       .bss section disappears because there are no input sections.  */
389    ${RELOCATING+. = ALIGN(${ALIGNMENT});}
390   }
391   ${RELOCATING+${OTHER_BSS_SECTIONS}}
392   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
393   ${RELOCATING+_end = .;}
394   ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
395   ${RELOCATING+PROVIDE (end = .);}
396
397   /* Stabs debugging sections.  */
398   .stab 0 : { *(.stab) }
399   .stabstr 0 : { *(.stabstr) }
400   .stab.excl 0 : { *(.stab.excl) }
401   .stab.exclstr 0 : { *(.stab.exclstr) }
402   .stab.index 0 : { *(.stab.index) }
403   .stab.indexstr 0 : { *(.stab.indexstr) }
404
405   .comment 0 : { *(.comment) }
406
407   /* DWARF debug sections.
408      Symbols in the DWARF debugging sections are relative to the beginning
409      of the section so we begin them at 0.  */
410
411   /* DWARF 1 */
412   .debug          0 : { *(.debug) }
413   .line           0 : { *(.line) }
414
415   /* GNU DWARF 1 extensions */
416   .debug_srcinfo  0 : { *(.debug_srcinfo) }
417   .debug_sfnames  0 : { *(.debug_sfnames) }
418
419   /* DWARF 1.1 and DWARF 2 */
420   .debug_aranges  0 : { *(.debug_aranges) }
421   .debug_pubnames 0 : { *(.debug_pubnames) }
422
423   /* DWARF 2 */
424   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
425   .debug_abbrev   0 : { *(.debug_abbrev) }
426   .debug_line     0 : { *(.debug_line) }
427   .debug_frame    0 : { *(.debug_frame) }
428   .debug_str      0 : { *(.debug_str) }
429   .debug_loc      0 : { *(.debug_loc) }
430   .debug_macinfo  0 : { *(.debug_macinfo) }
431
432   /* SGI/MIPS DWARF 2 extensions */
433   .debug_weaknames 0 : { *(.debug_weaknames) }
434   .debug_funcnames 0 : { *(.debug_funcnames) }
435   .debug_typenames 0 : { *(.debug_typenames) }
436   .debug_varnames  0 : { *(.debug_varnames) }
437
438   ${RELOCATING+${OTHER_RELOCATING_SECTIONS}}
439
440   /* These must appear regardless of ${RELOCATING}.  */
441   ${OTHER_SECTIONS}
442 }
443 EOF