file make-gas.com was initially added on branch binutils-2_10-branch.
[binutils.git] / ld / mpw-idtmips.c
blob08ddc70393a051a05835df559e5766b98dba17ac
1 /* This file is is generated by a shell script. DO NOT EDIT! */
3 /* Handle embedded relocs for MIPS.
4 Copyright 1994 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 "ldemul.h"
33 #include "ldfile.h"
34 #include "ldmisc.h"
36 static void gldmipsidt_before_parse PARAMS ((void));
37 static void gldmipsidt_after_open PARAMS ((void));
38 static void check_sections PARAMS ((bfd *, asection *, PTR));
39 static void gldmipsidt_after_allocation PARAMS ((void));
40 static char *gldmipsidt_get_script PARAMS ((int *isfile));
42 static void
43 gldmipsidt_before_parse()
45 #ifndef TARGET_ /* I.e., if not generic. */
46 ldfile_output_architecture = bfd_arch_mips;
47 #endif /* not TARGET_ */
50 /* This function is run after all the input files have been opened.
51 We create a .rel.sdata section for each input file with a non zero
52 .sdata section. The BFD backend will fill in these sections with
53 magic numbers which can be used to relocate the data section at run
54 time. This will only do the right thing if all the input files
55 have been compiled using -membedded-pic. */
57 static void
58 gldmipsidt_after_open ()
60 bfd *abfd;
62 if (! command_line.embedded_relocs
63 || link_info.relocateable)
64 return;
66 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
68 asection *datasec;
70 datasec = bfd_get_section_by_name (abfd, ".sdata");
72 /* Note that we assume that the reloc_count field has already
73 been set up. We could call bfd_get_reloc_upper_bound, but
74 that returns the size of a memory buffer rather than a reloc
75 count. We do not want to call bfd_canonicalize_reloc,
76 because although it would always work it would force us to
77 read in the relocs into BFD canonical form, which would waste
78 a significant amount of time and memory. */
79 if (datasec != NULL && datasec->reloc_count > 0)
81 asection *relsec;
83 relsec = bfd_make_section (abfd, ".rel.sdata");
84 if (relsec == NULL
85 || ! bfd_set_section_flags (abfd, relsec,
86 (SEC_ALLOC
87 | SEC_LOAD
88 | SEC_HAS_CONTENTS
89 | SEC_IN_MEMORY))
90 || ! bfd_set_section_alignment (abfd, relsec, 2)
91 || ! bfd_set_section_size (abfd, relsec,
92 datasec->reloc_count * 4))
93 einfo (_("%F%B: can not create .rel.sdata section: %E\n"));
96 /* Double check that all other data sections are empty, as is
97 required for embedded PIC code. */
98 bfd_map_over_sections (abfd, check_sections, (PTR) datasec);
102 /* Check that of the data sections, only the .sdata section has
103 relocs. This is called via bfd_map_over_sections. */
105 static void
106 check_sections (abfd, sec, sdatasec)
107 bfd *abfd;
108 asection *sec;
109 PTR sdatasec;
111 if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
112 && sec != (asection *) sdatasec
113 && sec->reloc_count != 0)
114 einfo (_("%F%X: section %s has relocs; can not use --embedded-relocs\n"),
115 abfd, bfd_get_section_name (abfd, sec));
118 /* This function is called after the section sizes and offsets have
119 been set. If we are generating embedded relocs, it calls a special
120 BFD backend routine to do the work. */
122 static void
123 gldmipsidt_after_allocation ()
125 bfd *abfd;
127 if (! command_line.embedded_relocs
128 || link_info.relocateable)
129 return;
131 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
133 asection *datasec, *relsec;
134 char *errmsg;
136 datasec = bfd_get_section_by_name (abfd, ".sdata");
138 if (datasec == NULL || datasec->reloc_count == 0)
139 continue;
141 relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
142 ASSERT (relsec != NULL);
144 if (! bfd_mips_ecoff_create_embedded_relocs (abfd, &link_info,
145 datasec, relsec,
146 &errmsg))
148 if (errmsg == NULL)
149 einfo (_("%B%X: can not create runtime reloc information: %E\n"),
150 abfd);
151 else
152 einfo (_("%X%B: can not create runtime reloc information: %s\n"),
153 abfd, errmsg);
158 static char *
159 gldmipsidt_get_script(isfile)
160 int *isfile;
162 *isfile = 0;
164 if (link_info.relocateable == true && config.build_constructors == true)
165 return
166 concat(
167 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
168 \"ecoff-littlemips\")\n\
169 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
170 ENTRY(start)\n\
171 SECTIONS\n\
172 {\n\
173 .text : {\n\
174 ;\n\
175 *(.init)\n\
176 ;\n\
177 *(.text)\n\
178 *(.rel.sdata)\n\
179 *(.fini)\n\
180 ;\n\
181 ;\n\
182 }\n\
183 "," .rdata : {\n\
184 *(.rdata)\n\
185 }\n\
186 .data : {\n\
187 *(.data)\n\
188 CONSTRUCTORS\n\
189 }\n\
190 .lit8 : {\n\
191 *(.lit8)\n\
192 }\n\
193 .lit4 : {\n\
194 *(.lit4)\n\
195 }\n\
196 "," .sdata : {\n\
197 *(.sdata)\n\
198 }\n\
199 .sbss : {\n\
200 *(.sbss)\n\
201 *(.scommon)\n\
202 }\n\
203 .bss : {\n\
204 *(.bss)\n\
205 *(COMMON)\n\
206 }\n\
207 }\n\n", NULL)
208 ; else if (link_info.relocateable == true) return
209 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
210 \"ecoff-littlemips\")\n\
211 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
212 ENTRY(start)\n\
213 SECTIONS\n\
214 {\n\
215 .text : {\n\
216 ;\n\
217 *(.init)\n\
218 ;\n\
219 *(.text)\n\
220 *(.rel.sdata)\n\
221 *(.fini)\n\
222 ;\n\
223 ;\n\
224 }\n\
225 .rdata : {\n\
226 *(.rdata)\n\
227 }\n\
228 .data : {\n\
229 *(.data)\n\
230 }\n\
231 .lit8 : {\n\
232 *(.lit8)\n\
233 }\n\
234 .lit4 : {\n\
235 *(.lit4)\n\
236 }\n\
237 .sdata : {\n\
238 *(.sdata)\n\
239 }\n\
240 .sbss : {\n\
241 *(.sbss)\n\
242 *(.scommon)\n\
243 }\n\
244 .bss : {\n\
245 *(.bss)\n\
246 *(COMMON)\n\
247 }\n\
248 }\n\n"
249 ; else if (!config.text_read_only) return
250 concat(
251 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
252 \"ecoff-littlemips\")\n\
253 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
254 ENTRY(start)\n\
255 SECTIONS\n\
256 {\n\
257 . = 0xa0012000;\n\
258 .text : {\n\
259 _ftext = . ;\n\
260 *(.init)\n\
261 eprol = .;\n\
262 *(.text)\n\
263 PROVIDE (__runtime_reloc_start = .);\n\
264 *(.rel.sdata)\n\
265 PROVIDE (__runtime_reloc_stop = .);\n\
266 *(.fini)\n\
267 etext = .;\n\
268 _etext = .;\n\
269 "," }\n\
270 . = .;\n\
271 .rdata : {\n\
272 *(.rdata)\n\
273 }\n\
274 _fdata = ALIGN(16);\n\
275 .data : {\n\
276 *(.data)\n\
277 CONSTRUCTORS\n\
278 }\n\
279 _gp = ALIGN(16) + 0x8000;\n\
280 .lit8 : {\n\
281 *(.lit8)\n\
282 }\n\
283 .lit4 : {\n\
284 *(.lit4)\n\
285 }\n\
286 .sdata : {\n\
287 *(.sdata)\n\
288 }\n\
289 "," edata = .;\n\
290 _edata = .;\n\
291 _fbss = .;\n\
292 .sbss : {\n\
293 *(.sbss)\n\
294 *(.scommon)\n\
295 }\n\
296 .bss : {\n\
297 *(.bss)\n\
298 *(COMMON)\n\
299 }\n\
300 end = .;\n\
301 _end = .;\n\
302 }\n\n"
303 , NULL)
304 ; else if (!config.magic_demand_paged) return
305 concat (
306 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
307 \"ecoff-littlemips\")\n\
308 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
309 ENTRY(start)\n\
310 SECTIONS\n\
311 {\n\
312 . = 0xa0012000;\n\
313 .text : {\n\
314 _ftext = . ;\n\
315 *(.init)\n\
316 eprol = .;\n\
317 *(.text)\n\
318 PROVIDE (__runtime_reloc_start = .);\n\
319 *(.rel.sdata)\n\
320 PROVIDE (__runtime_reloc_stop = .);\n\
321 *(.fini)\n\
322 etext = .;\n\
323 _etext = .;\n\
324 "," }\n\
325 . = .;\n\
326 .rdata : {\n\
327 *(.rdata)\n\
328 }\n\
329 _fdata = ALIGN(16);\n\
330 .data : {\n\
331 *(.data)\n\
332 CONSTRUCTORS\n\
333 }\n\
334 _gp = ALIGN(16) + 0x8000;\n\
335 .lit8 : {\n\
336 *(.lit8)\n\
337 "," }\n\
338 .lit4 : {\n\
339 *(.lit4)\n\
340 }\n\
341 .sdata : {\n\
342 *(.sdata)\n\
343 }\n\
344 edata = .;\n\
345 _edata = .;\n\
346 _fbss = .;\n\
347 .sbss : {\n\
348 *(.sbss)\n\
349 *(.scommon)\n\
350 "," }\n\
351 .bss : {\n\
352 *(.bss)\n\
353 *(COMMON)\n\
354 }\n\
355 end = .;\n\
356 _end = .;\n\
357 }\n\n"
358 , NULL)
359 ; else return
360 concat (
361 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
362 \"ecoff-littlemips\")\n\
363 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
364 ENTRY(start)\n\
365 SECTIONS\n\
366 {\n\
367 . = 0xa0012000;\n\
368 .text : {\n\
369 _ftext = . ;\n\
370 *(.init)\n\
371 eprol = .;\n\
372 *(.text)\n\
373 PROVIDE (__runtime_reloc_start = .);\n\
374 *(.rel.sdata)\n\
375 PROVIDE (__runtime_reloc_stop = .);\n\
376 *(.fini)\n\
377 etext = .;\n\
378 _etext = .;\n\
379 "," }\n\
380 . = .;\n\
381 .rdata : {\n\
382 *(.rdata)\n\
383 }\n\
384 _fdata = ALIGN(16);\n\
385 .data : {\n\
386 *(.data)\n\
387 CONSTRUCTORS\n\
388 }\n\
389 _gp = ALIGN(16) + 0x8000;\n\
390 .lit8 : {\n\
391 *(.lit8)\n\
392 }\n\
393 .lit4 : {\n\
394 *(.lit4)\n\
395 "," }\n\
396 .sdata : {\n\
397 *(.sdata)\n\
398 }\n\
399 edata = .;\n\
400 _edata = .;\n\
401 _fbss = .;\n\
402 .sbss : {\n\
403 *(.sbss)\n\
404 *(.scommon)\n\
405 }\n\
406 .bss : {\n\
407 *(.bss)\n\
408 *(COMMON)\n\
409 }\n\
410 end = .;\n\
411 _end = .;\n\
412 }\n\n"
413 , NULL)
416 struct ld_emulation_xfer_struct ld_mipsidt_emulation =
418 gldmipsidt_before_parse,
419 syslib_default,
420 hll_default,
421 after_parse_default,
422 gldmipsidt_after_open,
423 gldmipsidt_after_allocation,
424 set_output_arch_default,
425 ldemul_default_target,
426 before_allocation_default,
427 gldmipsidt_get_script,
428 "mipsidt",
429 "ecoff-bigmips"