* ldlang.c (exp_init_os): Handle etree_provide.
[platform/upstream/binutils.git] / ld / scripttempl / elf32sh-symbian.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 text 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 #       STACK_ADDR - start of a .stack section.
37 #       OTHER_END_SYMBOLS - symbols to place right at the end of the script.
38 #
39 # When adding sections, do note that the names of some sections are used
40 # when specifying the start address of the next.
41 #
42
43 #  Many sections come in three flavours.  There is the 'real' section,
44 #  like ".data".  Then there are the per-procedure or per-variable
45 #  sections, generated by -ffunction-sections and -fdata-sections in GCC,
46 #  and useful for --gc-sections, which for a variable "foo" might be
47 #  ".data.foo".  Then there are the linkonce sections, for which the linker
48 #  eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
49 #  The exact correspondences are:
50 #
51 #  Section      Linkonce section
52 #  .text        .gnu.linkonce.t.foo
53 #  .rodata      .gnu.linkonce.r.foo
54 #  .data        .gnu.linkonce.d.foo
55 #  .bss         .gnu.linkonce.b.foo
56 #  .sdata       .gnu.linkonce.s.foo
57 #  .sbss        .gnu.linkonce.sb.foo
58 #  .sdata2      .gnu.linkonce.s2.foo
59 #  .sbss2       .gnu.linkonce.sb2.foo
60 #  .debug_info  .gnu.linkonce.wi.foo
61 #  .tdata       .gnu.linkonce.td.foo
62 #  .tbss        .gnu.linkonce.tb.foo
63 #
64 #  Each of these can also have corresponding .rel.* and .rela.* sections.
65
66 test -z "$ENTRY" && ENTRY=_start
67 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
68 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
69 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
70 test -z "${ELFSIZE}" && ELFSIZE=32
71 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
72 test "$LD_FLAG" = "N" && DATA_ADDR=.
73 test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
74 test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
75 DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
76 DATA_SEGMENT_END=""
77 if test -n "${COMMONPAGESIZE}"; then
78   DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
79   DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
80 fi
81  INTERP=".interp    ALIGN(4) : { *(.interp) }"
82     PLT=".plt            : { *(.plt) } :dynamic :dyn"
83 DYNAMIC=".dynamic        : { *(.dynamic) } :dynamic :dyn"
84  RODATA=".rodata    ALIGN(4) : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
85 STACKNOTE="/DISCARD/ : { *(.note.GNU-stack)  *(.directive) }"
86 test -z "$GOT" && GOT=".got          ${RELOCATING-0} : { *(.got.plt) *(.got) } :dynamic :dyn"
87 CTOR=".ctors     ALIGN(4) : 
88   {
89     ${CONSTRUCTING+${CTOR_START}}
90     /* gcc uses crtbegin.o to find the start of
91        the constructors, so we make sure it is
92        first.  Because this is a wildcard, it
93        doesn't matter if the user does not
94        actually link against crtbegin.o; the
95        linker won't look for a file to match a
96        wildcard.  The wildcard also means that it
97        doesn't matter which directory crtbegin.o
98        is in.  */
99
100     KEEP (*crtbegin*.o(.ctors))
101
102     /* We don't want to include the .ctor section from
103        from the crtend.o file until after the sorted ctors.
104        The .ctor section from the crtend file contains the
105        end of ctors marker and it must be last */
106
107     KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors))
108     KEEP (*(SORT(.ctors.*)))
109     KEEP (*(.ctors))
110     ${CONSTRUCTING+${CTOR_END}}
111   } :text"
112 DTOR=".dtors        ALIGN(4) :
113   {
114     ${CONSTRUCTING+${DTOR_START}}
115     KEEP (*crtbegin*.o(.dtors))
116     KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors))
117     KEEP (*(SORT(.dtors.*)))
118     KEEP (*(.dtors))
119     ${CONSTRUCTING+${DTOR_END}}
120   } :text"
121 STACK="  .stack        ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
122   {
123     ${RELOCATING+_stack = .;}
124     *(.stack)
125   } :data"
126
127 # if this is for an embedded system, don't add SIZEOF_HEADERS.
128 if [ -z "$EMBEDDED" ]; then
129    test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
130 else
131    test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
132 fi
133
134 cat <<EOF
135 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
136               "${LITTLE_OUTPUT_FORMAT}")
137 OUTPUT_ARCH(${OUTPUT_ARCH})
138 ENTRY(${ENTRY})
139
140 ${RELOCATING+${LIB_SEARCH_DIRS}}
141 ${RELOCATING+/* Do we need any of these for elf?
142    __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}}  */}
143 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
144 ${RELOCATING+${INPUT_FILES}}
145 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
146   if gld -r is used and the intermediate file has sections starting
147   at non-zero addresses.  Could be a Solaris ld bug, could be a GNU ld
148   bug.  But for now assigning the zero vmas works.  */}
149
150 PHDRS
151 {
152   headers PT_PHDR PHDRS ;
153   text    PT_LOAD ;
154   data    PT_LOAD ;
155   dyn     PT_LOAD FLAGS (0) ;
156   dynamic PT_DYNAMIC ;
157 }
158
159 SECTIONS
160 {
161   /* Read-only sections, merged into text segment: */
162   ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}}
163   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0};}}
164   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0};}}
165   ${CREATE_SHLIB-${INTERP}}
166   
167   ${INITIAL_READONLY_SECTIONS}
168
169   .init ALIGN(4) : 
170   { 
171     ${RELOCATING+${INIT_START}}
172     KEEP (*(.init))
173     ${RELOCATING+${INIT_END}}
174   } :text =${NOP-0}
175
176   .text ALIGN(4) :
177   {
178     ${RELOCATING+${TEXT_START_SYMBOLS}}
179     *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
180     /* .gnu.warning sections are handled specially by elf32.em.  */
181     *(.gnu.warning)
182     ${RELOCATING+${OTHER_TEXT_SECTIONS}}
183   } =${NOP-0}
184   
185   ${RELOCATING+${CTOR}}
186   ${RELOCATING+${DTOR}}
187   
188   .fini ALIGN(4) :
189   {
190     ${RELOCATING+${FINI_START}}
191     KEEP (*(.fini))
192     ${RELOCATING+${FINI_END}}
193   } =${NOP-0}
194   
195   ${RELOCATING+PROVIDE (__etext = .);}
196   ${RELOCATING+PROVIDE (_etext = .);}
197   ${RELOCATING+PROVIDE (etext = .);}
198   
199   ${WRITABLE_RODATA-${RODATA}}
200   .rodata1 ALIGN(4) : { *(.rodata1) }
201   
202   ExportTable  ALIGN(4) : { KEEP (*(ExportTable)) }
203   .eh_frame_hdr ALIGN(4) : { *(.eh_frame_hdr) } :text
204
205   /* Adjust the address for the data segment.  We want to adjust up to
206      the same address within the page on the next page up.  */
207   . = ALIGN(128) + (. & (128 - 1));
208   /* Ensure the __preinit_array_start label is properly aligned.  We
209      could instead move the label definition inside the section, but
210      the linker would then create the section even if it turns out to
211      be empty, which isn't pretty.  */
212   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
213   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
214   .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
215   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
216
217   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
218   .init_array   ${RELOCATING-0} : { *(.init_array) }
219   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
220
221   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
222   .fini_array   ${RELOCATING-0} : { *(.fini_array) }
223   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
224
225   ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
226   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
227   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
228
229   .data  ALIGN(4) :
230   {
231     ${RELOCATING+${DATA_START_SYMBOLS}}
232     *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
233     ${CONSTRUCTING+SORT(CONSTRUCTORS)}
234   } :data
235   
236   .data1            ALIGN(4) : { *(.data1) } :data
237   .tdata            ALIGN(4) : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) } :data
238   .tbss             ALIGN(4) : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} } :data
239   .eh_frame         ALIGN(4) : { KEEP (*(.eh_frame)) } :data
240   .gcc_except_table ALIGN(4) : { *(.gcc_except_table) } :data
241   ${WRITABLE_RODATA+${RODATA}}
242   ${OTHER_READWRITE_SECTIONS}
243   ${SDATA}
244   ${OTHER_SDATA_SECTIONS}
245   ${RELOCATING+_edata = .;}
246   ${RELOCATING+PROVIDE (edata = .);}
247   ${RELOCATING+__bss_start = .;}
248   ${RELOCATING+${OTHER_BSS_SYMBOLS}}
249   ${BSS_PLT+${PLT}}
250   .bss  ALIGN(4) :
251   {
252    *(.dynbss)
253    *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
254    *(COMMON)
255    /* Align here to ensure that the .bss section occupies space up to
256       _end.  Align after .bss to ensure correct alignment even if the
257       .bss section disappears because there are no input sections.  */
258    ${RELOCATING+. = ALIGN(${ALIGNMENT});}
259   } :data
260   ${OTHER_BSS_SECTIONS}
261   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
262   ${RELOCATING+_end = .;}
263   ${RELOCATING+${OTHER_END_SYMBOLS}}
264   ${RELOCATING+PROVIDE (end = .);}
265   ${RELOCATING+${DATA_SEGMENT_END}}
266
267   ${TEXT_DYNAMIC-${DYNAMIC}}
268   ${TEXT_DYNAMIC+${DYNAMIC}}
269   .hash         ${RELOCATING-0} : { *(.hash) } :dynamic :dyn
270   .dynsym       ${RELOCATING-0} : { *(.dynsym) } :dynamic :dyn
271   .dynstr       ${RELOCATING-0} : { *(.dynstr) } :dynamic :dyn
272   ${DATA_PLT-${BSS_PLT-${PLT}}}
273   .got.plt        : { *(.got.plt) } :dynamic :dyn
274   .gnu.version  ${RELOCATING-0} : { *(.gnu.version) }
275   .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
276   .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
277 EOF
278 if [ "x$COMBRELOC" = x ]; then
279   COMBRELOCCAT=cat
280 else
281   COMBRELOCCAT="cat > $COMBRELOC"
282 fi
283 eval $COMBRELOCCAT <<EOF
284   .rel.init     ${RELOCATING-0} : { *(.rel.init) }
285   .rela.init    ${RELOCATING-0} : { *(.rela.init) }
286   .rel.text     ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
287   .rela.text    ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
288   .rel.fini     ${RELOCATING-0} : { *(.rel.fini) }
289   .rela.fini    ${RELOCATING-0} : { *(.rela.fini) }
290   .rel.rodata   ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
291   .rela.rodata  ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
292   ${OTHER_READONLY_RELOC_SECTIONS}
293   .rel.data     ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
294   .rela.data    ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
295   .rel.tdata    ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
296   .rela.tdata   ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
297   .rel.tbss     ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
298   .rela.tbss    ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
299   .rel.ctors    ${RELOCATING-0} : { *(.rel.ctors) }
300   .rela.ctors   ${RELOCATING-0} : { *(.rela.ctors) }
301   .rel.dtors    ${RELOCATING-0} : { *(.rel.dtors) }
302   .rela.dtors   ${RELOCATING-0} : { *(.rela.dtors) }
303   .rel.got      ${RELOCATING-0} : { *(.rel.got) }
304   .rela.got     ${RELOCATING-0} : { *(.rela.got) }
305   ${OTHER_GOT_RELOC_SECTIONS}
306   .rel.bss      ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
307   .rela.bss     ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
308 EOF
309 if [ -n "$COMBRELOC" ]; then
310 cat <<EOF
311   .rel.dyn      ${RELOCATING-0} :
312     {
313 EOF
314 sed -e '/^[     ]*[{}][         ]*$/d;/:[       ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/      \1/' $COMBRELOC
315 cat <<EOF
316     }
317   .rela.dyn     ${RELOCATING-0} :
318     {
319 EOF
320 sed -e '/^[     ]*[{}][         ]*$/d;/:[       ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/      \1/' $COMBRELOC
321 cat <<EOF
322     }
323 EOF
324 fi
325 cat <<EOF
326   .rel.plt      ${RELOCATING-0} : { *(.rel.plt) }
327   .rela.plt     ${RELOCATING-0} : { *(.rela.plt) }
328   ${OTHER_PLT_RELOC_SECTIONS}
329
330
331   /* Stabs debugging sections.  */
332   .stab          0 : { *(.stab) }
333   .stabstr       0 : { *(.stabstr) }
334   .stab.excl     0 : { *(.stab.excl) }
335   .stab.exclstr  0 : { *(.stab.exclstr) }
336   .stab.index    0 : { *(.stab.index) }
337   .stab.indexstr 0 : { *(.stab.indexstr) }
338
339   .comment       0 : { *(.comment) }
340
341   /* DWARF debug sections.
342      Symbols in the DWARF debugging sections are relative to the beginning
343      of the section so we begin them at 0.  */
344
345   /* DWARF 1 */
346   .debug          0 : { *(.debug) }
347   .line           0 : { *(.line) }
348
349   /* GNU DWARF 1 extensions */
350   .debug_srcinfo  0 : { *(.debug_srcinfo) }
351   .debug_sfnames  0 : { *(.debug_sfnames) }
352
353   /* DWARF 1.1 and DWARF 2 */
354   .debug_aranges  0 : { *(.debug_aranges) }
355   .debug_pubnames 0 : { *(.debug_pubnames) }
356
357   /* DWARF 2 */
358   .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
359   .debug_abbrev   0 : { *(.debug_abbrev) }
360   .debug_line     0 : { *(.debug_line) }
361   .debug_frame    0 : { *(.debug_frame) }
362   .debug_str      0 : { *(.debug_str) }
363   .debug_loc      0 : { *(.debug_loc) }
364   .debug_macinfo  0 : { *(.debug_macinfo) }
365
366   /* SGI/MIPS DWARF 2 extensions */
367   .debug_weaknames 0 : { *(.debug_weaknames) }
368   .debug_funcnames 0 : { *(.debug_funcnames) }
369   .debug_typenames 0 : { *(.debug_typenames) }
370   .debug_varnames  0 : { *(.debug_varnames) }
371
372   ${STACK_ADDR+${STACK}}
373   ${OTHER_SECTIONS}
374   ${RELOCATING+${OTHER_END_SYMBOLS}}
375   ${RELOCATING+${STACKNOTE}}
376 }
377 EOF