Commit | Line | Data |
---|---|---|
b4477fa8 NC |
1 | # |
2 | # Unusual variables checked by this code: | |
3 | # NOP - four byte opcode for no-op (defaults to 0) | |
4 | # NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not | |
5 | # empty. | |
6 | # DATA_ADDR - if end-of-text-plus-one-page isn't right for data start | |
7 | # INITIAL_READONLY_SECTIONS - at start of text segment | |
8 | # OTHER_READONLY_SECTIONS - other than .text .init .rodata ... | |
9 | # (e.g., .PARISC.milli) | |
10 | # OTHER_TEXT_SECTIONS - these get put in .text when relocating | |
11 | # OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ... | |
12 | # (e.g., .PARISC.global) | |
104d59d1 | 13 | # ATTRS_SECTIONS - at the end |
b4477fa8 NC |
14 | # OTHER_SECTIONS - at the end |
15 | # EXECUTABLE_SYMBOLS - symbols that must be defined for an | |
16 | # executable (e.g., _DYNAMIC_LINK) | |
17 | # TEXT_START_SYMBOLS - symbols that appear at the start of the | |
18 | # .text section. | |
19 | # DATA_START_SYMBOLS - symbols that appear at the start of the | |
20 | # .data section. | |
21 | # OTHER_GOT_SYMBOLS - symbols defined just before .got. | |
22 | # OTHER_GOT_SECTIONS - sections just after .got. | |
23 | # OTHER_SDATA_SECTIONS - sections just after .sdata. | |
24 | # OTHER_BSS_SYMBOLS - symbols that appear at the start of the | |
25 | # .bss section besides __bss_start. | |
26 | # DATA_PLT - .plt should be in data segment, not text segment. | |
27 | # BSS_PLT - .plt should be in bss segment | |
28 | # TEXT_DYNAMIC - .dynamic in text segment, not data segment. | |
29 | # EMBEDDED - whether this is for an embedded system. | |
30 | # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set | |
31 | # start address of shared library. | |
32 | # INPUT_FILES - INPUT command of files to always include | |
33 | # WRITABLE_RODATA - if set, the .rodata section should be writable | |
34 | # INIT_START, INIT_END - statements just before and just after | |
35 | # combination of .init sections. | |
36 | # FINI_START, FINI_END - statements just before and just after | |
37 | # combination of .fini sections. | |
38 | # STACK_ADDR - start of a .stack section. | |
827a1c67 | 39 | # OTHER_SYMBOLS - symbols to place right at the end of the script. |
b4477fa8 NC |
40 | # |
41 | # When adding sections, do note that the names of some sections are used | |
42 | # when specifying the start address of the next. | |
43 | # | |
44 | ||
45 | # Many sections come in three flavours. There is the 'real' section, | |
46 | # like ".data". Then there are the per-procedure or per-variable | |
47 | # sections, generated by -ffunction-sections and -fdata-sections in GCC, | |
48 | # and useful for --gc-sections, which for a variable "foo" might be | |
49 | # ".data.foo". Then there are the linkonce sections, for which the linker | |
50 | # eliminates duplicates, which are named like ".gnu.linkonce.d.foo". | |
51 | # The exact correspondences are: | |
52 | # | |
53 | # Section Linkonce section | |
54 | # .text .gnu.linkonce.t.foo | |
55 | # .rodata .gnu.linkonce.r.foo | |
56 | # .data .gnu.linkonce.d.foo | |
57 | # .bss .gnu.linkonce.b.foo | |
58 | # .sdata .gnu.linkonce.s.foo | |
59 | # .sbss .gnu.linkonce.sb.foo | |
60 | # .sdata2 .gnu.linkonce.s2.foo | |
61 | # .sbss2 .gnu.linkonce.sb2.foo | |
62 | # .debug_info .gnu.linkonce.wi.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" | |
104d59d1 | 72 | test -z "$ATTRS_SECTIONS" && ATTRS_SECTIONS=".gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }" |
b4477fa8 | 73 | test "$LD_FLAG" = "N" && DATA_ADDR=. |
ec2d9b29 AM |
74 | INTERP=".interp ${RELOCATING-0} : { *(.interp) }" |
75 | PLT=".plt ${RELOCATING-0} : { *(.plt) }" | |
76 | DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }" | |
77 | RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }" | |
b4477fa8 | 78 | if test -z "${NO_SMALL_DATA}"; then |
ec2d9b29 | 79 | SBSS=".sbss ${RELOCATING-0} : |
b4477fa8 NC |
80 | { |
81 | ${RELOCATING+PROVIDE (__sbss_start = .);} | |
82 | ${RELOCATING+PROVIDE (___sbss_start = .);} | |
83 | *(.dynsbss) | |
84 | *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*}) | |
85 | *(.scommon) | |
86 | ${RELOCATING+PROVIDE (__sbss_end = .);} | |
87 | ${RELOCATING+PROVIDE (___sbss_end = .);} | |
88 | }" | |
ec2d9b29 | 89 | SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }" |
b4477fa8 NC |
90 | SDATA="/* We want the small data sections together, so single-instruction offsets |
91 | can access them all, and initialized data all before uninitialized, so | |
92 | we can shorten the on-disk segment size. */ | |
ec2d9b29 | 93 | .sdata ${RELOCATING-0} : |
b4477fa8 NC |
94 | { |
95 | ${RELOCATING+${SDATA_START_SYMBOLS}} | |
96 | *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*}) | |
97 | }" | |
ec2d9b29 AM |
98 | SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) }" |
99 | REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) } | |
100 | .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }" | |
101 | REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) } | |
102 | .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }" | |
103 | REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) } | |
104 | .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }" | |
105 | REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) } | |
106 | .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }" | |
b4477fa8 NC |
107 | fi |
108 | CTOR=" | |
109 | ${CONSTRUCTING+${CTOR_START}} | |
110 | /* gcc uses crtbegin.o to find the start of | |
111 | the constructors, so we make sure it is | |
112 | first. Because this is a wildcard, it | |
113 | doesn't matter if the user does not | |
114 | actually link against crtbegin.o; the | |
115 | linker won't look for a file to match a | |
116 | wildcard. The wildcard also means that it | |
117 | doesn't matter which directory crtbegin.o | |
118 | is in. */ | |
119 | ||
40cf2291 AM |
120 | KEEP (*crtbegin.o(.ctors)) |
121 | KEEP (*crtbegin?.o(.ctors)) | |
b4477fa8 NC |
122 | |
123 | /* We don't want to include the .ctor section from | |
bd6791bc | 124 | the crtend.o file until after the sorted ctors. |
b4477fa8 NC |
125 | The .ctor section from the crtend file contains the |
126 | end of ctors marker and it must be last */ | |
127 | ||
40cf2291 | 128 | KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors)) |
b4477fa8 NC |
129 | KEEP (*(SORT(.ctors.*))) |
130 | KEEP (*(.ctors)) | |
131 | ${CONSTRUCTING+${CTOR_END}} | |
132 | " | |
133 | DTOR=" | |
134 | ${CONSTRUCTING+${DTOR_START}} | |
40cf2291 AM |
135 | KEEP (*crtbegin.o(.dtors)) |
136 | KEEP (*crtbegin?.o(.dtors)) | |
137 | KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors)) | |
b4477fa8 NC |
138 | KEEP (*(SORT(.dtors.*))) |
139 | KEEP (*(.dtors)) | |
140 | ${CONSTRUCTING+${DTOR_END}} | |
141 | " | |
ec2d9b29 | 142 | STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} : |
b4477fa8 NC |
143 | { |
144 | ${RELOCATING+_stack = .;} | |
145 | *(.stack) | |
146 | }" | |
147 | ||
148 | test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}" | |
149 | ||
150 | cat <<EOF | |
151 | OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}", | |
152 | "${LITTLE_OUTPUT_FORMAT}") | |
153 | OUTPUT_ARCH(${OUTPUT_ARCH}) | |
b34c1498 | 154 | ${RELOCATING+ENTRY(${ENTRY})} |
b4477fa8 NC |
155 | |
156 | ${RELOCATING+${LIB_SEARCH_DIRS}} | |
157 | ${RELOCATING+/* Do we need any of these for elf? | |
158 | __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */} | |
159 | ${RELOCATING+${EXECUTABLE_SYMBOLS}} | |
160 | ${RELOCATING+${INPUT_FILES}} | |
ec2d9b29 AM |
161 | ${RELOCATING- /* For some reason, the Solaris linker makes bad executables |
162 | if gld -r is used and the intermediate file has sections starting | |
163 | at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld | |
164 | bug. But for now assigning the zero vmas works. */} | |
b4477fa8 NC |
165 | |
166 | SECTIONS | |
167 | { | |
168 | /* Read-only sections, merged into text segment: */ | |
169 | ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}} | |
170 | ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0};}} | |
171 | ${CREATE_SHLIB-${INTERP}} | |
172 | ${INITIAL_READONLY_SECTIONS} | |
173 | ${TEXT_DYNAMIC+${DYNAMIC}} | |
ec2d9b29 AM |
174 | .hash ${RELOCATING-0} : { *(.hash) } |
175 | .dynsym ${RELOCATING-0} : { *(.dynsym) } | |
176 | .dynstr ${RELOCATING-0} : { *(.dynstr) } | |
177 | .gnu.version ${RELOCATING-0} : { *(.gnu.version) } | |
178 | .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) } | |
179 | .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) } | |
b4477fa8 NC |
180 | |
181 | EOF | |
182 | if [ "x$COMBRELOC" = x ]; then | |
183 | COMBRELOCCAT=cat | |
184 | else | |
185 | COMBRELOCCAT="cat > $COMBRELOC" | |
186 | fi | |
187 | eval $COMBRELOCCAT <<EOF | |
ec2d9b29 AM |
188 | .rel.init ${RELOCATING-0} : { *(.rel.init) } |
189 | .rela.init ${RELOCATING-0} : { *(.rela.init) } | |
190 | .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) } | |
191 | .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) } | |
192 | .rel.fini ${RELOCATING-0} : { *(.rel.fini) } | |
193 | .rela.fini ${RELOCATING-0} : { *(.rela.fini) } | |
194 | .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) } | |
195 | .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) } | |
b4477fa8 | 196 | ${OTHER_READONLY_RELOC_SECTIONS} |
ec2d9b29 AM |
197 | .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) } |
198 | .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) } | |
199 | .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) } | |
200 | .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) } | |
201 | .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) } | |
202 | .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) } | |
203 | .rel.got ${RELOCATING-0} : { *(.rel.got) } | |
204 | .rela.got ${RELOCATING-0} : { *(.rela.got) } | |
b4477fa8 NC |
205 | ${OTHER_GOT_RELOC_SECTIONS} |
206 | ${REL_SDATA} | |
207 | ${REL_SBSS} | |
208 | ${REL_SDATA2} | |
209 | ${REL_SBSS2} | |
ec2d9b29 AM |
210 | .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) } |
211 | .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) } | |
b4477fa8 NC |
212 | EOF |
213 | if [ -n "$COMBRELOC" ]; then | |
214 | cat <<EOF | |
ec2d9b29 | 215 | .rel.dyn ${RELOCATING-0} : |
b4477fa8 NC |
216 | { |
217 | EOF | |
218 | sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC | |
219 | cat <<EOF | |
220 | } | |
ec2d9b29 | 221 | .rela.dyn ${RELOCATING-0} : |
b4477fa8 NC |
222 | { |
223 | EOF | |
224 | sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC | |
225 | cat <<EOF | |
226 | } | |
227 | EOF | |
228 | fi | |
229 | cat <<EOF | |
230 | . = ALIGN(0x1000); | |
ec2d9b29 AM |
231 | .rel.plt ${RELOCATING-0} : { *(.rel.plt) } |
232 | .rela.plt ${RELOCATING-0} : { *(.rela.plt) } | |
b4477fa8 NC |
233 | ${OTHER_PLT_RELOC_SECTIONS} |
234 | ${DATA_PLT-${BSS_PLT-${PLT}}} | |
ec2d9b29 | 235 | .text ${RELOCATING-0} : |
b4477fa8 NC |
236 | { |
237 | ${RELOCATING+${TEXT_START_SYMBOLS}} | |
238 | *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*}) | |
239 | /* .gnu.warning sections are handled specially by elf32.em. */ | |
240 | *(.gnu.warning) | |
241 | ${RELOCATING+${OTHER_TEXT_SECTIONS}} | |
242 | } =${NOP-0} | |
ec2d9b29 | 243 | .fini ${RELOCATING-0} : |
b4477fa8 NC |
244 | { |
245 | ${RELOCATING+${FINI_START}} | |
246 | KEEP (*(.fini)) | |
247 | ${RELOCATING+${FINI_END}} | |
248 | } =${NOP-0} | |
249 | ${RELOCATING+PROVIDE (__etext = .);} | |
250 | ${RELOCATING+PROVIDE (_etext = .);} | |
251 | ${RELOCATING+PROVIDE (etext = .);} | |
252 | . = ALIGN(0x1000); | |
253 | ${CREATE_SHLIB-${SDATA2}} | |
254 | ${CREATE_SHLIB-${SBSS2}} | |
255 | ${OTHER_READONLY_SECTIONS} | |
256 | .eh_frame_hdr : { *(.eh_frame_hdr) } | |
257 | ||
258 | . = ALIGN(0x1000); | |
ec2d9b29 | 259 | .data ${RELOCATING-0} : |
b4477fa8 NC |
260 | { |
261 | *(.rodata .rodata.*) | |
262 | *(.rodata1) | |
263 | *(.gnu.linkonce.r.*) | |
264 | ${RELOCATING+${DATA_START_SYMBOLS}} | |
265 | *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*}) | |
266 | ${CONSTRUCTING+SORT(CONSTRUCTORS)} | |
267 | KEEP (*(.eh_frame)) | |
268 | *(.gcc_except_table) | |
269 | ${CTOR} | |
270 | ${DTOR} | |
271 | KEEP (*(.jcr)) | |
272 | } | |
ec2d9b29 | 273 | .data1 ${RELOCATING-0} : { *(.data1) } |
b4477fa8 | 274 | . = ALIGN(0x1000); |
ec2d9b29 | 275 | .gcc_except_table ${RELOCATING-0} : { *(.gcc_except_table) } |
b4477fa8 NC |
276 | ${WRITABLE_RODATA+${RODATA}} |
277 | ${OTHER_READWRITE_SECTIONS} | |
278 | ${TEXT_DYNAMIC-${DYNAMIC}} | |
279 | ${DATA_PLT+${PLT}} | |
280 | ${RELOCATING+${OTHER_GOT_SYMBOLS}} | |
ec2d9b29 | 281 | .got ${RELOCATING-0} : { *(.got.plt) *(.got) } |
b4477fa8 NC |
282 | ${OTHER_GOT_SECTIONS} |
283 | ${CREATE_SHLIB+${SDATA2}} | |
284 | ${CREATE_SHLIB+${SBSS2}} | |
285 | ${SDATA} | |
286 | ${OTHER_SDATA_SECTIONS} | |
287 | ${RELOCATING+_edata = .;} | |
288 | ${RELOCATING+PROVIDE (edata = .);} | |
289 | ${RELOCATING+__bss_start = .;} | |
290 | ${RELOCATING+${OTHER_BSS_SYMBOLS}} | |
291 | ${SBSS} | |
292 | ${BSS_PLT+${PLT}} | |
293 | . = ALIGN(0x1000); | |
ec2d9b29 | 294 | .bss ${RELOCATING-0} : |
b4477fa8 NC |
295 | { |
296 | *(.dynbss) | |
297 | *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*}) | |
298 | *(COMMON) | |
299 | /* Align here to ensure that the .bss section occupies space up to | |
300 | _end. Align after .bss to ensure correct alignment even if the | |
301 | .bss section disappears because there are no input sections. */ | |
302 | ${RELOCATING+. = ALIGN(${ALIGNMENT});} | |
303 | } | |
827a1c67 | 304 | ${RELOCATING+${OTHER_BSS_END_SYMBOLS}} |
b4477fa8 | 305 | ${RELOCATING+. = ALIGN(${ALIGNMENT});} |
9f4fb502 | 306 | ${RELOCATING+${OTHER_END_SYMBOLS}} |
827a1c67 | 307 | ${RELOCATING+_end = .;} |
b4477fa8 NC |
308 | ${RELOCATING+PROVIDE (end = .);} |
309 | ||
310 | /* Stabs debugging sections. */ | |
311 | . = ALIGN(0x1000); | |
312 | .stab 0 : { *(.stab) } | |
313 | .stabstr 0 : { *(.stabstr) } | |
314 | .stab.excl 0 : { *(.stab.excl) } | |
315 | .stab.exclstr 0 : { *(.stab.exclstr) } | |
316 | .stab.index 0 : { *(.stab.index) } | |
317 | .stab.indexstr 0 : { *(.stab.indexstr) } | |
318 | ||
319 | . = ALIGN(0x1000); | |
320 | .comment 0 : { *(.comment) } | |
321 | ||
ceb0a680 | 322 | EOF |
b4477fa8 | 323 | |
d061dfac | 324 | . $srcdir/scripttempl/DWARF.sc |
b4477fa8 | 325 | |
ceb0a680 | 326 | cat <<EOF |
b4477fa8 | 327 | ${STACK_ADDR+${STACK}} |
104d59d1 | 328 | ${ATTRS_SECTIONS} |
b4477fa8 | 329 | ${OTHER_SECTIONS} |
827a1c67 | 330 | ${RELOCATING+${OTHER_SYMBOLS}} |
b4477fa8 NC |
331 | } |
332 | EOF |