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