Commit | Line | Data |
---|---|---|
1f29e30b JG |
1 | /* BFD back-end for MIPS Extended-Coff files. |
2 | Copyright 1990, 1991, 1992 Free Software Foundation, Inc. | |
68b70212 | 3 | Written by Per Bothner. |
515c4292 | 4 | Symbol and line number support added by Ian Lance Taylor. |
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" |
294eaca4 SC |
25 | #include "coff/mips.h" |
26 | #include "coff/internal.h" | |
515c4292 ILT |
27 | #include "coff/sym.h" |
28 | #include "coff/symconst.h" | |
29 | #include "coff/ecoff-ext.h" | |
30 | #include "libcoff.h" | |
31 | ||
32 | /* `Tdata' information kept for ECOFF files. */ | |
33 | ||
34 | #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data) | |
35 | ||
36 | typedef struct ecoff_tdata | |
37 | { | |
38 | /* The symbol table file position. */ | |
39 | file_ptr sym_filepos; | |
40 | ||
41 | /* The unswapped ECOFF symbolic information. */ | |
42 | PTR raw_syments; | |
43 | ||
44 | /* The swapped ECOFF symbolic header. */ | |
45 | HDRR symbolic_header; | |
46 | ||
47 | /* Pointers to the unswapped symbolic information. */ | |
48 | unsigned char *line; | |
49 | struct dnr_ext *external_dnr; | |
50 | struct pdr_ext *external_pdr; | |
51 | struct sym_ext *external_sym; | |
52 | struct opt_ext *external_opt; | |
53 | union aux_ext *external_aux; | |
54 | char *ss; | |
55 | char *ssext; | |
56 | struct fdr_ext *external_fdr; | |
57 | struct rfd_ext *external_rfd; | |
58 | struct ext_ext *external_ext; | |
59 | ||
60 | /* The swapped fdr information. */ | |
61 | FDR *fdr; | |
62 | ||
63 | /* The canonical BFD symbols. */ | |
64 | struct ecoff_symbol_struct *canonical_symbols; | |
65 | ||
66 | } ecoff_data_type; | |
67 | ||
68 | /* Each canonical asymbol really looks like this. */ | |
69 | ||
70 | typedef struct ecoff_symbol_struct | |
71 | { | |
72 | /* The actual symbol which the rest of BFD works with */ | |
73 | asymbol symbol; | |
74 | ||
75 | /* The fdr for this symbol. */ | |
76 | FDR *fdr; | |
77 | ||
78 | /* true if this is a local symbol rather than an external one. */ | |
79 | boolean local; | |
80 | ||
81 | /* A pointer to the unswapped hidden information for this symbol */ | |
82 | union | |
83 | { | |
84 | struct sym_ext *lnative; | |
85 | struct ext_ext *enative; | |
86 | } | |
87 | native; | |
88 | } ecoff_symbol_type; | |
89 | ||
90 | /* We take the address of the first element of a asymbol to ensure that the | |
91 | macro is only ever applied to an asymbol. */ | |
92 | #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd))) | |
93 | ||
94 | /* MIPS ECOFF has COFF sections, but the debugging information is | |
95 | stored in a completely different format. This files uses the some | |
96 | of the swapping routines from coffswap.h, and some of the generic | |
97 | COFF routines in coffgen.c, but, unlike the real COFF targets, does | |
98 | not use coffcode.h itself. */ | |
99 | ||
100 | /* Get the generic COFF swapping routines, except for the symbol and | |
101 | lineno ones. Give them ecoff names. */ | |
102 | #define NO_COFF_SYMBOLS | |
103 | #define NO_COFF_LINENOS | |
104 | #define coff_swap_reloc_in ecoff_swap_reloc_in | |
105 | #define coff_swap_reloc_out ecoff_swap_reloc_out | |
106 | #define coff_swap_filehdr_in ecoff_swap_filehdr_in | |
107 | #define coff_swap_filehdr_out ecoff_swap_filehdr_out | |
108 | #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in | |
109 | #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out | |
110 | #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in | |
111 | #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out | |
112 | #include "coffswap.h" | |
113 | \f | |
114 | /* This stuff is somewhat copied from coffcode.h. */ | |
115 | ||
116 | static asection bfd_debug_section = { "*DEBUG*" }; | |
117 | ||
118 | /* See whether the magic number matches. */ | |
119 | ||
120 | static boolean | |
121 | DEFUN(ecoff_bad_format_hook, (abfd, filehdr), | |
122 | bfd *abfd AND | |
123 | PTR filehdr) | |
124 | { | |
125 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
126 | ||
127 | if (ECOFFBADMAG (*internal_f)) | |
128 | return false; | |
129 | ||
130 | return true; | |
131 | } | |
132 | ||
133 | /* This is a hook needed by SCO COFF, but we have nothing to do. */ | |
134 | ||
135 | static asection * | |
136 | DEFUN (ecoff_make_section_hook, (abfd, name), | |
137 | bfd *abfd AND | |
138 | char *name) | |
139 | { | |
140 | return (asection *) NULL; | |
141 | } | |
142 | ||
143 | /* Initialize a new section. */ | |
144 | ||
145 | static boolean | |
146 | DEFUN (ecoff_new_section_hook, (abfd, section), | |
147 | bfd *abfd AND | |
148 | asection *section) | |
149 | { | |
150 | section->alignment_power = abfd->xvec->align_power_min; | |
151 | return true; | |
152 | } | |
153 | ||
154 | #define ecoff_set_alignment_hook \ | |
155 | ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void) | |
156 | ||
157 | static boolean | |
158 | DEFUN (ecoff_mkobject, (abfd), | |
159 | bfd *abfd) | |
160 | { | |
161 | abfd->tdata.ecoff_obj_data = ((struct ecoff_tdata *) | |
162 | bfd_zalloc (abfd, sizeof(ecoff_data_type))); | |
163 | if (abfd->tdata.ecoff_obj_data == NULL) | |
164 | { | |
165 | bfd_error = no_memory; | |
166 | return false; | |
167 | } | |
168 | ||
169 | return true; | |
170 | } | |
171 | ||
172 | /* Create the COFF backend specific information. */ | |
173 | ||
174 | static PTR | |
175 | DEFUN(ecoff_mkobject_hook,(abfd, filehdr), | |
176 | bfd *abfd AND | |
177 | PTR filehdr) | |
178 | { | |
179 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
180 | ecoff_data_type *ecoff; | |
181 | ||
182 | if (ecoff_mkobject (abfd) == false) | |
183 | return NULL; | |
184 | ||
185 | ecoff = ecoff_data (abfd); | |
186 | ecoff->sym_filepos = internal_f->f_symptr; | |
187 | return (PTR) ecoff; | |
188 | } | |
189 | ||
190 | /* Determine the machine architecture and type. */ | |
191 | static boolean | |
192 | DEFUN (ecoff_set_arch_mach_hook, (abfd, filehdr), | |
193 | bfd *abfd AND | |
194 | PTR filehdr) | |
195 | { | |
196 | long machine; | |
197 | enum bfd_architecture arch; | |
198 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
199 | ||
200 | machine = 0; | |
201 | switch (internal_f->f_magic) { | |
202 | case MIPS_MAGIC_1: | |
203 | case MIPS_MAGIC_2: | |
204 | case MIPS_MAGIC_3: | |
205 | arch = bfd_arch_mips; | |
206 | machine = 0; | |
207 | break; | |
208 | ||
209 | default: /* Unreadable input file type */ | |
210 | arch = bfd_arch_obscure; | |
211 | break; | |
212 | } | |
213 | ||
214 | bfd_default_set_arch_mach(abfd, arch, machine); | |
215 | return true; | |
216 | } | |
217 | ||
218 | /* Get the BFD flags to use for a section. */ | |
219 | ||
220 | static flagword | |
221 | DEFUN(styp_to_sec_flags, (abfd, hdr), | |
222 | bfd *abfd AND | |
223 | PTR hdr) | |
224 | { | |
225 | struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr; | |
226 | long styp_flags = internal_s->s_flags; | |
227 | flagword sec_flags=0; | |
228 | ||
229 | if (styp_flags & STYP_NOLOAD) | |
230 | sec_flags |= SEC_NEVER_LOAD; | |
231 | ||
232 | /* For 386 COFF, at least, an unloadable text or data section is | |
233 | actually a shared library section. */ | |
234 | if (styp_flags & STYP_TEXT) | |
235 | { | |
236 | if (sec_flags & SEC_NEVER_LOAD) | |
237 | sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY; | |
238 | else | |
239 | sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC; | |
240 | } | |
241 | else if ((styp_flags & STYP_DATA) | |
242 | || (styp_flags & STYP_RDATA) | |
243 | || (styp_flags & STYP_SDATA)) | |
244 | { | |
245 | if (sec_flags & SEC_NEVER_LOAD) | |
246 | sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY; | |
247 | else | |
248 | sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC; | |
249 | if (styp_flags & STYP_RDATA) | |
250 | sec_flags |= SEC_READONLY; | |
251 | } | |
252 | else if ((styp_flags & STYP_BSS) | |
253 | || (styp_flags & STYP_SBSS)) | |
254 | { | |
255 | sec_flags |= SEC_ALLOC; | |
256 | } | |
257 | else if (styp_flags & STYP_INFO) | |
258 | { | |
259 | sec_flags |= SEC_NEVER_LOAD; | |
260 | } | |
261 | else if ((styp_flags & STYP_LIT8) | |
262 | || (styp_flags & STYP_LIT4)) | |
263 | { | |
264 | sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY; | |
265 | } | |
266 | else | |
267 | { | |
268 | sec_flags |= SEC_ALLOC | SEC_LOAD; | |
269 | } | |
270 | ||
271 | return sec_flags; | |
272 | } | |
273 | \f | |
274 | /* ECOFF symbol table routines. The ECOFF symbol table is described | |
275 | in gcc/mips-tfile.c. */ | |
276 | ||
277 | /* Create an empty symbol. */ | |
278 | ||
279 | static asymbol * | |
280 | DEFUN (ecoff_make_empty_symbol, (abfd), | |
281 | bfd *abfd) | |
282 | { | |
283 | ecoff_symbol_type *new; | |
284 | ||
285 | new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type)); | |
286 | if (new == (ecoff_symbol_type *) NULL) | |
287 | { | |
288 | bfd_error = no_memory; | |
289 | return (asymbol *) NULL; | |
290 | } | |
291 | new->symbol.section = (asection *) NULL; | |
292 | new->fdr = (FDR *) NULL; | |
293 | new->local = false; | |
294 | new->native.lnative = (struct sym_ext *) NULL; | |
295 | new->symbol.the_bfd = abfd; | |
296 | return &new->symbol; | |
297 | } | |
298 | ||
299 | /* Set the BFD flags and section for an ECOFF symbol. */ | |
300 | ||
301 | static void | |
302 | DEFUN (ecoff_set_symbol_info, (abfd, ecoff_sym, asym, ext), | |
303 | bfd *abfd AND | |
304 | SYMR *ecoff_sym AND | |
305 | asymbol *asym AND | |
306 | int ext) | |
307 | { | |
308 | asym->the_bfd = abfd; | |
309 | asym->value = ecoff_sym->value; | |
310 | asym->section = &bfd_debug_section; | |
311 | asym->udata = NULL; | |
312 | if (ext) | |
313 | asym->flags = BSF_EXPORT | BSF_GLOBAL; | |
314 | else | |
315 | asym->flags = BSF_LOCAL; | |
316 | switch (ecoff_sym->sc) | |
317 | { | |
318 | case scNil: | |
319 | asym->flags = 0; | |
320 | break; | |
321 | case scText: | |
322 | asym->section = bfd_make_section_old_way (abfd, ".text"); | |
323 | asym->value -= asym->section->vma; | |
324 | break; | |
325 | case scData: | |
326 | asym->section = bfd_make_section_old_way (abfd, ".data"); | |
327 | asym->value -= asym->section->vma; | |
328 | break; | |
329 | case scBss: | |
330 | asym->section = &bfd_com_section; | |
331 | asym->flags = 0; | |
332 | break; | |
333 | case scRegister: | |
334 | asym->flags = BSF_DEBUGGING; | |
335 | break; | |
336 | case scAbs: | |
337 | asym->section = &bfd_abs_section; | |
338 | asym->flags = 0; | |
339 | break; | |
340 | case scUndefined: | |
341 | asym->section = &bfd_und_section; | |
342 | asym->flags = 0; | |
343 | break; | |
344 | case scCdbLocal: | |
345 | case scBits: | |
346 | case scCdbSystem: | |
347 | case scRegImage: | |
348 | case scInfo: | |
349 | case scUserStruct: | |
350 | asym->flags = BSF_DEBUGGING; | |
351 | break; | |
352 | case scSData: | |
353 | asym->section = bfd_make_section_old_way (abfd, ".sdata"); | |
354 | asym->value -= asym->section->vma; | |
355 | break; | |
356 | case scSBss: | |
357 | asym->section = &bfd_com_section; | |
358 | asym->flags = 0; | |
359 | break; | |
360 | case scRData: | |
361 | asym->section = bfd_make_section_old_way (abfd, ".rdata"); | |
362 | asym->value -= asym->section->vma; | |
363 | break; | |
364 | case scVar: | |
365 | asym->flags = BSF_DEBUGGING; | |
366 | break; | |
367 | case scCommon: | |
368 | case scSCommon: | |
369 | asym->section = &bfd_com_section; | |
370 | asym->flags = 0; | |
371 | break; | |
372 | case scVarRegister: | |
373 | case scVariant: | |
374 | asym->flags = BSF_DEBUGGING; | |
375 | break; | |
376 | case scSUndefined: | |
377 | asym->section = &bfd_und_section; | |
378 | asym->flags = 0; | |
379 | break; | |
380 | case scInit: | |
381 | asym->section = bfd_make_section_old_way (abfd, ".init"); | |
382 | asym->value -= asym->section->vma; | |
383 | break; | |
384 | case scBasedVar: | |
385 | case scXData: | |
386 | case scPData: | |
387 | asym->flags = BSF_DEBUGGING; | |
388 | break; | |
389 | case scFini: | |
390 | asym->section = bfd_make_section_old_way (abfd, ".fini"); | |
391 | asym->value -= asym->section->vma; | |
392 | break; | |
393 | default: | |
394 | asym->flags = 0; | |
395 | break; | |
396 | } | |
397 | } | |
398 | ||
399 | /* Read an ECOFF symbol table. */ | |
400 | ||
401 | static boolean | |
402 | DEFUN (ecoff_slurp_symbol_table, (abfd), | |
403 | bfd *abfd) | |
404 | { | |
405 | struct hdr_ext external_symhdr; | |
406 | HDRR *internal_symhdr; | |
407 | bfd_size_type raw_base; | |
408 | bfd_size_type raw_size; | |
409 | PTR raw; | |
410 | bfd_size_type internal_size; | |
411 | struct fdr_ext *fraw_src; | |
412 | struct fdr_ext *fraw_end; | |
413 | struct fdr *fdr_ptr; | |
414 | struct fdr *fdr_end; | |
415 | ecoff_symbol_type *internal; | |
416 | ecoff_symbol_type *internal_ptr; | |
417 | struct ext_ext *eraw_src; | |
418 | struct ext_ext *eraw_end; | |
419 | ||
420 | /* If we've already read in the symbol table, do nothing. */ | |
421 | if (ecoff_data (abfd)->canonical_symbols != NULL) | |
422 | return true; | |
423 | ||
424 | /* At this point bfd_get_symcount (abfd) holds the number of symbols | |
425 | as read from the file header, but on ECOFF this is always the | |
426 | size of the symbolic information header. It would be cleaner to | |
427 | handle this when we first read the file in coffgen.c. */ | |
428 | if (bfd_get_symcount (abfd) != sizeof (external_symhdr)) | |
429 | { | |
430 | bfd_error = bad_value; | |
431 | return false; | |
432 | } | |
433 | ||
434 | /* Read the symbolic information header. */ | |
435 | if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1 | |
436 | || (bfd_read ((PTR) &external_symhdr, sizeof (external_symhdr), 1, abfd) | |
437 | != sizeof (external_symhdr))) | |
438 | { | |
439 | bfd_error = system_call_error; | |
440 | return false; | |
441 | } | |
442 | internal_symhdr = &ecoff_data (abfd)->symbolic_header; | |
443 | ecoff_swap_hdr_in (abfd, &external_symhdr, internal_symhdr); | |
444 | ||
445 | if (internal_symhdr->magic != magicSym) | |
446 | { | |
447 | bfd_error = bad_value; | |
448 | return false; | |
449 | } | |
450 | ||
451 | /* Now we can get the correct number of symbols. */ | |
452 | bfd_get_symcount (abfd) = (internal_symhdr->isymMax | |
453 | + internal_symhdr->iextMax); | |
454 | ||
455 | /* Read the entire symbol table at once. This expression assumes | |
456 | that the external symbols are always the last item. */ | |
457 | raw_base = ecoff_data (abfd)->sym_filepos + sizeof (external_symhdr); | |
458 | raw_size = (internal_symhdr->cbExtOffset - raw_base | |
459 | + internal_symhdr->iextMax * sizeof (struct ext_ext)); | |
460 | raw = (PTR) bfd_alloc (abfd, raw_size); | |
461 | if (raw == NULL) | |
462 | { | |
463 | bfd_error = no_memory; | |
464 | return false; | |
465 | } | |
466 | if (bfd_read (raw, raw_size, 1, abfd) != raw_size) | |
467 | { | |
468 | bfd_error = system_call_error; | |
469 | bfd_release (abfd, raw); | |
470 | return false; | |
471 | } | |
472 | ||
473 | ecoff_data (abfd)->raw_syments = raw; | |
474 | ||
475 | /* Get pointers for the numeric offsets in the HDRR structure. */ | |
476 | #define FIX(off1, off2, type) \ | |
477 | if (internal_symhdr->off1 == 0) \ | |
478 | ecoff_data (abfd)->off2 = (type *) NULL; \ | |
479 | else \ | |
480 | ecoff_data (abfd)->off2 = (type *) ((char *) raw \ | |
481 | + internal_symhdr->off1 \ | |
482 | - raw_base) | |
483 | FIX (cbLineOffset, line, unsigned char); | |
484 | FIX (cbDnOffset, external_dnr, struct dnr_ext); | |
485 | FIX (cbPdOffset, external_pdr, struct pdr_ext); | |
486 | FIX (cbSymOffset, external_sym, struct sym_ext); | |
487 | FIX (cbOptOffset, external_opt, struct opt_ext); | |
488 | FIX (cbAuxOffset, external_aux, union aux_ext); | |
489 | FIX (cbSsOffset, ss, char); | |
490 | FIX (cbSsExtOffset, ssext, char); | |
491 | FIX (cbFdOffset, external_fdr, struct fdr_ext); | |
492 | FIX (cbRfdOffset, external_rfd, struct rfd_ext); | |
493 | FIX (cbExtOffset, external_ext, struct ext_ext); | |
494 | #undef FIX | |
495 | ||
496 | /* I don't want to always swap all the data, because it will just | |
497 | waste time and most programs will never look at this data. The | |
498 | only time the linker needs most of the debugging information | |
499 | swapped is when linking big-endian and little-endian MIPS object | |
500 | files together, which is not a common occurrence. | |
501 | ||
502 | We need to look at the fdr to deal with a lot of information in | |
503 | the symbols, so we swap them here. We also canonicalize the | |
504 | symbols. */ | |
505 | ecoff_data (abfd)->fdr = (struct fdr *) bfd_alloc (abfd, | |
506 | (internal_symhdr->ifdMax * | |
507 | sizeof (struct fdr))); | |
508 | if (ecoff_data (abfd)->fdr == NULL) | |
509 | { | |
510 | bfd_error = no_memory; | |
511 | return false; | |
512 | } | |
513 | fdr_ptr = ecoff_data (abfd)->fdr; | |
514 | fraw_src = ecoff_data (abfd)->external_fdr; | |
515 | fraw_end = fraw_src + internal_symhdr->ifdMax; | |
516 | for (; fraw_src < fraw_end; fraw_src++, fdr_ptr++) | |
517 | ecoff_swap_fdr_in (abfd, fraw_src, fdr_ptr); | |
518 | ||
519 | internal_size = bfd_get_symcount (abfd) * sizeof (ecoff_symbol_type); | |
520 | internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size); | |
521 | if (internal == NULL) | |
522 | { | |
523 | bfd_error = no_memory; | |
524 | return false; | |
525 | } | |
526 | ||
527 | internal_ptr = internal; | |
528 | eraw_src = ecoff_data (abfd)->external_ext; | |
529 | eraw_end = eraw_src + internal_symhdr->iextMax; | |
530 | for (; eraw_src < eraw_end; eraw_src++, internal_ptr++) | |
531 | { | |
532 | EXTR internal_esym; | |
533 | ||
534 | ecoff_swap_ext_in (abfd, eraw_src, &internal_esym); | |
535 | internal_ptr->symbol.name = (ecoff_data (abfd)->ssext | |
536 | + internal_esym.asym.iss); | |
537 | ecoff_set_symbol_info (abfd, &internal_esym.asym, | |
538 | &internal_ptr->symbol, 1); | |
539 | internal_ptr->fdr = ecoff_data (abfd)->fdr + internal_esym.ifd; | |
540 | internal_ptr->local = false; | |
541 | internal_ptr->native.enative = eraw_src; | |
542 | } | |
543 | ||
544 | /* The local symbols must be accessed via the fdr's, because the | |
545 | string and aux indices are relative to the fdr information. */ | |
546 | fdr_ptr = ecoff_data (abfd)->fdr; | |
547 | fdr_end = fdr_ptr + internal_symhdr->ifdMax; | |
548 | for (; fdr_ptr < fdr_end; fdr_ptr++) | |
549 | { | |
550 | struct sym_ext *lraw_src; | |
551 | struct sym_ext *lraw_end; | |
552 | ||
553 | lraw_src = ecoff_data (abfd)->external_sym + fdr_ptr->isymBase; | |
554 | lraw_end = lraw_src + fdr_ptr->csym; | |
555 | for (; lraw_src < lraw_end; lraw_src++, internal_ptr++) | |
556 | { | |
557 | SYMR internal_sym; | |
558 | ||
559 | ecoff_swap_sym_in (abfd, lraw_src, &internal_sym); | |
560 | internal_ptr->symbol.name = (ecoff_data (abfd)->ss | |
561 | + fdr_ptr->issBase | |
562 | + internal_sym.iss); | |
563 | ecoff_set_symbol_info (abfd, &internal_sym, | |
564 | &internal_ptr->symbol, 0); | |
565 | internal_ptr->fdr = fdr_ptr; | |
566 | internal_ptr->local = true; | |
567 | internal_ptr->native.lnative = lraw_src; | |
568 | } | |
569 | } | |
570 | ||
571 | ecoff_data (abfd)->canonical_symbols = internal; | |
572 | ||
573 | return true; | |
574 | } | |
575 | ||
576 | static unsigned int | |
577 | DEFUN (ecoff_get_symtab_upper_bound, (abfd), | |
578 | bfd *abfd) | |
579 | { | |
580 | if (! ecoff_slurp_symbol_table (abfd)) | |
581 | return 0; | |
582 | ||
583 | return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *)); | |
584 | } | |
585 | ||
586 | static unsigned int | |
587 | DEFUN (ecoff_get_symtab, (abfd, alocation), | |
588 | bfd *abfd AND | |
589 | asymbol **alocation) | |
590 | { | |
591 | unsigned int counter = 0; | |
592 | ecoff_symbol_type *symbase; | |
593 | ecoff_symbol_type **location = (ecoff_symbol_type **) alocation; | |
594 | ||
595 | if (! ecoff_slurp_symbol_table (abfd)) | |
596 | return 0; | |
597 | ||
598 | symbase = ecoff_data (abfd)->canonical_symbols; | |
599 | while (counter < bfd_get_symcount (abfd)) | |
600 | { | |
601 | *(location++) = symbase++; | |
602 | counter++; | |
603 | } | |
604 | *location++ = (ecoff_symbol_type *) NULL; | |
605 | return bfd_get_symcount (abfd); | |
606 | } | |
607 | ||
608 | /* Turn ECOFF type information into a printable string. | |
609 | emit_aggregate and type_to_string are from gcc/mips-tdump.c, with | |
610 | swapping added and used_ptr removed. */ | |
611 | ||
612 | /* Write aggregate information to a string. */ | |
613 | ||
614 | static void | |
615 | DEFUN (emit_aggregate, (abfd, string, rndx, isym, which), | |
616 | bfd *abfd AND | |
617 | char *string AND | |
618 | RNDXR *rndx AND | |
619 | long isym AND | |
620 | CONST char *which) | |
621 | { | |
622 | int ifd = rndx->rfd; | |
623 | int indx = rndx->index; | |
624 | int sym_base, ss_base; | |
625 | CONST char *name; | |
626 | ||
627 | if (ifd == 0xfff) | |
628 | ifd = isym; | |
629 | ||
630 | sym_base = ecoff_data (abfd)->fdr[ifd].isymBase; | |
631 | ss_base = ecoff_data (abfd)->fdr[ifd].issBase; | |
632 | ||
633 | if (indx == indexNil) | |
634 | name = "/* no name */"; | |
635 | else | |
636 | { | |
637 | SYMR sym; | |
638 | ||
639 | indx += sym_base; | |
640 | ecoff_swap_sym_in (abfd, | |
641 | ecoff_data (abfd)->external_sym + indx, | |
642 | &sym); | |
643 | name = ecoff_data (abfd)->ss + ss_base + sym.iss; | |
644 | } | |
645 | ||
646 | sprintf (string, | |
647 | "%s %s { ifd = %d, index = %d }", | |
648 | which, name, ifd, | |
649 | indx + ecoff_data (abfd)->symbolic_header.iextMax); | |
650 | } | |
651 | ||
652 | /* Convert the type information to string format. */ | |
653 | ||
654 | static char * | |
655 | DEFUN (type_to_string, (abfd, aux_ptr, indx, bigendian), | |
656 | bfd *abfd AND | |
657 | union aux_ext *aux_ptr AND | |
658 | int indx AND | |
659 | int bigendian) | |
660 | { | |
661 | AUXU u; | |
662 | struct qual { | |
663 | unsigned int type; | |
664 | int low_bound; | |
665 | int high_bound; | |
666 | int stride; | |
667 | } qualifiers[7]; | |
668 | ||
669 | unsigned int basic_type; | |
670 | int i; | |
671 | static char buffer1[1024]; | |
672 | static char buffer2[1024]; | |
673 | char *p1 = buffer1; | |
674 | char *p2 = buffer2; | |
675 | RNDXR rndx; | |
676 | ||
677 | for (i = 0; i < 7; i++) | |
678 | { | |
679 | qualifiers[i].low_bound = 0; | |
680 | qualifiers[i].high_bound = 0; | |
681 | qualifiers[i].stride = 0; | |
682 | } | |
683 | ||
684 | if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1) | |
685 | return "-1 (no type)"; | |
686 | ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti); | |
687 | ||
688 | basic_type = u.ti.bt; | |
689 | qualifiers[0].type = u.ti.tq0; | |
690 | qualifiers[1].type = u.ti.tq1; | |
691 | qualifiers[2].type = u.ti.tq2; | |
692 | qualifiers[3].type = u.ti.tq3; | |
693 | qualifiers[4].type = u.ti.tq4; | |
694 | qualifiers[5].type = u.ti.tq5; | |
695 | qualifiers[6].type = tqNil; | |
696 | ||
697 | /* | |
698 | * Go get the basic type. | |
699 | */ | |
700 | switch (basic_type) | |
701 | { | |
702 | case btNil: /* undefined */ | |
703 | strcpy (p1, "nil"); | |
704 | break; | |
705 | ||
706 | case btAdr: /* address - integer same size as pointer */ | |
707 | strcpy (p1, "address"); | |
708 | break; | |
709 | ||
710 | case btChar: /* character */ | |
711 | strcpy (p1, "char"); | |
712 | break; | |
713 | ||
714 | case btUChar: /* unsigned character */ | |
715 | strcpy (p1, "unsigned char"); | |
716 | break; | |
717 | ||
718 | case btShort: /* short */ | |
719 | strcpy (p1, "short"); | |
720 | break; | |
721 | ||
722 | case btUShort: /* unsigned short */ | |
723 | strcpy (p1, "unsigned short"); | |
724 | break; | |
725 | ||
726 | case btInt: /* int */ | |
727 | strcpy (p1, "int"); | |
728 | break; | |
729 | ||
730 | case btUInt: /* unsigned int */ | |
731 | strcpy (p1, "unsigned int"); | |
732 | break; | |
733 | ||
734 | case btLong: /* long */ | |
735 | strcpy (p1, "long"); | |
736 | break; | |
737 | ||
738 | case btULong: /* unsigned long */ | |
739 | strcpy (p1, "unsigned long"); | |
740 | break; | |
741 | ||
742 | case btFloat: /* float (real) */ | |
743 | strcpy (p1, "float"); | |
744 | break; | |
745 | ||
746 | case btDouble: /* Double (real) */ | |
747 | strcpy (p1, "double"); | |
748 | break; | |
749 | ||
750 | /* Structures add 1-2 aux words: | |
751 | 1st word is [ST_RFDESCAPE, offset] pointer to struct def; | |
752 | 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */ | |
753 | ||
754 | case btStruct: /* Structure (Record) */ | |
755 | ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx); | |
756 | emit_aggregate (abfd, p1, &rndx, | |
757 | AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]), | |
758 | "struct"); | |
759 | indx++; /* skip aux words */ | |
760 | break; | |
761 | ||
762 | /* Unions add 1-2 aux words: | |
763 | 1st word is [ST_RFDESCAPE, offset] pointer to union def; | |
764 | 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */ | |
765 | ||
766 | case btUnion: /* Union */ | |
767 | ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx); | |
768 | emit_aggregate (abfd, p1, &rndx, | |
769 | AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]), | |
770 | "union"); | |
771 | indx++; /* skip aux words */ | |
772 | break; | |
773 | ||
774 | /* Enumerations add 1-2 aux words: | |
775 | 1st word is [ST_RFDESCAPE, offset] pointer to enum def; | |
776 | 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */ | |
777 | ||
778 | case btEnum: /* Enumeration */ | |
779 | ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx); | |
780 | emit_aggregate (abfd, p1, &rndx, | |
781 | AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]), | |
782 | "enum"); | |
783 | indx++; /* skip aux words */ | |
784 | break; | |
785 | ||
786 | case btTypedef: /* defined via a typedef, isymRef points */ | |
787 | strcpy (p1, "typedef"); | |
788 | break; | |
789 | ||
790 | case btRange: /* subrange of int */ | |
791 | strcpy (p1, "subrange"); | |
792 | break; | |
793 | ||
794 | case btSet: /* pascal sets */ | |
795 | strcpy (p1, "set"); | |
796 | break; | |
797 | ||
798 | case btComplex: /* fortran complex */ | |
799 | strcpy (p1, "complex"); | |
800 | break; | |
801 | ||
802 | case btDComplex: /* fortran double complex */ | |
803 | strcpy (p1, "double complex"); | |
804 | break; | |
805 | ||
806 | case btIndirect: /* forward or unnamed typedef */ | |
807 | strcpy (p1, "forward/unamed typedef"); | |
808 | break; | |
809 | ||
810 | case btFixedDec: /* Fixed Decimal */ | |
811 | strcpy (p1, "fixed decimal"); | |
812 | break; | |
813 | ||
814 | case btFloatDec: /* Float Decimal */ | |
815 | strcpy (p1, "float decimal"); | |
816 | break; | |
817 | ||
818 | case btString: /* Varying Length Character String */ | |
819 | strcpy (p1, "string"); | |
820 | break; | |
821 | ||
822 | case btBit: /* Aligned Bit String */ | |
823 | strcpy (p1, "bit"); | |
824 | break; | |
825 | ||
826 | case btPicture: /* Picture */ | |
827 | strcpy (p1, "picture"); | |
828 | break; | |
829 | ||
830 | case btVoid: /* Void */ | |
831 | strcpy (p1, "void"); | |
832 | break; | |
833 | ||
834 | default: | |
835 | sprintf (p1, "Unknown basic type %d", (int) basic_type); | |
836 | break; | |
837 | } | |
838 | ||
839 | p1 += strlen (buffer1); | |
840 | ||
841 | /* | |
842 | * If this is a bitfield, get the bitsize. | |
843 | */ | |
844 | if (u.ti.fBitfield) | |
845 | { | |
846 | int bitsize; | |
847 | ||
848 | bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]); | |
849 | sprintf (p1, " : %d", bitsize); | |
850 | p1 += strlen (buffer1); | |
851 | } | |
852 | ||
853 | ||
854 | /* | |
855 | * Deal with any qualifiers. | |
856 | */ | |
857 | if (qualifiers[0].type != tqNil) | |
858 | { | |
859 | /* | |
860 | * Snarf up any array bounds in the correct order. Arrays | |
861 | * store 5 successive words in the aux. table: | |
862 | * word 0 RNDXR to type of the bounds (ie, int) | |
863 | * word 1 Current file descriptor index | |
864 | * word 2 low bound | |
865 | * word 3 high bound (or -1 if []) | |
866 | * word 4 stride size in bits | |
867 | */ | |
868 | for (i = 0; i < 7; i++) | |
869 | { | |
870 | if (qualifiers[i].type == tqArray) | |
871 | { | |
872 | qualifiers[i].low_bound = | |
873 | AUX_GET_DNLOW (bigendian, &aux_ptr[indx+2]); | |
874 | qualifiers[i].high_bound = | |
875 | AUX_GET_DNHIGH (bigendian, &aux_ptr[indx+3]); | |
876 | qualifiers[i].stride = | |
877 | AUX_GET_WIDTH (bigendian, &aux_ptr[indx+4]); | |
878 | indx += 5; | |
879 | } | |
880 | } | |
881 | ||
882 | /* | |
883 | * Now print out the qualifiers. | |
884 | */ | |
885 | for (i = 0; i < 6; i++) | |
886 | { | |
887 | switch (qualifiers[i].type) | |
888 | { | |
889 | case tqNil: | |
890 | case tqMax: | |
891 | break; | |
892 | ||
893 | case tqPtr: | |
894 | strcpy (p2, "ptr to "); | |
895 | p2 += sizeof ("ptr to ")-1; | |
896 | break; | |
897 | ||
898 | case tqVol: | |
899 | strcpy (p2, "volatile "); | |
900 | p2 += sizeof ("volatile ")-1; | |
901 | break; | |
902 | ||
903 | case tqFar: | |
904 | strcpy (p2, "far "); | |
905 | p2 += sizeof ("far ")-1; | |
906 | break; | |
907 | ||
908 | case tqProc: | |
909 | strcpy (p2, "func. ret. "); | |
910 | p2 += sizeof ("func. ret. "); | |
911 | break; | |
912 | ||
913 | case tqArray: | |
914 | { | |
915 | int first_array = i; | |
916 | int j; | |
917 | ||
918 | /* Print array bounds reversed (ie, in the order the C | |
919 | programmer writes them). C is such a fun language.... */ | |
920 | ||
921 | while (i < 5 && qualifiers[i+1].type == tqArray) | |
922 | i++; | |
923 | ||
924 | for (j = i; j >= first_array; j--) | |
925 | { | |
926 | strcpy (p2, "array ["); | |
927 | p2 += sizeof ("array [")-1; | |
928 | if (qualifiers[j].low_bound != 0) | |
929 | sprintf (p2, | |
930 | "%ld:%ld {%ld bits}", | |
931 | (long) qualifiers[j].low_bound, | |
932 | (long) qualifiers[j].high_bound, | |
933 | (long) qualifiers[j].stride); | |
934 | ||
935 | else if (qualifiers[j].high_bound != -1) | |
936 | sprintf (p2, | |
937 | "%ld {%ld bits}", | |
938 | (long) (qualifiers[j].high_bound + 1), | |
939 | (long) (qualifiers[j].stride)); | |
940 | ||
941 | else | |
942 | sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride)); | |
943 | ||
944 | p2 += strlen (p2); | |
945 | strcpy (p2, "] of "); | |
946 | p2 += sizeof ("] of ")-1; | |
947 | } | |
948 | } | |
949 | break; | |
950 | } | |
951 | } | |
952 | } | |
953 | ||
954 | strcpy (p2, buffer1); | |
955 | return buffer2; | |
956 | } | |
957 | ||
958 | /* Print information about an ECOFF symbol. */ | |
959 | ||
960 | static void | |
961 | DEFUN (ecoff_print_symbol, (abfd, filep, symbol, how), | |
962 | bfd *abfd AND | |
963 | PTR filep AND | |
964 | asymbol *symbol AND | |
965 | bfd_print_symbol_type how) | |
966 | { | |
967 | FILE *file = (FILE *)filep; | |
968 | ||
969 | switch (how) | |
970 | { | |
971 | case bfd_print_symbol_name: | |
972 | fprintf (file, "%s", symbol->name); | |
973 | break; | |
974 | case bfd_print_symbol_more: | |
975 | if (ecoffsymbol (symbol)->local) | |
976 | { | |
977 | SYMR ecoff_sym; | |
978 | ||
979 | ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative, | |
980 | &ecoff_sym); | |
981 | fprintf (file, "ecoff local %lx %x %x", | |
982 | (unsigned long) ecoff_sym.value, | |
983 | (unsigned) ecoff_sym.st, (unsigned) ecoff_sym.sc); | |
984 | } | |
985 | else | |
986 | { | |
987 | EXTR ecoff_ext; | |
988 | ||
989 | ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative, | |
990 | &ecoff_ext); | |
991 | fprintf (file, "ecoff extern %lx %x %x", | |
992 | (unsigned long) ecoff_ext.asym.value, | |
993 | (unsigned) ecoff_ext.asym.st, | |
994 | (unsigned) ecoff_ext.asym.sc); | |
995 | } | |
996 | break; | |
997 | case bfd_print_symbol_nm: | |
998 | { | |
999 | CONST char *section_name = symbol->section->name; | |
1000 | ||
1001 | bfd_print_symbol_vandf ((PTR) file, symbol); | |
1002 | fprintf (file, " %-5s %s %s", | |
1003 | section_name, | |
1004 | ecoffsymbol (symbol)->local ? "l" : "e", | |
1005 | symbol->name); | |
1006 | } | |
1007 | break; | |
1008 | case bfd_print_symbol_all: | |
1009 | /* Print out the symbols in a reasonable way */ | |
1010 | { | |
1011 | CONST char *section_name = symbol->section->name; | |
1012 | char type; | |
1013 | int pos; | |
1014 | EXTR ecoff_ext; | |
1015 | char jmptbl; | |
1016 | char cobol_main; | |
1017 | char weakext; | |
1018 | ||
1019 | if (ecoffsymbol (symbol)->local) | |
1020 | { | |
1021 | ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative, | |
1022 | &ecoff_ext.asym); | |
1023 | type = 'l'; | |
1024 | pos = (ecoffsymbol (symbol)->native.lnative | |
1025 | - ecoff_data (abfd)->external_sym | |
1026 | + ecoff_data (abfd)->symbolic_header.iextMax); | |
1027 | jmptbl = ' '; | |
1028 | cobol_main = ' '; | |
1029 | weakext = ' '; | |
1030 | } | |
1031 | else | |
1032 | { | |
1033 | ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative, | |
1034 | &ecoff_ext); | |
1035 | type = 'e'; | |
1036 | pos = (ecoffsymbol (symbol)->native.enative | |
1037 | - ecoff_data (abfd)->external_ext); | |
1038 | jmptbl = ecoff_ext.jmptbl ? 'j' : ' '; | |
1039 | cobol_main = ecoff_ext.cobol_main ? 'c' : ' '; | |
1040 | weakext = ecoff_ext.weakext ? 'w' : ' '; | |
1041 | } | |
1042 | ||
1043 | fprintf (file, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s", | |
1044 | pos, type, (unsigned long) ecoff_ext.asym.value, | |
1045 | (unsigned) ecoff_ext.asym.st, | |
1046 | (unsigned) ecoff_ext.asym.sc, | |
1047 | (unsigned) ecoff_ext.asym.index, | |
1048 | jmptbl, cobol_main, weakext, | |
1049 | symbol->name); | |
1050 | ||
1051 | if (ecoffsymbol (symbol)->fdr != NULL | |
1052 | && ecoff_ext.asym.index != indexNil) | |
1053 | { | |
1054 | unsigned indx; | |
1055 | int bigendian; | |
1056 | long sym_base; | |
1057 | union aux_ext *aux_base; | |
1058 | ||
1059 | indx = ecoff_ext.asym.index; | |
1060 | ||
1061 | /* sym_base is used to map the fdr relative indices which | |
1062 | appear in the file to the position number which we are | |
1063 | using. */ | |
1064 | sym_base = ecoffsymbol (symbol)->fdr->isymBase; | |
1065 | if (ecoffsymbol (symbol)->local) | |
1066 | sym_base += ecoff_data (abfd)->symbolic_header.iextMax; | |
1067 | ||
1068 | /* aux_base is the start of the aux entries for this file; | |
1069 | asym.index is an offset from this. */ | |
1070 | aux_base = (ecoff_data (abfd)->external_aux | |
1071 | + ecoffsymbol (symbol)->fdr->iauxBase); | |
1072 | ||
1073 | /* The aux entries are stored in host byte order; the | |
1074 | order is indicated by a bit in the fdr. */ | |
1075 | bigendian = ecoffsymbol (symbol)->fdr->fBigendian; | |
1076 | ||
1077 | /* This switch is basically from gcc/mips-tdump.c */ | |
1078 | switch (ecoff_ext.asym.st) | |
1079 | { | |
1080 | case stNil: | |
1081 | case stLabel: | |
1082 | break; | |
1083 | ||
1084 | case stFile: | |
1085 | case stBlock: | |
1086 | printf ("\n End+1 symbol: %ld", indx + sym_base); | |
1087 | break; | |
1088 | ||
1089 | case stEnd: | |
1090 | if (ecoff_ext.asym.sc == scText | |
1091 | || ecoff_ext.asym.sc == scInfo) | |
1092 | printf ("\n First symbol: %ld", indx + sym_base); | |
1093 | else | |
1094 | printf ("\n First symbol: %ld", | |
1095 | (AUX_GET_ISYM (bigendian, | |
1096 | &aux_base[ecoff_ext.asym.index]) | |
1097 | + sym_base)); | |
1098 | break; | |
1099 | ||
1100 | case stProc: | |
1101 | case stStaticProc: | |
1102 | if (MIPS_IS_STAB (&ecoff_ext.asym)) | |
1103 | ; | |
1104 | else if (ecoffsymbol (symbol)->local) | |
1105 | printf ("\n End+1 symbol: %-7ld Type: %s", | |
1106 | (AUX_GET_ISYM (bigendian, | |
1107 | &aux_base[ecoff_ext.asym.index]) | |
1108 | + sym_base), | |
1109 | type_to_string (abfd, aux_base, indx + 1, | |
1110 | bigendian)); | |
1111 | else | |
1112 | printf ("\n Type: %s", | |
1113 | type_to_string (abfd, aux_base, indx, bigendian)); | |
1114 | ||
1115 | break; | |
1116 | ||
1117 | default: | |
1118 | if (!MIPS_IS_STAB (&ecoff_ext.asym)) | |
1119 | printf ("\n Type: %s", | |
1120 | type_to_string (abfd, aux_base, indx, bigendian)); | |
1121 | break; | |
1122 | } | |
1123 | } | |
1124 | } | |
1125 | break; | |
1126 | } | |
1127 | } | |
1128 | \f | |
1129 | /* Provided a BFD, a section and an offset into the section, calculate | |
1130 | and return the name of the source file and the line nearest to the | |
1131 | wanted location. */ | |
1132 | ||
1133 | static boolean | |
1134 | DEFUN (ecoff_find_nearest_line, (abfd, | |
1135 | section, | |
1136 | ignore_symbols, | |
1137 | offset, | |
1138 | filename_ptr, | |
1139 | functionname_ptr, | |
1140 | retline_ptr), | |
1141 | bfd *abfd AND | |
1142 | asection *section AND | |
1143 | asymbol **ignore_symbols AND | |
1144 | bfd_vma offset AND | |
1145 | CONST char **filename_ptr AND | |
1146 | CONST char **functionname_ptr AND | |
1147 | unsigned int *retline_ptr) | |
1148 | { | |
1149 | FDR *fdr_ptr; | |
1150 | FDR *fdr_start; | |
1151 | FDR *fdr_end; | |
1152 | FDR *fdr_hold; | |
1153 | struct pdr_ext *pdr_ptr; | |
1154 | struct pdr_ext *pdr_end; | |
1155 | PDR pdr; | |
1156 | unsigned char *line_ptr; | |
1157 | unsigned char *line_end; | |
1158 | int lineno; | |
1159 | SYMR proc_sym; | |
1160 | ||
1161 | /* If we're not in the .text section, we don't have any line | |
1162 | numbers. */ | |
1163 | if (strcmp (section->name, _TEXT) != 0) | |
1164 | return false; | |
1165 | ||
1166 | /* Each file descriptor (FDR) has a memory address. Here we track | |
1167 | down which FDR we want. The FDR's are stored in increasing | |
1168 | memory order. If speed is ever important, this can become a | |
1169 | binary search. We must ignore FDR's with no PDR entries; they | |
1170 | will have the adr of the FDR before or after them. */ | |
1171 | fdr_start = ecoff_data (abfd)->fdr; | |
1172 | fdr_end = fdr_start + ecoff_data (abfd)->symbolic_header.ifdMax; | |
1173 | fdr_hold = (FDR *) NULL; | |
1174 | for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++) | |
1175 | { | |
1176 | if (offset < fdr_ptr->adr) | |
1177 | break; | |
1178 | if (fdr_ptr->cpd > 0) | |
1179 | fdr_hold = fdr_ptr; | |
1180 | } | |
1181 | if (fdr_hold == (FDR *) NULL) | |
1182 | return false; | |
1183 | fdr_ptr = fdr_hold; | |
1184 | ||
1185 | /* Each FDR has a list of procedure descriptors (PDR). PDR's also | |
1186 | have an address, which is relative to the FDR address, and are | |
1187 | also stored in increasing memory order. */ | |
1188 | offset -= fdr_ptr->adr; | |
1189 | pdr_ptr = ecoff_data (abfd)->external_pdr + fdr_ptr->ipdFirst; | |
1190 | pdr_end = pdr_ptr + fdr_ptr->cpd; | |
1191 | ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr); | |
1192 | if (offset < pdr.adr) | |
1193 | return false; | |
1194 | for (pdr_ptr++; pdr_ptr < pdr_end; pdr_ptr++) | |
1195 | { | |
1196 | ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr); | |
1197 | if (offset < pdr.adr) | |
1198 | break; | |
1199 | } | |
1200 | ||
1201 | /* Now we can look for the actual line number. The line numbers are | |
1202 | stored in a very funky format, which I won't try to describe. | |
1203 | Note that right here pdr_ptr and pdr hold the PDR *after* the one | |
1204 | we want; we need this to compute line_end. */ | |
1205 | line_end = ecoff_data (abfd)->line; | |
1206 | if (pdr_ptr == pdr_end) | |
1207 | line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine; | |
1208 | else | |
1209 | line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset; | |
1210 | ||
1211 | /* Now change pdr and pdr_ptr to the one we want. */ | |
1212 | pdr_ptr--; | |
1213 | ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr); | |
1214 | ||
1215 | offset -= pdr.adr; | |
1216 | lineno = pdr.lnLow; | |
1217 | line_ptr = (ecoff_data (abfd)->line | |
1218 | + fdr_ptr->cbLineOffset | |
1219 | + pdr.cbLineOffset); | |
1220 | while (line_ptr < line_end) | |
1221 | { | |
1222 | int delta; | |
1223 | int count; | |
1224 | ||
1225 | delta = *line_ptr >> 4; | |
1226 | if (delta >= 0x8) | |
1227 | delta -= 0x10; | |
1228 | count = (*line_ptr & 0xf) + 1; | |
1229 | ++line_ptr; | |
1230 | if (delta == -8) | |
1231 | { | |
1232 | delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff); | |
1233 | if (delta >= 0x8000) | |
1234 | delta -= 0x10000; | |
1235 | line_ptr += 2; | |
1236 | } | |
1237 | lineno += delta; | |
1238 | if (offset < count * 4) | |
1239 | break; | |
1240 | offset -= count * 4; | |
1241 | } | |
1242 | ||
1243 | /* If offset is too large, this line is not interesting. */ | |
1244 | if (offset > 100) | |
1245 | return false; | |
1246 | ||
1247 | *filename_ptr = ecoff_data (abfd)->ss + fdr_ptr->issBase + fdr_ptr->rss; | |
1248 | ecoff_swap_sym_in (abfd, | |
1249 | (ecoff_data (abfd)->external_sym | |
1250 | + fdr_ptr->isymBase | |
1251 | + pdr.isym), | |
1252 | &proc_sym); | |
1253 | *functionname_ptr = ecoff_data (abfd)->ss + proc_sym.iss; | |
1254 | *retline_ptr = lineno; | |
1255 | return true; | |
1256 | } | |
1257 | \f | |
1258 | static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table = { | |
1259 | (void (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_in */ | |
1260 | (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */ | |
1261 | (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */ | |
1262 | (unsigned (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_out */ | |
1263 | (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */ | |
1264 | (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */ | |
1265 | ecoff_swap_reloc_out, ecoff_swap_filehdr_out, ecoff_swap_aouthdr_out, | |
1266 | ecoff_swap_scnhdr_out, | |
1267 | FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, true, | |
1268 | ecoff_swap_filehdr_in, ecoff_swap_aouthdr_in, ecoff_swap_scnhdr_in, | |
1269 | ecoff_bad_format_hook, ecoff_set_arch_mach_hook, ecoff_mkobject_hook, | |
1270 | styp_to_sec_flags, ecoff_make_section_hook, ecoff_set_alignment_hook, | |
1271 | ecoff_slurp_symbol_table | |
1272 | }; | |
1273 | ||
1274 | /* Routines that need to be written. */ | |
1275 | #define ecoff_write_object_contents (boolean (*) PARAMS ((bfd *))) bfd_false | |
1276 | #define ecoff_set_section_contents (boolean (*) PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type))) bfd_false | |
1277 | #define ecoff_get_reloc_upper_bound (unsigned int (*) PARAMS ((bfd *, sec_ptr))) bfd_0 | |
1278 | #define ecoff_canonicalize_reloc (unsigned int (*) PARAMS ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry **))) bfd_0 | |
1279 | #define ecoff_set_arch_mach (boolean (*) PARAMS ((bfd *, enum bfd_architecture, unsigned long))) bfd_false | |
1280 | #define ecoff_sizeof_headers (int (*) PARAMS ((bfd *, boolean))) bfd_0 | |
1281 | ||
1282 | /* get_lineno could be written for ECOFF, but it would currently only | |
1283 | be useful for linking ECOFF and COFF files together, which doesn't | |
1284 | seem too likely. */ | |
1285 | #define ecoff_get_lineno (struct lineno_cache_entry *(*)()) bfd_nullvoidptr | |
1286 | ||
1287 | #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command | |
1288 | #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal | |
1289 | #define ecoff_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p | |
1290 | #define ecoff_slurp_armap bfd_slurp_coff_armap | |
1291 | #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table | |
1292 | #define ecoff_write_armap coff_write_armap | |
1293 | #define ecoff_truncate_arname bfd_dont_truncate_arname | |
1294 | #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file | |
1295 | #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt | |
1296 | #define ecoff_get_section_contents bfd_generic_get_section_contents | |
1297 | #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup | |
1298 | ||
1299 | #define ecoff_bfd_debug_info_start bfd_void | |
1300 | #define ecoff_bfd_debug_info_end bfd_void | |
1301 | #define ecoff_bfd_debug_info_accumulate \ | |
1302 | (void (*) PARAMS ((bfd *, struct sec *))) bfd_void | |
1303 | #define ecoff_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents | |
1304 | #define ecoff_bfd_relax_section bfd_generic_relax_section | |
0c2fae09 | 1305 | #define ecoff_bfd_seclet_link bfd_generic_seclet_link |
c9301d7b | 1306 | |
1327fb29 | 1307 | bfd_target ecoff_little_vec = |
294eaca4 SC |
1308 | { |
1309 | "ecoff-littlemips", /* name */ | |
515c4292 | 1310 | bfd_target_ecoff_flavour, |
294eaca4 SC |
1311 | false, /* data byte order is little */ |
1312 | false, /* header byte order is little */ | |
1313 | ||
1314 | (HAS_RELOC | EXEC_P | /* object flags */ | |
1315 | HAS_LINENO | HAS_DEBUG | | |
1316 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT), | |
1317 | ||
1318 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect | |
1319 | flags */ | |
1320 | 0, /* leading underscore */ | |
1321 | '/', /* ar_pad_char */ | |
1322 | 15, /* ar_max_namelen */ | |
1323 | 3, /* minimum alignment power */ | |
1324 | _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */ | |
1325 | _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */ | |
1326 | ||
515c4292 | 1327 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ |
294eaca4 | 1328 | bfd_generic_archive_p, _bfd_dummy_target}, |
515c4292 | 1329 | {bfd_false, ecoff_mkobject, bfd_false, /* bfd_set_format */ |
294eaca4 | 1330 | bfd_false}, |
515c4292 ILT |
1331 | {bfd_false, ecoff_write_object_contents, bfd_false, bfd_false}, |
1332 | JUMP_TABLE (ecoff), | |
1333 | 0, 0, | |
1334 | (PTR) &bfd_ecoff_std_swap_table | |
1335 | }; | |
1327fb29 SC |
1336 | |
1337 | bfd_target ecoff_big_vec = | |
294eaca4 SC |
1338 | { |
1339 | "ecoff-bigmips", /* name */ | |
515c4292 | 1340 | bfd_target_ecoff_flavour, |
294eaca4 SC |
1341 | true, /* data byte order is big */ |
1342 | true, /* header byte order is big */ | |
1343 | ||
1344 | (HAS_RELOC | EXEC_P | /* object flags */ | |
1345 | HAS_LINENO | HAS_DEBUG | | |
1346 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT), | |
1347 | ||
1348 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect flags */ | |
1349 | 0, /* leading underscore */ | |
1350 | ' ', /* ar_pad_char */ | |
1351 | 16, /* ar_max_namelen */ | |
1352 | 3, /* minimum alignment power */ | |
1353 | _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, | |
1354 | _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, | |
1355 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ | |
1356 | bfd_generic_archive_p, _bfd_dummy_target}, | |
515c4292 | 1357 | {bfd_false, ecoff_mkobject, bfd_false, /* bfd_set_format */ |
294eaca4 | 1358 | bfd_false}, |
515c4292 | 1359 | {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */ |
294eaca4 | 1360 | bfd_false, bfd_false}, |
515c4292 ILT |
1361 | JUMP_TABLE(ecoff), |
1362 | 0, 0, | |
1363 | (PTR) &bfd_ecoff_std_swap_table | |
1364 | /* Note that there is another bfd_target just above this one. If | |
1365 | you are adding initializers here, you should be adding them there | |
1366 | as well. */ | |
1367 | }; |