1 /* BFD back-end for MIPS Extended-Coff files.
2 Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support 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"
28 #include "coff/mips.h"
29 #include "coff/internal.h"
31 #include "coff/symconst.h"
32 #include "coff/ecoff-ext.h"
35 /* `Tdata' information kept for ECOFF files. */
37 #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data)
39 typedef struct ecoff_tdata
41 /* The reloc file position, set by
42 ecoff_compute_section_file_positions. */
43 file_ptr reloc_filepos
;
45 /* The symbol table file position, set by ecoff_mkobject_hook. */
48 /* The cached gp value. This is used when relocating. */
51 /* The register masks. When linking, all the masks found in the
52 input files are combined into the masks of the output file. */
53 unsigned long gprmask
;
54 unsigned long cprmask
[4];
56 /* The size of the unswapped ECOFF symbolic information. */
57 bfd_size_type raw_size
;
59 /* The unswapped ECOFF symbolic information. */
62 /* The swapped ECOFF symbolic header. */
65 /* Pointers to the unswapped symbolic information. */
67 struct dnr_ext
*external_dnr
;
68 struct pdr_ext
*external_pdr
;
69 struct sym_ext
*external_sym
;
70 struct opt_ext
*external_opt
;
71 union aux_ext
*external_aux
;
74 struct fdr_ext
*external_fdr
;
75 struct rfd_ext
*external_rfd
;
76 struct ext_ext
*external_ext
;
78 /* The swapped FDR information. */
81 /* The FDR index. This is set for an input BFD to a link so that
82 the external symbols can set their FDR index correctly. */
85 /* The canonical BFD symbols. */
86 struct ecoff_symbol_struct
*canonical_symbols
;
90 /* Each canonical asymbol really looks like this. */
92 typedef struct ecoff_symbol_struct
94 /* The actual symbol which the rest of BFD works with */
97 /* The fdr for this symbol. */
100 /* true if this is a local symbol rather than an external one. */
103 /* A pointer to the unswapped hidden information for this symbol */
106 struct sym_ext
*lnative
;
107 struct ext_ext
*enative
;
112 /* We take the address of the first element of a asymbol to ensure that the
113 macro is only ever applied to an asymbol. */
114 #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd)))
116 /* This is a hack borrowed from coffcode.h; we need to save the index
117 of a symbol when we write it out so that can set the symbol index
118 correctly when we write out the relocs. */
119 #define ecoff_get_sym_index(symbol) ((unsigned long) (symbol)->udata)
120 #define ecoff_set_sym_index(symbol, idx) ((symbol)->udata = (PTR) (idx))
122 /* The page boundary used to align sections in the executable file. */
123 #define PAGE_SIZE 0x2000
125 /* MIPS ECOFF has COFF sections, but the debugging information is
126 stored in a completely different format. This files uses the some
127 of the swapping routines from coffswap.h, and some of the generic
128 COFF routines in coffgen.c, but, unlike the real COFF targets, does
129 not use coffcode.h itself. */
131 /* Get the generic COFF swapping routines, except for the reloc,
132 symbol, and lineno ones. Give them ecoff names. */
134 #define NO_COFF_RELOCS
135 #define NO_COFF_SYMBOLS
136 #define NO_COFF_LINENOS
137 #define coff_swap_filehdr_in ecoff_swap_filehdr_in
138 #define coff_swap_filehdr_out ecoff_swap_filehdr_out
139 #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in
140 #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out
141 #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in
142 #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out
143 #include "coffswap.h"
145 /* This stuff is somewhat copied from coffcode.h. */
147 static asection bfd_debug_section
= { "*DEBUG*" };
149 /* See whether the magic number matches. */
152 DEFUN(ecoff_bad_format_hook
, (abfd
, filehdr
),
156 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
158 if (ECOFFBADMAG (*internal_f
))
164 /* This is a hook needed by SCO COFF, but we have nothing to do. */
167 DEFUN (ecoff_make_section_hook
, (abfd
, name
),
171 return (asection
*) NULL
;
174 /* Initialize a new section. */
177 DEFUN (ecoff_new_section_hook
, (abfd
, section
),
181 section
->alignment_power
= abfd
->xvec
->align_power_min
;
183 if (strcmp (section
->name
, _TEXT
) == 0)
184 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
185 else if (strcmp (section
->name
, _DATA
) == 0
186 || strcmp (section
->name
, _SDATA
) == 0)
187 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
188 else if (strcmp (section
->name
, _RDATA
) == 0
189 || strcmp (section
->name
, _LIT8
) == 0
190 || strcmp (section
->name
, _LIT4
) == 0)
191 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
192 else if (strcmp (section
->name
, _BSS
) == 0
193 || strcmp (section
->name
, _SBSS
) == 0)
194 section
->flags
|= SEC_ALLOC
;
196 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
197 uncertain about .init on some systems and I don't know how shared
203 #define ecoff_set_alignment_hook \
204 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
207 DEFUN (ecoff_mkobject
, (abfd
),
210 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
211 bfd_zalloc (abfd
, sizeof(ecoff_data_type
)));
212 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
214 bfd_error
= no_memory
;
221 /* Create the COFF backend specific information. */
224 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
229 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
230 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
231 ecoff_data_type
*ecoff
;
233 if (ecoff_mkobject (abfd
) == false)
236 ecoff
= ecoff_data (abfd
);
237 ecoff
->sym_filepos
= internal_f
->f_symptr
;
239 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
243 ecoff
->gp
= internal_a
->gp_value
;
244 ecoff
->gprmask
= internal_a
->gprmask
;
245 for (i
= 0; i
< 3; i
++)
246 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
252 /* Determine the machine architecture and type. */
254 DEFUN (ecoff_set_arch_mach_hook
, (abfd
, filehdr
),
259 enum bfd_architecture arch
;
260 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
263 switch (internal_f
->f_magic
) {
267 arch
= bfd_arch_mips
;
271 default: /* Unreadable input file type */
272 arch
= bfd_arch_obscure
;
276 bfd_default_set_arch_mach(abfd
, arch
, machine
);
280 /* Get the section s_flags to use for a section. */
283 DEFUN (sec_to_styp_flags
, (name
, flags
),
291 if (strcmp (name
, _TEXT
) == 0)
293 else if (strcmp (name
, _DATA
) == 0)
295 else if (strcmp (name
, _SDATA
) == 0)
297 else if (strcmp (name
, _RDATA
) == 0)
299 else if (strcmp (name
, _LIT8
) == 0)
301 else if (strcmp (name
, _LIT4
) == 0)
303 else if (strcmp (name
, _BSS
) == 0)
305 else if (strcmp (name
, _SBSS
) == 0)
307 else if (flags
& SEC_CODE
)
309 else if (flags
& SEC_DATA
)
311 else if (flags
& SEC_READONLY
)
313 else if (flags
& SEC_LOAD
)
318 if (flags
& SEC_NEVER_LOAD
)
324 /* Get the BFD flags to use for a section. */
327 DEFUN (styp_to_sec_flags
, (abfd
, hdr
),
331 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
332 long styp_flags
= internal_s
->s_flags
;
333 flagword sec_flags
=0;
335 if (styp_flags
& STYP_NOLOAD
)
336 sec_flags
|= SEC_NEVER_LOAD
;
338 /* For 386 COFF, at least, an unloadable text or data section is
339 actually a shared library section. */
340 if (styp_flags
& STYP_TEXT
)
342 if (sec_flags
& SEC_NEVER_LOAD
)
343 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
345 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
347 else if ((styp_flags
& STYP_DATA
)
348 || (styp_flags
& STYP_RDATA
)
349 || (styp_flags
& STYP_SDATA
))
351 if (sec_flags
& SEC_NEVER_LOAD
)
352 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
354 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
355 if (styp_flags
& STYP_RDATA
)
356 sec_flags
|= SEC_READONLY
;
358 else if ((styp_flags
& STYP_BSS
)
359 || (styp_flags
& STYP_SBSS
))
361 sec_flags
|= SEC_ALLOC
;
363 else if (styp_flags
& STYP_INFO
)
365 sec_flags
|= SEC_NEVER_LOAD
;
367 else if ((styp_flags
& STYP_LIT8
)
368 || (styp_flags
& STYP_LIT4
))
370 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
374 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
380 /* Read in and swap the important symbolic information for an ECOFF
384 DEFUN (ecoff_slurp_symbolic_info
, (abfd
),
387 struct hdr_ext external_symhdr
;
388 HDRR
*internal_symhdr
;
389 bfd_size_type raw_base
;
390 bfd_size_type raw_size
;
392 struct fdr_ext
*fraw_src
;
393 struct fdr_ext
*fraw_end
;
396 /* Check whether we've already gotten it, and whether there's any to
398 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
400 if (ecoff_data (abfd
)->sym_filepos
== 0)
402 bfd_get_symcount (abfd
) = 0;
406 /* At this point bfd_get_symcount (abfd) holds the number of symbols
407 as read from the file header, but on ECOFF this is always the
408 size of the symbolic information header. It would be cleaner to
409 handle this when we first read the file in coffgen.c. */
410 if (bfd_get_symcount (abfd
) != sizeof (external_symhdr
))
412 bfd_error
= bad_value
;
416 /* Read the symbolic information header. */
417 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
418 || (bfd_read ((PTR
) &external_symhdr
, sizeof (external_symhdr
), 1, abfd
)
419 != sizeof (external_symhdr
)))
421 bfd_error
= system_call_error
;
424 internal_symhdr
= &ecoff_data (abfd
)->symbolic_header
;
425 ecoff_swap_hdr_in (abfd
, &external_symhdr
, internal_symhdr
);
427 if (internal_symhdr
->magic
!= magicSym
)
429 bfd_error
= bad_value
;
433 /* Now we can get the correct number of symbols. */
434 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
435 + internal_symhdr
->iextMax
);
437 /* Read all the symbolic information at once. */
438 raw_base
= ecoff_data (abfd
)->sym_filepos
+ sizeof (struct hdr_ext
);
440 if (internal_symhdr
->cbExtOffset
!= 0)
441 raw_size
= (internal_symhdr
->cbExtOffset
443 + internal_symhdr
->iextMax
* sizeof (struct ext_ext
));
446 long cbline
, issmax
, issextmax
;
448 cbline
= (internal_symhdr
->cbLine
+ 3) &~ 4;
449 issmax
= (internal_symhdr
->issMax
+ 3) &~ 4;
450 issextmax
= (internal_symhdr
->issExtMax
+ 3) &~ 4;
451 raw_size
= (cbline
* sizeof (unsigned char)
452 + internal_symhdr
->idnMax
* sizeof (struct dnr_ext
)
453 + internal_symhdr
->ipdMax
* sizeof (struct pdr_ext
)
454 + internal_symhdr
->isymMax
* sizeof (struct sym_ext
)
455 + internal_symhdr
->ioptMax
* sizeof (struct opt_ext
)
456 + internal_symhdr
->iauxMax
* sizeof (union aux_ext
)
457 + issmax
* sizeof (char)
458 + issextmax
* sizeof (char)
459 + internal_symhdr
->ifdMax
* sizeof (struct fdr_ext
)
460 + internal_symhdr
->crfd
* sizeof (struct rfd_ext
)
461 + internal_symhdr
->iextMax
* sizeof (struct ext_ext
));
466 ecoff_data (abfd
)->sym_filepos
= 0;
469 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
472 bfd_error
= no_memory
;
475 if (bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
477 bfd_error
= system_call_error
;
478 bfd_release (abfd
, raw
);
482 ecoff_data (abfd
)->raw_size
= raw_size
;
483 ecoff_data (abfd
)->raw_syments
= raw
;
485 /* Get pointers for the numeric offsets in the HDRR structure. */
486 #define FIX(off1, off2, type) \
487 if (internal_symhdr->off1 == 0) \
488 ecoff_data (abfd)->off2 = (type *) NULL; \
490 ecoff_data (abfd)->off2 = (type *) ((char *) raw \
491 + internal_symhdr->off1 \
493 FIX (cbLineOffset
, line
, unsigned char);
494 FIX (cbDnOffset
, external_dnr
, struct dnr_ext
);
495 FIX (cbPdOffset
, external_pdr
, struct pdr_ext
);
496 FIX (cbSymOffset
, external_sym
, struct sym_ext
);
497 FIX (cbOptOffset
, external_opt
, struct opt_ext
);
498 FIX (cbAuxOffset
, external_aux
, union aux_ext
);
499 FIX (cbSsOffset
, ss
, char);
500 FIX (cbSsExtOffset
, ssext
, char);
501 FIX (cbFdOffset
, external_fdr
, struct fdr_ext
);
502 FIX (cbRfdOffset
, external_rfd
, struct rfd_ext
);
503 FIX (cbExtOffset
, external_ext
, struct ext_ext
);
506 /* I don't want to always swap all the data, because it will just
507 waste time and most programs will never look at it. The only
508 time the linker needs most of the debugging information swapped
509 is when linking big-endian and little-endian MIPS object files
510 together, which is not a common occurrence.
512 We need to look at the fdr to deal with a lot of information in
513 the symbols, so we swap them here. */
514 ecoff_data (abfd
)->fdr
= (struct fdr
*) bfd_alloc (abfd
,
515 (internal_symhdr
->ifdMax
*
516 sizeof (struct fdr
)));
517 if (ecoff_data (abfd
)->fdr
== NULL
)
519 bfd_error
= no_memory
;
522 fdr_ptr
= ecoff_data (abfd
)->fdr
;
523 fraw_src
= ecoff_data (abfd
)->external_fdr
;
524 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
;
525 for (; fraw_src
< fraw_end
; fraw_src
++, fdr_ptr
++)
526 ecoff_swap_fdr_in (abfd
, fraw_src
, fdr_ptr
);
531 /* ECOFF symbol table routines. The ECOFF symbol table is described
532 in gcc/mips-tfile.c. */
534 /* ECOFF uses two common sections. One is the usual one, and the
535 other is for small objects. All the small objects are kept
536 together, and then referenced via the gp pointer, which yields
537 faster assembler code. This is what we use for the small common
539 static asection ecoff_scom_section
;
540 static asymbol ecoff_scom_symbol
;
541 static asymbol
*ecoff_scom_symbol_ptr
;
543 /* Create an empty symbol. */
546 DEFUN (ecoff_make_empty_symbol
, (abfd
),
549 ecoff_symbol_type
*new;
551 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
552 if (new == (ecoff_symbol_type
*) NULL
)
554 bfd_error
= no_memory
;
555 return (asymbol
*) NULL
;
557 new->symbol
.section
= (asection
*) NULL
;
558 new->fdr
= (FDR
*) NULL
;
560 new->native
.lnative
= (struct sym_ext
*) NULL
;
561 new->symbol
.the_bfd
= abfd
;
565 /* Set the BFD flags and section for an ECOFF symbol. */
568 DEFUN (ecoff_set_symbol_info
, (abfd
, ecoff_sym
, asym
, ext
),
574 asym
->the_bfd
= abfd
;
575 asym
->value
= ecoff_sym
->value
;
576 asym
->section
= &bfd_debug_section
;
579 /* Most symbol types are just for debugging. */
580 switch (ecoff_sym
->st
)
591 asym
->flags
= BSF_DEBUGGING
;
596 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
598 asym
->flags
= BSF_LOCAL
;
599 switch (ecoff_sym
->sc
)
602 /* Used for compiler generated labels. Leave them in the
603 debugging section, and mark them as local. If BSF_DEBUGGING
604 is set, then nm does not display them for some reason. If no
605 flags are set then the linker whines about them. */
606 asym
->flags
= BSF_LOCAL
;
609 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
610 asym
->value
-= asym
->section
->vma
;
613 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
614 asym
->value
-= asym
->section
->vma
;
619 asym
->section
= &bfd_com_section
;
624 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
625 asym
->value
-= asym
->section
->vma
;
629 asym
->flags
= BSF_DEBUGGING
;
632 asym
->section
= &bfd_abs_section
;
635 asym
->section
= &bfd_und_section
;
645 asym
->flags
= BSF_DEBUGGING
;
648 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
649 asym
->value
-= asym
->section
->vma
;
652 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
654 asym
->value
-= asym
->section
->vma
;
657 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
658 asym
->value
-= asym
->section
->vma
;
661 asym
->flags
= BSF_DEBUGGING
;
664 asym
->section
= &bfd_com_section
;
667 if (ecoff_scom_section
.name
== NULL
)
669 /* Initialize the small common section. */
670 ecoff_scom_section
.name
= "*SCOM*";
671 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
672 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
673 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
674 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
675 ecoff_scom_symbol
.name
= "*SCOM*";
676 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
677 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
678 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
680 asym
->section
= &ecoff_scom_section
;
685 asym
->flags
= BSF_DEBUGGING
;
688 asym
->section
= &bfd_und_section
;
693 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
694 asym
->value
-= asym
->section
->vma
;
699 asym
->flags
= BSF_DEBUGGING
;
702 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
703 asym
->value
-= asym
->section
->vma
;
710 /* Read an ECOFF symbol table. */
713 DEFUN (ecoff_slurp_symbol_table
, (abfd
),
716 bfd_size_type internal_size
;
717 ecoff_symbol_type
*internal
;
718 ecoff_symbol_type
*internal_ptr
;
719 struct ext_ext
*eraw_src
;
720 struct ext_ext
*eraw_end
;
724 /* If we've already read in the symbol table, do nothing. */
725 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
728 /* Get the symbolic information. */
729 if (ecoff_slurp_symbolic_info (abfd
) == false)
731 if (bfd_get_symcount (abfd
) == 0)
734 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
735 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
736 if (internal
== NULL
)
738 bfd_error
= no_memory
;
742 internal_ptr
= internal
;
743 eraw_src
= ecoff_data (abfd
)->external_ext
;
744 eraw_end
= eraw_src
+ ecoff_data (abfd
)->symbolic_header
.iextMax
;
745 for (; eraw_src
< eraw_end
; eraw_src
++, internal_ptr
++)
749 ecoff_swap_ext_in (abfd
, eraw_src
, &internal_esym
);
750 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ssext
751 + internal_esym
.asym
.iss
);
752 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
753 &internal_ptr
->symbol
, 1);
754 internal_ptr
->fdr
= ecoff_data (abfd
)->fdr
+ internal_esym
.ifd
;
755 internal_ptr
->local
= false;
756 internal_ptr
->native
.enative
= eraw_src
;
759 /* The local symbols must be accessed via the fdr's, because the
760 string and aux indices are relative to the fdr information. */
761 fdr_ptr
= ecoff_data (abfd
)->fdr
;
762 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
763 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
765 struct sym_ext
*lraw_src
;
766 struct sym_ext
*lraw_end
;
768 lraw_src
= ecoff_data (abfd
)->external_sym
+ fdr_ptr
->isymBase
;
769 lraw_end
= lraw_src
+ fdr_ptr
->csym
;
770 for (; lraw_src
< lraw_end
; lraw_src
++, internal_ptr
++)
774 ecoff_swap_sym_in (abfd
, lraw_src
, &internal_sym
);
775 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ss
778 ecoff_set_symbol_info (abfd
, &internal_sym
,
779 &internal_ptr
->symbol
, 0);
780 internal_ptr
->fdr
= fdr_ptr
;
781 internal_ptr
->local
= true;
782 internal_ptr
->native
.lnative
= lraw_src
;
786 ecoff_data (abfd
)->canonical_symbols
= internal
;
792 DEFUN (ecoff_get_symtab_upper_bound
, (abfd
),
795 if (ecoff_slurp_symbolic_info (abfd
) == false
796 || bfd_get_symcount (abfd
) == 0)
799 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
803 DEFUN (ecoff_get_symtab
, (abfd
, alocation
),
807 unsigned int counter
= 0;
808 ecoff_symbol_type
*symbase
;
809 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
811 if (ecoff_slurp_symbol_table (abfd
) == false
812 || bfd_get_symcount (abfd
) == 0)
815 symbase
= ecoff_data (abfd
)->canonical_symbols
;
816 while (counter
< bfd_get_symcount (abfd
))
818 *(location
++) = symbase
++;
821 *location
++ = (ecoff_symbol_type
*) NULL
;
822 return bfd_get_symcount (abfd
);
825 /* Turn ECOFF type information into a printable string.
826 emit_aggregate and type_to_string are from gcc/mips-tdump.c, with
827 swapping added and used_ptr removed. */
829 /* Write aggregate information to a string. */
832 DEFUN (emit_aggregate
, (abfd
, string
, rndx
, isym
, which
),
840 int indx
= rndx
->index
;
841 int sym_base
, ss_base
;
847 sym_base
= ecoff_data (abfd
)->fdr
[ifd
].isymBase
;
848 ss_base
= ecoff_data (abfd
)->fdr
[ifd
].issBase
;
850 if (indx
== indexNil
)
851 name
= "/* no name */";
857 ecoff_swap_sym_in (abfd
,
858 ecoff_data (abfd
)->external_sym
+ indx
,
860 name
= ecoff_data (abfd
)->ss
+ ss_base
+ sym
.iss
;
864 "%s %s { ifd = %d, index = %d }",
866 indx
+ ecoff_data (abfd
)->symbolic_header
.iextMax
);
869 /* Convert the type information to string format. */
872 DEFUN (type_to_string
, (abfd
, aux_ptr
, indx
, bigendian
),
874 union aux_ext
*aux_ptr AND
886 unsigned int basic_type
;
888 static char buffer1
[1024];
889 static char buffer2
[1024];
894 for (i
= 0; i
< 7; i
++)
896 qualifiers
[i
].low_bound
= 0;
897 qualifiers
[i
].high_bound
= 0;
898 qualifiers
[i
].stride
= 0;
901 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
902 return "-1 (no type)";
903 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
905 basic_type
= u
.ti
.bt
;
906 qualifiers
[0].type
= u
.ti
.tq0
;
907 qualifiers
[1].type
= u
.ti
.tq1
;
908 qualifiers
[2].type
= u
.ti
.tq2
;
909 qualifiers
[3].type
= u
.ti
.tq3
;
910 qualifiers
[4].type
= u
.ti
.tq4
;
911 qualifiers
[5].type
= u
.ti
.tq5
;
912 qualifiers
[6].type
= tqNil
;
915 * Go get the basic type.
919 case btNil
: /* undefined */
923 case btAdr
: /* address - integer same size as pointer */
924 strcpy (p1
, "address");
927 case btChar
: /* character */
931 case btUChar
: /* unsigned character */
932 strcpy (p1
, "unsigned char");
935 case btShort
: /* short */
936 strcpy (p1
, "short");
939 case btUShort
: /* unsigned short */
940 strcpy (p1
, "unsigned short");
943 case btInt
: /* int */
947 case btUInt
: /* unsigned int */
948 strcpy (p1
, "unsigned int");
951 case btLong
: /* long */
955 case btULong
: /* unsigned long */
956 strcpy (p1
, "unsigned long");
959 case btFloat
: /* float (real) */
960 strcpy (p1
, "float");
963 case btDouble
: /* Double (real) */
964 strcpy (p1
, "double");
967 /* Structures add 1-2 aux words:
968 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
969 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
971 case btStruct
: /* Structure (Record) */
972 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
973 emit_aggregate (abfd
, p1
, &rndx
,
974 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
976 indx
++; /* skip aux words */
979 /* Unions add 1-2 aux words:
980 1st word is [ST_RFDESCAPE, offset] pointer to union def;
981 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
983 case btUnion
: /* Union */
984 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
985 emit_aggregate (abfd
, p1
, &rndx
,
986 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
988 indx
++; /* skip aux words */
991 /* Enumerations add 1-2 aux words:
992 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
993 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
995 case btEnum
: /* Enumeration */
996 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
997 emit_aggregate (abfd
, p1
, &rndx
,
998 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1000 indx
++; /* skip aux words */
1003 case btTypedef
: /* defined via a typedef, isymRef points */
1004 strcpy (p1
, "typedef");
1007 case btRange
: /* subrange of int */
1008 strcpy (p1
, "subrange");
1011 case btSet
: /* pascal sets */
1015 case btComplex
: /* fortran complex */
1016 strcpy (p1
, "complex");
1019 case btDComplex
: /* fortran double complex */
1020 strcpy (p1
, "double complex");
1023 case btIndirect
: /* forward or unnamed typedef */
1024 strcpy (p1
, "forward/unamed typedef");
1027 case btFixedDec
: /* Fixed Decimal */
1028 strcpy (p1
, "fixed decimal");
1031 case btFloatDec
: /* Float Decimal */
1032 strcpy (p1
, "float decimal");
1035 case btString
: /* Varying Length Character String */
1036 strcpy (p1
, "string");
1039 case btBit
: /* Aligned Bit String */
1043 case btPicture
: /* Picture */
1044 strcpy (p1
, "picture");
1047 case btVoid
: /* Void */
1048 strcpy (p1
, "void");
1052 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1056 p1
+= strlen (buffer1
);
1059 * If this is a bitfield, get the bitsize.
1065 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1066 sprintf (p1
, " : %d", bitsize
);
1067 p1
+= strlen (buffer1
);
1072 * Deal with any qualifiers.
1074 if (qualifiers
[0].type
!= tqNil
)
1077 * Snarf up any array bounds in the correct order. Arrays
1078 * store 5 successive words in the aux. table:
1079 * word 0 RNDXR to type of the bounds (ie, int)
1080 * word 1 Current file descriptor index
1082 * word 3 high bound (or -1 if [])
1083 * word 4 stride size in bits
1085 for (i
= 0; i
< 7; i
++)
1087 if (qualifiers
[i
].type
== tqArray
)
1089 qualifiers
[i
].low_bound
=
1090 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1091 qualifiers
[i
].high_bound
=
1092 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1093 qualifiers
[i
].stride
=
1094 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1100 * Now print out the qualifiers.
1102 for (i
= 0; i
< 6; i
++)
1104 switch (qualifiers
[i
].type
)
1111 strcpy (p2
, "ptr to ");
1112 p2
+= sizeof ("ptr to ")-1;
1116 strcpy (p2
, "volatile ");
1117 p2
+= sizeof ("volatile ")-1;
1121 strcpy (p2
, "far ");
1122 p2
+= sizeof ("far ")-1;
1126 strcpy (p2
, "func. ret. ");
1127 p2
+= sizeof ("func. ret. ");
1132 int first_array
= i
;
1135 /* Print array bounds reversed (ie, in the order the C
1136 programmer writes them). C is such a fun language.... */
1138 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1141 for (j
= i
; j
>= first_array
; j
--)
1143 strcpy (p2
, "array [");
1144 p2
+= sizeof ("array [")-1;
1145 if (qualifiers
[j
].low_bound
!= 0)
1147 "%ld:%ld {%ld bits}",
1148 (long) qualifiers
[j
].low_bound
,
1149 (long) qualifiers
[j
].high_bound
,
1150 (long) qualifiers
[j
].stride
);
1152 else if (qualifiers
[j
].high_bound
!= -1)
1155 (long) (qualifiers
[j
].high_bound
+ 1),
1156 (long) (qualifiers
[j
].stride
));
1159 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1162 strcpy (p2
, "] of ");
1163 p2
+= sizeof ("] of ")-1;
1171 strcpy (p2
, buffer1
);
1175 /* Print information about an ECOFF symbol. */
1178 DEFUN (ecoff_print_symbol
, (abfd
, filep
, symbol
, how
),
1182 bfd_print_symbol_type how
)
1184 FILE *file
= (FILE *)filep
;
1188 case bfd_print_symbol_name
:
1189 fprintf (file
, "%s", symbol
->name
);
1191 case bfd_print_symbol_more
:
1192 if (ecoffsymbol (symbol
)->local
)
1196 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1198 fprintf (file
, "ecoff local %lx %x %x",
1199 (unsigned long) ecoff_sym
.value
,
1200 (unsigned) ecoff_sym
.st
, (unsigned) ecoff_sym
.sc
);
1206 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1208 fprintf (file
, "ecoff extern %lx %x %x",
1209 (unsigned long) ecoff_ext
.asym
.value
,
1210 (unsigned) ecoff_ext
.asym
.st
,
1211 (unsigned) ecoff_ext
.asym
.sc
);
1214 case bfd_print_symbol_nm
:
1216 CONST
char *section_name
= symbol
->section
->name
;
1218 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
1219 fprintf (file
, " %-5s %s %s",
1221 ecoffsymbol (symbol
)->local
? "l" : "e",
1225 case bfd_print_symbol_all
:
1226 /* Print out the symbols in a reasonable way */
1235 if (ecoffsymbol (symbol
)->local
)
1237 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1240 pos
= (ecoffsymbol (symbol
)->native
.lnative
1241 - ecoff_data (abfd
)->external_sym
1242 + ecoff_data (abfd
)->symbolic_header
.iextMax
);
1249 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1252 pos
= (ecoffsymbol (symbol
)->native
.enative
1253 - ecoff_data (abfd
)->external_ext
);
1254 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1255 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1256 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1259 fprintf (file
, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s",
1260 pos
, type
, (unsigned long) ecoff_ext
.asym
.value
,
1261 (unsigned) ecoff_ext
.asym
.st
,
1262 (unsigned) ecoff_ext
.asym
.sc
,
1263 (unsigned) ecoff_ext
.asym
.index
,
1264 jmptbl
, cobol_main
, weakext
,
1267 if (ecoffsymbol (symbol
)->fdr
!= NULL
1268 && ecoff_ext
.asym
.index
!= indexNil
)
1273 union aux_ext
*aux_base
;
1275 indx
= ecoff_ext
.asym
.index
;
1277 /* sym_base is used to map the fdr relative indices which
1278 appear in the file to the position number which we are
1280 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1281 if (ecoffsymbol (symbol
)->local
)
1282 sym_base
+= ecoff_data (abfd
)->symbolic_header
.iextMax
;
1284 /* aux_base is the start of the aux entries for this file;
1285 asym.index is an offset from this. */
1286 aux_base
= (ecoff_data (abfd
)->external_aux
1287 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1289 /* The aux entries are stored in host byte order; the
1290 order is indicated by a bit in the fdr. */
1291 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1293 /* This switch is basically from gcc/mips-tdump.c */
1294 switch (ecoff_ext
.asym
.st
)
1302 printf ("\n End+1 symbol: %ld", indx
+ sym_base
);
1306 if (ecoff_ext
.asym
.sc
== scText
1307 || ecoff_ext
.asym
.sc
== scInfo
)
1308 printf ("\n First symbol: %ld", indx
+ sym_base
);
1310 printf ("\n First symbol: %ld",
1311 (AUX_GET_ISYM (bigendian
,
1312 &aux_base
[ecoff_ext
.asym
.index
])
1318 if (MIPS_IS_STAB (&ecoff_ext
.asym
))
1320 else if (ecoffsymbol (symbol
)->local
)
1321 printf ("\n End+1 symbol: %-7ld Type: %s",
1322 (AUX_GET_ISYM (bigendian
,
1323 &aux_base
[ecoff_ext
.asym
.index
])
1325 type_to_string (abfd
, aux_base
, indx
+ 1,
1328 printf ("\n Local symbol: %d",
1331 + ecoff_data (abfd
)->symbolic_header
.iextMax
));
1335 if (!MIPS_IS_STAB (&ecoff_ext
.asym
))
1336 printf ("\n Type: %s",
1337 type_to_string (abfd
, aux_base
, indx
, bigendian
));
1346 /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in
1347 external form. They use a bit which indicates whether the symbol
1350 /* Swap a reloc in. */
1353 DEFUN (ecoff_swap_reloc_in
, (abfd
, ext
, intern
),
1356 struct internal_reloc
*intern
)
1358 intern
->r_vaddr
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->r_vaddr
);
1359 if (abfd
->xvec
->header_byteorder_big_p
!= false)
1361 intern
->r_symndx
= (((int) ext
->r_bits
[0]
1362 << RELOC_BITS0_SYMNDX_SH_LEFT_BIG
)
1363 | ((int) ext
->r_bits
[1]
1364 << RELOC_BITS1_SYMNDX_SH_LEFT_BIG
)
1365 | ((int) ext
->r_bits
[2]
1366 << RELOC_BITS2_SYMNDX_SH_LEFT_BIG
));
1367 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_BIG
)
1368 >> RELOC_BITS3_TYPE_SH_BIG
);
1369 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_BIG
) != 0;
1373 intern
->r_symndx
= (((int) ext
->r_bits
[0]
1374 << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
)
1375 | ((int) ext
->r_bits
[1]
1376 << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
)
1377 | ((int) ext
->r_bits
[2]
1378 << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
));
1379 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_LITTLE
)
1380 >> RELOC_BITS3_TYPE_SH_LITTLE
);
1381 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_LITTLE
) != 0;
1385 /* Swap a reloc out. */
1388 DEFUN (ecoff_swap_reloc_out
, (abfd
, src
, dst
),
1393 struct internal_reloc
*intern
= (struct internal_reloc
*) src
;
1394 RELOC
*ext
= (RELOC
*) dst
;
1396 bfd_h_put_32 (abfd
, intern
->r_vaddr
, (bfd_byte
*) ext
->r_vaddr
);
1397 if (abfd
->xvec
->header_byteorder_big_p
!= false)
1399 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_BIG
;
1400 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_BIG
;
1401 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_BIG
;
1402 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_BIG
)
1403 & RELOC_BITS3_TYPE_BIG
)
1404 | (intern
->r_extern
? RELOC_BITS3_EXTERN_BIG
: 0));
1408 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
;
1409 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
;
1410 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
;
1411 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_LITTLE
)
1412 & RELOC_BITS3_TYPE_LITTLE
)
1413 | (intern
->r_extern
? RELOC_BITS3_EXTERN_LITTLE
: 0));
1419 /* ECOFF relocs are either against external symbols, or against
1420 sections. If we are producing relocateable output, and the reloc
1421 is against an external symbol, the resulting reloc will also be
1422 against the same symbol. In such a case, we don't want to change
1423 anything about the way the reloc is handled, since it will all be
1424 done at final link time. Rather than put special case code into
1425 bfd_perform_relocation, all the reloc types use this howto
1426 function. It just short circuits the reloc if producing
1427 relocateable output against an external symbol. */
1429 static bfd_reloc_status_type
1430 ecoff_generic_reloc (abfd
,
1437 arelent
*reloc_entry
;
1440 asection
*input_section
;
1443 if (output_bfd
!= (bfd
*) NULL
1444 && (symbol
->flags
& BSF_SECTION_SYM
) == 0)
1446 reloc_entry
->address
+= input_section
->output_offset
;
1447 return bfd_reloc_ok
;
1450 return bfd_reloc_continue
;
1453 /* Do a REFHI relocation. The next reloc must be the corresponding
1454 REFLO. This has to be done in a function so that carry is handled
1457 static bfd_reloc_status_type
1458 ecoff_refhi_reloc (abfd
,
1465 arelent
*reloc_entry
;
1468 asection
*input_section
;
1471 bfd_reloc_status_type ret
;
1476 unsigned long vallo
;
1478 /* If we're relocating, and this an external symbol, we don't want
1479 to change anything. */
1480 if (output_bfd
!= (bfd
*) NULL
1481 && (symbol
->flags
& BSF_SECTION_SYM
) == 0)
1483 reloc_entry
->address
+= input_section
->output_offset
;
1484 return bfd_reloc_ok
;
1488 if (symbol
->section
== &bfd_und_section
1489 && output_bfd
== (bfd
*) NULL
)
1490 ret
= bfd_reloc_undefined
;
1492 rello
= reloc_entry
+ 1;
1493 BFD_ASSERT (rello
->howto
->type
== ECOFF_R_REFLO
1494 && *rello
->sym_ptr_ptr
== *reloc_entry
->sym_ptr_ptr
);
1496 if (bfd_is_com_section (symbol
->section
))
1499 relocation
= symbol
->value
;
1501 relocation
+= symbol
->section
->output_section
->vma
;
1502 relocation
+= symbol
->section
->output_offset
;
1503 relocation
+= reloc_entry
->addend
;
1505 if (reloc_entry
->address
> input_section
->_cooked_size
)
1506 return bfd_reloc_outofrange
;
1508 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1509 vallo
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ rello
->address
) & 0xffff;
1510 val
= ((insn
& 0xffff) << 16) + vallo
;
1513 /* The low order 16 bits are always treated as a signed value.
1514 Therefore, a negative value in the low order bits requires an
1515 adjustment in the high order bits. We need to make this
1516 adjustment in two ways: once for the bits we took from the data,
1517 and once for the bits we are putting back in to the data. */
1518 if ((vallo
& 0x8000) != 0)
1520 if ((val
& 0x8000) != 0)
1523 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1524 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1526 if (output_bfd
!= (bfd
*) NULL
)
1527 reloc_entry
->address
+= input_section
->output_offset
;
1532 /* Do a GPREL relocation. This is a 16 bit value which must become
1533 the offset from the gp register. */
1535 static bfd_reloc_status_type
1536 ecoff_gprel_reloc (abfd
,
1543 arelent
*reloc_entry
;
1546 asection
*input_section
;
1549 boolean relocateable
;
1554 /* If we're relocating, and this an external symbol, we don't want
1555 to change anything. */
1556 if (output_bfd
!= (bfd
*) NULL
1557 && (symbol
->flags
& BSF_SECTION_SYM
) == 0)
1559 reloc_entry
->address
+= input_section
->output_offset
;
1560 return bfd_reloc_ok
;
1563 if (output_bfd
!= (bfd
*) NULL
)
1564 relocateable
= true;
1567 relocateable
= false;
1568 output_bfd
= symbol
->section
->output_section
->owner
;
1571 if (symbol
->section
== &bfd_und_section
1572 && relocateable
== false)
1573 return bfd_reloc_undefined
;
1575 /* We have to figure out the gp value, so that we can adjust the
1576 symbol value correctly. We look up the symbol _gp in the output
1577 BFD. If we can't find it, we're stuck. We cache it in the ECOFF
1579 if (ecoff_data (output_bfd
)->gp
== 0)
1581 if (relocateable
!= false)
1583 /* Make up a value. */
1584 ecoff_data (output_bfd
)->gp
=
1585 symbol
->section
->output_section
->vma
+ 0x4000;
1593 count
= bfd_get_symcount (output_bfd
);
1594 sym
= bfd_get_outsymbols (output_bfd
);
1596 /* We should do something more friendly here, but we don't
1597 have a good reloc status to return. */
1598 if (sym
== (asymbol
**) NULL
)
1601 for (i
= 0; i
< count
; i
++, sym
++)
1603 register CONST
char *name
;
1605 name
= bfd_asymbol_name (*sym
);
1606 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1608 ecoff_data (output_bfd
)->gp
= bfd_asymbol_value (*sym
);
1613 /* We should do something more friendly here, but we don't have
1614 a good reloc status to return. */
1620 if (bfd_is_com_section (symbol
->section
))
1623 relocation
= symbol
->value
;
1625 relocation
+= symbol
->section
->output_section
->vma
;
1626 relocation
+= symbol
->section
->output_offset
;
1628 if (reloc_entry
->address
> input_section
->_cooked_size
)
1629 return bfd_reloc_outofrange
;
1631 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1633 /* Set val to the offset into the section (if we are relocating
1634 against an external symbol, insn & 0xffff will be zero and so
1635 will reloc_entry->addend). */
1636 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1640 /* Adjust val for the final section location and GP value. */
1641 val
+= (relocation
- ecoff_data (output_bfd
)->gp
);
1643 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1644 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1646 if (relocateable
!= false)
1647 reloc_entry
->address
+= input_section
->output_offset
;
1649 /* Make sure it fit in 16 bits. */
1650 if (val
>= 0x8000 && val
< 0xffff8000)
1651 return bfd_reloc_outofrange
;
1653 return bfd_reloc_ok
;
1656 /* How to process the various relocs types. */
1658 static reloc_howto_type ecoff_howto_table
[] =
1660 /* Reloc type 0 is ignored. The reloc reading code ensures that
1661 this is a reference to the .abs section, which will cause
1662 bfd_perform_relocation to do nothing. */
1663 HOWTO (ECOFF_R_IGNORE
, /* type */
1665 0, /* size (0 = byte, 1 = short, 2 = long) */
1666 8, /* bitsize (obsolete) */
1667 false, /* pc_relative */
1669 false, /* absolute (obsolete) */
1670 false, /* complain_on_overflow */
1671 0, /* special_function */
1672 "IGNORE", /* name */
1673 false, /* partial_inplace */
1676 false), /* pcrel_offset */
1678 /* A 16 bit reference to a symbol, normally from a data section. */
1679 HOWTO (ECOFF_R_REFHALF
, /* type */
1681 1, /* size (0 = byte, 1 = short, 2 = long) */
1682 16, /* bitsize (obsolete) */
1683 false, /* pc_relative */
1685 false, /* absolute (obsolete) */
1686 true, /* complain_on_overflow */
1687 ecoff_generic_reloc
, /* special_function */
1688 "REFHALF", /* name */
1689 true, /* partial_inplace */
1690 0xffff, /* src_mask */
1691 0xffff, /* dst_mask */
1692 false), /* pcrel_offset */
1694 /* A 32 bit reference to a symbol, normally from a data section. */
1695 HOWTO (ECOFF_R_REFWORD
, /* type */
1697 2, /* size (0 = byte, 1 = short, 2 = long) */
1698 32, /* bitsize (obsolete) */
1699 false, /* pc_relative */
1701 false, /* absolute (obsolete) */
1702 true, /* complain_on_overflow */
1703 ecoff_generic_reloc
, /* special_function */
1704 "REFWORD", /* name */
1705 true, /* partial_inplace */
1706 0xffffffff, /* src_mask */
1707 0xffffffff, /* dst_mask */
1708 false), /* pcrel_offset */
1710 /* A 26 bit absolute jump address. */
1711 HOWTO (ECOFF_R_JMPADDR
, /* type */
1713 2, /* size (0 = byte, 1 = short, 2 = long) */
1714 32, /* bitsize (obsolete) */
1715 false, /* pc_relative */
1717 false, /* absolute (obsolete) */
1718 true, /* complain_on_overflow */
1719 ecoff_generic_reloc
, /* special_function */
1720 "JMPADDR", /* name */
1721 true, /* partial_inplace */
1722 0x3ffffff, /* src_mask */
1723 0x3ffffff, /* dst_mask */
1724 false), /* pcrel_offset */
1726 /* The high 16 bits of a symbol value. Handled by the function
1727 ecoff_refhi_reloc. */
1728 HOWTO (ECOFF_R_REFHI
, /* type */
1729 16, /* rightshift */
1730 2, /* size (0 = byte, 1 = short, 2 = long) */
1731 32, /* bitsize (obsolete) */
1732 false, /* pc_relative */
1734 false, /* absolute (obsolete) */
1735 true, /* complain_on_overflow */
1736 ecoff_refhi_reloc
, /* special_function */
1738 true, /* partial_inplace */
1739 0xffff, /* src_mask */
1740 0xffff, /* dst_mask */
1741 false), /* pcrel_offset */
1743 /* The low 16 bits of a symbol value. */
1744 HOWTO (ECOFF_R_REFLO
, /* type */
1746 2, /* size (0 = byte, 1 = short, 2 = long) */
1747 32, /* bitsize (obsolete) */
1748 false, /* pc_relative */
1750 false, /* absolute (obsolete) */
1751 true, /* complain_on_overflow */
1752 ecoff_generic_reloc
, /* special_function */
1754 true, /* partial_inplace */
1755 0xffff, /* src_mask */
1756 0xffff, /* dst_mask */
1757 false), /* pcrel_offset */
1759 /* A reference to an offset from the gp register. Handled by the
1760 function ecoff_gprel_reloc. */
1761 HOWTO (ECOFF_R_GPREL
, /* type */
1763 2, /* size (0 = byte, 1 = short, 2 = long) */
1764 32, /* bitsize (obsolete) */
1765 false, /* pc_relative */
1767 false, /* absolute (obsolete) */
1768 true, /* complain_on_overflow */
1769 ecoff_gprel_reloc
, /* special_function */
1771 true, /* partial_inplace */
1772 0xffff, /* src_mask */
1773 0xffff, /* dst_mask */
1774 false), /* pcrel_offset */
1776 /* A reference to a literal using an offset from the gp register.
1777 Handled by the function ecoff_gprel_reloc. */
1778 HOWTO (ECOFF_R_LITERAL
, /* type */
1780 2, /* size (0 = byte, 1 = short, 2 = long) */
1781 32, /* bitsize (obsolete) */
1782 false, /* pc_relative */
1784 false, /* absolute (obsolete) */
1785 true, /* complain_on_overflow */
1786 ecoff_gprel_reloc
, /* special_function */
1787 "LITERAL", /* name */
1788 true, /* partial_inplace */
1789 0xffff, /* src_mask */
1790 0xffff, /* dst_mask */
1791 false) /* pcrel_offset */
1794 /* Read in the relocs for a section. */
1797 DEFUN (ecoff_slurp_reloc_table
, (abfd
, section
, symbols
),
1799 asection
*section AND
1802 RELOC
*external_relocs
;
1803 arelent
*internal_relocs
;
1807 if (section
->relocation
!= (arelent
*) NULL
1808 || section
->reloc_count
== 0
1809 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1812 if (ecoff_slurp_symbol_table (abfd
) == false)
1815 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1817 * section
->reloc_count
));
1818 external_relocs
= (RELOC
*) bfd_alloc (abfd
, RELSZ
* section
->reloc_count
);
1819 if (internal_relocs
== (arelent
*) NULL
1820 || external_relocs
== (RELOC
*) NULL
)
1822 bfd_error
= no_memory
;
1825 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1827 if (bfd_read (external_relocs
, 1, RELSZ
* section
->reloc_count
, abfd
)
1828 != RELSZ
* section
->reloc_count
)
1830 bfd_error
= system_call_error
;
1834 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1836 struct internal_reloc intern
;
1838 ecoff_swap_reloc_in (abfd
, external_relocs
+ i
, &intern
);
1840 if (intern
.r_type
> ECOFF_R_LITERAL
)
1843 if (intern
.r_extern
)
1845 /* r_symndx is an index into the external symbols. */
1846 BFD_ASSERT (intern
.r_symndx
>= 0
1848 < ecoff_data (abfd
)->symbolic_header
.iextMax
));
1849 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1854 CONST
char *sec_name
;
1857 /* r_symndx is a section key. */
1858 switch (intern
.r_symndx
)
1860 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1861 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1862 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1863 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1864 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1865 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1866 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1867 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1868 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1872 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1873 if (sec
== (asection
*) NULL
)
1875 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1877 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1878 if (intern
.r_type
== ECOFF_R_GPREL
1879 || intern
.r_type
== ECOFF_R_LITERAL
)
1880 rptr
->addend
+= ecoff_data (abfd
)->gp
;
1883 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1884 rptr
->howto
= &ecoff_howto_table
[intern
.r_type
];
1886 /* If the type is ECOFF_R_IGNORE, make sure this is a reference
1887 to the absolute section so that the reloc is ignored. */
1888 if (intern
.r_type
== ECOFF_R_IGNORE
)
1889 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1892 bfd_release (abfd
, external_relocs
);
1894 section
->relocation
= internal_relocs
;
1899 /* Get a canonical list of relocs. */
1902 DEFUN (ecoff_canonicalize_reloc
, (abfd
, section
, relptr
, symbols
),
1904 asection
*section AND
1905 arelent
**relptr AND
1910 if (section
->flags
& SEC_CONSTRUCTOR
)
1912 arelent_chain
*chain
;
1914 /* This section has relocs made up by us, not the file, so take
1915 them out of their chain and place them into the data area
1917 for (count
= 0, chain
= section
->constructor_chain
;
1918 count
< section
->reloc_count
;
1919 count
++, chain
= chain
->next
)
1920 *relptr
++ = &chain
->relent
;
1926 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1929 tblptr
= section
->relocation
;
1930 if (tblptr
== (arelent
*) NULL
)
1933 for (count
= 0; count
< section
->reloc_count
; count
++)
1934 *relptr
++ = tblptr
++;
1937 *relptr
= (arelent
*) NULL
;
1939 return section
->reloc_count
;
1942 /* Provided a BFD, a section and an offset into the section, calculate
1943 and return the name of the source file and the line nearest to the
1947 DEFUN (ecoff_find_nearest_line
, (abfd
,
1955 asection
*section AND
1956 asymbol
**ignore_symbols AND
1958 CONST
char **filename_ptr AND
1959 CONST
char **functionname_ptr AND
1960 unsigned int *retline_ptr
)
1966 struct pdr_ext
*pdr_ptr
;
1967 struct pdr_ext
*pdr_end
;
1969 unsigned char *line_ptr
;
1970 unsigned char *line_end
;
1973 /* If we're not in the .text section, we don't have any line
1975 if (strcmp (section
->name
, _TEXT
) != 0)
1978 /* Make sure we have the FDR's. */
1979 if (ecoff_slurp_symbolic_info (abfd
) == false
1980 || bfd_get_symcount (abfd
) == 0)
1983 /* Each file descriptor (FDR) has a memory address. Here we track
1984 down which FDR we want. The FDR's are stored in increasing
1985 memory order. If speed is ever important, this can become a
1986 binary search. We must ignore FDR's with no PDR entries; they
1987 will have the adr of the FDR before or after them. */
1988 fdr_start
= ecoff_data (abfd
)->fdr
;
1989 fdr_end
= fdr_start
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
1990 fdr_hold
= (FDR
*) NULL
;
1991 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1993 if (offset
< fdr_ptr
->adr
)
1995 if (fdr_ptr
->cpd
> 0)
1998 if (fdr_hold
== (FDR
*) NULL
)
2002 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2003 have an address, which is relative to the FDR address, and are
2004 also stored in increasing memory order. */
2005 offset
-= fdr_ptr
->adr
;
2006 pdr_ptr
= ecoff_data (abfd
)->external_pdr
+ fdr_ptr
->ipdFirst
;
2007 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
;
2008 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2009 if (offset
< pdr
.adr
)
2011 for (pdr_ptr
++; pdr_ptr
< pdr_end
; pdr_ptr
++)
2013 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2014 if (offset
< pdr
.adr
)
2018 /* Now we can look for the actual line number. The line numbers are
2019 stored in a very funky format, which I won't try to describe.
2020 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2021 we want; we need this to compute line_end. */
2022 line_end
= ecoff_data (abfd
)->line
;
2023 if (pdr_ptr
== pdr_end
)
2024 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2026 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2028 /* Now change pdr and pdr_ptr to the one we want. */
2030 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2034 line_ptr
= (ecoff_data (abfd
)->line
2035 + fdr_ptr
->cbLineOffset
2036 + pdr
.cbLineOffset
);
2037 while (line_ptr
< line_end
)
2042 delta
= *line_ptr
>> 4;
2045 count
= (*line_ptr
& 0xf) + 1;
2049 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2050 if (delta
>= 0x8000)
2055 if (offset
< count
* 4)
2057 offset
-= count
* 4;
2060 /* If offset is too large, this line is not interesting. */
2064 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2065 at least according to gdb/mipsread.c. */
2066 if (fdr_ptr
->rss
== -1)
2068 *filename_ptr
= NULL
;
2070 *functionname_ptr
= NULL
;
2075 ecoff_swap_ext_in (abfd
,
2076 (ecoff_data (abfd
)->external_ext
2079 *functionname_ptr
= ecoff_data (abfd
)->ssext
+ proc_ext
.asym
.iss
;
2086 *filename_ptr
= ecoff_data (abfd
)->ss
+ fdr_ptr
->issBase
+ fdr_ptr
->rss
;
2087 ecoff_swap_sym_in (abfd
,
2088 (ecoff_data (abfd
)->external_sym
2092 *functionname_ptr
= (ecoff_data (abfd
)->ss
2096 *retline_ptr
= lineno
;
2100 /* We can't use the generic linking routines for ECOFF, because we
2101 have to handle all the debugging information. The generic link
2102 routine just works out the section contents and attaches a list of
2105 We link by looping over all the seclets. We make two passes. On
2106 the first we set the actual section contents and determine the size
2107 of the debugging information. On the second we accumulate the
2108 debugging information and write it out.
2110 This currently always accumulates the debugging information, which
2111 is incorrect, because it ignores the -s and -S options of the
2112 linker. The linker needs to be modified to give us that
2113 information in a more useful format (currently it just provides a
2114 list of symbols which should appear in the output file). */
2116 /* Clear the output_has_begun flag for all the input BFD's. We use it
2117 to avoid linking in the debugging information for a BFD more than
2121 DEFUN (ecoff_clear_output_flags
, (abfd
),
2124 register asection
*o
;
2125 register bfd_seclet_type
*p
;
2127 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2128 for (p
= o
->seclets_head
;
2129 p
!= (bfd_seclet_type
*) NULL
;
2131 if (p
->type
== bfd_indirect_seclet
)
2132 p
->u
.indirect
.section
->owner
->output_has_begun
= false;
2135 /* Handle an indirect seclet on the first pass. Set the contents of
2136 the output section, and accumulate the debugging information if
2140 DEFUN (ecoff_rel
, (output_bfd
, seclet
, output_section
, data
, relocateable
),
2142 bfd_seclet_type
*seclet AND
2143 asection
*output_section AND
2145 boolean relocateable
)
2148 HDRR
*output_symhdr
;
2150 ecoff_symbol_type
*sym_ptr
;
2151 ecoff_symbol_type
*sym_end
;
2153 if ((output_section
->flags
& SEC_HAS_CONTENTS
)
2154 && !(output_section
->flags
& SEC_NEVER_LOAD
)
2155 && (output_section
->flags
& SEC_LOAD
)
2158 data
= (PTR
) bfd_get_relocated_section_contents (output_bfd
,
2162 if (bfd_set_section_contents (output_bfd
,
2173 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2175 /* We want to figure out how much space will be required to
2176 incorporate all the debugging information from input_bfd. We use
2177 the output_has_begun field to avoid adding it in more than once.
2178 The actual incorporation is done in the second pass, in
2179 ecoff_get_debug. The code has to parallel that code in its
2180 manipulations of output_symhdr. */
2182 if (input_bfd
->output_has_begun
)
2184 input_bfd
->output_has_begun
= true;
2186 output_symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2188 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2194 /* We just accumulate local symbols from a non-ECOFF BFD. The
2195 external symbols are handled separately. */
2197 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2198 get_symtab_upper_bound (input_bfd
));
2199 if (symbols
== (asymbol
**) NULL
)
2201 bfd_error
= no_memory
;
2204 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2206 for (sym_ptr
= symbols
; sym_ptr
< sym_end
; sym_ptr
++)
2210 len
= strlen ((*sym_ptr
)->name
);
2211 if (((*sym_ptr
)->flags
& BSF_EXPORT
) == 0)
2213 ++output_symhdr
->isymMax
;
2214 output_symhdr
->issMax
+= len
+ 1;
2218 bfd_release (output_bfd
, (PTR
) symbols
);
2220 ++output_symhdr
->ifdMax
;
2225 /* We simply add in the information from another ECOFF BFD. First
2226 we make sure we have the symbolic information. */
2227 if (ecoff_slurp_symbol_table (input_bfd
) == false)
2229 if (bfd_get_symcount (input_bfd
) == 0)
2232 input_symhdr
= &ecoff_data (input_bfd
)->symbolic_header
;
2234 /* Figure out how much information we are going to be putting in.
2235 The external symbols are handled separately. */
2236 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2237 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2238 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2239 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2240 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2241 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2242 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2243 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2244 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2246 /* The RFD's are special, since we create them if needed. */
2247 if (input_symhdr
->crfd
> 0)
2248 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2250 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2255 /* Handle an arbitrary seclet on the first pass. */
2258 DEFUN (ecoff_dump_seclet
, (abfd
, seclet
, section
, data
, relocateable
),
2260 bfd_seclet_type
*seclet AND
2261 asection
*section AND
2263 boolean relocateable
)
2265 switch (seclet
->type
)
2267 case bfd_indirect_seclet
:
2268 /* The contents of this section come from another one somewhere
2270 return ecoff_rel (abfd
, seclet
, section
, data
, relocateable
);
2272 case bfd_fill_seclet
:
2273 /* Fill in the section with fill.value. This is used to pad out
2274 sections, but we must avoid padding the .bss section. */
2275 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
2277 if (seclet
->u
.fill
.value
!= 0)
2282 char *d
= (char *) bfd_alloc (abfd
, seclet
->size
);
2286 for (i
= 0; i
< seclet
->size
; i
+=2)
2287 d
[i
] = seclet
->u
.fill
.value
>> 8;
2288 for (i
= 1; i
< seclet
->size
; i
+=2)
2289 d
[i
] = seclet
->u
.fill
.value
;
2290 ret
= bfd_set_section_contents (abfd
, section
, d
, seclet
->offset
,
2292 bfd_release (abfd
, (PTR
) d
);
2304 /* Add a string to the debugging information we are accumulating for a
2305 file. Return the offset from the fdr string base or from the
2306 external string base. */
2309 DEFUN (ecoff_add_string
, (output_bfd
, fdr
, string
, external
),
2312 CONST
char *string AND
2319 symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2320 len
= strlen (string
);
2323 strcpy (ecoff_data (output_bfd
)->ssext
+ symhdr
->issExtMax
, string
);
2324 ret
= symhdr
->issExtMax
;
2325 symhdr
->issExtMax
+= len
+ 1;
2329 strcpy (ecoff_data (output_bfd
)->ss
+ symhdr
->issMax
, string
);
2331 symhdr
->issMax
+= len
+ 1;
2332 fdr
->cbSs
+= len
+ 1;
2337 /* Accumulate the debugging information from an input section. */
2340 DEFUN (ecoff_get_debug
, (output_bfd
, seclet
, section
),
2342 bfd_seclet_type
*seclet AND
2346 HDRR
*output_symhdr
;
2348 ecoff_data_type
*output_ecoff
;
2349 ecoff_data_type
*input_ecoff
;
2351 struct sym_ext
*sym_out
;
2352 struct ext_ext
*ext_out
;
2353 ecoff_symbol_type
*esym_ptr
;
2354 ecoff_symbol_type
*esym_end
;
2357 struct fdr_ext
*fdr_out
;
2359 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2361 /* Don't get the information more than once. */
2362 if (input_bfd
->output_has_begun
)
2364 input_bfd
->output_has_begun
= true;
2366 output_ecoff
= ecoff_data (output_bfd
);
2367 output_symhdr
= &output_ecoff
->symbolic_header
;
2369 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2376 /* This is not an ECOFF BFD. Just gather the symbols. */
2378 memset (&fdr
, 0, sizeof fdr
);
2380 fdr
.adr
= bfd_get_section_vma (output_bfd
, section
) + seclet
->offset
;
2381 fdr
.issBase
= output_symhdr
->issMax
;
2383 fdr
.rss
= ecoff_add_string (output_bfd
,
2385 bfd_get_filename (input_bfd
),
2387 fdr
.isymBase
= output_symhdr
->isymMax
;
2389 /* Get the local symbols from the input BFD. */
2390 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2391 get_symtab_upper_bound (input_bfd
));
2392 if (symbols
== (asymbol
**) NULL
)
2394 bfd_error
= no_memory
;
2397 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2399 /* Handle the local symbols. Any external symbols are handled
2402 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
2406 if (((*sym_ptr
)->flags
& BSF_EXPORT
) != 0)
2408 memset (&internal_sym
, 0, sizeof internal_sym
);
2409 internal_sym
.iss
= ecoff_add_string (output_bfd
,
2413 internal_sym
.value
= (*sym_ptr
)->value
;
2414 internal_sym
.st
= stNil
;
2415 internal_sym
.sc
= scUndefined
;
2416 internal_sym
.index
= indexNil
;
2417 ecoff_swap_sym_out (output_bfd
, &internal_sym
,
2418 (output_ecoff
->external_sym
2419 + output_symhdr
->isymMax
));
2421 ++output_symhdr
->isymMax
;
2424 bfd_release (output_bfd
, (PTR
) symbols
);
2426 /* Leave everything else in the FDR zeroed out. This will cause
2427 the lang field to be langC. The fBigendian field will
2428 indicate little endian format, but it doesn't matter because
2429 it only applies to aux fields and there are none. */
2431 ecoff_swap_fdr_out (output_bfd
, &fdr
,
2432 (output_ecoff
->external_fdr
2433 + output_symhdr
->ifdMax
));
2434 ++output_symhdr
->ifdMax
;
2438 /* This is an ECOFF BFD. We want to grab the information from
2439 input_bfd and attach it to output_bfd. */
2440 count
= bfd_get_symcount (input_bfd
);
2443 input_ecoff
= ecoff_data (input_bfd
);
2444 input_symhdr
= &input_ecoff
->symbolic_header
;
2446 /* I think that it is more efficient to simply copy the debugging
2447 information from the input BFD to the output BFD. Because ECOFF
2448 uses relative pointers for most of the debugging information,
2449 only a little of it has to be changed at all. */
2451 /* Swap in the local symbols, adjust their values, and swap them out
2452 again. The external symbols are handled separately. */
2453 sym_out
= output_ecoff
->external_sym
+ output_symhdr
->isymMax
;
2455 esym_ptr
= ecoff_data (input_bfd
)->canonical_symbols
;
2456 esym_end
= esym_ptr
+ count
;
2457 for (; esym_ptr
< esym_end
; esym_ptr
++)
2459 if (esym_ptr
->local
)
2463 ecoff_swap_sym_in (input_bfd
, esym_ptr
->native
.lnative
, &sym
);
2464 if (! bfd_is_com_section (esym_ptr
->symbol
.section
)
2465 && (esym_ptr
->symbol
.flags
& BSF_DEBUGGING
) == 0
2466 && esym_ptr
->symbol
.section
!= &bfd_und_section
)
2467 sym
.value
= (esym_ptr
->symbol
.value
2468 + esym_ptr
->symbol
.section
->output_offset
2469 + esym_ptr
->symbol
.section
->output_section
->vma
);
2470 ecoff_swap_sym_out (output_bfd
, &sym
, sym_out
);
2475 /* That should have accounted for all the local symbols in
2477 BFD_ASSERT ((sym_out
- output_ecoff
->external_sym
) - output_symhdr
->isymMax
2478 == input_symhdr
->isymMax
);
2480 /* Copy the information that does not need swapping. */
2481 memcpy (output_ecoff
->line
+ output_symhdr
->cbLine
,
2483 input_symhdr
->cbLine
* sizeof (unsigned char));
2484 memcpy (output_ecoff
->external_aux
+ output_symhdr
->iauxMax
,
2485 input_ecoff
->external_aux
,
2486 input_symhdr
->iauxMax
* sizeof (union aux_ext
));
2487 memcpy (output_ecoff
->ss
+ output_symhdr
->issMax
,
2489 input_symhdr
->issMax
* sizeof (char));
2491 /* Some of the information may need to be swapped. */
2492 if (output_bfd
->xvec
->header_byteorder_big_p
2493 == input_bfd
->xvec
->header_byteorder_big_p
)
2495 /* The two BFD's have the same endianness, so memcpy will
2497 memcpy (output_ecoff
->external_dnr
+ output_symhdr
->idnMax
,
2498 input_ecoff
->external_dnr
,
2499 input_symhdr
->idnMax
* sizeof (struct dnr_ext
));
2500 memcpy (output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
,
2501 input_ecoff
->external_pdr
,
2502 input_symhdr
->ipdMax
* sizeof (struct pdr_ext
));
2503 memcpy (output_ecoff
->external_opt
+ output_symhdr
->ioptMax
,
2504 input_ecoff
->external_opt
,
2505 input_symhdr
->ioptMax
* sizeof (struct opt_ext
));
2509 struct dnr_ext
*dnr_in
;
2510 struct dnr_ext
*dnr_end
;
2511 struct dnr_ext
*dnr_out
;
2512 struct pdr_ext
*pdr_in
;
2513 struct pdr_ext
*pdr_end
;
2514 struct pdr_ext
*pdr_out
;
2515 struct opt_ext
*opt_in
;
2516 struct opt_ext
*opt_end
;
2517 struct opt_ext
*opt_out
;
2519 /* The two BFD's have different endianness, so we must swap
2520 everything in and out. This code would always work, but it
2521 would be slow in the normal case. */
2522 dnr_in
= input_ecoff
->external_dnr
;
2523 dnr_end
= dnr_in
+ input_symhdr
->idnMax
;
2524 dnr_out
= output_ecoff
->external_dnr
+ output_symhdr
->idnMax
;
2525 for (; dnr_in
< dnr_end
; dnr_in
++, dnr_out
++)
2529 ecoff_swap_dnr_in (input_bfd
, dnr_in
, &dnr
);
2530 ecoff_swap_dnr_out (output_bfd
, &dnr
, dnr_out
);
2532 pdr_in
= input_ecoff
->external_pdr
;
2533 pdr_end
= pdr_in
+ input_symhdr
->ipdMax
;
2534 pdr_out
= output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
;
2535 for (; pdr_in
< pdr_end
; pdr_in
++, pdr_out
++)
2539 ecoff_swap_pdr_in (input_bfd
, pdr_in
, &pdr
);
2540 ecoff_swap_pdr_out (output_bfd
, &pdr
, pdr_out
);
2542 opt_in
= input_ecoff
->external_opt
;
2543 opt_end
= opt_in
+ input_symhdr
->ioptMax
;
2544 opt_out
= output_ecoff
->external_opt
+ output_symhdr
->ioptMax
;
2545 for (; opt_in
< opt_end
; opt_in
++, opt_out
++)
2549 ecoff_swap_opt_in (input_bfd
, opt_in
, &opt
);
2550 ecoff_swap_opt_out (output_bfd
, &opt
, opt_out
);
2554 /* Set ifdbase so that the external symbols know how to adjust their
2556 input_ecoff
->ifdbase
= output_symhdr
->ifdMax
;
2558 fdr_ptr
= input_ecoff
->fdr
;
2559 fdr_end
= fdr_ptr
+ input_symhdr
->ifdMax
;
2560 fdr_out
= output_ecoff
->external_fdr
+ output_symhdr
->ifdMax
;
2561 for (; fdr_ptr
< fdr_end
; fdr_ptr
++, fdr_out
++)
2567 /* The memory address for this fdr is the address for the seclet
2568 plus the offset to this fdr within input_bfd. */
2569 fdr
.adr
= (bfd_get_section_vma (output_bfd
, section
)
2571 + (fdr_ptr
->adr
- input_ecoff
->fdr
->adr
));
2573 fdr
.issBase
+= output_symhdr
->issMax
;
2574 fdr
.isymBase
+= output_symhdr
->isymMax
;
2575 fdr
.ilineBase
+= output_symhdr
->ilineMax
;
2576 fdr
.ioptBase
+= output_symhdr
->ioptMax
;
2577 fdr
.ipdFirst
+= output_symhdr
->ipdMax
;
2578 fdr
.iauxBase
+= output_symhdr
->iauxMax
;
2579 fdr
.rfdBase
+= output_symhdr
->crfd
;
2581 /* If there are no RFD's, we are going to add some. We don't
2582 want to adjust irfd for this, so that all the FDR's can share
2584 if (input_symhdr
->crfd
== 0)
2585 fdr
.crfd
= input_symhdr
->ifdMax
;
2587 if (fdr
.cbLine
!= 0)
2588 fdr
.cbLineOffset
+= output_symhdr
->cbLine
;
2590 ecoff_swap_fdr_out (output_bfd
, &fdr
, fdr_out
);
2593 if (input_symhdr
->crfd
> 0)
2595 struct rfd_ext
*rfd_in
;
2596 struct rfd_ext
*rfd_end
;
2597 struct rfd_ext
*rfd_out
;
2599 /* Swap and adjust the RFD's. RFD's are only created by the
2600 linker, so this will only be necessary if one of the input
2601 files is the result of a partial link. Presumably all
2602 necessary RFD's are present. */
2603 rfd_in
= input_ecoff
->external_rfd
;
2604 rfd_end
= rfd_in
+ input_symhdr
->crfd
;
2605 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
2606 for (; rfd_in
< rfd_end
; rfd_in
++, rfd_out
++)
2610 ecoff_swap_rfd_in (input_bfd
, rfd_in
, &rfd
);
2611 rfd
+= output_symhdr
->ifdMax
;
2612 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
2614 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2618 struct rfd_ext
*rfd_out
;
2619 struct rfd_ext
*rfd_end
;
2622 /* Create RFD's. Some of the debugging information includes
2623 relative file indices. These indices are taken as indices to
2624 the RFD table if there is one, or to the global table if
2625 there is not. If we did not create RFD's, we would have to
2626 parse and adjust all the debugging information which contains
2628 rfd
= output_symhdr
->ifdMax
;
2629 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
2630 rfd_end
= rfd_out
+ input_symhdr
->ifdMax
;
2631 for (; rfd_out
< rfd_end
; rfd_out
++, rfd
++)
2632 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
2633 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2636 /* Combine the register masks. */
2640 output_ecoff
->gprmask
|= input_ecoff
->gprmask
;
2641 for (i
= 0; i
< 3; i
++)
2642 output_ecoff
->cprmask
[i
] |= input_ecoff
->cprmask
[i
];
2645 /* Update the counts. */
2646 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2647 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2648 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2649 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2650 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2651 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2652 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2653 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2654 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2659 /* This is the actual link routine. It makes two passes over all the
2663 DEFUN (ecoff_bfd_seclet_link
, (abfd
, data
, relocateable
),
2666 boolean relocateable
)
2670 register asection
*o
;
2671 register bfd_seclet_type
*p
;
2672 asymbol
**sym_ptr_ptr
;
2676 /* We accumulate the debugging information counts in the symbolic
2678 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
2679 symhdr
->magic
= magicSym
;
2680 /* FIXME: What should the version stamp be? */
2682 symhdr
->ilineMax
= 0;
2686 symhdr
->isymMax
= 0;
2687 symhdr
->ioptMax
= 0;
2688 symhdr
->iauxMax
= 0;
2690 symhdr
->issExtMax
= 0;
2693 symhdr
->iextMax
= 0;
2695 /* We need to copy over the debugging symbols from each input BFD.
2696 When we do this copying, we have to adjust the text address in
2697 the FDR structures, so we have to know the text address used for
2698 the input BFD. Since we only want to copy the symbols once per
2699 input BFD, but we are going to look at each input BFD multiple
2700 times (once for each section it provides), we arrange to always
2701 look at the text section first. That means that when we copy the
2702 debugging information, we always know the text address. So we
2703 actually do each pass in two sub passes; first the text sections,
2704 then the non-text sections. We use the output_has_begun flag to
2705 determine whether we have copied over the debugging information
2708 /* Do the first pass: set the output section contents and count the
2709 debugging information. */
2710 ecoff_clear_output_flags (abfd
);
2711 for (ipass
= 0; ipass
< 2; ipass
++)
2713 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2715 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2716 so they are done on pass 0. For other sections the
2717 expression is true, so they are done on pass 1. */
2718 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2721 for (p
= o
->seclets_head
;
2722 p
!= (bfd_seclet_type
*) NULL
;
2725 if (ecoff_dump_seclet (abfd
, p
, o
, data
, relocateable
)
2732 /* We handle the external symbols differently. We use the ones
2733 attached to the output_bfd. The linker will have already
2734 determined which symbols are to be attached. Here we just
2735 determine how much space we will need for them. */
2736 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2737 if (sym_ptr_ptr
!= NULL
)
2741 sym_end
= sym_ptr_ptr
+ bfd_get_symcount (abfd
);
2742 for (; sym_ptr_ptr
< sym_end
; sym_ptr_ptr
++)
2744 if (((*sym_ptr_ptr
)->flags
& BSF_DEBUGGING
) == 0
2745 && ((*sym_ptr_ptr
)->flags
& BSF_LOCAL
) == 0)
2748 symhdr
->issExtMax
+= strlen ((*sym_ptr_ptr
)->name
) + 1;
2753 /* Adjust the counts so that structures are longword aligned. */
2754 symhdr
->cbLine
= (symhdr
->cbLine
+ 3) &~ 3;
2755 symhdr
->issMax
= (symhdr
->issMax
+ 3) &~ 3;
2756 symhdr
->issExtMax
= (symhdr
->issExtMax
+ 3) &~ 3;
2758 /* Now the counts in symhdr are the correct size for the debugging
2759 information. We allocate the right amount of space, and reset
2760 the counts so that the second pass can use them as indices. It
2761 would be possible to output the debugging information directly to
2762 the file in pass 2, rather than to build it in memory and then
2763 write it out. Outputting to the file would require a lot of
2764 seeks and small writes, though, and I think this approach is
2766 size
= (symhdr
->cbLine
* sizeof (unsigned char)
2767 + symhdr
->idnMax
* sizeof (struct dnr_ext
)
2768 + symhdr
->ipdMax
* sizeof (struct pdr_ext
)
2769 + symhdr
->isymMax
* sizeof (struct sym_ext
)
2770 + symhdr
->ioptMax
* sizeof (struct opt_ext
)
2771 + symhdr
->iauxMax
* sizeof (union aux_ext
)
2772 + symhdr
->issMax
* sizeof (char)
2773 + symhdr
->issExtMax
* sizeof (char)
2774 + symhdr
->ifdMax
* sizeof (struct fdr_ext
)
2775 + symhdr
->crfd
* sizeof (struct rfd_ext
)
2776 + symhdr
->iextMax
* sizeof (struct ext_ext
));
2777 raw
= (char *) bfd_alloc (abfd
, size
);
2778 if (raw
== (char *) NULL
)
2780 bfd_error
= no_memory
;
2783 ecoff_data (abfd
)->raw_size
= size
;
2784 ecoff_data (abfd
)->raw_syments
= (PTR
) raw
;
2786 /* Initialize the raw pointers. */
2787 #define SET(field, count, type) \
2788 ecoff_data (abfd)->field = (type *) raw; \
2789 raw += symhdr->count * sizeof (type)
2791 SET (line
, cbLine
, unsigned char);
2792 SET (external_dnr
, idnMax
, struct dnr_ext
);
2793 SET (external_pdr
, ipdMax
, struct pdr_ext
);
2794 SET (external_sym
, isymMax
, struct sym_ext
);
2795 SET (external_opt
, ioptMax
, struct opt_ext
);
2796 SET (external_aux
, iauxMax
, union aux_ext
);
2797 SET (ss
, issMax
, char);
2798 SET (ssext
, issExtMax
, char);
2799 SET (external_fdr
, ifdMax
, struct fdr_ext
);
2800 SET (external_rfd
, crfd
, struct rfd_ext
);
2801 SET (external_ext
, iextMax
, struct ext_ext
);
2804 /* Reset the counts so the second pass can use them to know how far
2806 symhdr
->ilineMax
= 0;
2810 symhdr
->isymMax
= 0;
2811 symhdr
->ioptMax
= 0;
2812 symhdr
->iauxMax
= 0;
2814 symhdr
->issExtMax
= 0;
2817 symhdr
->iextMax
= 0;
2819 /* Do the second pass: accumulate the debugging information. */
2820 ecoff_clear_output_flags (abfd
);
2821 for (ipass
= 0; ipass
< 2; ipass
++)
2823 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2825 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2827 for (p
= o
->seclets_head
;
2828 p
!= (bfd_seclet_type
*) NULL
;
2831 if (p
->type
== bfd_indirect_seclet
)
2833 if (ecoff_get_debug (abfd
, p
, o
) == false)
2840 /* Put in the external symbols. */
2841 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2842 if (sym_ptr_ptr
!= NULL
)
2845 struct ext_ext
*external_ext
;
2847 ssext
= ecoff_data (abfd
)->ssext
;
2848 external_ext
= ecoff_data (abfd
)->external_ext
;
2849 for (; *sym_ptr_ptr
!= NULL
; sym_ptr_ptr
++)
2854 sym_ptr
= *sym_ptr_ptr
;
2856 if ((sym_ptr
->flags
& BSF_DEBUGGING
) != 0
2857 || (sym_ptr
->flags
& BSF_LOCAL
) != 0)
2860 /* The enative pointer can be NULL for a symbol created by
2861 the linker via ecoff_make_empty_symbol. */
2862 if (bfd_asymbol_flavour (sym_ptr
) != bfd_target_ecoff_flavour
2863 || (((ecoff_symbol_type
*) sym_ptr
)->native
.enative
2864 == (struct ext_ext
*) NULL
))
2867 esym
.cobol_main
= 0;
2871 /* FIXME: we can do better than this for st and sc. */
2872 esym
.asym
.st
= stGlobal
;
2873 esym
.asym
.sc
= scAbs
;
2874 esym
.asym
.reserved
= 0;
2875 esym
.asym
.index
= indexNil
;
2879 ecoff_symbol_type
*ecoff_sym_ptr
;
2881 ecoff_sym_ptr
= (ecoff_symbol_type
*) sym_ptr
;
2882 if (ecoff_sym_ptr
->local
)
2884 ecoff_swap_ext_in (abfd
, ecoff_sym_ptr
->native
.enative
, &esym
);
2886 /* Adjust the FDR index for the symbol by that used for
2888 esym
.ifd
+= ecoff_data (bfd_asymbol_bfd (sym_ptr
))->ifdbase
;
2891 esym
.asym
.iss
= symhdr
->issExtMax
;
2893 if (bfd_is_com_section (sym_ptr
->section
)
2894 || sym_ptr
->section
== &bfd_und_section
)
2895 esym
.asym
.value
= sym_ptr
->value
;
2897 esym
.asym
.value
= (sym_ptr
->value
2898 + sym_ptr
->section
->output_offset
2899 + sym_ptr
->section
->output_section
->vma
);
2901 ecoff_swap_ext_out (abfd
, &esym
, external_ext
+ symhdr
->iextMax
);
2903 ecoff_set_sym_index (sym_ptr
, symhdr
->iextMax
);
2907 strcpy (ssext
+ symhdr
->issExtMax
, sym_ptr
->name
);
2908 symhdr
->issExtMax
+= strlen (sym_ptr
->name
) + 1;
2912 /* Adjust the counts so that structures are longword aligned. */
2913 symhdr
->cbLine
= (symhdr
->cbLine
+ 3) &~ 3;
2914 symhdr
->issMax
= (symhdr
->issMax
+ 3) &~ 3;
2915 symhdr
->issExtMax
= (symhdr
->issExtMax
+ 3) &~ 3;
2920 /* Set the architecture. The only architecture we support here is
2921 mips. We set the architecture anyhow, since many callers ignore
2922 the return value. */
2925 DEFUN (ecoff_set_arch_mach
, (abfd
, arch
, machine
),
2927 enum bfd_architecture arch AND
2928 unsigned long machine
)
2930 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2931 return arch
== bfd_arch_mips
;
2934 /* Calculate the file position for each section, and set
2938 DEFUN (ecoff_compute_section_file_positions
, (abfd
),
2948 if (bfd_get_start_address (abfd
))
2949 abfd
->flags
|= EXEC_P
;
2951 /* Unlike normal COFF, ECOFF always use the ``optional'' header. */
2954 sofar
+= abfd
->section_count
* SCNHSZ
;
2957 for (current
= abfd
->sections
;
2958 current
!= (asection
*) NULL
;
2959 current
= current
->next
)
2961 /* Only deal with sections which have contents */
2962 if (! (current
->flags
& SEC_HAS_CONTENTS
))
2965 /* On Ultrix, the data sections in an executable file must be
2966 aligned to a page boundary within the file. This does not
2967 affect the section size, though. FIXME: Does this work for
2969 if ((abfd
->flags
& EXEC_P
) != 0
2970 && first_data
!= false
2971 && (current
->flags
& SEC_CODE
) == 0)
2973 sofar
= (sofar
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
2977 /* Align the sections in the file to the same boundary on
2978 which they are aligned in virtual memory. */
2980 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2982 current
->filepos
= sofar
;
2984 sofar
+= current
->_raw_size
;
2986 /* make sure that this section is of the right size too */
2988 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2989 current
->_raw_size
+= sofar
- old_sofar
;
2992 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2995 /* Set the contents of a section. */
2998 DEFUN (ecoff_set_section_contents
, (abfd
, section
, location
, offset
, count
),
3000 asection
*section AND
3003 bfd_size_type count
)
3005 if (abfd
->output_has_begun
== false)
3006 ecoff_compute_section_file_positions (abfd
);
3008 bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
3011 return (bfd_write (location
, 1, count
, abfd
) == count
) ? true : false;
3016 /* Write out an ECOFF file. */
3019 DEFUN (ecoff_write_object_contents
, (abfd
),
3025 file_ptr reloc_base
;
3027 unsigned long reloc_size
;
3028 unsigned long text_size
;
3029 unsigned long text_start
;
3030 unsigned long data_size
;
3031 unsigned long data_start
;
3032 unsigned long bss_size
;
3033 struct internal_filehdr internal_f
;
3034 struct internal_aouthdr internal_a
;
3037 bfd_error
= system_call_error
;
3039 if(abfd
->output_has_begun
== false)
3040 ecoff_compute_section_file_positions(abfd
);
3042 if (abfd
->sections
!= (asection
*) NULL
)
3043 scn_base
= abfd
->sections
->filepos
;
3046 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
3050 for (current
= abfd
->sections
;
3051 current
!= (asection
*)NULL
;
3052 current
= current
->next
)
3054 current
->target_index
= count
;
3056 if (current
->reloc_count
!= 0)
3058 bfd_size_type relsize
;
3060 current
->rel_filepos
= reloc_base
;
3061 relsize
= current
->reloc_count
* RELSZ
;
3062 reloc_size
+= relsize
;
3063 reloc_base
+= relsize
;
3066 current
->rel_filepos
= 0;
3069 sym_base
= reloc_base
+ reloc_size
;
3071 /* At least on Ultrix, the symbol table of an executable file must
3072 be aligned to a page boundary. FIXME: Is this true on other
3074 if ((abfd
->flags
& EXEC_P
) != 0)
3075 sym_base
= (sym_base
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
3077 ecoff_data (abfd
)->sym_filepos
= sym_base
;
3079 text_size
= FILHSZ
+ AOUTSZ
+ abfd
->section_count
* SCNHSZ
;
3085 /* Write section headers to the file. */
3087 internal_f
.f_nscns
= 0;
3088 if (bfd_seek (abfd
, (file_ptr
) (FILHSZ
+ AOUTSZ
), SEEK_SET
) != 0)
3090 for (current
= abfd
->sections
;
3091 current
!= (asection
*) NULL
;
3092 current
= current
->next
)
3094 struct internal_scnhdr section
;
3097 ++internal_f
.f_nscns
;
3099 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
3101 /* FIXME: is this correct for shared libraries? I think it is
3102 but I have no platform to check. Ian Lance Taylor. */
3103 vma
= bfd_get_section_vma (abfd
, current
);
3104 if (strcmp (current
->name
, _LIB
) == 0)
3105 section
.s_vaddr
= 0;
3107 section
.s_vaddr
= vma
;
3109 section
.s_paddr
= vma
;
3110 section
.s_size
= bfd_get_section_size_before_reloc (current
);
3112 /* If this section has no size or is unloadable then the scnptr
3114 if (current
->_raw_size
== 0
3115 || (current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
3116 section
.s_scnptr
= 0;
3118 section
.s_scnptr
= current
->filepos
;
3119 section
.s_relptr
= current
->rel_filepos
;
3121 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3122 object file produced by the assembler is supposed to point to
3123 information about how much room is required by objects of
3124 various different sizes. I think this only matters if we
3125 want the linker to compute the best size to use, or
3126 something. I don't know what happens if the information is
3128 section
.s_lnnoptr
= 0;
3130 section
.s_nreloc
= current
->reloc_count
;
3131 section
.s_nlnno
= 0;
3132 section
.s_flags
= sec_to_styp_flags (current
->name
, current
->flags
);
3137 ecoff_swap_scnhdr_out (abfd
, (PTR
) §ion
, (PTR
) &buff
);
3138 if (bfd_write ((PTR
) &buff
, 1, SCNHSZ
, abfd
) != SCNHSZ
)
3142 if ((section
.s_flags
& STYP_TEXT
) != 0)
3144 text_size
+= bfd_get_section_size_before_reloc (current
);
3145 if (text_start
== 0 || text_start
> vma
)
3148 else if ((section
.s_flags
& STYP_RDATA
) != 0
3149 || (section
.s_flags
& STYP_DATA
) != 0
3150 || (section
.s_flags
& STYP_LIT8
) != 0
3151 || (section
.s_flags
& STYP_LIT4
) != 0
3152 || (section
.s_flags
& STYP_SDATA
) != 0)
3154 data_size
+= bfd_get_section_size_before_reloc (current
);
3155 if (data_start
== 0 || data_start
> vma
)
3158 else if ((section
.s_flags
& STYP_BSS
) != 0
3159 || (section
.s_flags
& STYP_SBSS
) != 0)
3160 bss_size
+= bfd_get_section_size_before_reloc (current
);
3163 /* Set up the file header. */
3165 internal_f
.f_magic
= MIPS_MAGIC_2
;
3168 We will NOT put a fucking timestamp in the header here. Every time you
3169 put it back, I will come in and take it out again. I'm sorry. This
3170 field does not belong here. We fill it with a 0 so it compares the
3171 same but is not a reasonable time. -- gnu@cygnus.com
3173 internal_f
.f_timdat
= 0;
3175 if (bfd_get_symcount (abfd
) != 0)
3177 /* The ECOFF f_nsyms field is not actually the number of
3178 symbols, it's the size of symbolic information header. */
3179 internal_f
.f_nsyms
= sizeof (struct hdr_ext
);
3180 internal_f
.f_symptr
= sym_base
;
3184 internal_f
.f_nsyms
= 0;
3185 internal_f
.f_symptr
= 0;
3188 internal_f
.f_opthdr
= AOUTSZ
;
3190 internal_f
.f_flags
= F_LNNO
;
3191 if (reloc_size
== 0)
3192 internal_f
.f_flags
|= F_RELFLG
;
3193 if (bfd_get_symcount (abfd
) == 0)
3194 internal_f
.f_flags
|= F_LSYMS
;
3195 if (abfd
->flags
& EXEC_P
)
3196 internal_f
.f_flags
|= F_EXEC
;
3198 if (! abfd
->xvec
->byteorder_big_p
)
3199 internal_f
.f_flags
|= F_AR32WR
;
3201 internal_f
.f_flags
|= F_AR32W
;
3203 /* Set up the ``optional'' header. */
3204 internal_a
.magic
= ZMAGIC
;
3206 /* FIXME: What should this be? */
3207 internal_a
.vstamp
= 0;
3209 /* At least on Ultrix, these have to be rounded to page boundaries.
3210 FIXME: Is this true on other platforms? */
3211 internal_a
.tsize
= (text_size
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
3212 internal_a
.text_start
= text_start
&~ (PAGE_SIZE
- 1);
3213 internal_a
.dsize
= (data_size
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
3214 internal_a
.data_start
= data_start
&~ (PAGE_SIZE
- 1);
3216 /* On Ultrix, the initial portions of the .sbss and .bss segments
3217 are at the end of the data section. The bsize field in the
3218 optional header records how many bss bytes are required beyond
3219 those in the data section. The value is not rounded to a page
3221 if (bss_size
< internal_a
.dsize
- data_size
)
3224 bss_size
-= internal_a
.dsize
- data_size
;
3225 internal_a
.bsize
= bss_size
;
3226 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
3228 internal_a
.entry
= bfd_get_start_address (abfd
);
3230 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
3232 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
3233 for (i
= 0; i
< 3; i
++)
3234 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
3236 /* Write out the file header and the optional header. */
3238 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3243 ecoff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, (PTR
) &buff
);
3244 if (bfd_write ((PTR
) &buff
, 1, FILHSZ
, abfd
) != FILHSZ
)
3251 ecoff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, (PTR
) &buff
);
3252 if (bfd_write ((PTR
) &buff
, 1, AOUTSZ
, abfd
) != AOUTSZ
)
3256 /* Write out the relocs. */
3257 for (current
= abfd
->sections
;
3258 current
!= (asection
*) NULL
;
3259 current
= current
->next
)
3262 arelent
**reloc_ptr_ptr
;
3263 arelent
**reloc_end
;
3266 if (current
->reloc_count
== 0)
3269 buff
= (RELOC
*) bfd_alloc (abfd
, current
->reloc_count
* RELSZ
);
3270 if (buff
== (RELOC
*) NULL
)
3272 bfd_error
= no_memory
;
3276 reloc_ptr_ptr
= current
->orelocation
;
3277 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
3279 for (; reloc_ptr_ptr
< reloc_end
; reloc_ptr_ptr
++, out_ptr
++)
3283 struct internal_reloc in
;
3285 memset (&in
, 0, sizeof in
);
3287 reloc
= *reloc_ptr_ptr
;
3288 sym
= *reloc
->sym_ptr_ptr
;
3290 in
.r_vaddr
= reloc
->address
+ bfd_get_section_vma (abfd
, current
);
3291 in
.r_type
= reloc
->howto
->type
;
3292 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
3294 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
3301 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
3302 if (strcmp (name
, ".text") == 0)
3303 in
.r_symndx
= RELOC_SECTION_TEXT
;
3304 else if (strcmp (name
, ".rdata") == 0)
3305 in
.r_symndx
= RELOC_SECTION_RDATA
;
3306 else if (strcmp (name
, ".data") == 0)
3307 in
.r_symndx
= RELOC_SECTION_DATA
;
3308 else if (strcmp (name
, ".sdata") == 0)
3309 in
.r_symndx
= RELOC_SECTION_SDATA
;
3310 else if (strcmp (name
, ".sbss") == 0)
3311 in
.r_symndx
= RELOC_SECTION_SBSS
;
3312 else if (strcmp (name
, ".bss") == 0)
3313 in
.r_symndx
= RELOC_SECTION_BSS
;
3314 else if (strcmp (name
, ".init") == 0)
3315 in
.r_symndx
= RELOC_SECTION_INIT
;
3316 else if (strcmp (name
, ".lit8") == 0)
3317 in
.r_symndx
= RELOC_SECTION_LIT8
;
3318 else if (strcmp (name
, ".lit4") == 0)
3319 in
.r_symndx
= RELOC_SECTION_LIT4
;
3325 ecoff_swap_reloc_out (abfd
, (PTR
) &in
, (PTR
) out_ptr
);
3328 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3330 if (bfd_write ((PTR
) buff
, RELSZ
, current
->reloc_count
, abfd
)
3331 != RELSZ
* current
->reloc_count
)
3333 bfd_release (abfd
, (PTR
) buff
);
3336 /* Write out the symbolic debugging information. */
3337 if (bfd_get_symcount (abfd
) > 0)
3340 unsigned long sym_offset
;
3341 struct hdr_ext buff
;
3343 /* Set up the offsets in the symbolic header. */
3344 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
3345 sym_offset
= ecoff_data (abfd
)->sym_filepos
+ sizeof (struct hdr_ext
);
3347 #define SET(offset, size, ptr) \
3348 if (symhdr->size == 0) \
3349 symhdr->offset = 0; \
3351 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3352 - (char *) ecoff_data (abfd)->raw_syments) \
3355 SET (cbLineOffset
, cbLine
, line
);
3356 SET (cbDnOffset
, idnMax
, external_dnr
);
3357 SET (cbPdOffset
, ipdMax
, external_pdr
);
3358 SET (cbSymOffset
, isymMax
, external_sym
);
3359 SET (cbOptOffset
, ioptMax
, external_opt
);
3360 SET (cbAuxOffset
, iauxMax
, external_aux
);
3361 SET (cbSsOffset
, issMax
, ss
);
3362 SET (cbSsExtOffset
, issExtMax
, ssext
);
3363 SET (cbFdOffset
, ifdMax
, external_fdr
);
3364 SET (cbRfdOffset
, crfd
, external_rfd
);
3365 SET (cbExtOffset
, iextMax
, external_ext
);
3368 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
,
3371 ecoff_swap_hdr_out (abfd
, &ecoff_data (abfd
)->symbolic_header
, &buff
);
3372 if (bfd_write ((PTR
) &buff
, 1, sizeof buff
, abfd
) != sizeof buff
)
3374 if (bfd_write ((PTR
) ecoff_data (abfd
)->raw_syments
, 1,
3375 ecoff_data (abfd
)->raw_size
, abfd
)
3376 != ecoff_data (abfd
)->raw_size
)
3383 /* Archive handling. ECOFF uses what appears to be a unique type of
3384 archive header (which I call an armap). The byte ordering of the
3385 armap and the contents are encoded in the name of the armap itself.
3386 At least for now, we only support archives with the same byte
3387 ordering in the armap and the contents.
3389 The first four bytes in the armap are the number of symbol
3390 definitions. This is always a power of two.
3392 This is followed by the symbol definitions. Each symbol definition
3393 occupies 8 bytes. The first four bytes are the offset from the
3394 start of the armap strings to the null-terminated string naming
3395 this symbol. The second four bytes are the file offset to the
3396 archive member which defines this symbol. If the second four bytes
3397 are 0, then this is not actually a symbol definition, and it should
3400 The symbols are hashed into the armap with a closed hashing scheme.
3401 See the functions below for the details of the algorithm.
3403 We could use the hash table when looking up symbols in a library.
3404 This would require a new BFD target entry point to replace the
3405 bfd_get_next_mapent function used by the linker.
3407 After the symbol definitions comes four bytes holding the size of
3408 the string table, followed by the string table itself. */
3410 /* The name of an archive headers looks like this:
3411 __________E[BL]E[BL]_ (with a trailing space).
3412 The trailing space is changed to an X if the archive is changed to
3413 indicate that the armap is out of date. */
3415 #define ARMAP_BIG_ENDIAN 'B'
3416 #define ARMAP_LITTLE_ENDIAN 'L'
3417 #define ARMAP_MARKER 'E'
3418 #define ARMAP_START "__________"
3419 #define ARMAP_HEADER_MARKER_INDEX 10
3420 #define ARMAP_HEADER_ENDIAN_INDEX 11
3421 #define ARMAP_OBJECT_MARKER_INDEX 12
3422 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3423 #define ARMAP_END_INDEX 14
3424 #define ARMAP_END "_ "
3426 /* This is a magic number used in the hashing algorithm. */
3427 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3429 /* This returns the hash value to use for a string. It also sets
3430 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3431 is the number of entries in the hash table, and HLOG is the log
3435 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3437 unsigned int *rehash
;
3445 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3446 hash
*= ARMAP_HASH_MAGIC
;
3447 *rehash
= (hash
& (size
- 1)) | 1;
3448 return hash
>> (32 - hlog
);
3451 /* Read in the armap. */
3454 DEFUN (ecoff_slurp_armap
, (abfd
),
3459 struct areltdata
*mapdata
;
3460 bfd_size_type parsed_size
;
3462 struct artdata
*ardata
;
3465 struct symdef
*symdef_ptr
;
3468 /* Get the name of the first element. */
3469 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3475 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
3477 /* See if the first element is an armap. */
3478 if (strncmp (nextname
, ARMAP_START
, sizeof ARMAP_START
- 1) != 0
3479 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3480 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3481 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3482 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3483 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3484 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3485 || strncmp (nextname
+ ARMAP_END_INDEX
,
3486 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3488 bfd_has_map (abfd
) = false;
3492 /* Make sure we have the right byte ordering. */
3493 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3494 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3495 || ((nextname
[ARMAP_OBJECT_MARKER_INDEX
] == ARMAP_BIG_ENDIAN
)
3496 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3498 bfd_error
= wrong_format
;
3502 /* Read in the armap. */
3503 ardata
= bfd_ardata (abfd
);
3504 mapdata
= snarf_ar_hdr (abfd
);
3505 if (mapdata
== (struct areltdata
*) NULL
)
3507 parsed_size
= mapdata
->parsed_size
;
3508 bfd_release (abfd
, (PTR
) mapdata
);
3510 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3511 if (raw_armap
== (char *) NULL
)
3513 bfd_error
= no_memory
;
3517 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3519 bfd_error
= malformed_archive
;
3520 bfd_release (abfd
, (PTR
) raw_armap
);
3524 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3526 ardata
->symdef_count
= 0;
3527 ardata
->cache
= (struct ar_cache
*) NULL
;
3529 /* Hack: overlay the symdefs on top of the raw archive data. This
3530 is the way do_slurp_bsd_armap works. */
3531 raw_ptr
= raw_armap
+ LONG_SIZE
;
3532 symdef_ptr
= (struct symdef
*) raw_ptr
;
3533 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3534 stringbase
= raw_ptr
+ count
* (2 * LONG_SIZE
) + LONG_SIZE
;
3536 #ifdef CHECK_ARMAP_HASH
3540 /* Double check that I have the hashing algorithm right by making
3541 sure that every symbol can be looked up successfully. */
3543 for (i
= 1; i
< count
; i
<<= 1)
3545 BFD_ASSERT (i
== count
);
3547 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3549 unsigned int name_offset
, file_offset
;
3550 unsigned int hash
, rehash
, srch
;
3552 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3553 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3554 if (file_offset
== 0)
3556 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3561 /* See if we can rehash to this location. */
3562 for (srch
= (hash
+ rehash
) & (count
- 1);
3563 srch
!= hash
&& srch
!= i
;
3564 srch
= (srch
+ rehash
) & (count
- 1))
3565 BFD_ASSERT (bfd_h_get_32 (abfd
,
3568 + (srch
* 2 * LONG_SIZE
)
3571 BFD_ASSERT (srch
== i
);
3575 raw_ptr
= raw_armap
+ LONG_SIZE
;
3576 #endif /* CHECK_ARMAP_HASH */
3578 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3580 unsigned int name_offset
, file_offset
;
3582 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3583 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3584 if (file_offset
== 0)
3586 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3587 symdef_ptr
->file_offset
= file_offset
;
3589 ++ardata
->symdef_count
;
3592 ardata
->first_file_filepos
= bfd_tell (abfd
);
3593 /* Pad to an even boundary. */
3594 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3596 bfd_has_map (abfd
) = true;
3601 /* Write out an armap. */
3604 DEFUN (ecoff_write_armap
, (abfd
, elength
, map
, orl_count
, stridx
),
3606 unsigned int elength AND
3608 unsigned int orl_count AND
3611 unsigned int hashsize
, hashlog
;
3612 unsigned int symdefsize
;
3614 unsigned int stringsize
;
3615 unsigned int mapsize
;
3618 struct stat statbuf
;
3620 bfd_byte temp
[LONG_SIZE
];
3621 bfd_byte
*hashtable
;
3625 /* Ultrix appears to use as a hash table size the least power of two
3626 greater than twice the number of entries. */
3627 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3629 hashsize
= 1 << hashlog
;
3631 symdefsize
= hashsize
* 2 * LONG_SIZE
;
3633 stringsize
= stridx
+ padit
;
3635 /* Include 8 bytes to store symdefsize and stringsize in output. */
3636 mapsize
= LONG_SIZE
+ symdefsize
+ stringsize
+ LONG_SIZE
;
3638 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3640 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3642 /* Work out the ECOFF armap name. */
3643 strcpy (hdr
.ar_name
, ARMAP_START
);
3644 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3645 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3646 (abfd
->xvec
->header_byteorder_big_p
3648 : ARMAP_LITTLE_ENDIAN
);
3649 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3650 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3651 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3652 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3654 /* Write the timestamp of the archive header to be just a little bit
3655 later than the timestamp of the file, otherwise the linker will
3656 complain that the index is out of date. Actually, the Ultrix
3657 linker just checks the archive name; the GNU linker may check the
3659 if (stat (abfd
->filename
, &statbuf
) < 0)
3660 statbuf
.st_mtime
= time ((PTR
) NULL
);
3661 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3663 /* The DECstation uses zeroes for the uid, gid and mode of the
3665 hdr
.ar_uid
[0] = '0';
3666 hdr
.ar_gid
[0] = '0';
3667 hdr
.ar_mode
[0] = '0';
3669 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3671 hdr
.ar_fmag
[0] = '`';
3672 hdr
.ar_fmag
[1] = '\n';
3674 /* Turn all null bytes in the header into spaces. */
3675 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3676 if (((char *)(&hdr
))[i
] == '\0')
3677 (((char *)(&hdr
))[i
]) = ' ';
3679 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3680 != sizeof (struct ar_hdr
))
3683 bfd_h_put_32 (abfd
, hashsize
, temp
);
3684 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
3687 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3689 current
= abfd
->archive_head
;
3691 for (i
= 0; i
< orl_count
; i
++)
3693 unsigned int hash
, rehash
;
3695 /* Advance firstreal to the file position of this archive
3697 if (((bfd
*) map
[i
].pos
) != last_elt
)
3701 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3702 firstreal
+= firstreal
% 2;
3703 current
= current
->next
;
3705 while (current
!= (bfd
*) map
[i
].pos
);
3710 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3711 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
3712 + (hash
* 2 * LONG_SIZE
)
3718 /* The desired slot is already taken. */
3719 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3721 srch
= (srch
+ rehash
) & (hashsize
- 1))
3722 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
3723 + (srch
* 2 * LONG_SIZE
)
3728 BFD_ASSERT (srch
!= hash
);
3733 bfd_h_put_32 (abfd
, map
[i
].namidx
,
3734 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
));
3735 bfd_h_put_32 (abfd
, firstreal
,
3736 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
+ LONG_SIZE
));
3739 if (bfd_write (hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3742 bfd_release (abfd
, hashtable
);
3744 /* Now write the strings. */
3745 bfd_h_put_32 (abfd
, stringsize
, temp
);
3746 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
3748 for (i
= 0; i
< orl_count
; i
++)
3752 len
= strlen (*map
[i
].name
) + 1;
3753 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3757 /* The spec sez this should be a newline. But in order to be
3758 bug-compatible for DECstation ar we use a null. */
3761 if (bfd_write ("\0", 1, 1, abfd
) != 1)
3768 /* We just use the generic extended name support. This is a GNU
3770 #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
3772 /* See whether this BFD is an archive. If it is, read in the armap
3773 and the extended name table. */
3776 DEFUN (ecoff_archive_p
, (abfd
),
3779 char armag
[SARMAG
+ 1];
3781 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3782 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3784 bfd_error
= wrong_format
;
3785 return (bfd_target
*) NULL
;
3788 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3789 involves a cast, we can't do it as the left operand of
3791 abfd
->tdata
.aout_ar_data
=
3792 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3794 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3796 bfd_error
= no_memory
;
3797 return (bfd_target
*) NULL
;
3800 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3802 if (ecoff_slurp_armap (abfd
) == false
3803 || ecoff_slurp_extended_name_table (abfd
) == false)
3805 bfd_release (abfd
, bfd_ardata (abfd
));
3806 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3807 return (bfd_target
*) NULL
;
3813 static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table
= {
3814 (void (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_in */
3815 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_in */
3816 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_in */
3817 (unsigned (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_out */
3818 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_out */
3819 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_out */
3820 ecoff_swap_reloc_out
, ecoff_swap_filehdr_out
, ecoff_swap_aouthdr_out
,
3821 ecoff_swap_scnhdr_out
,
3822 FILHSZ
, AOUTSZ
, SCNHSZ
, 0, 0, 0, true,
3823 ecoff_swap_filehdr_in
, ecoff_swap_aouthdr_in
, ecoff_swap_scnhdr_in
,
3824 ecoff_bad_format_hook
, ecoff_set_arch_mach_hook
, ecoff_mkobject_hook
,
3825 styp_to_sec_flags
, ecoff_make_section_hook
, ecoff_set_alignment_hook
,
3826 ecoff_slurp_symbol_table
3829 /* get_lineno could be written for ECOFF, but it would currently only
3830 be useful for linking ECOFF and COFF files together, which doesn't
3832 #define ecoff_get_lineno \
3833 ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr)
3835 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
3836 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
3837 #define ecoff_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
3838 #define ecoff_truncate_arname bfd_dont_truncate_arname
3839 #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file
3840 #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
3841 #define ecoff_get_section_contents bfd_generic_get_section_contents
3842 #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
3843 #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup
3844 #define ecoff_sizeof_headers coff_sizeof_headers
3845 #define ecoff_bfd_debug_info_start bfd_void
3846 #define ecoff_bfd_debug_info_end bfd_void
3847 #define ecoff_bfd_debug_info_accumulate \
3848 ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void)
3849 #define ecoff_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
3850 #define ecoff_bfd_relax_section bfd_generic_relax_section
3852 bfd_target ecoff_little_vec
=
3854 "ecoff-littlemips", /* name */
3855 bfd_target_ecoff_flavour
,
3856 false, /* data byte order is little */
3857 false, /* header byte order is little */
3859 (HAS_RELOC
| EXEC_P
| /* object flags */
3860 HAS_LINENO
| HAS_DEBUG
|
3861 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
),
3863 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect
3865 0, /* leading underscore */
3866 '/', /* ar_pad_char */
3867 15, /* ar_max_namelen */
3868 3, /* minimum alignment power */
3869 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* data */
3870 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* hdrs */
3872 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
3873 ecoff_archive_p
, _bfd_dummy_target
},
3874 {bfd_false
, ecoff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
3876 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
3877 _bfd_write_archive_contents
, bfd_false
},
3880 (PTR
) &bfd_ecoff_std_swap_table
3883 bfd_target ecoff_big_vec
=
3885 "ecoff-bigmips", /* name */
3886 bfd_target_ecoff_flavour
,
3887 true, /* data byte order is big */
3888 true, /* header byte order is big */
3890 (HAS_RELOC
| EXEC_P
| /* object flags */
3891 HAS_LINENO
| HAS_DEBUG
|
3892 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
),
3894 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect flags */
3895 0, /* leading underscore */
3896 ' ', /* ar_pad_char */
3897 16, /* ar_max_namelen */
3898 3, /* minimum alignment power */
3899 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
,
3900 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
,
3901 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
3902 ecoff_archive_p
, _bfd_dummy_target
},
3903 {bfd_false
, ecoff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
3905 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
3906 _bfd_write_archive_contents
, bfd_false
},
3909 (PTR
) &bfd_ecoff_std_swap_table
3910 /* Note that there is another bfd_target just above this one. If
3911 you are adding initializers here, you should be adding them there