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 /* The linker needs a section to hold small common variables while
126 linking. There is no convenient way to create it when the linker
127 needs it, so we always create one for each BFD. We then avoid
129 #define SCOMMON ".scommon"
131 /* MIPS ECOFF has COFF sections, but the debugging information is
132 stored in a completely different format. This files uses the some
133 of the swapping routines from coffswap.h, and some of the generic
134 COFF routines in coffgen.c, but, unlike the real COFF targets, does
135 not use coffcode.h itself. */
137 /* Get the generic COFF swapping routines, except for the reloc,
138 symbol, and lineno ones. Give them ecoff names. */
140 #define NO_COFF_RELOCS
141 #define NO_COFF_SYMBOLS
142 #define NO_COFF_LINENOS
143 #define coff_swap_filehdr_in ecoff_swap_filehdr_in
144 #define coff_swap_filehdr_out ecoff_swap_filehdr_out
145 #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in
146 #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out
147 #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in
148 #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out
149 #include "coffswap.h"
151 /* This stuff is somewhat copied from coffcode.h. */
153 static asection bfd_debug_section
= { "*DEBUG*" };
155 /* See whether the magic number matches. */
158 DEFUN(ecoff_bad_format_hook
, (abfd
, filehdr
),
162 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
164 if (ECOFFBADMAG (*internal_f
))
170 /* This is a hook needed by SCO COFF, but we have nothing to do. */
173 DEFUN (ecoff_make_section_hook
, (abfd
, name
),
177 return (asection
*) NULL
;
180 /* Initialize a new section. */
183 DEFUN (ecoff_new_section_hook
, (abfd
, section
),
187 section
->alignment_power
= abfd
->xvec
->align_power_min
;
189 if (strcmp (section
->name
, _TEXT
) == 0)
190 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
191 else if (strcmp (section
->name
, _DATA
) == 0
192 || strcmp (section
->name
, _SDATA
) == 0)
193 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
194 else if (strcmp (section
->name
, _RDATA
) == 0
195 || strcmp (section
->name
, _LIT8
) == 0
196 || strcmp (section
->name
, _LIT4
) == 0)
197 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
198 else if (strcmp (section
->name
, _BSS
) == 0
199 || strcmp (section
->name
, _SBSS
) == 0)
200 section
->flags
|= SEC_ALLOC
;
202 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
203 uncertain about .init on some systems and I don't know how shared
209 #define ecoff_set_alignment_hook \
210 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
213 DEFUN (ecoff_mkobject
, (abfd
),
216 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
217 bfd_zalloc (abfd
, sizeof(ecoff_data_type
)));
218 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
220 bfd_error
= no_memory
;
224 /* Always create a .scommon section for every BFD. This is a hack so
225 that the linker has something to attach scSCommon symbols to. */
226 bfd_make_section (abfd
, SCOMMON
);
231 /* Create the COFF backend specific information. */
234 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
239 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
240 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
241 ecoff_data_type
*ecoff
;
243 if (ecoff_mkobject (abfd
) == false)
246 ecoff
= ecoff_data (abfd
);
247 ecoff
->sym_filepos
= internal_f
->f_symptr
;
249 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
253 ecoff
->gp
= internal_a
->gp_value
;
254 ecoff
->gprmask
= internal_a
->gprmask
;
255 for (i
= 0; i
< 4; i
++)
256 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
262 /* Determine the machine architecture and type. */
264 DEFUN (ecoff_set_arch_mach_hook
, (abfd
, filehdr
),
269 enum bfd_architecture arch
;
270 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
273 switch (internal_f
->f_magic
) {
277 arch
= bfd_arch_mips
;
281 default: /* Unreadable input file type */
282 arch
= bfd_arch_obscure
;
286 bfd_default_set_arch_mach(abfd
, arch
, machine
);
290 /* Get the section s_flags to use for a section. */
293 DEFUN (sec_to_styp_flags
, (name
, flags
),
301 if (strcmp (name
, _TEXT
) == 0)
303 else if (strcmp (name
, _DATA
) == 0)
305 else if (strcmp (name
, _SDATA
) == 0)
307 else if (strcmp (name
, _RDATA
) == 0)
309 else if (strcmp (name
, _LIT8
) == 0)
311 else if (strcmp (name
, _LIT4
) == 0)
313 else if (strcmp (name
, _BSS
) == 0)
315 else if (strcmp (name
, _SBSS
) == 0)
317 else if (flags
& SEC_CODE
)
319 else if (flags
& SEC_DATA
)
321 else if (flags
& SEC_READONLY
)
323 else if (flags
& SEC_LOAD
)
328 if (flags
& SEC_NEVER_LOAD
)
334 /* Get the BFD flags to use for a section. */
337 DEFUN (styp_to_sec_flags
, (abfd
, hdr
),
341 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
342 long styp_flags
= internal_s
->s_flags
;
343 flagword sec_flags
=0;
345 if (styp_flags
& STYP_NOLOAD
)
346 sec_flags
|= SEC_NEVER_LOAD
;
348 /* For 386 COFF, at least, an unloadable text or data section is
349 actually a shared library section. */
350 if (styp_flags
& STYP_TEXT
)
352 if (sec_flags
& SEC_NEVER_LOAD
)
353 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
355 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
357 else if ((styp_flags
& STYP_DATA
)
358 || (styp_flags
& STYP_RDATA
)
359 || (styp_flags
& STYP_SDATA
))
361 if (sec_flags
& SEC_NEVER_LOAD
)
362 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
364 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
365 if (styp_flags
& STYP_RDATA
)
366 sec_flags
|= SEC_READONLY
;
368 else if ((styp_flags
& STYP_BSS
)
369 || (styp_flags
& STYP_SBSS
))
371 sec_flags
|= SEC_ALLOC
;
373 else if (styp_flags
& STYP_INFO
)
375 sec_flags
|= SEC_NEVER_LOAD
;
377 else if ((styp_flags
& STYP_LIT8
)
378 || (styp_flags
& STYP_LIT4
))
380 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
384 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
390 /* Read in and swap the important symbolic information for an ECOFF
394 DEFUN (ecoff_slurp_symbolic_info
, (abfd
),
397 struct hdr_ext external_symhdr
;
398 HDRR
*internal_symhdr
;
399 bfd_size_type raw_base
;
400 bfd_size_type raw_size
;
402 struct fdr_ext
*fraw_src
;
403 struct fdr_ext
*fraw_end
;
406 /* Check whether we've already gotten it, and whether there's any to
408 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
410 if (ecoff_data (abfd
)->sym_filepos
== 0)
412 bfd_get_symcount (abfd
) = 0;
416 /* At this point bfd_get_symcount (abfd) holds the number of symbols
417 as read from the file header, but on ECOFF this is always the
418 size of the symbolic information header. It would be cleaner to
419 handle this when we first read the file in coffgen.c. */
420 if (bfd_get_symcount (abfd
) != sizeof (external_symhdr
))
422 bfd_error
= bad_value
;
426 /* Read the symbolic information header. */
427 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
428 || (bfd_read ((PTR
) &external_symhdr
, sizeof (external_symhdr
), 1, abfd
)
429 != sizeof (external_symhdr
)))
431 bfd_error
= system_call_error
;
434 internal_symhdr
= &ecoff_data (abfd
)->symbolic_header
;
435 ecoff_swap_hdr_in (abfd
, &external_symhdr
, internal_symhdr
);
437 if (internal_symhdr
->magic
!= magicSym
)
439 bfd_error
= bad_value
;
443 /* Now we can get the correct number of symbols. */
444 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
445 + internal_symhdr
->iextMax
);
447 /* Read all the symbolic information at once. */
448 raw_base
= ecoff_data (abfd
)->sym_filepos
+ sizeof (struct hdr_ext
);
450 if (internal_symhdr
->cbExtOffset
!= 0)
451 raw_size
= (internal_symhdr
->cbExtOffset
453 + internal_symhdr
->iextMax
* sizeof (struct ext_ext
));
456 long cbline
, issmax
, issextmax
;
458 cbline
= (internal_symhdr
->cbLine
+ 3) &~ 4;
459 issmax
= (internal_symhdr
->issMax
+ 3) &~ 4;
460 issextmax
= (internal_symhdr
->issExtMax
+ 3) &~ 4;
461 raw_size
= (cbline
* sizeof (unsigned char)
462 + internal_symhdr
->idnMax
* sizeof (struct dnr_ext
)
463 + internal_symhdr
->ipdMax
* sizeof (struct pdr_ext
)
464 + internal_symhdr
->isymMax
* sizeof (struct sym_ext
)
465 + internal_symhdr
->ioptMax
* sizeof (struct opt_ext
)
466 + internal_symhdr
->iauxMax
* sizeof (union aux_ext
)
467 + issmax
* sizeof (char)
468 + issextmax
* sizeof (char)
469 + internal_symhdr
->ifdMax
* sizeof (struct fdr_ext
)
470 + internal_symhdr
->crfd
* sizeof (struct rfd_ext
)
471 + internal_symhdr
->iextMax
* sizeof (struct ext_ext
));
476 ecoff_data (abfd
)->sym_filepos
= 0;
479 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
482 bfd_error
= no_memory
;
485 if (bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
487 bfd_error
= system_call_error
;
488 bfd_release (abfd
, raw
);
492 ecoff_data (abfd
)->raw_size
= raw_size
;
493 ecoff_data (abfd
)->raw_syments
= raw
;
495 /* Get pointers for the numeric offsets in the HDRR structure. */
496 #define FIX(off1, off2, type) \
497 if (internal_symhdr->off1 == 0) \
498 ecoff_data (abfd)->off2 = (type *) NULL; \
500 ecoff_data (abfd)->off2 = (type *) ((char *) raw \
501 + internal_symhdr->off1 \
503 FIX (cbLineOffset
, line
, unsigned char);
504 FIX (cbDnOffset
, external_dnr
, struct dnr_ext
);
505 FIX (cbPdOffset
, external_pdr
, struct pdr_ext
);
506 FIX (cbSymOffset
, external_sym
, struct sym_ext
);
507 FIX (cbOptOffset
, external_opt
, struct opt_ext
);
508 FIX (cbAuxOffset
, external_aux
, union aux_ext
);
509 FIX (cbSsOffset
, ss
, char);
510 FIX (cbSsExtOffset
, ssext
, char);
511 FIX (cbFdOffset
, external_fdr
, struct fdr_ext
);
512 FIX (cbRfdOffset
, external_rfd
, struct rfd_ext
);
513 FIX (cbExtOffset
, external_ext
, struct ext_ext
);
516 /* I don't want to always swap all the data, because it will just
517 waste time and most programs will never look at it. The only
518 time the linker needs most of the debugging information swapped
519 is when linking big-endian and little-endian MIPS object files
520 together, which is not a common occurrence.
522 We need to look at the fdr to deal with a lot of information in
523 the symbols, so we swap them here. */
524 ecoff_data (abfd
)->fdr
= (struct fdr
*) bfd_alloc (abfd
,
525 (internal_symhdr
->ifdMax
*
526 sizeof (struct fdr
)));
527 if (ecoff_data (abfd
)->fdr
== NULL
)
529 bfd_error
= no_memory
;
532 fdr_ptr
= ecoff_data (abfd
)->fdr
;
533 fraw_src
= ecoff_data (abfd
)->external_fdr
;
534 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
;
535 for (; fraw_src
< fraw_end
; fraw_src
++, fdr_ptr
++)
536 ecoff_swap_fdr_in (abfd
, fraw_src
, fdr_ptr
);
541 /* ECOFF symbol table routines. The ECOFF symbol table is described
542 in gcc/mips-tfile.c. */
544 /* ECOFF uses two common sections. One is the usual one, and the
545 other is for small objects. All the small objects are kept
546 together, and then referenced via the gp pointer, which yields
547 faster assembler code. This is what we use for the small common
549 static asection ecoff_scom_section
;
550 static asymbol ecoff_scom_symbol
;
551 static asymbol
*ecoff_scom_symbol_ptr
;
553 /* Create an empty symbol. */
556 DEFUN (ecoff_make_empty_symbol
, (abfd
),
559 ecoff_symbol_type
*new;
561 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
562 if (new == (ecoff_symbol_type
*) NULL
)
564 bfd_error
= no_memory
;
565 return (asymbol
*) NULL
;
567 new->symbol
.section
= (asection
*) NULL
;
568 new->fdr
= (FDR
*) NULL
;
570 new->native
.lnative
= (struct sym_ext
*) NULL
;
571 new->symbol
.the_bfd
= abfd
;
575 /* Set the BFD flags and section for an ECOFF symbol. */
578 DEFUN (ecoff_set_symbol_info
, (abfd
, ecoff_sym
, asym
, ext
),
584 asym
->the_bfd
= abfd
;
585 asym
->value
= ecoff_sym
->value
;
586 asym
->section
= &bfd_debug_section
;
589 /* Most symbol types are just for debugging. */
590 switch (ecoff_sym
->st
)
601 asym
->flags
= BSF_DEBUGGING
;
606 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
608 asym
->flags
= BSF_LOCAL
;
609 switch (ecoff_sym
->sc
)
612 /* Used for compiler generated labels. Leave them in the
613 debugging section, and mark them as local. If BSF_DEBUGGING
614 is set, then nm does not display them for some reason. If no
615 flags are set then the linker whines about them. */
616 asym
->flags
= BSF_LOCAL
;
619 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
620 asym
->value
-= asym
->section
->vma
;
623 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
624 asym
->value
-= asym
->section
->vma
;
629 asym
->section
= &bfd_com_section
;
634 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
635 asym
->value
-= asym
->section
->vma
;
639 asym
->flags
= BSF_DEBUGGING
;
642 asym
->section
= &bfd_abs_section
;
645 asym
->section
= &bfd_und_section
;
655 asym
->flags
= BSF_DEBUGGING
;
658 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
659 asym
->value
-= asym
->section
->vma
;
662 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
664 asym
->value
-= asym
->section
->vma
;
667 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
668 asym
->value
-= asym
->section
->vma
;
671 asym
->flags
= BSF_DEBUGGING
;
674 /* FIXME: We should take a -G argument, which gives the maximum
675 size of objects to be put in the small common section. Until
676 we do, we put objects of sizes up to 8 in the small common
677 section. The assembler should do this for us, but the native
678 assembler seems to get confused. */
681 asym
->section
= &bfd_com_section
;
686 if (ecoff_scom_section
.name
== NULL
)
688 /* Initialize the small common section. */
689 ecoff_scom_section
.name
= SCOMMON
;
690 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
691 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
692 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
693 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
694 ecoff_scom_symbol
.name
= SCOMMON
;
695 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
696 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
697 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
699 asym
->section
= &ecoff_scom_section
;
704 asym
->flags
= BSF_DEBUGGING
;
707 asym
->section
= &bfd_und_section
;
712 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
713 asym
->value
-= asym
->section
->vma
;
718 asym
->flags
= BSF_DEBUGGING
;
721 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
722 asym
->value
-= asym
->section
->vma
;
729 /* Read an ECOFF symbol table. */
732 DEFUN (ecoff_slurp_symbol_table
, (abfd
),
735 bfd_size_type internal_size
;
736 ecoff_symbol_type
*internal
;
737 ecoff_symbol_type
*internal_ptr
;
738 struct ext_ext
*eraw_src
;
739 struct ext_ext
*eraw_end
;
743 /* If we've already read in the symbol table, do nothing. */
744 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
747 /* Get the symbolic information. */
748 if (ecoff_slurp_symbolic_info (abfd
) == false)
750 if (bfd_get_symcount (abfd
) == 0)
753 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
754 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
755 if (internal
== NULL
)
757 bfd_error
= no_memory
;
761 internal_ptr
= internal
;
762 eraw_src
= ecoff_data (abfd
)->external_ext
;
763 eraw_end
= eraw_src
+ ecoff_data (abfd
)->symbolic_header
.iextMax
;
764 for (; eraw_src
< eraw_end
; eraw_src
++, internal_ptr
++)
768 ecoff_swap_ext_in (abfd
, eraw_src
, &internal_esym
);
769 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ssext
770 + internal_esym
.asym
.iss
);
771 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
772 &internal_ptr
->symbol
, 1);
773 internal_ptr
->fdr
= ecoff_data (abfd
)->fdr
+ internal_esym
.ifd
;
774 internal_ptr
->local
= false;
775 internal_ptr
->native
.enative
= eraw_src
;
778 /* The local symbols must be accessed via the fdr's, because the
779 string and aux indices are relative to the fdr information. */
780 fdr_ptr
= ecoff_data (abfd
)->fdr
;
781 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
782 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
784 struct sym_ext
*lraw_src
;
785 struct sym_ext
*lraw_end
;
787 lraw_src
= ecoff_data (abfd
)->external_sym
+ fdr_ptr
->isymBase
;
788 lraw_end
= lraw_src
+ fdr_ptr
->csym
;
789 for (; lraw_src
< lraw_end
; lraw_src
++, internal_ptr
++)
793 ecoff_swap_sym_in (abfd
, lraw_src
, &internal_sym
);
794 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ss
797 ecoff_set_symbol_info (abfd
, &internal_sym
,
798 &internal_ptr
->symbol
, 0);
799 internal_ptr
->fdr
= fdr_ptr
;
800 internal_ptr
->local
= true;
801 internal_ptr
->native
.lnative
= lraw_src
;
805 ecoff_data (abfd
)->canonical_symbols
= internal
;
811 DEFUN (ecoff_get_symtab_upper_bound
, (abfd
),
814 if (ecoff_slurp_symbolic_info (abfd
) == false
815 || bfd_get_symcount (abfd
) == 0)
818 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
822 DEFUN (ecoff_get_symtab
, (abfd
, alocation
),
826 unsigned int counter
= 0;
827 ecoff_symbol_type
*symbase
;
828 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
830 if (ecoff_slurp_symbol_table (abfd
) == false
831 || bfd_get_symcount (abfd
) == 0)
834 symbase
= ecoff_data (abfd
)->canonical_symbols
;
835 while (counter
< bfd_get_symcount (abfd
))
837 *(location
++) = symbase
++;
840 *location
++ = (ecoff_symbol_type
*) NULL
;
841 return bfd_get_symcount (abfd
);
844 /* Turn ECOFF type information into a printable string.
845 emit_aggregate and type_to_string are from gcc/mips-tdump.c, with
846 swapping added and used_ptr removed. */
848 /* Write aggregate information to a string. */
851 DEFUN (emit_aggregate
, (abfd
, string
, rndx
, isym
, which
),
859 int indx
= rndx
->index
;
860 int sym_base
, ss_base
;
866 sym_base
= ecoff_data (abfd
)->fdr
[ifd
].isymBase
;
867 ss_base
= ecoff_data (abfd
)->fdr
[ifd
].issBase
;
869 if (indx
== indexNil
)
870 name
= "/* no name */";
876 ecoff_swap_sym_in (abfd
,
877 ecoff_data (abfd
)->external_sym
+ indx
,
879 name
= ecoff_data (abfd
)->ss
+ ss_base
+ sym
.iss
;
883 "%s %s { ifd = %d, index = %d }",
885 indx
+ ecoff_data (abfd
)->symbolic_header
.iextMax
);
888 /* Convert the type information to string format. */
891 DEFUN (type_to_string
, (abfd
, aux_ptr
, indx
, bigendian
),
893 union aux_ext
*aux_ptr AND
905 unsigned int basic_type
;
907 static char buffer1
[1024];
908 static char buffer2
[1024];
913 for (i
= 0; i
< 7; i
++)
915 qualifiers
[i
].low_bound
= 0;
916 qualifiers
[i
].high_bound
= 0;
917 qualifiers
[i
].stride
= 0;
920 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
921 return "-1 (no type)";
922 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
924 basic_type
= u
.ti
.bt
;
925 qualifiers
[0].type
= u
.ti
.tq0
;
926 qualifiers
[1].type
= u
.ti
.tq1
;
927 qualifiers
[2].type
= u
.ti
.tq2
;
928 qualifiers
[3].type
= u
.ti
.tq3
;
929 qualifiers
[4].type
= u
.ti
.tq4
;
930 qualifiers
[5].type
= u
.ti
.tq5
;
931 qualifiers
[6].type
= tqNil
;
934 * Go get the basic type.
938 case btNil
: /* undefined */
942 case btAdr
: /* address - integer same size as pointer */
943 strcpy (p1
, "address");
946 case btChar
: /* character */
950 case btUChar
: /* unsigned character */
951 strcpy (p1
, "unsigned char");
954 case btShort
: /* short */
955 strcpy (p1
, "short");
958 case btUShort
: /* unsigned short */
959 strcpy (p1
, "unsigned short");
962 case btInt
: /* int */
966 case btUInt
: /* unsigned int */
967 strcpy (p1
, "unsigned int");
970 case btLong
: /* long */
974 case btULong
: /* unsigned long */
975 strcpy (p1
, "unsigned long");
978 case btFloat
: /* float (real) */
979 strcpy (p1
, "float");
982 case btDouble
: /* Double (real) */
983 strcpy (p1
, "double");
986 /* Structures add 1-2 aux words:
987 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
988 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
990 case btStruct
: /* Structure (Record) */
991 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
992 emit_aggregate (abfd
, p1
, &rndx
,
993 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
995 indx
++; /* skip aux words */
998 /* Unions add 1-2 aux words:
999 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1000 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1002 case btUnion
: /* Union */
1003 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1004 emit_aggregate (abfd
, p1
, &rndx
,
1005 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1007 indx
++; /* skip aux words */
1010 /* Enumerations add 1-2 aux words:
1011 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1012 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1014 case btEnum
: /* Enumeration */
1015 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1016 emit_aggregate (abfd
, p1
, &rndx
,
1017 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1019 indx
++; /* skip aux words */
1022 case btTypedef
: /* defined via a typedef, isymRef points */
1023 strcpy (p1
, "typedef");
1026 case btRange
: /* subrange of int */
1027 strcpy (p1
, "subrange");
1030 case btSet
: /* pascal sets */
1034 case btComplex
: /* fortran complex */
1035 strcpy (p1
, "complex");
1038 case btDComplex
: /* fortran double complex */
1039 strcpy (p1
, "double complex");
1042 case btIndirect
: /* forward or unnamed typedef */
1043 strcpy (p1
, "forward/unamed typedef");
1046 case btFixedDec
: /* Fixed Decimal */
1047 strcpy (p1
, "fixed decimal");
1050 case btFloatDec
: /* Float Decimal */
1051 strcpy (p1
, "float decimal");
1054 case btString
: /* Varying Length Character String */
1055 strcpy (p1
, "string");
1058 case btBit
: /* Aligned Bit String */
1062 case btPicture
: /* Picture */
1063 strcpy (p1
, "picture");
1066 case btVoid
: /* Void */
1067 strcpy (p1
, "void");
1071 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1075 p1
+= strlen (buffer1
);
1078 * If this is a bitfield, get the bitsize.
1084 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1085 sprintf (p1
, " : %d", bitsize
);
1086 p1
+= strlen (buffer1
);
1091 * Deal with any qualifiers.
1093 if (qualifiers
[0].type
!= tqNil
)
1096 * Snarf up any array bounds in the correct order. Arrays
1097 * store 5 successive words in the aux. table:
1098 * word 0 RNDXR to type of the bounds (ie, int)
1099 * word 1 Current file descriptor index
1101 * word 3 high bound (or -1 if [])
1102 * word 4 stride size in bits
1104 for (i
= 0; i
< 7; i
++)
1106 if (qualifiers
[i
].type
== tqArray
)
1108 qualifiers
[i
].low_bound
=
1109 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1110 qualifiers
[i
].high_bound
=
1111 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1112 qualifiers
[i
].stride
=
1113 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1119 * Now print out the qualifiers.
1121 for (i
= 0; i
< 6; i
++)
1123 switch (qualifiers
[i
].type
)
1130 strcpy (p2
, "ptr to ");
1131 p2
+= sizeof ("ptr to ")-1;
1135 strcpy (p2
, "volatile ");
1136 p2
+= sizeof ("volatile ")-1;
1140 strcpy (p2
, "far ");
1141 p2
+= sizeof ("far ")-1;
1145 strcpy (p2
, "func. ret. ");
1146 p2
+= sizeof ("func. ret. ");
1151 int first_array
= i
;
1154 /* Print array bounds reversed (ie, in the order the C
1155 programmer writes them). C is such a fun language.... */
1157 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1160 for (j
= i
; j
>= first_array
; j
--)
1162 strcpy (p2
, "array [");
1163 p2
+= sizeof ("array [")-1;
1164 if (qualifiers
[j
].low_bound
!= 0)
1166 "%ld:%ld {%ld bits}",
1167 (long) qualifiers
[j
].low_bound
,
1168 (long) qualifiers
[j
].high_bound
,
1169 (long) qualifiers
[j
].stride
);
1171 else if (qualifiers
[j
].high_bound
!= -1)
1174 (long) (qualifiers
[j
].high_bound
+ 1),
1175 (long) (qualifiers
[j
].stride
));
1178 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1181 strcpy (p2
, "] of ");
1182 p2
+= sizeof ("] of ")-1;
1190 strcpy (p2
, buffer1
);
1194 /* Print information about an ECOFF symbol. */
1197 DEFUN (ecoff_print_symbol
, (abfd
, filep
, symbol
, how
),
1201 bfd_print_symbol_type how
)
1203 FILE *file
= (FILE *)filep
;
1207 case bfd_print_symbol_name
:
1208 fprintf (file
, "%s", symbol
->name
);
1210 case bfd_print_symbol_more
:
1211 if (ecoffsymbol (symbol
)->local
)
1215 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1217 fprintf (file
, "ecoff local %lx %x %x",
1218 (unsigned long) ecoff_sym
.value
,
1219 (unsigned) ecoff_sym
.st
, (unsigned) ecoff_sym
.sc
);
1225 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1227 fprintf (file
, "ecoff extern %lx %x %x",
1228 (unsigned long) ecoff_ext
.asym
.value
,
1229 (unsigned) ecoff_ext
.asym
.st
,
1230 (unsigned) ecoff_ext
.asym
.sc
);
1233 case bfd_print_symbol_nm
:
1235 CONST
char *section_name
= symbol
->section
->name
;
1237 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
1238 fprintf (file
, " %-5s %s %s",
1240 ecoffsymbol (symbol
)->local
? "l" : "e",
1244 case bfd_print_symbol_all
:
1245 /* Print out the symbols in a reasonable way */
1254 if (ecoffsymbol (symbol
)->local
)
1256 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1259 pos
= (ecoffsymbol (symbol
)->native
.lnative
1260 - ecoff_data (abfd
)->external_sym
1261 + ecoff_data (abfd
)->symbolic_header
.iextMax
);
1268 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1271 pos
= (ecoffsymbol (symbol
)->native
.enative
1272 - ecoff_data (abfd
)->external_ext
);
1273 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1274 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1275 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1278 fprintf (file
, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s",
1279 pos
, type
, (unsigned long) ecoff_ext
.asym
.value
,
1280 (unsigned) ecoff_ext
.asym
.st
,
1281 (unsigned) ecoff_ext
.asym
.sc
,
1282 (unsigned) ecoff_ext
.asym
.index
,
1283 jmptbl
, cobol_main
, weakext
,
1286 if (ecoffsymbol (symbol
)->fdr
!= NULL
1287 && ecoff_ext
.asym
.index
!= indexNil
)
1292 union aux_ext
*aux_base
;
1294 indx
= ecoff_ext
.asym
.index
;
1296 /* sym_base is used to map the fdr relative indices which
1297 appear in the file to the position number which we are
1299 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1300 if (ecoffsymbol (symbol
)->local
)
1301 sym_base
+= ecoff_data (abfd
)->symbolic_header
.iextMax
;
1303 /* aux_base is the start of the aux entries for this file;
1304 asym.index is an offset from this. */
1305 aux_base
= (ecoff_data (abfd
)->external_aux
1306 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1308 /* The aux entries are stored in host byte order; the
1309 order is indicated by a bit in the fdr. */
1310 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1312 /* This switch is basically from gcc/mips-tdump.c */
1313 switch (ecoff_ext
.asym
.st
)
1321 printf ("\n End+1 symbol: %ld", indx
+ sym_base
);
1325 if (ecoff_ext
.asym
.sc
== scText
1326 || ecoff_ext
.asym
.sc
== scInfo
)
1327 printf ("\n First symbol: %ld", indx
+ sym_base
);
1329 printf ("\n First symbol: %ld",
1330 (AUX_GET_ISYM (bigendian
,
1331 &aux_base
[ecoff_ext
.asym
.index
])
1337 if (MIPS_IS_STAB (&ecoff_ext
.asym
))
1339 else if (ecoffsymbol (symbol
)->local
)
1340 printf ("\n End+1 symbol: %-7ld Type: %s",
1341 (AUX_GET_ISYM (bigendian
,
1342 &aux_base
[ecoff_ext
.asym
.index
])
1344 type_to_string (abfd
, aux_base
, indx
+ 1,
1347 printf ("\n Local symbol: %d",
1350 + ecoff_data (abfd
)->symbolic_header
.iextMax
));
1354 if (!MIPS_IS_STAB (&ecoff_ext
.asym
))
1355 printf ("\n Type: %s",
1356 type_to_string (abfd
, aux_base
, indx
, bigendian
));
1365 /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in
1366 external form. They use a bit which indicates whether the symbol
1369 /* Swap a reloc in. */
1372 DEFUN (ecoff_swap_reloc_in
, (abfd
, ext
, intern
),
1375 struct internal_reloc
*intern
)
1377 intern
->r_vaddr
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->r_vaddr
);
1378 if (abfd
->xvec
->header_byteorder_big_p
!= false)
1380 intern
->r_symndx
= (((int) ext
->r_bits
[0]
1381 << RELOC_BITS0_SYMNDX_SH_LEFT_BIG
)
1382 | ((int) ext
->r_bits
[1]
1383 << RELOC_BITS1_SYMNDX_SH_LEFT_BIG
)
1384 | ((int) ext
->r_bits
[2]
1385 << RELOC_BITS2_SYMNDX_SH_LEFT_BIG
));
1386 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_BIG
)
1387 >> RELOC_BITS3_TYPE_SH_BIG
);
1388 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_BIG
) != 0;
1392 intern
->r_symndx
= (((int) ext
->r_bits
[0]
1393 << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
)
1394 | ((int) ext
->r_bits
[1]
1395 << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
)
1396 | ((int) ext
->r_bits
[2]
1397 << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
));
1398 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_LITTLE
)
1399 >> RELOC_BITS3_TYPE_SH_LITTLE
);
1400 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_LITTLE
) != 0;
1404 /* Swap a reloc out. */
1407 DEFUN (ecoff_swap_reloc_out
, (abfd
, src
, dst
),
1412 struct internal_reloc
*intern
= (struct internal_reloc
*) src
;
1413 RELOC
*ext
= (RELOC
*) dst
;
1415 bfd_h_put_32 (abfd
, intern
->r_vaddr
, (bfd_byte
*) ext
->r_vaddr
);
1416 if (abfd
->xvec
->header_byteorder_big_p
!= false)
1418 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_BIG
;
1419 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_BIG
;
1420 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_BIG
;
1421 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_BIG
)
1422 & RELOC_BITS3_TYPE_BIG
)
1423 | (intern
->r_extern
? RELOC_BITS3_EXTERN_BIG
: 0));
1427 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
;
1428 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
;
1429 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
;
1430 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_LITTLE
)
1431 & RELOC_BITS3_TYPE_LITTLE
)
1432 | (intern
->r_extern
? RELOC_BITS3_EXTERN_LITTLE
: 0));
1438 /* ECOFF relocs are either against external symbols, or against
1439 sections. If we are producing relocateable output, and the reloc
1440 is against an external symbol, the resulting reloc will also be
1441 against the same symbol. In such a case, we don't want to change
1442 anything about the way the reloc is handled, since it will all be
1443 done at final link time. Rather than put special case code into
1444 bfd_perform_relocation, all the reloc types use this howto
1445 function. It just short circuits the reloc if producing
1446 relocateable output against an external symbol. */
1448 static bfd_reloc_status_type
1449 ecoff_generic_reloc (abfd
,
1456 arelent
*reloc_entry
;
1459 asection
*input_section
;
1462 if (output_bfd
!= (bfd
*) NULL
1463 && (symbol
->flags
& BSF_SECTION_SYM
) == 0)
1465 reloc_entry
->address
+= input_section
->output_offset
;
1466 return bfd_reloc_ok
;
1469 return bfd_reloc_continue
;
1472 /* Do a REFHI relocation. The next reloc must be the corresponding
1473 REFLO. This has to be done in a function so that carry is handled
1476 static bfd_reloc_status_type
1477 ecoff_refhi_reloc (abfd
,
1484 arelent
*reloc_entry
;
1487 asection
*input_section
;
1490 bfd_reloc_status_type ret
;
1495 unsigned long vallo
;
1497 /* If we're relocating, and this an external symbol, we don't want
1498 to change anything. */
1499 if (output_bfd
!= (bfd
*) NULL
1500 && (symbol
->flags
& BSF_SECTION_SYM
) == 0)
1502 reloc_entry
->address
+= input_section
->output_offset
;
1503 return bfd_reloc_ok
;
1507 if (symbol
->section
== &bfd_und_section
1508 && output_bfd
== (bfd
*) NULL
)
1509 ret
= bfd_reloc_undefined
;
1511 rello
= reloc_entry
+ 1;
1512 BFD_ASSERT (rello
->howto
->type
== ECOFF_R_REFLO
1513 && *rello
->sym_ptr_ptr
== *reloc_entry
->sym_ptr_ptr
);
1515 if (bfd_is_com_section (symbol
->section
))
1518 relocation
= symbol
->value
;
1520 relocation
+= symbol
->section
->output_section
->vma
;
1521 relocation
+= symbol
->section
->output_offset
;
1522 relocation
+= reloc_entry
->addend
;
1524 if (reloc_entry
->address
> input_section
->_cooked_size
)
1525 return bfd_reloc_outofrange
;
1527 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1528 vallo
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ rello
->address
) & 0xffff;
1529 val
= ((insn
& 0xffff) << 16) + vallo
;
1532 /* The low order 16 bits are always treated as a signed value.
1533 Therefore, a negative value in the low order bits requires an
1534 adjustment in the high order bits. We need to make this
1535 adjustment in two ways: once for the bits we took from the data,
1536 and once for the bits we are putting back in to the data. */
1537 if ((vallo
& 0x8000) != 0)
1539 if ((val
& 0x8000) != 0)
1542 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1543 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1545 if (output_bfd
!= (bfd
*) NULL
)
1546 reloc_entry
->address
+= input_section
->output_offset
;
1551 /* Do a GPREL relocation. This is a 16 bit value which must become
1552 the offset from the gp register. */
1554 static bfd_reloc_status_type
1555 ecoff_gprel_reloc (abfd
,
1562 arelent
*reloc_entry
;
1565 asection
*input_section
;
1568 boolean relocateable
;
1573 /* If we're relocating, and this an external symbol, we don't want
1574 to change anything. */
1575 if (output_bfd
!= (bfd
*) NULL
1576 && (symbol
->flags
& BSF_SECTION_SYM
) == 0)
1578 reloc_entry
->address
+= input_section
->output_offset
;
1579 return bfd_reloc_ok
;
1582 if (output_bfd
!= (bfd
*) NULL
)
1583 relocateable
= true;
1586 relocateable
= false;
1587 output_bfd
= symbol
->section
->output_section
->owner
;
1590 if (symbol
->section
== &bfd_und_section
1591 && relocateable
== false)
1592 return bfd_reloc_undefined
;
1594 /* We have to figure out the gp value, so that we can adjust the
1595 symbol value correctly. We look up the symbol _gp in the output
1596 BFD. If we can't find it, we're stuck. We cache it in the ECOFF
1598 if (ecoff_data (output_bfd
)->gp
== 0)
1600 if (relocateable
!= false)
1602 /* Make up a value. */
1603 ecoff_data (output_bfd
)->gp
=
1604 symbol
->section
->output_section
->vma
+ 0x4000;
1612 count
= bfd_get_symcount (output_bfd
);
1613 sym
= bfd_get_outsymbols (output_bfd
);
1615 /* We should do something more friendly here, but we don't
1616 have a good reloc status to return. */
1617 if (sym
== (asymbol
**) NULL
)
1620 for (i
= 0; i
< count
; i
++, sym
++)
1622 register CONST
char *name
;
1624 name
= bfd_asymbol_name (*sym
);
1625 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1627 ecoff_data (output_bfd
)->gp
= bfd_asymbol_value (*sym
);
1632 /* We should do something more friendly here, but we don't have
1633 a good reloc status to return. */
1639 if (bfd_is_com_section (symbol
->section
))
1642 relocation
= symbol
->value
;
1644 relocation
+= symbol
->section
->output_section
->vma
;
1645 relocation
+= symbol
->section
->output_offset
;
1647 if (reloc_entry
->address
> input_section
->_cooked_size
)
1648 return bfd_reloc_outofrange
;
1650 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1652 /* Set val to the offset into the section (if we are relocating
1653 against an external symbol, insn & 0xffff will be zero and so
1654 will reloc_entry->addend). */
1655 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1659 /* Adjust val for the final section location and GP value. */
1660 val
+= (relocation
- ecoff_data (output_bfd
)->gp
);
1662 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1663 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1665 if (relocateable
!= false)
1666 reloc_entry
->address
+= input_section
->output_offset
;
1668 /* Make sure it fit in 16 bits. */
1669 if (val
>= 0x8000 && val
< 0xffff8000)
1670 return bfd_reloc_outofrange
;
1672 return bfd_reloc_ok
;
1675 /* How to process the various relocs types. */
1677 static reloc_howto_type ecoff_howto_table
[] =
1679 /* Reloc type 0 is ignored. The reloc reading code ensures that
1680 this is a reference to the .abs section, which will cause
1681 bfd_perform_relocation to do nothing. */
1682 HOWTO (ECOFF_R_IGNORE
, /* type */
1684 0, /* size (0 = byte, 1 = short, 2 = long) */
1685 8, /* bitsize (obsolete) */
1686 false, /* pc_relative */
1688 false, /* absolute (obsolete) */
1689 false, /* complain_on_overflow */
1690 0, /* special_function */
1691 "IGNORE", /* name */
1692 false, /* partial_inplace */
1695 false), /* pcrel_offset */
1697 /* A 16 bit reference to a symbol, normally from a data section. */
1698 HOWTO (ECOFF_R_REFHALF
, /* type */
1700 1, /* size (0 = byte, 1 = short, 2 = long) */
1701 16, /* bitsize (obsolete) */
1702 false, /* pc_relative */
1704 false, /* absolute (obsolete) */
1705 true, /* complain_on_overflow */
1706 ecoff_generic_reloc
, /* special_function */
1707 "REFHALF", /* name */
1708 true, /* partial_inplace */
1709 0xffff, /* src_mask */
1710 0xffff, /* dst_mask */
1711 false), /* pcrel_offset */
1713 /* A 32 bit reference to a symbol, normally from a data section. */
1714 HOWTO (ECOFF_R_REFWORD
, /* type */
1716 2, /* size (0 = byte, 1 = short, 2 = long) */
1717 32, /* bitsize (obsolete) */
1718 false, /* pc_relative */
1720 false, /* absolute (obsolete) */
1721 true, /* complain_on_overflow */
1722 ecoff_generic_reloc
, /* special_function */
1723 "REFWORD", /* name */
1724 true, /* partial_inplace */
1725 0xffffffff, /* src_mask */
1726 0xffffffff, /* dst_mask */
1727 false), /* pcrel_offset */
1729 /* A 26 bit absolute jump address. */
1730 HOWTO (ECOFF_R_JMPADDR
, /* type */
1732 2, /* size (0 = byte, 1 = short, 2 = long) */
1733 32, /* bitsize (obsolete) */
1734 false, /* pc_relative */
1736 false, /* absolute (obsolete) */
1737 true, /* complain_on_overflow */
1738 ecoff_generic_reloc
, /* special_function */
1739 "JMPADDR", /* name */
1740 true, /* partial_inplace */
1741 0x3ffffff, /* src_mask */
1742 0x3ffffff, /* dst_mask */
1743 false), /* pcrel_offset */
1745 /* The high 16 bits of a symbol value. Handled by the function
1746 ecoff_refhi_reloc. */
1747 HOWTO (ECOFF_R_REFHI
, /* type */
1748 16, /* rightshift */
1749 2, /* size (0 = byte, 1 = short, 2 = long) */
1750 32, /* bitsize (obsolete) */
1751 false, /* pc_relative */
1753 false, /* absolute (obsolete) */
1754 true, /* complain_on_overflow */
1755 ecoff_refhi_reloc
, /* special_function */
1757 true, /* partial_inplace */
1758 0xffff, /* src_mask */
1759 0xffff, /* dst_mask */
1760 false), /* pcrel_offset */
1762 /* The low 16 bits of a symbol value. */
1763 HOWTO (ECOFF_R_REFLO
, /* type */
1765 2, /* size (0 = byte, 1 = short, 2 = long) */
1766 32, /* bitsize (obsolete) */
1767 false, /* pc_relative */
1769 false, /* absolute (obsolete) */
1770 true, /* complain_on_overflow */
1771 ecoff_generic_reloc
, /* special_function */
1773 true, /* partial_inplace */
1774 0xffff, /* src_mask */
1775 0xffff, /* dst_mask */
1776 false), /* pcrel_offset */
1778 /* A reference to an offset from the gp register. Handled by the
1779 function ecoff_gprel_reloc. */
1780 HOWTO (ECOFF_R_GPREL
, /* type */
1782 2, /* size (0 = byte, 1 = short, 2 = long) */
1783 32, /* bitsize (obsolete) */
1784 false, /* pc_relative */
1786 false, /* absolute (obsolete) */
1787 true, /* complain_on_overflow */
1788 ecoff_gprel_reloc
, /* special_function */
1790 true, /* partial_inplace */
1791 0xffff, /* src_mask */
1792 0xffff, /* dst_mask */
1793 false), /* pcrel_offset */
1795 /* A reference to a literal using an offset from the gp register.
1796 Handled by the function ecoff_gprel_reloc. */
1797 HOWTO (ECOFF_R_LITERAL
, /* type */
1799 2, /* size (0 = byte, 1 = short, 2 = long) */
1800 32, /* bitsize (obsolete) */
1801 false, /* pc_relative */
1803 false, /* absolute (obsolete) */
1804 true, /* complain_on_overflow */
1805 ecoff_gprel_reloc
, /* special_function */
1806 "LITERAL", /* name */
1807 true, /* partial_inplace */
1808 0xffff, /* src_mask */
1809 0xffff, /* dst_mask */
1810 false) /* pcrel_offset */
1813 /* Read in the relocs for a section. */
1816 DEFUN (ecoff_slurp_reloc_table
, (abfd
, section
, symbols
),
1818 asection
*section AND
1821 RELOC
*external_relocs
;
1822 arelent
*internal_relocs
;
1826 if (section
->relocation
!= (arelent
*) NULL
1827 || section
->reloc_count
== 0
1828 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1831 if (ecoff_slurp_symbol_table (abfd
) == false)
1834 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1836 * section
->reloc_count
));
1837 external_relocs
= (RELOC
*) bfd_alloc (abfd
, RELSZ
* section
->reloc_count
);
1838 if (internal_relocs
== (arelent
*) NULL
1839 || external_relocs
== (RELOC
*) NULL
)
1841 bfd_error
= no_memory
;
1844 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1846 if (bfd_read (external_relocs
, 1, RELSZ
* section
->reloc_count
, abfd
)
1847 != RELSZ
* section
->reloc_count
)
1849 bfd_error
= system_call_error
;
1853 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1855 struct internal_reloc intern
;
1857 ecoff_swap_reloc_in (abfd
, external_relocs
+ i
, &intern
);
1859 if (intern
.r_type
> ECOFF_R_LITERAL
)
1862 if (intern
.r_extern
)
1864 /* r_symndx is an index into the external symbols. */
1865 BFD_ASSERT (intern
.r_symndx
>= 0
1867 < ecoff_data (abfd
)->symbolic_header
.iextMax
));
1868 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1873 CONST
char *sec_name
;
1876 /* r_symndx is a section key. */
1877 switch (intern
.r_symndx
)
1879 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1880 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1881 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1882 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1883 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1884 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1885 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1886 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1887 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1891 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1892 if (sec
== (asection
*) NULL
)
1894 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1896 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1897 if (intern
.r_type
== ECOFF_R_GPREL
1898 || intern
.r_type
== ECOFF_R_LITERAL
)
1899 rptr
->addend
+= ecoff_data (abfd
)->gp
;
1902 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1903 rptr
->howto
= &ecoff_howto_table
[intern
.r_type
];
1905 /* If the type is ECOFF_R_IGNORE, make sure this is a reference
1906 to the absolute section so that the reloc is ignored. */
1907 if (intern
.r_type
== ECOFF_R_IGNORE
)
1908 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1911 bfd_release (abfd
, external_relocs
);
1913 section
->relocation
= internal_relocs
;
1918 /* Get a canonical list of relocs. */
1921 DEFUN (ecoff_canonicalize_reloc
, (abfd
, section
, relptr
, symbols
),
1923 asection
*section AND
1924 arelent
**relptr AND
1929 if (section
->flags
& SEC_CONSTRUCTOR
)
1931 arelent_chain
*chain
;
1933 /* This section has relocs made up by us, not the file, so take
1934 them out of their chain and place them into the data area
1936 for (count
= 0, chain
= section
->constructor_chain
;
1937 count
< section
->reloc_count
;
1938 count
++, chain
= chain
->next
)
1939 *relptr
++ = &chain
->relent
;
1945 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1948 tblptr
= section
->relocation
;
1949 if (tblptr
== (arelent
*) NULL
)
1952 for (count
= 0; count
< section
->reloc_count
; count
++)
1953 *relptr
++ = tblptr
++;
1956 *relptr
= (arelent
*) NULL
;
1958 return section
->reloc_count
;
1961 /* Provided a BFD, a section and an offset into the section, calculate
1962 and return the name of the source file and the line nearest to the
1966 DEFUN (ecoff_find_nearest_line
, (abfd
,
1974 asection
*section AND
1975 asymbol
**ignore_symbols AND
1977 CONST
char **filename_ptr AND
1978 CONST
char **functionname_ptr AND
1979 unsigned int *retline_ptr
)
1985 struct pdr_ext
*pdr_ptr
;
1986 struct pdr_ext
*pdr_end
;
1988 unsigned char *line_ptr
;
1989 unsigned char *line_end
;
1992 /* If we're not in the .text section, we don't have any line
1994 if (strcmp (section
->name
, _TEXT
) != 0)
1997 /* Make sure we have the FDR's. */
1998 if (ecoff_slurp_symbolic_info (abfd
) == false
1999 || bfd_get_symcount (abfd
) == 0)
2002 /* Each file descriptor (FDR) has a memory address. Here we track
2003 down which FDR we want. The FDR's are stored in increasing
2004 memory order. If speed is ever important, this can become a
2005 binary search. We must ignore FDR's with no PDR entries; they
2006 will have the adr of the FDR before or after them. */
2007 fdr_start
= ecoff_data (abfd
)->fdr
;
2008 fdr_end
= fdr_start
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
2009 fdr_hold
= (FDR
*) NULL
;
2010 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2012 if (offset
< fdr_ptr
->adr
)
2014 if (fdr_ptr
->cpd
> 0)
2017 if (fdr_hold
== (FDR
*) NULL
)
2021 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2022 have an address, which is relative to the FDR address, and are
2023 also stored in increasing memory order. */
2024 offset
-= fdr_ptr
->adr
;
2025 pdr_ptr
= ecoff_data (abfd
)->external_pdr
+ fdr_ptr
->ipdFirst
;
2026 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
;
2027 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2028 if (offset
< pdr
.adr
)
2030 for (pdr_ptr
++; pdr_ptr
< pdr_end
; pdr_ptr
++)
2032 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2033 if (offset
< pdr
.adr
)
2037 /* Now we can look for the actual line number. The line numbers are
2038 stored in a very funky format, which I won't try to describe.
2039 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2040 we want; we need this to compute line_end. */
2041 line_end
= ecoff_data (abfd
)->line
;
2042 if (pdr_ptr
== pdr_end
)
2043 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2045 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2047 /* Now change pdr and pdr_ptr to the one we want. */
2049 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2053 line_ptr
= (ecoff_data (abfd
)->line
2054 + fdr_ptr
->cbLineOffset
2055 + pdr
.cbLineOffset
);
2056 while (line_ptr
< line_end
)
2061 delta
= *line_ptr
>> 4;
2064 count
= (*line_ptr
& 0xf) + 1;
2068 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2069 if (delta
>= 0x8000)
2074 if (offset
< count
* 4)
2076 offset
-= count
* 4;
2079 /* If offset is too large, this line is not interesting. */
2083 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2084 at least according to gdb/mipsread.c. */
2085 if (fdr_ptr
->rss
== -1)
2087 *filename_ptr
= NULL
;
2089 *functionname_ptr
= NULL
;
2094 ecoff_swap_ext_in (abfd
,
2095 (ecoff_data (abfd
)->external_ext
2098 *functionname_ptr
= ecoff_data (abfd
)->ssext
+ proc_ext
.asym
.iss
;
2105 *filename_ptr
= ecoff_data (abfd
)->ss
+ fdr_ptr
->issBase
+ fdr_ptr
->rss
;
2106 ecoff_swap_sym_in (abfd
,
2107 (ecoff_data (abfd
)->external_sym
2111 *functionname_ptr
= (ecoff_data (abfd
)->ss
2115 *retline_ptr
= lineno
;
2119 /* We can't use the generic linking routines for ECOFF, because we
2120 have to handle all the debugging information. The generic link
2121 routine just works out the section contents and attaches a list of
2124 We link by looping over all the seclets. We make two passes. On
2125 the first we set the actual section contents and determine the size
2126 of the debugging information. On the second we accumulate the
2127 debugging information and write it out.
2129 This currently always accumulates the debugging information, which
2130 is incorrect, because it ignores the -s and -S options of the
2131 linker. The linker needs to be modified to give us that
2132 information in a more useful format (currently it just provides a
2133 list of symbols which should appear in the output file). */
2135 /* Clear the output_has_begun flag for all the input BFD's. We use it
2136 to avoid linking in the debugging information for a BFD more than
2140 DEFUN (ecoff_clear_output_flags
, (abfd
),
2143 register asection
*o
;
2144 register bfd_seclet_type
*p
;
2146 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2147 for (p
= o
->seclets_head
;
2148 p
!= (bfd_seclet_type
*) NULL
;
2150 if (p
->type
== bfd_indirect_seclet
)
2151 p
->u
.indirect
.section
->owner
->output_has_begun
= false;
2154 /* Handle an indirect seclet on the first pass. Set the contents of
2155 the output section, and accumulate the debugging information if
2159 DEFUN (ecoff_rel
, (output_bfd
, seclet
, output_section
, data
, relocateable
),
2161 bfd_seclet_type
*seclet AND
2162 asection
*output_section AND
2164 boolean relocateable
)
2167 HDRR
*output_symhdr
;
2169 ecoff_symbol_type
*sym_ptr
;
2170 ecoff_symbol_type
*sym_end
;
2172 if ((output_section
->flags
& SEC_HAS_CONTENTS
)
2173 && !(output_section
->flags
& SEC_NEVER_LOAD
)
2174 && (output_section
->flags
& SEC_LOAD
)
2177 data
= (PTR
) bfd_get_relocated_section_contents (output_bfd
,
2181 if (bfd_set_section_contents (output_bfd
,
2192 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2194 /* We want to figure out how much space will be required to
2195 incorporate all the debugging information from input_bfd. We use
2196 the output_has_begun field to avoid adding it in more than once.
2197 The actual incorporation is done in the second pass, in
2198 ecoff_get_debug. The code has to parallel that code in its
2199 manipulations of output_symhdr. */
2201 if (input_bfd
->output_has_begun
)
2203 input_bfd
->output_has_begun
= true;
2205 output_symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2207 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2213 /* We just accumulate local symbols from a non-ECOFF BFD. The
2214 external symbols are handled separately. */
2216 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2217 get_symtab_upper_bound (input_bfd
));
2218 if (symbols
== (asymbol
**) NULL
)
2220 bfd_error
= no_memory
;
2223 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2225 for (sym_ptr
= symbols
; sym_ptr
< sym_end
; sym_ptr
++)
2229 len
= strlen ((*sym_ptr
)->name
);
2230 if (((*sym_ptr
)->flags
& BSF_EXPORT
) == 0)
2232 ++output_symhdr
->isymMax
;
2233 output_symhdr
->issMax
+= len
+ 1;
2237 bfd_release (output_bfd
, (PTR
) symbols
);
2239 ++output_symhdr
->ifdMax
;
2244 /* We simply add in the information from another ECOFF BFD. First
2245 we make sure we have the symbolic information. */
2246 if (ecoff_slurp_symbol_table (input_bfd
) == false)
2248 if (bfd_get_symcount (input_bfd
) == 0)
2251 input_symhdr
= &ecoff_data (input_bfd
)->symbolic_header
;
2253 /* Figure out how much information we are going to be putting in.
2254 The external symbols are handled separately. */
2255 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2256 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2257 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2258 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2259 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2260 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2261 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2262 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2263 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2265 /* The RFD's are special, since we create them if needed. */
2266 if (input_symhdr
->crfd
> 0)
2267 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2269 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2274 /* Handle an arbitrary seclet on the first pass. */
2277 DEFUN (ecoff_dump_seclet
, (abfd
, seclet
, section
, data
, relocateable
),
2279 bfd_seclet_type
*seclet AND
2280 asection
*section AND
2282 boolean relocateable
)
2284 switch (seclet
->type
)
2286 case bfd_indirect_seclet
:
2287 /* The contents of this section come from another one somewhere
2289 return ecoff_rel (abfd
, seclet
, section
, data
, relocateable
);
2291 case bfd_fill_seclet
:
2292 /* Fill in the section with fill.value. This is used to pad out
2293 sections, but we must avoid padding the .bss section. */
2294 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
2296 if (seclet
->u
.fill
.value
!= 0)
2301 char *d
= (char *) bfd_alloc (abfd
, seclet
->size
);
2305 for (i
= 0; i
< seclet
->size
; i
+=2)
2306 d
[i
] = seclet
->u
.fill
.value
>> 8;
2307 for (i
= 1; i
< seclet
->size
; i
+=2)
2308 d
[i
] = seclet
->u
.fill
.value
;
2309 ret
= bfd_set_section_contents (abfd
, section
, d
, seclet
->offset
,
2311 bfd_release (abfd
, (PTR
) d
);
2323 /* Add a string to the debugging information we are accumulating for a
2324 file. Return the offset from the fdr string base or from the
2325 external string base. */
2328 DEFUN (ecoff_add_string
, (output_bfd
, fdr
, string
, external
),
2331 CONST
char *string AND
2338 symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2339 len
= strlen (string
);
2342 strcpy (ecoff_data (output_bfd
)->ssext
+ symhdr
->issExtMax
, string
);
2343 ret
= symhdr
->issExtMax
;
2344 symhdr
->issExtMax
+= len
+ 1;
2348 strcpy (ecoff_data (output_bfd
)->ss
+ symhdr
->issMax
, string
);
2350 symhdr
->issMax
+= len
+ 1;
2351 fdr
->cbSs
+= len
+ 1;
2356 /* Accumulate the debugging information from an input section. */
2359 DEFUN (ecoff_get_debug
, (output_bfd
, seclet
, section
, relocateable
),
2361 bfd_seclet_type
*seclet AND
2362 asection
*section AND
2363 boolean relocateable
)
2366 HDRR
*output_symhdr
;
2368 ecoff_data_type
*output_ecoff
;
2369 ecoff_data_type
*input_ecoff
;
2371 struct sym_ext
*sym_out
;
2372 struct ext_ext
*ext_out
;
2373 ecoff_symbol_type
*esym_ptr
;
2374 ecoff_symbol_type
*esym_end
;
2377 struct fdr_ext
*fdr_out
;
2379 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2381 /* Don't get the information more than once. */
2382 if (input_bfd
->output_has_begun
)
2384 input_bfd
->output_has_begun
= true;
2386 output_ecoff
= ecoff_data (output_bfd
);
2387 output_symhdr
= &output_ecoff
->symbolic_header
;
2389 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2396 /* This is not an ECOFF BFD. Just gather the symbols. */
2398 memset (&fdr
, 0, sizeof fdr
);
2400 fdr
.adr
= bfd_get_section_vma (output_bfd
, section
) + seclet
->offset
;
2401 fdr
.issBase
= output_symhdr
->issMax
;
2403 fdr
.rss
= ecoff_add_string (output_bfd
,
2405 bfd_get_filename (input_bfd
),
2407 fdr
.isymBase
= output_symhdr
->isymMax
;
2409 /* Get the local symbols from the input BFD. */
2410 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2411 get_symtab_upper_bound (input_bfd
));
2412 if (symbols
== (asymbol
**) NULL
)
2414 bfd_error
= no_memory
;
2417 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2419 /* Handle the local symbols. Any external symbols are handled
2422 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
2426 if (((*sym_ptr
)->flags
& BSF_EXPORT
) != 0)
2428 memset (&internal_sym
, 0, sizeof internal_sym
);
2429 internal_sym
.iss
= ecoff_add_string (output_bfd
,
2434 if (bfd_is_com_section ((*sym_ptr
)->section
)
2435 || (*sym_ptr
)->section
== &bfd_und_section
)
2436 internal_sym
.value
= (*sym_ptr
)->value
;
2438 internal_sym
.value
= ((*sym_ptr
)->value
2439 + (*sym_ptr
)->section
->output_offset
2440 + (*sym_ptr
)->section
->output_section
->vma
);
2441 internal_sym
.st
= stNil
;
2442 internal_sym
.sc
= scUndefined
;
2443 internal_sym
.index
= indexNil
;
2444 ecoff_swap_sym_out (output_bfd
, &internal_sym
,
2445 (output_ecoff
->external_sym
2446 + output_symhdr
->isymMax
));
2448 ++output_symhdr
->isymMax
;
2451 bfd_release (output_bfd
, (PTR
) symbols
);
2453 /* Leave everything else in the FDR zeroed out. This will cause
2454 the lang field to be langC. The fBigendian field will
2455 indicate little endian format, but it doesn't matter because
2456 it only applies to aux fields and there are none. */
2458 ecoff_swap_fdr_out (output_bfd
, &fdr
,
2459 (output_ecoff
->external_fdr
2460 + output_symhdr
->ifdMax
));
2461 ++output_symhdr
->ifdMax
;
2465 /* This is an ECOFF BFD. We want to grab the information from
2466 input_bfd and attach it to output_bfd. */
2467 count
= bfd_get_symcount (input_bfd
);
2470 input_ecoff
= ecoff_data (input_bfd
);
2471 input_symhdr
= &input_ecoff
->symbolic_header
;
2473 /* I think that it is more efficient to simply copy the debugging
2474 information from the input BFD to the output BFD. Because ECOFF
2475 uses relative pointers for most of the debugging information,
2476 only a little of it has to be changed at all. */
2478 /* Swap in the local symbols, adjust their values, and swap them out
2479 again. The external symbols are handled separately. */
2480 sym_out
= output_ecoff
->external_sym
+ output_symhdr
->isymMax
;
2482 esym_ptr
= ecoff_data (input_bfd
)->canonical_symbols
;
2483 esym_end
= esym_ptr
+ count
;
2484 for (; esym_ptr
< esym_end
; esym_ptr
++)
2486 if (esym_ptr
->local
)
2490 ecoff_swap_sym_in (input_bfd
, esym_ptr
->native
.lnative
, &sym
);
2492 /* If we're producing an executable, move common symbols
2494 if (relocateable
== false)
2496 if (sym
.sc
== scCommon
)
2498 else if (sym
.sc
== scSCommon
)
2502 if (! bfd_is_com_section (esym_ptr
->symbol
.section
)
2503 && (esym_ptr
->symbol
.flags
& BSF_DEBUGGING
) == 0
2504 && esym_ptr
->symbol
.section
!= &bfd_und_section
)
2505 sym
.value
= (esym_ptr
->symbol
.value
2506 + esym_ptr
->symbol
.section
->output_offset
2507 + esym_ptr
->symbol
.section
->output_section
->vma
);
2508 ecoff_swap_sym_out (output_bfd
, &sym
, sym_out
);
2513 /* That should have accounted for all the local symbols in
2515 BFD_ASSERT ((sym_out
- output_ecoff
->external_sym
) - output_symhdr
->isymMax
2516 == input_symhdr
->isymMax
);
2518 /* Copy the information that does not need swapping. */
2519 memcpy (output_ecoff
->line
+ output_symhdr
->cbLine
,
2521 input_symhdr
->cbLine
* sizeof (unsigned char));
2522 memcpy (output_ecoff
->external_aux
+ output_symhdr
->iauxMax
,
2523 input_ecoff
->external_aux
,
2524 input_symhdr
->iauxMax
* sizeof (union aux_ext
));
2525 memcpy (output_ecoff
->ss
+ output_symhdr
->issMax
,
2527 input_symhdr
->issMax
* sizeof (char));
2529 /* Some of the information may need to be swapped. */
2530 if (output_bfd
->xvec
->header_byteorder_big_p
2531 == input_bfd
->xvec
->header_byteorder_big_p
)
2533 /* The two BFD's have the same endianness, so memcpy will
2535 memcpy (output_ecoff
->external_dnr
+ output_symhdr
->idnMax
,
2536 input_ecoff
->external_dnr
,
2537 input_symhdr
->idnMax
* sizeof (struct dnr_ext
));
2538 memcpy (output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
,
2539 input_ecoff
->external_pdr
,
2540 input_symhdr
->ipdMax
* sizeof (struct pdr_ext
));
2541 memcpy (output_ecoff
->external_opt
+ output_symhdr
->ioptMax
,
2542 input_ecoff
->external_opt
,
2543 input_symhdr
->ioptMax
* sizeof (struct opt_ext
));
2547 struct dnr_ext
*dnr_in
;
2548 struct dnr_ext
*dnr_end
;
2549 struct dnr_ext
*dnr_out
;
2550 struct pdr_ext
*pdr_in
;
2551 struct pdr_ext
*pdr_end
;
2552 struct pdr_ext
*pdr_out
;
2553 struct opt_ext
*opt_in
;
2554 struct opt_ext
*opt_end
;
2555 struct opt_ext
*opt_out
;
2557 /* The two BFD's have different endianness, so we must swap
2558 everything in and out. This code would always work, but it
2559 would be slow in the normal case. */
2560 dnr_in
= input_ecoff
->external_dnr
;
2561 dnr_end
= dnr_in
+ input_symhdr
->idnMax
;
2562 dnr_out
= output_ecoff
->external_dnr
+ output_symhdr
->idnMax
;
2563 for (; dnr_in
< dnr_end
; dnr_in
++, dnr_out
++)
2567 ecoff_swap_dnr_in (input_bfd
, dnr_in
, &dnr
);
2568 ecoff_swap_dnr_out (output_bfd
, &dnr
, dnr_out
);
2570 pdr_in
= input_ecoff
->external_pdr
;
2571 pdr_end
= pdr_in
+ input_symhdr
->ipdMax
;
2572 pdr_out
= output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
;
2573 for (; pdr_in
< pdr_end
; pdr_in
++, pdr_out
++)
2577 ecoff_swap_pdr_in (input_bfd
, pdr_in
, &pdr
);
2578 ecoff_swap_pdr_out (output_bfd
, &pdr
, pdr_out
);
2580 opt_in
= input_ecoff
->external_opt
;
2581 opt_end
= opt_in
+ input_symhdr
->ioptMax
;
2582 opt_out
= output_ecoff
->external_opt
+ output_symhdr
->ioptMax
;
2583 for (; opt_in
< opt_end
; opt_in
++, opt_out
++)
2587 ecoff_swap_opt_in (input_bfd
, opt_in
, &opt
);
2588 ecoff_swap_opt_out (output_bfd
, &opt
, opt_out
);
2592 /* Set ifdbase so that the external symbols know how to adjust their
2594 input_ecoff
->ifdbase
= output_symhdr
->ifdMax
;
2596 fdr_ptr
= input_ecoff
->fdr
;
2597 fdr_end
= fdr_ptr
+ input_symhdr
->ifdMax
;
2598 fdr_out
= output_ecoff
->external_fdr
+ output_symhdr
->ifdMax
;
2599 for (; fdr_ptr
< fdr_end
; fdr_ptr
++, fdr_out
++)
2605 /* The memory address for this fdr is the address for the seclet
2606 plus the offset to this fdr within input_bfd. */
2607 fdr
.adr
= (bfd_get_section_vma (output_bfd
, section
)
2609 + (fdr_ptr
->adr
- input_ecoff
->fdr
->adr
));
2611 fdr
.issBase
+= output_symhdr
->issMax
;
2612 fdr
.isymBase
+= output_symhdr
->isymMax
;
2613 fdr
.ilineBase
+= output_symhdr
->ilineMax
;
2614 fdr
.ioptBase
+= output_symhdr
->ioptMax
;
2615 fdr
.ipdFirst
+= output_symhdr
->ipdMax
;
2616 fdr
.iauxBase
+= output_symhdr
->iauxMax
;
2617 fdr
.rfdBase
+= output_symhdr
->crfd
;
2619 /* If there are no RFD's, we are going to add some. We don't
2620 want to adjust irfd for this, so that all the FDR's can share
2622 if (input_symhdr
->crfd
== 0)
2623 fdr
.crfd
= input_symhdr
->ifdMax
;
2625 if (fdr
.cbLine
!= 0)
2626 fdr
.cbLineOffset
+= output_symhdr
->cbLine
;
2628 ecoff_swap_fdr_out (output_bfd
, &fdr
, fdr_out
);
2631 if (input_symhdr
->crfd
> 0)
2633 struct rfd_ext
*rfd_in
;
2634 struct rfd_ext
*rfd_end
;
2635 struct rfd_ext
*rfd_out
;
2637 /* Swap and adjust the RFD's. RFD's are only created by the
2638 linker, so this will only be necessary if one of the input
2639 files is the result of a partial link. Presumably all
2640 necessary RFD's are present. */
2641 rfd_in
= input_ecoff
->external_rfd
;
2642 rfd_end
= rfd_in
+ input_symhdr
->crfd
;
2643 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
2644 for (; rfd_in
< rfd_end
; rfd_in
++, rfd_out
++)
2648 ecoff_swap_rfd_in (input_bfd
, rfd_in
, &rfd
);
2649 rfd
+= output_symhdr
->ifdMax
;
2650 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
2652 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2656 struct rfd_ext
*rfd_out
;
2657 struct rfd_ext
*rfd_end
;
2660 /* Create RFD's. Some of the debugging information includes
2661 relative file indices. These indices are taken as indices to
2662 the RFD table if there is one, or to the global table if
2663 there is not. If we did not create RFD's, we would have to
2664 parse and adjust all the debugging information which contains
2666 rfd
= output_symhdr
->ifdMax
;
2667 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
2668 rfd_end
= rfd_out
+ input_symhdr
->ifdMax
;
2669 for (; rfd_out
< rfd_end
; rfd_out
++, rfd
++)
2670 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
2671 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2674 /* Combine the register masks. */
2678 output_ecoff
->gprmask
|= input_ecoff
->gprmask
;
2679 for (i
= 0; i
< 4; i
++)
2680 output_ecoff
->cprmask
[i
] |= input_ecoff
->cprmask
[i
];
2683 /* Update the counts. */
2684 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2685 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2686 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2687 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2688 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2689 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2690 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2691 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2692 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2697 /* This is the actual link routine. It makes two passes over all the
2701 DEFUN (ecoff_bfd_seclet_link
, (abfd
, data
, relocateable
),
2704 boolean relocateable
)
2708 register asection
*o
;
2709 register bfd_seclet_type
*p
;
2710 asymbol
**sym_ptr_ptr
;
2714 /* We accumulate the debugging information counts in the symbolic
2716 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
2717 symhdr
->magic
= magicSym
;
2718 /* FIXME: What should the version stamp be? */
2720 symhdr
->ilineMax
= 0;
2724 symhdr
->isymMax
= 0;
2725 symhdr
->ioptMax
= 0;
2726 symhdr
->iauxMax
= 0;
2728 symhdr
->issExtMax
= 0;
2731 symhdr
->iextMax
= 0;
2733 /* We need to copy over the debugging symbols from each input BFD.
2734 When we do this copying, we have to adjust the text address in
2735 the FDR structures, so we have to know the text address used for
2736 the input BFD. Since we only want to copy the symbols once per
2737 input BFD, but we are going to look at each input BFD multiple
2738 times (once for each section it provides), we arrange to always
2739 look at the text section first. That means that when we copy the
2740 debugging information, we always know the text address. So we
2741 actually do each pass in two sub passes; first the text sections,
2742 then the non-text sections. We use the output_has_begun flag to
2743 determine whether we have copied over the debugging information
2746 /* Do the first pass: set the output section contents and count the
2747 debugging information. */
2748 ecoff_clear_output_flags (abfd
);
2749 for (ipass
= 0; ipass
< 2; ipass
++)
2751 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2753 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2754 so they are done on pass 0. For other sections the
2755 expression is true, so they are done on pass 1. */
2756 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2759 for (p
= o
->seclets_head
;
2760 p
!= (bfd_seclet_type
*) NULL
;
2763 if (ecoff_dump_seclet (abfd
, p
, o
, data
, relocateable
)
2770 /* We handle the external symbols differently. We use the ones
2771 attached to the output_bfd. The linker will have already
2772 determined which symbols are to be attached. Here we just
2773 determine how much space we will need for them. */
2774 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2775 if (sym_ptr_ptr
!= NULL
)
2779 sym_end
= sym_ptr_ptr
+ bfd_get_symcount (abfd
);
2780 for (; sym_ptr_ptr
< sym_end
; sym_ptr_ptr
++)
2782 if (((*sym_ptr_ptr
)->flags
& BSF_DEBUGGING
) == 0
2783 && ((*sym_ptr_ptr
)->flags
& BSF_LOCAL
) == 0)
2786 symhdr
->issExtMax
+= strlen ((*sym_ptr_ptr
)->name
) + 1;
2791 /* Adjust the counts so that structures are longword aligned. */
2792 symhdr
->cbLine
= (symhdr
->cbLine
+ 3) &~ 3;
2793 symhdr
->issMax
= (symhdr
->issMax
+ 3) &~ 3;
2794 symhdr
->issExtMax
= (symhdr
->issExtMax
+ 3) &~ 3;
2796 /* Now the counts in symhdr are the correct size for the debugging
2797 information. We allocate the right amount of space, and reset
2798 the counts so that the second pass can use them as indices. It
2799 would be possible to output the debugging information directly to
2800 the file in pass 2, rather than to build it in memory and then
2801 write it out. Outputting to the file would require a lot of
2802 seeks and small writes, though, and I think this approach is
2804 size
= (symhdr
->cbLine
* sizeof (unsigned char)
2805 + symhdr
->idnMax
* sizeof (struct dnr_ext
)
2806 + symhdr
->ipdMax
* sizeof (struct pdr_ext
)
2807 + symhdr
->isymMax
* sizeof (struct sym_ext
)
2808 + symhdr
->ioptMax
* sizeof (struct opt_ext
)
2809 + symhdr
->iauxMax
* sizeof (union aux_ext
)
2810 + symhdr
->issMax
* sizeof (char)
2811 + symhdr
->issExtMax
* sizeof (char)
2812 + symhdr
->ifdMax
* sizeof (struct fdr_ext
)
2813 + symhdr
->crfd
* sizeof (struct rfd_ext
)
2814 + symhdr
->iextMax
* sizeof (struct ext_ext
));
2815 raw
= (char *) bfd_alloc (abfd
, size
);
2816 if (raw
== (char *) NULL
)
2818 bfd_error
= no_memory
;
2821 ecoff_data (abfd
)->raw_size
= size
;
2822 ecoff_data (abfd
)->raw_syments
= (PTR
) raw
;
2824 /* Initialize the raw pointers. */
2825 #define SET(field, count, type) \
2826 ecoff_data (abfd)->field = (type *) raw; \
2827 raw += symhdr->count * sizeof (type)
2829 SET (line
, cbLine
, unsigned char);
2830 SET (external_dnr
, idnMax
, struct dnr_ext
);
2831 SET (external_pdr
, ipdMax
, struct pdr_ext
);
2832 SET (external_sym
, isymMax
, struct sym_ext
);
2833 SET (external_opt
, ioptMax
, struct opt_ext
);
2834 SET (external_aux
, iauxMax
, union aux_ext
);
2835 SET (ss
, issMax
, char);
2836 SET (ssext
, issExtMax
, char);
2837 SET (external_fdr
, ifdMax
, struct fdr_ext
);
2838 SET (external_rfd
, crfd
, struct rfd_ext
);
2839 SET (external_ext
, iextMax
, struct ext_ext
);
2842 /* Reset the counts so the second pass can use them to know how far
2844 symhdr
->ilineMax
= 0;
2848 symhdr
->isymMax
= 0;
2849 symhdr
->ioptMax
= 0;
2850 symhdr
->iauxMax
= 0;
2852 symhdr
->issExtMax
= 0;
2855 symhdr
->iextMax
= 0;
2857 /* Do the second pass: accumulate the debugging information. */
2858 ecoff_clear_output_flags (abfd
);
2859 for (ipass
= 0; ipass
< 2; ipass
++)
2861 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2863 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2865 for (p
= o
->seclets_head
;
2866 p
!= (bfd_seclet_type
*) NULL
;
2869 if (p
->type
== bfd_indirect_seclet
)
2871 if (ecoff_get_debug (abfd
, p
, o
, relocateable
) == false)
2878 /* Put in the external symbols. */
2879 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2880 if (sym_ptr_ptr
!= NULL
)
2883 struct ext_ext
*external_ext
;
2885 ssext
= ecoff_data (abfd
)->ssext
;
2886 external_ext
= ecoff_data (abfd
)->external_ext
;
2887 for (; *sym_ptr_ptr
!= NULL
; sym_ptr_ptr
++)
2892 sym_ptr
= *sym_ptr_ptr
;
2894 if ((sym_ptr
->flags
& BSF_DEBUGGING
) != 0
2895 || (sym_ptr
->flags
& BSF_LOCAL
) != 0)
2898 /* The enative pointer can be NULL for a symbol created by
2899 the linker via ecoff_make_empty_symbol. */
2900 if (bfd_asymbol_flavour (sym_ptr
) != bfd_target_ecoff_flavour
2901 || (((ecoff_symbol_type
*) sym_ptr
)->native
.enative
2902 == (struct ext_ext
*) NULL
))
2905 esym
.cobol_main
= 0;
2909 /* FIXME: we can do better than this for st and sc. */
2910 esym
.asym
.st
= stGlobal
;
2911 esym
.asym
.sc
= scAbs
;
2912 esym
.asym
.reserved
= 0;
2913 esym
.asym
.index
= indexNil
;
2917 ecoff_symbol_type
*ecoff_sym_ptr
;
2919 ecoff_sym_ptr
= (ecoff_symbol_type
*) sym_ptr
;
2920 if (ecoff_sym_ptr
->local
)
2922 ecoff_swap_ext_in (abfd
, ecoff_sym_ptr
->native
.enative
, &esym
);
2924 /* If we're producing an executable, move common symbols
2926 if (relocateable
== false)
2928 if (esym
.asym
.sc
== scCommon
)
2929 esym
.asym
.sc
= scBss
;
2930 else if (esym
.asym
.sc
== scSCommon
)
2931 esym
.asym
.sc
= scSBss
;
2934 /* Adjust the FDR index for the symbol by that used for
2936 esym
.ifd
+= ecoff_data (bfd_asymbol_bfd (sym_ptr
))->ifdbase
;
2939 esym
.asym
.iss
= symhdr
->issExtMax
;
2941 if (bfd_is_com_section (sym_ptr
->section
)
2942 || sym_ptr
->section
== &bfd_und_section
)
2943 esym
.asym
.value
= sym_ptr
->value
;
2945 esym
.asym
.value
= (sym_ptr
->value
2946 + sym_ptr
->section
->output_offset
2947 + sym_ptr
->section
->output_section
->vma
);
2949 ecoff_swap_ext_out (abfd
, &esym
, external_ext
+ symhdr
->iextMax
);
2951 ecoff_set_sym_index (sym_ptr
, symhdr
->iextMax
);
2955 strcpy (ssext
+ symhdr
->issExtMax
, sym_ptr
->name
);
2956 symhdr
->issExtMax
+= strlen (sym_ptr
->name
) + 1;
2960 /* Adjust the counts so that structures are longword aligned. */
2961 symhdr
->cbLine
= (symhdr
->cbLine
+ 3) &~ 3;
2962 symhdr
->issMax
= (symhdr
->issMax
+ 3) &~ 3;
2963 symhdr
->issExtMax
= (symhdr
->issExtMax
+ 3) &~ 3;
2968 /* Set the architecture. The only architecture we support here is
2969 mips. We set the architecture anyhow, since many callers ignore
2970 the return value. */
2973 DEFUN (ecoff_set_arch_mach
, (abfd
, arch
, machine
),
2975 enum bfd_architecture arch AND
2976 unsigned long machine
)
2978 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2979 return arch
== bfd_arch_mips
;
2982 /* Get the size of the section headers. We do not output the .scommon
2983 section which we created in ecoff_mkobject. */
2986 ecoff_sizeof_headers (abfd
, reloc
)
2990 return FILHSZ
+ AOUTSZ
+ (abfd
->section_count
- 1) * SCNHSZ
;
2993 /* Calculate the file position for each section, and set
2997 DEFUN (ecoff_compute_section_file_positions
, (abfd
),
3005 if (bfd_get_start_address (abfd
))
3006 abfd
->flags
|= EXEC_P
;
3008 sofar
= ecoff_sizeof_headers (abfd
, false);
3011 for (current
= abfd
->sections
;
3012 current
!= (asection
*) NULL
;
3013 current
= current
->next
)
3015 /* Only deal with sections which have contents */
3016 if (! (current
->flags
& SEC_HAS_CONTENTS
)
3017 || strcmp (current
->name
, SCOMMON
) == 0)
3020 /* On Ultrix, the data sections in an executable file must be
3021 aligned to a page boundary within the file. This does not
3022 affect the section size, though. FIXME: Does this work for
3024 if ((abfd
->flags
& EXEC_P
) != 0
3025 && first_data
!= false
3026 && (current
->flags
& SEC_CODE
) == 0)
3028 sofar
= (sofar
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
3032 /* Align the sections in the file to the same boundary on
3033 which they are aligned in virtual memory. */
3035 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3037 current
->filepos
= sofar
;
3039 sofar
+= current
->_raw_size
;
3041 /* make sure that this section is of the right size too */
3043 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3044 current
->_raw_size
+= sofar
- old_sofar
;
3047 ecoff_data (abfd
)->reloc_filepos
= sofar
;
3050 /* Set the contents of a section. */
3053 DEFUN (ecoff_set_section_contents
, (abfd
, section
, location
, offset
, count
),
3055 asection
*section AND
3058 bfd_size_type count
)
3060 if (abfd
->output_has_begun
== false)
3061 ecoff_compute_section_file_positions (abfd
);
3063 bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
3066 return (bfd_write (location
, 1, count
, abfd
) == count
) ? true : false;
3071 /* Write out an ECOFF file. */
3074 DEFUN (ecoff_write_object_contents
, (abfd
),
3080 file_ptr reloc_base
;
3082 unsigned long reloc_size
;
3083 unsigned long text_size
;
3084 unsigned long text_start
;
3085 unsigned long data_size
;
3086 unsigned long data_start
;
3087 unsigned long bss_size
;
3088 struct internal_filehdr internal_f
;
3089 struct internal_aouthdr internal_a
;
3092 bfd_error
= system_call_error
;
3094 if(abfd
->output_has_begun
== false)
3095 ecoff_compute_section_file_positions(abfd
);
3097 if (abfd
->sections
!= (asection
*) NULL
)
3098 scn_base
= abfd
->sections
->filepos
;
3101 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
3105 for (current
= abfd
->sections
;
3106 current
!= (asection
*)NULL
;
3107 current
= current
->next
)
3109 if (strcmp (current
->name
, SCOMMON
) == 0)
3111 current
->target_index
= count
;
3113 if (current
->reloc_count
!= 0)
3115 bfd_size_type relsize
;
3117 current
->rel_filepos
= reloc_base
;
3118 relsize
= current
->reloc_count
* RELSZ
;
3119 reloc_size
+= relsize
;
3120 reloc_base
+= relsize
;
3123 current
->rel_filepos
= 0;
3126 sym_base
= reloc_base
+ reloc_size
;
3128 /* At least on Ultrix, the symbol table of an executable file must
3129 be aligned to a page boundary. FIXME: Is this true on other
3131 if ((abfd
->flags
& EXEC_P
) != 0)
3132 sym_base
= (sym_base
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
3134 ecoff_data (abfd
)->sym_filepos
= sym_base
;
3136 text_size
= ecoff_sizeof_headers (abfd
, false);
3142 /* Write section headers to the file. */
3144 internal_f
.f_nscns
= 0;
3145 if (bfd_seek (abfd
, (file_ptr
) (FILHSZ
+ AOUTSZ
), SEEK_SET
) != 0)
3147 for (current
= abfd
->sections
;
3148 current
!= (asection
*) NULL
;
3149 current
= current
->next
)
3151 struct internal_scnhdr section
;
3154 if (strcmp (current
->name
, SCOMMON
) == 0)
3156 BFD_ASSERT (bfd_get_section_size_before_reloc (current
) == 0
3157 && current
->reloc_count
== 0);
3161 ++internal_f
.f_nscns
;
3163 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
3165 /* FIXME: is this correct for shared libraries? I think it is
3166 but I have no platform to check. Ian Lance Taylor. */
3167 vma
= bfd_get_section_vma (abfd
, current
);
3168 if (strcmp (current
->name
, _LIB
) == 0)
3169 section
.s_vaddr
= 0;
3171 section
.s_vaddr
= vma
;
3173 section
.s_paddr
= vma
;
3174 section
.s_size
= bfd_get_section_size_before_reloc (current
);
3176 /* If this section has no size or is unloadable then the scnptr
3178 if (current
->_raw_size
== 0
3179 || (current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
3180 section
.s_scnptr
= 0;
3182 section
.s_scnptr
= current
->filepos
;
3183 section
.s_relptr
= current
->rel_filepos
;
3185 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3186 object file produced by the assembler is supposed to point to
3187 information about how much room is required by objects of
3188 various different sizes. I think this only matters if we
3189 want the linker to compute the best size to use, or
3190 something. I don't know what happens if the information is
3192 section
.s_lnnoptr
= 0;
3194 section
.s_nreloc
= current
->reloc_count
;
3195 section
.s_nlnno
= 0;
3196 section
.s_flags
= sec_to_styp_flags (current
->name
, current
->flags
);
3201 ecoff_swap_scnhdr_out (abfd
, (PTR
) §ion
, (PTR
) &buff
);
3202 if (bfd_write ((PTR
) &buff
, 1, SCNHSZ
, abfd
) != SCNHSZ
)
3206 if ((section
.s_flags
& STYP_TEXT
) != 0)
3208 text_size
+= bfd_get_section_size_before_reloc (current
);
3209 if (text_start
== 0 || text_start
> vma
)
3212 else if ((section
.s_flags
& STYP_RDATA
) != 0
3213 || (section
.s_flags
& STYP_DATA
) != 0
3214 || (section
.s_flags
& STYP_LIT8
) != 0
3215 || (section
.s_flags
& STYP_LIT4
) != 0
3216 || (section
.s_flags
& STYP_SDATA
) != 0)
3218 data_size
+= bfd_get_section_size_before_reloc (current
);
3219 if (data_start
== 0 || data_start
> vma
)
3222 else if ((section
.s_flags
& STYP_BSS
) != 0
3223 || (section
.s_flags
& STYP_SBSS
) != 0)
3224 bss_size
+= bfd_get_section_size_before_reloc (current
);
3227 /* Set up the file header. */
3229 internal_f
.f_magic
= MIPS_MAGIC_2
;
3232 We will NOT put a fucking timestamp in the header here. Every time you
3233 put it back, I will come in and take it out again. I'm sorry. This
3234 field does not belong here. We fill it with a 0 so it compares the
3235 same but is not a reasonable time. -- gnu@cygnus.com
3237 internal_f
.f_timdat
= 0;
3239 if (bfd_get_symcount (abfd
) != 0)
3241 /* The ECOFF f_nsyms field is not actually the number of
3242 symbols, it's the size of symbolic information header. */
3243 internal_f
.f_nsyms
= sizeof (struct hdr_ext
);
3244 internal_f
.f_symptr
= sym_base
;
3248 internal_f
.f_nsyms
= 0;
3249 internal_f
.f_symptr
= 0;
3252 internal_f
.f_opthdr
= AOUTSZ
;
3254 internal_f
.f_flags
= F_LNNO
;
3255 if (reloc_size
== 0)
3256 internal_f
.f_flags
|= F_RELFLG
;
3257 if (bfd_get_symcount (abfd
) == 0)
3258 internal_f
.f_flags
|= F_LSYMS
;
3259 if (abfd
->flags
& EXEC_P
)
3260 internal_f
.f_flags
|= F_EXEC
;
3262 if (! abfd
->xvec
->byteorder_big_p
)
3263 internal_f
.f_flags
|= F_AR32WR
;
3265 internal_f
.f_flags
|= F_AR32W
;
3267 /* Set up the ``optional'' header. */
3268 internal_a
.magic
= ZMAGIC
;
3270 /* FIXME: What should this be? */
3271 internal_a
.vstamp
= 0;
3273 /* At least on Ultrix, these have to be rounded to page boundaries.
3274 FIXME: Is this true on other platforms? */
3275 internal_a
.tsize
= (text_size
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
3276 internal_a
.text_start
= text_start
&~ (PAGE_SIZE
- 1);
3277 internal_a
.dsize
= (data_size
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
3278 internal_a
.data_start
= data_start
&~ (PAGE_SIZE
- 1);
3280 /* On Ultrix, the initial portions of the .sbss and .bss segments
3281 are at the end of the data section. The bsize field in the
3282 optional header records how many bss bytes are required beyond
3283 those in the data section. The value is not rounded to a page
3285 if (bss_size
< internal_a
.dsize
- data_size
)
3288 bss_size
-= internal_a
.dsize
- data_size
;
3289 internal_a
.bsize
= bss_size
;
3290 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
3292 internal_a
.entry
= bfd_get_start_address (abfd
);
3294 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
3296 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
3297 for (i
= 0; i
< 4; i
++)
3298 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
3300 /* Write out the file header and the optional header. */
3302 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3307 ecoff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, (PTR
) &buff
);
3308 if (bfd_write ((PTR
) &buff
, 1, FILHSZ
, abfd
) != FILHSZ
)
3315 ecoff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, (PTR
) &buff
);
3316 if (bfd_write ((PTR
) &buff
, 1, AOUTSZ
, abfd
) != AOUTSZ
)
3320 /* Write out the relocs. */
3321 for (current
= abfd
->sections
;
3322 current
!= (asection
*) NULL
;
3323 current
= current
->next
)
3326 arelent
**reloc_ptr_ptr
;
3327 arelent
**reloc_end
;
3330 if (current
->reloc_count
== 0)
3333 buff
= (RELOC
*) bfd_alloc (abfd
, current
->reloc_count
* RELSZ
);
3334 if (buff
== (RELOC
*) NULL
)
3336 bfd_error
= no_memory
;
3340 reloc_ptr_ptr
= current
->orelocation
;
3341 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
3343 for (; reloc_ptr_ptr
< reloc_end
; reloc_ptr_ptr
++, out_ptr
++)
3347 struct internal_reloc in
;
3349 memset (&in
, 0, sizeof in
);
3351 reloc
= *reloc_ptr_ptr
;
3352 sym
= *reloc
->sym_ptr_ptr
;
3354 in
.r_vaddr
= reloc
->address
+ bfd_get_section_vma (abfd
, current
);
3355 in
.r_type
= reloc
->howto
->type
;
3356 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
3358 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
3365 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
3366 if (strcmp (name
, ".text") == 0)
3367 in
.r_symndx
= RELOC_SECTION_TEXT
;
3368 else if (strcmp (name
, ".rdata") == 0)
3369 in
.r_symndx
= RELOC_SECTION_RDATA
;
3370 else if (strcmp (name
, ".data") == 0)
3371 in
.r_symndx
= RELOC_SECTION_DATA
;
3372 else if (strcmp (name
, ".sdata") == 0)
3373 in
.r_symndx
= RELOC_SECTION_SDATA
;
3374 else if (strcmp (name
, ".sbss") == 0)
3375 in
.r_symndx
= RELOC_SECTION_SBSS
;
3376 else if (strcmp (name
, ".bss") == 0)
3377 in
.r_symndx
= RELOC_SECTION_BSS
;
3378 else if (strcmp (name
, ".init") == 0)
3379 in
.r_symndx
= RELOC_SECTION_INIT
;
3380 else if (strcmp (name
, ".lit8") == 0)
3381 in
.r_symndx
= RELOC_SECTION_LIT8
;
3382 else if (strcmp (name
, ".lit4") == 0)
3383 in
.r_symndx
= RELOC_SECTION_LIT4
;
3389 ecoff_swap_reloc_out (abfd
, (PTR
) &in
, (PTR
) out_ptr
);
3392 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3394 if (bfd_write ((PTR
) buff
, RELSZ
, current
->reloc_count
, abfd
)
3395 != RELSZ
* current
->reloc_count
)
3397 bfd_release (abfd
, (PTR
) buff
);
3400 /* Write out the symbolic debugging information. */
3401 if (bfd_get_symcount (abfd
) > 0)
3404 unsigned long sym_offset
;
3405 struct hdr_ext buff
;
3407 /* Set up the offsets in the symbolic header. */
3408 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
3409 sym_offset
= ecoff_data (abfd
)->sym_filepos
+ sizeof (struct hdr_ext
);
3411 #define SET(offset, size, ptr) \
3412 if (symhdr->size == 0) \
3413 symhdr->offset = 0; \
3415 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3416 - (char *) ecoff_data (abfd)->raw_syments) \
3419 SET (cbLineOffset
, cbLine
, line
);
3420 SET (cbDnOffset
, idnMax
, external_dnr
);
3421 SET (cbPdOffset
, ipdMax
, external_pdr
);
3422 SET (cbSymOffset
, isymMax
, external_sym
);
3423 SET (cbOptOffset
, ioptMax
, external_opt
);
3424 SET (cbAuxOffset
, iauxMax
, external_aux
);
3425 SET (cbSsOffset
, issMax
, ss
);
3426 SET (cbSsExtOffset
, issExtMax
, ssext
);
3427 SET (cbFdOffset
, ifdMax
, external_fdr
);
3428 SET (cbRfdOffset
, crfd
, external_rfd
);
3429 SET (cbExtOffset
, iextMax
, external_ext
);
3432 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
,
3435 ecoff_swap_hdr_out (abfd
, &ecoff_data (abfd
)->symbolic_header
, &buff
);
3436 if (bfd_write ((PTR
) &buff
, 1, sizeof buff
, abfd
) != sizeof buff
)
3438 if (bfd_write ((PTR
) ecoff_data (abfd
)->raw_syments
, 1,
3439 ecoff_data (abfd
)->raw_size
, abfd
)
3440 != ecoff_data (abfd
)->raw_size
)
3447 /* Archive handling. ECOFF uses what appears to be a unique type of
3448 archive header (which I call an armap). The byte ordering of the
3449 armap and the contents are encoded in the name of the armap itself.
3450 At least for now, we only support archives with the same byte
3451 ordering in the armap and the contents.
3453 The first four bytes in the armap are the number of symbol
3454 definitions. This is always a power of two.
3456 This is followed by the symbol definitions. Each symbol definition
3457 occupies 8 bytes. The first four bytes are the offset from the
3458 start of the armap strings to the null-terminated string naming
3459 this symbol. The second four bytes are the file offset to the
3460 archive member which defines this symbol. If the second four bytes
3461 are 0, then this is not actually a symbol definition, and it should
3464 The symbols are hashed into the armap with a closed hashing scheme.
3465 See the functions below for the details of the algorithm.
3467 We could use the hash table when looking up symbols in a library.
3468 This would require a new BFD target entry point to replace the
3469 bfd_get_next_mapent function used by the linker.
3471 After the symbol definitions comes four bytes holding the size of
3472 the string table, followed by the string table itself. */
3474 /* The name of an archive headers looks like this:
3475 __________E[BL]E[BL]_ (with a trailing space).
3476 The trailing space is changed to an X if the archive is changed to
3477 indicate that the armap is out of date. */
3479 #define ARMAP_BIG_ENDIAN 'B'
3480 #define ARMAP_LITTLE_ENDIAN 'L'
3481 #define ARMAP_MARKER 'E'
3482 #define ARMAP_START "__________"
3483 #define ARMAP_HEADER_MARKER_INDEX 10
3484 #define ARMAP_HEADER_ENDIAN_INDEX 11
3485 #define ARMAP_OBJECT_MARKER_INDEX 12
3486 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3487 #define ARMAP_END_INDEX 14
3488 #define ARMAP_END "_ "
3490 /* This is a magic number used in the hashing algorithm. */
3491 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3493 /* This returns the hash value to use for a string. It also sets
3494 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3495 is the number of entries in the hash table, and HLOG is the log
3499 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3501 unsigned int *rehash
;
3509 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3510 hash
*= ARMAP_HASH_MAGIC
;
3511 *rehash
= (hash
& (size
- 1)) | 1;
3512 return hash
>> (32 - hlog
);
3515 /* Read in the armap. */
3518 DEFUN (ecoff_slurp_armap
, (abfd
),
3523 struct areltdata
*mapdata
;
3524 bfd_size_type parsed_size
;
3526 struct artdata
*ardata
;
3529 struct symdef
*symdef_ptr
;
3532 /* Get the name of the first element. */
3533 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3539 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
3541 /* See if the first element is an armap. */
3542 if (strncmp (nextname
, ARMAP_START
, sizeof ARMAP_START
- 1) != 0
3543 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3544 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3545 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3546 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3547 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3548 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3549 || strncmp (nextname
+ ARMAP_END_INDEX
,
3550 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3552 bfd_has_map (abfd
) = false;
3556 /* Make sure we have the right byte ordering. */
3557 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3558 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3559 || ((nextname
[ARMAP_OBJECT_MARKER_INDEX
] == ARMAP_BIG_ENDIAN
)
3560 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3562 bfd_error
= wrong_format
;
3566 /* Read in the armap. */
3567 ardata
= bfd_ardata (abfd
);
3568 mapdata
= snarf_ar_hdr (abfd
);
3569 if (mapdata
== (struct areltdata
*) NULL
)
3571 parsed_size
= mapdata
->parsed_size
;
3572 bfd_release (abfd
, (PTR
) mapdata
);
3574 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3575 if (raw_armap
== (char *) NULL
)
3577 bfd_error
= no_memory
;
3581 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3583 bfd_error
= malformed_archive
;
3584 bfd_release (abfd
, (PTR
) raw_armap
);
3588 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3590 ardata
->symdef_count
= 0;
3591 ardata
->cache
= (struct ar_cache
*) NULL
;
3593 /* Hack: overlay the symdefs on top of the raw archive data. This
3594 is the way do_slurp_bsd_armap works. */
3595 raw_ptr
= raw_armap
+ LONG_SIZE
;
3596 symdef_ptr
= (struct symdef
*) raw_ptr
;
3597 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3598 stringbase
= raw_ptr
+ count
* (2 * LONG_SIZE
) + LONG_SIZE
;
3600 #ifdef CHECK_ARMAP_HASH
3604 /* Double check that I have the hashing algorithm right by making
3605 sure that every symbol can be looked up successfully. */
3607 for (i
= 1; i
< count
; i
<<= 1)
3609 BFD_ASSERT (i
== count
);
3611 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3613 unsigned int name_offset
, file_offset
;
3614 unsigned int hash
, rehash
, srch
;
3616 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3617 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3618 if (file_offset
== 0)
3620 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3625 /* See if we can rehash to this location. */
3626 for (srch
= (hash
+ rehash
) & (count
- 1);
3627 srch
!= hash
&& srch
!= i
;
3628 srch
= (srch
+ rehash
) & (count
- 1))
3629 BFD_ASSERT (bfd_h_get_32 (abfd
,
3632 + (srch
* 2 * LONG_SIZE
)
3635 BFD_ASSERT (srch
== i
);
3639 raw_ptr
= raw_armap
+ LONG_SIZE
;
3640 #endif /* CHECK_ARMAP_HASH */
3642 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3644 unsigned int name_offset
, file_offset
;
3646 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3647 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3648 if (file_offset
== 0)
3650 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3651 symdef_ptr
->file_offset
= file_offset
;
3653 ++ardata
->symdef_count
;
3656 ardata
->first_file_filepos
= bfd_tell (abfd
);
3657 /* Pad to an even boundary. */
3658 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3660 bfd_has_map (abfd
) = true;
3665 /* Write out an armap. */
3668 DEFUN (ecoff_write_armap
, (abfd
, elength
, map
, orl_count
, stridx
),
3670 unsigned int elength AND
3672 unsigned int orl_count AND
3675 unsigned int hashsize
, hashlog
;
3676 unsigned int symdefsize
;
3678 unsigned int stringsize
;
3679 unsigned int mapsize
;
3682 struct stat statbuf
;
3684 bfd_byte temp
[LONG_SIZE
];
3685 bfd_byte
*hashtable
;
3689 /* Ultrix appears to use as a hash table size the least power of two
3690 greater than twice the number of entries. */
3691 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3693 hashsize
= 1 << hashlog
;
3695 symdefsize
= hashsize
* 2 * LONG_SIZE
;
3697 stringsize
= stridx
+ padit
;
3699 /* Include 8 bytes to store symdefsize and stringsize in output. */
3700 mapsize
= LONG_SIZE
+ symdefsize
+ stringsize
+ LONG_SIZE
;
3702 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3704 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3706 /* Work out the ECOFF armap name. */
3707 strcpy (hdr
.ar_name
, ARMAP_START
);
3708 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3709 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3710 (abfd
->xvec
->header_byteorder_big_p
3712 : ARMAP_LITTLE_ENDIAN
);
3713 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3714 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3715 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3716 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3718 /* Write the timestamp of the archive header to be just a little bit
3719 later than the timestamp of the file, otherwise the linker will
3720 complain that the index is out of date. Actually, the Ultrix
3721 linker just checks the archive name; the GNU linker may check the
3723 if (stat (abfd
->filename
, &statbuf
) < 0)
3724 statbuf
.st_mtime
= time ((PTR
) NULL
);
3725 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3727 /* The DECstation uses zeroes for the uid, gid and mode of the
3729 hdr
.ar_uid
[0] = '0';
3730 hdr
.ar_gid
[0] = '0';
3731 hdr
.ar_mode
[0] = '0';
3733 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3735 hdr
.ar_fmag
[0] = '`';
3736 hdr
.ar_fmag
[1] = '\n';
3738 /* Turn all null bytes in the header into spaces. */
3739 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3740 if (((char *)(&hdr
))[i
] == '\0')
3741 (((char *)(&hdr
))[i
]) = ' ';
3743 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3744 != sizeof (struct ar_hdr
))
3747 bfd_h_put_32 (abfd
, hashsize
, temp
);
3748 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
3751 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3753 current
= abfd
->archive_head
;
3755 for (i
= 0; i
< orl_count
; i
++)
3757 unsigned int hash
, rehash
;
3759 /* Advance firstreal to the file position of this archive
3761 if (((bfd
*) map
[i
].pos
) != last_elt
)
3765 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3766 firstreal
+= firstreal
% 2;
3767 current
= current
->next
;
3769 while (current
!= (bfd
*) map
[i
].pos
);
3774 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3775 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
3776 + (hash
* 2 * LONG_SIZE
)
3782 /* The desired slot is already taken. */
3783 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3785 srch
= (srch
+ rehash
) & (hashsize
- 1))
3786 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
3787 + (srch
* 2 * LONG_SIZE
)
3792 BFD_ASSERT (srch
!= hash
);
3797 bfd_h_put_32 (abfd
, map
[i
].namidx
,
3798 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
));
3799 bfd_h_put_32 (abfd
, firstreal
,
3800 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
+ LONG_SIZE
));
3803 if (bfd_write (hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3806 bfd_release (abfd
, hashtable
);
3808 /* Now write the strings. */
3809 bfd_h_put_32 (abfd
, stringsize
, temp
);
3810 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
3812 for (i
= 0; i
< orl_count
; i
++)
3816 len
= strlen (*map
[i
].name
) + 1;
3817 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3821 /* The spec sez this should be a newline. But in order to be
3822 bug-compatible for DECstation ar we use a null. */
3825 if (bfd_write ("\0", 1, 1, abfd
) != 1)
3832 /* We just use the generic extended name support. This is a GNU
3834 #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
3836 /* See whether this BFD is an archive. If it is, read in the armap
3837 and the extended name table. */
3840 DEFUN (ecoff_archive_p
, (abfd
),
3843 char armag
[SARMAG
+ 1];
3845 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3846 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3848 bfd_error
= wrong_format
;
3849 return (bfd_target
*) NULL
;
3852 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3853 involves a cast, we can't do it as the left operand of
3855 abfd
->tdata
.aout_ar_data
=
3856 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3858 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3860 bfd_error
= no_memory
;
3861 return (bfd_target
*) NULL
;
3864 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3866 if (ecoff_slurp_armap (abfd
) == false
3867 || ecoff_slurp_extended_name_table (abfd
) == false)
3869 bfd_release (abfd
, bfd_ardata (abfd
));
3870 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3871 return (bfd_target
*) NULL
;
3877 static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table
= {
3878 (void (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_in */
3879 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_in */
3880 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_in */
3881 (unsigned (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_out */
3882 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_out */
3883 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_out */
3884 ecoff_swap_reloc_out
, ecoff_swap_filehdr_out
, ecoff_swap_aouthdr_out
,
3885 ecoff_swap_scnhdr_out
,
3886 FILHSZ
, AOUTSZ
, SCNHSZ
, 0, 0, 0, true,
3887 ecoff_swap_filehdr_in
, ecoff_swap_aouthdr_in
, ecoff_swap_scnhdr_in
,
3888 ecoff_bad_format_hook
, ecoff_set_arch_mach_hook
, ecoff_mkobject_hook
,
3889 styp_to_sec_flags
, ecoff_make_section_hook
, ecoff_set_alignment_hook
,
3890 ecoff_slurp_symbol_table
3893 /* get_lineno could be written for ECOFF, but it would currently only
3894 be useful for linking ECOFF and COFF files together, which doesn't
3896 #define ecoff_get_lineno \
3897 ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr)
3899 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
3900 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
3901 #define ecoff_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
3902 #define ecoff_truncate_arname bfd_dont_truncate_arname
3903 #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file
3904 #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
3905 #define ecoff_get_section_contents bfd_generic_get_section_contents
3906 #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
3907 #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup
3908 #define ecoff_bfd_debug_info_start bfd_void
3909 #define ecoff_bfd_debug_info_end bfd_void
3910 #define ecoff_bfd_debug_info_accumulate \
3911 ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void)
3912 #define ecoff_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
3913 #define ecoff_bfd_relax_section bfd_generic_relax_section
3915 bfd_target ecoff_little_vec
=
3917 "ecoff-littlemips", /* name */
3918 bfd_target_ecoff_flavour
,
3919 false, /* data byte order is little */
3920 false, /* header byte order is little */
3922 (HAS_RELOC
| EXEC_P
| /* object flags */
3923 HAS_LINENO
| HAS_DEBUG
|
3924 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
),
3926 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect
3928 0, /* leading underscore */
3929 '/', /* ar_pad_char */
3930 15, /* ar_max_namelen */
3931 3, /* minimum alignment power */
3932 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* data */
3933 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* hdrs */
3935 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
3936 ecoff_archive_p
, _bfd_dummy_target
},
3937 {bfd_false
, ecoff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
3939 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
3940 _bfd_write_archive_contents
, bfd_false
},
3943 (PTR
) &bfd_ecoff_std_swap_table
3946 bfd_target ecoff_big_vec
=
3948 "ecoff-bigmips", /* name */
3949 bfd_target_ecoff_flavour
,
3950 true, /* data byte order is big */
3951 true, /* header byte order is big */
3953 (HAS_RELOC
| EXEC_P
| /* object flags */
3954 HAS_LINENO
| HAS_DEBUG
|
3955 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
),
3957 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect flags */
3958 0, /* leading underscore */
3959 ' ', /* ar_pad_char */
3960 16, /* ar_max_namelen */
3961 3, /* minimum alignment power */
3962 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
,
3963 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
,
3964 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
3965 ecoff_archive_p
, _bfd_dummy_target
},
3966 {bfd_false
, ecoff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
3968 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
3969 _bfd_write_archive_contents
, bfd_false
},
3972 (PTR
) &bfd_ecoff_std_swap_table
3973 /* Note that there is another bfd_target just above this one. If
3974 you are adding initializers here, you should be adding them there