2001-01-03 Philip Blundell <pb@futuretv.com>
[binutils.git] / ld / mpw-idtmips.c
blob69b91ac3b956669df9371fef8e1cb9970aacdd0e
1 /* This file is is generated by a shell script. DO NOT EDIT! */
3 /* Handle embedded relocs for MIPS.
4 Copyright 1994, 2000 Free Software Foundation, Inc.
5 Written by Ian Lance Taylor <ian@cygnus.com> based on generic.em.
7 This file is part of GLD, the Gnu Linker.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #define TARGET_IS_mipsidt
25 #include "libiberty.h"
26 #include "bfd.h"
27 #include "sysdep.h"
28 #include "bfdlink.h"
30 #include "ld.h"
31 #include "ldmain.h"
32 #include "ldmisc.h"
34 #include "ldexp.h"
35 #include "ldlang.h"
36 #include "ldfile.h"
37 #include "ldemul.h"
39 static void gldmipsidt_before_parse PARAMS ((void));
40 static void gldmipsidt_after_open PARAMS ((void));
41 static void check_sections PARAMS ((bfd *, asection *, PTR));
42 static void gldmipsidt_after_allocation PARAMS ((void));
43 static char *gldmipsidt_get_script PARAMS ((int *isfile));
45 static void
46 gldmipsidt_before_parse()
48 #ifndef TARGET_ /* I.e., if not generic. */
49 ldfile_output_architecture = bfd_arch_mips;
50 #endif /* not TARGET_ */
53 /* This function is run after all the input files have been opened.
54 We create a .rel.sdata section for each input file with a non zero
55 .sdata section. The BFD backend will fill in these sections with
56 magic numbers which can be used to relocate the data section at run
57 time. This will only do the right thing if all the input files
58 have been compiled using -membedded-pic. */
60 static void
61 gldmipsidt_after_open ()
63 bfd *abfd;
65 if (! command_line.embedded_relocs
66 || link_info.relocateable)
67 return;
69 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
71 asection *datasec;
73 datasec = bfd_get_section_by_name (abfd, ".sdata");
75 /* Note that we assume that the reloc_count field has already
76 been set up. We could call bfd_get_reloc_upper_bound, but
77 that returns the size of a memory buffer rather than a reloc
78 count. We do not want to call bfd_canonicalize_reloc,
79 because although it would always work it would force us to
80 read in the relocs into BFD canonical form, which would waste
81 a significant amount of time and memory. */
82 if (datasec != NULL && datasec->reloc_count > 0)
84 asection *relsec;
86 relsec = bfd_make_section (abfd, ".rel.sdata");
87 if (relsec == NULL
88 || ! bfd_set_section_flags (abfd, relsec,
89 (SEC_ALLOC
90 | SEC_LOAD
91 | SEC_HAS_CONTENTS
92 | SEC_IN_MEMORY))
93 || ! bfd_set_section_alignment (abfd, relsec, 2)
94 || ! bfd_set_section_size (abfd, relsec,
95 datasec->reloc_count * 4))
96 einfo (_("%F%B: can not create .rel.sdata section: %E\n"));
99 /* Double check that all other data sections are empty, as is
100 required for embedded PIC code. */
101 bfd_map_over_sections (abfd, check_sections, (PTR) datasec);
105 /* Check that of the data sections, only the .sdata section has
106 relocs. This is called via bfd_map_over_sections. */
108 static void
109 check_sections (abfd, sec, sdatasec)
110 bfd *abfd;
111 asection *sec;
112 PTR sdatasec;
114 if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
115 && sec != (asection *) sdatasec
116 && sec->reloc_count != 0)
117 einfo (_("%F%X: section %s has relocs; can not use --embedded-relocs\n"),
118 abfd, bfd_get_section_name (abfd, sec));
121 /* This function is called after the section sizes and offsets have
122 been set. If we are generating embedded relocs, it calls a special
123 BFD backend routine to do the work. */
125 static void
126 gldmipsidt_after_allocation ()
128 bfd *abfd;
130 if (! command_line.embedded_relocs
131 || link_info.relocateable)
132 return;
134 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
136 asection *datasec, *relsec;
137 char *errmsg;
139 datasec = bfd_get_section_by_name (abfd, ".sdata");
141 if (datasec == NULL || datasec->reloc_count == 0)
142 continue;
144 relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
145 ASSERT (relsec != NULL);
147 if (! bfd_mips_ecoff_create_embedded_relocs (abfd, &link_info,
148 datasec, relsec,
149 &errmsg))
151 if (errmsg == NULL)
152 einfo (_("%B%X: can not create runtime reloc information: %E\n"),
153 abfd);
154 else
155 einfo (_("%X%B: can not create runtime reloc information: %s\n"),
156 abfd, errmsg);
161 static char *
162 gldmipsidt_get_script(isfile)
163 int *isfile;
165 *isfile = 0;
167 if (link_info.relocateable == true && config.build_constructors == true)
168 return
169 concat(
170 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
171 \"ecoff-littlemips\")\n\
172 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
173 ENTRY(start)\n\
174 SECTIONS\n\
175 {\n\
176 .text : {\n\
177 ;\n\
178 *(.init)\n\
179 ;\n\
180 *(.text)\n\
181 *(.rel.sdata)\n\
182 *(.fini)\n\
183 ;\n\
184 ;\n\
185 }\n\
186 "," .rdata : {\n\
187 *(.rdata)\n\
188 }\n\
189 .data : {\n\
190 *(.data)\n\
191 CONSTRUCTORS\n\
192 }\n\
193 .lit8 : {\n\
194 *(.lit8)\n\
195 }\n\
196 .lit4 : {\n\
197 *(.lit4)\n\
198 }\n\
199 "," .sdata : {\n\
200 *(.sdata)\n\
201 }\n\
202 .sbss : {\n\
203 *(.sbss)\n\
204 *(.scommon)\n\
205 }\n\
206 .bss : {\n\
207 *(.bss)\n\
208 *(COMMON)\n\
209 }\n\
210 }\n\n", NULL)
211 ; else if (link_info.relocateable == true) return
212 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
213 \"ecoff-littlemips\")\n\
214 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
215 ENTRY(start)\n\
216 SECTIONS\n\
217 {\n\
218 .text : {\n\
219 ;\n\
220 *(.init)\n\
221 ;\n\
222 *(.text)\n\
223 *(.rel.sdata)\n\
224 *(.fini)\n\
225 ;\n\
226 ;\n\
227 }\n\
228 .rdata : {\n\
229 *(.rdata)\n\
230 }\n\
231 .data : {\n\
232 *(.data)\n\
233 }\n\
234 .lit8 : {\n\
235 *(.lit8)\n\
236 }\n\
237 .lit4 : {\n\
238 *(.lit4)\n\
239 }\n\
240 .sdata : {\n\
241 *(.sdata)\n\
242 }\n\
243 .sbss : {\n\
244 *(.sbss)\n\
245 *(.scommon)\n\
246 }\n\
247 .bss : {\n\
248 *(.bss)\n\
249 *(COMMON)\n\
250 }\n\
251 }\n\n"
252 ; else if (!config.text_read_only) return
253 concat(
254 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
255 \"ecoff-littlemips\")\n\
256 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
257 ENTRY(start)\n\
258 SECTIONS\n\
259 {\n\
260 . = 0xa0012000;\n\
261 .text : {\n\
262 _ftext = . ;\n\
263 *(.init)\n\
264 eprol = .;\n\
265 *(.text)\n\
266 PROVIDE (__runtime_reloc_start = .);\n\
267 *(.rel.sdata)\n\
268 PROVIDE (__runtime_reloc_stop = .);\n\
269 *(.fini)\n\
270 etext = .;\n\
271 _etext = .;\n\
272 "," }\n\
273 . = .;\n\
274 .rdata : {\n\
275 *(.rdata)\n\
276 }\n\
277 _fdata = ALIGN(16);\n\
278 .data : {\n\
279 *(.data)\n\
280 CONSTRUCTORS\n\
281 }\n\
282 _gp = ALIGN(16) + 0x8000;\n\
283 .lit8 : {\n\
284 *(.lit8)\n\
285 }\n\
286 .lit4 : {\n\
287 *(.lit4)\n\
288 }\n\
289 .sdata : {\n\
290 *(.sdata)\n\
291 }\n\
292 "," edata = .;\n\
293 _edata = .;\n\
294 _fbss = .;\n\
295 .sbss : {\n\
296 *(.sbss)\n\
297 *(.scommon)\n\
298 }\n\
299 .bss : {\n\
300 *(.bss)\n\
301 *(COMMON)\n\
302 }\n\
303 end = .;\n\
304 _end = .;\n\
305 }\n\n"
306 , NULL)
307 ; else if (!config.magic_demand_paged) return
308 concat (
309 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
310 \"ecoff-littlemips\")\n\
311 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
312 ENTRY(start)\n\
313 SECTIONS\n\
314 {\n\
315 . = 0xa0012000;\n\
316 .text : {\n\
317 _ftext = . ;\n\
318 *(.init)\n\
319 eprol = .;\n\
320 *(.text)\n\
321 PROVIDE (__runtime_reloc_start = .);\n\
322 *(.rel.sdata)\n\
323 PROVIDE (__runtime_reloc_stop = .);\n\
324 *(.fini)\n\
325 etext = .;\n\
326 _etext = .;\n\
327 "," }\n\
328 . = .;\n\
329 .rdata : {\n\
330 *(.rdata)\n\
331 }\n\
332 _fdata = ALIGN(16);\n\
333 .data : {\n\
334 *(.data)\n\
335 CONSTRUCTORS\n\
336 }\n\
337 _gp = ALIGN(16) + 0x8000;\n\
338 .lit8 : {\n\
339 *(.lit8)\n\
340 "," }\n\
341 .lit4 : {\n\
342 *(.lit4)\n\
343 }\n\
344 .sdata : {\n\
345 *(.sdata)\n\
346 }\n\
347 edata = .;\n\
348 _edata = .;\n\
349 _fbss = .;\n\
350 .sbss : {\n\
351 *(.sbss)\n\
352 *(.scommon)\n\
353 "," }\n\
354 .bss : {\n\
355 *(.bss)\n\
356 *(COMMON)\n\
357 }\n\
358 end = .;\n\
359 _end = .;\n\
360 }\n\n"
361 , NULL)
362 ; else return
363 concat (
364 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
365 \"ecoff-littlemips\")\n\
366 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
367 ENTRY(start)\n\
368 SECTIONS\n\
369 {\n\
370 . = 0xa0012000;\n\
371 .text : {\n\
372 _ftext = . ;\n\
373 *(.init)\n\
374 eprol = .;\n\
375 *(.text)\n\
376 PROVIDE (__runtime_reloc_start = .);\n\
377 *(.rel.sdata)\n\
378 PROVIDE (__runtime_reloc_stop = .);\n\
379 *(.fini)\n\
380 etext = .;\n\
381 _etext = .;\n\
382 "," }\n\
383 . = .;\n\
384 .rdata : {\n\
385 *(.rdata)\n\
386 }\n\
387 _fdata = ALIGN(16);\n\
388 .data : {\n\
389 *(.data)\n\
390 CONSTRUCTORS\n\
391 }\n\
392 _gp = ALIGN(16) + 0x8000;\n\
393 .lit8 : {\n\
394 *(.lit8)\n\
395 }\n\
396 .lit4 : {\n\
397 *(.lit4)\n\
398 "," }\n\
399 .sdata : {\n\
400 *(.sdata)\n\
401 }\n\
402 edata = .;\n\
403 _edata = .;\n\
404 _fbss = .;\n\
405 .sbss : {\n\
406 *(.sbss)\n\
407 *(.scommon)\n\
408 }\n\
409 .bss : {\n\
410 *(.bss)\n\
411 *(COMMON)\n\
412 }\n\
413 end = .;\n\
414 _end = .;\n\
415 }\n\n"
416 , NULL)
419 struct ld_emulation_xfer_struct ld_mipsidt_emulation =
421 gldmipsidt_before_parse,
422 syslib_default,
423 hll_default,
424 after_parse_default,
425 gldmipsidt_after_open,
426 gldmipsidt_after_allocation,
427 set_output_arch_default,
428 ldemul_default_target,
429 before_allocation_default,
430 gldmipsidt_get_script,
431 "mipsidt",
432 "ecoff-bigmips"