Commit | Line | Data |
---|---|---|
1f29e30b JG |
1 | /* BFD back-end for MIPS Extended-Coff files. |
2 | Copyright 1990, 1991, 1992 Free Software Foundation, Inc. | |
8fa0d3a0 ILT |
3 | Original version by Per Bothner. |
4 | Full support by Ian Lance Taylor, ian@cygnus.com. | |
1327fb29 | 5 | |
68b70212 | 6 | This file is part of BFD, the Binary File Descriptor library. |
23b0b558 | 7 | |
68b70212 | 8 | This program is free software; you can redistribute it and/or modify |
23b0b558 | 9 | it under the terms of the GNU General Public License as published by |
68b70212 JG |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. | |
23b0b558 | 12 | |
68b70212 | 13 | This program is distributed in the hope that it will be useful, |
23b0b558 JG |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
68b70212 JG |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
1327fb29 | 21 | |
23b0b558 | 22 | #include "bfd.h" |
dd4646ca | 23 | #include "sysdep.h" |
1327fb29 | 24 | #include "libbfd.h" |
8fa0d3a0 | 25 | #include "seclet.h" |
294eaca4 SC |
26 | #include "coff/mips.h" |
27 | #include "coff/internal.h" | |
515c4292 ILT |
28 | #include "coff/sym.h" |
29 | #include "coff/symconst.h" | |
30 | #include "coff/ecoff-ext.h" | |
31 | #include "libcoff.h" | |
32 | ||
33 | /* `Tdata' information kept for ECOFF files. */ | |
34 | ||
35 | #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data) | |
36 | ||
37 | typedef struct ecoff_tdata | |
38 | { | |
8fa0d3a0 ILT |
39 | /* The reloc file position, set by |
40 | ecoff_compute_section_file_positions. */ | |
41 | file_ptr reloc_filepos; | |
42 | ||
43 | /* The symbol table file position, set by ecoff_mkobject_hook. */ | |
515c4292 ILT |
44 | file_ptr sym_filepos; |
45 | ||
8fa0d3a0 ILT |
46 | /* The size of the unswapped ECOFF symbolic information. */ |
47 | bfd_size_type raw_size; | |
48 | ||
515c4292 ILT |
49 | /* The unswapped ECOFF symbolic information. */ |
50 | PTR raw_syments; | |
51 | ||
52 | /* The swapped ECOFF symbolic header. */ | |
53 | HDRR symbolic_header; | |
54 | ||
55 | /* Pointers to the unswapped symbolic information. */ | |
56 | unsigned char *line; | |
57 | struct dnr_ext *external_dnr; | |
58 | struct pdr_ext *external_pdr; | |
59 | struct sym_ext *external_sym; | |
60 | struct opt_ext *external_opt; | |
61 | union aux_ext *external_aux; | |
62 | char *ss; | |
63 | char *ssext; | |
64 | struct fdr_ext *external_fdr; | |
65 | struct rfd_ext *external_rfd; | |
66 | struct ext_ext *external_ext; | |
67 | ||
68 | /* The swapped fdr information. */ | |
69 | FDR *fdr; | |
70 | ||
71 | /* The canonical BFD symbols. */ | |
72 | struct ecoff_symbol_struct *canonical_symbols; | |
73 | ||
74 | } ecoff_data_type; | |
75 | ||
76 | /* Each canonical asymbol really looks like this. */ | |
77 | ||
78 | typedef struct ecoff_symbol_struct | |
79 | { | |
80 | /* The actual symbol which the rest of BFD works with */ | |
81 | asymbol symbol; | |
82 | ||
83 | /* The fdr for this symbol. */ | |
84 | FDR *fdr; | |
85 | ||
86 | /* true if this is a local symbol rather than an external one. */ | |
87 | boolean local; | |
88 | ||
89 | /* A pointer to the unswapped hidden information for this symbol */ | |
90 | union | |
91 | { | |
92 | struct sym_ext *lnative; | |
93 | struct ext_ext *enative; | |
94 | } | |
95 | native; | |
96 | } ecoff_symbol_type; | |
97 | ||
98 | /* We take the address of the first element of a asymbol to ensure that the | |
99 | macro is only ever applied to an asymbol. */ | |
100 | #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd))) | |
101 | ||
102 | /* MIPS ECOFF has COFF sections, but the debugging information is | |
103 | stored in a completely different format. This files uses the some | |
104 | of the swapping routines from coffswap.h, and some of the generic | |
105 | COFF routines in coffgen.c, but, unlike the real COFF targets, does | |
106 | not use coffcode.h itself. */ | |
107 | ||
8fa0d3a0 ILT |
108 | /* Get the generic COFF swapping routines, except for the reloc, |
109 | symbol, and lineno ones. Give them ecoff names. */ | |
110 | #define NO_COFF_RELOCS | |
515c4292 ILT |
111 | #define NO_COFF_SYMBOLS |
112 | #define NO_COFF_LINENOS | |
515c4292 ILT |
113 | #define coff_swap_filehdr_in ecoff_swap_filehdr_in |
114 | #define coff_swap_filehdr_out ecoff_swap_filehdr_out | |
115 | #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in | |
116 | #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out | |
117 | #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in | |
118 | #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out | |
119 | #include "coffswap.h" | |
120 | \f | |
121 | /* This stuff is somewhat copied from coffcode.h. */ | |
122 | ||
123 | static asection bfd_debug_section = { "*DEBUG*" }; | |
124 | ||
125 | /* See whether the magic number matches. */ | |
126 | ||
127 | static boolean | |
128 | DEFUN(ecoff_bad_format_hook, (abfd, filehdr), | |
129 | bfd *abfd AND | |
130 | PTR filehdr) | |
131 | { | |
132 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
133 | ||
134 | if (ECOFFBADMAG (*internal_f)) | |
135 | return false; | |
136 | ||
137 | return true; | |
138 | } | |
139 | ||
140 | /* This is a hook needed by SCO COFF, but we have nothing to do. */ | |
141 | ||
142 | static asection * | |
143 | DEFUN (ecoff_make_section_hook, (abfd, name), | |
144 | bfd *abfd AND | |
145 | char *name) | |
146 | { | |
147 | return (asection *) NULL; | |
148 | } | |
149 | ||
150 | /* Initialize a new section. */ | |
151 | ||
152 | static boolean | |
153 | DEFUN (ecoff_new_section_hook, (abfd, section), | |
154 | bfd *abfd AND | |
155 | asection *section) | |
156 | { | |
157 | section->alignment_power = abfd->xvec->align_power_min; | |
8fa0d3a0 ILT |
158 | |
159 | if (strcmp (section->name, _TEXT) == 0) | |
160 | section->flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC; | |
161 | else if (strcmp (section->name, _DATA) == 0 | |
162 | || strcmp (section->name, _SDATA) == 0) | |
163 | section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC; | |
164 | else if (strcmp (section->name, _RDATA) == 0 | |
165 | || strcmp (section->name, _LIT8) == 0 | |
166 | || strcmp (section->name, _LIT4) == 0) | |
167 | section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY; | |
168 | else if (strcmp (section->name, _BSS) == 0 | |
169 | || strcmp (section->name, _SBSS) == 0) | |
170 | section->flags |= SEC_ALLOC; | |
171 | ||
172 | /* Probably any other section name is SEC_NEVER_LOAD, but I'm | |
173 | uncertain about .init on some systems and I don't know how shared | |
174 | libraries work. */ | |
175 | ||
515c4292 ILT |
176 | return true; |
177 | } | |
178 | ||
179 | #define ecoff_set_alignment_hook \ | |
180 | ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void) | |
181 | ||
182 | static boolean | |
183 | DEFUN (ecoff_mkobject, (abfd), | |
184 | bfd *abfd) | |
185 | { | |
186 | abfd->tdata.ecoff_obj_data = ((struct ecoff_tdata *) | |
187 | bfd_zalloc (abfd, sizeof(ecoff_data_type))); | |
188 | if (abfd->tdata.ecoff_obj_data == NULL) | |
189 | { | |
190 | bfd_error = no_memory; | |
191 | return false; | |
192 | } | |
193 | ||
194 | return true; | |
195 | } | |
196 | ||
197 | /* Create the COFF backend specific information. */ | |
198 | ||
199 | static PTR | |
200 | DEFUN(ecoff_mkobject_hook,(abfd, filehdr), | |
201 | bfd *abfd AND | |
202 | PTR filehdr) | |
203 | { | |
204 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
205 | ecoff_data_type *ecoff; | |
206 | ||
207 | if (ecoff_mkobject (abfd) == false) | |
208 | return NULL; | |
209 | ||
210 | ecoff = ecoff_data (abfd); | |
211 | ecoff->sym_filepos = internal_f->f_symptr; | |
212 | return (PTR) ecoff; | |
213 | } | |
214 | ||
215 | /* Determine the machine architecture and type. */ | |
216 | static boolean | |
217 | DEFUN (ecoff_set_arch_mach_hook, (abfd, filehdr), | |
218 | bfd *abfd AND | |
219 | PTR filehdr) | |
220 | { | |
221 | long machine; | |
222 | enum bfd_architecture arch; | |
223 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
224 | ||
225 | machine = 0; | |
226 | switch (internal_f->f_magic) { | |
227 | case MIPS_MAGIC_1: | |
228 | case MIPS_MAGIC_2: | |
229 | case MIPS_MAGIC_3: | |
230 | arch = bfd_arch_mips; | |
231 | machine = 0; | |
232 | break; | |
233 | ||
234 | default: /* Unreadable input file type */ | |
235 | arch = bfd_arch_obscure; | |
236 | break; | |
237 | } | |
238 | ||
239 | bfd_default_set_arch_mach(abfd, arch, machine); | |
240 | return true; | |
241 | } | |
242 | ||
8fa0d3a0 ILT |
243 | /* Get the section s_flags to use for a section. */ |
244 | ||
245 | static long | |
246 | DEFUN (sec_to_styp_flags, (name, flags), | |
247 | CONST char *name AND | |
248 | flagword flags) | |
249 | { | |
250 | long styp; | |
251 | ||
252 | styp = 0; | |
253 | ||
254 | if (strcmp (name, _TEXT) == 0) | |
255 | styp = STYP_TEXT; | |
256 | else if (strcmp (name, _DATA) == 0) | |
257 | styp == STYP_DATA; | |
258 | else if (strcmp (name, _SDATA) == 0) | |
259 | styp == STYP_SDATA; | |
260 | else if (strcmp (name, _RDATA) == 0) | |
261 | styp = STYP_RDATA; | |
262 | else if (strcmp (name, _LIT8) == 0) | |
263 | styp = STYP_LIT8; | |
264 | else if (strcmp (name, _LIT4) == 0) | |
265 | styp = STYP_LIT4; | |
266 | else if (strcmp (name, _BSS) == 0) | |
267 | styp = STYP_BSS; | |
268 | else if (strcmp (name, _SBSS) == 0) | |
269 | styp = STYP_SBSS; | |
270 | else if (flags & SEC_CODE) | |
271 | styp = STYP_TEXT; | |
272 | else if (flags & SEC_DATA) | |
273 | styp = STYP_DATA; | |
274 | else if (flags & SEC_READONLY) | |
275 | styp = STYP_RDATA; | |
276 | else if (flags & SEC_LOAD) | |
277 | styp = STYP_TEXT; | |
278 | else | |
279 | styp = STYP_BSS; | |
280 | ||
281 | if (flags & SEC_NEVER_LOAD) | |
282 | styp |= STYP_NOLOAD; | |
283 | ||
284 | return styp; | |
285 | } | |
286 | ||
515c4292 ILT |
287 | /* Get the BFD flags to use for a section. */ |
288 | ||
289 | static flagword | |
8fa0d3a0 ILT |
290 | DEFUN (styp_to_sec_flags, (abfd, hdr), |
291 | bfd *abfd AND | |
292 | PTR hdr) | |
515c4292 ILT |
293 | { |
294 | struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr; | |
295 | long styp_flags = internal_s->s_flags; | |
296 | flagword sec_flags=0; | |
297 | ||
298 | if (styp_flags & STYP_NOLOAD) | |
299 | sec_flags |= SEC_NEVER_LOAD; | |
300 | ||
301 | /* For 386 COFF, at least, an unloadable text or data section is | |
302 | actually a shared library section. */ | |
303 | if (styp_flags & STYP_TEXT) | |
304 | { | |
305 | if (sec_flags & SEC_NEVER_LOAD) | |
306 | sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY; | |
307 | else | |
308 | sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC; | |
309 | } | |
310 | else if ((styp_flags & STYP_DATA) | |
311 | || (styp_flags & STYP_RDATA) | |
312 | || (styp_flags & STYP_SDATA)) | |
313 | { | |
314 | if (sec_flags & SEC_NEVER_LOAD) | |
315 | sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY; | |
316 | else | |
317 | sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC; | |
318 | if (styp_flags & STYP_RDATA) | |
319 | sec_flags |= SEC_READONLY; | |
320 | } | |
321 | else if ((styp_flags & STYP_BSS) | |
322 | || (styp_flags & STYP_SBSS)) | |
323 | { | |
324 | sec_flags |= SEC_ALLOC; | |
325 | } | |
326 | else if (styp_flags & STYP_INFO) | |
327 | { | |
328 | sec_flags |= SEC_NEVER_LOAD; | |
329 | } | |
330 | else if ((styp_flags & STYP_LIT8) | |
331 | || (styp_flags & STYP_LIT4)) | |
332 | { | |
333 | sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY; | |
334 | } | |
335 | else | |
336 | { | |
337 | sec_flags |= SEC_ALLOC | SEC_LOAD; | |
338 | } | |
339 | ||
340 | return sec_flags; | |
341 | } | |
342 | \f | |
8fa0d3a0 ILT |
343 | /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in |
344 | external form. They use a bit which indicates whether the symbol | |
345 | is external. */ | |
346 | ||
347 | /* Swap a reloc in. */ | |
348 | ||
349 | static void | |
350 | DEFUN (ecoff_swap_reloc_in, (abfd, ext, intern), | |
351 | bfd *abfd AND | |
352 | RELOC *ext AND | |
353 | struct internal_reloc *intern) | |
354 | { | |
355 | intern->r_vaddr = bfd_h_get_32 (abfd, (bfd_byte *) ext->r_vaddr); | |
356 | if (abfd->xvec->header_byteorder_big_p != false) | |
357 | { | |
358 | intern->r_symndx = ((ext->r_bits[0] | |
359 | << RELOC_BITS0_SYMNDX_SH_LEFT_BIG) | |
360 | | (ext->r_bits[1] | |
361 | << RELOC_BITS1_SYMNDX_SH_LEFT_BIG) | |
362 | | (ext->r_bits[2] | |
363 | << RELOC_BITS2_SYMNDX_SH_LEFT_BIG)); | |
364 | intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_BIG) | |
365 | >> RELOC_BITS3_TYPE_SH_BIG); | |
366 | intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_BIG) != 0; | |
367 | } | |
368 | else | |
369 | { | |
370 | intern->r_symndx = ((ext->r_bits[0] | |
371 | << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE) | |
372 | | (ext->r_bits[1] | |
373 | << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE) | |
374 | | (ext->r_bits[2] | |
375 | << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE)); | |
376 | intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_LITTLE) | |
377 | >> RELOC_BITS3_TYPE_SH_LITTLE); | |
378 | intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_LITTLE) != 0; | |
379 | } | |
380 | } | |
381 | ||
382 | /* Swap a reloc out. */ | |
383 | ||
384 | static unsigned int | |
385 | DEFUN (ecoff_swap_reloc_out, (abfd, src, dst), | |
386 | bfd *abfd AND | |
387 | PTR src AND | |
388 | PTR dst) | |
389 | { | |
390 | struct internal_reloc *intern = (struct internal_reloc *) src; | |
391 | RELOC *ext = (RELOC *) dst; | |
392 | ||
393 | bfd_h_put_32 (abfd, intern->r_vaddr, (bfd_byte *) ext->r_vaddr); | |
394 | if (abfd->xvec->header_byteorder_big_p != false) | |
395 | { | |
396 | ext->r_bits[0] = intern->r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_BIG; | |
397 | ext->r_bits[1] = intern->r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_BIG; | |
398 | ext->r_bits[2] = intern->r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_BIG; | |
399 | ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_BIG) | |
400 | & RELOC_BITS3_TYPE_BIG) | |
401 | | (intern->r_extern ? RELOC_BITS3_EXTERN_BIG : 0)); | |
402 | } | |
403 | else | |
404 | { | |
405 | ext->r_bits[0] = intern->r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE; | |
406 | ext->r_bits[1] = intern->r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE; | |
407 | ext->r_bits[2] = intern->r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE; | |
408 | ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_LITTLE) | |
409 | & RELOC_BITS3_TYPE_LITTLE) | |
410 | | (intern->r_extern ? RELOC_BITS3_EXTERN_LITTLE : 0)); | |
411 | } | |
412 | ||
413 | return RELSZ; | |
414 | } | |
415 | \f | |
416 | /* Read in and swap the important symbolic information for an ECOFF | |
417 | object file. */ | |
418 | ||
419 | static boolean | |
420 | DEFUN (ecoff_slurp_symbolic_info, (abfd), | |
421 | bfd *abfd) | |
422 | { | |
423 | struct hdr_ext external_symhdr; | |
424 | HDRR *internal_symhdr; | |
425 | bfd_size_type raw_base; | |
426 | bfd_size_type raw_size; | |
427 | PTR raw; | |
428 | struct fdr_ext *fraw_src; | |
429 | struct fdr_ext *fraw_end; | |
430 | struct fdr *fdr_ptr; | |
431 | ||
432 | /* Check whether we've already gotten it, and whether there's any to | |
433 | get. */ | |
434 | if (ecoff_data (abfd)->raw_syments != (PTR) NULL) | |
435 | return true; | |
436 | if (ecoff_data (abfd)->sym_filepos == 0) | |
437 | { | |
438 | bfd_get_symcount (abfd) = 0; | |
439 | return true; | |
440 | } | |
441 | ||
442 | /* At this point bfd_get_symcount (abfd) holds the number of symbols | |
443 | as read from the file header, but on ECOFF this is always the | |
444 | size of the symbolic information header. It would be cleaner to | |
445 | handle this when we first read the file in coffgen.c. */ | |
446 | if (bfd_get_symcount (abfd) != sizeof (external_symhdr)) | |
447 | { | |
448 | bfd_error = bad_value; | |
449 | return false; | |
450 | } | |
451 | ||
452 | /* Read the symbolic information header. */ | |
453 | if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1 | |
454 | || (bfd_read ((PTR) &external_symhdr, sizeof (external_symhdr), 1, abfd) | |
455 | != sizeof (external_symhdr))) | |
456 | { | |
457 | bfd_error = system_call_error; | |
458 | return false; | |
459 | } | |
460 | internal_symhdr = &ecoff_data (abfd)->symbolic_header; | |
461 | ecoff_swap_hdr_in (abfd, &external_symhdr, internal_symhdr); | |
462 | ||
463 | if (internal_symhdr->magic != magicSym) | |
464 | { | |
465 | bfd_error = bad_value; | |
466 | return false; | |
467 | } | |
468 | ||
469 | /* Now we can get the correct number of symbols. */ | |
470 | bfd_get_symcount (abfd) = (internal_symhdr->isymMax | |
471 | + internal_symhdr->iextMax); | |
472 | ||
473 | /* Read all the symbolic information at once. This expression | |
474 | assumes that the external symbols are always the last item. */ | |
475 | raw_base = ecoff_data (abfd)->sym_filepos + sizeof (external_symhdr); | |
476 | raw_size = (internal_symhdr->cbExtOffset - raw_base | |
477 | + internal_symhdr->iextMax * sizeof (struct ext_ext)); | |
478 | raw = (PTR) bfd_alloc (abfd, raw_size); | |
479 | if (raw == NULL) | |
480 | { | |
481 | bfd_error = no_memory; | |
482 | return false; | |
483 | } | |
484 | if (bfd_read (raw, raw_size, 1, abfd) != raw_size) | |
485 | { | |
486 | bfd_error = system_call_error; | |
487 | bfd_release (abfd, raw); | |
488 | return false; | |
489 | } | |
490 | ||
491 | ecoff_data (abfd)->raw_size = raw_size; | |
492 | ecoff_data (abfd)->raw_syments = raw; | |
493 | ||
494 | /* Get pointers for the numeric offsets in the HDRR structure. */ | |
495 | #define FIX(off1, off2, type) \ | |
496 | if (internal_symhdr->off1 == 0) \ | |
497 | ecoff_data (abfd)->off2 = (type *) NULL; \ | |
498 | else \ | |
499 | ecoff_data (abfd)->off2 = (type *) ((char *) raw \ | |
500 | + internal_symhdr->off1 \ | |
501 | - raw_base) | |
502 | FIX (cbLineOffset, line, unsigned char); | |
503 | FIX (cbDnOffset, external_dnr, struct dnr_ext); | |
504 | FIX (cbPdOffset, external_pdr, struct pdr_ext); | |
505 | FIX (cbSymOffset, external_sym, struct sym_ext); | |
506 | FIX (cbOptOffset, external_opt, struct opt_ext); | |
507 | FIX (cbAuxOffset, external_aux, union aux_ext); | |
508 | FIX (cbSsOffset, ss, char); | |
509 | FIX (cbSsExtOffset, ssext, char); | |
510 | FIX (cbFdOffset, external_fdr, struct fdr_ext); | |
511 | FIX (cbRfdOffset, external_rfd, struct rfd_ext); | |
512 | FIX (cbExtOffset, external_ext, struct ext_ext); | |
513 | #undef FIX | |
514 | ||
515 | /* I don't want to always swap all the data, because it will just | |
516 | waste time and most programs will never look at it. The only | |
517 | time the linker needs most of the debugging information swapped | |
518 | is when linking big-endian and little-endian MIPS object files | |
519 | together, which is not a common occurrence. | |
520 | ||
521 | We need to look at the fdr to deal with a lot of information in | |
522 | the symbols, so we swap them here. */ | |
523 | ecoff_data (abfd)->fdr = (struct fdr *) bfd_alloc (abfd, | |
524 | (internal_symhdr->ifdMax * | |
525 | sizeof (struct fdr))); | |
526 | if (ecoff_data (abfd)->fdr == NULL) | |
527 | { | |
528 | bfd_error = no_memory; | |
529 | return false; | |
530 | } | |
531 | fdr_ptr = ecoff_data (abfd)->fdr; | |
532 | fraw_src = ecoff_data (abfd)->external_fdr; | |
533 | fraw_end = fraw_src + internal_symhdr->ifdMax; | |
534 | for (; fraw_src < fraw_end; fraw_src++, fdr_ptr++) | |
535 | ecoff_swap_fdr_in (abfd, fraw_src, fdr_ptr); | |
536 | ||
537 | return true; | |
538 | } | |
539 | \f | |
515c4292 ILT |
540 | /* ECOFF symbol table routines. The ECOFF symbol table is described |
541 | in gcc/mips-tfile.c. */ | |
542 | ||
543 | /* Create an empty symbol. */ | |
544 | ||
545 | static asymbol * | |
546 | DEFUN (ecoff_make_empty_symbol, (abfd), | |
547 | bfd *abfd) | |
548 | { | |
549 | ecoff_symbol_type *new; | |
550 | ||
551 | new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type)); | |
552 | if (new == (ecoff_symbol_type *) NULL) | |
553 | { | |
554 | bfd_error = no_memory; | |
555 | return (asymbol *) NULL; | |
556 | } | |
557 | new->symbol.section = (asection *) NULL; | |
558 | new->fdr = (FDR *) NULL; | |
559 | new->local = false; | |
560 | new->native.lnative = (struct sym_ext *) NULL; | |
561 | new->symbol.the_bfd = abfd; | |
562 | return &new->symbol; | |
563 | } | |
564 | ||
565 | /* Set the BFD flags and section for an ECOFF symbol. */ | |
566 | ||
567 | static void | |
568 | DEFUN (ecoff_set_symbol_info, (abfd, ecoff_sym, asym, ext), | |
569 | bfd *abfd AND | |
570 | SYMR *ecoff_sym AND | |
571 | asymbol *asym AND | |
572 | int ext) | |
573 | { | |
574 | asym->the_bfd = abfd; | |
575 | asym->value = ecoff_sym->value; | |
576 | asym->section = &bfd_debug_section; | |
577 | asym->udata = NULL; | |
578 | if (ext) | |
579 | asym->flags = BSF_EXPORT | BSF_GLOBAL; | |
580 | else | |
581 | asym->flags = BSF_LOCAL; | |
582 | switch (ecoff_sym->sc) | |
583 | { | |
584 | case scNil: | |
585 | asym->flags = 0; | |
586 | break; | |
587 | case scText: | |
588 | asym->section = bfd_make_section_old_way (abfd, ".text"); | |
589 | asym->value -= asym->section->vma; | |
590 | break; | |
591 | case scData: | |
592 | asym->section = bfd_make_section_old_way (abfd, ".data"); | |
593 | asym->value -= asym->section->vma; | |
594 | break; | |
595 | case scBss: | |
596 | asym->section = &bfd_com_section; | |
597 | asym->flags = 0; | |
598 | break; | |
599 | case scRegister: | |
600 | asym->flags = BSF_DEBUGGING; | |
601 | break; | |
602 | case scAbs: | |
603 | asym->section = &bfd_abs_section; | |
604 | asym->flags = 0; | |
605 | break; | |
606 | case scUndefined: | |
607 | asym->section = &bfd_und_section; | |
608 | asym->flags = 0; | |
609 | break; | |
610 | case scCdbLocal: | |
611 | case scBits: | |
612 | case scCdbSystem: | |
613 | case scRegImage: | |
614 | case scInfo: | |
615 | case scUserStruct: | |
616 | asym->flags = BSF_DEBUGGING; | |
617 | break; | |
618 | case scSData: | |
619 | asym->section = bfd_make_section_old_way (abfd, ".sdata"); | |
620 | asym->value -= asym->section->vma; | |
621 | break; | |
622 | case scSBss: | |
623 | asym->section = &bfd_com_section; | |
624 | asym->flags = 0; | |
625 | break; | |
626 | case scRData: | |
627 | asym->section = bfd_make_section_old_way (abfd, ".rdata"); | |
628 | asym->value -= asym->section->vma; | |
629 | break; | |
630 | case scVar: | |
631 | asym->flags = BSF_DEBUGGING; | |
632 | break; | |
633 | case scCommon: | |
634 | case scSCommon: | |
635 | asym->section = &bfd_com_section; | |
636 | asym->flags = 0; | |
637 | break; | |
638 | case scVarRegister: | |
639 | case scVariant: | |
640 | asym->flags = BSF_DEBUGGING; | |
641 | break; | |
642 | case scSUndefined: | |
643 | asym->section = &bfd_und_section; | |
644 | asym->flags = 0; | |
645 | break; | |
646 | case scInit: | |
647 | asym->section = bfd_make_section_old_way (abfd, ".init"); | |
648 | asym->value -= asym->section->vma; | |
649 | break; | |
650 | case scBasedVar: | |
651 | case scXData: | |
652 | case scPData: | |
653 | asym->flags = BSF_DEBUGGING; | |
654 | break; | |
655 | case scFini: | |
656 | asym->section = bfd_make_section_old_way (abfd, ".fini"); | |
657 | asym->value -= asym->section->vma; | |
658 | break; | |
659 | default: | |
660 | asym->flags = 0; | |
661 | break; | |
662 | } | |
663 | } | |
664 | ||
665 | /* Read an ECOFF symbol table. */ | |
666 | ||
667 | static boolean | |
668 | DEFUN (ecoff_slurp_symbol_table, (abfd), | |
669 | bfd *abfd) | |
670 | { | |
515c4292 | 671 | bfd_size_type internal_size; |
515c4292 ILT |
672 | ecoff_symbol_type *internal; |
673 | ecoff_symbol_type *internal_ptr; | |
674 | struct ext_ext *eraw_src; | |
675 | struct ext_ext *eraw_end; | |
8fa0d3a0 ILT |
676 | FDR *fdr_ptr; |
677 | FDR *fdr_end; | |
515c4292 ILT |
678 | |
679 | /* If we've already read in the symbol table, do nothing. */ | |
680 | if (ecoff_data (abfd)->canonical_symbols != NULL) | |
681 | return true; | |
682 | ||
8fa0d3a0 ILT |
683 | /* Get the symbolic information. */ |
684 | if (ecoff_slurp_symbolic_info (abfd) == false) | |
685 | return false; | |
686 | if (bfd_get_symcount (abfd) == 0) | |
687 | return true; | |
515c4292 ILT |
688 | |
689 | internal_size = bfd_get_symcount (abfd) * sizeof (ecoff_symbol_type); | |
690 | internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size); | |
691 | if (internal == NULL) | |
692 | { | |
693 | bfd_error = no_memory; | |
694 | return false; | |
695 | } | |
696 | ||
697 | internal_ptr = internal; | |
698 | eraw_src = ecoff_data (abfd)->external_ext; | |
8fa0d3a0 | 699 | eraw_end = eraw_src + ecoff_data (abfd)->symbolic_header.iextMax; |
515c4292 ILT |
700 | for (; eraw_src < eraw_end; eraw_src++, internal_ptr++) |
701 | { | |
702 | EXTR internal_esym; | |
703 | ||
704 | ecoff_swap_ext_in (abfd, eraw_src, &internal_esym); | |
705 | internal_ptr->symbol.name = (ecoff_data (abfd)->ssext | |
706 | + internal_esym.asym.iss); | |
707 | ecoff_set_symbol_info (abfd, &internal_esym.asym, | |
708 | &internal_ptr->symbol, 1); | |
709 | internal_ptr->fdr = ecoff_data (abfd)->fdr + internal_esym.ifd; | |
710 | internal_ptr->local = false; | |
711 | internal_ptr->native.enative = eraw_src; | |
712 | } | |
713 | ||
714 | /* The local symbols must be accessed via the fdr's, because the | |
715 | string and aux indices are relative to the fdr information. */ | |
716 | fdr_ptr = ecoff_data (abfd)->fdr; | |
8fa0d3a0 | 717 | fdr_end = fdr_ptr + ecoff_data (abfd)->symbolic_header.ifdMax; |
515c4292 ILT |
718 | for (; fdr_ptr < fdr_end; fdr_ptr++) |
719 | { | |
720 | struct sym_ext *lraw_src; | |
721 | struct sym_ext *lraw_end; | |
722 | ||
723 | lraw_src = ecoff_data (abfd)->external_sym + fdr_ptr->isymBase; | |
724 | lraw_end = lraw_src + fdr_ptr->csym; | |
725 | for (; lraw_src < lraw_end; lraw_src++, internal_ptr++) | |
726 | { | |
727 | SYMR internal_sym; | |
728 | ||
729 | ecoff_swap_sym_in (abfd, lraw_src, &internal_sym); | |
730 | internal_ptr->symbol.name = (ecoff_data (abfd)->ss | |
731 | + fdr_ptr->issBase | |
732 | + internal_sym.iss); | |
733 | ecoff_set_symbol_info (abfd, &internal_sym, | |
734 | &internal_ptr->symbol, 0); | |
735 | internal_ptr->fdr = fdr_ptr; | |
736 | internal_ptr->local = true; | |
737 | internal_ptr->native.lnative = lraw_src; | |
738 | } | |
739 | } | |
740 | ||
741 | ecoff_data (abfd)->canonical_symbols = internal; | |
742 | ||
743 | return true; | |
744 | } | |
745 | ||
746 | static unsigned int | |
747 | DEFUN (ecoff_get_symtab_upper_bound, (abfd), | |
748 | bfd *abfd) | |
749 | { | |
8fa0d3a0 ILT |
750 | if (ecoff_slurp_symbolic_info (abfd) == false |
751 | || bfd_get_symcount (abfd) == 0) | |
515c4292 ILT |
752 | return 0; |
753 | ||
754 | return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *)); | |
755 | } | |
756 | ||
757 | static unsigned int | |
758 | DEFUN (ecoff_get_symtab, (abfd, alocation), | |
759 | bfd *abfd AND | |
760 | asymbol **alocation) | |
761 | { | |
762 | unsigned int counter = 0; | |
763 | ecoff_symbol_type *symbase; | |
764 | ecoff_symbol_type **location = (ecoff_symbol_type **) alocation; | |
765 | ||
8fa0d3a0 ILT |
766 | if (ecoff_slurp_symbol_table (abfd) == false |
767 | || bfd_get_symcount (abfd) == 0) | |
515c4292 ILT |
768 | return 0; |
769 | ||
770 | symbase = ecoff_data (abfd)->canonical_symbols; | |
771 | while (counter < bfd_get_symcount (abfd)) | |
772 | { | |
773 | *(location++) = symbase++; | |
774 | counter++; | |
775 | } | |
776 | *location++ = (ecoff_symbol_type *) NULL; | |
777 | return bfd_get_symcount (abfd); | |
778 | } | |
779 | ||
780 | /* Turn ECOFF type information into a printable string. | |
781 | emit_aggregate and type_to_string are from gcc/mips-tdump.c, with | |
782 | swapping added and used_ptr removed. */ | |
783 | ||
784 | /* Write aggregate information to a string. */ | |
785 | ||
786 | static void | |
787 | DEFUN (emit_aggregate, (abfd, string, rndx, isym, which), | |
788 | bfd *abfd AND | |
789 | char *string AND | |
790 | RNDXR *rndx AND | |
791 | long isym AND | |
792 | CONST char *which) | |
793 | { | |
794 | int ifd = rndx->rfd; | |
795 | int indx = rndx->index; | |
796 | int sym_base, ss_base; | |
797 | CONST char *name; | |
798 | ||
799 | if (ifd == 0xfff) | |
800 | ifd = isym; | |
801 | ||
802 | sym_base = ecoff_data (abfd)->fdr[ifd].isymBase; | |
803 | ss_base = ecoff_data (abfd)->fdr[ifd].issBase; | |
804 | ||
805 | if (indx == indexNil) | |
806 | name = "/* no name */"; | |
807 | else | |
808 | { | |
809 | SYMR sym; | |
810 | ||
811 | indx += sym_base; | |
812 | ecoff_swap_sym_in (abfd, | |
813 | ecoff_data (abfd)->external_sym + indx, | |
814 | &sym); | |
815 | name = ecoff_data (abfd)->ss + ss_base + sym.iss; | |
816 | } | |
817 | ||
818 | sprintf (string, | |
819 | "%s %s { ifd = %d, index = %d }", | |
820 | which, name, ifd, | |
821 | indx + ecoff_data (abfd)->symbolic_header.iextMax); | |
822 | } | |
823 | ||
824 | /* Convert the type information to string format. */ | |
825 | ||
826 | static char * | |
827 | DEFUN (type_to_string, (abfd, aux_ptr, indx, bigendian), | |
828 | bfd *abfd AND | |
829 | union aux_ext *aux_ptr AND | |
830 | int indx AND | |
831 | int bigendian) | |
832 | { | |
833 | AUXU u; | |
834 | struct qual { | |
835 | unsigned int type; | |
836 | int low_bound; | |
837 | int high_bound; | |
838 | int stride; | |
839 | } qualifiers[7]; | |
840 | ||
841 | unsigned int basic_type; | |
842 | int i; | |
843 | static char buffer1[1024]; | |
844 | static char buffer2[1024]; | |
845 | char *p1 = buffer1; | |
846 | char *p2 = buffer2; | |
847 | RNDXR rndx; | |
848 | ||
849 | for (i = 0; i < 7; i++) | |
850 | { | |
851 | qualifiers[i].low_bound = 0; | |
852 | qualifiers[i].high_bound = 0; | |
853 | qualifiers[i].stride = 0; | |
854 | } | |
855 | ||
856 | if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1) | |
857 | return "-1 (no type)"; | |
858 | ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti); | |
859 | ||
860 | basic_type = u.ti.bt; | |
861 | qualifiers[0].type = u.ti.tq0; | |
862 | qualifiers[1].type = u.ti.tq1; | |
863 | qualifiers[2].type = u.ti.tq2; | |
864 | qualifiers[3].type = u.ti.tq3; | |
865 | qualifiers[4].type = u.ti.tq4; | |
866 | qualifiers[5].type = u.ti.tq5; | |
867 | qualifiers[6].type = tqNil; | |
868 | ||
869 | /* | |
870 | * Go get the basic type. | |
871 | */ | |
872 | switch (basic_type) | |
873 | { | |
874 | case btNil: /* undefined */ | |
875 | strcpy (p1, "nil"); | |
876 | break; | |
877 | ||
878 | case btAdr: /* address - integer same size as pointer */ | |
879 | strcpy (p1, "address"); | |
880 | break; | |
881 | ||
882 | case btChar: /* character */ | |
883 | strcpy (p1, "char"); | |
884 | break; | |
885 | ||
886 | case btUChar: /* unsigned character */ | |
887 | strcpy (p1, "unsigned char"); | |
888 | break; | |
889 | ||
890 | case btShort: /* short */ | |
891 | strcpy (p1, "short"); | |
892 | break; | |
893 | ||
894 | case btUShort: /* unsigned short */ | |
895 | strcpy (p1, "unsigned short"); | |
896 | break; | |
897 | ||
898 | case btInt: /* int */ | |
899 | strcpy (p1, "int"); | |
900 | break; | |
901 | ||
902 | case btUInt: /* unsigned int */ | |
903 | strcpy (p1, "unsigned int"); | |
904 | break; | |
905 | ||
906 | case btLong: /* long */ | |
907 | strcpy (p1, "long"); | |
908 | break; | |
909 | ||
910 | case btULong: /* unsigned long */ | |
911 | strcpy (p1, "unsigned long"); | |
912 | break; | |
913 | ||
914 | case btFloat: /* float (real) */ | |
915 | strcpy (p1, "float"); | |
916 | break; | |
917 | ||
918 | case btDouble: /* Double (real) */ | |
919 | strcpy (p1, "double"); | |
920 | break; | |
921 | ||
922 | /* Structures add 1-2 aux words: | |
923 | 1st word is [ST_RFDESCAPE, offset] pointer to struct def; | |
924 | 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */ | |
925 | ||
926 | case btStruct: /* Structure (Record) */ | |
927 | ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx); | |
928 | emit_aggregate (abfd, p1, &rndx, | |
929 | AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]), | |
930 | "struct"); | |
931 | indx++; /* skip aux words */ | |
932 | break; | |
933 | ||
934 | /* Unions add 1-2 aux words: | |
935 | 1st word is [ST_RFDESCAPE, offset] pointer to union def; | |
936 | 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */ | |
937 | ||
938 | case btUnion: /* Union */ | |
939 | ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx); | |
940 | emit_aggregate (abfd, p1, &rndx, | |
941 | AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]), | |
942 | "union"); | |
943 | indx++; /* skip aux words */ | |
944 | break; | |
945 | ||
946 | /* Enumerations add 1-2 aux words: | |
947 | 1st word is [ST_RFDESCAPE, offset] pointer to enum def; | |
948 | 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */ | |
949 | ||
950 | case btEnum: /* Enumeration */ | |
951 | ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx); | |
952 | emit_aggregate (abfd, p1, &rndx, | |
953 | AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]), | |
954 | "enum"); | |
955 | indx++; /* skip aux words */ | |
956 | break; | |
957 | ||
958 | case btTypedef: /* defined via a typedef, isymRef points */ | |
959 | strcpy (p1, "typedef"); | |
960 | break; | |
961 | ||
962 | case btRange: /* subrange of int */ | |
963 | strcpy (p1, "subrange"); | |
964 | break; | |
965 | ||
966 | case btSet: /* pascal sets */ | |
967 | strcpy (p1, "set"); | |
968 | break; | |
969 | ||
970 | case btComplex: /* fortran complex */ | |
971 | strcpy (p1, "complex"); | |
972 | break; | |
973 | ||
974 | case btDComplex: /* fortran double complex */ | |
975 | strcpy (p1, "double complex"); | |
976 | break; | |
977 | ||
978 | case btIndirect: /* forward or unnamed typedef */ | |
979 | strcpy (p1, "forward/unamed typedef"); | |
980 | break; | |
981 | ||
982 | case btFixedDec: /* Fixed Decimal */ | |
983 | strcpy (p1, "fixed decimal"); | |
984 | break; | |
985 | ||
986 | case btFloatDec: /* Float Decimal */ | |
987 | strcpy (p1, "float decimal"); | |
988 | break; | |
989 | ||
990 | case btString: /* Varying Length Character String */ | |
991 | strcpy (p1, "string"); | |
992 | break; | |
993 | ||
994 | case btBit: /* Aligned Bit String */ | |
995 | strcpy (p1, "bit"); | |
996 | break; | |
997 | ||
998 | case btPicture: /* Picture */ | |
999 | strcpy (p1, "picture"); | |
1000 | break; | |
1001 | ||
1002 | case btVoid: /* Void */ | |
1003 | strcpy (p1, "void"); | |
1004 | break; | |
1005 | ||
1006 | default: | |
1007 | sprintf (p1, "Unknown basic type %d", (int) basic_type); | |
1008 | break; | |
1009 | } | |
1010 | ||
1011 | p1 += strlen (buffer1); | |
1012 | ||
1013 | /* | |
1014 | * If this is a bitfield, get the bitsize. | |
1015 | */ | |
1016 | if (u.ti.fBitfield) | |
1017 | { | |
1018 | int bitsize; | |
1019 | ||
1020 | bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]); | |
1021 | sprintf (p1, " : %d", bitsize); | |
1022 | p1 += strlen (buffer1); | |
1023 | } | |
1024 | ||
1025 | ||
1026 | /* | |
1027 | * Deal with any qualifiers. | |
1028 | */ | |
1029 | if (qualifiers[0].type != tqNil) | |
1030 | { | |
1031 | /* | |
1032 | * Snarf up any array bounds in the correct order. Arrays | |
1033 | * store 5 successive words in the aux. table: | |
1034 | * word 0 RNDXR to type of the bounds (ie, int) | |
1035 | * word 1 Current file descriptor index | |
1036 | * word 2 low bound | |
1037 | * word 3 high bound (or -1 if []) | |
1038 | * word 4 stride size in bits | |
1039 | */ | |
1040 | for (i = 0; i < 7; i++) | |
1041 | { | |
1042 | if (qualifiers[i].type == tqArray) | |
1043 | { | |
1044 | qualifiers[i].low_bound = | |
1045 | AUX_GET_DNLOW (bigendian, &aux_ptr[indx+2]); | |
1046 | qualifiers[i].high_bound = | |
1047 | AUX_GET_DNHIGH (bigendian, &aux_ptr[indx+3]); | |
1048 | qualifiers[i].stride = | |
1049 | AUX_GET_WIDTH (bigendian, &aux_ptr[indx+4]); | |
1050 | indx += 5; | |
1051 | } | |
1052 | } | |
1053 | ||
1054 | /* | |
1055 | * Now print out the qualifiers. | |
1056 | */ | |
1057 | for (i = 0; i < 6; i++) | |
1058 | { | |
1059 | switch (qualifiers[i].type) | |
1060 | { | |
1061 | case tqNil: | |
1062 | case tqMax: | |
1063 | break; | |
1064 | ||
1065 | case tqPtr: | |
1066 | strcpy (p2, "ptr to "); | |
1067 | p2 += sizeof ("ptr to ")-1; | |
1068 | break; | |
1069 | ||
1070 | case tqVol: | |
1071 | strcpy (p2, "volatile "); | |
1072 | p2 += sizeof ("volatile ")-1; | |
1073 | break; | |
1074 | ||
1075 | case tqFar: | |
1076 | strcpy (p2, "far "); | |
1077 | p2 += sizeof ("far ")-1; | |
1078 | break; | |
1079 | ||
1080 | case tqProc: | |
1081 | strcpy (p2, "func. ret. "); | |
1082 | p2 += sizeof ("func. ret. "); | |
1083 | break; | |
1084 | ||
1085 | case tqArray: | |
1086 | { | |
1087 | int first_array = i; | |
1088 | int j; | |
1089 | ||
1090 | /* Print array bounds reversed (ie, in the order the C | |
1091 | programmer writes them). C is such a fun language.... */ | |
1092 | ||
1093 | while (i < 5 && qualifiers[i+1].type == tqArray) | |
1094 | i++; | |
1095 | ||
1096 | for (j = i; j >= first_array; j--) | |
1097 | { | |
1098 | strcpy (p2, "array ["); | |
1099 | p2 += sizeof ("array [")-1; | |
1100 | if (qualifiers[j].low_bound != 0) | |
1101 | sprintf (p2, | |
1102 | "%ld:%ld {%ld bits}", | |
1103 | (long) qualifiers[j].low_bound, | |
1104 | (long) qualifiers[j].high_bound, | |
1105 | (long) qualifiers[j].stride); | |
1106 | ||
1107 | else if (qualifiers[j].high_bound != -1) | |
1108 | sprintf (p2, | |
1109 | "%ld {%ld bits}", | |
1110 | (long) (qualifiers[j].high_bound + 1), | |
1111 | (long) (qualifiers[j].stride)); | |
1112 | ||
1113 | else | |
1114 | sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride)); | |
1115 | ||
1116 | p2 += strlen (p2); | |
1117 | strcpy (p2, "] of "); | |
1118 | p2 += sizeof ("] of ")-1; | |
1119 | } | |
1120 | } | |
1121 | break; | |
1122 | } | |
1123 | } | |
1124 | } | |
1125 | ||
1126 | strcpy (p2, buffer1); | |
1127 | return buffer2; | |
1128 | } | |
1129 | ||
1130 | /* Print information about an ECOFF symbol. */ | |
1131 | ||
1132 | static void | |
1133 | DEFUN (ecoff_print_symbol, (abfd, filep, symbol, how), | |
1134 | bfd *abfd AND | |
1135 | PTR filep AND | |
1136 | asymbol *symbol AND | |
1137 | bfd_print_symbol_type how) | |
1138 | { | |
1139 | FILE *file = (FILE *)filep; | |
1140 | ||
1141 | switch (how) | |
1142 | { | |
1143 | case bfd_print_symbol_name: | |
1144 | fprintf (file, "%s", symbol->name); | |
1145 | break; | |
1146 | case bfd_print_symbol_more: | |
1147 | if (ecoffsymbol (symbol)->local) | |
1148 | { | |
1149 | SYMR ecoff_sym; | |
1150 | ||
1151 | ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative, | |
1152 | &ecoff_sym); | |
1153 | fprintf (file, "ecoff local %lx %x %x", | |
1154 | (unsigned long) ecoff_sym.value, | |
1155 | (unsigned) ecoff_sym.st, (unsigned) ecoff_sym.sc); | |
1156 | } | |
1157 | else | |
1158 | { | |
1159 | EXTR ecoff_ext; | |
1160 | ||
1161 | ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative, | |
1162 | &ecoff_ext); | |
1163 | fprintf (file, "ecoff extern %lx %x %x", | |
1164 | (unsigned long) ecoff_ext.asym.value, | |
1165 | (unsigned) ecoff_ext.asym.st, | |
1166 | (unsigned) ecoff_ext.asym.sc); | |
1167 | } | |
1168 | break; | |
1169 | case bfd_print_symbol_nm: | |
1170 | { | |
1171 | CONST char *section_name = symbol->section->name; | |
1172 | ||
1173 | bfd_print_symbol_vandf ((PTR) file, symbol); | |
1174 | fprintf (file, " %-5s %s %s", | |
1175 | section_name, | |
1176 | ecoffsymbol (symbol)->local ? "l" : "e", | |
1177 | symbol->name); | |
1178 | } | |
1179 | break; | |
1180 | case bfd_print_symbol_all: | |
1181 | /* Print out the symbols in a reasonable way */ | |
1182 | { | |
515c4292 ILT |
1183 | char type; |
1184 | int pos; | |
1185 | EXTR ecoff_ext; | |
1186 | char jmptbl; | |
1187 | char cobol_main; | |
1188 | char weakext; | |
1189 | ||
1190 | if (ecoffsymbol (symbol)->local) | |
1191 | { | |
1192 | ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative, | |
1193 | &ecoff_ext.asym); | |
1194 | type = 'l'; | |
1195 | pos = (ecoffsymbol (symbol)->native.lnative | |
1196 | - ecoff_data (abfd)->external_sym | |
1197 | + ecoff_data (abfd)->symbolic_header.iextMax); | |
1198 | jmptbl = ' '; | |
1199 | cobol_main = ' '; | |
1200 | weakext = ' '; | |
1201 | } | |
1202 | else | |
1203 | { | |
1204 | ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative, | |
1205 | &ecoff_ext); | |
1206 | type = 'e'; | |
1207 | pos = (ecoffsymbol (symbol)->native.enative | |
1208 | - ecoff_data (abfd)->external_ext); | |
1209 | jmptbl = ecoff_ext.jmptbl ? 'j' : ' '; | |
1210 | cobol_main = ecoff_ext.cobol_main ? 'c' : ' '; | |
1211 | weakext = ecoff_ext.weakext ? 'w' : ' '; | |
1212 | } | |
1213 | ||
1214 | fprintf (file, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s", | |
1215 | pos, type, (unsigned long) ecoff_ext.asym.value, | |
1216 | (unsigned) ecoff_ext.asym.st, | |
1217 | (unsigned) ecoff_ext.asym.sc, | |
1218 | (unsigned) ecoff_ext.asym.index, | |
1219 | jmptbl, cobol_main, weakext, | |
1220 | symbol->name); | |
1221 | ||
1222 | if (ecoffsymbol (symbol)->fdr != NULL | |
1223 | && ecoff_ext.asym.index != indexNil) | |
1224 | { | |
1225 | unsigned indx; | |
1226 | int bigendian; | |
1227 | long sym_base; | |
1228 | union aux_ext *aux_base; | |
1229 | ||
1230 | indx = ecoff_ext.asym.index; | |
1231 | ||
1232 | /* sym_base is used to map the fdr relative indices which | |
1233 | appear in the file to the position number which we are | |
1234 | using. */ | |
1235 | sym_base = ecoffsymbol (symbol)->fdr->isymBase; | |
1236 | if (ecoffsymbol (symbol)->local) | |
1237 | sym_base += ecoff_data (abfd)->symbolic_header.iextMax; | |
1238 | ||
1239 | /* aux_base is the start of the aux entries for this file; | |
1240 | asym.index is an offset from this. */ | |
1241 | aux_base = (ecoff_data (abfd)->external_aux | |
1242 | + ecoffsymbol (symbol)->fdr->iauxBase); | |
1243 | ||
1244 | /* The aux entries are stored in host byte order; the | |
1245 | order is indicated by a bit in the fdr. */ | |
1246 | bigendian = ecoffsymbol (symbol)->fdr->fBigendian; | |
1247 | ||
1248 | /* This switch is basically from gcc/mips-tdump.c */ | |
1249 | switch (ecoff_ext.asym.st) | |
1250 | { | |
1251 | case stNil: | |
1252 | case stLabel: | |
1253 | break; | |
1254 | ||
1255 | case stFile: | |
1256 | case stBlock: | |
1257 | printf ("\n End+1 symbol: %ld", indx + sym_base); | |
1258 | break; | |
1259 | ||
1260 | case stEnd: | |
1261 | if (ecoff_ext.asym.sc == scText | |
1262 | || ecoff_ext.asym.sc == scInfo) | |
1263 | printf ("\n First symbol: %ld", indx + sym_base); | |
1264 | else | |
1265 | printf ("\n First symbol: %ld", | |
1266 | (AUX_GET_ISYM (bigendian, | |
1267 | &aux_base[ecoff_ext.asym.index]) | |
1268 | + sym_base)); | |
1269 | break; | |
1270 | ||
1271 | case stProc: | |
1272 | case stStaticProc: | |
1273 | if (MIPS_IS_STAB (&ecoff_ext.asym)) | |
1274 | ; | |
1275 | else if (ecoffsymbol (symbol)->local) | |
1276 | printf ("\n End+1 symbol: %-7ld Type: %s", | |
1277 | (AUX_GET_ISYM (bigendian, | |
1278 | &aux_base[ecoff_ext.asym.index]) | |
1279 | + sym_base), | |
1280 | type_to_string (abfd, aux_base, indx + 1, | |
1281 | bigendian)); | |
1282 | else | |
1283 | printf ("\n Type: %s", | |
1284 | type_to_string (abfd, aux_base, indx, bigendian)); | |
1285 | ||
1286 | break; | |
1287 | ||
1288 | default: | |
1289 | if (!MIPS_IS_STAB (&ecoff_ext.asym)) | |
1290 | printf ("\n Type: %s", | |
1291 | type_to_string (abfd, aux_base, indx, bigendian)); | |
1292 | break; | |
1293 | } | |
1294 | } | |
1295 | } | |
1296 | break; | |
1297 | } | |
1298 | } | |
1299 | \f | |
1300 | /* Provided a BFD, a section and an offset into the section, calculate | |
1301 | and return the name of the source file and the line nearest to the | |
1302 | wanted location. */ | |
1303 | ||
1304 | static boolean | |
1305 | DEFUN (ecoff_find_nearest_line, (abfd, | |
1306 | section, | |
1307 | ignore_symbols, | |
1308 | offset, | |
1309 | filename_ptr, | |
1310 | functionname_ptr, | |
1311 | retline_ptr), | |
1312 | bfd *abfd AND | |
1313 | asection *section AND | |
1314 | asymbol **ignore_symbols AND | |
1315 | bfd_vma offset AND | |
1316 | CONST char **filename_ptr AND | |
1317 | CONST char **functionname_ptr AND | |
1318 | unsigned int *retline_ptr) | |
1319 | { | |
1320 | FDR *fdr_ptr; | |
1321 | FDR *fdr_start; | |
1322 | FDR *fdr_end; | |
1323 | FDR *fdr_hold; | |
1324 | struct pdr_ext *pdr_ptr; | |
1325 | struct pdr_ext *pdr_end; | |
1326 | PDR pdr; | |
1327 | unsigned char *line_ptr; | |
1328 | unsigned char *line_end; | |
1329 | int lineno; | |
1330 | SYMR proc_sym; | |
1331 | ||
1332 | /* If we're not in the .text section, we don't have any line | |
1333 | numbers. */ | |
1334 | if (strcmp (section->name, _TEXT) != 0) | |
1335 | return false; | |
1336 | ||
8fa0d3a0 ILT |
1337 | /* Make sure we have the FDR's. */ |
1338 | if (ecoff_slurp_symbolic_info (abfd) == false | |
1339 | || bfd_get_symcount (abfd) == 0) | |
1340 | return false; | |
1341 | ||
515c4292 ILT |
1342 | /* Each file descriptor (FDR) has a memory address. Here we track |
1343 | down which FDR we want. The FDR's are stored in increasing | |
1344 | memory order. If speed is ever important, this can become a | |
1345 | binary search. We must ignore FDR's with no PDR entries; they | |
1346 | will have the adr of the FDR before or after them. */ | |
1347 | fdr_start = ecoff_data (abfd)->fdr; | |
1348 | fdr_end = fdr_start + ecoff_data (abfd)->symbolic_header.ifdMax; | |
1349 | fdr_hold = (FDR *) NULL; | |
1350 | for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++) | |
1351 | { | |
1352 | if (offset < fdr_ptr->adr) | |
1353 | break; | |
1354 | if (fdr_ptr->cpd > 0) | |
1355 | fdr_hold = fdr_ptr; | |
1356 | } | |
1357 | if (fdr_hold == (FDR *) NULL) | |
1358 | return false; | |
1359 | fdr_ptr = fdr_hold; | |
1360 | ||
1361 | /* Each FDR has a list of procedure descriptors (PDR). PDR's also | |
1362 | have an address, which is relative to the FDR address, and are | |
1363 | also stored in increasing memory order. */ | |
1364 | offset -= fdr_ptr->adr; | |
1365 | pdr_ptr = ecoff_data (abfd)->external_pdr + fdr_ptr->ipdFirst; | |
1366 | pdr_end = pdr_ptr + fdr_ptr->cpd; | |
1367 | ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr); | |
1368 | if (offset < pdr.adr) | |
1369 | return false; | |
1370 | for (pdr_ptr++; pdr_ptr < pdr_end; pdr_ptr++) | |
1371 | { | |
1372 | ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr); | |
1373 | if (offset < pdr.adr) | |
1374 | break; | |
1375 | } | |
1376 | ||
1377 | /* Now we can look for the actual line number. The line numbers are | |
1378 | stored in a very funky format, which I won't try to describe. | |
1379 | Note that right here pdr_ptr and pdr hold the PDR *after* the one | |
1380 | we want; we need this to compute line_end. */ | |
1381 | line_end = ecoff_data (abfd)->line; | |
1382 | if (pdr_ptr == pdr_end) | |
1383 | line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine; | |
1384 | else | |
1385 | line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset; | |
1386 | ||
1387 | /* Now change pdr and pdr_ptr to the one we want. */ | |
1388 | pdr_ptr--; | |
1389 | ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr); | |
1390 | ||
1391 | offset -= pdr.adr; | |
1392 | lineno = pdr.lnLow; | |
1393 | line_ptr = (ecoff_data (abfd)->line | |
1394 | + fdr_ptr->cbLineOffset | |
1395 | + pdr.cbLineOffset); | |
1396 | while (line_ptr < line_end) | |
1397 | { | |
1398 | int delta; | |
1399 | int count; | |
1400 | ||
1401 | delta = *line_ptr >> 4; | |
1402 | if (delta >= 0x8) | |
1403 | delta -= 0x10; | |
1404 | count = (*line_ptr & 0xf) + 1; | |
1405 | ++line_ptr; | |
1406 | if (delta == -8) | |
1407 | { | |
1408 | delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff); | |
1409 | if (delta >= 0x8000) | |
1410 | delta -= 0x10000; | |
1411 | line_ptr += 2; | |
1412 | } | |
1413 | lineno += delta; | |
1414 | if (offset < count * 4) | |
1415 | break; | |
1416 | offset -= count * 4; | |
1417 | } | |
1418 | ||
1419 | /* If offset is too large, this line is not interesting. */ | |
1420 | if (offset > 100) | |
1421 | return false; | |
1422 | ||
1423 | *filename_ptr = ecoff_data (abfd)->ss + fdr_ptr->issBase + fdr_ptr->rss; | |
1424 | ecoff_swap_sym_in (abfd, | |
1425 | (ecoff_data (abfd)->external_sym | |
1426 | + fdr_ptr->isymBase | |
1427 | + pdr.isym), | |
1428 | &proc_sym); | |
1429 | *functionname_ptr = ecoff_data (abfd)->ss + proc_sym.iss; | |
1430 | *retline_ptr = lineno; | |
1431 | return true; | |
1432 | } | |
1433 | \f | |
8fa0d3a0 ILT |
1434 | /* We can't use the generic linking routines for ECOFF, because we |
1435 | have to handle all the debugging information. The generic link | |
1436 | routine just works out the section contents and attaches a list of | |
1437 | symbols. | |
1438 | ||
1439 | We link by looping over all the seclets. We make two passes. On | |
1440 | the first we set the actual section contents and determine the size | |
1441 | of the debugging information. On the second we accumulate the | |
1442 | debugging information and write it out. | |
1443 | ||
1444 | This currently always accumulates the debugging information, which | |
1445 | is incorrect, because it ignores the -s and -S options of the | |
1446 | linker. The linker needs to be modified to give us that | |
1447 | information in a more useful format (currently it just provides a | |
1448 | list of symbols which should appear in the output file). */ | |
1449 | ||
1450 | /* Clear the output_has_begun flag for all the input BFD's. We use it | |
1451 | to avoid linking in the debugging information for a BFD more than | |
1452 | once. */ | |
1453 | ||
1454 | static void | |
1455 | DEFUN (ecoff_clear_output_flags, (abfd), | |
1456 | bfd *abfd) | |
1457 | { | |
1458 | register asection *o; | |
1459 | register bfd_seclet_type *p; | |
1460 | ||
1461 | for (o = abfd->sections; o != (asection *) NULL; o = o->next) | |
1462 | for (p = o->seclets_head; | |
1463 | p != (bfd_seclet_type *) NULL; | |
1464 | p = p->next) | |
1465 | if (p->type == bfd_indirect_seclet) | |
1466 | p->u.indirect.section->owner->output_has_begun = false; | |
1467 | } | |
1468 | ||
1469 | /* Handle an indirect seclet on the first pass. Set the contents of | |
1470 | the output section, and accumulate the debugging information if | |
1471 | any. */ | |
1472 | ||
1473 | static boolean | |
1474 | DEFUN (ecoff_rel, (output_bfd, seclet, output_section, data, relocateable), | |
1475 | bfd *output_bfd AND | |
1476 | bfd_seclet_type *seclet AND | |
1477 | asection *output_section AND | |
1478 | PTR data AND | |
1479 | boolean relocateable) | |
1480 | { | |
1481 | bfd *input_bfd; | |
1482 | HDRR *output_symhdr; | |
1483 | HDRR *input_symhdr; | |
1484 | ||
1485 | if ((output_section->flags & SEC_HAS_CONTENTS) | |
1486 | && !(output_section->flags & SEC_NEVER_LOAD) | |
1487 | && (output_section->flags & SEC_LOAD) | |
1488 | && seclet->size) | |
1489 | { | |
1490 | data = (PTR) bfd_get_relocated_section_contents (output_bfd, | |
1491 | seclet, | |
1492 | data, | |
1493 | relocateable); | |
1494 | if (bfd_set_section_contents (output_bfd, | |
1495 | output_section, | |
1496 | data, | |
1497 | seclet->offset, | |
1498 | seclet->size) | |
1499 | == false) | |
1500 | { | |
1501 | abort(); | |
1502 | } | |
1503 | } | |
1504 | ||
1505 | input_bfd = seclet->u.indirect.section->owner; | |
1506 | ||
1507 | /* We want to figure out how much space will be required to | |
1508 | incorporate all the debugging information from input_bfd. We use | |
1509 | the output_has_begun field to avoid adding it in more than once. | |
1510 | The actual incorporation is done in the second pass, in | |
1511 | ecoff_get_debug. The code has to parallel that code in its | |
1512 | manipulations of output_symhdr. */ | |
1513 | ||
1514 | if (input_bfd->output_has_begun) | |
1515 | return true; | |
1516 | input_bfd->output_has_begun = true; | |
1517 | ||
1518 | output_symhdr = &ecoff_data (output_bfd)->symbolic_header; | |
1519 | ||
1520 | if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour) | |
1521 | { | |
1522 | asymbol **symbols; | |
1523 | asymbol **sym_ptr; | |
1524 | asymbol **sym_end; | |
1525 | ||
1526 | /* We just accumulate symbols from a non-ECOFF BFD. */ | |
1527 | ||
1528 | symbols = (asymbol **) bfd_alloc (output_bfd, | |
1529 | get_symtab_upper_bound (input_bfd)); | |
1530 | if (symbols == (asymbol **) NULL) | |
1531 | { | |
1532 | bfd_error = no_memory; | |
1533 | return false; | |
1534 | } | |
1535 | sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols); | |
1536 | ||
1537 | for (sym_ptr = symbols; sym_ptr < sym_end; sym_ptr++) | |
1538 | { | |
1539 | size_t len; | |
1540 | ||
1541 | len = strlen ((*sym_ptr)->name); | |
1542 | if (((*sym_ptr)->flags & BSF_EXPORT) == 0) | |
1543 | { | |
1544 | ++output_symhdr->isymMax; | |
1545 | output_symhdr->issMax += len + 1; | |
1546 | } | |
1547 | else | |
1548 | { | |
1549 | ++output_symhdr->iextMax; | |
1550 | output_symhdr->issExtMax += len + 1; | |
1551 | } | |
1552 | } | |
1553 | ||
1554 | bfd_release (output_bfd, (PTR) symbols); | |
1555 | ||
1556 | ++output_symhdr->ifdMax; | |
1557 | ||
1558 | return true; | |
1559 | } | |
1560 | ||
1561 | /* We simply add in the information from another ECOFF BFD. First | |
1562 | we make sure we have the symbolic information. */ | |
1563 | if (ecoff_slurp_symbolic_info (input_bfd) == false) | |
1564 | return false; | |
1565 | if (bfd_get_symcount (input_bfd) == 0) | |
1566 | return true; | |
1567 | ||
1568 | input_symhdr = &ecoff_data (input_bfd)->symbolic_header; | |
1569 | ||
1570 | output_symhdr->ilineMax += input_symhdr->ilineMax; | |
1571 | output_symhdr->cbLine += input_symhdr->cbLine; | |
1572 | output_symhdr->idnMax += input_symhdr->idnMax; | |
1573 | output_symhdr->ipdMax += input_symhdr->ipdMax; | |
1574 | output_symhdr->isymMax += input_symhdr->isymMax; | |
1575 | output_symhdr->ioptMax += input_symhdr->ioptMax; | |
1576 | output_symhdr->iauxMax += input_symhdr->iauxMax; | |
1577 | output_symhdr->issMax += input_symhdr->issMax; | |
1578 | output_symhdr->issExtMax += input_symhdr->issExtMax; | |
1579 | output_symhdr->ifdMax += input_symhdr->ifdMax; | |
1580 | output_symhdr->iextMax += input_symhdr->iextMax; | |
1581 | ||
1582 | /* The RFD's are special, since we create them if needed. */ | |
1583 | if (input_symhdr->crfd > 0) | |
1584 | output_symhdr->crfd += input_symhdr->crfd; | |
1585 | else | |
1586 | output_symhdr->crfd += input_symhdr->ifdMax; | |
1587 | ||
1588 | return true; | |
1589 | } | |
1590 | ||
1591 | /* Handle an arbitrary seclet on the first pass. */ | |
1592 | ||
1593 | static boolean | |
1594 | DEFUN (ecoff_dump_seclet, (abfd, seclet, section, data, relocateable), | |
1595 | bfd *abfd AND | |
1596 | bfd_seclet_type *seclet AND | |
1597 | asection *section AND | |
1598 | PTR data AND | |
1599 | boolean relocateable) | |
1600 | { | |
1601 | switch (seclet->type) | |
1602 | { | |
1603 | case bfd_indirect_seclet: | |
1604 | /* The contents of this section come from another one somewhere | |
1605 | else. */ | |
1606 | return ecoff_rel (abfd, seclet, section, data, relocateable); | |
1607 | ||
1608 | case bfd_fill_seclet: | |
1609 | /* Fill in the section with us. */ | |
1610 | { | |
1611 | char *d = (char *) bfd_alloc (abfd, seclet->size); | |
1612 | unsigned int i; | |
1613 | boolean ret; | |
1614 | ||
1615 | for (i = 0; i < seclet->size; i+=2) | |
1616 | d[i] = seclet->u.fill.value >> 8; | |
1617 | for (i = 1; i < seclet->size; i+=2) | |
1618 | d[i] = seclet->u.fill.value; | |
1619 | ret = bfd_set_section_contents (abfd, section, d, seclet->offset, | |
1620 | seclet->size); | |
1621 | bfd_release (abfd, (PTR) d); | |
1622 | return ret; | |
1623 | } | |
1624 | ||
1625 | default: | |
1626 | abort(); | |
1627 | } | |
1628 | ||
1629 | return true; | |
1630 | } | |
1631 | ||
1632 | /* Add a string to the debugging information we are accumulating for a | |
1633 | file. Return the offset from the fdr string base or from the | |
1634 | external string base. */ | |
1635 | ||
1636 | static long | |
1637 | DEFUN (ecoff_add_string, (output_bfd, fdr, string, external), | |
1638 | bfd *output_bfd AND | |
1639 | FDR *fdr AND | |
1640 | CONST char *string AND | |
1641 | boolean external) | |
1642 | { | |
1643 | HDRR *symhdr; | |
1644 | size_t len; | |
1645 | long ret; | |
1646 | ||
1647 | symhdr = &ecoff_data (output_bfd)->symbolic_header; | |
1648 | len = strlen (string); | |
1649 | if (external) | |
1650 | { | |
1651 | strcpy (ecoff_data (output_bfd)->ssext + symhdr->issExtMax, string); | |
1652 | ret = symhdr->issExtMax; | |
1653 | symhdr->issExtMax += len + 1; | |
1654 | } | |
1655 | else | |
1656 | { | |
1657 | strcpy (ecoff_data (output_bfd)->ss + symhdr->issMax, string); | |
1658 | ret = fdr->cbSs; | |
1659 | symhdr->issMax += len + 1; | |
1660 | fdr->cbSs += len + 1; | |
1661 | } | |
1662 | return ret; | |
1663 | } | |
1664 | ||
1665 | /* Accumulate the debugging information from an input section. */ | |
1666 | ||
1667 | static boolean | |
1668 | DEFUN (ecoff_get_debug, (output_bfd, seclet, section), | |
1669 | bfd *output_bfd AND | |
1670 | bfd_seclet_type *seclet AND | |
1671 | asection *section) | |
1672 | { | |
1673 | bfd *input_bfd; | |
1674 | HDRR *output_symhdr; | |
1675 | HDRR *input_symhdr; | |
1676 | ecoff_data_type *output_ecoff; | |
1677 | ecoff_data_type *input_ecoff; | |
1678 | FDR *fdr_ptr; | |
1679 | FDR *fdr_end; | |
1680 | struct fdr_ext *fdr_out; | |
1681 | struct ext_ext *ext_ptr; | |
1682 | struct ext_ext *ext_end; | |
1683 | struct ext_ext *ext_out; | |
1684 | long iss; | |
1685 | long isym; | |
1686 | long iline; | |
1687 | long iopt; | |
1688 | long ipdr; | |
1689 | long iaux; | |
1690 | long irfd; | |
1691 | long cbline; | |
1692 | ||
1693 | input_bfd = seclet->u.indirect.section->owner; | |
1694 | ||
1695 | /* Don't get the information more than once. */ | |
1696 | if (input_bfd->output_has_begun) | |
1697 | return true; | |
1698 | input_bfd->output_has_begun = true; | |
1699 | ||
1700 | output_ecoff = ecoff_data (output_bfd); | |
1701 | output_symhdr = &output_ecoff->symbolic_header; | |
1702 | ||
1703 | if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour) | |
1704 | { | |
1705 | FDR fdr; | |
1706 | asymbol **symbols; | |
1707 | asymbol **sym_ptr; | |
1708 | asymbol **sym_end; | |
1709 | ||
1710 | /* This is not an ECOFF BFD. Just gather the symbols. */ | |
1711 | ||
1712 | memset (&fdr, 0, sizeof fdr); | |
1713 | ||
1714 | fdr.adr = bfd_get_section_vma (output_bfd, section) + seclet->offset; | |
1715 | fdr.issBase = output_symhdr->issMax; | |
1716 | fdr.cbSs = 0; | |
1717 | fdr.rss = ecoff_add_string (output_bfd, | |
1718 | &fdr, | |
1719 | bfd_get_filename (input_bfd), | |
1720 | false); | |
1721 | fdr.isymBase = output_symhdr->isymMax; | |
1722 | ||
1723 | /* Get the symbols from the input BFD. */ | |
1724 | symbols = (asymbol **) bfd_alloc (output_bfd, | |
1725 | get_symtab_upper_bound (input_bfd)); | |
1726 | if (symbols == (asymbol **) NULL) | |
1727 | { | |
1728 | bfd_error = no_memory; | |
1729 | return false; | |
1730 | } | |
1731 | sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols); | |
1732 | ||
1733 | /* Handle the local symbols. */ | |
1734 | fdr.csym = 0; | |
1735 | for (sym_ptr = symbols; sym_ptr != sym_end; sym_ptr++) | |
1736 | { | |
1737 | SYMR internal_sym; | |
1738 | ||
1739 | if (((*sym_ptr)->flags & BSF_EXPORT) != 0) | |
1740 | continue; | |
1741 | memset (&internal_sym, 0, sizeof internal_sym); | |
1742 | internal_sym.iss = ecoff_add_string (output_bfd, | |
1743 | &fdr, | |
1744 | (*sym_ptr)->name, | |
1745 | false); | |
1746 | internal_sym.value = (*sym_ptr)->value; | |
1747 | internal_sym.st = stNil; | |
1748 | internal_sym.sc = scUndefined; | |
1749 | internal_sym.index = indexNil; | |
1750 | ecoff_swap_sym_out (output_bfd, &internal_sym, | |
1751 | (output_ecoff->external_sym | |
1752 | + output_symhdr->isymMax)); | |
1753 | ++fdr.csym; | |
1754 | ++output_symhdr->isymMax; | |
1755 | } | |
1756 | ||
1757 | /* Handle the external symbols. */ | |
1758 | for (sym_ptr = symbols; sym_ptr != sym_end; sym_ptr++) | |
1759 | { | |
1760 | EXTR internal_ext; | |
1761 | ||
1762 | if (((*sym_ptr)->flags & BSF_EXPORT) == 0) | |
1763 | continue; | |
1764 | memset (&internal_ext, 0, sizeof internal_ext); | |
1765 | internal_ext.ifd = output_symhdr->ifdMax; | |
1766 | internal_ext.asym.iss = ecoff_add_string (output_bfd, | |
1767 | &fdr, | |
1768 | (*sym_ptr)->name, | |
1769 | true); | |
1770 | internal_ext.asym.value = (*sym_ptr)->value; | |
1771 | internal_ext.asym.st = stNil; | |
1772 | internal_ext.asym.sc = scUndefined; | |
1773 | internal_ext.asym.reserved = 0; | |
1774 | internal_ext.asym.index = indexNil; | |
1775 | ecoff_swap_ext_out (output_bfd, &internal_ext, | |
1776 | (output_ecoff->external_ext | |
1777 | + output_symhdr->iextMax)); | |
1778 | ++output_symhdr->iextMax; | |
1779 | } | |
1780 | ||
1781 | bfd_release (output_bfd, (PTR) symbols); | |
1782 | ||
1783 | /* Leave everything else zeroed out. This will cause the lang | |
1784 | field to be langC. The fBigendian field will indicate little | |
1785 | endian format, but it doesn't matter because it only applies | |
1786 | to aux fields and there are none. */ | |
1787 | ||
1788 | ecoff_swap_fdr_out (output_bfd, &fdr, | |
1789 | (output_ecoff->external_fdr | |
1790 | + output_symhdr->ifdMax)); | |
1791 | ++output_symhdr->ifdMax; | |
1792 | return true; | |
1793 | } | |
1794 | ||
1795 | /* This is an ECOFF BFD. We want to grab the information from | |
1796 | input_bfd and attach it to output_bfd. */ | |
1797 | if (bfd_get_symcount (input_bfd) == 0) | |
1798 | return true; | |
1799 | input_ecoff = ecoff_data (input_bfd); | |
1800 | input_symhdr = &input_ecoff->symbolic_header; | |
1801 | ||
1802 | /* Because ECOFF uses relative pointers for most of the debugging | |
1803 | information, much of it can simply be copied from input_bfd to | |
1804 | output_bfd. */ | |
1805 | memcpy (output_ecoff->line + output_symhdr->cbLineOffset, | |
1806 | input_ecoff->line, | |
1807 | input_symhdr->cbLine * sizeof (unsigned char)); | |
1808 | memcpy (output_ecoff->external_aux + output_symhdr->iauxMax, | |
1809 | input_ecoff->external_aux, | |
1810 | input_symhdr->iauxMax * sizeof (union aux_ext)); | |
1811 | memcpy (output_ecoff->ss + output_symhdr->issMax, | |
1812 | input_ecoff->ss, | |
1813 | input_symhdr->issMax * sizeof (char)); | |
1814 | memcpy (output_ecoff->ssext + output_symhdr->issExtMax, | |
1815 | input_ecoff->ssext, | |
1816 | input_symhdr->issExtMax * sizeof (char)); | |
1817 | ||
1818 | /* Some of the information may need to be swapped. */ | |
1819 | if (output_bfd->xvec->byteorder_big_p == input_bfd->xvec->byteorder_big_p) | |
1820 | { | |
1821 | /* The two BFD's have the same endianness, so memcpy will | |
1822 | suffice. */ | |
1823 | memcpy (output_ecoff->external_dnr + output_symhdr->idnMax, | |
1824 | input_ecoff->external_dnr, | |
1825 | input_symhdr->idnMax * sizeof (struct dnr_ext)); | |
1826 | memcpy (output_ecoff->external_pdr + output_symhdr->ipdMax, | |
1827 | input_ecoff->external_pdr, | |
1828 | input_symhdr->ipdMax * sizeof (struct pdr_ext)); | |
1829 | memcpy (output_ecoff->external_sym + output_symhdr->isymMax, | |
1830 | input_ecoff->external_sym, | |
1831 | input_symhdr->isymMax * sizeof (struct sym_ext)); | |
1832 | memcpy (output_ecoff->external_opt + output_symhdr->ioptMax, | |
1833 | input_ecoff->external_opt, | |
1834 | input_symhdr->ioptMax * sizeof (struct opt_ext)); | |
1835 | } | |
1836 | else | |
1837 | { | |
1838 | struct dnr_ext *dnr_in; | |
1839 | struct dnr_ext *dnr_end; | |
1840 | struct dnr_ext *dnr_out; | |
1841 | struct pdr_ext *pdr_in; | |
1842 | struct pdr_ext *pdr_end; | |
1843 | struct pdr_ext *pdr_out; | |
1844 | struct sym_ext *sym_in; | |
1845 | struct sym_ext *sym_end; | |
1846 | struct sym_ext *sym_out; | |
1847 | struct opt_ext *opt_in; | |
1848 | struct opt_ext *opt_end; | |
1849 | struct opt_ext *opt_out; | |
1850 | ||
1851 | /* The two BFD's have different endianness, so we must swap | |
1852 | everything in and out. This code would always work, but it | |
1853 | would be very slow in the normal case. */ | |
1854 | dnr_in = input_ecoff->external_dnr; | |
1855 | dnr_end = dnr_in + input_symhdr->idnMax; | |
1856 | dnr_out = output_ecoff->external_dnr + output_symhdr->idnMax; | |
1857 | for (; dnr_in < dnr_end; dnr_in++, dnr_out++) | |
1858 | { | |
1859 | DNR dnr; | |
1860 | ||
1861 | ecoff_swap_dnr_in (input_bfd, dnr_in, &dnr); | |
1862 | ecoff_swap_dnr_out (output_bfd, &dnr, dnr_out); | |
1863 | } | |
1864 | pdr_in = input_ecoff->external_pdr; | |
1865 | pdr_end = pdr_in + input_symhdr->ipdMax; | |
1866 | pdr_out = output_ecoff->external_pdr + output_symhdr->ipdMax; | |
1867 | for (; pdr_in < pdr_end; pdr_in++, pdr_out++) | |
1868 | { | |
1869 | PDR pdr; | |
1870 | ||
1871 | ecoff_swap_pdr_in (input_bfd, pdr_in, &pdr); | |
1872 | ecoff_swap_pdr_out (output_bfd, &pdr, pdr_out); | |
1873 | } | |
1874 | sym_in = input_ecoff->external_sym; | |
1875 | sym_end = sym_in + input_symhdr->isymMax; | |
1876 | sym_out = output_ecoff->external_sym + output_symhdr->isymMax; | |
1877 | for (; sym_in < sym_end; sym_in++, sym_out++) | |
1878 | { | |
1879 | SYMR sym; | |
1880 | ||
1881 | ecoff_swap_sym_in (input_bfd, sym_in, &sym); | |
1882 | ecoff_swap_sym_out (output_bfd, &sym, sym_out); | |
1883 | } | |
1884 | opt_in = input_ecoff->external_opt; | |
1885 | opt_end = opt_in + input_symhdr->ioptMax; | |
1886 | opt_out = output_ecoff->external_opt + output_symhdr->ioptMax; | |
1887 | for (; opt_in < opt_end; opt_in++, opt_out++) | |
1888 | { | |
1889 | OPTR opt; | |
1890 | ||
1891 | ecoff_swap_opt_in (input_bfd, opt_in, &opt); | |
1892 | ecoff_swap_opt_out (output_bfd, &opt, opt_out); | |
1893 | } | |
1894 | } | |
1895 | ||
1896 | /* Step through the FDR's of input_bfd, adjust the offsets, and | |
1897 | swap them out. */ | |
1898 | iss = output_symhdr->issMax; | |
1899 | isym = output_symhdr->isymMax; | |
1900 | iline = output_symhdr->ilineMax; | |
1901 | iopt = output_symhdr->ioptMax; | |
1902 | ipdr = output_symhdr->ipdMax; | |
1903 | iaux = output_symhdr->iauxMax; | |
1904 | irfd = output_symhdr->crfd; | |
1905 | cbline = output_symhdr->cbLineOffset; | |
1906 | ||
1907 | fdr_ptr = input_ecoff->fdr; | |
1908 | fdr_end = fdr_ptr + input_symhdr->ifdMax; | |
1909 | fdr_out = output_ecoff->external_fdr + output_symhdr->ifdMax; | |
1910 | for (; fdr_ptr < fdr_end; fdr_ptr++, fdr_out++) | |
1911 | { | |
1912 | FDR fdr; | |
1913 | ||
1914 | fdr = *fdr_ptr; | |
1915 | ||
1916 | /* The memory address for this fdr is the address for the seclet | |
1917 | plus the offset to this fdr within input_bfd. */ | |
1918 | fdr.adr = (bfd_get_section_vma (output_bfd, section) | |
1919 | + seclet->offset | |
1920 | + (fdr_ptr->adr - input_ecoff->fdr->adr)); | |
1921 | ||
1922 | fdr.issBase = iss; | |
1923 | iss += fdr.cbSs * sizeof (char); | |
1924 | fdr.isymBase = isym; | |
1925 | isym += fdr.csym * sizeof (struct sym_ext); | |
1926 | fdr.ilineBase = iline; | |
1927 | iline += fdr.cline; | |
1928 | fdr.ioptBase = iopt; | |
1929 | iopt += fdr.copt * sizeof (struct opt_ext); | |
1930 | fdr.ipdFirst = ipdr; | |
1931 | ipdr += fdr.cpd * sizeof (struct pdr_ext); | |
1932 | fdr.iauxBase = iaux; | |
1933 | iaux += fdr.caux * sizeof (union aux_ext); | |
1934 | fdr.rfdBase = irfd; | |
1935 | irfd += fdr.crfd * sizeof (struct rfd_ext); | |
1936 | fdr.cbLineOffset = cbline; | |
1937 | cbline += fdr.cbLine * sizeof (unsigned char); | |
1938 | ||
1939 | ecoff_swap_fdr_out (output_bfd, &fdr, fdr_out); | |
1940 | } | |
1941 | ||
1942 | if (input_symhdr->crfd > 0) | |
1943 | { | |
1944 | struct rfd_ext *rfd_in; | |
1945 | struct rfd_ext *rfd_end; | |
1946 | struct rfd_ext *rfd_out; | |
1947 | ||
1948 | /* Swap and adjust the RFD's. RFD's are only created by the | |
1949 | linker, so this will only be necessary if one of the input | |
1950 | files is the result of a partial link. Presumably all | |
1951 | necessary RFD's are present. */ | |
1952 | rfd_in = input_ecoff->external_rfd; | |
1953 | rfd_end = rfd_in + input_symhdr->crfd; | |
1954 | rfd_out = output_ecoff->external_rfd + output_symhdr->crfd; | |
1955 | for (; rfd_in < rfd_end; rfd_in++, rfd_out++) | |
1956 | { | |
1957 | RFDT rfd; | |
1958 | ||
1959 | ecoff_swap_rfd_in (input_bfd, rfd_in, &rfd); | |
1960 | rfd += output_symhdr->ifdMax; | |
1961 | ecoff_swap_rfd_out (output_bfd, &rfd, rfd_out); | |
1962 | } | |
1963 | output_symhdr->crfd += input_symhdr->crfd; | |
1964 | } | |
1965 | else | |
1966 | { | |
1967 | struct rfd_ext *rfd_out; | |
1968 | struct rfd_ext *rfd_end; | |
1969 | RFDT rfd; | |
1970 | ||
1971 | /* Create RFD's. Some of the debugging information includes | |
1972 | relative file indices. These indices are taken as indices to | |
1973 | the RFD table if there is one, or to the global table if | |
1974 | there is not. If we did not create RFD's, we would have to | |
1975 | parse and adjust all the debugging information which contains | |
1976 | file indices. */ | |
1977 | rfd = output_symhdr->ifdMax; | |
1978 | rfd_out = output_ecoff->external_rfd + output_symhdr->crfd; | |
1979 | rfd_end = rfd_out + input_symhdr->ifdMax; | |
1980 | for (; rfd_out < rfd_end; rfd_out++, rfd++) | |
1981 | ecoff_swap_rfd_out (output_bfd, &rfd, rfd_out); | |
1982 | output_symhdr->crfd += input_symhdr->ifdMax; | |
1983 | } | |
1984 | ||
1985 | /* We have to swap the external symbols in and out because we have | |
1986 | to adjust the file descriptor indices. */ | |
1987 | ext_ptr = input_ecoff->external_ext; | |
1988 | ext_end = ext_ptr + input_symhdr->iextMax; | |
1989 | ext_out = output_ecoff->external_ext + output_symhdr->iextMax; | |
1990 | for (; ext_ptr < ext_end; ext_ptr++, ext_out++) | |
1991 | { | |
1992 | EXTR ext; | |
1993 | ||
1994 | ecoff_swap_ext_in (input_bfd, ext_ptr, &ext); | |
1995 | ext.ifd += output_symhdr->ifdMax; | |
1996 | ecoff_swap_ext_out (output_bfd, &ext, ext_out); | |
1997 | } | |
1998 | ||
1999 | /* Update the counts. */ | |
2000 | output_symhdr->ilineMax += input_symhdr->ilineMax; | |
2001 | output_symhdr->cbLine += input_symhdr->cbLine; | |
2002 | output_symhdr->idnMax += input_symhdr->idnMax; | |
2003 | output_symhdr->ipdMax += input_symhdr->ipdMax; | |
2004 | output_symhdr->isymMax += input_symhdr->isymMax; | |
2005 | output_symhdr->ioptMax += input_symhdr->ioptMax; | |
2006 | output_symhdr->iauxMax += input_symhdr->iauxMax; | |
2007 | output_symhdr->issMax += input_symhdr->issMax; | |
2008 | output_symhdr->issExtMax += input_symhdr->issExtMax; | |
2009 | output_symhdr->ifdMax += input_symhdr->ifdMax; | |
2010 | output_symhdr->iextMax += input_symhdr->iextMax; | |
2011 | ||
2012 | /* Double check that the counts we got by stepping through the FDR's | |
2013 | match the counts we got from input_symhdr. */ | |
2014 | BFD_ASSERT (output_symhdr->issMax == iss | |
2015 | && output_symhdr->isymMax == isym | |
2016 | && output_symhdr->ilineMax == iline | |
2017 | && output_symhdr->ioptMax == iopt | |
2018 | && output_symhdr->ipdMax == ipdr | |
2019 | && output_symhdr->iauxMax == iaux | |
2020 | && output_symhdr->cbLineOffset == cbline); | |
2021 | ||
2022 | return true; | |
2023 | } | |
2024 | ||
2025 | /* This is the actual link routine. It makes two passes over all the | |
2026 | seclets. */ | |
2027 | ||
2028 | static boolean | |
2029 | DEFUN (ecoff_bfd_seclet_link, (abfd, data, relocateable), | |
2030 | bfd *abfd AND | |
2031 | PTR data AND | |
2032 | boolean relocateable) | |
2033 | { | |
2034 | HDRR *symhdr; | |
2035 | int ipass; | |
2036 | register asection *o; | |
2037 | register bfd_seclet_type *p; | |
2038 | bfd_size_type size; | |
2039 | char *raw; | |
2040 | ||
2041 | /* We accumulate the debugging information counts in the symbolic | |
2042 | header. */ | |
2043 | symhdr = &ecoff_data (abfd)->symbolic_header; | |
2044 | symhdr->ilineMax = 0; | |
2045 | symhdr->cbLine = 0; | |
2046 | symhdr->idnMax = 0; | |
2047 | symhdr->ipdMax = 0; | |
2048 | symhdr->isymMax = 0; | |
2049 | symhdr->ioptMax = 0; | |
2050 | symhdr->iauxMax = 0; | |
2051 | symhdr->issMax = 0; | |
2052 | symhdr->issExtMax = 0; | |
2053 | symhdr->ifdMax = 0; | |
2054 | symhdr->crfd = 0; | |
2055 | symhdr->iextMax = 0; | |
2056 | ||
2057 | /* We are only going to look at each input BFD once. It is | |
2058 | convenient to look at the code section first, so that the first | |
2059 | time we look at a BFD we can set the text address (otherwise, | |
2060 | when we get to the text section, we would have to be able to | |
2061 | track down the file information associated with that BFD). So we | |
2062 | actually do each pass in two sub passes; first the code sections, | |
2063 | then the non-code sections. */ | |
2064 | ||
2065 | /* Do the first pass: set the output section contents and count the | |
2066 | debugging information. */ | |
2067 | ecoff_clear_output_flags (abfd); | |
2068 | for (ipass = 0; ipass < 2; ipass++) | |
2069 | { | |
2070 | for (o = abfd->sections; o != (asection *) NULL; o = o->next) | |
2071 | { | |
2072 | /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false, | |
2073 | so they are done on pass 0. For other sections the | |
2074 | expression is true, so they are done on pass 1. */ | |
2075 | if (((o->flags & SEC_CODE) == 0) != ipass) | |
2076 | continue; | |
2077 | ||
2078 | for (p = o->seclets_head; | |
2079 | p != (bfd_seclet_type *) NULL; | |
2080 | p = p->next) | |
2081 | { | |
2082 | if (ecoff_dump_seclet (abfd, p, o, data, relocateable) | |
2083 | == false) | |
2084 | return false; | |
2085 | } | |
2086 | } | |
2087 | } | |
2088 | ||
2089 | /* Now the counts in symhdr are the correct size for the debugging | |
2090 | information. We allocate the right amount of space, and reset | |
2091 | the counts so that the second pass can use them as indices. It | |
2092 | would be possible to output the debugging information directly to | |
2093 | the file in pass 2, rather than to build it in memory and then | |
2094 | write it out. Outputting to the file would require a lot of | |
2095 | seeks and small writes, though, and I think this approach is | |
2096 | faster. */ | |
2097 | size = (symhdr->cbLine * sizeof (unsigned char) | |
2098 | + symhdr->idnMax * sizeof (struct dnr_ext) | |
2099 | + symhdr->ipdMax * sizeof (struct pdr_ext) | |
2100 | + symhdr->isymMax * sizeof (struct sym_ext) | |
2101 | + symhdr->ioptMax * sizeof (struct opt_ext) | |
2102 | + symhdr->iauxMax * sizeof (union aux_ext) | |
2103 | + symhdr->issMax * sizeof (char) | |
2104 | + symhdr->issExtMax * sizeof (char) | |
2105 | + symhdr->ifdMax * sizeof (struct fdr_ext) | |
2106 | + symhdr->crfd * sizeof (struct rfd_ext) | |
2107 | + symhdr->iextMax * sizeof (struct ext_ext)); | |
2108 | raw = (char *) bfd_alloc (abfd, size); | |
2109 | if (raw == (char *) NULL) | |
2110 | { | |
2111 | bfd_error = no_memory; | |
2112 | return false; | |
2113 | } | |
2114 | ecoff_data (abfd)->raw_size = size; | |
2115 | ecoff_data (abfd)->raw_syments = (PTR) raw; | |
2116 | ||
2117 | /* Initialize the raw pointers. */ | |
2118 | #define SET(field, count, type) \ | |
2119 | ecoff_data (abfd)->field = (type *) raw; \ | |
2120 | raw += symhdr->count * sizeof (type) | |
2121 | ||
2122 | SET (line, cbLine, unsigned char); | |
2123 | SET (external_dnr, idnMax, struct dnr_ext); | |
2124 | SET (external_pdr, ipdMax, struct pdr_ext); | |
2125 | SET (external_sym, isymMax, struct sym_ext); | |
2126 | SET (external_opt, ioptMax, struct opt_ext); | |
2127 | SET (external_aux, iauxMax, union aux_ext); | |
2128 | SET (ss, issMax, char); | |
2129 | SET (ssext, issExtMax, char); | |
2130 | SET (external_fdr, ifdMax, struct fdr_ext); | |
2131 | SET (external_rfd, crfd, struct rfd_ext); | |
2132 | SET (external_ext, iextMax, struct ext_ext); | |
2133 | #undef SET | |
2134 | ||
2135 | /* Reset the counts so the second pass can use them to know how far | |
2136 | it has gotten. */ | |
2137 | symhdr->ilineMax = 0; | |
2138 | symhdr->cbLine = 0; | |
2139 | symhdr->idnMax = 0; | |
2140 | symhdr->ipdMax = 0; | |
2141 | symhdr->isymMax = 0; | |
2142 | symhdr->ioptMax = 0; | |
2143 | symhdr->iauxMax = 0; | |
2144 | symhdr->issMax = 0; | |
2145 | symhdr->issExtMax = 0; | |
2146 | symhdr->ifdMax = 0; | |
2147 | symhdr->crfd = 0; | |
2148 | symhdr->iextMax = 0; | |
2149 | ||
2150 | /* Do the second pass: accumulate the debugging information. */ | |
2151 | ecoff_clear_output_flags (abfd); | |
2152 | for (ipass = 0; ipass < 2; ipass++) | |
2153 | { | |
2154 | for (o = abfd->sections; o != (asection *) NULL; o = o->next) | |
2155 | { | |
2156 | if (((o->flags & SEC_CODE) == 0) != ipass) | |
2157 | continue; | |
2158 | for (p = o->seclets_head; | |
2159 | p != (bfd_seclet_type *) NULL; | |
2160 | p = p->next) | |
2161 | { | |
2162 | if (p->type == bfd_indirect_seclet) | |
2163 | { | |
2164 | if (ecoff_get_debug (abfd, p, o) == false) | |
2165 | return false; | |
2166 | } | |
2167 | } | |
2168 | } | |
2169 | } | |
2170 | ||
2171 | return true; | |
2172 | } | |
2173 | \f | |
2174 | /* Set the architecture. The only architecture we support here is | |
2175 | mips. We set the architecture anyhow, since many callers ignore | |
2176 | the return value. */ | |
2177 | ||
2178 | static boolean | |
2179 | DEFUN (ecoff_set_arch_mach, (abfd, arch, machine), | |
2180 | bfd *abfd AND | |
2181 | enum bfd_architecture arch AND | |
2182 | unsigned long machine) | |
2183 | { | |
2184 | bfd_default_set_arch_mach (abfd, arch, machine); | |
2185 | return arch == bfd_arch_mips; | |
2186 | } | |
2187 | ||
2188 | /* Calculate the file position for each section, and set | |
2189 | reloc_filepos. */ | |
2190 | ||
2191 | static void | |
2192 | DEFUN (ecoff_compute_section_file_positions, (abfd), | |
2193 | bfd *abfd) | |
2194 | { | |
2195 | asection *current; | |
2196 | asection *previous; | |
2197 | file_ptr sofar; | |
2198 | file_ptr old_sofar; | |
2199 | ||
2200 | sofar = FILHSZ; | |
2201 | ||
2202 | if (bfd_get_start_address (abfd)) | |
2203 | { | |
2204 | /* A start address may have been added to the original file. In | |
2205 | this case it will need an optional header to record it. */ | |
2206 | abfd->flags |= EXEC_P; | |
2207 | } | |
2208 | ||
2209 | if (abfd->flags & EXEC_P) | |
2210 | sofar += AOUTSZ; | |
2211 | ||
2212 | sofar += abfd->section_count * SCNHSZ; | |
2213 | ||
2214 | previous = (asection *) NULL; | |
2215 | for (current = abfd->sections; | |
2216 | current != (asection *) NULL; | |
2217 | current = current->next) | |
2218 | { | |
2219 | /* Only deal with sections which have contents */ | |
2220 | if (! (current->flags & SEC_HAS_CONTENTS)) | |
2221 | continue; | |
2222 | ||
2223 | /* Align the sections in the file to the same boundary on | |
2224 | which they are aligned in virtual memory. */ | |
2225 | old_sofar = sofar; | |
2226 | sofar = BFD_ALIGN (sofar, 1 << current->alignment_power); | |
2227 | if (previous != (asection *) NULL) | |
2228 | previous->_raw_size += sofar - old_sofar; | |
2229 | ||
2230 | current->filepos = sofar; | |
2231 | ||
2232 | sofar += current->_raw_size; | |
2233 | ||
2234 | /* make sure that this section is of the right size too */ | |
2235 | old_sofar = sofar; | |
2236 | sofar = BFD_ALIGN (sofar, 1 << current->alignment_power); | |
2237 | current->_raw_size += sofar - old_sofar; | |
2238 | previous = current; | |
2239 | } | |
2240 | ||
2241 | ecoff_data (abfd)->reloc_filepos = sofar; | |
2242 | } | |
2243 | ||
2244 | /* Set the contents of a section. */ | |
2245 | ||
2246 | static boolean | |
2247 | DEFUN (ecoff_set_section_contents, (abfd, section, location, offset, count), | |
2248 | bfd *abfd AND | |
2249 | sec_ptr section AND | |
2250 | PTR location AND | |
2251 | file_ptr offset AND | |
2252 | bfd_size_type count) | |
2253 | { | |
2254 | if (abfd->output_has_begun == false) | |
2255 | ecoff_compute_section_file_positions (abfd); | |
2256 | ||
2257 | bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET); | |
2258 | ||
2259 | if (count != 0) | |
2260 | return (bfd_write (location, 1, count, abfd) == count) ? true : false; | |
2261 | ||
2262 | return true; | |
2263 | } | |
2264 | ||
2265 | /* Write out an ECOFF file. */ | |
2266 | ||
2267 | static boolean | |
2268 | DEFUN (ecoff_write_object_contents, (abfd), | |
2269 | bfd *abfd) | |
2270 | { | |
2271 | asection *current; | |
2272 | unsigned int count; | |
2273 | file_ptr scn_base; | |
2274 | file_ptr reloc_base; | |
2275 | file_ptr sym_base; | |
2276 | unsigned long reloc_size; | |
2277 | unsigned long text_size; | |
2278 | unsigned long text_start; | |
2279 | unsigned long data_size; | |
2280 | unsigned long data_start; | |
2281 | unsigned long bss_size; | |
2282 | struct internal_filehdr internal_f; | |
2283 | struct internal_aouthdr internal_a; | |
2284 | ||
2285 | bfd_error = system_call_error; | |
2286 | ||
2287 | if(abfd->output_has_begun == false) | |
2288 | ecoff_compute_section_file_positions(abfd); | |
2289 | ||
2290 | if (abfd->sections != (asection *) NULL) | |
2291 | scn_base = abfd->sections->filepos; | |
2292 | else | |
2293 | scn_base = 0; | |
2294 | reloc_base = ecoff_data (abfd)->reloc_filepos; | |
2295 | ||
2296 | count = 1; | |
2297 | reloc_size = 0; | |
2298 | for (current = abfd->sections; | |
2299 | current != (asection *)NULL; | |
2300 | current = current->next) | |
2301 | { | |
2302 | current->target_index = count; | |
2303 | ++count; | |
2304 | if (current->reloc_count != 0) | |
2305 | { | |
2306 | bfd_size_type relsize; | |
2307 | ||
2308 | current->rel_filepos = reloc_base; | |
2309 | relsize = current->reloc_count * RELSZ; | |
2310 | reloc_size += relsize; | |
2311 | reloc_base += relsize; | |
2312 | } | |
2313 | else | |
2314 | current->rel_filepos = 0; | |
2315 | } | |
2316 | ||
2317 | sym_base = reloc_base + reloc_size; | |
2318 | ecoff_data (abfd)->sym_filepos = sym_base; | |
2319 | ||
2320 | text_size = 0; | |
2321 | text_start = 0; | |
2322 | data_size = 0; | |
2323 | data_start = 0; | |
2324 | bss_size = 0; | |
2325 | ||
2326 | /* Write section headers to the file. */ | |
2327 | ||
2328 | internal_f.f_nscns = 0; | |
2329 | if (bfd_seek (abfd, | |
2330 | (file_ptr) ((abfd->flags & EXEC_P) ? | |
2331 | (FILHSZ + AOUTSZ) : FILHSZ), | |
2332 | SEEK_SET) != 0) | |
2333 | return false; | |
2334 | for (current = abfd->sections; | |
2335 | current != (asection *) NULL; | |
2336 | current = current->next) | |
2337 | { | |
2338 | struct internal_scnhdr section; | |
2339 | bfd_vma vma; | |
2340 | ||
2341 | ++internal_f.f_nscns; | |
2342 | ||
2343 | strncpy (section.s_name, current->name, sizeof section.s_name); | |
2344 | ||
2345 | /* FIXME: is this correct for shared libraries? I think it is | |
2346 | but I have no platform to check. Ian Lance Taylor. */ | |
2347 | vma = bfd_get_section_vma (abfd, current); | |
2348 | if (strcmp (current->name, _LIB) == 0) | |
2349 | section.s_vaddr = 0; | |
2350 | else | |
2351 | section.s_vaddr = vma; | |
2352 | ||
2353 | section.s_paddr = vma; | |
2354 | section.s_size = bfd_get_section_size_before_reloc (current); | |
2355 | ||
2356 | /* If this section has no size or is unloadable then the scnptr | |
2357 | will be 0 too. */ | |
2358 | if (current->_raw_size == 0 | |
2359 | || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0) | |
2360 | section.s_scnptr = 0; | |
2361 | else | |
2362 | section.s_scnptr = current->filepos; | |
2363 | section.s_relptr = current->rel_filepos; | |
2364 | ||
2365 | /* FIXME: the lnnoptr of the .sbss or .sdata section of an | |
2366 | object file produced by the assembler is supposed to point to | |
2367 | information about how much room is required by objects of | |
2368 | various different sizes. I think this only matters if we | |
2369 | want the linker to compute the best size to use, or | |
2370 | something. I don't know what happens if the information is | |
2371 | not present. */ | |
2372 | section.s_lnnoptr = 0; | |
2373 | ||
2374 | section.s_nreloc = current->reloc_count; | |
2375 | section.s_nlnno = 0; | |
2376 | section.s_flags = sec_to_styp_flags (current->name, current->flags); | |
2377 | ||
2378 | { | |
2379 | SCNHDR buff; | |
2380 | ||
2381 | ecoff_swap_scnhdr_out (abfd, (PTR) §ion, (PTR) &buff); | |
2382 | if (bfd_write ((PTR) &buff, 1, SCNHSZ, abfd) != SCNHSZ) | |
2383 | return false; | |
2384 | } | |
2385 | ||
2386 | /* FIXME: These numbers don't add up to what the MIPS tools | |
2387 | produce, although I don't think it matters. */ | |
2388 | if ((section.s_flags & STYP_TEXT) != 0 | |
2389 | || (section.s_flags & STYP_RDATA) != 0 | |
2390 | || (section.s_flags & STYP_LIT8) != 0 | |
2391 | || (section.s_flags & STYP_LIT4) != 0) | |
2392 | { | |
2393 | text_size += bfd_get_section_size_before_reloc (current); | |
2394 | if (text_start == 0 || text_start > vma) | |
2395 | text_start = vma; | |
2396 | } | |
2397 | else if ((section.s_flags & STYP_DATA) != 0 | |
2398 | || (section.s_flags & STYP_SDATA) != 0) | |
2399 | { | |
2400 | data_size += bfd_get_section_size_before_reloc (current); | |
2401 | if (data_start == 0 || data_start > vma) | |
2402 | data_start = vma; | |
2403 | } | |
2404 | else if ((section.s_flags & STYP_BSS) != 0 | |
2405 | || (section.s_flags & STYP_SBSS) != 0) | |
2406 | bss_size += bfd_get_section_size_before_reloc (current); | |
2407 | } | |
2408 | ||
2409 | /* Set up the file header. */ | |
2410 | ||
2411 | internal_f.f_magic = MIPS_MAGIC_2; | |
2412 | ||
2413 | /* | |
2414 | We will NOT put a fucking timestamp in the header here. Every time you | |
2415 | put it back, I will come in and take it out again. I'm sorry. This | |
2416 | field does not belong here. We fill it with a 0 so it compares the | |
2417 | same but is not a reasonable time. -- gnu@cygnus.com | |
2418 | */ | |
2419 | internal_f.f_timdat = 0; | |
2420 | ||
2421 | internal_f.f_nsyms = bfd_get_symcount(abfd); | |
2422 | if (internal_f.f_nsyms != 0) | |
2423 | internal_f.f_symptr = sym_base; | |
2424 | else | |
2425 | internal_f.f_symptr = 0; | |
2426 | ||
2427 | if (abfd->flags & EXEC_P) | |
2428 | internal_f.f_opthdr = AOUTSZ; | |
2429 | else | |
2430 | internal_f.f_opthdr = 0; | |
2431 | ||
2432 | internal_f.f_flags = 0; | |
2433 | if (reloc_size == 0) | |
2434 | internal_f.f_flags |= F_RELFLG; | |
2435 | if (bfd_get_symcount (abfd) == 0) | |
2436 | internal_f.f_flags |= F_LSYMS; | |
2437 | if (abfd->flags & EXEC_P) | |
2438 | internal_f.f_flags |= F_EXEC; | |
2439 | ||
2440 | if (! abfd->xvec->byteorder_big_p) | |
2441 | internal_f.f_flags |= F_AR32WR; | |
2442 | else | |
2443 | internal_f.f_flags |= F_AR32W; | |
2444 | ||
2445 | /* Set up the optional header. */ | |
2446 | ||
2447 | if ((abfd->flags & EXEC_P) != 0) | |
2448 | { | |
2449 | internal_a.magic = ZMAGIC; | |
2450 | ||
2451 | /* FIXME: What should this be? */ | |
2452 | internal_a.vstamp = 0; | |
2453 | ||
2454 | internal_a.tsize = text_size; | |
2455 | internal_a.text_start = text_start; | |
2456 | internal_a.dsize = data_size; | |
2457 | internal_a.data_start = data_start; | |
2458 | internal_a.bsize = bss_size; | |
2459 | ||
2460 | internal_a.entry = bfd_get_start_address (abfd); | |
2461 | ||
2462 | /* FIXME: The MIPS optional header is larger than this.... */ | |
2463 | } | |
2464 | ||
2465 | /* Write out the file header and the optional header. */ | |
2466 | ||
2467 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) | |
2468 | return false; | |
2469 | ||
2470 | { | |
2471 | FILHDR buff; | |
2472 | ecoff_swap_filehdr_out (abfd, (PTR) &internal_f, (PTR) &buff); | |
2473 | if (bfd_write ((PTR) &buff, 1, FILHSZ, abfd) != FILHSZ) | |
2474 | return false; | |
2475 | } | |
2476 | ||
2477 | if ((abfd->flags & EXEC_P) != 0) | |
2478 | { | |
2479 | AOUTHDR buff; | |
2480 | ||
2481 | ecoff_swap_aouthdr_out (abfd, (PTR) &internal_a, (PTR) &buff); | |
2482 | if (bfd_write ((PTR) &buff, 1, AOUTSZ, abfd) != AOUTSZ) | |
2483 | return false; | |
2484 | } | |
2485 | ||
2486 | /* Write out the relocs. */ | |
2487 | ||
2488 | /* Write out the symbolic debugging information. */ | |
2489 | if (bfd_get_symcount (abfd) > 0) | |
2490 | { | |
2491 | struct hdr_ext buff; | |
2492 | ||
2493 | ecoff_swap_hdr_out (abfd, &ecoff_data (abfd)->symbolic_header, &buff); | |
2494 | if (bfd_write ((PTR) &buff, 1, sizeof buff, abfd) != sizeof buff) | |
2495 | return false; | |
2496 | if (bfd_write ((PTR) ecoff_data (abfd)->raw_syments, 1, | |
2497 | ecoff_data (abfd)->raw_size, abfd) | |
2498 | != ecoff_data (abfd)->raw_size) | |
2499 | return false; | |
2500 | } | |
2501 | ||
2502 | return true; | |
2503 | } | |
2504 | \f | |
515c4292 ILT |
2505 | static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table = { |
2506 | (void (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_in */ | |
2507 | (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */ | |
2508 | (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */ | |
2509 | (unsigned (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_out */ | |
2510 | (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */ | |
2511 | (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */ | |
2512 | ecoff_swap_reloc_out, ecoff_swap_filehdr_out, ecoff_swap_aouthdr_out, | |
2513 | ecoff_swap_scnhdr_out, | |
2514 | FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, true, | |
2515 | ecoff_swap_filehdr_in, ecoff_swap_aouthdr_in, ecoff_swap_scnhdr_in, | |
2516 | ecoff_bad_format_hook, ecoff_set_arch_mach_hook, ecoff_mkobject_hook, | |
2517 | styp_to_sec_flags, ecoff_make_section_hook, ecoff_set_alignment_hook, | |
2518 | ecoff_slurp_symbol_table | |
2519 | }; | |
2520 | ||
2521 | /* Routines that need to be written. */ | |
515c4292 | 2522 | #define ecoff_canonicalize_reloc (unsigned int (*) PARAMS ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry **))) bfd_0 |
515c4292 ILT |
2523 | |
2524 | /* get_lineno could be written for ECOFF, but it would currently only | |
2525 | be useful for linking ECOFF and COFF files together, which doesn't | |
2526 | seem too likely. */ | |
8fa0d3a0 ILT |
2527 | #define ecoff_get_lineno \ |
2528 | ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr) | |
515c4292 ILT |
2529 | |
2530 | #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command | |
2531 | #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal | |
2532 | #define ecoff_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p | |
2533 | #define ecoff_slurp_armap bfd_slurp_coff_armap | |
2534 | #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table | |
2535 | #define ecoff_write_armap coff_write_armap | |
2536 | #define ecoff_truncate_arname bfd_dont_truncate_arname | |
2537 | #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file | |
2538 | #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt | |
2539 | #define ecoff_get_section_contents bfd_generic_get_section_contents | |
8fa0d3a0 | 2540 | #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound |
515c4292 | 2541 | #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup |
8fa0d3a0 | 2542 | #define ecoff_sizeof_headers coff_sizeof_headers |
515c4292 | 2543 | #define ecoff_bfd_debug_info_start bfd_void |
8fa0d3a0 | 2544 | #define ecoff_bfd_debug_info_end bfd_void |
515c4292 | 2545 | #define ecoff_bfd_debug_info_accumulate \ |
8fa0d3a0 | 2546 | ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void) |
515c4292 ILT |
2547 | #define ecoff_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents |
2548 | #define ecoff_bfd_relax_section bfd_generic_relax_section | |
c9301d7b | 2549 | |
1327fb29 | 2550 | bfd_target ecoff_little_vec = |
294eaca4 SC |
2551 | { |
2552 | "ecoff-littlemips", /* name */ | |
515c4292 | 2553 | bfd_target_ecoff_flavour, |
294eaca4 SC |
2554 | false, /* data byte order is little */ |
2555 | false, /* header byte order is little */ | |
2556 | ||
2557 | (HAS_RELOC | EXEC_P | /* object flags */ | |
2558 | HAS_LINENO | HAS_DEBUG | | |
2559 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT), | |
2560 | ||
2561 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect | |
2562 | flags */ | |
2563 | 0, /* leading underscore */ | |
2564 | '/', /* ar_pad_char */ | |
2565 | 15, /* ar_max_namelen */ | |
2566 | 3, /* minimum alignment power */ | |
2567 | _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */ | |
2568 | _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */ | |
2569 | ||
515c4292 | 2570 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ |
294eaca4 | 2571 | bfd_generic_archive_p, _bfd_dummy_target}, |
515c4292 | 2572 | {bfd_false, ecoff_mkobject, bfd_false, /* bfd_set_format */ |
294eaca4 | 2573 | bfd_false}, |
515c4292 ILT |
2574 | {bfd_false, ecoff_write_object_contents, bfd_false, bfd_false}, |
2575 | JUMP_TABLE (ecoff), | |
2576 | 0, 0, | |
2577 | (PTR) &bfd_ecoff_std_swap_table | |
2578 | }; | |
1327fb29 SC |
2579 | |
2580 | bfd_target ecoff_big_vec = | |
294eaca4 SC |
2581 | { |
2582 | "ecoff-bigmips", /* name */ | |
515c4292 | 2583 | bfd_target_ecoff_flavour, |
294eaca4 SC |
2584 | true, /* data byte order is big */ |
2585 | true, /* header byte order is big */ | |
2586 | ||
2587 | (HAS_RELOC | EXEC_P | /* object flags */ | |
2588 | HAS_LINENO | HAS_DEBUG | | |
2589 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT), | |
2590 | ||
2591 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect flags */ | |
2592 | 0, /* leading underscore */ | |
2593 | ' ', /* ar_pad_char */ | |
2594 | 16, /* ar_max_namelen */ | |
2595 | 3, /* minimum alignment power */ | |
2596 | _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, | |
2597 | _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, | |
2598 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ | |
2599 | bfd_generic_archive_p, _bfd_dummy_target}, | |
515c4292 | 2600 | {bfd_false, ecoff_mkobject, bfd_false, /* bfd_set_format */ |
294eaca4 | 2601 | bfd_false}, |
515c4292 | 2602 | {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */ |
294eaca4 | 2603 | bfd_false, bfd_false}, |
515c4292 ILT |
2604 | JUMP_TABLE(ecoff), |
2605 | 0, 0, | |
2606 | (PTR) &bfd_ecoff_std_swap_table | |
2607 | /* Note that there is another bfd_target just above this one. If | |
2608 | you are adding initializers here, you should be adding them there | |
2609 | as well. */ | |
2610 | }; |