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. */
26 #include "coff/mips.h"
27 #include "coff/internal.h"
29 #include "coff/symconst.h"
30 #include "coff/ecoff-ext.h"
33 /* `Tdata' information kept for ECOFF files. */
35 #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data)
37 typedef struct ecoff_tdata
39 /* The reloc file position, set by
40 ecoff_compute_section_file_positions. */
41 file_ptr reloc_filepos
;
43 /* The symbol table file position, set by ecoff_mkobject_hook. */
46 /* The size of the unswapped ECOFF symbolic information. */
47 bfd_size_type raw_size
;
49 /* The unswapped ECOFF symbolic information. */
52 /* The swapped ECOFF symbolic header. */
55 /* Pointers to the unswapped symbolic information. */
57 struct dnr_ext
*external_dnr
;
58 struct pdr_ext
*external_pdr
;
59 struct sym_ext
*external_sym
;
60 struct opt_ext
*external_opt
;
61 union aux_ext
*external_aux
;
64 struct fdr_ext
*external_fdr
;
65 struct rfd_ext
*external_rfd
;
66 struct ext_ext
*external_ext
;
68 /* The swapped fdr information. */
71 /* The canonical BFD symbols. */
72 struct ecoff_symbol_struct
*canonical_symbols
;
76 /* Each canonical asymbol really looks like this. */
78 typedef struct ecoff_symbol_struct
80 /* The actual symbol which the rest of BFD works with */
83 /* The fdr for this symbol. */
86 /* true if this is a local symbol rather than an external one. */
89 /* A pointer to the unswapped hidden information for this symbol */
92 struct sym_ext
*lnative
;
93 struct ext_ext
*enative
;
98 /* We take the address of the first element of a asymbol to ensure that the
99 macro is only ever applied to an asymbol. */
100 #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd)))
102 /* MIPS ECOFF has COFF sections, but the debugging information is
103 stored in a completely different format. This files uses the some
104 of the swapping routines from coffswap.h, and some of the generic
105 COFF routines in coffgen.c, but, unlike the real COFF targets, does
106 not use coffcode.h itself. */
108 /* Get the generic COFF swapping routines, except for the reloc,
109 symbol, and lineno ones. Give them ecoff names. */
110 #define NO_COFF_RELOCS
111 #define NO_COFF_SYMBOLS
112 #define NO_COFF_LINENOS
113 #define coff_swap_filehdr_in ecoff_swap_filehdr_in
114 #define coff_swap_filehdr_out ecoff_swap_filehdr_out
115 #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in
116 #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out
117 #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in
118 #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out
119 #include "coffswap.h"
121 /* This stuff is somewhat copied from coffcode.h. */
123 static asection bfd_debug_section
= { "*DEBUG*" };
125 /* See whether the magic number matches. */
128 DEFUN(ecoff_bad_format_hook
, (abfd
, filehdr
),
132 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
134 if (ECOFFBADMAG (*internal_f
))
140 /* This is a hook needed by SCO COFF, but we have nothing to do. */
143 DEFUN (ecoff_make_section_hook
, (abfd
, name
),
147 return (asection
*) NULL
;
150 /* Initialize a new section. */
153 DEFUN (ecoff_new_section_hook
, (abfd
, section
),
157 section
->alignment_power
= abfd
->xvec
->align_power_min
;
159 if (strcmp (section
->name
, _TEXT
) == 0)
160 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
161 else if (strcmp (section
->name
, _DATA
) == 0
162 || strcmp (section
->name
, _SDATA
) == 0)
163 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
164 else if (strcmp (section
->name
, _RDATA
) == 0
165 || strcmp (section
->name
, _LIT8
) == 0
166 || strcmp (section
->name
, _LIT4
) == 0)
167 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
168 else if (strcmp (section
->name
, _BSS
) == 0
169 || strcmp (section
->name
, _SBSS
) == 0)
170 section
->flags
|= SEC_ALLOC
;
172 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
173 uncertain about .init on some systems and I don't know how shared
179 #define ecoff_set_alignment_hook \
180 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
183 DEFUN (ecoff_mkobject
, (abfd
),
186 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
187 bfd_zalloc (abfd
, sizeof(ecoff_data_type
)));
188 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
190 bfd_error
= no_memory
;
197 /* Create the COFF backend specific information. */
200 DEFUN(ecoff_mkobject_hook
,(abfd
, filehdr
),
204 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
205 ecoff_data_type
*ecoff
;
207 if (ecoff_mkobject (abfd
) == false)
210 ecoff
= ecoff_data (abfd
);
211 ecoff
->sym_filepos
= internal_f
->f_symptr
;
215 /* Determine the machine architecture and type. */
217 DEFUN (ecoff_set_arch_mach_hook
, (abfd
, filehdr
),
222 enum bfd_architecture arch
;
223 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
226 switch (internal_f
->f_magic
) {
230 arch
= bfd_arch_mips
;
234 default: /* Unreadable input file type */
235 arch
= bfd_arch_obscure
;
239 bfd_default_set_arch_mach(abfd
, arch
, machine
);
243 /* Get the section s_flags to use for a section. */
246 DEFUN (sec_to_styp_flags
, (name
, flags
),
254 if (strcmp (name
, _TEXT
) == 0)
256 else if (strcmp (name
, _DATA
) == 0)
258 else if (strcmp (name
, _SDATA
) == 0)
260 else if (strcmp (name
, _RDATA
) == 0)
262 else if (strcmp (name
, _LIT8
) == 0)
264 else if (strcmp (name
, _LIT4
) == 0)
266 else if (strcmp (name
, _BSS
) == 0)
268 else if (strcmp (name
, _SBSS
) == 0)
270 else if (flags
& SEC_CODE
)
272 else if (flags
& SEC_DATA
)
274 else if (flags
& SEC_READONLY
)
276 else if (flags
& SEC_LOAD
)
281 if (flags
& SEC_NEVER_LOAD
)
287 /* Get the BFD flags to use for a section. */
290 DEFUN (styp_to_sec_flags
, (abfd
, hdr
),
294 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
295 long styp_flags
= internal_s
->s_flags
;
296 flagword sec_flags
=0;
298 if (styp_flags
& STYP_NOLOAD
)
299 sec_flags
|= SEC_NEVER_LOAD
;
301 /* For 386 COFF, at least, an unloadable text or data section is
302 actually a shared library section. */
303 if (styp_flags
& STYP_TEXT
)
305 if (sec_flags
& SEC_NEVER_LOAD
)
306 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
308 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
310 else if ((styp_flags
& STYP_DATA
)
311 || (styp_flags
& STYP_RDATA
)
312 || (styp_flags
& STYP_SDATA
))
314 if (sec_flags
& SEC_NEVER_LOAD
)
315 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
317 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
318 if (styp_flags
& STYP_RDATA
)
319 sec_flags
|= SEC_READONLY
;
321 else if ((styp_flags
& STYP_BSS
)
322 || (styp_flags
& STYP_SBSS
))
324 sec_flags
|= SEC_ALLOC
;
326 else if (styp_flags
& STYP_INFO
)
328 sec_flags
|= SEC_NEVER_LOAD
;
330 else if ((styp_flags
& STYP_LIT8
)
331 || (styp_flags
& STYP_LIT4
))
333 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
337 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
343 /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in
344 external form. They use a bit which indicates whether the symbol
347 /* Swap a reloc in. */
350 DEFUN (ecoff_swap_reloc_in
, (abfd
, ext
, intern
),
353 struct internal_reloc
*intern
)
355 intern
->r_vaddr
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->r_vaddr
);
356 if (abfd
->xvec
->header_byteorder_big_p
!= false)
358 intern
->r_symndx
= ((ext
->r_bits
[0]
359 << RELOC_BITS0_SYMNDX_SH_LEFT_BIG
)
361 << RELOC_BITS1_SYMNDX_SH_LEFT_BIG
)
363 << RELOC_BITS2_SYMNDX_SH_LEFT_BIG
));
364 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_BIG
)
365 >> RELOC_BITS3_TYPE_SH_BIG
);
366 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_BIG
) != 0;
370 intern
->r_symndx
= ((ext
->r_bits
[0]
371 << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
)
373 << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
)
375 << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
));
376 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_LITTLE
)
377 >> RELOC_BITS3_TYPE_SH_LITTLE
);
378 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_LITTLE
) != 0;
382 /* Swap a reloc out. */
385 DEFUN (ecoff_swap_reloc_out
, (abfd
, src
, dst
),
390 struct internal_reloc
*intern
= (struct internal_reloc
*) src
;
391 RELOC
*ext
= (RELOC
*) dst
;
393 bfd_h_put_32 (abfd
, intern
->r_vaddr
, (bfd_byte
*) ext
->r_vaddr
);
394 if (abfd
->xvec
->header_byteorder_big_p
!= false)
396 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_BIG
;
397 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_BIG
;
398 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_BIG
;
399 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_BIG
)
400 & RELOC_BITS3_TYPE_BIG
)
401 | (intern
->r_extern
? RELOC_BITS3_EXTERN_BIG
: 0));
405 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
;
406 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
;
407 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
;
408 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_LITTLE
)
409 & RELOC_BITS3_TYPE_LITTLE
)
410 | (intern
->r_extern
? RELOC_BITS3_EXTERN_LITTLE
: 0));
416 /* Read in and swap the important symbolic information for an ECOFF
420 DEFUN (ecoff_slurp_symbolic_info
, (abfd
),
423 struct hdr_ext external_symhdr
;
424 HDRR
*internal_symhdr
;
425 bfd_size_type raw_base
;
426 bfd_size_type raw_size
;
428 struct fdr_ext
*fraw_src
;
429 struct fdr_ext
*fraw_end
;
432 /* Check whether we've already gotten it, and whether there's any to
434 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
436 if (ecoff_data (abfd
)->sym_filepos
== 0)
438 bfd_get_symcount (abfd
) = 0;
442 /* At this point bfd_get_symcount (abfd) holds the number of symbols
443 as read from the file header, but on ECOFF this is always the
444 size of the symbolic information header. It would be cleaner to
445 handle this when we first read the file in coffgen.c. */
446 if (bfd_get_symcount (abfd
) != sizeof (external_symhdr
))
448 bfd_error
= bad_value
;
452 /* Read the symbolic information header. */
453 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
454 || (bfd_read ((PTR
) &external_symhdr
, sizeof (external_symhdr
), 1, abfd
)
455 != sizeof (external_symhdr
)))
457 bfd_error
= system_call_error
;
460 internal_symhdr
= &ecoff_data (abfd
)->symbolic_header
;
461 ecoff_swap_hdr_in (abfd
, &external_symhdr
, internal_symhdr
);
463 if (internal_symhdr
->magic
!= magicSym
)
465 bfd_error
= bad_value
;
469 /* Now we can get the correct number of symbols. */
470 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
471 + internal_symhdr
->iextMax
);
473 /* Read all the symbolic information at once. This expression
474 assumes that the external symbols are always the last item. */
475 raw_base
= ecoff_data (abfd
)->sym_filepos
+ sizeof (external_symhdr
);
476 raw_size
= (internal_symhdr
->cbExtOffset
- raw_base
477 + internal_symhdr
->iextMax
* sizeof (struct ext_ext
));
478 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
481 bfd_error
= no_memory
;
484 if (bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
486 bfd_error
= system_call_error
;
487 bfd_release (abfd
, raw
);
491 ecoff_data (abfd
)->raw_size
= raw_size
;
492 ecoff_data (abfd
)->raw_syments
= raw
;
494 /* Get pointers for the numeric offsets in the HDRR structure. */
495 #define FIX(off1, off2, type) \
496 if (internal_symhdr->off1 == 0) \
497 ecoff_data (abfd)->off2 = (type *) NULL; \
499 ecoff_data (abfd)->off2 = (type *) ((char *) raw \
500 + internal_symhdr->off1 \
502 FIX (cbLineOffset
, line
, unsigned char);
503 FIX (cbDnOffset
, external_dnr
, struct dnr_ext
);
504 FIX (cbPdOffset
, external_pdr
, struct pdr_ext
);
505 FIX (cbSymOffset
, external_sym
, struct sym_ext
);
506 FIX (cbOptOffset
, external_opt
, struct opt_ext
);
507 FIX (cbAuxOffset
, external_aux
, union aux_ext
);
508 FIX (cbSsOffset
, ss
, char);
509 FIX (cbSsExtOffset
, ssext
, char);
510 FIX (cbFdOffset
, external_fdr
, struct fdr_ext
);
511 FIX (cbRfdOffset
, external_rfd
, struct rfd_ext
);
512 FIX (cbExtOffset
, external_ext
, struct ext_ext
);
515 /* I don't want to always swap all the data, because it will just
516 waste time and most programs will never look at it. The only
517 time the linker needs most of the debugging information swapped
518 is when linking big-endian and little-endian MIPS object files
519 together, which is not a common occurrence.
521 We need to look at the fdr to deal with a lot of information in
522 the symbols, so we swap them here. */
523 ecoff_data (abfd
)->fdr
= (struct fdr
*) bfd_alloc (abfd
,
524 (internal_symhdr
->ifdMax
*
525 sizeof (struct fdr
)));
526 if (ecoff_data (abfd
)->fdr
== NULL
)
528 bfd_error
= no_memory
;
531 fdr_ptr
= ecoff_data (abfd
)->fdr
;
532 fraw_src
= ecoff_data (abfd
)->external_fdr
;
533 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
;
534 for (; fraw_src
< fraw_end
; fraw_src
++, fdr_ptr
++)
535 ecoff_swap_fdr_in (abfd
, fraw_src
, fdr_ptr
);
540 /* ECOFF symbol table routines. The ECOFF symbol table is described
541 in gcc/mips-tfile.c. */
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 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
581 asym
->flags
= BSF_LOCAL
;
582 switch (ecoff_sym
->sc
)
588 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
589 asym
->value
-= asym
->section
->vma
;
592 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
593 asym
->value
-= asym
->section
->vma
;
596 asym
->section
= &bfd_com_section
;
600 asym
->flags
= BSF_DEBUGGING
;
603 asym
->section
= &bfd_abs_section
;
607 asym
->section
= &bfd_und_section
;
616 asym
->flags
= BSF_DEBUGGING
;
619 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
620 asym
->value
-= asym
->section
->vma
;
623 asym
->section
= &bfd_com_section
;
627 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
628 asym
->value
-= asym
->section
->vma
;
631 asym
->flags
= BSF_DEBUGGING
;
635 asym
->section
= &bfd_com_section
;
640 asym
->flags
= BSF_DEBUGGING
;
643 asym
->section
= &bfd_und_section
;
647 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
648 asym
->value
-= asym
->section
->vma
;
653 asym
->flags
= BSF_DEBUGGING
;
656 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
657 asym
->value
-= asym
->section
->vma
;
665 /* Read an ECOFF symbol table. */
668 DEFUN (ecoff_slurp_symbol_table
, (abfd
),
671 bfd_size_type internal_size
;
672 ecoff_symbol_type
*internal
;
673 ecoff_symbol_type
*internal_ptr
;
674 struct ext_ext
*eraw_src
;
675 struct ext_ext
*eraw_end
;
679 /* If we've already read in the symbol table, do nothing. */
680 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
683 /* Get the symbolic information. */
684 if (ecoff_slurp_symbolic_info (abfd
) == false)
686 if (bfd_get_symcount (abfd
) == 0)
689 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
690 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
691 if (internal
== NULL
)
693 bfd_error
= no_memory
;
697 internal_ptr
= internal
;
698 eraw_src
= ecoff_data (abfd
)->external_ext
;
699 eraw_end
= eraw_src
+ ecoff_data (abfd
)->symbolic_header
.iextMax
;
700 for (; eraw_src
< eraw_end
; eraw_src
++, internal_ptr
++)
704 ecoff_swap_ext_in (abfd
, eraw_src
, &internal_esym
);
705 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ssext
706 + internal_esym
.asym
.iss
);
707 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
708 &internal_ptr
->symbol
, 1);
709 internal_ptr
->fdr
= ecoff_data (abfd
)->fdr
+ internal_esym
.ifd
;
710 internal_ptr
->local
= false;
711 internal_ptr
->native
.enative
= eraw_src
;
714 /* The local symbols must be accessed via the fdr's, because the
715 string and aux indices are relative to the fdr information. */
716 fdr_ptr
= ecoff_data (abfd
)->fdr
;
717 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
718 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
720 struct sym_ext
*lraw_src
;
721 struct sym_ext
*lraw_end
;
723 lraw_src
= ecoff_data (abfd
)->external_sym
+ fdr_ptr
->isymBase
;
724 lraw_end
= lraw_src
+ fdr_ptr
->csym
;
725 for (; lraw_src
< lraw_end
; lraw_src
++, internal_ptr
++)
729 ecoff_swap_sym_in (abfd
, lraw_src
, &internal_sym
);
730 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ss
733 ecoff_set_symbol_info (abfd
, &internal_sym
,
734 &internal_ptr
->symbol
, 0);
735 internal_ptr
->fdr
= fdr_ptr
;
736 internal_ptr
->local
= true;
737 internal_ptr
->native
.lnative
= lraw_src
;
741 ecoff_data (abfd
)->canonical_symbols
= internal
;
747 DEFUN (ecoff_get_symtab_upper_bound
, (abfd
),
750 if (ecoff_slurp_symbolic_info (abfd
) == false
751 || bfd_get_symcount (abfd
) == 0)
754 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
758 DEFUN (ecoff_get_symtab
, (abfd
, alocation
),
762 unsigned int counter
= 0;
763 ecoff_symbol_type
*symbase
;
764 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
766 if (ecoff_slurp_symbol_table (abfd
) == false
767 || bfd_get_symcount (abfd
) == 0)
770 symbase
= ecoff_data (abfd
)->canonical_symbols
;
771 while (counter
< bfd_get_symcount (abfd
))
773 *(location
++) = symbase
++;
776 *location
++ = (ecoff_symbol_type
*) NULL
;
777 return bfd_get_symcount (abfd
);
780 /* Turn ECOFF type information into a printable string.
781 emit_aggregate and type_to_string are from gcc/mips-tdump.c, with
782 swapping added and used_ptr removed. */
784 /* Write aggregate information to a string. */
787 DEFUN (emit_aggregate
, (abfd
, string
, rndx
, isym
, which
),
795 int indx
= rndx
->index
;
796 int sym_base
, ss_base
;
802 sym_base
= ecoff_data (abfd
)->fdr
[ifd
].isymBase
;
803 ss_base
= ecoff_data (abfd
)->fdr
[ifd
].issBase
;
805 if (indx
== indexNil
)
806 name
= "/* no name */";
812 ecoff_swap_sym_in (abfd
,
813 ecoff_data (abfd
)->external_sym
+ indx
,
815 name
= ecoff_data (abfd
)->ss
+ ss_base
+ sym
.iss
;
819 "%s %s { ifd = %d, index = %d }",
821 indx
+ ecoff_data (abfd
)->symbolic_header
.iextMax
);
824 /* Convert the type information to string format. */
827 DEFUN (type_to_string
, (abfd
, aux_ptr
, indx
, bigendian
),
829 union aux_ext
*aux_ptr AND
841 unsigned int basic_type
;
843 static char buffer1
[1024];
844 static char buffer2
[1024];
849 for (i
= 0; i
< 7; i
++)
851 qualifiers
[i
].low_bound
= 0;
852 qualifiers
[i
].high_bound
= 0;
853 qualifiers
[i
].stride
= 0;
856 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
857 return "-1 (no type)";
858 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
860 basic_type
= u
.ti
.bt
;
861 qualifiers
[0].type
= u
.ti
.tq0
;
862 qualifiers
[1].type
= u
.ti
.tq1
;
863 qualifiers
[2].type
= u
.ti
.tq2
;
864 qualifiers
[3].type
= u
.ti
.tq3
;
865 qualifiers
[4].type
= u
.ti
.tq4
;
866 qualifiers
[5].type
= u
.ti
.tq5
;
867 qualifiers
[6].type
= tqNil
;
870 * Go get the basic type.
874 case btNil
: /* undefined */
878 case btAdr
: /* address - integer same size as pointer */
879 strcpy (p1
, "address");
882 case btChar
: /* character */
886 case btUChar
: /* unsigned character */
887 strcpy (p1
, "unsigned char");
890 case btShort
: /* short */
891 strcpy (p1
, "short");
894 case btUShort
: /* unsigned short */
895 strcpy (p1
, "unsigned short");
898 case btInt
: /* int */
902 case btUInt
: /* unsigned int */
903 strcpy (p1
, "unsigned int");
906 case btLong
: /* long */
910 case btULong
: /* unsigned long */
911 strcpy (p1
, "unsigned long");
914 case btFloat
: /* float (real) */
915 strcpy (p1
, "float");
918 case btDouble
: /* Double (real) */
919 strcpy (p1
, "double");
922 /* Structures add 1-2 aux words:
923 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
924 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
926 case btStruct
: /* Structure (Record) */
927 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
928 emit_aggregate (abfd
, p1
, &rndx
,
929 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
931 indx
++; /* skip aux words */
934 /* Unions add 1-2 aux words:
935 1st word is [ST_RFDESCAPE, offset] pointer to union def;
936 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
938 case btUnion
: /* Union */
939 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
940 emit_aggregate (abfd
, p1
, &rndx
,
941 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
943 indx
++; /* skip aux words */
946 /* Enumerations add 1-2 aux words:
947 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
948 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
950 case btEnum
: /* Enumeration */
951 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
952 emit_aggregate (abfd
, p1
, &rndx
,
953 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
955 indx
++; /* skip aux words */
958 case btTypedef
: /* defined via a typedef, isymRef points */
959 strcpy (p1
, "typedef");
962 case btRange
: /* subrange of int */
963 strcpy (p1
, "subrange");
966 case btSet
: /* pascal sets */
970 case btComplex
: /* fortran complex */
971 strcpy (p1
, "complex");
974 case btDComplex
: /* fortran double complex */
975 strcpy (p1
, "double complex");
978 case btIndirect
: /* forward or unnamed typedef */
979 strcpy (p1
, "forward/unamed typedef");
982 case btFixedDec
: /* Fixed Decimal */
983 strcpy (p1
, "fixed decimal");
986 case btFloatDec
: /* Float Decimal */
987 strcpy (p1
, "float decimal");
990 case btString
: /* Varying Length Character String */
991 strcpy (p1
, "string");
994 case btBit
: /* Aligned Bit String */
998 case btPicture
: /* Picture */
999 strcpy (p1
, "picture");
1002 case btVoid
: /* Void */
1003 strcpy (p1
, "void");
1007 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1011 p1
+= strlen (buffer1
);
1014 * If this is a bitfield, get the bitsize.
1020 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1021 sprintf (p1
, " : %d", bitsize
);
1022 p1
+= strlen (buffer1
);
1027 * Deal with any qualifiers.
1029 if (qualifiers
[0].type
!= tqNil
)
1032 * Snarf up any array bounds in the correct order. Arrays
1033 * store 5 successive words in the aux. table:
1034 * word 0 RNDXR to type of the bounds (ie, int)
1035 * word 1 Current file descriptor index
1037 * word 3 high bound (or -1 if [])
1038 * word 4 stride size in bits
1040 for (i
= 0; i
< 7; i
++)
1042 if (qualifiers
[i
].type
== tqArray
)
1044 qualifiers
[i
].low_bound
=
1045 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1046 qualifiers
[i
].high_bound
=
1047 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1048 qualifiers
[i
].stride
=
1049 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1055 * Now print out the qualifiers.
1057 for (i
= 0; i
< 6; i
++)
1059 switch (qualifiers
[i
].type
)
1066 strcpy (p2
, "ptr to ");
1067 p2
+= sizeof ("ptr to ")-1;
1071 strcpy (p2
, "volatile ");
1072 p2
+= sizeof ("volatile ")-1;
1076 strcpy (p2
, "far ");
1077 p2
+= sizeof ("far ")-1;
1081 strcpy (p2
, "func. ret. ");
1082 p2
+= sizeof ("func. ret. ");
1087 int first_array
= i
;
1090 /* Print array bounds reversed (ie, in the order the C
1091 programmer writes them). C is such a fun language.... */
1093 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1096 for (j
= i
; j
>= first_array
; j
--)
1098 strcpy (p2
, "array [");
1099 p2
+= sizeof ("array [")-1;
1100 if (qualifiers
[j
].low_bound
!= 0)
1102 "%ld:%ld {%ld bits}",
1103 (long) qualifiers
[j
].low_bound
,
1104 (long) qualifiers
[j
].high_bound
,
1105 (long) qualifiers
[j
].stride
);
1107 else if (qualifiers
[j
].high_bound
!= -1)
1110 (long) (qualifiers
[j
].high_bound
+ 1),
1111 (long) (qualifiers
[j
].stride
));
1114 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1117 strcpy (p2
, "] of ");
1118 p2
+= sizeof ("] of ")-1;
1126 strcpy (p2
, buffer1
);
1130 /* Print information about an ECOFF symbol. */
1133 DEFUN (ecoff_print_symbol
, (abfd
, filep
, symbol
, how
),
1137 bfd_print_symbol_type how
)
1139 FILE *file
= (FILE *)filep
;
1143 case bfd_print_symbol_name
:
1144 fprintf (file
, "%s", symbol
->name
);
1146 case bfd_print_symbol_more
:
1147 if (ecoffsymbol (symbol
)->local
)
1151 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1153 fprintf (file
, "ecoff local %lx %x %x",
1154 (unsigned long) ecoff_sym
.value
,
1155 (unsigned) ecoff_sym
.st
, (unsigned) ecoff_sym
.sc
);
1161 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1163 fprintf (file
, "ecoff extern %lx %x %x",
1164 (unsigned long) ecoff_ext
.asym
.value
,
1165 (unsigned) ecoff_ext
.asym
.st
,
1166 (unsigned) ecoff_ext
.asym
.sc
);
1169 case bfd_print_symbol_nm
:
1171 CONST
char *section_name
= symbol
->section
->name
;
1173 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
1174 fprintf (file
, " %-5s %s %s",
1176 ecoffsymbol (symbol
)->local
? "l" : "e",
1180 case bfd_print_symbol_all
:
1181 /* Print out the symbols in a reasonable way */
1190 if (ecoffsymbol (symbol
)->local
)
1192 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1195 pos
= (ecoffsymbol (symbol
)->native
.lnative
1196 - ecoff_data (abfd
)->external_sym
1197 + ecoff_data (abfd
)->symbolic_header
.iextMax
);
1204 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1207 pos
= (ecoffsymbol (symbol
)->native
.enative
1208 - ecoff_data (abfd
)->external_ext
);
1209 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1210 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1211 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1214 fprintf (file
, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s",
1215 pos
, type
, (unsigned long) ecoff_ext
.asym
.value
,
1216 (unsigned) ecoff_ext
.asym
.st
,
1217 (unsigned) ecoff_ext
.asym
.sc
,
1218 (unsigned) ecoff_ext
.asym
.index
,
1219 jmptbl
, cobol_main
, weakext
,
1222 if (ecoffsymbol (symbol
)->fdr
!= NULL
1223 && ecoff_ext
.asym
.index
!= indexNil
)
1228 union aux_ext
*aux_base
;
1230 indx
= ecoff_ext
.asym
.index
;
1232 /* sym_base is used to map the fdr relative indices which
1233 appear in the file to the position number which we are
1235 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1236 if (ecoffsymbol (symbol
)->local
)
1237 sym_base
+= ecoff_data (abfd
)->symbolic_header
.iextMax
;
1239 /* aux_base is the start of the aux entries for this file;
1240 asym.index is an offset from this. */
1241 aux_base
= (ecoff_data (abfd
)->external_aux
1242 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1244 /* The aux entries are stored in host byte order; the
1245 order is indicated by a bit in the fdr. */
1246 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1248 /* This switch is basically from gcc/mips-tdump.c */
1249 switch (ecoff_ext
.asym
.st
)
1257 printf ("\n End+1 symbol: %ld", indx
+ sym_base
);
1261 if (ecoff_ext
.asym
.sc
== scText
1262 || ecoff_ext
.asym
.sc
== scInfo
)
1263 printf ("\n First symbol: %ld", indx
+ sym_base
);
1265 printf ("\n First symbol: %ld",
1266 (AUX_GET_ISYM (bigendian
,
1267 &aux_base
[ecoff_ext
.asym
.index
])
1273 if (MIPS_IS_STAB (&ecoff_ext
.asym
))
1275 else if (ecoffsymbol (symbol
)->local
)
1276 printf ("\n End+1 symbol: %-7ld Type: %s",
1277 (AUX_GET_ISYM (bigendian
,
1278 &aux_base
[ecoff_ext
.asym
.index
])
1280 type_to_string (abfd
, aux_base
, indx
+ 1,
1283 printf ("\n Type: %s",
1284 type_to_string (abfd
, aux_base
, indx
, bigendian
));
1289 if (!MIPS_IS_STAB (&ecoff_ext
.asym
))
1290 printf ("\n Type: %s",
1291 type_to_string (abfd
, aux_base
, indx
, bigendian
));
1300 /* Provided a BFD, a section and an offset into the section, calculate
1301 and return the name of the source file and the line nearest to the
1305 DEFUN (ecoff_find_nearest_line
, (abfd
,
1313 asection
*section AND
1314 asymbol
**ignore_symbols AND
1316 CONST
char **filename_ptr AND
1317 CONST
char **functionname_ptr AND
1318 unsigned int *retline_ptr
)
1324 struct pdr_ext
*pdr_ptr
;
1325 struct pdr_ext
*pdr_end
;
1327 unsigned char *line_ptr
;
1328 unsigned char *line_end
;
1332 /* If we're not in the .text section, we don't have any line
1334 if (strcmp (section
->name
, _TEXT
) != 0)
1337 /* Make sure we have the FDR's. */
1338 if (ecoff_slurp_symbolic_info (abfd
) == false
1339 || bfd_get_symcount (abfd
) == 0)
1342 /* Each file descriptor (FDR) has a memory address. Here we track
1343 down which FDR we want. The FDR's are stored in increasing
1344 memory order. If speed is ever important, this can become a
1345 binary search. We must ignore FDR's with no PDR entries; they
1346 will have the adr of the FDR before or after them. */
1347 fdr_start
= ecoff_data (abfd
)->fdr
;
1348 fdr_end
= fdr_start
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
1349 fdr_hold
= (FDR
*) NULL
;
1350 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1352 if (offset
< fdr_ptr
->adr
)
1354 if (fdr_ptr
->cpd
> 0)
1357 if (fdr_hold
== (FDR
*) NULL
)
1361 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
1362 have an address, which is relative to the FDR address, and are
1363 also stored in increasing memory order. */
1364 offset
-= fdr_ptr
->adr
;
1365 pdr_ptr
= ecoff_data (abfd
)->external_pdr
+ fdr_ptr
->ipdFirst
;
1366 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
;
1367 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
1368 if (offset
< pdr
.adr
)
1370 for (pdr_ptr
++; pdr_ptr
< pdr_end
; pdr_ptr
++)
1372 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
1373 if (offset
< pdr
.adr
)
1377 /* Now we can look for the actual line number. The line numbers are
1378 stored in a very funky format, which I won't try to describe.
1379 Note that right here pdr_ptr and pdr hold the PDR *after* the one
1380 we want; we need this to compute line_end. */
1381 line_end
= ecoff_data (abfd
)->line
;
1382 if (pdr_ptr
== pdr_end
)
1383 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
1385 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
1387 /* Now change pdr and pdr_ptr to the one we want. */
1389 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
1393 line_ptr
= (ecoff_data (abfd
)->line
1394 + fdr_ptr
->cbLineOffset
1395 + pdr
.cbLineOffset
);
1396 while (line_ptr
< line_end
)
1401 delta
= *line_ptr
>> 4;
1404 count
= (*line_ptr
& 0xf) + 1;
1408 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
1409 if (delta
>= 0x8000)
1414 if (offset
< count
* 4)
1416 offset
-= count
* 4;
1419 /* If offset is too large, this line is not interesting. */
1423 *filename_ptr
= ecoff_data (abfd
)->ss
+ fdr_ptr
->issBase
+ fdr_ptr
->rss
;
1424 ecoff_swap_sym_in (abfd
,
1425 (ecoff_data (abfd
)->external_sym
1429 *functionname_ptr
= ecoff_data (abfd
)->ss
+ proc_sym
.iss
;
1430 *retline_ptr
= lineno
;
1434 /* We can't use the generic linking routines for ECOFF, because we
1435 have to handle all the debugging information. The generic link
1436 routine just works out the section contents and attaches a list of
1439 We link by looping over all the seclets. We make two passes. On
1440 the first we set the actual section contents and determine the size
1441 of the debugging information. On the second we accumulate the
1442 debugging information and write it out.
1444 This currently always accumulates the debugging information, which
1445 is incorrect, because it ignores the -s and -S options of the
1446 linker. The linker needs to be modified to give us that
1447 information in a more useful format (currently it just provides a
1448 list of symbols which should appear in the output file). */
1450 /* Clear the output_has_begun flag for all the input BFD's. We use it
1451 to avoid linking in the debugging information for a BFD more than
1455 DEFUN (ecoff_clear_output_flags
, (abfd
),
1458 register asection
*o
;
1459 register bfd_seclet_type
*p
;
1461 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
1462 for (p
= o
->seclets_head
;
1463 p
!= (bfd_seclet_type
*) NULL
;
1465 if (p
->type
== bfd_indirect_seclet
)
1466 p
->u
.indirect
.section
->owner
->output_has_begun
= false;
1469 /* Handle an indirect seclet on the first pass. Set the contents of
1470 the output section, and accumulate the debugging information if
1474 DEFUN (ecoff_rel
, (output_bfd
, seclet
, output_section
, data
, relocateable
),
1476 bfd_seclet_type
*seclet AND
1477 asection
*output_section AND
1479 boolean relocateable
)
1482 HDRR
*output_symhdr
;
1485 if ((output_section
->flags
& SEC_HAS_CONTENTS
)
1486 && !(output_section
->flags
& SEC_NEVER_LOAD
)
1487 && (output_section
->flags
& SEC_LOAD
)
1490 data
= (PTR
) bfd_get_relocated_section_contents (output_bfd
,
1494 if (bfd_set_section_contents (output_bfd
,
1505 input_bfd
= seclet
->u
.indirect
.section
->owner
;
1507 /* We want to figure out how much space will be required to
1508 incorporate all the debugging information from input_bfd. We use
1509 the output_has_begun field to avoid adding it in more than once.
1510 The actual incorporation is done in the second pass, in
1511 ecoff_get_debug. The code has to parallel that code in its
1512 manipulations of output_symhdr. */
1514 if (input_bfd
->output_has_begun
)
1516 input_bfd
->output_has_begun
= true;
1518 output_symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
1520 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
1526 /* We just accumulate symbols from a non-ECOFF BFD. */
1528 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
1529 get_symtab_upper_bound (input_bfd
));
1530 if (symbols
== (asymbol
**) NULL
)
1532 bfd_error
= no_memory
;
1535 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
1537 for (sym_ptr
= symbols
; sym_ptr
< sym_end
; sym_ptr
++)
1541 len
= strlen ((*sym_ptr
)->name
);
1542 if (((*sym_ptr
)->flags
& BSF_EXPORT
) == 0)
1544 ++output_symhdr
->isymMax
;
1545 output_symhdr
->issMax
+= len
+ 1;
1549 ++output_symhdr
->iextMax
;
1550 output_symhdr
->issExtMax
+= len
+ 1;
1554 bfd_release (output_bfd
, (PTR
) symbols
);
1556 ++output_symhdr
->ifdMax
;
1561 /* We simply add in the information from another ECOFF BFD. First
1562 we make sure we have the symbolic information. */
1563 if (ecoff_slurp_symbolic_info (input_bfd
) == false)
1565 if (bfd_get_symcount (input_bfd
) == 0)
1568 input_symhdr
= &ecoff_data (input_bfd
)->symbolic_header
;
1570 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
1571 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
1572 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
1573 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
1574 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
1575 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
1576 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
1577 output_symhdr
->issMax
+= input_symhdr
->issMax
;
1578 output_symhdr
->issExtMax
+= input_symhdr
->issExtMax
;
1579 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
1580 output_symhdr
->iextMax
+= input_symhdr
->iextMax
;
1582 /* The RFD's are special, since we create them if needed. */
1583 if (input_symhdr
->crfd
> 0)
1584 output_symhdr
->crfd
+= input_symhdr
->crfd
;
1586 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
1591 /* Handle an arbitrary seclet on the first pass. */
1594 DEFUN (ecoff_dump_seclet
, (abfd
, seclet
, section
, data
, relocateable
),
1596 bfd_seclet_type
*seclet AND
1597 asection
*section AND
1599 boolean relocateable
)
1601 switch (seclet
->type
)
1603 case bfd_indirect_seclet
:
1604 /* The contents of this section come from another one somewhere
1606 return ecoff_rel (abfd
, seclet
, section
, data
, relocateable
);
1608 case bfd_fill_seclet
:
1609 /* Fill in the section with us. */
1611 char *d
= (char *) bfd_alloc (abfd
, seclet
->size
);
1615 for (i
= 0; i
< seclet
->size
; i
+=2)
1616 d
[i
] = seclet
->u
.fill
.value
>> 8;
1617 for (i
= 1; i
< seclet
->size
; i
+=2)
1618 d
[i
] = seclet
->u
.fill
.value
;
1619 ret
= bfd_set_section_contents (abfd
, section
, d
, seclet
->offset
,
1621 bfd_release (abfd
, (PTR
) d
);
1632 /* Add a string to the debugging information we are accumulating for a
1633 file. Return the offset from the fdr string base or from the
1634 external string base. */
1637 DEFUN (ecoff_add_string
, (output_bfd
, fdr
, string
, external
),
1640 CONST
char *string AND
1647 symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
1648 len
= strlen (string
);
1651 strcpy (ecoff_data (output_bfd
)->ssext
+ symhdr
->issExtMax
, string
);
1652 ret
= symhdr
->issExtMax
;
1653 symhdr
->issExtMax
+= len
+ 1;
1657 strcpy (ecoff_data (output_bfd
)->ss
+ symhdr
->issMax
, string
);
1659 symhdr
->issMax
+= len
+ 1;
1660 fdr
->cbSs
+= len
+ 1;
1665 /* Accumulate the debugging information from an input section. */
1668 DEFUN (ecoff_get_debug
, (output_bfd
, seclet
, section
),
1670 bfd_seclet_type
*seclet AND
1674 HDRR
*output_symhdr
;
1676 ecoff_data_type
*output_ecoff
;
1677 ecoff_data_type
*input_ecoff
;
1680 struct fdr_ext
*fdr_out
;
1681 struct ext_ext
*ext_ptr
;
1682 struct ext_ext
*ext_end
;
1683 struct ext_ext
*ext_out
;
1693 input_bfd
= seclet
->u
.indirect
.section
->owner
;
1695 /* Don't get the information more than once. */
1696 if (input_bfd
->output_has_begun
)
1698 input_bfd
->output_has_begun
= true;
1700 output_ecoff
= ecoff_data (output_bfd
);
1701 output_symhdr
= &output_ecoff
->symbolic_header
;
1703 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
1710 /* This is not an ECOFF BFD. Just gather the symbols. */
1712 memset (&fdr
, 0, sizeof fdr
);
1714 fdr
.adr
= bfd_get_section_vma (output_bfd
, section
) + seclet
->offset
;
1715 fdr
.issBase
= output_symhdr
->issMax
;
1717 fdr
.rss
= ecoff_add_string (output_bfd
,
1719 bfd_get_filename (input_bfd
),
1721 fdr
.isymBase
= output_symhdr
->isymMax
;
1723 /* Get the symbols from the input BFD. */
1724 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
1725 get_symtab_upper_bound (input_bfd
));
1726 if (symbols
== (asymbol
**) NULL
)
1728 bfd_error
= no_memory
;
1731 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
1733 /* Handle the local symbols. */
1735 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
1739 if (((*sym_ptr
)->flags
& BSF_EXPORT
) != 0)
1741 memset (&internal_sym
, 0, sizeof internal_sym
);
1742 internal_sym
.iss
= ecoff_add_string (output_bfd
,
1746 internal_sym
.value
= (*sym_ptr
)->value
;
1747 internal_sym
.st
= stNil
;
1748 internal_sym
.sc
= scUndefined
;
1749 internal_sym
.index
= indexNil
;
1750 ecoff_swap_sym_out (output_bfd
, &internal_sym
,
1751 (output_ecoff
->external_sym
1752 + output_symhdr
->isymMax
));
1754 ++output_symhdr
->isymMax
;
1757 /* Handle the external symbols. */
1758 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
1762 if (((*sym_ptr
)->flags
& BSF_EXPORT
) == 0)
1764 memset (&internal_ext
, 0, sizeof internal_ext
);
1765 internal_ext
.ifd
= output_symhdr
->ifdMax
;
1766 internal_ext
.asym
.iss
= ecoff_add_string (output_bfd
,
1770 internal_ext
.asym
.value
= (*sym_ptr
)->value
;
1771 internal_ext
.asym
.st
= stNil
;
1772 internal_ext
.asym
.sc
= scUndefined
;
1773 internal_ext
.asym
.reserved
= 0;
1774 internal_ext
.asym
.index
= indexNil
;
1775 ecoff_swap_ext_out (output_bfd
, &internal_ext
,
1776 (output_ecoff
->external_ext
1777 + output_symhdr
->iextMax
));
1778 ++output_symhdr
->iextMax
;
1781 bfd_release (output_bfd
, (PTR
) symbols
);
1783 /* Leave everything else zeroed out. This will cause the lang
1784 field to be langC. The fBigendian field will indicate little
1785 endian format, but it doesn't matter because it only applies
1786 to aux fields and there are none. */
1788 ecoff_swap_fdr_out (output_bfd
, &fdr
,
1789 (output_ecoff
->external_fdr
1790 + output_symhdr
->ifdMax
));
1791 ++output_symhdr
->ifdMax
;
1795 /* This is an ECOFF BFD. We want to grab the information from
1796 input_bfd and attach it to output_bfd. */
1797 if (bfd_get_symcount (input_bfd
) == 0)
1799 input_ecoff
= ecoff_data (input_bfd
);
1800 input_symhdr
= &input_ecoff
->symbolic_header
;
1802 /* Because ECOFF uses relative pointers for most of the debugging
1803 information, much of it can simply be copied from input_bfd to
1805 memcpy (output_ecoff
->line
+ output_symhdr
->cbLineOffset
,
1807 input_symhdr
->cbLine
* sizeof (unsigned char));
1808 memcpy (output_ecoff
->external_aux
+ output_symhdr
->iauxMax
,
1809 input_ecoff
->external_aux
,
1810 input_symhdr
->iauxMax
* sizeof (union aux_ext
));
1811 memcpy (output_ecoff
->ss
+ output_symhdr
->issMax
,
1813 input_symhdr
->issMax
* sizeof (char));
1814 memcpy (output_ecoff
->ssext
+ output_symhdr
->issExtMax
,
1816 input_symhdr
->issExtMax
* sizeof (char));
1818 /* Some of the information may need to be swapped. */
1819 if (output_bfd
->xvec
->byteorder_big_p
== input_bfd
->xvec
->byteorder_big_p
)
1821 /* The two BFD's have the same endianness, so memcpy will
1823 memcpy (output_ecoff
->external_dnr
+ output_symhdr
->idnMax
,
1824 input_ecoff
->external_dnr
,
1825 input_symhdr
->idnMax
* sizeof (struct dnr_ext
));
1826 memcpy (output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
,
1827 input_ecoff
->external_pdr
,
1828 input_symhdr
->ipdMax
* sizeof (struct pdr_ext
));
1829 memcpy (output_ecoff
->external_sym
+ output_symhdr
->isymMax
,
1830 input_ecoff
->external_sym
,
1831 input_symhdr
->isymMax
* sizeof (struct sym_ext
));
1832 memcpy (output_ecoff
->external_opt
+ output_symhdr
->ioptMax
,
1833 input_ecoff
->external_opt
,
1834 input_symhdr
->ioptMax
* sizeof (struct opt_ext
));
1838 struct dnr_ext
*dnr_in
;
1839 struct dnr_ext
*dnr_end
;
1840 struct dnr_ext
*dnr_out
;
1841 struct pdr_ext
*pdr_in
;
1842 struct pdr_ext
*pdr_end
;
1843 struct pdr_ext
*pdr_out
;
1844 struct sym_ext
*sym_in
;
1845 struct sym_ext
*sym_end
;
1846 struct sym_ext
*sym_out
;
1847 struct opt_ext
*opt_in
;
1848 struct opt_ext
*opt_end
;
1849 struct opt_ext
*opt_out
;
1851 /* The two BFD's have different endianness, so we must swap
1852 everything in and out. This code would always work, but it
1853 would be very slow in the normal case. */
1854 dnr_in
= input_ecoff
->external_dnr
;
1855 dnr_end
= dnr_in
+ input_symhdr
->idnMax
;
1856 dnr_out
= output_ecoff
->external_dnr
+ output_symhdr
->idnMax
;
1857 for (; dnr_in
< dnr_end
; dnr_in
++, dnr_out
++)
1861 ecoff_swap_dnr_in (input_bfd
, dnr_in
, &dnr
);
1862 ecoff_swap_dnr_out (output_bfd
, &dnr
, dnr_out
);
1864 pdr_in
= input_ecoff
->external_pdr
;
1865 pdr_end
= pdr_in
+ input_symhdr
->ipdMax
;
1866 pdr_out
= output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
;
1867 for (; pdr_in
< pdr_end
; pdr_in
++, pdr_out
++)
1871 ecoff_swap_pdr_in (input_bfd
, pdr_in
, &pdr
);
1872 ecoff_swap_pdr_out (output_bfd
, &pdr
, pdr_out
);
1874 sym_in
= input_ecoff
->external_sym
;
1875 sym_end
= sym_in
+ input_symhdr
->isymMax
;
1876 sym_out
= output_ecoff
->external_sym
+ output_symhdr
->isymMax
;
1877 for (; sym_in
< sym_end
; sym_in
++, sym_out
++)
1881 ecoff_swap_sym_in (input_bfd
, sym_in
, &sym
);
1882 ecoff_swap_sym_out (output_bfd
, &sym
, sym_out
);
1884 opt_in
= input_ecoff
->external_opt
;
1885 opt_end
= opt_in
+ input_symhdr
->ioptMax
;
1886 opt_out
= output_ecoff
->external_opt
+ output_symhdr
->ioptMax
;
1887 for (; opt_in
< opt_end
; opt_in
++, opt_out
++)
1891 ecoff_swap_opt_in (input_bfd
, opt_in
, &opt
);
1892 ecoff_swap_opt_out (output_bfd
, &opt
, opt_out
);
1896 /* Step through the FDR's of input_bfd, adjust the offsets, and
1898 iss
= output_symhdr
->issMax
;
1899 isym
= output_symhdr
->isymMax
;
1900 iline
= output_symhdr
->ilineMax
;
1901 iopt
= output_symhdr
->ioptMax
;
1902 ipdr
= output_symhdr
->ipdMax
;
1903 iaux
= output_symhdr
->iauxMax
;
1904 irfd
= output_symhdr
->crfd
;
1905 cbline
= output_symhdr
->cbLineOffset
;
1907 fdr_ptr
= input_ecoff
->fdr
;
1908 fdr_end
= fdr_ptr
+ input_symhdr
->ifdMax
;
1909 fdr_out
= output_ecoff
->external_fdr
+ output_symhdr
->ifdMax
;
1910 for (; fdr_ptr
< fdr_end
; fdr_ptr
++, fdr_out
++)
1916 /* The memory address for this fdr is the address for the seclet
1917 plus the offset to this fdr within input_bfd. */
1918 fdr
.adr
= (bfd_get_section_vma (output_bfd
, section
)
1920 + (fdr_ptr
->adr
- input_ecoff
->fdr
->adr
));
1923 iss
+= fdr
.cbSs
* sizeof (char);
1924 fdr
.isymBase
= isym
;
1925 isym
+= fdr
.csym
* sizeof (struct sym_ext
);
1926 fdr
.ilineBase
= iline
;
1928 fdr
.ioptBase
= iopt
;
1929 iopt
+= fdr
.copt
* sizeof (struct opt_ext
);
1930 fdr
.ipdFirst
= ipdr
;
1931 ipdr
+= fdr
.cpd
* sizeof (struct pdr_ext
);
1932 fdr
.iauxBase
= iaux
;
1933 iaux
+= fdr
.caux
* sizeof (union aux_ext
);
1935 irfd
+= fdr
.crfd
* sizeof (struct rfd_ext
);
1936 fdr
.cbLineOffset
= cbline
;
1937 cbline
+= fdr
.cbLine
* sizeof (unsigned char);
1939 ecoff_swap_fdr_out (output_bfd
, &fdr
, fdr_out
);
1942 if (input_symhdr
->crfd
> 0)
1944 struct rfd_ext
*rfd_in
;
1945 struct rfd_ext
*rfd_end
;
1946 struct rfd_ext
*rfd_out
;
1948 /* Swap and adjust the RFD's. RFD's are only created by the
1949 linker, so this will only be necessary if one of the input
1950 files is the result of a partial link. Presumably all
1951 necessary RFD's are present. */
1952 rfd_in
= input_ecoff
->external_rfd
;
1953 rfd_end
= rfd_in
+ input_symhdr
->crfd
;
1954 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
1955 for (; rfd_in
< rfd_end
; rfd_in
++, rfd_out
++)
1959 ecoff_swap_rfd_in (input_bfd
, rfd_in
, &rfd
);
1960 rfd
+= output_symhdr
->ifdMax
;
1961 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
1963 output_symhdr
->crfd
+= input_symhdr
->crfd
;
1967 struct rfd_ext
*rfd_out
;
1968 struct rfd_ext
*rfd_end
;
1971 /* Create RFD's. Some of the debugging information includes
1972 relative file indices. These indices are taken as indices to
1973 the RFD table if there is one, or to the global table if
1974 there is not. If we did not create RFD's, we would have to
1975 parse and adjust all the debugging information which contains
1977 rfd
= output_symhdr
->ifdMax
;
1978 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
1979 rfd_end
= rfd_out
+ input_symhdr
->ifdMax
;
1980 for (; rfd_out
< rfd_end
; rfd_out
++, rfd
++)
1981 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
1982 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
1985 /* We have to swap the external symbols in and out because we have
1986 to adjust the file descriptor indices. */
1987 ext_ptr
= input_ecoff
->external_ext
;
1988 ext_end
= ext_ptr
+ input_symhdr
->iextMax
;
1989 ext_out
= output_ecoff
->external_ext
+ output_symhdr
->iextMax
;
1990 for (; ext_ptr
< ext_end
; ext_ptr
++, ext_out
++)
1994 ecoff_swap_ext_in (input_bfd
, ext_ptr
, &ext
);
1995 ext
.ifd
+= output_symhdr
->ifdMax
;
1996 ecoff_swap_ext_out (output_bfd
, &ext
, ext_out
);
1999 /* Update the counts. */
2000 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2001 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2002 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2003 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2004 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2005 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2006 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2007 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2008 output_symhdr
->issExtMax
+= input_symhdr
->issExtMax
;
2009 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2010 output_symhdr
->iextMax
+= input_symhdr
->iextMax
;
2012 /* Double check that the counts we got by stepping through the FDR's
2013 match the counts we got from input_symhdr. */
2014 BFD_ASSERT (output_symhdr
->issMax
== iss
2015 && output_symhdr
->isymMax
== isym
2016 && output_symhdr
->ilineMax
== iline
2017 && output_symhdr
->ioptMax
== iopt
2018 && output_symhdr
->ipdMax
== ipdr
2019 && output_symhdr
->iauxMax
== iaux
2020 && output_symhdr
->cbLineOffset
== cbline
);
2025 /* This is the actual link routine. It makes two passes over all the
2029 DEFUN (ecoff_bfd_seclet_link
, (abfd
, data
, relocateable
),
2032 boolean relocateable
)
2036 register asection
*o
;
2037 register bfd_seclet_type
*p
;
2041 /* We accumulate the debugging information counts in the symbolic
2043 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
2044 symhdr
->ilineMax
= 0;
2048 symhdr
->isymMax
= 0;
2049 symhdr
->ioptMax
= 0;
2050 symhdr
->iauxMax
= 0;
2052 symhdr
->issExtMax
= 0;
2055 symhdr
->iextMax
= 0;
2057 /* We are only going to look at each input BFD once. It is
2058 convenient to look at the code section first, so that the first
2059 time we look at a BFD we can set the text address (otherwise,
2060 when we get to the text section, we would have to be able to
2061 track down the file information associated with that BFD). So we
2062 actually do each pass in two sub passes; first the code sections,
2063 then the non-code sections. */
2065 /* Do the first pass: set the output section contents and count the
2066 debugging information. */
2067 ecoff_clear_output_flags (abfd
);
2068 for (ipass
= 0; ipass
< 2; ipass
++)
2070 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2072 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2073 so they are done on pass 0. For other sections the
2074 expression is true, so they are done on pass 1. */
2075 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2078 for (p
= o
->seclets_head
;
2079 p
!= (bfd_seclet_type
*) NULL
;
2082 if (ecoff_dump_seclet (abfd
, p
, o
, data
, relocateable
)
2089 /* Now the counts in symhdr are the correct size for the debugging
2090 information. We allocate the right amount of space, and reset
2091 the counts so that the second pass can use them as indices. It
2092 would be possible to output the debugging information directly to
2093 the file in pass 2, rather than to build it in memory and then
2094 write it out. Outputting to the file would require a lot of
2095 seeks and small writes, though, and I think this approach is
2097 size
= (symhdr
->cbLine
* sizeof (unsigned char)
2098 + symhdr
->idnMax
* sizeof (struct dnr_ext
)
2099 + symhdr
->ipdMax
* sizeof (struct pdr_ext
)
2100 + symhdr
->isymMax
* sizeof (struct sym_ext
)
2101 + symhdr
->ioptMax
* sizeof (struct opt_ext
)
2102 + symhdr
->iauxMax
* sizeof (union aux_ext
)
2103 + symhdr
->issMax
* sizeof (char)
2104 + symhdr
->issExtMax
* sizeof (char)
2105 + symhdr
->ifdMax
* sizeof (struct fdr_ext
)
2106 + symhdr
->crfd
* sizeof (struct rfd_ext
)
2107 + symhdr
->iextMax
* sizeof (struct ext_ext
));
2108 raw
= (char *) bfd_alloc (abfd
, size
);
2109 if (raw
== (char *) NULL
)
2111 bfd_error
= no_memory
;
2114 ecoff_data (abfd
)->raw_size
= size
;
2115 ecoff_data (abfd
)->raw_syments
= (PTR
) raw
;
2117 /* Initialize the raw pointers. */
2118 #define SET(field, count, type) \
2119 ecoff_data (abfd)->field = (type *) raw; \
2120 raw += symhdr->count * sizeof (type)
2122 SET (line
, cbLine
, unsigned char);
2123 SET (external_dnr
, idnMax
, struct dnr_ext
);
2124 SET (external_pdr
, ipdMax
, struct pdr_ext
);
2125 SET (external_sym
, isymMax
, struct sym_ext
);
2126 SET (external_opt
, ioptMax
, struct opt_ext
);
2127 SET (external_aux
, iauxMax
, union aux_ext
);
2128 SET (ss
, issMax
, char);
2129 SET (ssext
, issExtMax
, char);
2130 SET (external_fdr
, ifdMax
, struct fdr_ext
);
2131 SET (external_rfd
, crfd
, struct rfd_ext
);
2132 SET (external_ext
, iextMax
, struct ext_ext
);
2135 /* Reset the counts so the second pass can use them to know how far
2137 symhdr
->ilineMax
= 0;
2141 symhdr
->isymMax
= 0;
2142 symhdr
->ioptMax
= 0;
2143 symhdr
->iauxMax
= 0;
2145 symhdr
->issExtMax
= 0;
2148 symhdr
->iextMax
= 0;
2150 /* Do the second pass: accumulate the debugging information. */
2151 ecoff_clear_output_flags (abfd
);
2152 for (ipass
= 0; ipass
< 2; ipass
++)
2154 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2156 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2158 for (p
= o
->seclets_head
;
2159 p
!= (bfd_seclet_type
*) NULL
;
2162 if (p
->type
== bfd_indirect_seclet
)
2164 if (ecoff_get_debug (abfd
, p
, o
) == false)
2174 /* Set the architecture. The only architecture we support here is
2175 mips. We set the architecture anyhow, since many callers ignore
2176 the return value. */
2179 DEFUN (ecoff_set_arch_mach
, (abfd
, arch
, machine
),
2181 enum bfd_architecture arch AND
2182 unsigned long machine
)
2184 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2185 return arch
== bfd_arch_mips
;
2188 /* Calculate the file position for each section, and set
2192 DEFUN (ecoff_compute_section_file_positions
, (abfd
),
2202 if (bfd_get_start_address (abfd
))
2204 /* A start address may have been added to the original file. In
2205 this case it will need an optional header to record it. */
2206 abfd
->flags
|= EXEC_P
;
2209 if (abfd
->flags
& EXEC_P
)
2212 sofar
+= abfd
->section_count
* SCNHSZ
;
2214 previous
= (asection
*) NULL
;
2215 for (current
= abfd
->sections
;
2216 current
!= (asection
*) NULL
;
2217 current
= current
->next
)
2219 /* Only deal with sections which have contents */
2220 if (! (current
->flags
& SEC_HAS_CONTENTS
))
2223 /* Align the sections in the file to the same boundary on
2224 which they are aligned in virtual memory. */
2226 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2227 if (previous
!= (asection
*) NULL
)
2228 previous
->_raw_size
+= sofar
- old_sofar
;
2230 current
->filepos
= sofar
;
2232 sofar
+= current
->_raw_size
;
2234 /* make sure that this section is of the right size too */
2236 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2237 current
->_raw_size
+= sofar
- old_sofar
;
2241 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2244 /* Set the contents of a section. */
2247 DEFUN (ecoff_set_section_contents
, (abfd
, section
, location
, offset
, count
),
2252 bfd_size_type count
)
2254 if (abfd
->output_has_begun
== false)
2255 ecoff_compute_section_file_positions (abfd
);
2257 bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
2260 return (bfd_write (location
, 1, count
, abfd
) == count
) ? true : false;
2265 /* Write out an ECOFF file. */
2268 DEFUN (ecoff_write_object_contents
, (abfd
),
2274 file_ptr reloc_base
;
2276 unsigned long reloc_size
;
2277 unsigned long text_size
;
2278 unsigned long text_start
;
2279 unsigned long data_size
;
2280 unsigned long data_start
;
2281 unsigned long bss_size
;
2282 struct internal_filehdr internal_f
;
2283 struct internal_aouthdr internal_a
;
2285 bfd_error
= system_call_error
;
2287 if(abfd
->output_has_begun
== false)
2288 ecoff_compute_section_file_positions(abfd
);
2290 if (abfd
->sections
!= (asection
*) NULL
)
2291 scn_base
= abfd
->sections
->filepos
;
2294 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2298 for (current
= abfd
->sections
;
2299 current
!= (asection
*)NULL
;
2300 current
= current
->next
)
2302 current
->target_index
= count
;
2304 if (current
->reloc_count
!= 0)
2306 bfd_size_type relsize
;
2308 current
->rel_filepos
= reloc_base
;
2309 relsize
= current
->reloc_count
* RELSZ
;
2310 reloc_size
+= relsize
;
2311 reloc_base
+= relsize
;
2314 current
->rel_filepos
= 0;
2317 sym_base
= reloc_base
+ reloc_size
;
2318 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2326 /* Write section headers to the file. */
2328 internal_f
.f_nscns
= 0;
2330 (file_ptr
) ((abfd
->flags
& EXEC_P
) ?
2331 (FILHSZ
+ AOUTSZ
) : FILHSZ
),
2334 for (current
= abfd
->sections
;
2335 current
!= (asection
*) NULL
;
2336 current
= current
->next
)
2338 struct internal_scnhdr section
;
2341 ++internal_f
.f_nscns
;
2343 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2345 /* FIXME: is this correct for shared libraries? I think it is
2346 but I have no platform to check. Ian Lance Taylor. */
2347 vma
= bfd_get_section_vma (abfd
, current
);
2348 if (strcmp (current
->name
, _LIB
) == 0)
2349 section
.s_vaddr
= 0;
2351 section
.s_vaddr
= vma
;
2353 section
.s_paddr
= vma
;
2354 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2356 /* If this section has no size or is unloadable then the scnptr
2358 if (current
->_raw_size
== 0
2359 || (current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2360 section
.s_scnptr
= 0;
2362 section
.s_scnptr
= current
->filepos
;
2363 section
.s_relptr
= current
->rel_filepos
;
2365 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2366 object file produced by the assembler is supposed to point to
2367 information about how much room is required by objects of
2368 various different sizes. I think this only matters if we
2369 want the linker to compute the best size to use, or
2370 something. I don't know what happens if the information is
2372 section
.s_lnnoptr
= 0;
2374 section
.s_nreloc
= current
->reloc_count
;
2375 section
.s_nlnno
= 0;
2376 section
.s_flags
= sec_to_styp_flags (current
->name
, current
->flags
);
2381 ecoff_swap_scnhdr_out (abfd
, (PTR
) §ion
, (PTR
) &buff
);
2382 if (bfd_write ((PTR
) &buff
, 1, SCNHSZ
, abfd
) != SCNHSZ
)
2386 /* FIXME: These numbers don't add up to what the MIPS tools
2387 produce, although I don't think it matters. */
2388 if ((section
.s_flags
& STYP_TEXT
) != 0
2389 || (section
.s_flags
& STYP_RDATA
) != 0
2390 || (section
.s_flags
& STYP_LIT8
) != 0
2391 || (section
.s_flags
& STYP_LIT4
) != 0)
2393 text_size
+= bfd_get_section_size_before_reloc (current
);
2394 if (text_start
== 0 || text_start
> vma
)
2397 else if ((section
.s_flags
& STYP_DATA
) != 0
2398 || (section
.s_flags
& STYP_SDATA
) != 0)
2400 data_size
+= bfd_get_section_size_before_reloc (current
);
2401 if (data_start
== 0 || data_start
> vma
)
2404 else if ((section
.s_flags
& STYP_BSS
) != 0
2405 || (section
.s_flags
& STYP_SBSS
) != 0)
2406 bss_size
+= bfd_get_section_size_before_reloc (current
);
2409 /* Set up the file header. */
2411 internal_f
.f_magic
= MIPS_MAGIC_2
;
2414 We will NOT put a fucking timestamp in the header here. Every time you
2415 put it back, I will come in and take it out again. I'm sorry. This
2416 field does not belong here. We fill it with a 0 so it compares the
2417 same but is not a reasonable time. -- gnu@cygnus.com
2419 internal_f
.f_timdat
= 0;
2421 internal_f
.f_nsyms
= bfd_get_symcount(abfd
);
2422 if (internal_f
.f_nsyms
!= 0)
2423 internal_f
.f_symptr
= sym_base
;
2425 internal_f
.f_symptr
= 0;
2427 if (abfd
->flags
& EXEC_P
)
2428 internal_f
.f_opthdr
= AOUTSZ
;
2430 internal_f
.f_opthdr
= 0;
2432 internal_f
.f_flags
= 0;
2433 if (reloc_size
== 0)
2434 internal_f
.f_flags
|= F_RELFLG
;
2435 if (bfd_get_symcount (abfd
) == 0)
2436 internal_f
.f_flags
|= F_LSYMS
;
2437 if (abfd
->flags
& EXEC_P
)
2438 internal_f
.f_flags
|= F_EXEC
;
2440 if (! abfd
->xvec
->byteorder_big_p
)
2441 internal_f
.f_flags
|= F_AR32WR
;
2443 internal_f
.f_flags
|= F_AR32W
;
2445 /* Set up the optional header. */
2447 if ((abfd
->flags
& EXEC_P
) != 0)
2449 internal_a
.magic
= ZMAGIC
;
2451 /* FIXME: What should this be? */
2452 internal_a
.vstamp
= 0;
2454 internal_a
.tsize
= text_size
;
2455 internal_a
.text_start
= text_start
;
2456 internal_a
.dsize
= data_size
;
2457 internal_a
.data_start
= data_start
;
2458 internal_a
.bsize
= bss_size
;
2460 internal_a
.entry
= bfd_get_start_address (abfd
);
2462 /* FIXME: The MIPS optional header is larger than this.... */
2465 /* Write out the file header and the optional header. */
2467 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2472 ecoff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, (PTR
) &buff
);
2473 if (bfd_write ((PTR
) &buff
, 1, FILHSZ
, abfd
) != FILHSZ
)
2477 if ((abfd
->flags
& EXEC_P
) != 0)
2481 ecoff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, (PTR
) &buff
);
2482 if (bfd_write ((PTR
) &buff
, 1, AOUTSZ
, abfd
) != AOUTSZ
)
2486 /* Write out the relocs. */
2488 /* Write out the symbolic debugging information. */
2489 if (bfd_get_symcount (abfd
) > 0)
2491 struct hdr_ext buff
;
2493 ecoff_swap_hdr_out (abfd
, &ecoff_data (abfd
)->symbolic_header
, &buff
);
2494 if (bfd_write ((PTR
) &buff
, 1, sizeof buff
, abfd
) != sizeof buff
)
2496 if (bfd_write ((PTR
) ecoff_data (abfd
)->raw_syments
, 1,
2497 ecoff_data (abfd
)->raw_size
, abfd
)
2498 != ecoff_data (abfd
)->raw_size
)
2505 static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table
= {
2506 (void (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_in */
2507 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_in */
2508 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_in */
2509 (unsigned (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_out */
2510 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_out */
2511 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_out */
2512 ecoff_swap_reloc_out
, ecoff_swap_filehdr_out
, ecoff_swap_aouthdr_out
,
2513 ecoff_swap_scnhdr_out
,
2514 FILHSZ
, AOUTSZ
, SCNHSZ
, 0, 0, 0, true,
2515 ecoff_swap_filehdr_in
, ecoff_swap_aouthdr_in
, ecoff_swap_scnhdr_in
,
2516 ecoff_bad_format_hook
, ecoff_set_arch_mach_hook
, ecoff_mkobject_hook
,
2517 styp_to_sec_flags
, ecoff_make_section_hook
, ecoff_set_alignment_hook
,
2518 ecoff_slurp_symbol_table
2521 /* Routines that need to be written. */
2522 #define ecoff_canonicalize_reloc (unsigned int (*) PARAMS ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry **))) bfd_0
2524 /* get_lineno could be written for ECOFF, but it would currently only
2525 be useful for linking ECOFF and COFF files together, which doesn't
2527 #define ecoff_get_lineno \
2528 ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr)
2530 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
2531 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
2532 #define ecoff_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
2533 #define ecoff_slurp_armap bfd_slurp_coff_armap
2534 #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
2535 #define ecoff_write_armap coff_write_armap
2536 #define ecoff_truncate_arname bfd_dont_truncate_arname
2537 #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file
2538 #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
2539 #define ecoff_get_section_contents bfd_generic_get_section_contents
2540 #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
2541 #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup
2542 #define ecoff_sizeof_headers coff_sizeof_headers
2543 #define ecoff_bfd_debug_info_start bfd_void
2544 #define ecoff_bfd_debug_info_end bfd_void
2545 #define ecoff_bfd_debug_info_accumulate \
2546 ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void)
2547 #define ecoff_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
2548 #define ecoff_bfd_relax_section bfd_generic_relax_section
2550 bfd_target ecoff_little_vec
=
2552 "ecoff-littlemips", /* name */
2553 bfd_target_ecoff_flavour
,
2554 false, /* data byte order is little */
2555 false, /* header byte order is little */
2557 (HAS_RELOC
| EXEC_P
| /* object flags */
2558 HAS_LINENO
| HAS_DEBUG
|
2559 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
),
2561 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect
2563 0, /* leading underscore */
2564 '/', /* ar_pad_char */
2565 15, /* ar_max_namelen */
2566 3, /* minimum alignment power */
2567 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* data */
2568 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* hdrs */
2570 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
2571 bfd_generic_archive_p
, _bfd_dummy_target
},
2572 {bfd_false
, ecoff_mkobject
, bfd_false
, /* bfd_set_format */
2574 {bfd_false
, ecoff_write_object_contents
, bfd_false
, bfd_false
},
2577 (PTR
) &bfd_ecoff_std_swap_table
2580 bfd_target ecoff_big_vec
=
2582 "ecoff-bigmips", /* name */
2583 bfd_target_ecoff_flavour
,
2584 true, /* data byte order is big */
2585 true, /* header byte order is big */
2587 (HAS_RELOC
| EXEC_P
| /* object flags */
2588 HAS_LINENO
| HAS_DEBUG
|
2589 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
),
2591 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect flags */
2592 0, /* leading underscore */
2593 ' ', /* ar_pad_char */
2594 16, /* ar_max_namelen */
2595 3, /* minimum alignment power */
2596 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
,
2597 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
,
2598 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
2599 bfd_generic_archive_p
, _bfd_dummy_target
},
2600 {bfd_false
, ecoff_mkobject
, bfd_false
, /* bfd_set_format */
2602 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
2603 bfd_false
, bfd_false
},
2606 (PTR
) &bfd_ecoff_std_swap_table
2607 /* Note that there is another bfd_target just above this one. If
2608 you are adding initializers here, you should be adding them there