* scripttempl/elf.sc: Add support for .sbss2 and .sdata2 sections.
[binutils-gdb.git] / ld / scripttempl / elf.sc
1 #
2 # Unusual variables checked by this code:
3 # NOP - two 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 and .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 test -z "$ENTRY" && ENTRY=_start
41 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
42 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
43 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
44 test -z "${ELFSIZE}" && ELFSIZE=32
45 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
46 test "$LD_FLAG" = "N" && DATA_ADDR=.
47 INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
48 PLT=".plt ${RELOCATING-0} : { *(.plt) }"
49 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
50 RODATA=".rodata ${RELOCATING-0} : { *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r*)} }"
51 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2) }"
52 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2) }"
53 CTOR=".ctors ${CONSTRUCTING-0} :
54 {
55 ${CONSTRUCTING+${CTOR_START}}
56 /* gcc uses crtbegin.o to find the start of
57 the constructors, so we make sure it is
58 first. Because this is a wildcard, it
59 doesn't matter if the user does not
60 actually link against crtbegin.o; the
61 linker won't look for a file to match a
62 wildcard. The wildcard also means that it
63 doesn't matter which directory crtbegin.o
64 is in. */
65
66 KEEP (*crtbegin.o(.ctors))
67
68 /* We don't want to include the .ctor section from
69 from the crtend.o file until after the sorted ctors.
70 The .ctor section from the crtend file contains the
71 end of ctors marker and it must be last */
72
73 KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .ctors))
74 KEEP (*(SORT(.ctors.*)))
75 KEEP (*(.ctors))
76 ${CONSTRUCTING+${CTOR_END}}
77 }"
78
79 DTOR=" .dtors ${CONSTRUCTING-0} :
80 {
81 ${CONSTRUCTING+${DTOR_START}}
82 KEEP (*crtbegin.o(.dtors))
83 KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .dtors))
84 KEEP (*(SORT(.dtors.*)))
85 KEEP (*(.dtors))
86 ${CONSTRUCTING+${DTOR_END}}
87 }"
88
89 # if this is for an embedded system, don't add SIZEOF_HEADERS.
90 if [ -z "$EMBEDDED" ]; then
91 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
92 else
93 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
94 fi
95
96 cat <<EOF
97 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
98 "${LITTLE_OUTPUT_FORMAT}")
99 OUTPUT_ARCH(${OUTPUT_ARCH})
100 ENTRY(${ENTRY})
101
102 ${RELOCATING+${LIB_SEARCH_DIRS}}
103 ${RELOCATING+/* Do we need any of these for elf?
104 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
105 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
106 ${RELOCATING+${INPUT_FILES}}
107 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
108 if gld -r is used and the intermediate file has sections starting
109 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
110 bug. But for now assigning the zero vmas works. */}
111
112 SECTIONS
113 {
114 /* Read-only sections, merged into text segment: */
115 ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
116 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
117 ${CREATE_SHLIB-${INTERP}}
118 ${INITIAL_READONLY_SECTIONS}
119 ${TEXT_DYNAMIC+${DYNAMIC}}
120 .hash ${RELOCATING-0} : { *(.hash) }
121 .dynsym ${RELOCATING-0} : { *(.dynsym) }
122 .dynstr ${RELOCATING-0} : { *(.dynstr) }
123 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
124 .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) }
125 .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) }
126
127 .rel.text ${RELOCATING-0} :
128 {
129 *(.rel.text)
130 ${RELOCATING+*(.rel.text.*)}
131 ${RELOCATING+*(.rel.gnu.linkonce.t*)}
132 }
133 .rela.text ${RELOCATING-0} :
134 {
135 *(.rela.text)
136 ${RELOCATING+*(.rela.text.*)}
137 ${RELOCATING+*(.rela.gnu.linkonce.t*)}
138 }
139 .rel.init ${RELOCATING-0} : { *(.rel.init) }
140 .rela.init ${RELOCATING-0} : { *(.rela.init) }
141 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
142 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
143 .rel.rodata ${RELOCATING-0} :
144 {
145 *(.rel.rodata)
146 ${RELOCATING+*(.rel.rodata.*)}
147 ${RELOCATING+*(.rel.gnu.linkonce.r*)}
148 }
149 .rela.rodata ${RELOCATING-0} :
150 {
151 *(.rela.rodata)
152 ${RELOCATING+*(.rela.rodata.*)}
153 ${RELOCATING+*(.rela.gnu.linkonce.r*)}
154 }
155 ${OTHER_READONLY_RELOC_SECTIONS}
156 .rel.data ${RELOCATING-0} :
157 {
158 *(.rel.data)
159 ${RELOCATING+*(.rel.data.*)}
160 ${RELOCATING+*(.rel.gnu.linkonce.d*)}
161 }
162 .rela.data ${RELOCATING-0} :
163 {
164 *(.rela.data)
165 ${RELOCATING+*(.rela.data.*)}
166 ${RELOCATING+*(.rela.gnu.linkonce.d*)}
167 }
168 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
169 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
170 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
171 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
172 .rel.got ${RELOCATING-0} : { *(.rel.got) }
173 .rela.got ${RELOCATING-0} : { *(.rela.got) }
174 ${OTHER_GOT_RELOC_SECTIONS}
175 .rel.sdata ${RELOCATING-0} :
176 {
177 *(.rel.sdata)
178 ${RELOCATING+*(.rel.sdata.*)}
179 ${RELOCATING+*(.rel.gnu.linkonce.s*)}
180 }
181 .rela.sdata ${RELOCATING-0} :
182 {
183 *(.rela.sdata)
184 ${RELOCATING+*(.rela.sdata.*)}
185 ${RELOCATING+*(.rela.gnu.linkonce.s*)}
186 }
187 .rel.sbss ${RELOCATING-0} : { *(.rel.sbss) }
188 .rela.sbss ${RELOCATING-0} : { *(.rela.sbss) }
189 .rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2) }
190 .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2) }
191 .rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2) }
192 .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2) }
193 .rel.bss ${RELOCATING-0} : { *(.rel.bss) }
194 .rela.bss ${RELOCATING-0} : { *(.rela.bss) }
195 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
196 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
197 ${OTHER_PLT_RELOC_SECTIONS}
198
199 ${DATA_PLT-${BSS_PLT-${PLT}}}
200 /* .text should be before .init and so on, so that -Ttext=0x1234
201 will work. */
202 .text ${RELOCATING-0} :
203 {
204 ${RELOCATING+${TEXT_START_SYMBOLS}}
205 *(.text)
206 ${RELOCATING+*(.text.*)}
207 *(.stub)
208 /* .gnu.warning sections are handled specially by elf32.em. */
209 *(.gnu.warning)
210 ${RELOCATING+*(.gnu.linkonce.t*)}
211 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
212 } =${NOP-0}
213 .init ${RELOCATING-0} :
214 {
215 ${INIT_START}
216 KEEP (*(.init))
217 ${INIT_END}
218 } =${NOP-0}
219 .fini ${RELOCATING-0} :
220 {
221 ${FINI_START}
222 KEEP (*(.fini))
223 ${FINI_END}
224 } =${NOP-0}
225 ${RELOCATING+PROVIDE (__etext = .);}
226 ${RELOCATING+PROVIDE (_etext = .);}
227 ${RELOCATING+PROVIDE (etext = .);}
228 ${WRITABLE_RODATA-${RODATA}}
229 .rodata1 ${RELOCATING-0} : { *(.rodata1) }
230 ${CREATE_SHLIB-${SDATA2}}
231 ${CREATE_SHLIB-${SBSS2}}
232 ${RELOCATING+${OTHER_READONLY_SECTIONS}}
233
234 /* Adjust the address for the data segment. We want to adjust up to
235 the same address within the page on the next page up. */
236 ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
237 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
238
239 .data ${RELOCATING-0} :
240 {
241 ${RELOCATING+${DATA_START_SYMBOLS}}
242 *(.data)
243 ${RELOCATING+*(.data.*)}
244 ${RELOCATING+*(.gnu.linkonce.d*)}
245 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
246 }
247 .data1 ${RELOCATING-0} : { *(.data1) }
248 .eh_frame : { *(.eh_frame) }
249 .gcc_except_table : { *(.gcc_except_table) }
250 ${WRITABLE_RODATA+${RODATA}}
251 ${RELOCATING+${OTHER_READWRITE_SECTIONS}}
252 ${RELOCATING+${CTOR}}
253 ${RELOCATING+${DTOR}}
254 ${DATA_PLT+${PLT}}
255 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
256 .got ${RELOCATING-0} : { *(.got.plt) *(.got) }
257 ${CREATE_SHLIB+${SDATA2}}
258 ${CREATE_SHLIB+${SBSS2}}
259 ${TEXT_DYNAMIC-${DYNAMIC}}
260 /* We want the small data sections together, so single-instruction offsets
261 can access them all, and initialized data all before uninitialized, so
262 we can shorten the on-disk segment size. */
263 .sdata ${RELOCATING-0} :
264 {
265 ${RELOCATING+${SDATA_START_SYMBOLS}}
266 *(.sdata)
267 ${RELOCATING+*(.sdata.*)}
268 ${RELOCATING+*(.gnu.linkonce.s.*)}
269 }
270 ${RELOCATING+${OTHER_GOT_SECTIONS}}
271 ${RELOCATING+_edata = .;}
272 ${RELOCATING+PROVIDE (edata = .);}
273 ${RELOCATING+__bss_start = .;}
274 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
275 .sbss ${RELOCATING-0} :
276 {
277 ${RELOCATING+PROVIDE (__sbss_start = .);}
278 ${RELOCATING+PROVIDE (___sbss_start = .);}
279 *(.dynsbss)
280 *(.sbss)
281 ${RELOCATING+*(.sbss.*)}
282 *(.scommon)
283 ${RELOCATING+PROVIDE (__sbss_end = .);}
284 ${RELOCATING+PROVIDE (___sbss_end = .);}
285 }
286 ${BSS_PLT+${PLT}}
287 .bss ${RELOCATING-0} :
288 {
289 *(.dynbss)
290 *(.bss)
291 ${RELOCATING+*(.bss.*)}
292 *(COMMON)
293 /* Align here to ensure that the .bss section occupies space up to
294 _end. Align after .bss to ensure correct alignment even if the
295 .bss section disappears because there are no input sections. */
296 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
297 }
298 ${RELOCATING+${OTHER_BSS_SECTIONS}}
299 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
300 ${RELOCATING+_end = .;}
301 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
302 ${RELOCATING+PROVIDE (end = .);}
303
304 /* Stabs debugging sections. */
305 .stab 0 : { *(.stab) }
306 .stabstr 0 : { *(.stabstr) }
307 .stab.excl 0 : { *(.stab.excl) }
308 .stab.exclstr 0 : { *(.stab.exclstr) }
309 .stab.index 0 : { *(.stab.index) }
310 .stab.indexstr 0 : { *(.stab.indexstr) }
311
312 .comment 0 : { *(.comment) }
313
314 /* DWARF debug sections.
315 Symbols in the DWARF debugging sections are relative to the beginning
316 of the section so we begin them at 0. */
317
318 /* DWARF 1 */
319 .debug 0 : { *(.debug) }
320 .line 0 : { *(.line) }
321
322 /* GNU DWARF 1 extensions */
323 .debug_srcinfo 0 : { *(.debug_srcinfo) }
324 .debug_sfnames 0 : { *(.debug_sfnames) }
325
326 /* DWARF 1.1 and DWARF 2 */
327 .debug_aranges 0 : { *(.debug_aranges) }
328 .debug_pubnames 0 : { *(.debug_pubnames) }
329
330 /* DWARF 2 */
331 .debug_info 0 : { *(.debug_info) }
332 .debug_abbrev 0 : { *(.debug_abbrev) }
333 .debug_line 0 : { *(.debug_line) }
334 .debug_frame 0 : { *(.debug_frame) }
335 .debug_str 0 : { *(.debug_str) }
336 .debug_loc 0 : { *(.debug_loc) }
337 .debug_macinfo 0 : { *(.debug_macinfo) }
338
339 /* SGI/MIPS DWARF 2 extensions */
340 .debug_weaknames 0 : { *(.debug_weaknames) }
341 .debug_funcnames 0 : { *(.debug_funcnames) }
342 .debug_typenames 0 : { *(.debug_typenames) }
343 .debug_varnames 0 : { *(.debug_varnames) }
344
345 ${RELOCATING+${OTHER_RELOCATING_SECTIONS}}
346
347 /* These must appear regardless of ${RELOCATING}. */
348 ${OTHER_SECTIONS}
349 }
350 EOF