]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/scripttempl/elf64bpf.sc
2.41 Release sources
[thirdparty/binutils-gdb.git] / ld / scripttempl / elf64bpf.sc
1 # Copyright (C) 2014-2023 Free Software Foundation, Inc.
2 #
3 # Copying and distribution of this file, with or without modification,
4 # are permitted in any medium without royalty provided the copyright
5 # notice and this notice are preserved.
6 #
7 # Unusual variables checked by this code:
8 # NOP - four byte opcode for no-op (defaults to none)
9 # NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not
10 # empty.
11 # SMALL_DATA_CTOR - .ctors contains small data.
12 # SMALL_DATA_DTOR - .dtors contains small data.
13 # DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
14 # INITIAL_READONLY_SECTIONS - at start of text segment
15 # OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
16 # (e.g., .PARISC.milli)
17 # OTHER_TEXT_SECTIONS - these get put in .text when relocating
18 # INITIAL_READWRITE_SECTIONS - at start of data segment (after relro)
19 # OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
20 # (e.g., .PARISC.global)
21 # OTHER_RELRO_SECTIONS - other than .data.rel.ro ...
22 # (e.g. PPC32 .fixup, .got[12])
23 # OTHER_RELRO_SECTIONS_2 - as above, but after .dynamic in text segment
24 # OTHER_BSS_SECTIONS - other than .bss .sbss ...
25 # ATTRS_SECTIONS - at the end
26 # OTHER_SECTIONS - at the end
27 # EXECUTABLE_SYMBOLS - symbols that must be defined for an
28 # executable (e.g., _DYNAMIC_LINK)
29 # TEXT_START_ADDR - the first byte of the text segment, after any
30 # headers.
31 # TEXT_BASE_ADDRESS - the first byte of the text segment.
32 # TEXT_START_SYMBOLS - symbols that appear at the start of the
33 # .text section.
34 # DATA_START_SYMBOLS - symbols that appear at the start of the
35 # .data section.
36 # DATA_END_SYMBOLS - symbols that appear at the end of the
37 # writeable data sections.
38 # OTHER_GOT_SYMBOLS - symbols defined just before .got.
39 # OTHER_GOT_SECTIONS - sections just after .got.
40 # OTHER_PLT_SECTIONS - sections just after .plt.
41 # OTHER_SDATA_SECTIONS - sections just after .sdata.
42 # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
43 # .bss section besides __bss_start.
44 # PLT_NEXT_DATA - .plt next to data segment when .plt is in text segment.
45 # DATA_PLT - .plt should be in data segment, not text segment.
46 # PLT_BEFORE_GOT - .plt just before .got when .plt is in data segement.
47 # BSS_PLT - .plt should be in bss segment
48 # NO_REL_RELOCS - Don't include .rel.* sections in script
49 # NO_RELA_RELOCS - Don't include .rela.* sections in script
50 # NON_ALLOC_DYN - Place dynamic sections after data segment.
51 # TEXT_DYNAMIC - .dynamic in text segment, not data segment.
52 # EMBEDDED - whether this is for an embedded system.
53 # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
54 # start address of shared library.
55 # INPUT_FILES - INPUT command of files to always include
56 # WRITABLE_RODATA - if set, the .rodata section should be writable
57 # INIT_START, INIT_END - statements just before and just after
58 # combination of .init sections.
59 # FINI_START, FINI_END - statements just before and just after
60 # combination of .fini sections.
61 # STACK_ADDR - start of a .stack section.
62 # OTHER_SYMBOLS - symbols to place right at the end of the script.
63 # ETEXT_NAME - name of a symbol for the end of the text section,
64 # normally etext.
65 # SEPARATE_CODE - if set, .text and similar sections containing
66 # actual machine instructions must be in wholly disjoint
67 # pages from any other data, including headers
68 # SEPARATE_GOTPLT - if set, .got.plt should be separate output section,
69 # so that .got can be in the RELRO area. It should be set to
70 # the number of bytes in the beginning of .got.plt which can be
71 # in the RELRO area as well.
72 # USER_LABEL_PREFIX - prefix to add to user-visible symbols.
73 # RODATA_NAME, SDATA_NAME, SBSS_NAME, BSS_NAME - base parts of names
74 # for standard sections, without initial "." or suffixes.
75 #
76 # When adding sections, do note that the names of some sections are used
77 # when specifying the start address of the next.
78 #
79
80 # Many sections come in three flavours. There is the 'real' section,
81 # like ".data". Then there are the per-procedure or per-variable
82 # sections, generated by -ffunction-sections and -fdata-sections in GCC,
83 # and useful for --gc-sections, which for a variable "foo" might be
84 # ".data.foo". Then there are the linkonce sections, for which the linker
85 # eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
86 # The exact correspondences are:
87 #
88 # Section Linkonce section
89 # .text .gnu.linkonce.t.foo
90 # .rodata .gnu.linkonce.r.foo
91 # .data .gnu.linkonce.d.foo
92 # .bss .gnu.linkonce.b.foo
93 # .sdata .gnu.linkonce.s.foo
94 # .sbss .gnu.linkonce.sb.foo
95 # .sdata2 .gnu.linkonce.s2.foo
96 # .sbss2 .gnu.linkonce.sb2.foo
97 # .debug_info .gnu.linkonce.wi.foo
98 # .tdata .gnu.linkonce.td.foo
99 # .tbss .gnu.linkonce.tb.foo
100 # .lrodata .gnu.linkonce.lr.foo
101 # .ldata .gnu.linkonce.l.foo
102 # .lbss .gnu.linkonce.lb.foo
103 #
104 # Each of these can also have corresponding .rel.* and .rela.* sections.
105
106 if test -n "$NOP"; then
107 FILL="=$NOP"
108 else
109 FILL=
110 fi
111
112 test -n "$CREATE_SHLIB$CREATE_PIE" && CREATE_PIC=" "
113 test -z "$RODATA_NAME" && RODATA_NAME=rodata
114 test -z "$SDATA_NAME" && SDATA_NAME=sdata
115 test -z "$SBSS_NAME" && SBSS_NAME=sbss
116 test -z "$BSS_NAME" && BSS_NAME=bss
117 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
118 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
119 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
120 test -z "${ELFSIZE}" && ELFSIZE=32
121 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
122 test "$LD_FLAG" = "N" && DATA_ADDR=.
123 test -z "${ETEXT_NAME}" && ETEXT_NAME=${USER_LABEL_PREFIX}etext
124 test -n "$RELRO_NOW" && unset SEPARATE_GOTPLT
125 test -z "$ATTRS_SECTIONS" && ATTRS_SECTIONS=".gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }"
126 if test -z "$DATA_SEGMENT_ALIGN"; then
127 test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
128 test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
129 DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
130 DATA_SEGMENT_RELRO_END=""
131 DATA_SEGMENT_END=""
132 if test -n "${COMMONPAGESIZE}"; then
133 if test "${SEGMENT_SIZE}" != "${MAXPAGESIZE}"; then
134 DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
135 else
136 DATA_SEGMENT_ALIGN="DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
137 fi
138 DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
139 DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);"
140 fi
141 fi
142 if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}"; then
143 INITIAL_READONLY_SECTIONS=".interp ${RELOCATING-0} : { *(.interp) }"
144 fi
145 if test -z "$PLT"; then
146 IPLT=".iplt ${RELOCATING-0} : { *(.iplt) }"
147 PLT=".plt ${RELOCATING-0} : { *(.plt)${RELOCATING+${IREL_IN_PLT+ *(.iplt)}} }
148 ${IREL_IN_PLT-$IPLT}"
149 fi
150 test -n "${DATA_PLT-${BSS_PLT-text}}" && TEXT_PLT=
151 if test -z "$GOT"; then
152 if test -z "$SEPARATE_GOTPLT"; then
153 GOT=".got ${RELOCATING-0} : {${RELOCATING+ *(.got.plt) *(.igot.plt)} *(.got)${RELOCATING+ *(.igot)} }"
154 else
155 GOT=".got ${RELOCATING-0} : { *(.got)${RELOCATING+ *(.igot)} }"
156 GOTPLT=".got.plt ${RELOCATING-0} : { *(.got.plt)${RELOCATING+ *(.igot.plt)} }"
157 fi
158 fi
159 REL_IFUNC=".rel.ifunc ${RELOCATING-0} : { *(.rel.ifunc) }"
160 RELA_IFUNC=".rela.ifunc ${RELOCATING-0} : { *(.rela.ifunc) }"
161 REL_IPLT=".rel.iplt ${RELOCATING-0} :
162 {
163 ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_start = .);}}
164 *(.rel.iplt)
165 ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_end = .);}}
166 }"
167 RELA_IPLT=".rela.iplt ${RELOCATING-0} :
168 {
169 ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_start = .);}}
170 *(.rela.iplt)
171 ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_end = .);}}
172 }"
173 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
174 RODATA=".${RODATA_NAME} ${RELOCATING-0} : { *(.${RODATA_NAME}${RELOCATING+ .${RODATA_NAME}.* .gnu.linkonce.r.*}) }"
175 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
176 DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
177 if test -z "${NO_SMALL_DATA}"; then
178 SBSS=".${SBSS_NAME} ${RELOCATING-0} :
179 {
180 ${RELOCATING+${SBSS_START_SYMBOLS}}
181 ${CREATE_SHLIB+*(.${SBSS_NAME}2 .${SBSS_NAME}2.* .gnu.linkonce.sb2.*)}
182 ${RELOCATING+*(.dyn${SBSS_NAME})}
183 *(.${SBSS_NAME}${RELOCATING+ .${SBSS_NAME}.* .gnu.linkonce.sb.*})
184 ${RELOCATING+*(.scommon)}
185 ${RELOCATING+${SBSS_END_SYMBOLS}}
186 }"
187 SBSS2=".${SBSS_NAME}2 ${RELOCATING-0} : { *(.${SBSS_NAME}2${RELOCATING+ .${SBSS_NAME}2.* .gnu.linkonce.sb2.*}) }"
188 SDATA="/* We want the small data sections together, so single-instruction offsets
189 can access them all, and initialized data all before uninitialized, so
190 we can shorten the on-disk segment size. */
191 .${SDATA_NAME} ${RELOCATING-0} :
192 {
193 ${RELOCATING+${SDATA_START_SYMBOLS}}
194 ${CREATE_SHLIB+*(.${SDATA_NAME}2 .${SDATA_NAME}2.* .gnu.linkonce.s2.*)}
195 *(.${SDATA_NAME}${RELOCATING+ .${SDATA_NAME}.* .gnu.linkonce.s.*})
196 }"
197 SDATA2=".${SDATA_NAME}2 ${RELOCATING-0} :
198 {
199 ${RELOCATING+${SDATA2_START_SYMBOLS}}
200 *(.${SDATA_NAME}2${RELOCATING+ .${SDATA_NAME}2.* .gnu.linkonce.s2.*})
201 }"
202 REL_SDATA=".rel.${SDATA_NAME} ${RELOCATING-0} : { *(.rel.${SDATA_NAME}${RELOCATING+ .rel.${SDATA_NAME}.* .rel.gnu.linkonce.s.*}) }
203 .rela.${SDATA_NAME} ${RELOCATING-0} : { *(.rela.${SDATA_NAME}${RELOCATING+ .rela.${SDATA_NAME}.* .rela.gnu.linkonce.s.*}) }"
204 REL_SBSS=".rel.${SBSS_NAME} ${RELOCATING-0} : { *(.rel.${SBSS_NAME}${RELOCATING+ .rel.${SBSS_NAME}.* .rel.gnu.linkonce.sb.*}) }
205 .rela.${SBSS_NAME} ${RELOCATING-0} : { *(.rela.${SBSS_NAME}${RELOCATING+ .rela.${SBSS_NAME}.* .rela.gnu.linkonce.sb.*}) }"
206 REL_SDATA2=".rel.${SDATA_NAME}2 ${RELOCATING-0} : { *(.rel.${SDATA_NAME}2${RELOCATING+ .rel.${SDATA_NAME}2.* .rel.gnu.linkonce.s2.*}) }
207 .rela.${SDATA_NAME}2 ${RELOCATING-0} : { *(.rela.${SDATA_NAME}2${RELOCATING+ .rela.${SDATA_NAME}2.* .rela.gnu.linkonce.s2.*}) }"
208 REL_SBSS2=".rel.${SBSS_NAME}2 ${RELOCATING-0} : { *(.rel.${SBSS_NAME}2${RELOCATING+ .rel.${SBSS_NAME}2.* .rel.gnu.linkonce.sb2.*}) }
209 .rela.${SBSS_NAME}2 ${RELOCATING-0} : { *(.rela.${SBSS_NAME}2${RELOCATING+ .rela.${SBSS_NAME}2.* .rela.gnu.linkonce.sb2.*}) }"
210 else
211 NO_SMALL_DATA=" "
212 fi
213 if test -z "${SDATA_GOT}${DATA_GOT}"; then
214 if test -n "${NO_SMALL_DATA}"; then
215 DATA_GOT=" "
216 fi
217 fi
218 if test -z "${SDATA_GOT}${DATA_GOT}"; then
219 if test -z "${NO_SMALL_DATA}"; then
220 SDATA_GOT=" "
221 fi
222 fi
223 test -n "$SEPARATE_GOTPLT" && SEPARATE_GOTPLT=" "
224 test "${LARGE_SECTIONS}" = "yes" && REL_LARGE="
225 .rel.ldata ${RELOCATING-0} : { *(.rel.ldata${RELOCATING+ .rel.ldata.* .rel.gnu.linkonce.l.*}) }
226 .rela.ldata ${RELOCATING-0} : { *(.rela.ldata${RELOCATING+ .rela.ldata.* .rela.gnu.linkonce.l.*}) }
227 .rel.lbss ${RELOCATING-0} : { *(.rel.lbss${RELOCATING+ .rel.lbss.* .rel.gnu.linkonce.lb.*}) }
228 .rela.lbss ${RELOCATING-0} : { *(.rela.lbss${RELOCATING+ .rela.lbss.* .rela.gnu.linkonce.lb.*}) }
229 .rel.lrodata ${RELOCATING-0} : { *(.rel.lrodata${RELOCATING+ .rel.lrodata.* .rel.gnu.linkonce.lr.*}) }
230 .rela.lrodata ${RELOCATING-0} : { *(.rela.lrodata${RELOCATING+ .rela.lrodata.* .rela.gnu.linkonce.lr.*}) }"
231 test "${LARGE_SECTIONS}" = "yes" && LARGE_BSS="
232 .lbss ${RELOCATING-0} :
233 {
234 ${RELOCATING+*(.dynlbss)}
235 *(.lbss${RELOCATING+ .lbss.* .gnu.linkonce.lb.*})
236 ${RELOCATING+*(LARGE_COMMON)}
237 }"
238 test "${LARGE_SECTIONS}" = "yes" && LARGE_SECTIONS="
239 .lrodata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} :
240 {
241 *(.lrodata${RELOCATING+ .lrodata.* .gnu.linkonce.lr.*})
242 }
243 .ldata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} :
244 {
245 *(.ldata${RELOCATING+ .ldata.* .gnu.linkonce.l.*})
246 ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
247 }"
248 if test "${ENABLE_INITFINI_ARRAY}" = "yes"; then
249 SORT_INIT_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))"
250 SORT_FINI_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))"
251 CTORS_IN_INIT_ARRAY="EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors"
252 DTORS_IN_FINI_ARRAY="EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors"
253 else
254 SORT_INIT_ARRAY="KEEP (*(SORT(.init_array.*)))"
255 SORT_FINI_ARRAY="KEEP (*(SORT(.fini_array.*)))"
256 CTORS_IN_INIT_ARRAY=
257 DTORS_IN_FINI_ARRAY=
258 fi
259 PREINIT_ARRAY=".preinit_array :
260 {
261 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_start = .);}
262 KEEP (*(.preinit_array))
263 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_end = .);}
264 }"
265 INIT_ARRAY=".init_array :
266 {
267 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_start = .);}
268 ${SORT_INIT_ARRAY}
269 KEEP (*(.init_array ${CTORS_IN_INIT_ARRAY}))
270 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_end = .);}
271 }"
272 FINI_ARRAY=".fini_array :
273 {
274 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_start = .);}
275 ${SORT_FINI_ARRAY}
276 KEEP (*(.fini_array ${DTORS_IN_FINI_ARRAY}))
277 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_end = .);}
278 }"
279 CTOR=".ctors ${CONSTRUCTING-0} :
280 {
281 ${CONSTRUCTING+${CTOR_START}}
282 /* gcc uses crtbegin.o to find the start of
283 the constructors, so we make sure it is
284 first. Because this is a wildcard, it
285 doesn't matter if the user does not
286 actually link against crtbegin.o; the
287 linker won't look for a file to match a
288 wildcard. The wildcard also means that it
289 doesn't matter which directory crtbegin.o
290 is in. */
291
292 KEEP (*crtbegin.o(.ctors))
293 KEEP (*crtbegin?.o(.ctors))
294
295 /* We don't want to include the .ctor section from
296 the crtend.o file until after the sorted ctors.
297 The .ctor section from the crtend file contains the
298 end of ctors marker and it must be last */
299
300 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
301 KEEP (*(SORT(.ctors.*)))
302 KEEP (*(.ctors))
303 ${CONSTRUCTING+${CTOR_END}}
304 }"
305 DTOR=".dtors ${CONSTRUCTING-0} :
306 {
307 ${CONSTRUCTING+${DTOR_START}}
308 KEEP (*crtbegin.o(.dtors))
309 KEEP (*crtbegin?.o(.dtors))
310 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
311 KEEP (*(SORT(.dtors.*)))
312 KEEP (*(.dtors))
313 ${CONSTRUCTING+${DTOR_END}}
314 }"
315 STACK=".stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
316 {
317 ${RELOCATING+${USER_LABEL_PREFIX}_stack = .;}
318 *(.stack)
319 ${RELOCATING+${STACK_SENTINEL}}
320 }"
321
322 TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${TEXT_START_ADDR})"
323 SHLIB_TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${SHLIB_TEXT_START_ADDR:-0})"
324
325 # Don't bother with separate code segment when there are data sections
326 # between .plt and .text.
327 if test -z "$TINY_READONLY_SECTION"; then
328 case "$LD_FLAG" in
329 *textonly*)
330 SEPARATE_TEXT=" "
331 TEXT_SEGMENT_ALIGN=". = ALIGN(${MAXPAGESIZE});"
332 ;;
333 esac
334 fi
335
336 if [ -z "$SEPARATE_CODE" ]; then
337 SIZEOF_HEADERS_CODE=" + SIZEOF_HEADERS"
338 else
339 SIZEOF_HEADERS_CODE=
340 fi
341
342 # If this is for an embedded system, don't add SIZEOF_HEADERS.
343 if [ -z "$EMBEDDED" ]; then
344 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}${SIZEOF_HEADERS_CODE}"
345 else
346 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
347 fi
348
349 cat <<EOF
350 /* Copyright (C) 2014-2023 Free Software Foundation, Inc.
351
352 Copying and distribution of this script, with or without modification,
353 are permitted in any medium without royalty provided the copyright
354 notice and this notice are preserved. */
355
356 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
357 "${LITTLE_OUTPUT_FORMAT}")
358 OUTPUT_ARCH(${OUTPUT_ARCH})
359
360 ${RELOCATING+${LIB_SEARCH_DIRS}}
361 ${RELOCATING+${CREATE_SHLIB-${EXECUTABLE_SYMBOLS}}}
362 ${RELOCATING+${INPUT_FILES}}
363 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
364 if gld -r is used and the intermediate file has sections starting
365 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
366 bug. But for now assigning the zero vmas works. */}
367
368 SECTIONS
369 {
370 ${RELOCATING+${SEPARATE_TEXT-/* Read-only sections, merged into text segment: */}}
371 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR}); . = ${TEXT_BASE_ADDRESS};}}}
372 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR}${SIZEOF_HEADERS_CODE};}}
373 ${CREATE_PIE+${RELOCATING+PROVIDE (__executable_start = ${SHLIB_TEXT_START_ADDR}); . = ${SHLIB_TEXT_START_ADDR}${SIZEOF_HEADERS_CODE};}}
374 EOF
375
376 emit_early_ro()
377 {
378 cat <<EOF
379 ${INITIAL_READONLY_SECTIONS}
380 .note.gnu.build-id ${RELOCATING-0}: { *(.note.gnu.build-id) }
381 EOF
382 }
383
384 test -n "${SEPARATE_CODE}" || emit_early_ro
385
386 test -n "${RELOCATING+0}" || unset NON_ALLOC_DYN
387 test -z "${NON_ALLOC_DYN}" || TEXT_DYNAMIC=
388 cat > ldscripts/dyntmp.$$ <<EOF
389 ${TEXT_DYNAMIC+${DYNAMIC}}
390 .hash ${RELOCATING-0} : { *(.hash) }
391 .gnu.hash ${RELOCATING-0} : { *(.gnu.hash) }
392 .dynsym ${RELOCATING-0} : { *(.dynsym) }
393 .dynstr ${RELOCATING-0} : { *(.dynstr) }
394 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
395 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
396 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
397 EOF
398
399 if [ "x$COMBRELOC" = x ]; then
400 COMBRELOCCAT="cat >> ldscripts/dyntmp.$$"
401 else
402 COMBRELOCCAT="cat > $COMBRELOC"
403 fi
404 eval $COMBRELOCCAT <<EOF
405 ${INITIAL_RELOC_SECTIONS}
406 .rel.init ${RELOCATING-0} : { *(.rel.init) }
407 .rela.init ${RELOCATING-0} : { *(.rela.init) }
408 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
409 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
410 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
411 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
412 .rel.${RODATA_NAME} ${RELOCATING-0} : { *(.rel.${RODATA_NAME}${RELOCATING+ .rel.${RODATA_NAME}.* .rel.gnu.linkonce.r.*}) }
413 .rela.${RODATA_NAME} ${RELOCATING-0} : { *(.rela.${RODATA_NAME}${RELOCATING+ .rela.${RODATA_NAME}.* .rela.gnu.linkonce.r.*}) }
414 ${OTHER_READONLY_RELOC_SECTIONS}
415 .rel.data.rel.ro ${RELOCATING-0} : { *(.rel.data.rel.ro${RELOCATING+ .rel.data.rel.ro.* .rel.gnu.linkonce.d.rel.ro.*}) }
416 .rela.data.rel.ro ${RELOCATING-0} : { *(.rela.data.rel.ro${RELOCATING+ .rela.data.rel.ro.* .rela.gnu.linkonce.d.rel.ro.*}) }
417 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
418 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
419 ${OTHER_READWRITE_RELOC_SECTIONS}
420 .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
421 .rela.tdata ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
422 .rel.tbss ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
423 .rela.tbss ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
424 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
425 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
426 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
427 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
428 .rel.got ${RELOCATING-0} : { *(.rel.got) }
429 .rela.got ${RELOCATING-0} : { *(.rela.got) }
430 ${OTHER_GOT_RELOC_SECTIONS}
431 ${REL_SDATA}
432 ${REL_SBSS}
433 ${REL_SDATA2}
434 ${REL_SBSS2}
435 .rel.${BSS_NAME} ${RELOCATING-0} : { *(.rel.${BSS_NAME}${RELOCATING+ .rel.${BSS_NAME}.* .rel.gnu.linkonce.b.*}) }
436 .rela.${BSS_NAME} ${RELOCATING-0} : { *(.rela.${BSS_NAME}${RELOCATING+ .rela.${BSS_NAME}.* .rela.gnu.linkonce.b.*}) }
437 ${REL_LARGE}
438 ${IREL_IN_PLT+$REL_IFUNC}
439 ${IREL_IN_PLT+$RELA_IFUNC}
440 ${IREL_IN_PLT-$REL_IPLT}
441 ${IREL_IN_PLT-$RELA_IPLT}
442 EOF
443
444 if [ -n "$COMBRELOC" ]; then
445 cat >> ldscripts/dyntmp.$$ <<EOF
446 .rel.dyn ${RELOCATING-0} :
447 {
448 EOF
449 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;/__rela_iplt_/d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC >> ldscripts/dyntmp.$$
450 cat >> ldscripts/dyntmp.$$ <<EOF
451 }
452 .rela.dyn ${RELOCATING-0} :
453 {
454 EOF
455 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;/__rel_iplt_/d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC >> ldscripts/dyntmp.$$
456 cat >> ldscripts/dyntmp.$$ <<EOF
457 }
458 EOF
459 fi
460
461 cat >> ldscripts/dyntmp.$$ <<EOF
462 .rel.plt ${RELOCATING-0} :
463 {
464 *(.rel.plt)
465 ${IREL_IN_PLT+${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_start = .);}}}
466 ${IREL_IN_PLT+${RELOCATING+*(.rel.iplt)}}
467 ${IREL_IN_PLT+${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_end = .);}}}
468 }
469 .rela.plt ${RELOCATING-0} :
470 {
471 *(.rela.plt)
472 ${IREL_IN_PLT+${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_start = .);}}}
473 ${IREL_IN_PLT+${RELOCATING+*(.rela.iplt)}}
474 ${IREL_IN_PLT+${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_end = .);}}}
475 }
476 ${OTHER_PLT_RELOC_SECTIONS}
477 EOF
478
479 emit_dyn()
480 {
481 if test -z "${NO_REL_RELOCS}${NO_RELA_RELOCS}"; then
482 cat ldscripts/dyntmp.$$
483 else
484 if test -z "${NO_REL_RELOCS}"; then
485 sed -e '/^[ ]*\.rela\.[^}]*$/,/}/d;/^[ ]*\.rela\./d;/__rela_iplt_/d' ldscripts/dyntmp.$$
486 fi
487 if test -z "${NO_RELA_RELOCS}"; then
488 sed -e '/^[ ]*\.rel\.[^}]*$/,/}/d;/^[ ]*\.rel\./d;/__rel_iplt_/d' ldscripts/dyntmp.$$
489 fi
490 fi
491 rm -f ldscripts/dyntmp.$$
492 }
493
494 test -n "${NON_ALLOC_DYN}${SEPARATE_CODE}" || emit_dyn
495
496 cat <<EOF
497 ${RELOCATING+${TEXT_SEGMENT_ALIGN}}
498
499 .init ${RELOCATING-0}${RELOCATING+${INIT_ADDR}} :
500 {
501 ${RELOCATING+${INIT_START}}
502 KEEP (*(SORT_NONE(.init)))
503 ${RELOCATING+${INIT_END}}
504 } ${FILL}
505
506 ${TEXT_PLT+${PLT_NEXT_DATA-${PLT} ${OTHER_PLT_SECTIONS}}}
507 ${TINY_READONLY_SECTION}
508 .text ${RELOCATING-0} :
509 {
510 ${RELOCATING+${TEXT_START_SYMBOLS}}
511 ${RELOCATING+*(.text.unlikely .text.*_unlikely .text.unlikely.*)}
512 ${RELOCATING+*(.text.exit .text.exit.*)}
513 ${RELOCATING+*(.text.startup .text.startup.*)}
514 ${RELOCATING+*(.text.hot .text.hot.*)}
515 ${RELOCATING+*(SORT(.text.sorted.*))}
516 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
517 /* .gnu.warning sections are handled specially by elf.em. */
518 *(.gnu.warning)
519 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
520 } ${FILL}
521 .fini ${RELOCATING-0}${RELOCATING+${FINI_ADDR}} :
522 {
523 ${RELOCATING+${FINI_START}}
524 KEEP (*(SORT_NONE(.fini)))
525 ${RELOCATING+${FINI_END}}
526 } ${FILL}
527 ${RELOCATING+PROVIDE (__${ETEXT_NAME} = .);}
528 ${RELOCATING+PROVIDE (_${ETEXT_NAME} = .);}
529 ${RELOCATING+PROVIDE (${ETEXT_NAME} = .);}
530 ${RELOCATING+${TEXT_SEGMENT_ALIGN}}
531 EOF
532
533 if test -n "${SEPARATE_CODE}${SEPARATE_TEXT}"; then
534 if test -n "${RODATA_ADDR}"; then
535 RODATA_ADDR="\
536 SEGMENT_START(\"rodata-segment\", ${RODATA_ADDR}) + SIZEOF_HEADERS"
537 else
538 RODATA_ADDR="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
539 RODATA_ADDR="SEGMENT_START(\"rodata-segment\", ${RODATA_ADDR})"
540 fi
541 if test -n "${SHLIB_RODATA_ADDR}"; then
542 SHLIB_RODATA_ADDR="\
543 SEGMENT_START(\"rodata-segment\", ${SHLIB_RODATA_ADDR}) + SIZEOF_HEADERS"
544 else
545 SHLIB_RODATA_ADDR="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
546 SHLIB_RODATA_ADDR="SEGMENT_START(\"rodata-segment\", ${SHLIB_RODATA_ADDR})"
547 fi
548 cat <<EOF
549 ${RELOCATING+/* Adjust the address for the rodata segment. We want to adjust up to
550 the same address within the page on the next page up. */
551 ${CREATE_SHLIB-${CREATE_PIE-. = ${RODATA_ADDR};}}
552 ${CREATE_SHLIB+. = ${SHLIB_RODATA_ADDR};}
553 ${CREATE_PIE+. = ${SHLIB_RODATA_ADDR};}}
554 EOF
555 if test -n "${SEPARATE_CODE}"; then
556 emit_early_ro
557 emit_dyn
558 fi
559 fi
560
561 cat <<EOF
562 ${WRITABLE_RODATA-${RODATA}}
563 .${RODATA_NAME}1 ${RELOCATING-0} : { *(.${RODATA_NAME}1) }
564 ${CREATE_SHLIB-${SDATA2}}
565 ${CREATE_SHLIB-${SBSS2}}
566 ${OTHER_READONLY_SECTIONS}
567 .eh_frame_hdr ${RELOCATING-0} : { *(.eh_frame_hdr)${RELOCATING+ *(.eh_frame_entry .eh_frame_entry.*)} }
568 .eh_frame ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame))${RELOCATING+ *(.eh_frame.*)} }
569 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
570 .gnu_extab ${RELOCATING-0} : ONLY_IF_RO { *(.gnu_extab*) }
571 /* These sections are generated by the Sun/Oracle C++ compiler. */
572 .exception_ranges ${RELOCATING-0} : ONLY_IF_RO { *(.exception_ranges${RELOCATING+*}) }
573 ${TEXT_PLT+${PLT_NEXT_DATA+${PLT} ${OTHER_PLT_SECTIONS}}}
574
575 ${RELOCATING+/* Adjust the address for the data segment. We want to adjust up to
576 the same address within the page on the next page up. */}
577 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
578 ${CREATE_SHLIB+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}
579 ${CREATE_PIE+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}
580
581 /* Exception handling */
582 .eh_frame ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame))${RELOCATING+ *(.eh_frame.*)} }
583 .gnu_extab ${RELOCATING-0} : ONLY_IF_RW { *(.gnu_extab) }
584 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
585 .exception_ranges ${RELOCATING-0} : ONLY_IF_RW { *(.exception_ranges${RELOCATING+*}) }
586
587 /* Thread Local Storage sections */
588 .tdata ${RELOCATING-0} :
589 {
590 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__tdata_start = .);}}
591 *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*})
592 }
593 .tbss ${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
594
595 ${RELOCATING+${PREINIT_ARRAY}}
596 ${RELOCATING+${INIT_ARRAY}}
597 ${RELOCATING+${FINI_ARRAY}}
598 ${SMALL_DATA_CTOR-${RELOCATING+${CTOR}}}
599 ${SMALL_DATA_DTOR-${RELOCATING+${DTOR}}}
600 .jcr ${RELOCATING-0} : { KEEP (*(.jcr)) }
601
602 ${RELOCATING+${DATARELRO}}
603 ${OTHER_RELRO_SECTIONS}
604 ${TEXT_DYNAMIC-${DYNAMIC}}
605 ${OTHER_RELRO_SECTIONS_2}
606 ${DATA_GOT+${RELRO_NOW+${DATA_PLT+${PLT_BEFORE_GOT+${PLT}}}}}
607 ${DATA_GOT+${RELRO_NOW+${GOT}}}
608 ${DATA_GOT+${RELRO_NOW+${GOTPLT}}}
609 ${DATA_GOT+${RELRO_NOW-${SEPARATE_GOTPLT+${GOT}}}}
610 ${RELOCATING+${DATA_SEGMENT_RELRO_END}}
611 ${INITIAL_READWRITE_SECTIONS}
612 ${DATA_SDATA+${SDATA}}
613 ${DATA_SDATA+${OTHER_SDATA_SECTIONS}}
614 ${DATA_SDATA+${SBSS}}
615 ${DATA_GOT+${RELRO_NOW-${DATA_PLT+${PLT_BEFORE_GOT+${PLT}}}}}
616 ${DATA_GOT+${RELRO_NOW-${SEPARATE_GOTPLT-${GOT}}}}
617 ${DATA_GOT+${RELRO_NOW-${GOTPLT}}}
618
619 ${DATA_PLT+${PLT_BEFORE_GOT-${PLT}}}
620
621 .data ${RELOCATING-0} :
622 {
623 ${RELOCATING+${DATA_START_SYMBOLS}}
624 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
625 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
626 }
627 .data1 ${RELOCATING-0} : { *(.data1) }
628 ${WRITABLE_RODATA+${RODATA}}
629 ${OTHER_READWRITE_SECTIONS}
630 ${SMALL_DATA_CTOR+${RELOCATING+${CTOR}}}
631 ${SMALL_DATA_DTOR+${RELOCATING+${DTOR}}}
632 ${SDATA_GOT+${DATA_PLT+${PLT_BEFORE_GOT+${PLT}}}}
633 ${SDATA_GOT+${RELOCATING+${OTHER_GOT_SYMBOLS+. = .; ${OTHER_GOT_SYMBOLS}}}}
634 ${SDATA_GOT+${GOT}}
635 ${SDATA_GOT+${OTHER_GOT_SECTIONS}}
636 ${DATA_SDATA-${SDATA}}
637 ${DATA_SDATA-${OTHER_SDATA_SECTIONS}}
638 ${RELOCATING+${DATA_END_SYMBOLS-${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}_edata = .${CREATE_SHLIB+)}; PROVIDE (${USER_LABEL_PREFIX}edata = .);}}
639 ${RELOCATING+. = .;}
640 ${RELOCATING+${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}__bss_start = .${CREATE_SHLIB+)};}
641 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
642 ${DATA_SDATA-${SBSS}}
643 ${BSS_PLT+${PLT}}
644 .${BSS_NAME} ${RELOCATING-0} :
645 {
646 ${RELOCATING+*(.dynbss)}
647 *(.${BSS_NAME}${RELOCATING+ .${BSS_NAME}.* .gnu.linkonce.b.*})
648 ${RELOCATING+*(COMMON)
649 /* Align here to ensure that the .bss section occupies space up to
650 _end. Align after .bss to ensure correct alignment even if the
651 .bss section disappears because there are no input sections.
652 FIXME: Why do we need it? When there is no .bss section, we do not
653 pad the .data section. */
654 . = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
655 }
656 ${OTHER_BSS_SECTIONS}
657 ${LARGE_BSS_AFTER_BSS+${LARGE_BSS}}
658 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
659 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
660 EOF
661
662 LARGE_DATA_ADDR=". = SEGMENT_START(\"ldata-segment\", ${LARGE_DATA_ADDR-.});"
663 SHLIB_LARGE_DATA_ADDR=". = SEGMENT_START(\"ldata-segment\", ${SHLIB_LARGE_DATA_ADDR-.});"
664
665 cat <<EOF
666 ${RELOCATING+${CREATE_SHLIB-${CREATE_PIE-${LARGE_DATA_ADDR}}}}
667 ${CREATE_SHLIB+${SHLIB_LARGE_DATA_ADDR}}
668 ${CREATE_PIE+${SHLIB_LARGE_DATA_ADDR}}
669 ${LARGE_SECTIONS}
670 ${LARGE_BSS_AFTER_BSS-${LARGE_BSS}}
671 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
672 ${RELOCATING+${OTHER_END_SYMBOLS}}
673 ${RELOCATING+${END_SYMBOLS-${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}_end = .${CREATE_SHLIB+)}; PROVIDE (${USER_LABEL_PREFIX}end = .);}}
674 ${RELOCATING+${DATA_SEGMENT_END}}
675 ${TINY_DATA_SECTION}
676 ${TINY_BSS_SECTION}
677 ${STACK_ADDR+${STACK}}
678 EOF
679
680 test -z "${NON_ALLOC_DYN}" || emit_dyn
681
682 source_sh $srcdir/scripttempl/misc-sections.sc
683
684 cat <<EOF
685 ${ATTRS_SECTIONS}
686 ${OTHER_SECTIONS}
687 ${RELOCATING+${OTHER_SYMBOLS}}
688 ${RELOCATING+${DISCARDED}}
689 }
690 EOF