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 boolean ecoff_slurp_symbolic_header PARAMS ((bfd *abfd));
49 static boolean ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym,
50 asymbol *asym, int ext,
51 asymbol **indirect_ptr_ptr));
52 static void ecoff_emit_aggregate PARAMS ((bfd *abfd, FDR *fdr,
54 RNDXR *rndx, long isym,
56 static char *ecoff_type_to_string PARAMS ((bfd *abfd, FDR *fdr,
58 static boolean ecoff_slurp_reloc_table PARAMS ((bfd *abfd, asection *section,
60 static void ecoff_compute_section_file_positions PARAMS ((bfd *abfd));
61 static bfd_size_type ecoff_compute_reloc_file_positions PARAMS ((bfd *abfd));
62 static boolean ecoff_get_extr PARAMS ((asymbol *, EXTR *));
63 static void ecoff_set_index PARAMS ((asymbol *, bfd_size_type));
64 static unsigned int ecoff_armap_hash PARAMS ((CONST char *s,
69 /* This stuff is somewhat copied from coffcode.h. */
71 static asection bfd_debug_section = { "*DEBUG*" };
73 /* Create an ECOFF object. */
79 abfd->tdata.ecoff_obj_data = ((struct ecoff_tdata *)
80 bfd_zalloc (abfd, sizeof (ecoff_data_type)));
81 if (abfd->tdata.ecoff_obj_data == NULL)
83 bfd_set_error (bfd_error_no_memory);
90 /* This is a hook called by coff_real_object_p to create any backend
91 specific information. */
94 ecoff_mkobject_hook (abfd, filehdr, aouthdr)
99 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
100 struct internal_aouthdr *internal_a = (struct internal_aouthdr *) aouthdr;
101 ecoff_data_type *ecoff;
103 if (ecoff_mkobject (abfd) == false)
106 ecoff = ecoff_data (abfd);
108 ecoff->sym_filepos = internal_f->f_symptr;
110 if (internal_a != (struct internal_aouthdr *) NULL)
114 ecoff->text_start = internal_a->text_start;
115 ecoff->text_end = internal_a->text_start + internal_a->tsize;
116 ecoff->gp = internal_a->gp_value;
117 ecoff->gprmask = internal_a->gprmask;
118 for (i = 0; i < 4; i++)
119 ecoff->cprmask[i] = internal_a->cprmask[i];
120 ecoff->fprmask = internal_a->fprmask;
121 if (internal_a->magic == ECOFF_AOUT_ZMAGIC)
122 abfd->flags |= D_PAGED;
125 /* It turns out that no special action is required by the MIPS or
126 Alpha ECOFF backends. They have different information in the
127 a.out header, but we just copy it all (e.g., gprmask, cprmask and
128 fprmask) and let the swapping routines ensure that only relevant
129 information is written out. */
134 /* This is a hook needed by SCO COFF, but we have nothing to do. */
138 ecoff_make_section_hook (abfd, name)
142 return (asection *) NULL;
145 /* Initialize a new section. */
148 ecoff_new_section_hook (abfd, section)
152 /* For the .pdata section, which has a special meaning on the Alpha,
153 we set the alignment to 8. We correct this later in
154 ecoff_compute_section_file_positions. We do this hackery because
155 we need to know the exact unaligned size of the .pdata section in
156 order to set the lnnoptr field correctly. */
157 if (strcmp (section->name, _PDATA) == 0)
158 section->alignment_power = 3;
160 section->alignment_power = abfd->xvec->align_power_min;
162 if (strcmp (section->name, _TEXT) == 0)
163 section->flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
164 else if (strcmp (section->name, _DATA) == 0
165 || strcmp (section->name, _SDATA) == 0)
166 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
167 else if (strcmp (section->name, _RDATA) == 0
168 || strcmp (section->name, _LIT8) == 0
169 || strcmp (section->name, _LIT4) == 0)
170 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
171 else if (strcmp (section->name, _BSS) == 0
172 || strcmp (section->name, _SBSS) == 0)
173 section->flags |= SEC_ALLOC;
174 else if (strcmp (section->name, _LIB) == 0)
176 /* An Irix 4 shared libary. */
177 section->flags |= SEC_COFF_SHARED_LIBRARY;
180 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
181 uncertain about .init on some systems and I don't know how shared
187 /* Determine the machine architecture and type. This is called from
188 the generic COFF routines. It is the inverse of ecoff_get_magic,
189 below. This could be an ECOFF backend routine, with one version
190 for each target, but there aren't all that many ECOFF targets. */
193 ecoff_set_arch_mach_hook (abfd, filehdr)
197 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
198 enum bfd_architecture arch;
201 switch (internal_f->f_magic)
204 case MIPS_MAGIC_LITTLE:
206 arch = bfd_arch_mips;
210 case MIPS_MAGIC_LITTLE2:
211 case MIPS_MAGIC_BIG2:
212 /* MIPS ISA level 2: the r6000 */
213 arch = bfd_arch_mips;
217 case MIPS_MAGIC_LITTLE3:
218 case MIPS_MAGIC_BIG3:
219 /* MIPS ISA level 3: the r4000 */
220 arch = bfd_arch_mips;
225 arch = bfd_arch_alpha;
230 arch = bfd_arch_obscure;
235 return bfd_default_set_arch_mach (abfd, arch, mach);
238 /* Get the magic number to use based on the architecture and machine.
239 This is the inverse of ecoff_set_arch_mach_hook, above. */
242 ecoff_get_magic (abfd)
247 switch (bfd_get_arch (abfd))
250 switch (bfd_get_mach (abfd))
255 big = MIPS_MAGIC_BIG;
256 little = MIPS_MAGIC_LITTLE;
260 big = MIPS_MAGIC_BIG2;
261 little = MIPS_MAGIC_LITTLE2;
265 big = MIPS_MAGIC_BIG3;
266 little = MIPS_MAGIC_LITTLE3;
270 return abfd->xvec->byteorder_big_p ? big : little;
281 /* Get the section s_flags to use for a section. */
284 ecoff_sec_to_styp_flags (name, flags)
292 if (strcmp (name, _TEXT) == 0)
294 else if (strcmp (name, _DATA) == 0)
296 else if (strcmp (name, _SDATA) == 0)
298 else if (strcmp (name, _RDATA) == 0)
300 else if (strcmp (name, _LITA) == 0)
302 else if (strcmp (name, _LIT8) == 0)
304 else if (strcmp (name, _LIT4) == 0)
306 else if (strcmp (name, _BSS) == 0)
308 else if (strcmp (name, _SBSS) == 0)
310 else if (strcmp (name, _INIT) == 0)
311 styp = STYP_ECOFF_INIT;
312 else if (strcmp (name, _FINI) == 0)
313 styp = STYP_ECOFF_FINI;
314 else if (strcmp (name, _PDATA) == 0)
316 else if (strcmp (name, _XDATA) == 0)
318 else if (strcmp (name, _LIB) == 0)
319 styp = STYP_ECOFF_LIB;
320 else if (flags & SEC_CODE)
322 else if (flags & SEC_DATA)
324 else if (flags & SEC_READONLY)
326 else if (flags & SEC_LOAD)
331 if (flags & SEC_NEVER_LOAD)
337 /* Get the BFD flags to use for a section. */
341 ecoff_styp_to_sec_flags (abfd, hdr)
345 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
346 long styp_flags = internal_s->s_flags;
347 flagword sec_flags=0;
349 if (styp_flags & STYP_NOLOAD)
350 sec_flags |= SEC_NEVER_LOAD;
352 /* For 386 COFF, at least, an unloadable text or data section is
353 actually a shared library section. */
354 if ((styp_flags & STYP_TEXT)
355 || (styp_flags & STYP_ECOFF_INIT)
356 || (styp_flags & STYP_ECOFF_FINI))
358 if (sec_flags & SEC_NEVER_LOAD)
359 sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
361 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
363 else if ((styp_flags & STYP_DATA)
364 || (styp_flags & STYP_RDATA)
365 || (styp_flags & STYP_SDATA)
366 || styp_flags == STYP_PDATA
367 || styp_flags == STYP_XDATA)
369 if (sec_flags & SEC_NEVER_LOAD)
370 sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
372 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
373 if ((styp_flags & STYP_RDATA)
374 || styp_flags == STYP_PDATA)
375 sec_flags |= SEC_READONLY;
377 else if ((styp_flags & STYP_BSS)
378 || (styp_flags & STYP_SBSS))
380 sec_flags |= SEC_ALLOC;
382 else if ((styp_flags & STYP_INFO) || styp_flags == STYP_COMMENT)
384 sec_flags |= SEC_NEVER_LOAD;
386 else if ((styp_flags & STYP_LITA)
387 || (styp_flags & STYP_LIT8)
388 || (styp_flags & STYP_LIT4))
390 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
392 else if (styp_flags & STYP_ECOFF_LIB)
394 sec_flags |= SEC_COFF_SHARED_LIBRARY;
398 sec_flags |= SEC_ALLOC | SEC_LOAD;
404 /* Routines to swap auxiliary information in and out. I am assuming
405 that the auxiliary information format is always going to be target
408 /* Swap in a type information record.
409 BIGEND says whether AUX symbols are big-endian or little-endian; this
410 info comes from the file header record (fh-fBigendian). */
413 ecoff_swap_tir_in (bigend, ext_copy, intern)
415 const struct tir_ext *ext_copy;
418 struct tir_ext ext[1];
420 *ext = *ext_copy; /* Make it reasonable to do in-place. */
422 /* now the fun stuff... */
424 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_BIG);
425 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_BIG);
426 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_BIG)
427 >> TIR_BITS1_BT_SH_BIG;
428 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_BIG)
429 >> TIR_BITS_TQ4_SH_BIG;
430 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_BIG)
431 >> TIR_BITS_TQ5_SH_BIG;
432 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_BIG)
433 >> TIR_BITS_TQ0_SH_BIG;
434 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_BIG)
435 >> TIR_BITS_TQ1_SH_BIG;
436 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_BIG)
437 >> TIR_BITS_TQ2_SH_BIG;
438 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_BIG)
439 >> TIR_BITS_TQ3_SH_BIG;
441 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_LITTLE);
442 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_LITTLE);
443 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_LITTLE)
444 >> TIR_BITS1_BT_SH_LITTLE;
445 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_LITTLE)
446 >> TIR_BITS_TQ4_SH_LITTLE;
447 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_LITTLE)
448 >> TIR_BITS_TQ5_SH_LITTLE;
449 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_LITTLE)
450 >> TIR_BITS_TQ0_SH_LITTLE;
451 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_LITTLE)
452 >> TIR_BITS_TQ1_SH_LITTLE;
453 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_LITTLE)
454 >> TIR_BITS_TQ2_SH_LITTLE;
455 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_LITTLE)
456 >> TIR_BITS_TQ3_SH_LITTLE;
460 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
465 /* Swap out a type information record.
466 BIGEND says whether AUX symbols are big-endian or little-endian; this
467 info comes from the file header record (fh-fBigendian). */
470 ecoff_swap_tir_out (bigend, intern_copy, ext)
472 const TIR *intern_copy;
477 *intern = *intern_copy; /* Make it reasonable to do in-place. */
479 /* now the fun stuff... */
481 ext->t_bits1[0] = ((intern->fBitfield ? TIR_BITS1_FBITFIELD_BIG : 0)
482 | (intern->continued ? TIR_BITS1_CONTINUED_BIG : 0)
483 | ((intern->bt << TIR_BITS1_BT_SH_BIG)
484 & TIR_BITS1_BT_BIG));
485 ext->t_tq45[0] = (((intern->tq4 << TIR_BITS_TQ4_SH_BIG)
487 | ((intern->tq5 << TIR_BITS_TQ5_SH_BIG)
488 & TIR_BITS_TQ5_BIG));
489 ext->t_tq01[0] = (((intern->tq0 << TIR_BITS_TQ0_SH_BIG)
491 | ((intern->tq1 << TIR_BITS_TQ1_SH_BIG)
492 & TIR_BITS_TQ1_BIG));
493 ext->t_tq23[0] = (((intern->tq2 << TIR_BITS_TQ2_SH_BIG)
495 | ((intern->tq3 << TIR_BITS_TQ3_SH_BIG)
496 & TIR_BITS_TQ3_BIG));
498 ext->t_bits1[0] = ((intern->fBitfield ? TIR_BITS1_FBITFIELD_LITTLE : 0)
499 | (intern->continued ? TIR_BITS1_CONTINUED_LITTLE : 0)
500 | ((intern->bt << TIR_BITS1_BT_SH_LITTLE)
501 & TIR_BITS1_BT_LITTLE));
502 ext->t_tq45[0] = (((intern->tq4 << TIR_BITS_TQ4_SH_LITTLE)
503 & TIR_BITS_TQ4_LITTLE)
504 | ((intern->tq5 << TIR_BITS_TQ5_SH_LITTLE)
505 & TIR_BITS_TQ5_LITTLE));
506 ext->t_tq01[0] = (((intern->tq0 << TIR_BITS_TQ0_SH_LITTLE)
507 & TIR_BITS_TQ0_LITTLE)
508 | ((intern->tq1 << TIR_BITS_TQ1_SH_LITTLE)
509 & TIR_BITS_TQ1_LITTLE));
510 ext->t_tq23[0] = (((intern->tq2 << TIR_BITS_TQ2_SH_LITTLE)
511 & TIR_BITS_TQ2_LITTLE)
512 | ((intern->tq3 << TIR_BITS_TQ3_SH_LITTLE)
513 & TIR_BITS_TQ3_LITTLE));
517 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
522 /* Swap in a relative symbol record. BIGEND says whether it is in
523 big-endian or little-endian format.*/
526 ecoff_swap_rndx_in (bigend, ext_copy, intern)
528 const struct rndx_ext *ext_copy;
531 struct rndx_ext ext[1];
533 *ext = *ext_copy; /* Make it reasonable to do in-place. */
535 /* now the fun stuff... */
537 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_BIG)
538 | ((ext->r_bits[1] & RNDX_BITS1_RFD_BIG)
539 >> RNDX_BITS1_RFD_SH_BIG);
540 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_BIG)
541 << RNDX_BITS1_INDEX_SH_LEFT_BIG)
542 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG)
543 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG);
545 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE)
546 | ((ext->r_bits[1] & RNDX_BITS1_RFD_LITTLE)
547 << RNDX_BITS1_RFD_SH_LEFT_LITTLE);
548 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_LITTLE)
549 >> RNDX_BITS1_INDEX_SH_LITTLE)
550 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE)
551 | ((unsigned int) ext->r_bits[3]
552 << RNDX_BITS3_INDEX_SH_LEFT_LITTLE);
556 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
561 /* Swap out a relative symbol record. BIGEND says whether it is in
562 big-endian or little-endian format.*/
565 ecoff_swap_rndx_out (bigend, intern_copy, ext)
567 const RNDXR *intern_copy;
568 struct rndx_ext *ext;
572 *intern = *intern_copy; /* Make it reasonable to do in-place. */
574 /* now the fun stuff... */
576 ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_BIG;
577 ext->r_bits[1] = (((intern->rfd << RNDX_BITS1_RFD_SH_BIG)
578 & RNDX_BITS1_RFD_BIG)
579 | ((intern->index >> RNDX_BITS1_INDEX_SH_LEFT_BIG)
580 & RNDX_BITS1_INDEX_BIG));
581 ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_BIG;
582 ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_BIG;
584 ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_LITTLE;
585 ext->r_bits[1] = (((intern->rfd >> RNDX_BITS1_RFD_SH_LEFT_LITTLE)
586 & RNDX_BITS1_RFD_LITTLE)
587 | ((intern->index << RNDX_BITS1_INDEX_SH_LITTLE)
588 & RNDX_BITS1_INDEX_LITTLE));
589 ext->r_bits[2] = intern->index >> RNDX_BITS2_INDEX_SH_LEFT_LITTLE;
590 ext->r_bits[3] = intern->index >> RNDX_BITS3_INDEX_SH_LEFT_LITTLE;
594 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
599 /* Read in the symbolic header for an ECOFF object file. */
602 ecoff_slurp_symbolic_header (abfd)
605 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
606 bfd_size_type external_hdr_size;
608 HDRR *internal_symhdr;
610 /* See if we've already read it in. */
611 if (ecoff_data (abfd)->debug_info.symbolic_header.magic ==
612 backend->debug_swap.sym_magic)
615 /* See whether there is a symbolic header. */
616 if (ecoff_data (abfd)->sym_filepos == 0)
618 bfd_get_symcount (abfd) = 0;
622 /* At this point bfd_get_symcount (abfd) holds the number of symbols
623 as read from the file header, but on ECOFF this is always the
624 size of the symbolic information header. It would be cleaner to
625 handle this when we first read the file in coffgen.c. */
626 external_hdr_size = backend->debug_swap.external_hdr_size;
627 if (bfd_get_symcount (abfd) != external_hdr_size)
629 bfd_set_error (bfd_error_bad_value);
633 /* Read the symbolic information header. */
634 raw = (PTR) malloc ((size_t) external_hdr_size);
637 bfd_set_error (bfd_error_no_memory);
641 if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1
642 || (bfd_read (raw, external_hdr_size, 1, abfd)
643 != external_hdr_size))
645 internal_symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
646 (*backend->debug_swap.swap_hdr_in) (abfd, raw, internal_symhdr);
648 if (internal_symhdr->magic != backend->debug_swap.sym_magic)
650 bfd_set_error (bfd_error_bad_value);
654 /* Now we can get the correct number of symbols. */
655 bfd_get_symcount (abfd) = (internal_symhdr->isymMax
656 + internal_symhdr->iextMax);
667 /* Read in and swap the important symbolic information for an ECOFF
668 object file. This is called by gdb via the read_debug_info entry
669 point in the backend structure. */
673 ecoff_slurp_symbolic_info (abfd, ignore, debug)
676 struct ecoff_debug_info *debug;
678 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
679 HDRR *internal_symhdr;
680 bfd_size_type raw_base;
681 bfd_size_type raw_size;
683 bfd_size_type external_fdr_size;
687 bfd_size_type raw_end;
688 bfd_size_type cb_end;
690 BFD_ASSERT (debug == &ecoff_data (abfd)->debug_info);
692 /* Check whether we've already gotten it, and whether there's any to
694 if (ecoff_data (abfd)->raw_syments != (PTR) NULL)
696 if (ecoff_data (abfd)->sym_filepos == 0)
698 bfd_get_symcount (abfd) = 0;
702 if (! ecoff_slurp_symbolic_header (abfd))
705 internal_symhdr = &debug->symbolic_header;
707 /* Read all the symbolic information at once. */
708 raw_base = (ecoff_data (abfd)->sym_filepos
709 + backend->debug_swap.external_hdr_size);
711 /* Alpha ecoff makes the determination of raw_size difficult. It has
712 an undocumented debug data section between the symhdr and the first
713 documented section. And the ordering of the sections varies between
714 statically and dynamically linked executables.
715 If bfd supports SEEK_END someday, this code could be simplified. */
719 #define UPDATE_RAW_END(start, count, size) \
720 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
721 if (cb_end > raw_end) \
724 UPDATE_RAW_END (cbLineOffset, cbLine, sizeof (unsigned char));
725 UPDATE_RAW_END (cbDnOffset, idnMax, backend->debug_swap.external_dnr_size);
726 UPDATE_RAW_END (cbPdOffset, ipdMax, backend->debug_swap.external_pdr_size);
727 UPDATE_RAW_END (cbSymOffset, isymMax, backend->debug_swap.external_sym_size);
728 UPDATE_RAW_END (cbOptOffset, ioptMax, backend->debug_swap.external_opt_size);
729 UPDATE_RAW_END (cbAuxOffset, iauxMax, sizeof (union aux_ext));
730 UPDATE_RAW_END (cbSsOffset, issMax, sizeof (char));
731 UPDATE_RAW_END (cbSsExtOffset, issExtMax, sizeof (char));
732 UPDATE_RAW_END (cbFdOffset, ifdMax, backend->debug_swap.external_fdr_size);
733 UPDATE_RAW_END (cbRfdOffset, crfd, backend->debug_swap.external_rfd_size);
734 UPDATE_RAW_END (cbExtOffset, iextMax, backend->debug_swap.external_ext_size);
736 #undef UPDATE_RAW_END
738 raw_size = raw_end - raw_base;
741 ecoff_data (abfd)->sym_filepos = 0;
744 raw = (PTR) bfd_alloc (abfd, raw_size);
747 bfd_set_error (bfd_error_no_memory);
751 (ecoff_data (abfd)->sym_filepos
752 + backend->debug_swap.external_hdr_size),
754 || bfd_read (raw, raw_size, 1, abfd) != raw_size)
756 bfd_release (abfd, raw);
760 ecoff_data (abfd)->raw_syments = raw;
762 /* Get pointers for the numeric offsets in the HDRR structure. */
763 #define FIX(off1, off2, type) \
764 if (internal_symhdr->off1 == 0) \
765 debug->off2 = (type) NULL; \
767 debug->off2 = (type) ((char *) raw \
768 + internal_symhdr->off1 \
770 FIX (cbLineOffset, line, unsigned char *);
771 FIX (cbDnOffset, external_dnr, PTR);
772 FIX (cbPdOffset, external_pdr, PTR);
773 FIX (cbSymOffset, external_sym, PTR);
774 FIX (cbOptOffset, external_opt, PTR);
775 FIX (cbAuxOffset, external_aux, union aux_ext *);
776 FIX (cbSsOffset, ss, char *);
777 FIX (cbSsExtOffset, ssext, char *);
778 FIX (cbFdOffset, external_fdr, PTR);
779 FIX (cbRfdOffset, external_rfd, PTR);
780 FIX (cbExtOffset, external_ext, PTR);
783 /* I don't want to always swap all the data, because it will just
784 waste time and most programs will never look at it. The only
785 time the linker needs most of the debugging information swapped
786 is when linking big-endian and little-endian MIPS object files
787 together, which is not a common occurrence.
789 We need to look at the fdr to deal with a lot of information in
790 the symbols, so we swap them here. */
791 debug->fdr = (struct fdr *) bfd_alloc (abfd,
792 (internal_symhdr->ifdMax *
793 sizeof (struct fdr)));
794 if (debug->fdr == NULL)
796 bfd_set_error (bfd_error_no_memory);
799 external_fdr_size = backend->debug_swap.external_fdr_size;
800 fdr_ptr = debug->fdr;
801 fraw_src = (char *) debug->external_fdr;
802 fraw_end = fraw_src + internal_symhdr->ifdMax * external_fdr_size;
803 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
804 (*backend->debug_swap.swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
809 /* ECOFF symbol table routines. The ECOFF symbol table is described
810 in gcc/mips-tfile.c. */
812 /* ECOFF uses two common sections. One is the usual one, and the
813 other is for small objects. All the small objects are kept
814 together, and then referenced via the gp pointer, which yields
815 faster assembler code. This is what we use for the small common
817 static asection ecoff_scom_section;
818 static asymbol ecoff_scom_symbol;
819 static asymbol *ecoff_scom_symbol_ptr;
821 /* Create an empty symbol. */
824 ecoff_make_empty_symbol (abfd)
827 ecoff_symbol_type *new;
829 new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type));
830 if (new == (ecoff_symbol_type *) NULL)
832 bfd_set_error (bfd_error_no_memory);
833 return (asymbol *) NULL;
835 memset ((PTR) new, 0, sizeof *new);
836 new->symbol.section = (asection *) NULL;
837 new->fdr = (FDR *) NULL;
840 new->symbol.the_bfd = abfd;
844 /* Set the BFD flags and section for an ECOFF symbol. */
847 ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
852 asymbol **indirect_ptr_ptr;
854 asym->the_bfd = abfd;
855 asym->value = ecoff_sym->value;
856 asym->section = &bfd_debug_section;
859 /* An indirect symbol requires two consecutive stabs symbols. */
860 if (*indirect_ptr_ptr != (asymbol *) NULL)
862 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym));
864 /* @@ Stuffing pointers into integers is a no-no.
865 We can usually get away with it if the integer is
866 large enough though. */
867 if (sizeof (asym) > sizeof (bfd_vma))
869 (*indirect_ptr_ptr)->value = (bfd_vma) asym;
871 asym->flags = BSF_DEBUGGING;
872 asym->section = &bfd_und_section;
873 *indirect_ptr_ptr = NULL;
877 if (ECOFF_IS_STAB (ecoff_sym)
878 && (ECOFF_UNMARK_STAB (ecoff_sym->index) | N_EXT) == (N_INDR | N_EXT))
880 asym->flags = BSF_DEBUGGING | BSF_INDIRECT;
881 asym->section = &bfd_ind_section;
882 /* Pass this symbol on to the next call to this function. */
883 *indirect_ptr_ptr = asym;
887 /* Most symbol types are just for debugging. */
888 switch (ecoff_sym->st)
897 if (ECOFF_IS_STAB (ecoff_sym))
899 asym->flags = BSF_DEBUGGING;
904 asym->flags = BSF_DEBUGGING;
909 asym->flags = BSF_EXPORT | BSF_GLOBAL;
911 asym->flags = BSF_LOCAL;
912 switch (ecoff_sym->sc)
915 /* Used for compiler generated labels. Leave them in the
916 debugging section, and mark them as local. If BSF_DEBUGGING
917 is set, then nm does not display them for some reason. If no
918 flags are set then the linker whines about them. */
919 asym->flags = BSF_LOCAL;
922 asym->section = bfd_make_section_old_way (abfd, ".text");
923 asym->value -= asym->section->vma;
926 asym->section = bfd_make_section_old_way (abfd, ".data");
927 asym->value -= asym->section->vma;
930 asym->section = bfd_make_section_old_way (abfd, ".bss");
931 asym->value -= asym->section->vma;
934 asym->flags = BSF_DEBUGGING;
937 asym->section = &bfd_abs_section;
940 asym->section = &bfd_und_section;
950 asym->flags = BSF_DEBUGGING;
953 asym->section = bfd_make_section_old_way (abfd, ".sdata");
954 asym->value -= asym->section->vma;
957 asym->section = bfd_make_section_old_way (abfd, ".sbss");
958 asym->value -= asym->section->vma;
961 asym->section = bfd_make_section_old_way (abfd, ".rdata");
962 asym->value -= asym->section->vma;
965 asym->flags = BSF_DEBUGGING;
968 if (asym->value > ecoff_data (abfd)->gp_size)
970 asym->section = &bfd_com_section;
976 if (ecoff_scom_section.name == NULL)
978 /* Initialize the small common section. */
979 ecoff_scom_section.name = SCOMMON;
980 ecoff_scom_section.flags = SEC_IS_COMMON;
981 ecoff_scom_section.output_section = &ecoff_scom_section;
982 ecoff_scom_section.symbol = &ecoff_scom_symbol;
983 ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
984 ecoff_scom_symbol.name = SCOMMON;
985 ecoff_scom_symbol.flags = BSF_SECTION_SYM;
986 ecoff_scom_symbol.section = &ecoff_scom_section;
987 ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
989 asym->section = &ecoff_scom_section;
994 asym->flags = BSF_DEBUGGING;
997 asym->section = &bfd_und_section;
1002 asym->section = bfd_make_section_old_way (abfd, ".init");
1003 asym->value -= asym->section->vma;
1008 asym->flags = BSF_DEBUGGING;
1011 asym->section = bfd_make_section_old_way (abfd, ".fini");
1012 asym->value -= asym->section->vma;
1018 /* Look for special constructors symbols and make relocation entries
1019 in a special construction section. These are produced by the
1020 -fgnu-linker argument to g++. */
1021 if (ECOFF_IS_STAB (ecoff_sym))
1023 switch (ECOFF_UNMARK_STAB (ecoff_sym->index))
1035 arelent_chain *reloc_chain;
1036 unsigned int bitsize;
1038 /* Get a section with the same name as the symbol (usually
1039 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1040 name ___CTOR_LIST (three underscores). We need
1041 __CTOR_LIST (two underscores), since ECOFF doesn't use
1042 a leading underscore. This should be handled by gcc,
1043 but instead we do it here. Actually, this should all
1044 be done differently anyhow. */
1045 name = bfd_asymbol_name (asym);
1046 if (name[0] == '_' && name[1] == '_' && name[2] == '_')
1051 section = bfd_get_section_by_name (abfd, name);
1052 if (section == (asection *) NULL)
1056 copy = (char *) bfd_alloc (abfd, strlen (name) + 1);
1059 bfd_set_error (bfd_error_no_memory);
1062 strcpy (copy, name);
1063 section = bfd_make_section (abfd, copy);
1066 /* Build a reloc pointing to this constructor. */
1068 (arelent_chain *) bfd_alloc (abfd, sizeof (arelent_chain));
1071 bfd_set_error (bfd_error_no_memory);
1074 reloc_chain->relent.sym_ptr_ptr =
1075 bfd_get_section (asym)->symbol_ptr_ptr;
1076 reloc_chain->relent.address = section->_raw_size;
1077 reloc_chain->relent.addend = asym->value;
1078 reloc_chain->relent.howto =
1079 ecoff_backend (abfd)->constructor_reloc;
1081 /* Set up the constructor section to hold the reloc. */
1082 section->flags = SEC_CONSTRUCTOR;
1083 ++section->reloc_count;
1085 /* Constructor sections must be rounded to a boundary
1086 based on the bitsize. These are not real sections--
1087 they are handled specially by the linker--so the ECOFF
1088 16 byte alignment restriction does not apply. */
1089 bitsize = ecoff_backend (abfd)->constructor_bitsize;
1090 section->alignment_power = 1;
1091 while ((1 << section->alignment_power) < bitsize / 8)
1092 ++section->alignment_power;
1094 reloc_chain->next = section->constructor_chain;
1095 section->constructor_chain = reloc_chain;
1096 section->_raw_size += bitsize / 8;
1098 /* Mark the symbol as a constructor. */
1099 asym->flags |= BSF_CONSTRUCTOR;
1107 /* Read an ECOFF symbol table. */
1110 ecoff_slurp_symbol_table (abfd)
1113 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
1114 const bfd_size_type external_ext_size
1115 = backend->debug_swap.external_ext_size;
1116 const bfd_size_type external_sym_size
1117 = backend->debug_swap.external_sym_size;
1118 void (* const swap_ext_in) PARAMS ((bfd *, PTR, EXTR *))
1119 = backend->debug_swap.swap_ext_in;
1120 void (* const swap_sym_in) PARAMS ((bfd *, PTR, SYMR *))
1121 = backend->debug_swap.swap_sym_in;
1122 bfd_size_type internal_size;
1123 ecoff_symbol_type *internal;
1124 ecoff_symbol_type *internal_ptr;
1125 asymbol *indirect_ptr;
1131 /* If we've already read in the symbol table, do nothing. */
1132 if (ecoff_data (abfd)->canonical_symbols != NULL)
1135 /* Get the symbolic information. */
1136 if (! ecoff_slurp_symbolic_info (abfd, (asection *) NULL,
1137 &ecoff_data (abfd)->debug_info))
1139 if (bfd_get_symcount (abfd) == 0)
1142 internal_size = bfd_get_symcount (abfd) * sizeof (ecoff_symbol_type);
1143 internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size);
1144 if (internal == NULL)
1146 bfd_set_error (bfd_error_no_memory);
1150 internal_ptr = internal;
1151 indirect_ptr = NULL;
1152 eraw_src = (char *) ecoff_data (abfd)->debug_info.external_ext;
1153 eraw_end = (eraw_src
1154 + (ecoff_data (abfd)->debug_info.symbolic_header.iextMax
1155 * external_ext_size));
1156 for (; eraw_src < eraw_end; eraw_src += external_ext_size, internal_ptr++)
1160 (*swap_ext_in) (abfd, (PTR) eraw_src, &internal_esym);
1161 internal_ptr->symbol.name = (ecoff_data (abfd)->debug_info.ssext
1162 + internal_esym.asym.iss);
1163 if (!ecoff_set_symbol_info (abfd, &internal_esym.asym,
1164 &internal_ptr->symbol, 1, &indirect_ptr))
1166 /* The alpha uses a negative ifd field for section symbols. */
1167 if (internal_esym.ifd >= 0)
1168 internal_ptr->fdr = (ecoff_data (abfd)->debug_info.fdr
1169 + internal_esym.ifd);
1171 internal_ptr->fdr = NULL;
1172 internal_ptr->local = false;
1173 internal_ptr->native = (PTR) eraw_src;
1175 BFD_ASSERT (indirect_ptr == (asymbol *) NULL);
1177 /* The local symbols must be accessed via the fdr's, because the
1178 string and aux indices are relative to the fdr information. */
1179 fdr_ptr = ecoff_data (abfd)->debug_info.fdr;
1180 fdr_end = fdr_ptr + ecoff_data (abfd)->debug_info.symbolic_header.ifdMax;
1181 for (; fdr_ptr < fdr_end; fdr_ptr++)
1186 lraw_src = ((char *) ecoff_data (abfd)->debug_info.external_sym
1187 + fdr_ptr->isymBase * external_sym_size);
1188 lraw_end = lraw_src + fdr_ptr->csym * external_sym_size;
1190 lraw_src < lraw_end;
1191 lraw_src += external_sym_size, internal_ptr++)
1195 (*swap_sym_in) (abfd, (PTR) lraw_src, &internal_sym);
1196 internal_ptr->symbol.name = (ecoff_data (abfd)->debug_info.ss
1198 + internal_sym.iss);
1199 if (!ecoff_set_symbol_info (abfd, &internal_sym,
1200 &internal_ptr->symbol, 0, &indirect_ptr))
1202 internal_ptr->fdr = fdr_ptr;
1203 internal_ptr->local = true;
1204 internal_ptr->native = (PTR) lraw_src;
1207 BFD_ASSERT (indirect_ptr == (asymbol *) NULL);
1209 ecoff_data (abfd)->canonical_symbols = internal;
1214 /* Return the amount of space needed for the canonical symbols. */
1217 ecoff_get_symtab_upper_bound (abfd)
1220 if (! ecoff_slurp_symbolic_info (abfd, (asection *) NULL,
1221 &ecoff_data (abfd)->debug_info))
1224 if (bfd_get_symcount (abfd) == 0)
1227 return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *));
1230 /* Get the canonical symbols. */
1233 ecoff_get_symtab (abfd, alocation)
1235 asymbol **alocation;
1237 unsigned int counter = 0;
1238 ecoff_symbol_type *symbase;
1239 ecoff_symbol_type **location = (ecoff_symbol_type **) alocation;
1241 if (ecoff_slurp_symbol_table (abfd) == false)
1243 if (bfd_get_symcount (abfd) == 0)
1246 symbase = ecoff_data (abfd)->canonical_symbols;
1247 while (counter < bfd_get_symcount (abfd))
1249 *(location++) = symbase++;
1252 *location++ = (ecoff_symbol_type *) NULL;
1253 return bfd_get_symcount (abfd);
1256 /* Turn ECOFF type information into a printable string.
1257 ecoff_emit_aggregate and ecoff_type_to_string are from
1258 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1260 /* Write aggregate information to a string. */
1263 ecoff_emit_aggregate (abfd, fdr, string, rndx, isym, which)
1271 const struct ecoff_debug_swap * const debug_swap =
1272 &ecoff_backend (abfd)->debug_swap;
1273 struct ecoff_debug_info * const debug_info = &ecoff_data (abfd)->debug_info;
1274 unsigned int ifd = rndx->rfd;
1275 unsigned int indx = rndx->index;
1281 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1282 struct return type of a procedure compiled without -g. */
1283 if (ifd == 0xffffffff
1284 || (rndx->rfd == 0xfff && indx == 0))
1285 name = "<undefined>";
1286 else if (indx == indexNil)
1292 if (debug_info->external_rfd == NULL)
1293 fdr = debug_info->fdr + ifd;
1298 (*debug_swap->swap_rfd_in) (abfd,
1299 ((char *) debug_info->external_rfd
1300 + ((fdr->rfdBase + ifd)
1301 * debug_swap->external_rfd_size)),
1303 fdr = debug_info->fdr + rfd;
1306 indx += fdr->isymBase;
1308 (*debug_swap->swap_sym_in) (abfd,
1309 ((char *) debug_info->external_sym
1310 + indx * debug_swap->external_sym_size),
1313 name = debug_info->ss + fdr->issBase + sym.iss;
1317 "%s %s { ifd = %u, index = %lu }",
1320 + debug_info->symbolic_header.iextMax));
1323 /* Convert the type information to string format. */
1326 ecoff_type_to_string (abfd, fdr, indx)
1331 union aux_ext *aux_ptr;
1340 unsigned int basic_type;
1342 static char buffer1[1024];
1343 static char buffer2[1024];
1348 aux_ptr = ecoff_data (abfd)->debug_info.external_aux + fdr->iauxBase;
1349 bigendian = fdr->fBigendian;
1351 for (i = 0; i < 7; i++)
1353 qualifiers[i].low_bound = 0;
1354 qualifiers[i].high_bound = 0;
1355 qualifiers[i].stride = 0;
1358 if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1)
1359 return "-1 (no type)";
1360 ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti);
1362 basic_type = u.ti.bt;
1363 qualifiers[0].type = u.ti.tq0;
1364 qualifiers[1].type = u.ti.tq1;
1365 qualifiers[2].type = u.ti.tq2;
1366 qualifiers[3].type = u.ti.tq3;
1367 qualifiers[4].type = u.ti.tq4;
1368 qualifiers[5].type = u.ti.tq5;
1369 qualifiers[6].type = tqNil;
1372 * Go get the basic type.
1376 case btNil: /* undefined */
1380 case btAdr: /* address - integer same size as pointer */
1381 strcpy (p1, "address");
1384 case btChar: /* character */
1385 strcpy (p1, "char");
1388 case btUChar: /* unsigned character */
1389 strcpy (p1, "unsigned char");
1392 case btShort: /* short */
1393 strcpy (p1, "short");
1396 case btUShort: /* unsigned short */
1397 strcpy (p1, "unsigned short");
1400 case btInt: /* int */
1404 case btUInt: /* unsigned int */
1405 strcpy (p1, "unsigned int");
1408 case btLong: /* long */
1409 strcpy (p1, "long");
1412 case btULong: /* unsigned long */
1413 strcpy (p1, "unsigned long");
1416 case btFloat: /* float (real) */
1417 strcpy (p1, "float");
1420 case btDouble: /* Double (real) */
1421 strcpy (p1, "double");
1424 /* Structures add 1-2 aux words:
1425 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1426 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1428 case btStruct: /* Structure (Record) */
1429 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1430 ecoff_emit_aggregate (abfd, fdr, p1, &rndx,
1431 (long) AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1433 indx++; /* skip aux words */
1436 /* Unions add 1-2 aux words:
1437 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1438 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1440 case btUnion: /* Union */
1441 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1442 ecoff_emit_aggregate (abfd, fdr, p1, &rndx,
1443 (long) AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1445 indx++; /* skip aux words */
1448 /* Enumerations add 1-2 aux words:
1449 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1450 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1452 case btEnum: /* Enumeration */
1453 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1454 ecoff_emit_aggregate (abfd, fdr, p1, &rndx,
1455 (long) AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1457 indx++; /* skip aux words */
1460 case btTypedef: /* defined via a typedef, isymRef points */
1461 strcpy (p1, "typedef");
1464 case btRange: /* subrange of int */
1465 strcpy (p1, "subrange");
1468 case btSet: /* pascal sets */
1472 case btComplex: /* fortran complex */
1473 strcpy (p1, "complex");
1476 case btDComplex: /* fortran double complex */
1477 strcpy (p1, "double complex");
1480 case btIndirect: /* forward or unnamed typedef */
1481 strcpy (p1, "forward/unamed typedef");
1484 case btFixedDec: /* Fixed Decimal */
1485 strcpy (p1, "fixed decimal");
1488 case btFloatDec: /* Float Decimal */
1489 strcpy (p1, "float decimal");
1492 case btString: /* Varying Length Character String */
1493 strcpy (p1, "string");
1496 case btBit: /* Aligned Bit String */
1500 case btPicture: /* Picture */
1501 strcpy (p1, "picture");
1504 case btVoid: /* Void */
1505 strcpy (p1, "void");
1509 sprintf (p1, "Unknown basic type %d", (int) basic_type);
1513 p1 += strlen (buffer1);
1516 * If this is a bitfield, get the bitsize.
1522 bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]);
1523 sprintf (p1, " : %d", bitsize);
1524 p1 += strlen (buffer1);
1529 * Deal with any qualifiers.
1531 if (qualifiers[0].type != tqNil)
1534 * Snarf up any array bounds in the correct order. Arrays
1535 * store 5 successive words in the aux. table:
1536 * word 0 RNDXR to type of the bounds (ie, int)
1537 * word 1 Current file descriptor index
1539 * word 3 high bound (or -1 if [])
1540 * word 4 stride size in bits
1542 for (i = 0; i < 7; i++)
1544 if (qualifiers[i].type == tqArray)
1546 qualifiers[i].low_bound =
1547 AUX_GET_DNLOW (bigendian, &aux_ptr[indx+2]);
1548 qualifiers[i].high_bound =
1549 AUX_GET_DNHIGH (bigendian, &aux_ptr[indx+3]);
1550 qualifiers[i].stride =
1551 AUX_GET_WIDTH (bigendian, &aux_ptr[indx+4]);
1557 * Now print out the qualifiers.
1559 for (i = 0; i < 6; i++)
1561 switch (qualifiers[i].type)
1568 strcpy (p2, "ptr to ");
1569 p2 += sizeof ("ptr to ")-1;
1573 strcpy (p2, "volatile ");
1574 p2 += sizeof ("volatile ")-1;
1578 strcpy (p2, "far ");
1579 p2 += sizeof ("far ")-1;
1583 strcpy (p2, "func. ret. ");
1584 p2 += sizeof ("func. ret. ");
1589 int first_array = i;
1592 /* Print array bounds reversed (ie, in the order the C
1593 programmer writes them). C is such a fun language.... */
1595 while (i < 5 && qualifiers[i+1].type == tqArray)
1598 for (j = i; j >= first_array; j--)
1600 strcpy (p2, "array [");
1601 p2 += sizeof ("array [")-1;
1602 if (qualifiers[j].low_bound != 0)
1604 "%ld:%ld {%ld bits}",
1605 (long) qualifiers[j].low_bound,
1606 (long) qualifiers[j].high_bound,
1607 (long) qualifiers[j].stride);
1609 else if (qualifiers[j].high_bound != -1)
1612 (long) (qualifiers[j].high_bound + 1),
1613 (long) (qualifiers[j].stride));
1616 sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride));
1619 strcpy (p2, "] of ");
1620 p2 += sizeof ("] of ")-1;
1628 strcpy (p2, buffer1);
1632 /* Return information about ECOFF symbol SYMBOL in RET. */
1636 ecoff_get_symbol_info (abfd, symbol, ret)
1637 bfd *abfd; /* Ignored. */
1641 bfd_symbol_info (symbol, ret);
1644 /* Print information about an ECOFF symbol. */
1647 ecoff_print_symbol (abfd, filep, symbol, how)
1651 bfd_print_symbol_type how;
1653 const struct ecoff_debug_swap * const debug_swap
1654 = &ecoff_backend (abfd)->debug_swap;
1655 FILE *file = (FILE *)filep;
1659 case bfd_print_symbol_name:
1660 fprintf (file, "%s", symbol->name);
1662 case bfd_print_symbol_more:
1663 if (ecoffsymbol (symbol)->local)
1667 (*debug_swap->swap_sym_in) (abfd, ecoffsymbol (symbol)->native,
1669 fprintf (file, "ecoff local ");
1670 fprintf_vma (file, (bfd_vma) ecoff_sym.value);
1671 fprintf (file, " %x %x", (unsigned) ecoff_sym.st,
1672 (unsigned) ecoff_sym.sc);
1678 (*debug_swap->swap_ext_in) (abfd, ecoffsymbol (symbol)->native,
1680 fprintf (file, "ecoff extern ");
1681 fprintf_vma (file, (bfd_vma) ecoff_ext.asym.value);
1682 fprintf (file, " %x %x", (unsigned) ecoff_ext.asym.st,
1683 (unsigned) ecoff_ext.asym.sc);
1686 case bfd_print_symbol_all:
1687 /* Print out the symbols in a reasonable way */
1696 if (ecoffsymbol (symbol)->local)
1698 (*debug_swap->swap_sym_in) (abfd, ecoffsymbol (symbol)->native,
1701 pos = ((((char *) ecoffsymbol (symbol)->native
1702 - (char *) ecoff_data (abfd)->debug_info.external_sym)
1703 / debug_swap->external_sym_size)
1704 + ecoff_data (abfd)->debug_info.symbolic_header.iextMax);
1711 (*debug_swap->swap_ext_in) (abfd, ecoffsymbol (symbol)->native,
1714 pos = (((char *) ecoffsymbol (symbol)->native
1715 - (char *) ecoff_data (abfd)->debug_info.external_ext)
1716 / debug_swap->external_ext_size);
1717 jmptbl = ecoff_ext.jmptbl ? 'j' : ' ';
1718 cobol_main = ecoff_ext.cobol_main ? 'c' : ' ';
1719 weakext = ecoff_ext.weakext ? 'w' : ' ';
1722 fprintf (file, "[%3d] %c ",
1724 fprintf_vma (file, (bfd_vma) ecoff_ext.asym.value);
1725 fprintf (file, " st %x sc %x indx %x %c%c%c %s",
1726 (unsigned) ecoff_ext.asym.st,
1727 (unsigned) ecoff_ext.asym.sc,
1728 (unsigned) ecoff_ext.asym.index,
1729 jmptbl, cobol_main, weakext,
1732 if (ecoffsymbol (symbol)->fdr != NULL
1733 && ecoff_ext.asym.index != indexNil)
1738 bfd_size_type sym_base;
1739 union aux_ext *aux_base;
1741 fdr = ecoffsymbol (symbol)->fdr;
1742 indx = ecoff_ext.asym.index;
1744 /* sym_base is used to map the fdr relative indices which
1745 appear in the file to the position number which we are
1747 sym_base = fdr->isymBase;
1748 if (ecoffsymbol (symbol)->local)
1750 ecoff_data (abfd)->debug_info.symbolic_header.iextMax;
1752 /* aux_base is the start of the aux entries for this file;
1753 asym.index is an offset from this. */
1754 aux_base = (ecoff_data (abfd)->debug_info.external_aux
1757 /* The aux entries are stored in host byte order; the
1758 order is indicated by a bit in the fdr. */
1759 bigendian = fdr->fBigendian;
1761 /* This switch is basically from gcc/mips-tdump.c */
1762 switch (ecoff_ext.asym.st)
1770 fprintf (file, "\n End+1 symbol: %ld",
1771 (long) (indx + sym_base));
1775 if (ecoff_ext.asym.sc == scText
1776 || ecoff_ext.asym.sc == scInfo)
1777 fprintf (file, "\n First symbol: %ld",
1778 (long) (indx + sym_base));
1780 fprintf (file, "\n First symbol: %ld",
1782 (AUX_GET_ISYM (bigendian,
1783 &aux_base[ecoff_ext.asym.index])
1789 if (ECOFF_IS_STAB (&ecoff_ext.asym))
1791 else if (ecoffsymbol (symbol)->local)
1792 fprintf (file, "\n End+1 symbol: %-7ld Type: %s",
1794 (AUX_GET_ISYM (bigendian,
1795 &aux_base[ecoff_ext.asym.index])
1797 ecoff_type_to_string (abfd, fdr, indx + 1));
1799 fprintf (file, "\n Local symbol: %ld",
1802 + (ecoff_data (abfd)
1803 ->debug_info.symbolic_header.iextMax)));
1807 fprintf (file, "\n struct; End+1 symbol: %ld",
1808 (long) (indx + sym_base));
1812 fprintf (file, "\n union; End+1 symbol: %ld",
1813 (long) (indx + sym_base));
1817 fprintf (file, "\n enum; End+1 symbol: %ld",
1818 (long) (indx + sym_base));
1822 if (! ECOFF_IS_STAB (&ecoff_ext.asym))
1823 fprintf (file, "\n Type: %s",
1824 ecoff_type_to_string (abfd, fdr, indx));
1833 /* Read in the relocs for a section. */
1836 ecoff_slurp_reloc_table (abfd, section, symbols)
1841 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
1842 arelent *internal_relocs;
1843 bfd_size_type external_reloc_size;
1844 bfd_size_type external_relocs_size;
1845 char *external_relocs;
1849 if (section->relocation != (arelent *) NULL
1850 || section->reloc_count == 0
1851 || (section->flags & SEC_CONSTRUCTOR) != 0)
1854 if (ecoff_slurp_symbol_table (abfd) == false)
1857 internal_relocs = (arelent *) bfd_alloc (abfd,
1859 * section->reloc_count));
1860 external_reloc_size = backend->external_reloc_size;
1861 external_relocs_size = external_reloc_size * section->reloc_count;
1862 external_relocs = (char *) bfd_alloc (abfd, external_relocs_size);
1863 if (internal_relocs == (arelent *) NULL
1864 || external_relocs == (char *) NULL)
1866 bfd_set_error (bfd_error_no_memory);
1869 if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
1871 if (bfd_read (external_relocs, 1, external_relocs_size, abfd)
1872 != external_relocs_size)
1875 for (i = 0, rptr = internal_relocs; i < section->reloc_count; i++, rptr++)
1877 struct internal_reloc intern;
1879 (*backend->swap_reloc_in) (abfd,
1880 external_relocs + i * external_reloc_size,
1883 if (intern.r_extern)
1885 /* r_symndx is an index into the external symbols. */
1886 BFD_ASSERT (intern.r_symndx >= 0
1888 < (ecoff_data (abfd)
1889 ->debug_info.symbolic_header.iextMax)));
1890 rptr->sym_ptr_ptr = symbols + intern.r_symndx;
1893 else if (intern.r_symndx == RELOC_SECTION_NONE
1894 || intern.r_symndx == RELOC_SECTION_ABS)
1896 rptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
1901 CONST char *sec_name;
1904 /* r_symndx is a section key. */
1905 switch (intern.r_symndx)
1907 case RELOC_SECTION_TEXT: sec_name = ".text"; break;
1908 case RELOC_SECTION_RDATA: sec_name = ".rdata"; break;
1909 case RELOC_SECTION_DATA: sec_name = ".data"; break;
1910 case RELOC_SECTION_SDATA: sec_name = ".sdata"; break;
1911 case RELOC_SECTION_SBSS: sec_name = ".sbss"; break;
1912 case RELOC_SECTION_BSS: sec_name = ".bss"; break;
1913 case RELOC_SECTION_INIT: sec_name = ".init"; break;
1914 case RELOC_SECTION_LIT8: sec_name = ".lit8"; break;
1915 case RELOC_SECTION_LIT4: sec_name = ".lit4"; break;
1916 case RELOC_SECTION_XDATA: sec_name = ".xdata"; break;
1917 case RELOC_SECTION_PDATA: sec_name = ".pdata"; break;
1918 case RELOC_SECTION_FINI: sec_name = ".fini"; break;
1919 case RELOC_SECTION_LITA: sec_name = ".lita"; break;
1923 sec = bfd_get_section_by_name (abfd, sec_name);
1924 if (sec == (asection *) NULL)
1926 rptr->sym_ptr_ptr = sec->symbol_ptr_ptr;
1928 rptr->addend = - bfd_get_section_vma (abfd, sec);
1931 rptr->address = intern.r_vaddr - bfd_get_section_vma (abfd, section);
1933 /* Let the backend select the howto field and do any other
1934 required processing. */
1935 (*backend->adjust_reloc_in) (abfd, &intern, rptr);
1938 bfd_release (abfd, external_relocs);
1940 section->relocation = internal_relocs;
1945 /* Get a canonical list of relocs. */
1948 ecoff_canonicalize_reloc (abfd, section, relptr, symbols)
1956 if (section->flags & SEC_CONSTRUCTOR)
1958 arelent_chain *chain;
1960 /* This section has relocs made up by us, not the file, so take
1961 them out of their chain and place them into the data area
1963 for (count = 0, chain = section->constructor_chain;
1964 count < section->reloc_count;
1965 count++, chain = chain->next)
1966 *relptr++ = &chain->relent;
1972 if (ecoff_slurp_reloc_table (abfd, section, symbols) == false)
1975 tblptr = section->relocation;
1977 for (count = 0; count < section->reloc_count; count++)
1978 *relptr++ = tblptr++;
1981 *relptr = (arelent *) NULL;
1983 return section->reloc_count;
1986 /* Provided a BFD, a section and an offset into the section, calculate
1987 and return the name of the source file and the line nearest to the
1992 ecoff_find_nearest_line (abfd,
2001 asymbol **ignore_symbols;
2003 CONST char **filename_ptr;
2004 CONST char **functionname_ptr;
2005 unsigned int *retline_ptr;
2007 const struct ecoff_debug_swap * const debug_swap
2008 = &ecoff_backend (abfd)->debug_swap;
2013 bfd_size_type external_pdr_size;
2018 unsigned char *line_ptr;
2019 unsigned char *line_end;
2022 /* If we're not in the .text section, we don't have any line
2024 if (strcmp (section->name, _TEXT) != 0
2025 || offset < ecoff_data (abfd)->text_start
2026 || offset >= ecoff_data (abfd)->text_end)
2029 /* Make sure we have the FDR's. */
2030 if (! ecoff_slurp_symbolic_info (abfd, (asection *) NULL,
2031 &ecoff_data (abfd)->debug_info)
2032 || bfd_get_symcount (abfd) == 0)
2035 /* Each file descriptor (FDR) has a memory address. Here we track
2036 down which FDR we want. The FDR's are stored in increasing
2037 memory order. If speed is ever important, this can become a
2038 binary search. We must ignore FDR's with no PDR entries; they
2039 will have the adr of the FDR before or after them. */
2040 fdr_start = ecoff_data (abfd)->debug_info.fdr;
2041 fdr_end = fdr_start + ecoff_data (abfd)->debug_info.symbolic_header.ifdMax;
2042 fdr_hold = (FDR *) NULL;
2043 for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
2045 if (fdr_ptr->cpd == 0)
2047 if (offset < fdr_ptr->adr)
2051 if (fdr_hold == (FDR *) NULL)
2055 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2056 have an address, which is relative to the FDR address, and are
2057 also stored in increasing memory order. */
2058 offset -= fdr_ptr->adr;
2059 external_pdr_size = debug_swap->external_pdr_size;
2060 pdr_ptr = ((char *) ecoff_data (abfd)->debug_info.external_pdr
2061 + fdr_ptr->ipdFirst * external_pdr_size);
2062 pdr_end = pdr_ptr + fdr_ptr->cpd * external_pdr_size;
2063 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
2064 if (offset < pdr.adr)
2067 /* The address of the first PDR is an offset which applies to the
2068 addresses of all the PDR's. */
2069 first_off = pdr.adr;
2071 for (pdr_ptr += external_pdr_size;
2073 pdr_ptr += external_pdr_size)
2075 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
2076 if (offset < pdr.adr)
2080 /* Now we can look for the actual line number. The line numbers are
2081 stored in a very funky format, which I won't try to describe.
2082 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2083 we want; we need this to compute line_end. */
2084 line_end = ecoff_data (abfd)->debug_info.line;
2085 if (pdr_ptr == pdr_end)
2086 line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
2088 line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset;
2090 /* Now change pdr and pdr_ptr to the one we want. */
2091 pdr_ptr -= external_pdr_size;
2092 (*debug_swap->swap_pdr_in) (abfd, (PTR) pdr_ptr, &pdr);
2094 offset -= pdr.adr - first_off;
2096 line_ptr = (ecoff_data (abfd)->debug_info.line
2097 + fdr_ptr->cbLineOffset
2098 + pdr.cbLineOffset);
2099 while (line_ptr < line_end)
2104 delta = *line_ptr >> 4;
2107 count = (*line_ptr & 0xf) + 1;
2111 delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff);
2112 if (delta >= 0x8000)
2117 if (offset < count * 4)
2119 offset -= count * 4;
2122 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2123 at least according to gdb/mipsread.c. */
2124 if (fdr_ptr->rss == -1)
2126 *filename_ptr = NULL;
2128 *functionname_ptr = NULL;
2133 (*debug_swap->swap_ext_in)
2135 ((char *) ecoff_data (abfd)->debug_info.external_ext
2136 + pdr.isym * debug_swap->external_ext_size),
2138 *functionname_ptr = (ecoff_data (abfd)->debug_info.ssext
2139 + proc_ext.asym.iss);
2146 *filename_ptr = (ecoff_data (abfd)->debug_info.ss
2149 (*debug_swap->swap_sym_in)
2151 ((char *) ecoff_data (abfd)->debug_info.external_sym
2152 + (fdr_ptr->isymBase + pdr.isym) * debug_swap->external_sym_size),
2154 *functionname_ptr = (ecoff_data (abfd)->debug_info.ss
2158 if (lineno == ilineNil)
2160 *retline_ptr = lineno;
2164 /* Copy private BFD data. This is called by objcopy and strip. We
2165 use it to copy the ECOFF debugging information from one BFD to the
2166 other. It would be theoretically possible to represent the ECOFF
2167 debugging information in the symbol table. However, it would be a
2168 lot of work, and there would be little gain (gas, gdb, and ld
2169 already access the ECOFF debugging information via the
2170 ecoff_debug_info structure, and that structure would have to be
2171 retained in order to support ECOFF debugging in MIPS ELF).
2173 The debugging information for the ECOFF external symbols comes from
2174 the symbol table, so this function only handles the other debugging
2178 ecoff_bfd_copy_private_bfd_data (ibfd, obfd)
2182 struct ecoff_debug_info *iinfo = &ecoff_data (ibfd)->debug_info;
2183 struct ecoff_debug_info *oinfo = &ecoff_data (obfd)->debug_info;
2185 asymbol **sym_ptr_ptr;
2189 /* This function is selected based on the input vector. We only
2190 want to copy information over if the output BFD also uses ECOFF
2192 if (bfd_get_flavour (obfd) != bfd_target_ecoff_flavour)
2195 /* Copy the GP value and the register masks. */
2196 ecoff_data (obfd)->gp = ecoff_data (ibfd)->gp;
2197 ecoff_data (obfd)->gprmask = ecoff_data (ibfd)->gprmask;
2198 ecoff_data (obfd)->fprmask = ecoff_data (ibfd)->fprmask;
2199 for (i = 0; i < 3; i++)
2200 ecoff_data (obfd)->cprmask[i] = ecoff_data (ibfd)->cprmask[i];
2202 /* Copy the version stamp. */
2203 oinfo->symbolic_header.vstamp = iinfo->symbolic_header.vstamp;
2205 /* If there are no symbols, don't copy any debugging information. */
2206 c = bfd_get_symcount (obfd);
2207 sym_ptr_ptr = bfd_get_outsymbols (obfd);
2208 if (c == 0 || sym_ptr_ptr == (asymbol **) NULL)
2211 /* See if there are any local symbols. */
2213 for (; c > 0; c--, sym_ptr_ptr++)
2215 if (ecoffsymbol (*sym_ptr_ptr)->local)
2224 /* There are some local symbols. We just bring over all the
2225 debugging information. FIXME: This is not quite the right
2226 thing to do. If the user has asked us to discard all
2227 debugging information, then we are probably going to wind up
2228 keeping it because there will probably be some local symbol
2229 which objcopy did not discard. We should actually break
2230 apart the debugging information and only keep that which
2231 applies to the symbols we want to keep. */
2232 oinfo->symbolic_header.ilineMax = iinfo->symbolic_header.ilineMax;
2233 oinfo->symbolic_header.cbLine = iinfo->symbolic_header.cbLine;
2234 oinfo->line = iinfo->line;
2236 oinfo->symbolic_header.idnMax = iinfo->symbolic_header.idnMax;
2237 oinfo->external_dnr = iinfo->external_dnr;
2239 oinfo->symbolic_header.ipdMax = iinfo->symbolic_header.ipdMax;
2240 oinfo->external_pdr = iinfo->external_pdr;
2242 oinfo->symbolic_header.isymMax = iinfo->symbolic_header.isymMax;
2243 oinfo->external_sym = iinfo->external_sym;
2245 oinfo->symbolic_header.ioptMax = iinfo->symbolic_header.ioptMax;
2246 oinfo->external_opt = iinfo->external_opt;
2248 oinfo->symbolic_header.iauxMax = iinfo->symbolic_header.iauxMax;
2249 oinfo->external_aux = iinfo->external_aux;
2251 oinfo->symbolic_header.issMax = iinfo->symbolic_header.issMax;
2252 oinfo->ss = iinfo->ss;
2254 oinfo->symbolic_header.ifdMax = iinfo->symbolic_header.ifdMax;
2255 oinfo->external_fdr = iinfo->external_fdr;
2257 oinfo->symbolic_header.crfd = iinfo->symbolic_header.crfd;
2258 oinfo->external_rfd = iinfo->external_rfd;
2262 /* We are discarding all the local symbol information. Look
2263 through the external symbols and remove all references to FDR
2264 or aux information. */
2265 c = bfd_get_symcount (obfd);
2266 sym_ptr_ptr = bfd_get_outsymbols (obfd);
2267 for (; c > 0; c--, sym_ptr_ptr++)
2271 (*(ecoff_backend (obfd)->debug_swap.swap_ext_in))
2272 (obfd, ecoffsymbol (*sym_ptr_ptr)->native, &esym);
2274 esym.asym.index = indexNil;
2275 (*(ecoff_backend (obfd)->debug_swap.swap_ext_out))
2276 (obfd, &esym, ecoffsymbol (*sym_ptr_ptr)->native);
2283 /* Set the architecture. The supported architecture is stored in the
2284 backend pointer. We always set the architecture anyhow, since many
2285 callers ignore the return value. */
2288 ecoff_set_arch_mach (abfd, arch, machine)
2290 enum bfd_architecture arch;
2291 unsigned long machine;
2293 bfd_default_set_arch_mach (abfd, arch, machine);
2294 return arch == ecoff_backend (abfd)->arch;
2297 /* Get the size of the section headers. */
2301 ecoff_sizeof_headers (abfd, reloc)
2310 for (current = abfd->sections;
2311 current != (asection *)NULL;
2312 current = current->next)
2315 ret = (bfd_coff_filhsz (abfd)
2316 + bfd_coff_aoutsz (abfd)
2317 + c * bfd_coff_scnhsz (abfd));
2318 return BFD_ALIGN (ret, 16);
2321 /* Get the contents of a section. */
2324 ecoff_get_section_contents (abfd, section, location, offset, count)
2329 bfd_size_type count;
2331 return _bfd_generic_get_section_contents (abfd, section, location,
2335 /* Calculate the file position for each section, and set
2339 ecoff_compute_section_file_positions (abfd)
2347 sofar = ecoff_sizeof_headers (abfd, false);
2350 for (current = abfd->sections;
2351 current != (asection *) NULL;
2352 current = current->next)
2354 unsigned int alignment_power;
2356 /* Only deal with sections which have contents */
2357 if ((current->flags & (SEC_HAS_CONTENTS | SEC_LOAD)) == 0)
2360 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2361 supposed to indicate the number of .pdata entries that are
2362 really in the section. Each entry is 8 bytes. We store this
2363 away in line_filepos before increasing the section size. */
2364 if (strcmp (current->name, _PDATA) != 0)
2365 alignment_power = current->alignment_power;
2368 current->line_filepos = current->_raw_size / 8;
2369 alignment_power = 4;
2372 /* On Ultrix, the data sections in an executable file must be
2373 aligned to a page boundary within the file. This does not
2374 affect the section size, though. FIXME: Does this work for
2375 other platforms? It requires some modification for the
2376 Alpha, because .rdata on the Alpha goes with the text, not
2378 if ((abfd->flags & EXEC_P) != 0
2379 && (abfd->flags & D_PAGED) != 0
2380 && first_data != false
2381 && (current->flags & SEC_CODE) == 0
2382 && (! ecoff_backend (abfd)->rdata_in_text
2383 || strcmp (current->name, _RDATA) != 0)
2384 && strcmp (current->name, _PDATA) != 0)
2386 const bfd_vma round = ecoff_backend (abfd)->round;
2388 sofar = (sofar + round - 1) &~ (round - 1);
2391 else if (strcmp (current->name, _LIB) == 0)
2393 const bfd_vma round = ecoff_backend (abfd)->round;
2394 /* On Irix 4, the location of contents of the .lib section
2395 from a shared library section is also rounded up to a
2398 sofar = (sofar + round - 1) &~ (round - 1);
2401 /* Align the sections in the file to the same boundary on
2402 which they are aligned in virtual memory. */
2404 sofar = BFD_ALIGN (sofar, 1 << alignment_power);
2406 current->filepos = sofar;
2408 sofar += current->_raw_size;
2410 /* make sure that this section is of the right size too */
2412 sofar = BFD_ALIGN (sofar, 1 << alignment_power);
2413 current->_raw_size += sofar - old_sofar;
2416 ecoff_data (abfd)->reloc_filepos = sofar;
2419 /* Determine the location of the relocs for all the sections in the
2420 output file, as well as the location of the symbolic debugging
2423 static bfd_size_type
2424 ecoff_compute_reloc_file_positions (abfd)
2427 const bfd_size_type external_reloc_size =
2428 ecoff_backend (abfd)->external_reloc_size;
2429 file_ptr reloc_base;
2430 bfd_size_type reloc_size;
2434 if (! abfd->output_has_begun)
2436 ecoff_compute_section_file_positions (abfd);
2437 abfd->output_has_begun = true;
2440 reloc_base = ecoff_data (abfd)->reloc_filepos;
2443 for (current = abfd->sections;
2444 current != (asection *)NULL;
2445 current = current->next)
2447 if (current->reloc_count == 0)
2448 current->rel_filepos = 0;
2451 bfd_size_type relsize;
2453 current->rel_filepos = reloc_base;
2454 relsize = current->reloc_count * external_reloc_size;
2455 reloc_size += relsize;
2456 reloc_base += relsize;
2460 sym_base = ecoff_data (abfd)->reloc_filepos + reloc_size;
2462 /* At least on Ultrix, the symbol table of an executable file must
2463 be aligned to a page boundary. FIXME: Is this true on other
2465 if ((abfd->flags & EXEC_P) != 0
2466 && (abfd->flags & D_PAGED) != 0)
2467 sym_base = ((sym_base + ecoff_backend (abfd)->round - 1)
2468 &~ (ecoff_backend (abfd)->round - 1));
2470 ecoff_data (abfd)->sym_filepos = sym_base;
2475 /* Set the contents of a section. */
2478 ecoff_set_section_contents (abfd, section, location, offset, count)
2483 bfd_size_type count;
2485 /* This must be done first, because bfd_set_section_contents is
2486 going to set output_has_begun to true. */
2487 if (abfd->output_has_begun == false)
2488 ecoff_compute_section_file_positions (abfd);
2490 /* If this is a .lib section, bump the vma address so that it winds
2491 up being the number of .lib sections output. This is right for
2492 Irix 4. Ian Taylor <ian@cygnus.com>. */
2493 if (strcmp (section->name, _LIB) == 0)
2499 if (bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET) != 0
2500 || bfd_write (location, 1, count, abfd) != count)
2506 /* Get the GP value for an ECOFF file. This is a hook used by
2510 bfd_ecoff_get_gp_value (abfd)
2513 if (bfd_get_flavour (abfd) != bfd_target_ecoff_flavour
2514 || bfd_get_format (abfd) != bfd_object)
2516 bfd_set_error (bfd_error_invalid_operation);
2520 return ecoff_data (abfd)->gp;
2523 /* Set the GP value for an ECOFF file. This is a hook used by the
2527 bfd_ecoff_set_gp_value (abfd, gp_value)
2531 if (bfd_get_flavour (abfd) != bfd_target_ecoff_flavour
2532 || bfd_get_format (abfd) != bfd_object)
2534 bfd_set_error (bfd_error_invalid_operation);
2538 ecoff_data (abfd)->gp = gp_value;
2543 /* Set the register masks for an ECOFF file. This is a hook used by
2547 bfd_ecoff_set_regmasks (abfd, gprmask, fprmask, cprmask)
2549 unsigned long gprmask;
2550 unsigned long fprmask;
2551 unsigned long *cprmask;
2553 ecoff_data_type *tdata;
2555 if (bfd_get_flavour (abfd) != bfd_target_ecoff_flavour
2556 || bfd_get_format (abfd) != bfd_object)
2558 bfd_set_error (bfd_error_invalid_operation);
2562 tdata = ecoff_data (abfd);
2563 tdata->gprmask = gprmask;
2564 tdata->fprmask = fprmask;
2565 if (cprmask != (unsigned long *) NULL)
2569 for (i = 0; i < 3; i++)
2570 tdata->cprmask[i] = cprmask[i];
2576 /* Get ECOFF EXTR information for an external symbol. This function
2577 is passed to bfd_ecoff_debug_externals. */
2580 ecoff_get_extr (sym, esym)
2584 ecoff_symbol_type *ecoff_sym_ptr;
2587 if (bfd_asymbol_flavour (sym) != bfd_target_ecoff_flavour
2588 || ecoffsymbol (sym)->native == NULL)
2590 /* Don't include debugging, local, or section symbols. */
2591 if ((sym->flags & BSF_DEBUGGING) != 0
2592 || (sym->flags & BSF_LOCAL) != 0
2593 || (sym->flags & BSF_SECTION_SYM) != 0)
2597 esym->cobol_main = 0;
2601 /* FIXME: we can do better than this for st and sc. */
2602 esym->asym.st = stGlobal;
2603 esym->asym.sc = scAbs;
2604 esym->asym.reserved = 0;
2605 esym->asym.index = indexNil;
2609 ecoff_sym_ptr = ecoffsymbol (sym);
2611 if (ecoff_sym_ptr->local)
2614 input_bfd = bfd_asymbol_bfd (sym);
2615 (*(ecoff_backend (input_bfd)->debug_swap.swap_ext_in))
2616 (input_bfd, ecoff_sym_ptr->native, esym);
2618 /* If the symbol was defined by the linker, then esym will be
2619 undefined but sym will not be. Get a better class for such a
2621 if ((esym->asym.sc == scUndefined
2622 || esym->asym.sc == scSUndefined)
2623 && bfd_get_section (sym) != &bfd_und_section)
2624 esym->asym.sc = scAbs;
2626 /* Adjust the FDR index for the symbol by that used for the input
2628 if (esym->ifd != -1)
2630 struct ecoff_debug_info *input_debug;
2632 input_debug = &ecoff_data (input_bfd)->debug_info;
2633 BFD_ASSERT (esym->ifd < input_debug->symbolic_header.ifdMax);
2634 if (input_debug->ifdmap != (RFDT *) NULL)
2635 esym->ifd = input_debug->ifdmap[esym->ifd];
2641 /* Set the external symbol index. This routine is passed to
2642 bfd_ecoff_debug_externals. */
2645 ecoff_set_index (sym, indx)
2649 ecoff_set_sym_index (sym, indx);
2652 /* Write out an ECOFF file. */
2655 ecoff_write_object_contents (abfd)
2658 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
2659 const bfd_vma round = backend->round;
2660 const bfd_size_type filhsz = bfd_coff_filhsz (abfd);
2661 const bfd_size_type aoutsz = bfd_coff_aoutsz (abfd);
2662 const bfd_size_type scnhsz = bfd_coff_scnhsz (abfd);
2663 const bfd_size_type external_hdr_size
2664 = backend->debug_swap.external_hdr_size;
2665 const bfd_size_type external_reloc_size = backend->external_reloc_size;
2666 void (* const adjust_reloc_out) PARAMS ((bfd *,
2668 struct internal_reloc *))
2669 = backend->adjust_reloc_out;
2670 void (* const swap_reloc_out) PARAMS ((bfd *,
2671 const struct internal_reloc *,
2673 = backend->swap_reloc_out;
2674 struct ecoff_debug_info * const debug = &ecoff_data (abfd)->debug_info;
2675 HDRR * const symhdr = &debug->symbolic_header;
2678 bfd_size_type reloc_size;
2679 bfd_size_type text_size;
2681 boolean set_text_start;
2682 bfd_size_type data_size;
2684 boolean set_data_start;
2685 bfd_size_type bss_size;
2687 PTR reloc_buff = NULL;
2688 struct internal_filehdr internal_f;
2689 struct internal_aouthdr internal_a;
2692 /* Determine where the sections and relocs will go in the output
2694 reloc_size = ecoff_compute_reloc_file_positions (abfd);
2697 for (current = abfd->sections;
2698 current != (asection *)NULL;
2699 current = current->next)
2701 current->target_index = count;
2705 if ((abfd->flags & D_PAGED) != 0)
2706 text_size = ecoff_sizeof_headers (abfd, false);
2710 set_text_start = false;
2713 set_data_start = false;
2716 /* Write section headers to the file. */
2718 /* Allocate buff big enough to hold a section header,
2719 file header, or a.out header. */
2727 buff = (PTR) malloc (siz);
2730 bfd_set_error (bfd_error_no_memory);
2735 internal_f.f_nscns = 0;
2736 if (bfd_seek (abfd, (file_ptr) (filhsz + aoutsz), SEEK_SET) != 0)
2738 for (current = abfd->sections;
2739 current != (asection *) NULL;
2740 current = current->next)
2742 struct internal_scnhdr section;
2745 ++internal_f.f_nscns;
2747 strncpy (section.s_name, current->name, sizeof section.s_name);
2749 /* This seems to be correct for Irix 4 shared libraries. */
2750 vma = bfd_get_section_vma (abfd, current);
2751 if (strcmp (current->name, _LIB) == 0)
2752 section.s_vaddr = 0;
2754 section.s_vaddr = vma;
2756 section.s_paddr = vma;
2757 section.s_size = bfd_get_section_size_before_reloc (current);
2759 /* If this section is unloadable then the scnptr will be 0. */
2760 if ((current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
2761 section.s_scnptr = 0;
2763 section.s_scnptr = current->filepos;
2764 section.s_relptr = current->rel_filepos;
2766 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2767 object file produced by the assembler is supposed to point to
2768 information about how much room is required by objects of
2769 various different sizes. I think this only matters if we
2770 want the linker to compute the best size to use, or
2771 something. I don't know what happens if the information is
2773 if (strcmp (current->name, _PDATA) != 0)
2774 section.s_lnnoptr = 0;
2777 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2778 hold the number of entries in the section (each entry is
2779 8 bytes). We stored this in the line_filepos field in
2780 ecoff_compute_section_file_positions. */
2781 section.s_lnnoptr = current->line_filepos;
2784 section.s_nreloc = current->reloc_count;
2785 section.s_nlnno = 0;
2786 section.s_flags = ecoff_sec_to_styp_flags (current->name,
2789 bfd_coff_swap_scnhdr_out (abfd, (PTR) §ion, buff);
2790 if (bfd_write (buff, 1, scnhsz, abfd) != scnhsz)
2793 if ((section.s_flags & STYP_TEXT) != 0
2794 || ((section.s_flags & STYP_RDATA) != 0
2795 && backend->rdata_in_text)
2796 || strcmp (current->name, _PDATA) == 0)
2798 text_size += bfd_get_section_size_before_reloc (current);
2799 if (! set_text_start || text_start > vma)
2802 set_text_start = true;
2805 else if ((section.s_flags & STYP_RDATA) != 0
2806 || (section.s_flags & STYP_DATA) != 0
2807 || (section.s_flags & STYP_LITA) != 0
2808 || (section.s_flags & STYP_LIT8) != 0
2809 || (section.s_flags & STYP_LIT4) != 0
2810 || (section.s_flags & STYP_SDATA) != 0
2811 || strcmp (current->name, _XDATA) == 0)
2813 data_size += bfd_get_section_size_before_reloc (current);
2814 if (! set_data_start || data_start > vma)
2817 set_data_start = true;
2820 else if ((section.s_flags & STYP_BSS) != 0
2821 || (section.s_flags & STYP_SBSS) != 0)
2822 bss_size += bfd_get_section_size_before_reloc (current);
2823 else if ((section.s_flags & STYP_ECOFF_LIB) != 0)
2829 /* Set up the file header. */
2831 internal_f.f_magic = ecoff_get_magic (abfd);
2833 /* We will NOT put a fucking timestamp in the header here. Every
2834 time you put it back, I will come in and take it out again. I'm
2835 sorry. This field does not belong here. We fill it with a 0 so
2836 it compares the same but is not a reasonable time. --
2838 internal_f.f_timdat = 0;
2840 if (bfd_get_symcount (abfd) != 0)
2842 /* The ECOFF f_nsyms field is not actually the number of
2843 symbols, it's the size of symbolic information header. */
2844 internal_f.f_nsyms = external_hdr_size;
2845 internal_f.f_symptr = ecoff_data (abfd)->sym_filepos;
2849 internal_f.f_nsyms = 0;
2850 internal_f.f_symptr = 0;
2853 internal_f.f_opthdr = aoutsz;
2855 internal_f.f_flags = F_LNNO;
2856 if (reloc_size == 0)
2857 internal_f.f_flags |= F_RELFLG;
2858 if (bfd_get_symcount (abfd) == 0)
2859 internal_f.f_flags |= F_LSYMS;
2860 if (abfd->flags & EXEC_P)
2861 internal_f.f_flags |= F_EXEC;
2863 if (! abfd->xvec->byteorder_big_p)
2864 internal_f.f_flags |= F_AR32WR;
2866 internal_f.f_flags |= F_AR32W;
2868 /* Set up the ``optional'' header. */
2869 if ((abfd->flags & D_PAGED) != 0)
2870 internal_a.magic = ECOFF_AOUT_ZMAGIC;
2872 internal_a.magic = ECOFF_AOUT_OMAGIC;
2874 /* FIXME: Is this really correct? */
2875 internal_a.vstamp = symhdr->vstamp;
2877 /* At least on Ultrix, these have to be rounded to page boundaries.
2878 FIXME: Is this true on other platforms? */
2879 if ((abfd->flags & D_PAGED) != 0)
2881 internal_a.tsize = (text_size + round - 1) &~ (round - 1);
2882 internal_a.text_start = text_start &~ (round - 1);
2883 internal_a.dsize = (data_size + round - 1) &~ (round - 1);
2884 internal_a.data_start = data_start &~ (round - 1);
2888 internal_a.tsize = text_size;
2889 internal_a.text_start = text_start;
2890 internal_a.dsize = data_size;
2891 internal_a.data_start = data_start;
2894 /* On Ultrix, the initial portions of the .sbss and .bss segments
2895 are at the end of the data section. The bsize field in the
2896 optional header records how many bss bytes are required beyond
2897 those in the data section. The value is not rounded to a page
2899 if (bss_size < internal_a.dsize - data_size)
2902 bss_size -= internal_a.dsize - data_size;
2903 internal_a.bsize = bss_size;
2904 internal_a.bss_start = internal_a.data_start + internal_a.dsize;
2906 internal_a.entry = bfd_get_start_address (abfd);
2908 internal_a.gp_value = ecoff_data (abfd)->gp;
2910 internal_a.gprmask = ecoff_data (abfd)->gprmask;
2911 internal_a.fprmask = ecoff_data (abfd)->fprmask;
2912 for (i = 0; i < 4; i++)
2913 internal_a.cprmask[i] = ecoff_data (abfd)->cprmask[i];
2915 /* Write out the file header and the optional header. */
2917 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
2920 bfd_coff_swap_filehdr_out (abfd, (PTR) &internal_f, buff);
2921 if (bfd_write (buff, 1, filhsz, abfd) != filhsz)
2924 bfd_coff_swap_aouthdr_out (abfd, (PTR) &internal_a, buff);
2925 if (bfd_write (buff, 1, aoutsz, abfd) != aoutsz)
2928 /* Build the external symbol information. This must be done before
2929 writing out the relocs so that we know the symbol indices. We
2930 don't do this if this BFD was created by the backend linker,
2931 since it will have already handled the symbols and relocs. */
2932 if (! ecoff_data (abfd)->linker)
2934 symhdr->iextMax = 0;
2935 symhdr->issExtMax = 0;
2936 debug->external_ext = debug->external_ext_end = NULL;
2937 debug->ssext = debug->ssext_end = NULL;
2938 if (bfd_ecoff_debug_externals (abfd, debug, &backend->debug_swap,
2939 (((abfd->flags & EXEC_P) == 0)
2941 ecoff_get_extr, ecoff_set_index)
2945 /* Write out the relocs. */
2946 for (current = abfd->sections;
2947 current != (asection *) NULL;
2948 current = current->next)
2950 arelent **reloc_ptr_ptr;
2951 arelent **reloc_end;
2954 if (current->reloc_count == 0)
2958 bfd_alloc (abfd, current->reloc_count * external_reloc_size);
2959 if (reloc_buff == NULL)
2961 bfd_set_error (bfd_error_no_memory);
2965 reloc_ptr_ptr = current->orelocation;
2966 reloc_end = reloc_ptr_ptr + current->reloc_count;
2967 out_ptr = (char *) reloc_buff;
2969 reloc_ptr_ptr < reloc_end;
2970 reloc_ptr_ptr++, out_ptr += external_reloc_size)
2974 struct internal_reloc in;
2976 memset ((PTR) &in, 0, sizeof in);
2978 reloc = *reloc_ptr_ptr;
2979 sym = *reloc->sym_ptr_ptr;
2981 in.r_vaddr = (reloc->address
2982 + bfd_get_section_vma (abfd, current));
2983 in.r_type = reloc->howto->type;
2985 if ((sym->flags & BSF_SECTION_SYM) == 0)
2987 in.r_symndx = ecoff_get_sym_index (*reloc->sym_ptr_ptr);
2994 name = bfd_get_section_name (abfd, bfd_get_section (sym));
2995 if (strcmp (name, ".text") == 0)
2996 in.r_symndx = RELOC_SECTION_TEXT;
2997 else if (strcmp (name, ".rdata") == 0)
2998 in.r_symndx = RELOC_SECTION_RDATA;
2999 else if (strcmp (name, ".data") == 0)
3000 in.r_symndx = RELOC_SECTION_DATA;
3001 else if (strcmp (name, ".sdata") == 0)
3002 in.r_symndx = RELOC_SECTION_SDATA;
3003 else if (strcmp (name, ".sbss") == 0)
3004 in.r_symndx = RELOC_SECTION_SBSS;
3005 else if (strcmp (name, ".bss") == 0)
3006 in.r_symndx = RELOC_SECTION_BSS;
3007 else if (strcmp (name, ".init") == 0)
3008 in.r_symndx = RELOC_SECTION_INIT;
3009 else if (strcmp (name, ".lit8") == 0)
3010 in.r_symndx = RELOC_SECTION_LIT8;
3011 else if (strcmp (name, ".lit4") == 0)
3012 in.r_symndx = RELOC_SECTION_LIT4;
3013 else if (strcmp (name, ".xdata") == 0)
3014 in.r_symndx = RELOC_SECTION_XDATA;
3015 else if (strcmp (name, ".pdata") == 0)
3016 in.r_symndx = RELOC_SECTION_PDATA;
3017 else if (strcmp (name, ".fini") == 0)
3018 in.r_symndx = RELOC_SECTION_FINI;
3019 else if (strcmp (name, ".lita") == 0)
3020 in.r_symndx = RELOC_SECTION_LITA;
3021 else if (strcmp (name, "*ABS*") == 0)
3022 in.r_symndx = RELOC_SECTION_ABS;
3028 (*adjust_reloc_out) (abfd, reloc, &in);
3030 (*swap_reloc_out) (abfd, &in, (PTR) out_ptr);
3033 if (bfd_seek (abfd, current->rel_filepos, SEEK_SET) != 0)
3035 if (bfd_write (reloc_buff,
3036 external_reloc_size, current->reloc_count, abfd)
3037 != external_reloc_size * current->reloc_count)
3039 bfd_release (abfd, reloc_buff);
3043 /* Write out the symbolic debugging information. */
3044 if (bfd_get_symcount (abfd) > 0)
3046 /* Write out the debugging information. */
3047 if (bfd_ecoff_write_debug (abfd, debug, &backend->debug_swap,
3048 ecoff_data (abfd)->sym_filepos)
3054 /* The .bss section of a demand paged executable must receive an
3055 entire page. If there are symbols, the symbols will start on the
3056 next page. If there are no symbols, we must fill out the page by
3058 if (bfd_get_symcount (abfd) == 0
3059 && (abfd->flags & EXEC_P) != 0
3060 && (abfd->flags & D_PAGED) != 0)
3064 if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
3067 if (bfd_read (&c, 1, 1, abfd) == 0)
3069 if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
3072 if (bfd_write (&c, 1, 1, abfd) != 1)
3076 if (reloc_buff != NULL)
3077 bfd_release (abfd, reloc_buff);
3082 if (reloc_buff != NULL)
3083 bfd_release (abfd, reloc_buff);
3089 /* Archive handling. ECOFF uses what appears to be a unique type of
3090 archive header (armap). The byte ordering of the armap and the
3091 contents are encoded in the name of the armap itself. At least for
3092 now, we only support archives with the same byte ordering in the
3093 armap and the contents.
3095 The first four bytes in the armap are the number of symbol
3096 definitions. This is always a power of two.
3098 This is followed by the symbol definitions. Each symbol definition
3099 occupies 8 bytes. The first four bytes are the offset from the
3100 start of the armap strings to the null-terminated string naming
3101 this symbol. The second four bytes are the file offset to the
3102 archive member which defines this symbol. If the second four bytes
3103 are 0, then this is not actually a symbol definition, and it should
3106 The symbols are hashed into the armap with a closed hashing scheme.
3107 See the functions below for the details of the algorithm.
3109 After the symbol definitions comes four bytes holding the size of
3110 the string table, followed by the string table itself. */
3112 /* The name of an archive headers looks like this:
3113 __________E[BL]E[BL]_ (with a trailing space).
3114 The trailing space is changed to an X if the archive is changed to
3115 indicate that the armap is out of date.
3117 The Alpha seems to use ________64E[BL]E[BL]_. */
3119 #define ARMAP_BIG_ENDIAN 'B'
3120 #define ARMAP_LITTLE_ENDIAN 'L'
3121 #define ARMAP_MARKER 'E'
3122 #define ARMAP_START_LENGTH 10
3123 #define ARMAP_HEADER_MARKER_INDEX 10
3124 #define ARMAP_HEADER_ENDIAN_INDEX 11
3125 #define ARMAP_OBJECT_MARKER_INDEX 12
3126 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3127 #define ARMAP_END_INDEX 14
3128 #define ARMAP_END "_ "
3130 /* This is a magic number used in the hashing algorithm. */
3131 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3133 /* This returns the hash value to use for a string. It also sets
3134 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3135 is the number of entries in the hash table, and HLOG is the log
3139 ecoff_armap_hash (s, rehash, size, hlog)
3141 unsigned int *rehash;
3149 hash = ((hash >> 27) | (hash << 5)) + *s++;
3150 hash *= ARMAP_HASH_MAGIC;
3151 *rehash = (hash & (size - 1)) | 1;
3152 return hash >> (32 - hlog);
3155 /* Read in the armap. */
3158 ecoff_slurp_armap (abfd)
3163 struct areltdata *mapdata;
3164 bfd_size_type parsed_size;
3166 struct artdata *ardata;
3169 struct symdef *symdef_ptr;
3172 /* Get the name of the first element. */
3173 i = bfd_read ((PTR) nextname, 1, 16, abfd);
3179 if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0)
3182 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3183 standard COFF armap. We could move the ECOFF armap stuff into
3184 bfd_slurp_armap, but that seems inappropriate since no other
3185 target uses this format. Instead, we check directly for a COFF
3187 if (strncmp (nextname, "/ ", 16) == 0)
3188 return bfd_slurp_armap (abfd);
3190 /* See if the first element is an armap. */
3191 if (strncmp (nextname, ecoff_backend (abfd)->armap_start,
3192 ARMAP_START_LENGTH) != 0
3193 || nextname[ARMAP_HEADER_MARKER_INDEX] != ARMAP_MARKER
3194 || (nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3195 && nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3196 || nextname[ARMAP_OBJECT_MARKER_INDEX] != ARMAP_MARKER
3197 || (nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3198 && nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3199 || strncmp (nextname + ARMAP_END_INDEX,
3200 ARMAP_END, sizeof ARMAP_END - 1) != 0)
3202 bfd_has_map (abfd) = false;
3206 /* Make sure we have the right byte ordering. */
3207 if (((nextname[ARMAP_HEADER_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3208 ^ (abfd->xvec->header_byteorder_big_p != false))
3209 || ((nextname[ARMAP_OBJECT_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3210 ^ (abfd->xvec->byteorder_big_p != false)))
3212 bfd_set_error (bfd_error_wrong_format);
3216 /* Read in the armap. */
3217 ardata = bfd_ardata (abfd);
3218 mapdata = _bfd_snarf_ar_hdr (abfd);
3219 if (mapdata == (struct areltdata *) NULL)
3221 parsed_size = mapdata->parsed_size;
3222 bfd_release (abfd, (PTR) mapdata);
3224 raw_armap = (char *) bfd_alloc (abfd, parsed_size);
3225 if (raw_armap == (char *) NULL)
3227 bfd_set_error (bfd_error_no_memory);
3231 if (bfd_read ((PTR) raw_armap, 1, parsed_size, abfd) != parsed_size)
3233 if (bfd_get_error () != bfd_error_system_call)
3234 bfd_set_error (bfd_error_malformed_archive);
3235 bfd_release (abfd, (PTR) raw_armap);
3239 ardata->tdata = (PTR) raw_armap;
3241 count = bfd_h_get_32 (abfd, (PTR) raw_armap);
3243 ardata->symdef_count = 0;
3244 ardata->cache = (struct ar_cache *) NULL;
3246 /* This code used to overlay the symdefs over the raw archive data,
3247 but that doesn't work on a 64 bit host. */
3249 stringbase = raw_armap + count * 8 + 8;
3251 #ifdef CHECK_ARMAP_HASH
3255 /* Double check that I have the hashing algorithm right by making
3256 sure that every symbol can be looked up successfully. */
3258 for (i = 1; i < count; i <<= 1)
3260 BFD_ASSERT (i == count);
3262 raw_ptr = raw_armap + 4;
3263 for (i = 0; i < count; i++, raw_ptr += 8)
3265 unsigned int name_offset, file_offset;
3266 unsigned int hash, rehash, srch;
3268 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3269 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + 4));
3270 if (file_offset == 0)
3272 hash = ecoff_armap_hash (stringbase + name_offset, &rehash, count,
3277 /* See if we can rehash to this location. */
3278 for (srch = (hash + rehash) & (count - 1);
3279 srch != hash && srch != i;
3280 srch = (srch + rehash) & (count - 1))
3281 BFD_ASSERT (bfd_h_get_32 (abfd, (PTR) (raw_armap + 8 + srch * 8))
3283 BFD_ASSERT (srch == i);
3287 #endif /* CHECK_ARMAP_HASH */
3289 raw_ptr = raw_armap + 4;
3290 for (i = 0; i < count; i++, raw_ptr += 8)
3291 if (bfd_h_get_32 (abfd, (PTR) (raw_ptr + 4)) != 0)
3292 ++ardata->symdef_count;
3294 symdef_ptr = ((struct symdef *)
3296 ardata->symdef_count * sizeof (struct symdef)));
3299 bfd_set_error (bfd_error_no_memory);
3303 ardata->symdefs = (carsym *) symdef_ptr;
3305 raw_ptr = raw_armap + 4;
3306 for (i = 0; i < count; i++, raw_ptr += 8)
3308 unsigned int name_offset, file_offset;
3310 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + 4));
3311 if (file_offset == 0)
3313 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3314 symdef_ptr->s.name = stringbase + name_offset;
3315 symdef_ptr->file_offset = file_offset;
3319 ardata->first_file_filepos = bfd_tell (abfd);
3320 /* Pad to an even boundary. */
3321 ardata->first_file_filepos += ardata->first_file_filepos % 2;
3323 bfd_has_map (abfd) = true;
3328 /* Write out an armap. */
3331 ecoff_write_armap (abfd, elength, map, orl_count, stridx)
3333 unsigned int elength;
3335 unsigned int orl_count;
3338 unsigned int hashsize, hashlog;
3339 unsigned int symdefsize;
3341 unsigned int stringsize;
3342 unsigned int mapsize;
3345 struct stat statbuf;
3348 bfd_byte *hashtable;
3352 /* Ultrix appears to use as a hash table size the least power of two
3353 greater than twice the number of entries. */
3354 for (hashlog = 0; (1 << hashlog) <= 2 * orl_count; hashlog++)
3356 hashsize = 1 << hashlog;
3358 symdefsize = hashsize * 8;
3360 stringsize = stridx + padit;
3362 /* Include 8 bytes to store symdefsize and stringsize in output. */
3363 mapsize = symdefsize + stringsize + 8;
3365 firstreal = SARMAG + sizeof (struct ar_hdr) + mapsize + elength;
3367 memset ((PTR) &hdr, 0, sizeof hdr);
3369 /* Work out the ECOFF armap name. */
3370 strcpy (hdr.ar_name, ecoff_backend (abfd)->armap_start);
3371 hdr.ar_name[ARMAP_HEADER_MARKER_INDEX] = ARMAP_MARKER;
3372 hdr.ar_name[ARMAP_HEADER_ENDIAN_INDEX] =
3373 (abfd->xvec->header_byteorder_big_p
3375 : ARMAP_LITTLE_ENDIAN);
3376 hdr.ar_name[ARMAP_OBJECT_MARKER_INDEX] = ARMAP_MARKER;
3377 hdr.ar_name[ARMAP_OBJECT_ENDIAN_INDEX] =
3378 abfd->xvec->byteorder_big_p ? ARMAP_BIG_ENDIAN : ARMAP_LITTLE_ENDIAN;
3379 memcpy (hdr.ar_name + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1);
3381 /* Write the timestamp of the archive header to be just a little bit
3382 later than the timestamp of the file, otherwise the linker will
3383 complain that the index is out of date. Actually, the Ultrix
3384 linker just checks the archive name; the GNU linker may check the
3386 stat (abfd->filename, &statbuf);
3387 sprintf (hdr.ar_date, "%ld", (long) (statbuf.st_mtime + 60));
3389 /* The DECstation uses zeroes for the uid, gid and mode of the
3391 hdr.ar_uid[0] = '0';
3392 hdr.ar_gid[0] = '0';
3393 hdr.ar_mode[0] = '0';
3395 sprintf (hdr.ar_size, "%-10d", (int) mapsize);
3397 hdr.ar_fmag[0] = '`';
3398 hdr.ar_fmag[1] = '\012';
3400 /* Turn all null bytes in the header into spaces. */
3401 for (i = 0; i < sizeof (struct ar_hdr); i++)
3402 if (((char *)(&hdr))[i] == '\0')
3403 (((char *)(&hdr))[i]) = ' ';
3405 if (bfd_write ((PTR) &hdr, 1, sizeof (struct ar_hdr), abfd)
3406 != sizeof (struct ar_hdr))
3409 bfd_h_put_32 (abfd, (bfd_vma) hashsize, temp);
3410 if (bfd_write ((PTR) temp, 1, 4, abfd) != 4)
3413 hashtable = (bfd_byte *) bfd_zalloc (abfd, symdefsize);
3416 bfd_set_error (bfd_error_no_memory);
3420 current = abfd->archive_head;
3422 for (i = 0; i < orl_count; i++)
3424 unsigned int hash, rehash;
3426 /* Advance firstreal to the file position of this archive
3428 if (((bfd *) map[i].pos) != last_elt)
3432 firstreal += arelt_size (current) + sizeof (struct ar_hdr);
3433 firstreal += firstreal % 2;
3434 current = current->next;
3436 while (current != (bfd *) map[i].pos);
3441 hash = ecoff_armap_hash (*map[i].name, &rehash, hashsize, hashlog);
3442 if (bfd_h_get_32 (abfd, (PTR) (hashtable + (hash * 8) + 4)) != 0)
3446 /* The desired slot is already taken. */
3447 for (srch = (hash + rehash) & (hashsize - 1);
3449 srch = (srch + rehash) & (hashsize - 1))
3450 if (bfd_h_get_32 (abfd, (PTR) (hashtable + (srch * 8) + 4)) == 0)
3453 BFD_ASSERT (srch != hash);
3458 bfd_h_put_32 (abfd, (bfd_vma) map[i].namidx,
3459 (PTR) (hashtable + hash * 8));
3460 bfd_h_put_32 (abfd, (bfd_vma) firstreal,
3461 (PTR) (hashtable + hash * 8 + 4));
3464 if (bfd_write ((PTR) hashtable, 1, symdefsize, abfd) != symdefsize)
3467 bfd_release (abfd, hashtable);
3469 /* Now write the strings. */
3470 bfd_h_put_32 (abfd, (bfd_vma) stringsize, temp);
3471 if (bfd_write ((PTR) temp, 1, 4, abfd) != 4)
3473 for (i = 0; i < orl_count; i++)
3477 len = strlen (*map[i].name) + 1;
3478 if (bfd_write ((PTR) (*map[i].name), 1, len, abfd) != len)
3482 /* The spec sez this should be a newline. But in order to be
3483 bug-compatible for DECstation ar we use a null. */
3486 if (bfd_write ("", 1, 1, abfd) != 1)
3493 /* See whether this BFD is an archive. If it is, read in the armap
3494 and the extended name table. */
3497 ecoff_archive_p (abfd)
3500 char armag[SARMAG + 1];
3502 if (bfd_read ((PTR) armag, 1, SARMAG, abfd) != SARMAG
3503 || strncmp (armag, ARMAG, SARMAG) != 0)
3505 if (bfd_get_error () != bfd_error_system_call)
3506 bfd_set_error (bfd_error_wrong_format);
3507 return (bfd_target *) NULL;
3510 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3511 involves a cast, we can't do it as the left operand of
3513 abfd->tdata.aout_ar_data =
3514 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
3516 if (bfd_ardata (abfd) == (struct artdata *) NULL)
3518 bfd_set_error (bfd_error_no_memory);
3519 return (bfd_target *) NULL;
3522 bfd_ardata (abfd)->first_file_filepos = SARMAG;
3523 bfd_ardata (abfd)->cache = NULL;
3524 bfd_ardata (abfd)->archive_head = NULL;
3525 bfd_ardata (abfd)->symdefs = NULL;
3526 bfd_ardata (abfd)->extended_names = NULL;
3527 bfd_ardata (abfd)->tdata = NULL;
3529 if (ecoff_slurp_armap (abfd) == false
3530 || ecoff_slurp_extended_name_table (abfd) == false)
3532 bfd_release (abfd, bfd_ardata (abfd));
3533 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
3534 return (bfd_target *) NULL;
3540 /* ECOFF linker code. */
3542 static struct bfd_hash_entry *ecoff_link_hash_newfunc
3543 PARAMS ((struct bfd_hash_entry *entry,
3544 struct bfd_hash_table *table,
3545 const char *string));
3546 static boolean ecoff_link_add_archive_symbols
3547 PARAMS ((bfd *, struct bfd_link_info *));
3548 static boolean ecoff_link_check_archive_element
3549 PARAMS ((bfd *, struct bfd_link_info *, boolean *pneeded));
3550 static boolean ecoff_link_add_object_symbols
3551 PARAMS ((bfd *, struct bfd_link_info *));
3552 static boolean ecoff_link_add_externals
3553 PARAMS ((bfd *, struct bfd_link_info *, PTR, char *));
3555 /* Routine to create an entry in an ECOFF link hash table. */
3557 static struct bfd_hash_entry *
3558 ecoff_link_hash_newfunc (entry, table, string)
3559 struct bfd_hash_entry *entry;
3560 struct bfd_hash_table *table;
3563 struct ecoff_link_hash_entry *ret = (struct ecoff_link_hash_entry *) entry;
3565 /* Allocate the structure if it has not already been allocated by a
3567 if (ret == (struct ecoff_link_hash_entry *) NULL)
3568 ret = ((struct ecoff_link_hash_entry *)
3569 bfd_hash_allocate (table, sizeof (struct ecoff_link_hash_entry)));
3570 if (ret == (struct ecoff_link_hash_entry *) NULL)
3572 bfd_set_error (bfd_error_no_memory);
3576 /* Call the allocation method of the superclass. */
3577 ret = ((struct ecoff_link_hash_entry *)
3578 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3583 /* Set local fields. */
3589 memset ((PTR) &ret->esym, 0, sizeof ret->esym);
3591 return (struct bfd_hash_entry *) ret;
3594 /* Create an ECOFF link hash table. */
3596 struct bfd_link_hash_table *
3597 ecoff_bfd_link_hash_table_create (abfd)
3600 struct ecoff_link_hash_table *ret;
3602 ret = ((struct ecoff_link_hash_table *)
3603 malloc (sizeof (struct ecoff_link_hash_table)));
3606 bfd_set_error (bfd_error_no_memory);
3609 if (! _bfd_link_hash_table_init (&ret->root, abfd,
3610 ecoff_link_hash_newfunc))
3613 return (struct bfd_link_hash_table *) NULL;
3618 /* Look up an entry in an ECOFF link hash table. */
3620 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3621 ((struct ecoff_link_hash_entry *) \
3622 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3624 /* Traverse an ECOFF link hash table. */
3626 #define ecoff_link_hash_traverse(table, func, info) \
3627 (bfd_link_hash_traverse \
3629 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3632 /* Get the ECOFF link hash table from the info structure. This is
3635 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3637 /* Given an ECOFF BFD, add symbols to the global hash table as
3641 ecoff_bfd_link_add_symbols (abfd, info)
3643 struct bfd_link_info *info;
3645 switch (bfd_get_format (abfd))
3648 return ecoff_link_add_object_symbols (abfd, info);
3650 return ecoff_link_add_archive_symbols (abfd, info);
3652 bfd_set_error (bfd_error_wrong_format);
3657 /* Add the symbols from an archive file to the global hash table.
3658 This looks through the undefined symbols, looks each one up in the
3659 archive hash table, and adds any associated object file. We do not
3660 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3661 already have a hash table, so there is no reason to construct
3665 ecoff_link_add_archive_symbols (abfd, info)
3667 struct bfd_link_info *info;
3669 const bfd_byte *raw_armap;
3670 struct bfd_link_hash_entry **pundef;
3671 unsigned int armap_count;
3672 unsigned int armap_log;
3674 const bfd_byte *hashtable;
3675 const char *stringbase;
3677 if (! bfd_has_map (abfd))
3679 bfd_set_error (bfd_error_no_symbols);
3683 /* If we don't have any raw data for this archive, as can happen on
3684 Irix 4.0.5F, we call the generic routine.
3685 FIXME: We should be more clever about this, since someday tdata
3686 may get to something for a generic archive. */
3687 raw_armap = (const bfd_byte *) bfd_ardata (abfd)->tdata;
3688 if (raw_armap == (bfd_byte *) NULL)
3689 return (_bfd_generic_link_add_archive_symbols
3690 (abfd, info, ecoff_link_check_archive_element));
3692 armap_count = bfd_h_get_32 (abfd, raw_armap);
3695 for (i = 1; i < armap_count; i <<= 1)
3697 BFD_ASSERT (i == armap_count);
3699 hashtable = raw_armap + 4;
3700 stringbase = (const char *) raw_armap + armap_count * 8 + 8;
3702 /* Look through the list of undefined symbols. */
3703 pundef = &info->hash->undefs;
3704 while (*pundef != (struct bfd_link_hash_entry *) NULL)
3706 struct bfd_link_hash_entry *h;
3707 unsigned int hash, rehash;
3708 unsigned int file_offset;
3714 /* When a symbol is defined, it is not necessarily removed from
3716 if (h->type != bfd_link_hash_undefined
3717 && h->type != bfd_link_hash_common)
3719 /* Remove this entry from the list, for general cleanliness
3720 and because we are going to look through the list again
3721 if we search any more libraries. We can't remove the
3722 entry if it is the tail, because that would lose any
3723 entries we add to the list later on. */
3724 if (*pundef != info->hash->undefs_tail)
3725 *pundef = (*pundef)->next;
3727 pundef = &(*pundef)->next;
3731 /* Native ECOFF linkers do not pull in archive elements merely
3732 to satisfy common definitions, so neither do we. We leave
3733 them on the list, though, in case we are linking against some
3734 other object format. */
3735 if (h->type != bfd_link_hash_undefined)
3737 pundef = &(*pundef)->next;
3741 /* Look for this symbol in the archive hash table. */
3742 hash = ecoff_armap_hash (h->root.string, &rehash, armap_count,
3745 file_offset = bfd_h_get_32 (abfd, hashtable + (hash * 8) + 4);
3746 if (file_offset == 0)
3748 /* Nothing in this slot. */
3749 pundef = &(*pundef)->next;
3753 name = stringbase + bfd_h_get_32 (abfd, hashtable + (hash * 8));
3754 if (name[0] != h->root.string[0]
3755 || strcmp (name, h->root.string) != 0)
3760 /* That was the wrong symbol. Try rehashing. */
3762 for (srch = (hash + rehash) & (armap_count - 1);
3764 srch = (srch + rehash) & (armap_count - 1))
3766 file_offset = bfd_h_get_32 (abfd, hashtable + (srch * 8) + 4);
3767 if (file_offset == 0)
3769 name = stringbase + bfd_h_get_32 (abfd, hashtable + (srch * 8));
3770 if (name[0] == h->root.string[0]
3771 && strcmp (name, h->root.string) == 0)
3780 pundef = &(*pundef)->next;
3787 element = _bfd_get_elt_at_filepos (abfd, file_offset);
3788 if (element == (bfd *) NULL)
3791 if (! bfd_check_format (element, bfd_object))
3794 /* Unlike the generic linker, we know that this element provides
3795 a definition for an undefined symbol and we know that we want
3796 to include it. We don't need to check anything. */
3797 if (! (*info->callbacks->add_archive_element) (info, element, name))
3799 if (! ecoff_link_add_object_symbols (element, info))
3802 pundef = &(*pundef)->next;
3808 /* This is called if we used _bfd_generic_link_add_archive_symbols
3809 because we were not dealing with an ECOFF archive. */
3812 ecoff_link_check_archive_element (abfd, info, pneeded)
3814 struct bfd_link_info *info;
3817 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
3818 void (* const swap_ext_in) PARAMS ((bfd *, PTR, EXTR *))
3819 = backend->debug_swap.swap_ext_in;
3821 bfd_size_type external_ext_size;
3822 PTR external_ext = NULL;
3830 if (! ecoff_slurp_symbolic_header (abfd))
3833 /* If there are no symbols, we don't want it. */
3834 if (bfd_get_symcount (abfd) == 0)
3835 goto successful_return;
3837 symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
3839 /* Read in the external symbols and external strings. */
3840 external_ext_size = backend->debug_swap.external_ext_size;
3841 esize = symhdr->iextMax * external_ext_size;
3842 external_ext = (PTR) malloc (esize);
3843 if (external_ext == NULL && esize != 0)
3845 bfd_set_error (bfd_error_no_memory);
3849 if (bfd_seek (abfd, symhdr->cbExtOffset, SEEK_SET) != 0
3850 || bfd_read (external_ext, 1, esize, abfd) != esize)
3853 ssext = (char *) malloc (symhdr->issExtMax);
3854 if (ssext == NULL && symhdr->issExtMax != 0)
3856 bfd_set_error (bfd_error_no_memory);
3860 if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0
3861 || bfd_read (ssext, 1, symhdr->issExtMax, abfd) != symhdr->issExtMax)
3864 /* Look through the external symbols to see if they define some
3865 symbol that is currently undefined. */
3866 ext_ptr = (char *) external_ext;
3867 ext_end = ext_ptr + esize;
3868 for (; ext_ptr < ext_end; ext_ptr += external_ext_size)
3873 struct bfd_link_hash_entry *h;
3875 (*swap_ext_in) (abfd, (PTR) ext_ptr, &esym);
3877 /* See if this symbol defines something. */
3878 if (esym.asym.st != stGlobal
3879 && esym.asym.st != stLabel
3880 && esym.asym.st != stProc)
3883 switch (esym.asym.sc)
3906 name = ssext + esym.asym.iss;
3907 h = bfd_link_hash_lookup (info->hash, name, false, false, true);
3909 /* Unlike the generic linker, we do not pull in elements because
3910 of common symbols. */
3911 if (h == (struct bfd_link_hash_entry *) NULL
3912 || h->type != bfd_link_hash_undefined)
3915 /* Include this element. */
3916 if (! (*info->callbacks->add_archive_element) (info, abfd, name))
3918 if (! ecoff_link_add_externals (abfd, info, external_ext, ssext))
3922 goto successful_return;
3926 if (external_ext != NULL)
3927 free (external_ext);
3932 if (external_ext != NULL)
3933 free (external_ext);
3939 /* Add symbols from an ECOFF object file to the global linker hash
3943 ecoff_link_add_object_symbols (abfd, info)
3945 struct bfd_link_info *info;
3948 bfd_size_type external_ext_size;
3949 PTR external_ext = NULL;
3954 if (! ecoff_slurp_symbolic_header (abfd))
3957 /* If there are no symbols, we don't want it. */
3958 if (bfd_get_symcount (abfd) == 0)
3961 symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
3963 /* Read in the external symbols and external strings. */
3964 external_ext_size = ecoff_backend (abfd)->debug_swap.external_ext_size;
3965 esize = symhdr->iextMax * external_ext_size;
3966 external_ext = (PTR) malloc (esize);
3967 if (external_ext == NULL && esize != 0)
3969 bfd_set_error (bfd_error_no_memory);
3973 if (bfd_seek (abfd, symhdr->cbExtOffset, SEEK_SET) != 0
3974 || bfd_read (external_ext, 1, esize, abfd) != esize)
3977 ssext = (char *) malloc (symhdr->issExtMax);
3978 if (ssext == NULL && symhdr->issExtMax != 0)
3980 bfd_set_error (bfd_error_no_memory);
3984 if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0
3985 || bfd_read (ssext, 1, symhdr->issExtMax, abfd) != symhdr->issExtMax)
3988 result = ecoff_link_add_externals (abfd, info, external_ext, ssext);
3992 if (external_ext != NULL)
3993 free (external_ext);
3999 if (external_ext != NULL)
4000 free (external_ext);
4004 /* Add the external symbols of an object file to the global linker
4005 hash table. The external symbols and strings we are passed are
4006 just allocated on the stack, and will be discarded. We must
4007 explicitly save any information we may need later on in the link.
4008 We do not want to read the external symbol information again. */
4011 ecoff_link_add_externals (abfd, info, external_ext, ssext)
4013 struct bfd_link_info *info;
4017 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
4018 void (* const swap_ext_in) PARAMS ((bfd *, PTR, EXTR *))
4019 = backend->debug_swap.swap_ext_in;
4020 bfd_size_type external_ext_size = backend->debug_swap.external_ext_size;
4021 unsigned long ext_count;
4022 struct ecoff_link_hash_entry **sym_hash;
4026 ext_count = ecoff_data (abfd)->debug_info.symbolic_header.iextMax;
4028 sym_hash = ((struct ecoff_link_hash_entry **)
4030 ext_count * sizeof (struct bfd_link_hash_entry *)));
4033 bfd_set_error (bfd_error_no_memory);
4036 ecoff_data (abfd)->sym_hashes = sym_hash;
4038 ext_ptr = (char *) external_ext;
4039 ext_end = ext_ptr + ext_count * external_ext_size;
4040 for (; ext_ptr < ext_end; ext_ptr += external_ext_size, sym_hash++)
4047 struct ecoff_link_hash_entry *h;
4051 (*swap_ext_in) (abfd, (PTR) ext_ptr, &esym);
4053 /* Skip debugging symbols. */
4055 switch (esym.asym.st)
4071 /* Get the information for this symbol. */
4072 value = esym.asym.value;
4073 switch (esym.asym.sc)
4093 section = bfd_make_section_old_way (abfd, ".text");
4094 value -= section->vma;
4097 section = bfd_make_section_old_way (abfd, ".data");
4098 value -= section->vma;
4101 section = bfd_make_section_old_way (abfd, ".bss");
4102 value -= section->vma;
4105 section = &bfd_abs_section;
4108 section = &bfd_und_section;
4111 section = bfd_make_section_old_way (abfd, ".sdata");
4112 value -= section->vma;
4115 section = bfd_make_section_old_way (abfd, ".sbss");
4116 value -= section->vma;
4119 section = bfd_make_section_old_way (abfd, ".rdata");
4120 value -= section->vma;
4123 if (value > ecoff_data (abfd)->gp_size)
4125 section = &bfd_com_section;
4130 if (ecoff_scom_section.name == NULL)
4132 /* Initialize the small common section. */
4133 ecoff_scom_section.name = SCOMMON;
4134 ecoff_scom_section.flags = SEC_IS_COMMON;
4135 ecoff_scom_section.output_section = &ecoff_scom_section;
4136 ecoff_scom_section.symbol = &ecoff_scom_symbol;
4137 ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
4138 ecoff_scom_symbol.name = SCOMMON;
4139 ecoff_scom_symbol.flags = BSF_SECTION_SYM;
4140 ecoff_scom_symbol.section = &ecoff_scom_section;
4141 ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
4143 section = &ecoff_scom_section;
4146 section = &bfd_und_section;
4149 section = bfd_make_section_old_way (abfd, ".init");
4150 value -= section->vma;
4153 section = bfd_make_section_old_way (abfd, ".fini");
4154 value -= section->vma;
4158 if (section == (asection *) NULL)
4161 name = ssext + esym.asym.iss;
4164 if (! (_bfd_generic_link_add_one_symbol
4165 (info, abfd, name, BSF_GLOBAL, section, value,
4166 (const char *) NULL, true, true,
4167 (struct bfd_link_hash_entry **) &h)))
4172 /* If we are building an ECOFF hash table, save the external
4173 symbol information. */
4174 if (info->hash->creator->flavour == bfd_get_flavour (abfd))
4176 if (h->abfd == (bfd *) NULL
4177 || (section != &bfd_und_section
4178 && (! bfd_is_com_section (section)
4179 || h->root.type != bfd_link_hash_defined)))
4185 /* Remember whether this symbol was small undefined. */
4186 if (esym.asym.sc == scSUndefined)
4189 /* If this symbol was ever small undefined, it needs to wind
4190 up in a GP relative section. We can't control the
4191 section of a defined symbol, but we can control the
4192 section of a common symbol. This case is actually needed
4193 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
4195 && h->root.type == bfd_link_hash_common
4196 && strcmp (h->root.u.c.section->name, SCOMMON) != 0)
4198 h->root.u.c.section = bfd_make_section_old_way (abfd, SCOMMON);
4199 h->root.u.c.section->flags = SEC_ALLOC;
4200 if (h->esym.asym.sc == scCommon)
4201 h->esym.asym.sc = scSCommon;
4209 /* ECOFF final link routines. */
4211 static boolean ecoff_final_link_debug_accumulate
4212 PARAMS ((bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *,
4214 static boolean ecoff_link_write_external
4215 PARAMS ((struct ecoff_link_hash_entry *, PTR));
4216 static boolean ecoff_indirect_link_order
4217 PARAMS ((bfd *, struct bfd_link_info *, asection *,
4218 struct bfd_link_order *));
4219 static boolean ecoff_reloc_link_order
4220 PARAMS ((bfd *, struct bfd_link_info *, asection *,
4221 struct bfd_link_order *));
4223 /* ECOFF final link routine. This looks through all the input BFDs
4224 and gathers together all the debugging information, and then
4225 processes all the link order information. This may cause it to
4226 close and reopen some input BFDs; I'll see how bad this is. */
4229 ecoff_bfd_final_link (abfd, info)
4231 struct bfd_link_info *info;
4233 const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
4234 struct ecoff_debug_info * const debug = &ecoff_data (abfd)->debug_info;
4237 register bfd *input_bfd;
4239 struct bfd_link_order *p;
4241 /* We accumulate the debugging information counts in the symbolic
4243 symhdr = &debug->symbolic_header;
4245 symhdr->ilineMax = 0;
4249 symhdr->isymMax = 0;
4250 symhdr->ioptMax = 0;
4251 symhdr->iauxMax = 0;
4253 symhdr->issExtMax = 0;
4256 symhdr->iextMax = 0;
4258 /* We accumulate the debugging information itself in the debug_info
4261 debug->external_dnr = NULL;
4262 debug->external_pdr = NULL;
4263 debug->external_sym = NULL;
4264 debug->external_opt = NULL;
4265 debug->external_aux = NULL;
4267 debug->ssext = debug->ssext_end = NULL;
4268 debug->external_fdr = NULL;
4269 debug->external_rfd = NULL;
4270 debug->external_ext = debug->external_ext_end = NULL;
4272 handle = bfd_ecoff_debug_init (abfd, debug, &backend->debug_swap, info);
4273 if (handle == (PTR) NULL)
4276 /* Accumulate the debugging symbols from each input BFD. */
4277 for (input_bfd = info->input_bfds;
4278 input_bfd != (bfd *) NULL;
4279 input_bfd = input_bfd->link_next)
4283 if (bfd_get_flavour (input_bfd) == bfd_target_ecoff_flavour)
4285 /* Abitrarily set the symbolic header vstamp to the vstamp
4286 of the first object file in the link. */
4287 if (symhdr->vstamp == 0)
4289 = ecoff_data (input_bfd)->debug_info.symbolic_header.vstamp;
4290 ret = ecoff_final_link_debug_accumulate (abfd, input_bfd, info,
4294 ret = bfd_ecoff_debug_accumulate_other (handle, abfd,
4295 debug, &backend->debug_swap,
4300 /* Combine the register masks. */
4301 ecoff_data (abfd)->gprmask |= ecoff_data (input_bfd)->gprmask;
4302 ecoff_data (abfd)->fprmask |= ecoff_data (input_bfd)->fprmask;
4303 ecoff_data (abfd)->cprmask[0] |= ecoff_data (input_bfd)->cprmask[0];
4304 ecoff_data (abfd)->cprmask[1] |= ecoff_data (input_bfd)->cprmask[1];
4305 ecoff_data (abfd)->cprmask[2] |= ecoff_data (input_bfd)->cprmask[2];
4306 ecoff_data (abfd)->cprmask[3] |= ecoff_data (input_bfd)->cprmask[3];
4309 /* Write out the external symbols. */
4310 ecoff_link_hash_traverse (ecoff_hash_table (info),
4311 ecoff_link_write_external,
4314 if (info->relocateable)
4316 /* We need to make a pass over the link_orders to count up the
4317 number of relocations we will need to output, so that we know
4318 how much space they will take up. */
4319 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
4322 for (p = o->link_order_head;
4323 p != (struct bfd_link_order *) NULL;
4325 if (p->type == bfd_indirect_link_order)
4326 o->reloc_count += p->u.indirect.section->reloc_count;
4327 else if (p->type == bfd_section_reloc_link_order
4328 || p->type == bfd_symbol_reloc_link_order)
4333 /* Compute the reloc and symbol file positions. */
4334 ecoff_compute_reloc_file_positions (abfd);
4336 /* Write out the debugging information. */
4337 if (! bfd_ecoff_write_accumulated_debug (handle, abfd, debug,
4338 &backend->debug_swap, info,
4339 ecoff_data (abfd)->sym_filepos))
4342 bfd_ecoff_debug_free (handle, abfd, debug, &backend->debug_swap, info);
4344 if (info->relocateable)
4346 /* Now reset the reloc_count field of the sections in the output
4347 BFD to 0, so that we can use them to keep track of how many
4348 relocs we have output thus far. */
4349 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
4353 /* Get a value for the GP register. */
4354 if (ecoff_data (abfd)->gp == 0)
4356 struct bfd_link_hash_entry *h;
4358 h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
4359 if (h != (struct bfd_link_hash_entry *) NULL
4360 && h->type == bfd_link_hash_defined)
4361 ecoff_data (abfd)->gp = (h->u.def.value
4362 + h->u.def.section->output_section->vma
4363 + h->u.def.section->output_offset);
4364 else if (info->relocateable)
4368 /* Make up a value. */
4370 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
4373 && (strcmp (o->name, _SBSS) == 0
4374 || strcmp (o->name, _SDATA) == 0
4375 || strcmp (o->name, _LIT4) == 0
4376 || strcmp (o->name, _LIT8) == 0
4377 || strcmp (o->name, _LITA) == 0))
4380 ecoff_data (abfd)->gp = lo + 0x8000;
4384 /* If the relocate_section function needs to do a reloc
4385 involving the GP value, it should make a reloc_dangerous
4386 callback to warn that GP is not defined. */
4390 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
4392 for (p = o->link_order_head;
4393 p != (struct bfd_link_order *) NULL;
4396 if (p->type == bfd_indirect_link_order
4397 && (bfd_get_flavour (p->u.indirect.section->owner)
4398 == bfd_target_ecoff_flavour))
4400 if (! ecoff_indirect_link_order (abfd, info, o, p))
4403 else if (p->type == bfd_section_reloc_link_order
4404 || p->type == bfd_symbol_reloc_link_order)
4406 if (! ecoff_reloc_link_order (abfd, info, o, p))
4411 if (! _bfd_default_link_order (abfd, info, o, p))
4417 bfd_get_symcount (abfd) = symhdr->iextMax + symhdr->isymMax;
4419 ecoff_data (abfd)->linker = true;
4424 /* Accumulate the debugging information for an input BFD into the
4425 output BFD. This must read in the symbolic information of the
4429 ecoff_final_link_debug_accumulate (output_bfd, input_bfd, info, handle)
4432 struct bfd_link_info *info;
4435 struct ecoff_debug_info * const debug = &ecoff_data (input_bfd)->debug_info;
4436 const struct ecoff_debug_swap * const swap =
4437 &ecoff_backend (input_bfd)->debug_swap;
4438 HDRR *symhdr = &debug->symbolic_header;
4441 #define READ(ptr, offset, count, size, type) \
4442 if (symhdr->count == 0) \
4443 debug->ptr = NULL; \
4446 debug->ptr = (type) malloc (size * symhdr->count); \
4447 if (debug->ptr == NULL) \
4449 bfd_set_error (bfd_error_no_memory); \
4451 goto return_something; \
4453 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4455 || (bfd_read (debug->ptr, size, symhdr->count, \
4456 input_bfd) != size * symhdr->count)) \
4459 goto return_something; \
4463 /* If raw_syments is not NULL, then the data was already by read by
4464 ecoff_slurp_symbolic_info. */
4465 if (ecoff_data (input_bfd)->raw_syments == NULL)
4467 READ (line, cbLineOffset, cbLine, sizeof (unsigned char),
4469 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
4470 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
4471 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
4472 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
4473 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
4475 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
4476 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
4477 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
4481 /* We do not read the external strings or the external symbols. */
4483 ret = (bfd_ecoff_debug_accumulate
4484 (handle, output_bfd, &ecoff_data (output_bfd)->debug_info,
4485 &ecoff_backend (output_bfd)->debug_swap,
4486 input_bfd, debug, swap, info));
4489 if (ecoff_data (input_bfd)->raw_syments == NULL)
4491 if (debug->line != NULL)
4493 if (debug->external_dnr != NULL)
4494 free (debug->external_dnr);
4495 if (debug->external_pdr != NULL)
4496 free (debug->external_pdr);
4497 if (debug->external_sym != NULL)
4498 free (debug->external_sym);
4499 if (debug->external_opt != NULL)
4500 free (debug->external_opt);
4501 if (debug->external_aux != NULL)
4502 free (debug->external_aux);
4503 if (debug->ss != NULL)
4505 if (debug->external_fdr != NULL)
4506 free (debug->external_fdr);
4507 if (debug->external_rfd != NULL)
4508 free (debug->external_rfd);
4510 /* Make sure we don't accidentally follow one of these pointers
4511 into freed memory. */
4513 debug->external_dnr = NULL;
4514 debug->external_pdr = NULL;
4515 debug->external_sym = NULL;
4516 debug->external_opt = NULL;
4517 debug->external_aux = NULL;
4519 debug->external_fdr = NULL;
4520 debug->external_rfd = NULL;
4526 /* Put out information for an external symbol. These come only from
4530 ecoff_link_write_external (h, data)
4531 struct ecoff_link_hash_entry *h;
4534 bfd *output_bfd = (bfd *) data;
4536 /* FIXME: We should check if this symbol is being stripped. */
4541 if (h->abfd == (bfd *) NULL)
4544 h->esym.cobol_main = 0;
4545 h->esym.weakext = 0;
4546 h->esym.reserved = 0;
4547 h->esym.ifd = ifdNil;
4548 h->esym.asym.value = 0;
4549 h->esym.asym.st = stGlobal;
4551 if (h->root.type != bfd_link_hash_defined)
4552 h->esym.asym.sc = scAbs;
4555 asection *output_section;
4558 output_section = h->root.u.def.section->output_section;
4559 name = bfd_section_name (output_section->owner, output_section);
4561 if (strcmp (name, _TEXT) == 0)
4562 h->esym.asym.sc = scText;
4563 else if (strcmp (name, _DATA) == 0)
4564 h->esym.asym.sc = scData;
4565 else if (strcmp (name, _SDATA) == 0)
4566 h->esym.asym.sc = scSData;
4567 else if (strcmp (name, _RDATA) == 0)
4568 h->esym.asym.sc = scRData;
4569 else if (strcmp (name, _BSS) == 0)
4570 h->esym.asym.sc = scBss;
4571 else if (strcmp (name, _SBSS) == 0)
4572 h->esym.asym.sc = scSBss;
4573 else if (strcmp (name, _INIT) == 0)
4574 h->esym.asym.sc = scInit;
4575 else if (strcmp (name, _FINI) == 0)
4576 h->esym.asym.sc = scFini;
4577 else if (strcmp (name, _PDATA) == 0)
4578 h->esym.asym.sc = scPData;
4579 else if (strcmp (name, _XDATA) == 0)
4580 h->esym.asym.sc = scXData;
4582 h->esym.asym.sc = scAbs;
4585 h->esym.asym.reserved = 0;
4586 h->esym.asym.index = indexNil;
4588 else if (h->esym.ifd != -1)
4590 struct ecoff_debug_info *debug;
4592 /* Adjust the FDR index for the symbol by that used for the
4594 debug = &ecoff_data (h->abfd)->debug_info;
4595 BFD_ASSERT (h->esym.ifd >= 0
4596 && h->esym.ifd < debug->symbolic_header.ifdMax);
4597 h->esym.ifd = debug->ifdmap[h->esym.ifd];
4600 switch (h->root.type)
4603 case bfd_link_hash_new:
4605 case bfd_link_hash_undefined:
4606 case bfd_link_hash_weak:
4607 if (h->esym.asym.sc != scUndefined
4608 && h->esym.asym.sc != scSUndefined)
4609 h->esym.asym.sc = scUndefined;
4611 case bfd_link_hash_defined:
4612 if (h->esym.asym.sc == scUndefined
4613 || h->esym.asym.sc == scSUndefined)
4614 h->esym.asym.sc = scAbs;
4615 else if (h->esym.asym.sc == scCommon)
4616 h->esym.asym.sc = scBss;
4617 else if (h->esym.asym.sc == scSCommon)
4618 h->esym.asym.sc = scSBss;
4619 h->esym.asym.value = (h->root.u.def.value
4620 + h->root.u.def.section->output_section->vma
4621 + h->root.u.def.section->output_offset);
4623 case bfd_link_hash_common:
4624 if (h->esym.asym.sc != scCommon
4625 && h->esym.asym.sc != scSCommon)
4626 h->esym.asym.sc = scCommon;
4627 h->esym.asym.value = h->root.u.c.size;
4629 case bfd_link_hash_indirect:
4630 case bfd_link_hash_warning:
4631 /* FIXME: Ignore these for now. The circumstances under which
4632 they should be written out are not clear to me. */
4636 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4638 h->indx = ecoff_data (output_bfd)->debug_info.symbolic_header.iextMax;
4641 return (bfd_ecoff_debug_one_external
4642 (output_bfd, &ecoff_data (output_bfd)->debug_info,
4643 &ecoff_backend (output_bfd)->debug_swap, h->root.root.string,
4647 /* Relocate and write an ECOFF section into an ECOFF output file. */
4650 ecoff_indirect_link_order (output_bfd, info, output_section, link_order)
4652 struct bfd_link_info *info;
4653 asection *output_section;
4654 struct bfd_link_order *link_order;
4656 asection *input_section;
4658 struct ecoff_section_tdata *section_tdata;
4659 bfd_size_type raw_size;
4660 bfd_size_type cooked_size;
4661 bfd_byte *contents = NULL;
4662 bfd_size_type external_reloc_size;
4663 bfd_size_type external_relocs_size;
4664 PTR external_relocs = NULL;
4666 BFD_ASSERT ((output_section->flags & SEC_HAS_CONTENTS) != 0);
4668 if (link_order->size == 0)
4671 input_section = link_order->u.indirect.section;
4672 input_bfd = input_section->owner;
4673 section_tdata = ecoff_section_data (input_bfd, input_section);
4675 raw_size = input_section->_raw_size;
4676 cooked_size = input_section->_cooked_size;
4677 if (cooked_size == 0)
4678 cooked_size = raw_size;
4680 BFD_ASSERT (input_section->output_section == output_section);
4681 BFD_ASSERT (input_section->output_offset == link_order->offset);
4682 BFD_ASSERT (cooked_size == link_order->size);
4684 /* Get the section contents. We allocate memory for the larger of
4685 the size before relocating and the size after relocating. */
4686 contents = (bfd_byte *) malloc (raw_size >= cooked_size
4689 if (contents == NULL && raw_size != 0)
4691 bfd_set_error (bfd_error_no_memory);
4695 /* If we are relaxing, the contents may have already been read into
4696 memory, in which case we copy them into our new buffer. We don't
4697 simply reuse the old buffer in case cooked_size > raw_size. */
4698 if (section_tdata != (struct ecoff_section_tdata *) NULL
4699 && section_tdata->contents != (bfd_byte *) NULL)
4700 memcpy (contents, section_tdata->contents, raw_size);
4703 if (! bfd_get_section_contents (input_bfd, input_section,
4705 (file_ptr) 0, raw_size))
4709 /* Get the relocs. If we are relaxing MIPS code, they will already
4710 have been read in. Otherwise, we read them in now. */
4711 external_reloc_size = ecoff_backend (input_bfd)->external_reloc_size;
4712 external_relocs_size = external_reloc_size * input_section->reloc_count;
4714 if (section_tdata != (struct ecoff_section_tdata *) NULL)
4715 external_relocs = section_tdata->external_relocs;
4718 external_relocs = (PTR) malloc (external_relocs_size);
4719 if (external_relocs == NULL && external_relocs_size != 0)
4721 bfd_set_error (bfd_error_no_memory);
4725 if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
4726 || (bfd_read (external_relocs, 1, external_relocs_size, input_bfd)
4727 != external_relocs_size))
4731 /* Relocate the section contents. */
4732 if (! ((*ecoff_backend (input_bfd)->relocate_section)
4733 (output_bfd, info, input_bfd, input_section, contents,
4737 /* Write out the relocated section. */
4738 if (! bfd_set_section_contents (output_bfd,
4741 input_section->output_offset,
4745 /* If we are producing relocateable output, the relocs were
4746 modified, and we write them out now. We use the reloc_count
4747 field of output_section to keep track of the number of relocs we
4748 have output so far. */
4749 if (info->relocateable)
4751 if (bfd_seek (output_bfd,
4752 (output_section->rel_filepos +
4753 output_section->reloc_count * external_reloc_size),
4755 || (bfd_write (external_relocs, 1, external_relocs_size, output_bfd)
4756 != external_relocs_size))
4758 output_section->reloc_count += input_section->reloc_count;
4761 if (contents != NULL)
4763 if (external_relocs != NULL && section_tdata == NULL)
4764 free (external_relocs);
4768 if (contents != NULL)
4770 if (external_relocs != NULL && section_tdata == NULL)
4771 free (external_relocs);
4775 /* Generate a reloc when linking an ECOFF file. This is a reloc
4776 requested by the linker, and does come from any input file. This
4777 is used to build constructor and destructor tables when linking
4781 ecoff_reloc_link_order (output_bfd, info, output_section, link_order)
4783 struct bfd_link_info *info;
4784 asection *output_section;
4785 struct bfd_link_order *link_order;
4788 struct internal_reloc in;
4789 bfd_size_type external_reloc_size;
4793 /* We set up an arelent to pass to the backend adjust_reloc_out
4795 rel.address = link_order->offset;
4797 rel.howto = bfd_reloc_type_lookup (output_bfd, link_order->u.reloc.p->reloc);
4798 if (rel.howto == (const reloc_howto_type *) NULL)
4800 bfd_set_error (bfd_error_bad_value);
4804 if (link_order->type == bfd_section_reloc_link_order)
4805 rel.sym_ptr_ptr = link_order->u.reloc.p->u.section->symbol_ptr_ptr;
4808 /* We can't set up a reloc against a symbol correctly, because
4809 we have no asymbol structure. Currently no adjust_reloc_out
4811 rel.sym_ptr_ptr = (asymbol **) NULL;
4814 /* All ECOFF relocs are in-place. Put the addend into the object
4817 BFD_ASSERT (rel.howto->partial_inplace);
4818 if (link_order->u.reloc.p->addend != 0)
4821 bfd_reloc_status_type rstat;
4825 size = bfd_get_reloc_size (rel.howto);
4826 buf = (bfd_byte *) bfd_zmalloc (size);
4827 if (buf == (bfd_byte *) NULL)
4829 bfd_set_error (bfd_error_no_memory);
4832 rstat = _bfd_relocate_contents (rel.howto, output_bfd,
4833 link_order->u.reloc.p->addend, buf);
4839 case bfd_reloc_outofrange:
4841 case bfd_reloc_overflow:
4842 if (! ((*info->callbacks->reloc_overflow)
4844 (link_order->type == bfd_section_reloc_link_order
4845 ? bfd_section_name (output_bfd,
4846 link_order->u.reloc.p->u.section)
4847 : link_order->u.reloc.p->u.name),
4848 rel.howto->name, link_order->u.reloc.p->addend,
4849 (bfd *) NULL, (asection *) NULL, (bfd_vma) 0)))
4856 ok = bfd_set_section_contents (output_bfd, output_section, (PTR) buf,
4857 (file_ptr) link_order->offset, size);
4865 /* Move the information into a internal_reloc structure. */
4866 in.r_vaddr = (rel.address
4867 + bfd_get_section_vma (output_bfd, output_section));
4868 in.r_type = rel.howto->type;
4870 if (link_order->type == bfd_symbol_reloc_link_order)
4872 struct ecoff_link_hash_entry *h;
4874 h = ecoff_link_hash_lookup (ecoff_hash_table (info),
4875 link_order->u.reloc.p->u.name,
4876 false, false, true);
4877 if (h != (struct ecoff_link_hash_entry *) NULL
4879 in.r_symndx = h->indx;
4882 if (! ((*info->callbacks->unattached_reloc)
4883 (info, link_order->u.reloc.p->u.name, (bfd *) NULL,
4884 (asection *) NULL, (bfd_vma) 0)))
4894 name = bfd_get_section_name (output_bfd,
4895 link_order->u.reloc.p->u.section);
4896 if (strcmp (name, ".text") == 0)
4897 in.r_symndx = RELOC_SECTION_TEXT;
4898 else if (strcmp (name, ".rdata") == 0)
4899 in.r_symndx = RELOC_SECTION_RDATA;
4900 else if (strcmp (name, ".data") == 0)
4901 in.r_symndx = RELOC_SECTION_DATA;
4902 else if (strcmp (name, ".sdata") == 0)
4903 in.r_symndx = RELOC_SECTION_SDATA;
4904 else if (strcmp (name, ".sbss") == 0)
4905 in.r_symndx = RELOC_SECTION_SBSS;
4906 else if (strcmp (name, ".bss") == 0)
4907 in.r_symndx = RELOC_SECTION_BSS;
4908 else if (strcmp (name, ".init") == 0)
4909 in.r_symndx = RELOC_SECTION_INIT;
4910 else if (strcmp (name, ".lit8") == 0)
4911 in.r_symndx = RELOC_SECTION_LIT8;
4912 else if (strcmp (name, ".lit4") == 0)
4913 in.r_symndx = RELOC_SECTION_LIT4;
4914 else if (strcmp (name, ".xdata") == 0)
4915 in.r_symndx = RELOC_SECTION_XDATA;
4916 else if (strcmp (name, ".pdata") == 0)
4917 in.r_symndx = RELOC_SECTION_PDATA;
4918 else if (strcmp (name, ".fini") == 0)
4919 in.r_symndx = RELOC_SECTION_FINI;
4920 else if (strcmp (name, ".lita") == 0)
4921 in.r_symndx = RELOC_SECTION_LITA;
4922 else if (strcmp (name, "*ABS*") == 0)
4923 in.r_symndx = RELOC_SECTION_ABS;
4929 /* Let the BFD backend adjust the reloc. */
4930 (*ecoff_backend (output_bfd)->adjust_reloc_out) (output_bfd, &rel, &in);
4932 /* Get some memory and swap out the reloc. */
4933 external_reloc_size = ecoff_backend (output_bfd)->external_reloc_size;
4934 rbuf = (bfd_byte *) malloc (external_reloc_size);
4935 if (rbuf == (bfd_byte *) NULL)
4937 bfd_set_error (bfd_error_no_memory);
4941 (*ecoff_backend (output_bfd)->swap_reloc_out) (output_bfd, &in, (PTR) rbuf);
4943 ok = (bfd_seek (output_bfd,
4944 (output_section->rel_filepos +
4945 output_section->reloc_count * external_reloc_size),
4947 && (bfd_write ((PTR) rbuf, 1, external_reloc_size, output_bfd)
4948 == external_reloc_size));
4951 ++output_section->reloc_count;