elfarcv2.sc revision 1.1.1.5 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 # OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
7 # (e.g., .PARISC.milli)
8 # When adding sections, do note that the names of some sections are used
9 # when specifying the start address of the next.
10 #
11 test -z "$ENTRY" && ENTRY=start
12 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
13 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
14 # If we request a big endian toolchain, give a big endian linker
15 test -z "$GOT" && GOT=".got ${RELOCATING-0} : {${RELOCATING+ *(.got.plt)} *(.got) } ${RELOCATING+ > ${DATA_MEMORY}}"
16 test "${ARC_ENDIAN}" = "big" && OUTPUT_FORMAT=${BIG_OUTPUT_FORMAT}
17 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
18 test -z "${ELFSIZE}" && ELFSIZE=32
19 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
20 test "$LD_FLAG" = "N" && DATA_ADDR=.
21
22 CTOR=".ctors ${CONSTRUCTING-0} :
23 {
24 ${CONSTRUCTING+${CTOR_START}}
25 /* gcc uses crtbegin.o to find the start of
26 the constructors, so we make sure it is
27 first. Because this is a wildcard, it
28 doesn't matter if the user does not
29 actually link against crtbegin.o; the
30 linker won't look for a file to match a
31 wildcard. The wildcard also means that it
32 doesn't matter which directory crtbegin.o
33 is in. */
34
35 KEEP (*crtbegin*.o(.ctors))
36
37 /* We don't want to include the .ctor section from
38 from the crtend.o file until after the sorted ctors.
39 The .ctor section from the crtend file contains the
40 end of ctors marker and it must be last */
41
42 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors))
43 KEEP (*(SORT(.ctors.*)))
44 KEEP (*(.ctors))
45 ${CONSTRUCTING+${CTOR_END}}
46 } ${RELOCATING+ > ${DATA_MEMORY}}"
47 DTOR=".dtors ${CONSTRUCTING-0} :
48 {
49 ${CONSTRUCTING+${DTOR_START}}
50 KEEP (*crtbegin*.o(.dtors))
51 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors))
52 KEEP (*(SORT(.dtors.*)))
53 KEEP (*(.dtors))
54 ${CONSTRUCTING+${DTOR_END}}
55 } ${RELOCATING+ > ${DATA_MEMORY}}"
56
57 IVT="
58 /* If the 'ivtbase_addr' symbol is defined, it indicates the base address of
59 the interrupt vectors. See description of INT_VECTOR_BASE register. */
60
61 .ivt DEFINED (ivtbase_addr) ? ivtbase_addr : ORIGIN(${STARTUP_MEMORY}) :
62 {
63 ${RELOCATING+ PROVIDE (__ivtbase_addr = .); }
64 KEEP (*(.ivt));
65 } ${RELOCATING+ > ${STARTUP_MEMORY}}"
66
67 if test -z "${NO_SMALL_DATA}"; then
68 SBSS=".sbss ${RELOCATING-0} :
69 {
70 ${RELOCATING+PROVIDE (__sbss_start = .);}
71 ${RELOCATING+PROVIDE (___sbss_start = .);}
72 *(.dynsbss)
73 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
74 *(.scommon)
75 ${RELOCATING+PROVIDE (__sbss_end = .);}
76 ${RELOCATING+PROVIDE (___sbss_end = .);}
77 } ${RELOCATING+ > ${SDATA_MEMORY}}"
78 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) } ${RELOCATING+ > ${SDATA_MEMORY}}"
79 SDATA="/* We want the small data sections together, so single-instruction offsets
80 can access them all, and initialized data all before uninitialized, so
81 we can shorten the on-disk segment size. */
82 .sdata ${RELOCATING-0} :
83 {
84 ${RELOCATING+${SDATA_START_SYMBOLS}}
85 *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
86
87 ${RELOCATING+_edata = .;}
88 ${RELOCATING+PROVIDE (edata = .);}
89 } ${RELOCATING+ > ${SDATA_MEMORY}}"
90 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) } ${RELOCATING+ > ${SDATA_MEMORY}}"
91 REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
92 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
93 REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
94 .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
95 REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
96 .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
97 REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
98 .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
99 fi
100
101 #
102 # We provide two emulations: a fixed on that defines some memory banks
103 # and a configurable one that includes a user provided memory definition.
104 #
105 case $GENERIC_BOARD in
106 yes|1|YES)
107 test -z "$MEMORY_FILE" && MEMORY_FILE="memory.x"
108 MEMORY_DEF="
109 /* Get memory banks definition from some user configuration file.
110 This file must be located in some linker directory (search path
111 with -L<dir>). See fixed memory banks emulation script. */
112 INCLUDE ${MEMORY_FILE};
113 "
114 ;;
115 *)
116 MEMORY_DEF="
117 __TEXT_REGION_ORIGIN__ = DEFINED(__TEXT_REGION_ORIGIN__) ? __TEXT_REGION_ORIGIN__ : 0x00;
118 __TEXT_REGION_LENGTH__ = DEFINED(__TEXT_REGION_LENGTH__) ? __TEXT_REGION_LENGTH__ : ${ICCM_SIZE};
119 __DATA_REGION_ORIGIN__ = DEFINED(__DATA_REGION_ORIGIN__) ? __DATA_REGION_ORIGIN__ : ${RAM_START_ADDR};
120 __DATA_REGION_LENGTH__ = DEFINED(__DATA_REGION_LENGTH__) ? __DATA_REGION_LENGTH__ : ${RAM_SIZE};
121
122 MEMORY
123 {
124 ICCM : ORIGIN = __TEXT_REGION_ORIGIN__, LENGTH = __TEXT_REGION_LENGTH__
125 DCCM : ORIGIN = __DATA_REGION_ORIGIN__, LENGTH = __DATA_REGION_LENGTH__
126 }
127 "
128 ;;
129 esac
130
131 cat <<EOF
132 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}", "${LITTLE_OUTPUT_FORMAT}")
133 OUTPUT_ARCH(${OUTPUT_ARCH})
134 ${RELOCATING+ENTRY(${ENTRY})}
135
136 ${RELOCATING+${LIB_SEARCH_DIRS}}
137 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
138 ${RELOCATING+${MEMORY_DEF}}
139
140 SECTIONS
141 {
142 ${RELOCATING+${IVT}}
143
144 /* Read-only sections, merged into text segment: */
145 ${TEXT_DYNAMIC+${DYNAMIC}}
146 .hash ${RELOCATING-0} : { *(.hash) }
147 .dynsym ${RELOCATING-0} : { *(.dynsym) }
148 .dynstr ${RELOCATING-0} : { *(.dynstr) }
149 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
150 .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) }
151 .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) }
152
153 .rel.init ${RELOCATING-0} : { *(.rel.init) }
154 .rela.init ${RELOCATING-0} : { *(.rela.init) }
155 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
156 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
157 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
158 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
159 .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
160 .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
161 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
162 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
163 .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
164 .rela.tdata ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
165 .rel.tbss ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
166 .rela.tbss ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
167 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
168 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
169 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
170 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
171 .rel.got ${RELOCATING-0} : { *(.rel.got) }
172 .rela.got ${RELOCATING-0} : { *(.rela.got) }
173 ${REL_SDATA}
174 ${REL_SBSS}
175 ${REL_SDATA2}
176 ${REL_SBSS2}
177 .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
178 .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
179
180 .text ${RELOCATING-0} :
181 {
182 ${RELOCATING+${TEXT_START_SYMBOLS}}
183
184 ${RELOCATING+ . = ALIGN(4);}
185 ${RELOCATING+${INIT_START}}
186 KEEP (*(SORT_NONE(.init)))
187 ${RELOCATING+${INIT_END}}
188
189 /* Start here after reset. */
190 ${RELOCATING+ . = ALIGN(4);}
191 KEEP (*crt0.o(.text.__startup))
192
193 /* Remaining code. */
194 ${RELOCATING+ . = ALIGN(4);}
195 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
196 /* .gnu.warning sections are handled specially by elf.em. */
197 *(.gnu.warning)
198
199 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
200
201 } ${RELOCATING+ > ${TEXT_MEMORY}} =${NOP-0}
202
203 .fini ${RELOCATING-0} :
204 {
205 ${RELOCATING+${FINI_START}}
206 KEEP (*(SORT_NONE(.fini)))
207 ${RELOCATING+${FINI_END}}
208
209 ${RELOCATING+PROVIDE (__etext = .);}
210 ${RELOCATING+PROVIDE (_etext = .);}
211 ${RELOCATING+PROVIDE (etext = .);}
212 } ${RELOCATING+ > ${TEXT_MEMORY}} =${NOP-0}
213
214 .jcr ${RELOCATING-0} :
215 {
216 KEEP (*(.jcr))
217 } ${RELOCATING+> ${TEXT_MEMORY}}
218
219 .eh_frame ${RELOCATING-0} :
220 {
221 KEEP (*(.eh_frame))
222 } ${RELOCATING+> ${TEXT_MEMORY}}
223
224 .gcc_except_table ${RELOCATING-0} :
225 {
226 *(.gcc_except_table) *(.gcc_except_table.*)
227 } ${RELOCATING+> ${TEXT_MEMORY}}
228
229 .plt ${RELOCATING-0} :
230 {
231 *(.plt)
232 } ${RELOCATING+> ${TEXT_MEMORY}}
233
234 .jlitab ${RELOCATING-0} :
235 {
236 ${RELOCATING+${JLI_START_TABLE}}
237 jlitab*.o:(.jlitab*) *(.jlitab*)
238 } ${RELOCATING+> ${TEXT_MEMORY}}
239
240 .rodata ${RELOCATING-0} :
241 {
242 *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r.*)}
243 } ${RELOCATING+> ${TEXT_MEMORY}}
244
245 .rodata1 ${RELOCATING-0} : { *(.rodata1) } ${RELOCATING+> ${TEXT_MEMORY}}
246
247 ${RELOCATING+${OTHER_READONLY_SECTIONS}}
248
249 /* Start of the data section image in ROM. */
250 ${RELOCATING+__data_image = .;}
251 ${RELOCATING+PROVIDE (__data_image = .);}
252
253 .data ${RELOCATING-0} :
254 {
255 ${RELOCATING+ PROVIDE (__data_start = .) ; }
256 /* --gc-sections will delete empty .data. This leads to wrong start
257 addresses for subsequent sections because -Tdata= from the command
258 line will have no effect, see PR13697. Thus, keep .data */
259 KEEP (*(.data))
260 ${RELOCATING+${DATA_START_SYMBOLS}}
261 ${RELOCATING+*(.data.* .gnu.linkonce.d.*)}
262 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
263
264 } ${RELOCATING+ > ${DATA_MEMORY}}
265
266 ${GOT}
267 ${RELOCATING+${CTOR}}
268 ${RELOCATING+${DTOR}}
269
270 ${RELOCATING+${SDATA}}
271 ${RELOCATING+${SDATA2}}
272 ${RELOCATING+${SBSS}}
273 ${RELOCATING+${SBSS2}}
274 .bss ${RELOCATING-0} :
275 {
276 ${RELOCATING+*(.dynbss)}
277 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
278 ${RELOCATING+*(COMMON)
279 /* Align here to ensure that the .bss section occupies space up to
280 _end. Align after .bss to ensure correct alignment even if the
281 .bss section disappears because there are no input sections. */
282 . = ALIGN(${ALIGNMENT});}
283 ${RELOCATING+_end = .;}
284 ${RELOCATING+PROVIDE (end = .);}
285 } ${RELOCATING+ > ${DATA_MEMORY}}
286
287 /* Global data not cleared after reset. */
288 .noinit ${RELOCATING-0}:
289 {
290 *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*})
291 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
292 ${RELOCATING+ PROVIDE (__start_heap = .) ; }
293 } ${RELOCATING+ > ${DATA_MEMORY}}
294
295 ${RELOCATING+ PROVIDE (__stack_top = (ORIGIN (${DATA_MEMORY}) + LENGTH (${DATA_MEMORY}) - 1) & -4);}
296 ${RELOCATING+ PROVIDE (__end_heap = ORIGIN (${DATA_MEMORY}) + LENGTH (${DATA_MEMORY}) - 1);}
297
298 .note.gnu.build-id : { *(.note.gnu.build-id) }
299 EOF
300
301 source_sh $srcdir/scripttempl/misc-sections.sc
302 source_sh $srcdir/scripttempl/DWARF.sc
303
304 cat <<EOF
305 /* ARC Extension Sections */
306 .arcextmap 0 : { *(.arcextmap.*) }
307 }
308 EOF
309