1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support added by Ian Lance Taylor, ian@cygnus.com.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "aout/ranlib.h"
29 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
30 some other stuff which we don't want and which conflicts with stuff
33 #include "aout/aout64.h"
36 #undef obj_sym_filepos
38 #include "coff/internal.h"
40 #include "coff/symconst.h"
41 #include "coff/ecoff.h"
45 /* Prototypes for static functions. */
47 static int ecoff_get_magic PARAMS ((bfd *abfd));
48 static void ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym,
49 asymbol *asym, int ext,
50 asymbol **indirect_ptr_ptr));
51 static void ecoff_emit_aggregate PARAMS ((bfd *abfd, char *string,
52 RNDXR *rndx, long isym,
54 static char *ecoff_type_to_string PARAMS ((bfd *abfd, union aux_ext *aux_ptr,
55 unsigned int indx, int bigendian));
56 static boolean ecoff_slurp_reloc_table PARAMS ((bfd *abfd, asection *section,
58 static void ecoff_compute_section_file_positions PARAMS ((bfd *abfd));
59 static boolean ecoff_get_extr PARAMS ((asymbol *, EXTR *));
60 static void ecoff_set_index PARAMS ((asymbol *, bfd_size_type));
61 static unsigned int ecoff_armap_hash PARAMS ((CONST char *s,
66 /* This stuff is somewhat copied from coffcode.h. */
68 static asection bfd_debug_section = { "*DEBUG*" };
70 /* Create an ECOFF object. */
76 abfd->tdata.ecoff_obj_data = ((struct ecoff_tdata *)
77 bfd_zalloc (abfd, sizeof (ecoff_data_type)));
78 if (abfd->tdata.ecoff_obj_data == NULL)
80 bfd_error = no_memory;
87 /* This is a hook called by coff_real_object_p to create any backend
88 specific information. */
91 ecoff_mkobject_hook (abfd, filehdr, aouthdr)
96 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
97 struct internal_aouthdr *internal_a = (struct internal_aouthdr *) aouthdr;
98 ecoff_data_type *ecoff;
101 if (ecoff_mkobject (abfd) == false)
104 ecoff = ecoff_data (abfd);
106 ecoff->sym_filepos = internal_f->f_symptr;
108 /* Create the .reginfo section to give programs outside BFD a way to
109 see the information stored in the a.out header. See the comment
111 regsec = bfd_make_section (abfd, REGINFO);
115 if (internal_a != (struct internal_aouthdr *) NULL)
119 ecoff->text_start = internal_a->text_start;
120 ecoff->text_end = internal_a->text_start + internal_a->tsize;
121 ecoff->gp = internal_a->gp_value;
122 ecoff->gprmask = internal_a->gprmask;
123 for (i = 0; i < 4; i++)
124 ecoff->cprmask[i] = internal_a->cprmask[i];
125 ecoff->fprmask = internal_a->fprmask;
126 if (internal_a->magic == ECOFF_AOUT_ZMAGIC)
127 abfd->flags |= D_PAGED;
130 /* It turns out that no special action is required by the MIPS or
131 Alpha ECOFF backends. They have different information in the
132 a.out header, but we just copy it all (e.g., gprmask, cprmask and
133 fprmask) and let the swapping routines ensure that only relevant
134 information is written out. */
139 /* This is a hook needed by SCO COFF, but we have nothing to do. */
142 ecoff_make_section_hook (abfd, name)
146 return (asection *) NULL;
149 /* Initialize a new section. */
152 ecoff_new_section_hook (abfd, section)
156 section->alignment_power = abfd->xvec->align_power_min;
158 if (strcmp (section->name, _TEXT) == 0)
159 section->flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
160 else if (strcmp (section->name, _DATA) == 0
161 || strcmp (section->name, _SDATA) == 0)
162 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
163 else if (strcmp (section->name, _RDATA) == 0
164 || strcmp (section->name, _LIT8) == 0
165 || strcmp (section->name, _LIT4) == 0)
166 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
167 else if (strcmp (section->name, _BSS) == 0
168 || strcmp (section->name, _SBSS) == 0)
169 section->flags |= SEC_ALLOC;
170 else if (strcmp (section->name, REGINFO) == 0)
172 section->flags |= SEC_HAS_CONTENTS | SEC_NEVER_LOAD;
173 section->_raw_size = sizeof (struct ecoff_reginfo);
176 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
177 uncertain about .init on some systems and I don't know how shared
183 /* Determine the machine architecture and type. This is called from
184 the generic COFF routines. It is the inverse of ecoff_get_magic,
185 below. This could be an ECOFF backend routine, with one version
186 for each target, but there aren't all that many ECOFF targets. */
189 ecoff_set_arch_mach_hook (abfd, filehdr)
193 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
194 enum bfd_architecture arch;
197 switch (internal_f->f_magic)
200 case MIPS_MAGIC_LITTLE:
202 arch = bfd_arch_mips;
206 case MIPS_MAGIC_LITTLE2:
207 case MIPS_MAGIC_BIG2:
208 /* MIPS ISA level 2: the r6000 */
209 arch = bfd_arch_mips;
213 case MIPS_MAGIC_LITTLE3:
214 case MIPS_MAGIC_BIG3:
215 /* MIPS ISA level 3: the r4000 */
216 arch = bfd_arch_mips;
221 arch = bfd_arch_alpha;
226 arch = bfd_arch_obscure;
231 return bfd_default_set_arch_mach (abfd, arch, mach);
234 /* Get the magic number to use based on the architecture and machine.
235 This is the inverse of ecoff_set_arch_mach_hook, above. */
238 ecoff_get_magic (abfd)
243 switch (bfd_get_arch (abfd))
246 switch (bfd_get_mach (abfd))
251 big = MIPS_MAGIC_BIG;
252 little = MIPS_MAGIC_LITTLE;
256 big = MIPS_MAGIC_BIG2;
257 little = MIPS_MAGIC_LITTLE2;
261 big = MIPS_MAGIC_BIG3;
262 little = MIPS_MAGIC_LITTLE3;
266 return abfd->xvec->byteorder_big_p ? big : little;
277 /* Get the section s_flags to use for a section. */
280 ecoff_sec_to_styp_flags (name, flags)
288 if (strcmp (name, _TEXT) == 0)
290 else if (strcmp (name, _DATA) == 0)
292 else if (strcmp (name, _SDATA) == 0)
294 else if (strcmp (name, _RDATA) == 0)
296 else if (strcmp (name, _LITA) == 0)
298 else if (strcmp (name, _LIT8) == 0)
300 else if (strcmp (name, _LIT4) == 0)
302 else if (strcmp (name, _BSS) == 0)
304 else if (strcmp (name, _SBSS) == 0)
306 else if (strcmp (name, _INIT) == 0)
307 styp = STYP_ECOFF_INIT;
308 else if (strcmp (name, _FINI) == 0)
309 styp = STYP_ECOFF_FINI;
310 else if (flags & SEC_CODE)
312 else if (flags & SEC_DATA)
314 else if (flags & SEC_READONLY)
316 else if (flags & SEC_LOAD)
321 if (flags & SEC_NEVER_LOAD)
327 /* Get the BFD flags to use for a section. */
330 ecoff_styp_to_sec_flags (abfd, hdr)
334 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
335 long styp_flags = internal_s->s_flags;
336 flagword sec_flags=0;
338 if (styp_flags & STYP_NOLOAD)
339 sec_flags |= SEC_NEVER_LOAD;
341 /* For 386 COFF, at least, an unloadable text or data section is
342 actually a shared library section. */
343 if ((styp_flags & STYP_TEXT)
344 || (styp_flags & STYP_ECOFF_INIT)
345 || (styp_flags & STYP_ECOFF_FINI))
347 if (sec_flags & SEC_NEVER_LOAD)
348 sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY;
350 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
352 else if ((styp_flags & STYP_DATA)
353 || (styp_flags & STYP_RDATA)
354 || (styp_flags & STYP_SDATA))
356 if (sec_flags & SEC_NEVER_LOAD)
357 sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY;
359 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
360 if (styp_flags & STYP_RDATA)
361 sec_flags |= SEC_READONLY;
363 else if ((styp_flags & STYP_BSS)
364 || (styp_flags & STYP_SBSS))
366 sec_flags |= SEC_ALLOC;
368 else if (styp_flags & STYP_INFO)
370 sec_flags |= SEC_NEVER_LOAD;
372 else if ((styp_flags & STYP_LITA)
373 || (styp_flags & STYP_LIT8)
374 || (styp_flags & STYP_LIT4))
376 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
380 sec_flags |= SEC_ALLOC | SEC_LOAD;
386 /* Routines to swap auxiliary information in and out. I am assuming
387 that the auxiliary information format is always going to be target
390 /* Swap in a type information record.
391 BIGEND says whether AUX symbols are big-endian or little-endian; this
392 info comes from the file header record (fh-fBigendian). */
395 ecoff_swap_tir_in (bigend, ext_copy, intern)
397 struct tir_ext *ext_copy;
400 struct tir_ext ext[1];
402 *ext = *ext_copy; /* Make it reasonable to do in-place. */
404 /* now the fun stuff... */
406 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_BIG);
407 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_BIG);
408 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_BIG)
409 >> TIR_BITS1_BT_SH_BIG;
410 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_BIG)
411 >> TIR_BITS_TQ4_SH_BIG;
412 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_BIG)
413 >> TIR_BITS_TQ5_SH_BIG;
414 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_BIG)
415 >> TIR_BITS_TQ0_SH_BIG;
416 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_BIG)
417 >> TIR_BITS_TQ1_SH_BIG;
418 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_BIG)
419 >> TIR_BITS_TQ2_SH_BIG;
420 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_BIG)
421 >> TIR_BITS_TQ3_SH_BIG;
423 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_LITTLE);
424 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_LITTLE);
425 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_LITTLE)
426 >> TIR_BITS1_BT_SH_LITTLE;
427 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_LITTLE)
428 >> TIR_BITS_TQ4_SH_LITTLE;
429 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_LITTLE)
430 >> TIR_BITS_TQ5_SH_LITTLE;
431 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_LITTLE)
432 >> TIR_BITS_TQ0_SH_LITTLE;
433 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_LITTLE)
434 >> TIR_BITS_TQ1_SH_LITTLE;
435 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_LITTLE)
436 >> TIR_BITS_TQ2_SH_LITTLE;
437 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_LITTLE)
438 >> TIR_BITS_TQ3_SH_LITTLE;
442 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
447 /* Swap out a type information record.
448 BIGEND says whether AUX symbols are big-endian or little-endian; this
449 info comes from the file header record (fh-fBigendian). */
452 ecoff_swap_tir_out (bigend, intern_copy, ext)
459 *intern = *intern_copy; /* Make it reasonable to do in-place. */
461 /* now the fun stuff... */
463 ext->t_bits1[0] = ((intern->fBitfield ? TIR_BITS1_FBITFIELD_BIG : 0)
464 | (intern->continued ? TIR_BITS1_CONTINUED_BIG : 0)
465 | ((intern->bt << TIR_BITS1_BT_SH_BIG)
466 & TIR_BITS1_BT_BIG));
467 ext->t_tq45[0] = (((intern->tq4 << TIR_BITS_TQ4_SH_BIG)
469 | ((intern->tq5 << TIR_BITS_TQ5_SH_BIG)
470 & TIR_BITS_TQ5_BIG));
471 ext->t_tq01[0] = (((intern->tq0 << TIR_BITS_TQ0_SH_BIG)
473 | ((intern->tq1 << TIR_BITS_TQ1_SH_BIG)
474 & TIR_BITS_TQ1_BIG));
475 ext->t_tq23[0] = (((intern->tq2 << TIR_BITS_TQ2_SH_BIG)
477 | ((intern->tq3 << TIR_BITS_TQ3_SH_BIG)
478 & TIR_BITS_TQ3_BIG));
480 ext->t_bits1[0] = ((intern->fBitfield ? TIR_BITS1_FBITFIELD_LITTLE : 0)
481 | (intern->continued ? TIR_BITS1_CONTINUED_LITTLE : 0)
482 | ((intern->bt << TIR_BITS1_BT_SH_LITTLE)
483 & TIR_BITS1_BT_LITTLE));
484 ext->t_tq45[0] = (((intern->tq4 << TIR_BITS_TQ4_SH_LITTLE)
485 & TIR_BITS_TQ4_LITTLE)
486 | ((intern->tq5 << TIR_BITS_TQ5_SH_LITTLE)
487 & TIR_BITS_TQ5_LITTLE));
488 ext->t_tq01[0] = (((intern->tq0 << TIR_BITS_TQ0_SH_LITTLE)
489 & TIR_BITS_TQ0_LITTLE)
490 | ((intern->tq1 << TIR_BITS_TQ1_SH_LITTLE)
491 & TIR_BITS_TQ1_LITTLE));
492 ext->t_tq23[0] = (((intern->tq2 << TIR_BITS_TQ2_SH_LITTLE)
493 & TIR_BITS_TQ2_LITTLE)
494 | ((intern->tq3 << TIR_BITS_TQ3_SH_LITTLE)
495 & TIR_BITS_TQ3_LITTLE));
499 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
504 /* Swap in a relative symbol record. BIGEND says whether it is in
505 big-endian or little-endian format.*/
508 ecoff_swap_rndx_in (bigend, ext_copy, intern)
510 struct rndx_ext *ext_copy;
513 struct rndx_ext ext[1];
515 *ext = *ext_copy; /* Make it reasonable to do in-place. */
517 /* now the fun stuff... */
519 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_BIG)
520 | ((ext->r_bits[1] & RNDX_BITS1_RFD_BIG)
521 >> RNDX_BITS1_RFD_SH_BIG);
522 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_BIG)
523 << RNDX_BITS1_INDEX_SH_LEFT_BIG)
524 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG)
525 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG);
527 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE)
528 | ((ext->r_bits[1] & RNDX_BITS1_RFD_LITTLE)
529 << RNDX_BITS1_RFD_SH_LEFT_LITTLE);
530 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_LITTLE)
531 >> RNDX_BITS1_INDEX_SH_LITTLE)
532 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE)
533 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE);
537 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
542 /* Swap out a relative symbol record. BIGEND says whether it is in
543 big-endian or little-endian format.*/
546 ecoff_swap_rndx_out (bigend, intern_copy, ext)
549 struct rndx_ext *ext;
553 *intern = *intern_copy; /* Make it reasonable to do in-place. */
555 /* now the fun stuff... */
557 ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_BIG;
558 ext->r_bits[1] = (((intern->rfd << RNDX_BITS1_RFD_SH_BIG)
559 & RNDX_BITS1_RFD_BIG)
560 | ((intern->index >> RNDX_BITS1_INDEX_SH_LEFT_BIG)
561 & RNDX_BITS1_INDEX_BIG));
562 ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_BIG;
563 ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_BIG;
565 ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_LITTLE;
566 ext->r_bits[1] = (((intern->rfd >> RNDX_BITS1_RFD_SH_LEFT_LITTLE)
567 & RNDX_BITS1_RFD_LITTLE)
568 | ((intern->index << RNDX_BITS1_INDEX_SH_LITTLE)
569 & RNDX_BITS1_INDEX_LITTLE));
570 ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_LITTLE;
571 ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_LITTLE;
575 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
580 /* Read in and swap the important symbolic information for an ECOFF
581 object file. This is called by gdb. */
584 ecoff_slurp_symbolic_info (abfd)
587 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
588 bfd_size_type external_hdr_size;
589 HDRR *internal_symhdr;
590 bfd_size_type raw_base;
591 bfd_size_type raw_size;
593 bfd_size_type external_fdr_size;
597 bfd_size_type raw_end;
598 bfd_size_type cb_end;
600 /* Check whether we've already gotten it, and whether there's any to
602 if (ecoff_data (abfd)->raw_syments != (PTR) NULL)
604 if (ecoff_data (abfd)->sym_filepos == 0)
606 bfd_get_symcount (abfd) = 0;
610 /* At this point bfd_get_symcount (abfd) holds the number of symbols
611 as read from the file header, but on ECOFF this is always the
612 size of the symbolic information header. It would be cleaner to
613 handle this when we first read the file in coffgen.c. */
614 external_hdr_size = backend->debug_swap.external_hdr_size;
615 if (bfd_get_symcount (abfd) != external_hdr_size)
617 bfd_error = bad_value;
621 /* Read the symbolic information header. */
622 raw = (PTR) alloca (external_hdr_size);
623 if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1
624 || (bfd_read (raw, external_hdr_size, 1, abfd)
625 != external_hdr_size))
627 bfd_error = system_call_error;
630 internal_symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
631 (*backend->debug_swap.swap_hdr_in) (abfd, raw, internal_symhdr);
633 if (internal_symhdr->magic != backend->debug_swap.sym_magic)
635 bfd_error = bad_value;
639 /* Now we can get the correct number of symbols. */
640 bfd_get_symcount (abfd) = (internal_symhdr->isymMax
641 + internal_symhdr->iextMax);
643 /* Read all the symbolic information at once. */
644 raw_base = ecoff_data (abfd)->sym_filepos + external_hdr_size;
646 /* Alpha ecoff makes the determination of raw_size difficult. It has
647 an undocumented debug data section between the symhdr and the first
648 documented section. And the ordering of the sections varies between
649 statically and dynamically linked executables.
650 If bfd supports SEEK_END someday, this code could be simplified. */
654 #define UPDATE_RAW_END(start, count, size) \
655 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
656 if (cb_end > raw_end) \
659 UPDATE_RAW_END (cbLineOffset, cbLine, sizeof (unsigned char));
660 UPDATE_RAW_END (cbDnOffset, idnMax, backend->debug_swap.external_dnr_size);
661 UPDATE_RAW_END (cbPdOffset, ipdMax, backend->debug_swap.external_pdr_size);
662 UPDATE_RAW_END (cbSymOffset, isymMax, backend->debug_swap.external_sym_size);
663 UPDATE_RAW_END (cbOptOffset, ioptMax, backend->debug_swap.external_opt_size);
664 UPDATE_RAW_END (cbAuxOffset, iauxMax, sizeof (union aux_ext));
665 UPDATE_RAW_END (cbSsOffset, issMax, sizeof (char));
666 UPDATE_RAW_END (cbSsExtOffset, issExtMax, sizeof (char));
667 UPDATE_RAW_END (cbFdOffset, ifdMax, backend->debug_swap.external_fdr_size);
668 UPDATE_RAW_END (cbRfdOffset, crfd, backend->debug_swap.external_rfd_size);
669 UPDATE_RAW_END (cbExtOffset, iextMax, backend->debug_swap.external_ext_size);
671 #undef UPDATE_RAW_END
673 raw_size = raw_end - raw_base;
676 ecoff_data (abfd)->sym_filepos = 0;
679 raw = (PTR) bfd_alloc (abfd, raw_size);
682 bfd_error = no_memory;
685 if (bfd_read (raw, raw_size, 1, abfd) != raw_size)
687 bfd_error = system_call_error;
688 bfd_release (abfd, raw);
692 ecoff_data (abfd)->raw_syments = raw;
694 /* Get pointers for the numeric offsets in the HDRR structure. */
695 #define FIX(off1, off2, type) \
696 if (internal_symhdr->off1 == 0) \
697 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
699 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
700 + internal_symhdr->off1 \
702 FIX (cbLineOffset, line, unsigned char *);
703 FIX (cbDnOffset, external_dnr, PTR);
704 FIX (cbPdOffset, external_pdr, PTR);
705 FIX (cbSymOffset, external_sym, PTR);
706 FIX (cbOptOffset, external_opt, PTR);
707 FIX (cbAuxOffset, external_aux, union aux_ext *);
708 FIX (cbSsOffset, ss, char *);
709 FIX (cbSsExtOffset, ssext, char *);
710 FIX (cbFdOffset, external_fdr, PTR);
711 FIX (cbRfdOffset, external_rfd, PTR);
712 FIX (cbExtOffset, external_ext, PTR);
715 /* I don't want to always swap all the data, because it will just
716 waste time and most programs will never look at it. The only
717 time the linker needs most of the debugging information swapped
718 is when linking big-endian and little-endian MIPS object files
719 together, which is not a common occurrence.
721 We need to look at the fdr to deal with a lot of information in
722 the symbols, so we swap them here. */
723 ecoff_data (abfd)->debug_info.fdr =
724 (struct fdr *) bfd_alloc (abfd,
725 (internal_symhdr->ifdMax *
726 sizeof (struct fdr)));
727 if (ecoff_data (abfd)->debug_info.fdr == NULL)
729 bfd_error = no_memory;
732 external_fdr_size = backend->debug_swap.external_fdr_size;
733 fdr_ptr = ecoff_data (abfd)->debug_info.fdr;
734 fraw_src = (char *) ecoff_data (abfd)->debug_info.external_fdr;
735 fraw_end = fraw_src + internal_symhdr->ifdMax * external_fdr_size;
736 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
737 (*backend->debug_swap.swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
742 /* ECOFF symbol table routines. The ECOFF symbol table is described
743 in gcc/mips-tfile.c. */
745 /* ECOFF uses two common sections. One is the usual one, and the
746 other is for small objects. All the small objects are kept
747 together, and then referenced via the gp pointer, which yields
748 faster assembler code. This is what we use for the small common
750 static asection ecoff_scom_section;
751 static asymbol ecoff_scom_symbol;
752 static asymbol *ecoff_scom_symbol_ptr;
754 /* Create an empty symbol. */
757 ecoff_make_empty_symbol (abfd)
760 ecoff_symbol_type *new;
762 new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type));
763 if (new == (ecoff_symbol_type *) NULL)
765 bfd_error = no_memory;
766 return (asymbol *) NULL;
768 memset (new, 0, sizeof *new);
769 new->symbol.section = (asection *) NULL;
770 new->fdr = (FDR *) NULL;
773 new->symbol.the_bfd = abfd;
777 /* Set the BFD flags and section for an ECOFF symbol. */
780 ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
785 asymbol **indirect_ptr_ptr;
787 asym->the_bfd = abfd;
788 asym->value = ecoff_sym->value;
789 asym->section = &bfd_debug_section;
792 /* An indirect symbol requires two consecutive stabs symbols. */
793 if (*indirect_ptr_ptr != (asymbol *) NULL)
795 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym));
797 /* @@ Stuffing pointers into integers is a no-no.
798 We can usually get away with it if the integer is
799 large enough though. */
800 if (sizeof (asym) > sizeof (bfd_vma))
802 (*indirect_ptr_ptr)->value = (bfd_vma) asym;
804 asym->flags = BSF_DEBUGGING;
805 asym->section = &bfd_und_section;
806 *indirect_ptr_ptr = NULL;
810 if (ECOFF_IS_STAB (ecoff_sym)
811 && (ECOFF_UNMARK_STAB (ecoff_sym->index) | N_EXT) == (N_INDR | N_EXT))
813 asym->flags = BSF_DEBUGGING | BSF_INDIRECT;
814 asym->section = &bfd_ind_section;
815 /* Pass this symbol on to the next call to this function. */
816 *indirect_ptr_ptr = asym;
820 /* Most symbol types are just for debugging. */
821 switch (ecoff_sym->st)
830 if (ECOFF_IS_STAB (ecoff_sym))
832 asym->flags = BSF_DEBUGGING;
837 asym->flags = BSF_DEBUGGING;
842 asym->flags = BSF_EXPORT | BSF_GLOBAL;
844 asym->flags = BSF_LOCAL;
845 switch (ecoff_sym->sc)
848 /* Used for compiler generated labels. Leave them in the
849 debugging section, and mark them as local. If BSF_DEBUGGING
850 is set, then nm does not display them for some reason. If no
851 flags are set then the linker whines about them. */
852 asym->flags = BSF_LOCAL;
855 asym->section = bfd_make_section_old_way (abfd, ".text");
856 asym->value -= asym->section->vma;
859 asym->section = bfd_make_section_old_way (abfd, ".data");
860 asym->value -= asym->section->vma;
863 asym->section = bfd_make_section_old_way (abfd, ".bss");
864 asym->value -= asym->section->vma;
867 asym->flags = BSF_DEBUGGING;
870 asym->section = &bfd_abs_section;
873 asym->section = &bfd_und_section;
883 asym->flags = BSF_DEBUGGING;
886 asym->section = bfd_make_section_old_way (abfd, ".sdata");
887 asym->value -= asym->section->vma;
890 asym->section = bfd_make_section_old_way (abfd, ".sbss");
891 asym->value -= asym->section->vma;
894 asym->section = bfd_make_section_old_way (abfd, ".rdata");
895 asym->value -= asym->section->vma;
898 asym->flags = BSF_DEBUGGING;
901 if (asym->value > ecoff_data (abfd)->gp_size)
903 asym->section = &bfd_com_section;
909 if (ecoff_scom_section.name == NULL)
911 /* Initialize the small common section. */
912 ecoff_scom_section.name = SCOMMON;
913 ecoff_scom_section.flags = SEC_IS_COMMON;
914 ecoff_scom_section.output_section = &ecoff_scom_section;
915 ecoff_scom_section.symbol = &ecoff_scom_symbol;
916 ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
917 ecoff_scom_symbol.name = SCOMMON;
918 ecoff_scom_symbol.flags = BSF_SECTION_SYM;
919 ecoff_scom_symbol.section = &ecoff_scom_section;
920 ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
922 asym->section = &ecoff_scom_section;
927 asym->flags = BSF_DEBUGGING;
930 asym->section = &bfd_und_section;
935 asym->section = bfd_make_section_old_way (abfd, ".init");
936 asym->value -= asym->section->vma;
941 asym->flags = BSF_DEBUGGING;
944 asym->section = bfd_make_section_old_way (abfd, ".fini");
945 asym->value -= asym->section->vma;
951 /* Look for special constructors symbols and make relocation entries
952 in a special construction section. These are produced by the
953 -fgnu-linker argument to g++. */
954 if (ECOFF_IS_STAB (ecoff_sym))
956 switch (ECOFF_UNMARK_STAB (ecoff_sym->index))
968 arelent_chain *reloc_chain;
969 unsigned int bitsize;
971 /* Get a section with the same name as the symbol (usually
972 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
973 name ___CTOR_LIST (three underscores). We need
974 __CTOR_LIST (two underscores), since ECOFF doesn't use
975 a leading underscore. This should be handled by gcc,
976 but instead we do it here. Actually, this should all
977 be done differently anyhow. */
978 name = bfd_asymbol_name (asym);
979 if (name[0] == '_' && name[1] == '_' && name[2] == '_')
984 section = bfd_get_section_by_name (abfd, name);
985 if (section == (asection *) NULL)
989 copy = (char *) bfd_alloc (abfd, strlen (name) + 1);
991 section = bfd_make_section (abfd, copy);
994 /* Build a reloc pointing to this constructor. */
996 (arelent_chain *) bfd_alloc (abfd, sizeof (arelent_chain));
997 reloc_chain->relent.sym_ptr_ptr =
998 bfd_get_section (asym)->symbol_ptr_ptr;
999 reloc_chain->relent.address = section->_raw_size;
1000 reloc_chain->relent.addend = asym->value;
1001 reloc_chain->relent.howto =
1002 ecoff_backend (abfd)->constructor_reloc;
1004 /* Set up the constructor section to hold the reloc. */
1005 section->flags = SEC_CONSTRUCTOR;
1006 ++section->reloc_count;
1008 /* Constructor sections must be rounded to a boundary
1009 based on the bitsize. These are not real sections--
1010 they are handled specially by the linker--so the ECOFF
1011 16 byte alignment restriction does not apply. */
1012 bitsize = ecoff_backend (abfd)->constructor_bitsize;
1013 section->alignment_power = 1;
1014 while ((1 << section->alignment_power) < bitsize / 8)
1015 ++section->alignment_power;
1017 reloc_chain->next = section->constructor_chain;
1018 section->constructor_chain = reloc_chain;
1019 section->_raw_size += bitsize / 8;
1021 /* Mark the symbol as a constructor. */
1022 asym->flags |= BSF_CONSTRUCTOR;
1029 /* Read an ECOFF symbol table. */
1032 ecoff_slurp_symbol_table (abfd)
1035 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
1036 const bfd_size_type external_ext_size
1037 = backend->debug_swap.external_ext_size;
1038 const bfd_size_type external_sym_size
1039 = backend->debug_swap.external_sym_size;
1040 void (* const swap_ext_in) PARAMS ((bfd *, PTR, EXTR *))
1041 = backend->debug_swap.swap_ext_in;
1042 void (* const swap_sym_in) PARAMS ((bfd *, PTR, SYMR *))
1043 = backend->debug_swap.swap_sym_in;
1044 bfd_size_type internal_size;
1045 ecoff_symbol_type *internal;
1046 ecoff_symbol_type *internal_ptr;
1047 asymbol *indirect_ptr;
1053 /* If we've already read in the symbol table, do nothing. */
1054 if (ecoff_data (abfd)->canonical_symbols != NULL)
1057 /* Get the symbolic information. */
1058 if (ecoff_slurp_symbolic_info (abfd) == false)
1060 if (bfd_get_symcount (abfd) == 0)
1063 internal_size = bfd_get_symcount (abfd) * sizeof (ecoff_symbol_type);
1064 internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size);
1065 if (internal == NULL)
1067 bfd_error = no_memory;
1071 internal_ptr = internal;
1072 indirect_ptr = NULL;
1073 eraw_src = (char *) ecoff_data (abfd)->debug_info.external_ext;
1074 eraw_end = (eraw_src
1075 + (ecoff_data (abfd)->debug_info.symbolic_header.iextMax
1076 * external_ext_size));
1077 for (; eraw_src < eraw_end; eraw_src += external_ext_size, internal_ptr++)
1081 (*swap_ext_in) (abfd, (PTR) eraw_src, &internal_esym);
1082 internal_ptr->symbol.name = (ecoff_data (abfd)->debug_info.ssext
1083 + internal_esym.asym.iss);
1084 ecoff_set_symbol_info (abfd, &internal_esym.asym,
1085 &internal_ptr->symbol, 1, &indirect_ptr);
1086 /* The alpha uses a negative ifd field for section symbols. */
1087 if (internal_esym.ifd >= 0)
1088 internal_ptr->fdr = (ecoff_data (abfd)->debug_info.fdr
1089 + internal_esym.ifd);
1091 internal_ptr->fdr = NULL;
1092 internal_ptr->local = false;
1093 internal_ptr->native = (PTR) eraw_src;
1095 BFD_ASSERT (indirect_ptr == (asymbol *) NULL);
1097 /* The local symbols must be accessed via the fdr's, because the
1098 string and aux indices are relative to the fdr information. */
1099 fdr_ptr = ecoff_data (abfd)->debug_info.fdr;
1100 fdr_end = fdr_ptr + ecoff_data (abfd)->debug_info.symbolic_header.ifdMax;
1101 for (; fdr_ptr < fdr_end; fdr_ptr++)
1106 lraw_src = ((char *) ecoff_data (abfd)->debug_info.external_sym
1107 + fdr_ptr->isymBase * external_sym_size);
1108 lraw_end = lraw_src + fdr_ptr->csym * external_sym_size;
1110 lraw_src < lraw_end;
1111 lraw_src += external_sym_size, internal_ptr++)
1115 (*swap_sym_in) (abfd, (PTR) lraw_src, &internal_sym);
1116 internal_ptr->symbol.name = (ecoff_data (abfd)->debug_info.ss
1118 + internal_sym.iss);
1119 ecoff_set_symbol_info (abfd, &internal_sym,
1120 &internal_ptr->symbol, 0, &indirect_ptr);
1121 internal_ptr->fdr = fdr_ptr;
1122 internal_ptr->local = true;
1123 internal_ptr->native = (PTR) lraw_src;
1126 BFD_ASSERT (indirect_ptr == (asymbol *) NULL);
1128 ecoff_data (abfd)->canonical_symbols = internal;
1133 /* Return the amount of space needed for the canonical symbols. */
1136 ecoff_get_symtab_upper_bound (abfd)
1139 if (ecoff_slurp_symbolic_info (abfd) == false
1140 || bfd_get_symcount (abfd) == 0)
1143 return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *));
1146 /* Get the canonicals symbols. */
1149 ecoff_get_symtab (abfd, alocation)
1151 asymbol **alocation;
1153 unsigned int counter = 0;
1154 ecoff_symbol_type *symbase;
1155 ecoff_symbol_type **location = (ecoff_symbol_type **) alocation;
1157 if (ecoff_slurp_symbol_table (abfd) == false
1158 || bfd_get_symcount (abfd) == 0)
1161 symbase = ecoff_data (abfd)->canonical_symbols;
1162 while (counter < bfd_get_symcount (abfd))
1164 *(location++) = symbase++;
1167 *location++ = (ecoff_symbol_type *) NULL;
1168 return bfd_get_symcount (abfd);
1171 /* Turn ECOFF type information into a printable string.
1172 ecoff_emit_aggregate and ecoff_type_to_string are from
1173 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1175 /* Write aggregate information to a string. */
1178 ecoff_emit_aggregate (abfd, string, rndx, isym, which)
1185 int ifd = rndx->rfd;
1186 int indx = rndx->index;
1187 int sym_base, ss_base;
1193 sym_base = ecoff_data (abfd)->debug_info.fdr[ifd].isymBase;
1194 ss_base = ecoff_data (abfd)->debug_info.fdr[ifd].issBase;
1196 if (indx == indexNil)
1197 name = "/* no name */";
1200 const struct ecoff_debug_swap * const debug_swap
1201 = &ecoff_backend (abfd)->debug_swap;
1205 (*debug_swap->swap_sym_in)
1207 ((char *) ecoff_data (abfd)->debug_info.external_sym
1208 + indx * debug_swap->external_sym_size),
1210 name = ecoff_data (abfd)->debug_info.ss + ss_base + sym.iss;
1214 "%s %s { ifd = %d, index = %ld }",
1217 + ecoff_data (abfd)->debug_info.symbolic_header.iextMax));
1220 /* Convert the type information to string format. */
1223 ecoff_type_to_string (abfd, aux_ptr, indx, bigendian)
1225 union aux_ext *aux_ptr;
1237 unsigned int basic_type;
1239 static char buffer1[1024];
1240 static char buffer2[1024];
1245 for (i = 0; i < 7; i++)
1247 qualifiers[i].low_bound = 0;
1248 qualifiers[i].high_bound = 0;
1249 qualifiers[i].stride = 0;
1252 if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1)
1253 return "-1 (no type)";
1254 ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti);
1256 basic_type = u.ti.bt;
1257 qualifiers[0].type = u.ti.tq0;
1258 qualifiers[1].type = u.ti.tq1;
1259 qualifiers[2].type = u.ti.tq2;
1260 qualifiers[3].type = u.ti.tq3;
1261 qualifiers[4].type = u.ti.tq4;
1262 qualifiers[5].type = u.ti.tq5;
1263 qualifiers[6].type = tqNil;
1266 * Go get the basic type.
1270 case btNil: /* undefined */
1274 case btAdr: /* address - integer same size as pointer */
1275 strcpy (p1, "address");
1278 case btChar: /* character */
1279 strcpy (p1, "char");
1282 case btUChar: /* unsigned character */
1283 strcpy (p1, "unsigned char");
1286 case btShort: /* short */
1287 strcpy (p1, "short");
1290 case btUShort: /* unsigned short */
1291 strcpy (p1, "unsigned short");
1294 case btInt: /* int */
1298 case btUInt: /* unsigned int */
1299 strcpy (p1, "unsigned int");
1302 case btLong: /* long */
1303 strcpy (p1, "long");
1306 case btULong: /* unsigned long */
1307 strcpy (p1, "unsigned long");
1310 case btFloat: /* float (real) */
1311 strcpy (p1, "float");
1314 case btDouble: /* Double (real) */
1315 strcpy (p1, "double");
1318 /* Structures add 1-2 aux words:
1319 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1320 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1322 case btStruct: /* Structure (Record) */
1323 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1324 ecoff_emit_aggregate (abfd, p1, &rndx,
1325 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1327 indx++; /* skip aux words */
1330 /* Unions add 1-2 aux words:
1331 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1332 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1334 case btUnion: /* Union */
1335 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1336 ecoff_emit_aggregate (abfd, p1, &rndx,
1337 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1339 indx++; /* skip aux words */
1342 /* Enumerations add 1-2 aux words:
1343 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1344 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1346 case btEnum: /* Enumeration */
1347 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1348 ecoff_emit_aggregate (abfd, p1, &rndx,
1349 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1351 indx++; /* skip aux words */
1354 case btTypedef: /* defined via a typedef, isymRef points */
1355 strcpy (p1, "typedef");
1358 case btRange: /* subrange of int */
1359 strcpy (p1, "subrange");
1362 case btSet: /* pascal sets */
1366 case btComplex: /* fortran complex */
1367 strcpy (p1, "complex");
1370 case btDComplex: /* fortran double complex */
1371 strcpy (p1, "double complex");
1374 case btIndirect: /* forward or unnamed typedef */
1375 strcpy (p1, "forward/unamed typedef");
1378 case btFixedDec: /* Fixed Decimal */
1379 strcpy (p1, "fixed decimal");
1382 case btFloatDec: /* Float Decimal */
1383 strcpy (p1, "float decimal");
1386 case btString: /* Varying Length Character String */
1387 strcpy (p1, "string");
1390 case btBit: /* Aligned Bit String */
1394 case btPicture: /* Picture */
1395 strcpy (p1, "picture");
1398 case btVoid: /* Void */
1399 strcpy (p1, "void");
1403 sprintf (p1, "Unknown basic type %d", (int) basic_type);
1407 p1 += strlen (buffer1);
1410 * If this is a bitfield, get the bitsize.
1416 bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]);
1417 sprintf (p1, " : %d", bitsize);
1418 p1 += strlen (buffer1);
1423 * Deal with any qualifiers.
1425 if (qualifiers[0].type != tqNil)
1428 * Snarf up any array bounds in the correct order. Arrays
1429 * store 5 successive words in the aux. table:
1430 * word 0 RNDXR to type of the bounds (ie, int)
1431 * word 1 Current file descriptor index
1433 * word 3 high bound (or -1 if [])
1434 * word 4 stride size in bits
1436 for (i = 0; i < 7; i++)
1438 if (qualifiers[i].type == tqArray)
1440 qualifiers[i].low_bound =
1441 AUX_GET_DNLOW (bigendian, &aux_ptr[indx+2]);
1442 qualifiers[i].high_bound =
1443 AUX_GET_DNHIGH (bigendian, &aux_ptr[indx+3]);
1444 qualifiers[i].stride =
1445 AUX_GET_WIDTH (bigendian, &aux_ptr[indx+4]);
1451 * Now print out the qualifiers.
1453 for (i = 0; i < 6; i++)
1455 switch (qualifiers[i].type)
1462 strcpy (p2, "ptr to ");
1463 p2 += sizeof ("ptr to ")-1;
1467 strcpy (p2, "volatile ");
1468 p2 += sizeof ("volatile ")-1;
1472 strcpy (p2, "far ");
1473 p2 += sizeof ("far ")-1;
1477 strcpy (p2, "func. ret. ");
1478 p2 += sizeof ("func. ret. ");
1483 int first_array = i;
1486 /* Print array bounds reversed (ie, in the order the C
1487 programmer writes them). C is such a fun language.... */
1489 while (i < 5 && qualifiers[i+1].type == tqArray)
1492 for (j = i; j >= first_array; j--)
1494 strcpy (p2, "array [");
1495 p2 += sizeof ("array [")-1;
1496 if (qualifiers[j].low_bound != 0)
1498 "%ld:%ld {%ld bits}",
1499 (long) qualifiers[j].low_bound,
1500 (long) qualifiers[j].high_bound,
1501 (long) qualifiers[j].stride);
1503 else if (qualifiers[j].high_bound != -1)
1506 (long) (qualifiers[j].high_bound + 1),
1507 (long) (qualifiers[j].stride));
1510 sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride));
1513 strcpy (p2, "] of ");
1514 p2 += sizeof ("] of ")-1;
1522 strcpy (p2, buffer1);
1526 /* Return information about ECOFF symbol SYMBOL in RET. */
1529 ecoff_get_symbol_info (abfd, symbol, ret)
1530 bfd *abfd; /* Ignored. */
1534 bfd_symbol_info (symbol, ret);
1537 /* Print information about an ECOFF symbol. */
1540 ecoff_print_symbol (abfd, filep, symbol, how)
1544 bfd_print_symbol_type how;
1546 const struct ecoff_debug_swap * const debug_swap
1547 = &ecoff_backend (abfd)->debug_swap;
1548 FILE *file = (FILE *)filep;
1552 case bfd_print_symbol_name:
1553 fprintf (file, "%s", symbol->name);
1555 case bfd_print_symbol_more:
1556 if (ecoffsymbol (symbol)->local)
1560 (*debug_swap->swap_sym_in) (abfd, ecoffsymbol (symbol)->native,
1562 fprintf (file, "ecoff local ");
1563 fprintf_vma (file, (bfd_vma) ecoff_sym.value);
1564 fprintf (file, " %x %x", (unsigned) ecoff_sym.st,
1565 (unsigned) ecoff_sym.sc);
1571 (*debug_swap->swap_ext_in) (abfd, ecoffsymbol (symbol)->native,
1573 fprintf (file, "ecoff extern ");
1574 fprintf_vma (file, (bfd_vma) ecoff_ext.asym.value);
1575 fprintf (file, " %x %x", (unsigned) ecoff_ext.asym.st,
1576 (unsigned) ecoff_ext.asym.sc);
1579 case bfd_print_symbol_all:
1580 /* Print out the symbols in a reasonable way */
1589 if (ecoffsymbol (symbol)->local)
1591 (*debug_swap->swap_sym_in) (abfd, ecoffsymbol (symbol)->native,
1594 pos = ((((char *) ecoffsymbol (symbol)->native
1595 - (char *) ecoff_data (abfd)->debug_info.external_sym)
1596 / debug_swap->external_sym_size)
1597 + ecoff_data (abfd)->debug_info.symbolic_header.iextMax);
1604 (*debug_swap->swap_ext_in) (abfd, ecoffsymbol (symbol)->native,
1607 pos = (((char *) ecoffsymbol (symbol)->native
1608 - (char *) ecoff_data (abfd)->debug_info.external_ext)
1609 / debug_swap->external_ext_size);
1610 jmptbl = ecoff_ext.jmptbl ? 'j' : ' ';
1611 cobol_main = ecoff_ext.cobol_main ? 'c' : ' ';
1612 weakext = ecoff_ext.weakext ? 'w' : ' ';
1615 fprintf (file, "[%3d] %c ",
1617 fprintf_vma (file, (bfd_vma) ecoff_ext.asym.value);
1618 fprintf (file, " st %x sc %x indx %x %c%c%c %s",
1619 (unsigned) ecoff_ext.asym.st,
1620 (unsigned) ecoff_ext.asym.sc,
1621 (unsigned) ecoff_ext.asym.index,
1622 jmptbl, cobol_main, weakext,
1625 if (ecoffsymbol (symbol)->fdr != NULL
1626 && ecoff_ext.asym.index != indexNil)
1630 bfd_size_type sym_base;
1631 union aux_ext *aux_base;
1633 indx = ecoff_ext.asym.index;
1635 /* sym_base is used to map the fdr relative indices which
1636 appear in the file to the position number which we are
1638 sym_base = ecoffsymbol (symbol)->fdr->isymBase;
1639 if (ecoffsymbol (symbol)->local)
1641 ecoff_data (abfd)->debug_info.symbolic_header.iextMax;
1643 /* aux_base is the start of the aux entries for this file;
1644 asym.index is an offset from this. */
1645 aux_base = (ecoff_data (abfd)->debug_info.external_aux
1646 + ecoffsymbol (symbol)->fdr->iauxBase);
1648 /* The aux entries are stored in host byte order; the
1649 order is indicated by a bit in the fdr. */
1650 bigendian = ecoffsymbol (symbol)->fdr->fBigendian;
1652 /* This switch is basically from gcc/mips-tdump.c */
1653 switch (ecoff_ext.asym.st)
1661 fprintf (file, "\n End+1 symbol: %ld",
1662 (long) (indx + sym_base));
1666 if (ecoff_ext.asym.sc == scText
1667 || ecoff_ext.asym.sc == scInfo)
1668 fprintf (file, "\n First symbol: %ld",
1669 (long) (indx + sym_base));
1671 fprintf (file, "\n First symbol: %ld",
1672 (long) (AUX_GET_ISYM (bigendian,
1673 &aux_base[ecoff_ext.asym.index])
1679 if (ECOFF_IS_STAB (&ecoff_ext.asym))
1681 else if (ecoffsymbol (symbol)->local)
1682 fprintf (file, "\n End+1 symbol: %-7ld Type: %s",
1683 (long) (AUX_GET_ISYM (bigendian,
1684 &aux_base[ecoff_ext.asym.index])
1686 ecoff_type_to_string (abfd, aux_base, indx + 1,
1689 fprintf (file, "\n Local symbol: %ld",
1692 + (ecoff_data (abfd)
1693 ->debug_info.symbolic_header.iextMax)));
1697 if (! ECOFF_IS_STAB (&ecoff_ext.asym))
1698 fprintf (file, "\n Type: %s",
1699 ecoff_type_to_string (abfd, aux_base, indx,
1709 /* Read in the relocs for a section. */
1712 ecoff_slurp_reloc_table (abfd, section, symbols)
1717 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
1718 arelent *internal_relocs;
1719 bfd_size_type external_reloc_size;
1720 bfd_size_type external_relocs_size;
1721 char *external_relocs;
1725 if (section->relocation != (arelent *) NULL
1726 || section->reloc_count == 0
1727 || (section->flags & SEC_CONSTRUCTOR) != 0)
1730 if (ecoff_slurp_symbol_table (abfd) == false)
1733 internal_relocs = (arelent *) bfd_alloc (abfd,
1735 * section->reloc_count));
1736 external_reloc_size = backend->external_reloc_size;
1737 external_relocs_size = external_reloc_size * section->reloc_count;
1738 external_relocs = (char *) bfd_alloc (abfd, external_relocs_size);
1739 if (internal_relocs == (arelent *) NULL
1740 || external_relocs == (char *) NULL)
1742 bfd_error = no_memory;
1745 if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
1747 if (bfd_read (external_relocs, 1, external_relocs_size, abfd)
1748 != external_relocs_size)
1750 bfd_error = system_call_error;
1754 for (i = 0, rptr = internal_relocs; i < section->reloc_count; i++, rptr++)
1756 struct internal_reloc intern;
1758 (*backend->swap_reloc_in) (abfd,
1759 external_relocs + i * external_reloc_size,
1762 if (intern.r_extern)
1764 /* r_symndx is an index into the external symbols. */
1765 BFD_ASSERT (intern.r_symndx >= 0
1767 < (ecoff_data (abfd)
1768 ->debug_info.symbolic_header.iextMax)));
1769 rptr->sym_ptr_ptr = symbols + intern.r_symndx;
1772 else if (intern.r_symndx == RELOC_SECTION_NONE
1773 || intern.r_symndx == RELOC_SECTION_ABS)
1775 rptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
1780 CONST char *sec_name;
1783 /* r_symndx is a section key. */
1784 switch (intern.r_symndx)
1786 case RELOC_SECTION_TEXT: sec_name = ".text"; break;
1787 case RELOC_SECTION_RDATA: sec_name = ".rdata"; break;
1788 case RELOC_SECTION_DATA: sec_name = ".data"; break;
1789 case RELOC_SECTION_SDATA: sec_name = ".sdata"; break;
1790 case RELOC_SECTION_SBSS: sec_name = ".sbss"; break;
1791 case RELOC_SECTION_BSS: sec_name = ".bss"; break;
1792 case RELOC_SECTION_INIT: sec_name = ".init"; break;
1793 case RELOC_SECTION_LIT8: sec_name = ".lit8"; break;
1794 case RELOC_SECTION_LIT4: sec_name = ".lit4"; break;
1795 case RELOC_SECTION_XDATA: sec_name = ".xdata"; break;
1796 case RELOC_SECTION_PDATA: sec_name = ".pdata"; break;
1797 case RELOC_SECTION_FINI: sec_name = ".fini"; break;
1798 case RELOC_SECTION_LITA: sec_name = ".lita"; break;
1802 sec = bfd_get_section_by_name (abfd, sec_name);
1803 if (sec == (asection *) NULL)
1805 rptr->sym_ptr_ptr = sec->symbol_ptr_ptr;
1807 rptr->addend = - bfd_get_section_vma (abfd, sec);
1810 rptr->address = intern.r_vaddr - bfd_get_section_vma (abfd, section);
1812 /* Let the backend select the howto field and do any other
1813 required processing. */
1814 (*backend->adjust_reloc_in) (abfd, &intern, rptr);
1817 bfd_release (abfd, external_relocs);
1819 section->relocation = internal_relocs;
1824 /* Get a canonical list of relocs. */
1827 ecoff_canonicalize_reloc (abfd, section, relptr, symbols)
1835 if (section->flags & SEC_CONSTRUCTOR)
1837 arelent_chain *chain;
1839 /* This section has relocs made up by us, not the file, so take
1840 them out of their chain and place them into the data area
1842 for (count = 0, chain = section->constructor_chain;
1843 count < section->reloc_count;
1844 count++, chain = chain->next)
1845 *relptr++ = &chain->relent;
1851 if (ecoff_slurp_reloc_table (abfd, section, symbols) == false)
1854 tblptr = section->relocation;
1855 if (tblptr == (arelent *) NULL)
1858 for (count = 0; count < section->reloc_count; count++)
1859 *relptr++ = tblptr++;
1862 *relptr = (arelent *) NULL;
1864 return section->reloc_count;
1867 /* Provided a BFD, a section and an offset into the section, calculate
1868 and return the name of the source file and the line nearest to the
1872 ecoff_find_nearest_line (abfd,
1881 asymbol **ignore_symbols;
1883 CONST char **filename_ptr;
1884 CONST char **functionname_ptr;
1885 unsigned int *retline_ptr;
1887 const struct ecoff_debug_swap * const debug_swap
1888 = &ecoff_backend (abfd)->debug_swap;
1893 bfd_size_type external_pdr_size;
1897 unsigned char *line_ptr;
1898 unsigned char *line_end;
1901 /* If we're not in the .text section, we don't have any line
1903 if (strcmp (section->name, _TEXT) != 0
1904 || offset < ecoff_data (abfd)->text_start
1905 || offset >= ecoff_data (abfd)->text_end)
1908 /* Make sure we have the FDR's. */
1909 if (ecoff_slurp_symbolic_info (abfd) == false
1910 || bfd_get_symcount (abfd) == 0)
1913 /* Each file descriptor (FDR) has a memory address. Here we track
1914 down which FDR we want. The FDR's are stored in increasing
1915 memory order. If speed is ever important, this can become a
1916 binary search. We must ignore FDR's with no PDR entries; they
1917 will have the adr of the FDR before or after them. */
1918 fdr_start = ecoff_data (abfd)->debug_info.fdr;
1919 fdr_end = fdr_start + ecoff_data (abfd)->debug_info.symbolic_header.ifdMax;
1920 fdr_hold = (FDR *) NULL;
1921 for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
1923 if (fdr_ptr->cpd == 0)
1925 if (offset < fdr_ptr->adr)
1929 if (fdr_hold == (FDR *) NULL)
1933 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
1934 have an address, which is relative to the FDR address, and are
1935 also stored in increasing memory order. */
1936 offset -= fdr_ptr->adr;
1937 external_pdr_size = debug_swap->external_pdr_size;
1938 pdr_ptr = ((char *) ecoff_data (abfd)->debug_info.external_pdr
1939 + fdr_ptr->ipdFirst * external_pdr_size);
1940 pdr_end = pdr_ptr + fdr_ptr->cpd * external_pdr_size;
1941 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
1943 /* The address of the first PDR is an offset which applies to the
1944 addresses of all the PDR's. */
1947 for (pdr_ptr += external_pdr_size;
1949 pdr_ptr += external_pdr_size)
1951 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
1952 if (offset < pdr.adr)
1956 /* Now we can look for the actual line number. The line numbers are
1957 stored in a very funky format, which I won't try to describe.
1958 Note that right here pdr_ptr and pdr hold the PDR *after* the one
1959 we want; we need this to compute line_end. */
1960 line_end = ecoff_data (abfd)->debug_info.line;
1961 if (pdr_ptr == pdr_end)
1962 line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
1964 line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset;
1966 /* Now change pdr and pdr_ptr to the one we want. */
1967 pdr_ptr -= external_pdr_size;
1968 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
1972 line_ptr = (ecoff_data (abfd)->debug_info.line
1973 + fdr_ptr->cbLineOffset
1974 + pdr.cbLineOffset);
1975 while (line_ptr < line_end)
1980 delta = *line_ptr >> 4;
1983 count = (*line_ptr & 0xf) + 1;
1987 delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff);
1988 if (delta >= 0x8000)
1993 if (offset < count * 4)
1995 offset -= count * 4;
1998 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
1999 at least according to gdb/mipsread.c. */
2000 if (fdr_ptr->rss == -1)
2002 *filename_ptr = NULL;
2004 *functionname_ptr = NULL;
2009 (*debug_swap->swap_ext_in)
2011 ((char *) ecoff_data (abfd)->debug_info.external_ext
2012 + pdr.isym * debug_swap->external_ext_size),
2014 *functionname_ptr = (ecoff_data (abfd)->debug_info.ssext
2015 + proc_ext.asym.iss);
2022 *filename_ptr = (ecoff_data (abfd)->debug_info.ss
2025 (*debug_swap->swap_sym_in)
2027 ((char *) ecoff_data (abfd)->debug_info.external_sym
2028 + (fdr_ptr->isymBase + pdr.isym) * debug_swap->external_sym_size),
2030 *functionname_ptr = (ecoff_data (abfd)->debug_info.ss
2034 if (lineno == ilineNil)
2036 *retline_ptr = lineno;
2040 /* We can't use the generic linking routines for ECOFF, because we
2041 have to handle all the debugging information. The generic link
2042 routine just works out the section contents and attaches a list of
2043 symbols. We find each input BFD by looping over all the seclets.
2044 We accumulate the debugging information for each input BFD. */
2046 /* Get ECOFF EXTR information for an external symbol. This function
2047 is passed to bfd_ecoff_debug_externals. */
2050 ecoff_get_extr (sym, esym)
2054 ecoff_symbol_type *ecoff_sym_ptr;
2057 /* Don't include debugging or local symbols. */
2058 if ((sym->flags & BSF_DEBUGGING) != 0
2059 || (sym->flags & BSF_LOCAL) != 0)
2062 if (bfd_asymbol_flavour (sym) != bfd_target_ecoff_flavour
2063 || ecoffsymbol (sym)->native == NULL)
2066 esym->cobol_main = 0;
2070 /* FIXME: we can do better than this for st and sc. */
2071 esym->asym.st = stGlobal;
2072 esym->asym.sc = scAbs;
2073 esym->asym.reserved = 0;
2074 esym->asym.index = indexNil;
2078 ecoff_sym_ptr = ecoffsymbol (sym);
2080 if (ecoff_sym_ptr->local)
2083 input_bfd = bfd_asymbol_bfd (sym);
2084 (*(ecoff_backend (input_bfd)->debug_swap.swap_ext_in))
2085 (input_bfd, ecoff_sym_ptr->native, esym);
2087 /* Adjust the FDR index for the symbol by that used for the input
2089 esym->ifd += ecoff_data (input_bfd)->debug_info.ifdbase;
2094 /* Set the external symbol index. This routine is passed to
2095 bfd_ecoff_debug_externals. */
2098 ecoff_set_index (sym, indx)
2102 ecoff_set_sym_index (sym, indx);
2105 /* This is the actual link routine. It builds the debugging
2106 information, and then lets the generic linking routine complete the
2110 ecoff_bfd_seclet_link (abfd, data, relocateable)
2113 boolean relocateable;
2115 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
2116 struct ecoff_debug_info * const debug = &ecoff_data (abfd)->debug_info;
2118 register asection *o;
2119 register bfd_seclet_type *p;
2121 /* We accumulate the debugging information counts in the symbolic
2123 symhdr = &debug->symbolic_header;
2124 symhdr->magic = backend->debug_swap.sym_magic;
2125 /* FIXME: What should the version stamp be? */
2127 symhdr->ilineMax = 0;
2131 symhdr->isymMax = 0;
2132 symhdr->ioptMax = 0;
2133 symhdr->iauxMax = 0;
2138 /* We accumulate the debugging information itself in the debug_info
2140 debug->line = debug->line_end = NULL;
2141 debug->external_dnr = debug->external_dnr_end = NULL;
2142 debug->external_pdr = debug->external_pdr_end = NULL;
2143 debug->external_sym = debug->external_sym_end = NULL;
2144 debug->external_opt = debug->external_opt_end = NULL;
2145 debug->external_aux = debug->external_aux_end = NULL;
2146 debug->ss = debug->ss_end = NULL;
2147 debug->external_fdr = debug->external_fdr_end = NULL;
2148 debug->external_rfd = debug->external_rfd_end = NULL;
2150 /* We need to accumulate the debugging symbols from each input BFD.
2151 We do this by looking through all the seclets to gather all the
2152 input BFD's. We use the output_has_begun field to avoid
2153 including a particular input BFD more than once. */
2155 /* Clear the output_has_begun fields. */
2156 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2157 for (p = o->seclets_head;
2158 p != (bfd_seclet_type *) NULL;
2160 if (p->type == bfd_indirect_seclet)
2161 p->u.indirect.section->owner->output_has_begun = false;
2163 /* Add in each input BFD. */
2164 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2166 for (p = o->seclets_head;
2167 p != (bfd_seclet_type *) NULL;
2173 if (p->type != bfd_indirect_seclet)
2176 input_bfd = p->u.indirect.section->owner;
2177 if (input_bfd->output_has_begun)
2180 if (bfd_get_flavour (input_bfd) == bfd_target_ecoff_flavour)
2181 ret = (bfd_ecoff_debug_accumulate
2182 (abfd, debug, &backend->debug_swap,
2183 input_bfd, &ecoff_data (input_bfd)->debug_info,
2184 &ecoff_backend (input_bfd)->debug_swap, relocateable));
2186 ret = bfd_ecoff_debug_link_other (abfd,
2188 &backend->debug_swap,
2194 /* Combine the register masks. */
2195 ecoff_data (abfd)->gprmask |= ecoff_data (input_bfd)->gprmask;
2196 ecoff_data (abfd)->fprmask |= ecoff_data (input_bfd)->fprmask;
2197 ecoff_data (abfd)->cprmask[0] |= ecoff_data (input_bfd)->cprmask[0];
2198 ecoff_data (abfd)->cprmask[1] |= ecoff_data (input_bfd)->cprmask[1];
2199 ecoff_data (abfd)->cprmask[2] |= ecoff_data (input_bfd)->cprmask[2];
2200 ecoff_data (abfd)->cprmask[3] |= ecoff_data (input_bfd)->cprmask[3];
2202 input_bfd->output_has_begun = true;
2205 /* Don't bother to do any linking of .reginfo sections. */
2206 if (strcmp (o->name, REGINFO) == 0)
2207 o->seclets_head = (bfd_seclet_type *) NULL;
2210 /* Let the generic link routine handle writing out the section
2212 return bfd_generic_seclet_link (abfd, data, relocateable);
2215 /* Set the architecture. The supported architecture is stored in the
2216 backend pointer. We always set the architecture anyhow, since many
2217 callers ignore the return value. */
2220 ecoff_set_arch_mach (abfd, arch, machine)
2222 enum bfd_architecture arch;
2223 unsigned long machine;
2225 bfd_default_set_arch_mach (abfd, arch, machine);
2226 return arch == ecoff_backend (abfd)->arch;
2229 /* Get the size of the section headers. We do not output the .reginfo
2233 ecoff_sizeof_headers (abfd, reloc)
2241 for (current = abfd->sections;
2242 current != (asection *)NULL;
2243 current = current->next)
2244 if (strcmp (current->name, REGINFO) != 0)
2247 return (bfd_coff_filhsz (abfd)
2248 + bfd_coff_aoutsz (abfd)
2249 + c * bfd_coff_scnhsz (abfd));
2252 /* Get the contents of a section. This is where we handle reading the
2253 .reginfo section, which implicitly holds the contents of an
2254 ecoff_reginfo structure. */
2257 ecoff_get_section_contents (abfd, section, location, offset, count)
2262 bfd_size_type count;
2264 ecoff_data_type *tdata = ecoff_data (abfd);
2265 struct ecoff_reginfo s;
2268 if (strcmp (section->name, REGINFO) != 0)
2269 return bfd_generic_get_section_contents (abfd, section, location,
2272 s.gp_value = tdata->gp;
2273 s.gprmask = tdata->gprmask;
2274 for (i = 0; i < 4; i++)
2275 s.cprmask[i] = tdata->cprmask[i];
2276 s.fprmask = tdata->fprmask;
2278 /* bfd_get_section_contents has already checked that the offset and
2279 size is reasonable. We don't have to worry about swapping or any
2280 such thing; the .reginfo section is defined such that the
2281 contents are an ecoff_reginfo structure as seen on the host. */
2282 memcpy (location, ((char *) &s) + offset, count);
2286 /* Calculate the file position for each section, and set
2290 ecoff_compute_section_file_positions (abfd)
2298 sofar = ecoff_sizeof_headers (abfd, false);
2301 for (current = abfd->sections;
2302 current != (asection *) NULL;
2303 current = current->next)
2305 /* Only deal with sections which have contents */
2306 if ((current->flags & (SEC_HAS_CONTENTS | SEC_LOAD)) == 0
2307 || strcmp (current->name, REGINFO) == 0)
2310 /* On Ultrix, the data sections in an executable file must be
2311 aligned to a page boundary within the file. This does not
2312 affect the section size, though. FIXME: Does this work for
2313 other platforms? It requires some modification for the
2314 Alpha, because .rdata on the Alpha goes with the text, not
2316 if ((abfd->flags & EXEC_P) != 0
2317 && (abfd->flags & D_PAGED) != 0
2318 && first_data != false
2319 && (current->flags & SEC_CODE) == 0
2320 && (! ecoff_backend (abfd)->rdata_in_text
2321 || strcmp (current->name, _RDATA) != 0)
2322 && strcmp (current->name, _PDATA) != 0)
2324 const bfd_vma round = ecoff_backend (abfd)->round;
2326 sofar = (sofar + round - 1) &~ (round - 1);
2330 /* Align the sections in the file to the same boundary on
2331 which they are aligned in virtual memory. */
2333 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
2335 current->filepos = sofar;
2337 sofar += current->_raw_size;
2339 /* make sure that this section is of the right size too */
2341 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
2342 current->_raw_size += sofar - old_sofar;
2345 ecoff_data (abfd)->reloc_filepos = sofar;
2348 /* Set the contents of a section. This is where we handle setting the
2349 contents of the .reginfo section, which implicitly holds a
2350 ecoff_reginfo structure. */
2353 ecoff_set_section_contents (abfd, section, location, offset, count)
2358 bfd_size_type count;
2360 if (abfd->output_has_begun == false)
2361 ecoff_compute_section_file_positions (abfd);
2363 if (strcmp (section->name, REGINFO) == 0)
2365 ecoff_data_type *tdata = ecoff_data (abfd);
2366 struct ecoff_reginfo s;
2369 /* If the caller is only changing part of the structure, we must
2370 retrieve the current information before the memcpy. */
2371 if (offset != 0 || count != sizeof (struct ecoff_reginfo))
2373 s.gp_value = tdata->gp;
2374 s.gprmask = tdata->gprmask;
2375 for (i = 0; i < 4; i++)
2376 s.cprmask[i] = tdata->cprmask[i];
2377 s.fprmask = tdata->fprmask;
2380 /* bfd_set_section_contents has already checked that the offset
2381 and size is reasonable. We don't have to worry about
2382 swapping or any such thing; the .reginfo section is defined
2383 such that the contents are an ecoff_reginfo structure as seen
2385 memcpy (((char *) &s) + offset, location, count);
2387 tdata->gp = s.gp_value;
2388 tdata->gprmask = s.gprmask;
2389 for (i = 0; i < 4; i++)
2390 tdata->cprmask[i] = s.cprmask[i];
2391 tdata->fprmask = s.fprmask;
2397 bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET);
2400 return (bfd_write (location, 1, count, abfd) == count) ? true : false;
2405 /* Write out an ECOFF file. */
2408 ecoff_write_object_contents (abfd)
2411 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
2412 const bfd_vma round = backend->round;
2413 const bfd_size_type filhsz = bfd_coff_filhsz (abfd);
2414 const bfd_size_type aoutsz = bfd_coff_aoutsz (abfd);
2415 const bfd_size_type scnhsz = bfd_coff_scnhsz (abfd);
2416 const bfd_size_type external_hdr_size
2417 = backend->debug_swap.external_hdr_size;
2418 const bfd_size_type external_reloc_size = backend->external_reloc_size;
2419 void (* const adjust_reloc_out) PARAMS ((bfd *,
2421 struct internal_reloc *))
2422 = backend->adjust_reloc_out;
2423 void (* const swap_reloc_out) PARAMS ((bfd *,
2424 const struct internal_reloc *,
2426 = backend->swap_reloc_out;
2427 struct ecoff_debug_info * const debug = &ecoff_data (abfd)->debug_info;
2428 HDRR * const symhdr = &debug->symbolic_header;
2432 file_ptr reloc_base;
2434 unsigned long reloc_size;
2435 unsigned long text_size;
2436 unsigned long text_start;
2437 unsigned long data_size;
2438 unsigned long data_start;
2439 unsigned long bss_size;
2441 struct internal_filehdr internal_f;
2442 struct internal_aouthdr internal_a;
2445 bfd_error = system_call_error;
2447 if(abfd->output_has_begun == false)
2448 ecoff_compute_section_file_positions(abfd);
2450 if (abfd->sections != (asection *) NULL)
2451 scn_base = abfd->sections->filepos;
2454 reloc_base = ecoff_data (abfd)->reloc_filepos;
2458 for (current = abfd->sections;
2459 current != (asection *)NULL;
2460 current = current->next)
2462 if (strcmp (current->name, REGINFO) == 0)
2464 current->target_index = count;
2466 if (current->reloc_count != 0)
2468 bfd_size_type relsize;
2470 current->rel_filepos = reloc_base;
2471 relsize = current->reloc_count * external_reloc_size;
2472 reloc_size += relsize;
2473 reloc_base += relsize;
2476 current->rel_filepos = 0;
2479 sym_base = reloc_base + reloc_size;
2481 /* At least on Ultrix, the symbol table of an executable file must
2482 be aligned to a page boundary. FIXME: Is this true on other
2484 if ((abfd->flags & EXEC_P) != 0
2485 && (abfd->flags & D_PAGED) != 0)
2486 sym_base = (sym_base + round - 1) &~ (round - 1);
2488 ecoff_data (abfd)->sym_filepos = sym_base;
2490 if ((abfd->flags & D_PAGED) != 0)
2491 text_size = ecoff_sizeof_headers (abfd, false);
2499 /* Write section headers to the file. */
2501 buff = (PTR) alloca (scnhsz);
2502 internal_f.f_nscns = 0;
2503 if (bfd_seek (abfd, (file_ptr) (filhsz + aoutsz), SEEK_SET) != 0)
2505 for (current = abfd->sections;
2506 current != (asection *) NULL;
2507 current = current->next)
2509 struct internal_scnhdr section;
2512 if (strcmp (current->name, REGINFO) == 0)
2514 BFD_ASSERT (current->reloc_count == 0);
2518 ++internal_f.f_nscns;
2520 strncpy (section.s_name, current->name, sizeof section.s_name);
2522 /* FIXME: is this correct for shared libraries? I think it is
2523 but I have no platform to check. Ian Lance Taylor. */
2524 vma = bfd_get_section_vma (abfd, current);
2525 if (strcmp (current->name, _LIB) == 0)
2526 section.s_vaddr = 0;
2528 section.s_vaddr = vma;
2530 section.s_paddr = vma;
2531 section.s_size = bfd_get_section_size_before_reloc (current);
2533 /* If this section is unloadable then the scnptr will be 0. */
2534 if ((current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
2535 section.s_scnptr = 0;
2537 section.s_scnptr = current->filepos;
2538 section.s_relptr = current->rel_filepos;
2540 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2541 object file produced by the assembler is supposed to point to
2542 information about how much room is required by objects of
2543 various different sizes. I think this only matters if we
2544 want the linker to compute the best size to use, or
2545 something. I don't know what happens if the information is
2547 section.s_lnnoptr = 0;
2549 section.s_nreloc = current->reloc_count;
2550 section.s_nlnno = 0;
2551 section.s_flags = ecoff_sec_to_styp_flags (current->name,
2554 bfd_coff_swap_scnhdr_out (abfd, (PTR) §ion, buff);
2555 if (bfd_write (buff, 1, scnhsz, abfd) != scnhsz)
2558 if ((section.s_flags & STYP_TEXT) != 0
2559 || ((section.s_flags & STYP_RDATA) != 0
2560 && backend->rdata_in_text)
2561 || strcmp (current->name, _PDATA) == 0)
2563 text_size += bfd_get_section_size_before_reloc (current);
2564 if (text_start == 0 || text_start > vma)
2567 else if ((section.s_flags & STYP_RDATA) != 0
2568 || (section.s_flags & STYP_DATA) != 0
2569 || (section.s_flags & STYP_LITA) != 0
2570 || (section.s_flags & STYP_LIT8) != 0
2571 || (section.s_flags & STYP_LIT4) != 0
2572 || (section.s_flags & STYP_SDATA) != 0)
2574 data_size += bfd_get_section_size_before_reloc (current);
2575 if (data_start == 0 || data_start > vma)
2578 else if ((section.s_flags & STYP_BSS) != 0
2579 || (section.s_flags & STYP_SBSS) != 0)
2580 bss_size += bfd_get_section_size_before_reloc (current);
2583 /* Set up the file header. */
2585 internal_f.f_magic = ecoff_get_magic (abfd);
2587 /* We will NOT put a fucking timestamp in the header here. Every
2588 time you put it back, I will come in and take it out again. I'm
2589 sorry. This field does not belong here. We fill it with a 0 so
2590 it compares the same but is not a reasonable time. --
2592 internal_f.f_timdat = 0;
2594 if (bfd_get_symcount (abfd) != 0)
2596 /* The ECOFF f_nsyms field is not actually the number of
2597 symbols, it's the size of symbolic information header. */
2598 internal_f.f_nsyms = external_hdr_size;
2599 internal_f.f_symptr = sym_base;
2603 internal_f.f_nsyms = 0;
2604 internal_f.f_symptr = 0;
2607 internal_f.f_opthdr = aoutsz;
2609 internal_f.f_flags = F_LNNO;
2610 if (reloc_size == 0)
2611 internal_f.f_flags |= F_RELFLG;
2612 if (bfd_get_symcount (abfd) == 0)
2613 internal_f.f_flags |= F_LSYMS;
2614 if (abfd->flags & EXEC_P)
2615 internal_f.f_flags |= F_EXEC;
2617 if (! abfd->xvec->byteorder_big_p)
2618 internal_f.f_flags |= F_AR32WR;
2620 internal_f.f_flags |= F_AR32W;
2622 /* Set up the ``optional'' header. */
2623 if ((abfd->flags & D_PAGED) != 0)
2624 internal_a.magic = ECOFF_AOUT_ZMAGIC;
2626 internal_a.magic = ECOFF_AOUT_OMAGIC;
2628 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
2629 linker happy. But, is it right? */
2630 internal_a.vstamp = 0x20a;
2632 /* At least on Ultrix, these have to be rounded to page boundaries.
2633 FIXME: Is this true on other platforms? */
2634 if ((abfd->flags & D_PAGED) != 0)
2636 internal_a.tsize = (text_size + round - 1) &~ (round - 1);
2637 internal_a.text_start = text_start &~ (round - 1);
2638 internal_a.dsize = (data_size + round - 1) &~ (round - 1);
2639 internal_a.data_start = data_start &~ (round - 1);
2643 internal_a.tsize = text_size;
2644 internal_a.text_start = text_start;
2645 internal_a.dsize = data_size;
2646 internal_a.data_start = data_start;
2649 /* On Ultrix, the initial portions of the .sbss and .bss segments
2650 are at the end of the data section. The bsize field in the
2651 optional header records how many bss bytes are required beyond
2652 those in the data section. The value is not rounded to a page
2654 if (bss_size < internal_a.dsize - data_size)
2657 bss_size -= internal_a.dsize - data_size;
2658 internal_a.bsize = bss_size;
2659 internal_a.bss_start = internal_a.data_start + internal_a.dsize;
2661 internal_a.entry = bfd_get_start_address (abfd);
2663 internal_a.gp_value = ecoff_data (abfd)->gp;
2665 internal_a.gprmask = ecoff_data (abfd)->gprmask;
2666 internal_a.fprmask = ecoff_data (abfd)->fprmask;
2667 for (i = 0; i < 4; i++)
2668 internal_a.cprmask[i] = ecoff_data (abfd)->cprmask[i];
2670 /* Write out the file header and the optional header. */
2672 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
2675 buff = (PTR) alloca (filhsz);
2676 bfd_coff_swap_filehdr_out (abfd, (PTR) &internal_f, buff);
2677 if (bfd_write (buff, 1, filhsz, abfd) != filhsz)
2680 buff = (PTR) alloca (aoutsz);
2681 bfd_coff_swap_aouthdr_out (abfd, (PTR) &internal_a, buff);
2682 if (bfd_write (buff, 1, aoutsz, abfd) != aoutsz)
2685 /* Build the external symbol information. This must be done before
2686 writing out the relocs so that we know the symbol indices. */
2687 symhdr->iextMax = 0;
2688 symhdr->issExtMax = 0;
2689 debug->external_ext = debug->external_ext_end = NULL;
2690 debug->ssext = debug->ssext_end = NULL;
2691 if (bfd_ecoff_debug_externals (abfd, debug, &backend->debug_swap,
2692 (((abfd->flags & EXEC_P) == 0)
2694 ecoff_get_extr, ecoff_set_index)
2698 /* Write out the relocs. */
2699 for (current = abfd->sections;
2700 current != (asection *) NULL;
2701 current = current->next)
2703 arelent **reloc_ptr_ptr;
2704 arelent **reloc_end;
2707 if (current->reloc_count == 0)
2710 buff = bfd_alloc (abfd, current->reloc_count * external_reloc_size);
2713 bfd_error = no_memory;
2717 reloc_ptr_ptr = current->orelocation;
2718 reloc_end = reloc_ptr_ptr + current->reloc_count;
2719 out_ptr = (char *) buff;
2721 reloc_ptr_ptr < reloc_end;
2722 reloc_ptr_ptr++, out_ptr += external_reloc_size)
2726 struct internal_reloc in;
2728 memset (&in, 0, sizeof in);
2730 reloc = *reloc_ptr_ptr;
2731 sym = *reloc->sym_ptr_ptr;
2733 in.r_vaddr = reloc->address + bfd_get_section_vma (abfd, current);
2734 in.r_type = reloc->howto->type;
2736 if ((sym->flags & BSF_SECTION_SYM) == 0)
2738 in.r_symndx = ecoff_get_sym_index (*reloc->sym_ptr_ptr);
2745 name = bfd_get_section_name (abfd, bfd_get_section (sym));
2746 if (strcmp (name, ".text") == 0)
2747 in.r_symndx = RELOC_SECTION_TEXT;
2748 else if (strcmp (name, ".rdata") == 0)
2749 in.r_symndx = RELOC_SECTION_RDATA;
2750 else if (strcmp (name, ".data") == 0)
2751 in.r_symndx = RELOC_SECTION_DATA;
2752 else if (strcmp (name, ".sdata") == 0)
2753 in.r_symndx = RELOC_SECTION_SDATA;
2754 else if (strcmp (name, ".sbss") == 0)
2755 in.r_symndx = RELOC_SECTION_SBSS;
2756 else if (strcmp (name, ".bss") == 0)
2757 in.r_symndx = RELOC_SECTION_BSS;
2758 else if (strcmp (name, ".init") == 0)
2759 in.r_symndx = RELOC_SECTION_INIT;
2760 else if (strcmp (name, ".lit8") == 0)
2761 in.r_symndx = RELOC_SECTION_LIT8;
2762 else if (strcmp (name, ".lit4") == 0)
2763 in.r_symndx = RELOC_SECTION_LIT4;
2764 else if (strcmp (name, ".xdata") == 0)
2765 in.r_symndx = RELOC_SECTION_XDATA;
2766 else if (strcmp (name, ".pdata") == 0)
2767 in.r_symndx = RELOC_SECTION_PDATA;
2768 else if (strcmp (name, ".fini") == 0)
2769 in.r_symndx = RELOC_SECTION_FINI;
2770 else if (strcmp (name, ".lita") == 0)
2771 in.r_symndx = RELOC_SECTION_LITA;
2772 else if (strcmp (name, "*ABS*") == 0)
2773 in.r_symndx = RELOC_SECTION_ABS;
2779 (*adjust_reloc_out) (abfd, reloc, &in);
2781 (*swap_reloc_out) (abfd, &in, (PTR) out_ptr);
2784 if (bfd_seek (abfd, current->rel_filepos, SEEK_SET) != 0)
2786 if (bfd_write (buff, external_reloc_size, current->reloc_count, abfd)
2787 != external_reloc_size * current->reloc_count)
2789 bfd_release (abfd, buff);
2792 /* Write out the symbolic debugging information. */
2793 if (bfd_get_symcount (abfd) > 0)
2795 /* Write out the debugging information. */
2796 if (bfd_ecoff_write_debug (abfd, debug, &backend->debug_swap,
2797 ecoff_data (abfd)->sym_filepos)
2801 else if ((abfd->flags & EXEC_P) != 0
2802 && (abfd->flags & D_PAGED) != 0)
2806 /* A demand paged executable must occupy an even number of
2808 if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
2811 if (bfd_read (&c, 1, 1, abfd) == 0)
2813 if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
2816 if (bfd_write (&c, 1, 1, abfd) != 1)
2823 /* Archive handling. ECOFF uses what appears to be a unique type of
2824 archive header (which I call an armap). The byte ordering of the
2825 armap and the contents are encoded in the name of the armap itself.
2826 At least for now, we only support archives with the same byte
2827 ordering in the armap and the contents.
2829 The first four bytes in the armap are the number of symbol
2830 definitions. This is always a power of two.
2832 This is followed by the symbol definitions. Each symbol definition
2833 occupies 8 bytes. The first four bytes are the offset from the
2834 start of the armap strings to the null-terminated string naming
2835 this symbol. The second four bytes are the file offset to the
2836 archive member which defines this symbol. If the second four bytes
2837 are 0, then this is not actually a symbol definition, and it should
2840 The symbols are hashed into the armap with a closed hashing scheme.
2841 See the functions below for the details of the algorithm.
2843 We could use the hash table when looking up symbols in a library.
2844 This would require a new BFD target entry point to replace the
2845 bfd_get_next_mapent function used by the linker.
2847 After the symbol definitions comes four bytes holding the size of
2848 the string table, followed by the string table itself. */
2850 /* The name of an archive headers looks like this:
2851 __________E[BL]E[BL]_ (with a trailing space).
2852 The trailing space is changed to an X if the archive is changed to
2853 indicate that the armap is out of date.
2855 The Alpha seems to use ________64E[BL]E[BL]_. */
2857 #define ARMAP_BIG_ENDIAN 'B'
2858 #define ARMAP_LITTLE_ENDIAN 'L'
2859 #define ARMAP_MARKER 'E'
2860 #define ARMAP_START_LENGTH 10
2861 #define ARMAP_HEADER_MARKER_INDEX 10
2862 #define ARMAP_HEADER_ENDIAN_INDEX 11
2863 #define ARMAP_OBJECT_MARKER_INDEX 12
2864 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2865 #define ARMAP_END_INDEX 14
2866 #define ARMAP_END "_ "
2868 /* This is a magic number used in the hashing algorithm. */
2869 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2871 /* This returns the hash value to use for a string. It also sets
2872 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2873 is the number of entries in the hash table, and HLOG is the log
2877 ecoff_armap_hash (s, rehash, size, hlog)
2879 unsigned int *rehash;
2887 hash = ((hash >> 27) | (hash << 5)) + *s++;
2888 hash *= ARMAP_HASH_MAGIC;
2889 *rehash = (hash & (size - 1)) | 1;
2890 return hash >> (32 - hlog);
2893 /* Read in the armap. */
2896 ecoff_slurp_armap (abfd)
2901 struct areltdata *mapdata;
2902 bfd_size_type parsed_size;
2904 struct artdata *ardata;
2907 struct symdef *symdef_ptr;
2910 /* Get the name of the first element. */
2911 i = bfd_read ((PTR) nextname, 1, 16, abfd);
2917 bfd_seek (abfd, (file_ptr) -16, SEEK_CUR);
2919 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2920 standard COFF armap. We could move the ECOFF armap stuff into
2921 bfd_slurp_armap, but that seems inappropriate since no other
2922 target uses this format. Instead, we check directly for a COFF
2924 if (strncmp (nextname, "/ ", 16) == 0)
2925 return bfd_slurp_armap (abfd);
2927 /* See if the first element is an armap. */
2928 if (strncmp (nextname, ecoff_backend (abfd)->armap_start,
2929 ARMAP_START_LENGTH) != 0
2930 || nextname[ARMAP_HEADER_MARKER_INDEX] != ARMAP_MARKER
2931 || (nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
2932 && nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
2933 || nextname[ARMAP_OBJECT_MARKER_INDEX] != ARMAP_MARKER
2934 || (nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
2935 && nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
2936 || strncmp (nextname + ARMAP_END_INDEX,
2937 ARMAP_END, sizeof ARMAP_END - 1) != 0)
2939 bfd_has_map (abfd) = false;
2943 /* Make sure we have the right byte ordering. */
2944 if (((nextname[ARMAP_HEADER_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
2945 ^ (abfd->xvec->header_byteorder_big_p != false))
2946 || ((nextname[ARMAP_OBJECT_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
2947 ^ (abfd->xvec->byteorder_big_p != false)))
2949 bfd_error = wrong_format;
2953 /* Read in the armap. */
2954 ardata = bfd_ardata (abfd);
2955 mapdata = snarf_ar_hdr (abfd);
2956 if (mapdata == (struct areltdata *) NULL)
2958 parsed_size = mapdata->parsed_size;
2959 bfd_release (abfd, (PTR) mapdata);
2961 raw_armap = (char *) bfd_alloc (abfd, parsed_size);
2962 if (raw_armap == (char *) NULL)
2964 bfd_error = no_memory;
2968 if (bfd_read ((PTR) raw_armap, 1, parsed_size, abfd) != parsed_size)
2970 bfd_error = malformed_archive;
2971 bfd_release (abfd, (PTR) raw_armap);
2975 count = bfd_h_get_32 (abfd, (PTR) raw_armap);
2977 ardata->symdef_count = 0;
2978 ardata->cache = (struct ar_cache *) NULL;
2980 /* This code used to overlay the symdefs over the raw archive data,
2981 but that doesn't work on a 64 bit host. */
2983 stringbase = raw_armap + count * 8 + 8;
2985 #ifdef CHECK_ARMAP_HASH
2989 /* Double check that I have the hashing algorithm right by making
2990 sure that every symbol can be looked up successfully. */
2992 for (i = 1; i < count; i <<= 1)
2994 BFD_ASSERT (i == count);
2996 raw_ptr = raw_armap + 4;
2997 for (i = 0; i < count; i++, raw_ptr += 8)
2999 unsigned int name_offset, file_offset;
3000 unsigned int hash, rehash, srch;
3002 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3003 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + 4));
3004 if (file_offset == 0)
3006 hash = ecoff_armap_hash (stringbase + name_offset, &rehash, count,
3011 /* See if we can rehash to this location. */
3012 for (srch = (hash + rehash) & (count - 1);
3013 srch != hash && srch != i;
3014 srch = (srch + rehash) & (count - 1))
3015 BFD_ASSERT (bfd_h_get_32 (abfd, (PTR) (raw_armap + 8 + srch * 8))
3017 BFD_ASSERT (srch == i);
3021 #endif /* CHECK_ARMAP_HASH */
3023 raw_ptr = raw_armap + 4;
3024 for (i = 0; i < count; i++, raw_ptr += 8)
3025 if (bfd_h_get_32 (abfd, (PTR) (raw_ptr + 4)) != 0)
3026 ++ardata->symdef_count;
3028 symdef_ptr = ((struct symdef *)
3030 ardata->symdef_count * sizeof (struct symdef)));
3031 ardata->symdefs = (carsym *) symdef_ptr;
3033 raw_ptr = raw_armap + 4;
3034 for (i = 0; i < count; i++, raw_ptr += 8)
3036 unsigned int name_offset, file_offset;
3038 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + 4));
3039 if (file_offset == 0)
3041 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3042 symdef_ptr->s.name = stringbase + name_offset;
3043 symdef_ptr->file_offset = file_offset;
3047 ardata->first_file_filepos = bfd_tell (abfd);
3048 /* Pad to an even boundary. */
3049 ardata->first_file_filepos += ardata->first_file_filepos % 2;
3051 bfd_has_map (abfd) = true;
3056 /* Write out an armap. */
3059 ecoff_write_armap (abfd, elength, map, orl_count, stridx)
3061 unsigned int elength;
3063 unsigned int orl_count;
3066 unsigned int hashsize, hashlog;
3067 unsigned int symdefsize;
3069 unsigned int stringsize;
3070 unsigned int mapsize;
3073 struct stat statbuf;
3076 bfd_byte *hashtable;
3080 /* Ultrix appears to use as a hash table size the least power of two
3081 greater than twice the number of entries. */
3082 for (hashlog = 0; (1 << hashlog) <= 2 * orl_count; hashlog++)
3084 hashsize = 1 << hashlog;
3086 symdefsize = hashsize * 8;
3088 stringsize = stridx + padit;
3090 /* Include 8 bytes to store symdefsize and stringsize in output. */
3091 mapsize = symdefsize + stringsize + 8;
3093 firstreal = SARMAG + sizeof (struct ar_hdr) + mapsize + elength;
3095 memset ((PTR) &hdr, 0, sizeof hdr);
3097 /* Work out the ECOFF armap name. */
3098 strcpy (hdr.ar_name, ecoff_backend (abfd)->armap_start);
3099 hdr.ar_name[ARMAP_HEADER_MARKER_INDEX] = ARMAP_MARKER;
3100 hdr.ar_name[ARMAP_HEADER_ENDIAN_INDEX] =
3101 (abfd->xvec->header_byteorder_big_p
3103 : ARMAP_LITTLE_ENDIAN);
3104 hdr.ar_name[ARMAP_OBJECT_MARKER_INDEX] = ARMAP_MARKER;
3105 hdr.ar_name[ARMAP_OBJECT_ENDIAN_INDEX] =
3106 abfd->xvec->byteorder_big_p ? ARMAP_BIG_ENDIAN : ARMAP_LITTLE_ENDIAN;
3107 memcpy (hdr.ar_name + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1);
3109 /* Write the timestamp of the archive header to be just a little bit
3110 later than the timestamp of the file, otherwise the linker will
3111 complain that the index is out of date. Actually, the Ultrix
3112 linker just checks the archive name; the GNU linker may check the
3114 stat (abfd->filename, &statbuf);
3115 sprintf (hdr.ar_date, "%ld", (long) (statbuf.st_mtime + 60));
3117 /* The DECstation uses zeroes for the uid, gid and mode of the
3119 hdr.ar_uid[0] = '0';
3120 hdr.ar_gid[0] = '0';
3121 hdr.ar_mode[0] = '0';
3123 sprintf (hdr.ar_size, "%-10d", (int) mapsize);
3125 hdr.ar_fmag[0] = '`';
3126 hdr.ar_fmag[1] = '\n';
3128 /* Turn all null bytes in the header into spaces. */
3129 for (i = 0; i < sizeof (struct ar_hdr); i++)
3130 if (((char *)(&hdr))[i] == '\0')
3131 (((char *)(&hdr))[i]) = ' ';
3133 if (bfd_write ((PTR) &hdr, 1, sizeof (struct ar_hdr), abfd)
3134 != sizeof (struct ar_hdr))
3137 bfd_h_put_32 (abfd, hashsize, temp);
3138 if (bfd_write (temp, 1, 4, abfd) != 4)
3141 hashtable = (bfd_byte *) bfd_zalloc (abfd, symdefsize);
3143 current = abfd->archive_head;
3145 for (i = 0; i < orl_count; i++)
3147 unsigned int hash, rehash;
3149 /* Advance firstreal to the file position of this archive
3151 if (((bfd *) map[i].pos) != last_elt)
3155 firstreal += arelt_size (current) + sizeof (struct ar_hdr);
3156 firstreal += firstreal % 2;
3157 current = current->next;
3159 while (current != (bfd *) map[i].pos);
3164 hash = ecoff_armap_hash (*map[i].name, &rehash, hashsize, hashlog);
3165 if (bfd_h_get_32 (abfd, (PTR) (hashtable + (hash * 8) + 4)) != 0)
3169 /* The desired slot is already taken. */
3170 for (srch = (hash + rehash) & (hashsize - 1);
3172 srch = (srch + rehash) & (hashsize - 1))
3173 if (bfd_h_get_32 (abfd, (PTR) (hashtable + (srch * 8) + 4)) == 0)
3176 BFD_ASSERT (srch != hash);
3181 bfd_h_put_32 (abfd, map[i].namidx, (PTR) (hashtable + hash * 8));
3182 bfd_h_put_32 (abfd, firstreal, (PTR) (hashtable + hash * 8 + 4));
3185 if (bfd_write (hashtable, 1, symdefsize, abfd) != symdefsize)
3188 bfd_release (abfd, hashtable);
3190 /* Now write the strings. */
3191 bfd_h_put_32 (abfd, stringsize, temp);
3192 if (bfd_write (temp, 1, 4, abfd) != 4)
3194 for (i = 0; i < orl_count; i++)
3198 len = strlen (*map[i].name) + 1;
3199 if (bfd_write ((PTR) (*map[i].name), 1, len, abfd) != len)
3203 /* The spec sez this should be a newline. But in order to be
3204 bug-compatible for DECstation ar we use a null. */
3207 if (bfd_write ("\0", 1, 1, abfd) != 1)
3214 /* See whether this BFD is an archive. If it is, read in the armap
3215 and the extended name table. */
3218 ecoff_archive_p (abfd)
3221 char armag[SARMAG + 1];
3223 if (bfd_read ((PTR) armag, 1, SARMAG, abfd) != SARMAG
3224 || strncmp (armag, ARMAG, SARMAG) != 0)
3226 bfd_error = wrong_format;
3227 return (bfd_target *) NULL;
3230 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3231 involves a cast, we can't do it as the left operand of
3233 abfd->tdata.aout_ar_data =
3234 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
3236 if (bfd_ardata (abfd) == (struct artdata *) NULL)
3238 bfd_error = no_memory;
3239 return (bfd_target *) NULL;
3242 bfd_ardata (abfd)->first_file_filepos = SARMAG;
3244 if (ecoff_slurp_armap (abfd) == false
3245 || ecoff_slurp_extended_name_table (abfd) == false)
3247 bfd_release (abfd, bfd_ardata (abfd));
3248 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
3249 return (bfd_target *) NULL;