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