1 /* BFD back-end for MIPS Extended-Coff files.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support added by Ian Lance Taylor, ian@cygnus.com.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "aout/ranlib.h"
28 #include "coff/mips.h"
29 #include "coff/internal.h"
31 #include "coff/symconst.h"
32 #include "coff/ecoff-ext.h"
36 /* Each canonical asymbol really looks like this. */
38 typedef struct ecoff_symbol_struct
40 /* The actual symbol which the rest of BFD works with */
43 /* The fdr for this symbol. */
46 /* true if this is a local symbol rather than an external one. */
49 /* A pointer to the unswapped hidden information for this symbol */
52 struct sym_ext
*lnative
;
53 struct ext_ext
*enative
;
58 /* We take the address of the first element of a asymbol to ensure that the
59 macro is only ever applied to an asymbol. */
60 #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd)))
62 /* The page boundary used to align sections in the executable file. */
63 #define PAGE_SIZE 0x2000
65 /* The linker needs a section to hold small common variables while
66 linking. There is no convenient way to create it when the linker
67 needs it, so we always create one for each BFD. We then avoid
69 #define SCOMMON ".scommon"
71 /* MIPS ECOFF has COFF sections, but the debugging information is
72 stored in a completely different format. This files uses the some
73 of the swapping routines from coffswap.h, and some of the generic
74 COFF routines in coffgen.c, but, unlike the real COFF targets, does
75 not use coffcode.h itself. */
77 /* Prototypes for static functions. */
79 static boolean ecoff_bad_format_hook
PARAMS ((bfd
*abfd
, PTR filehdr
));
80 static asection
*ecoff_make_section_hook
PARAMS ((bfd
*abfd
, char *name
));
81 static boolean ecoff_new_section_hook
PARAMS ((bfd
*abfd
, asection
*section
));
82 static boolean ecoff_mkobject
PARAMS ((bfd
*abfd
));
83 static PTR ecoff_mkobject_hook
PARAMS ((bfd
*abfd
, PTR filehdr
, PTR aouthdr
));
84 static boolean ecoff_set_arch_mach_hook
PARAMS ((bfd
*abfd
, PTR filehdr
));
85 static long ecoff_sec_to_styp_flags
PARAMS ((CONST
char *name
,
87 static flagword ecoff_styp_to_sec_flags
PARAMS ((bfd
*abfd
, PTR hdr
));
88 static asymbol
*ecoff_make_empty_symbol
PARAMS ((bfd
*abfd
));
89 static void ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
90 asymbol
*asym
, int ext
));
91 static boolean ecoff_slurp_symbol_table
PARAMS ((bfd
*abfd
));
92 static unsigned int ecoff_get_symtab_upper_bound
PARAMS ((bfd
*abfd
));
93 static unsigned int ecoff_get_symtab
PARAMS ((bfd
*abfd
,
94 asymbol
**alocation
));
95 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, char *string
,
96 RNDXR
*rndx
, long isym
,
98 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, union aux_ext
*aux_ptr
,
99 int indx
, int bigendian
));
100 static void ecoff_print_symbol
PARAMS ((bfd
*abfd
, PTR filep
,
102 bfd_print_symbol_type how
));
103 static void ecoff_swap_reloc_in
PARAMS ((bfd
*abfd
, RELOC
*ext
,
104 struct internal_reloc
*intern
));
105 static unsigned int ecoff_swap_reloc_out
PARAMS ((bfd
*abfd
, PTR src
,
107 static bfd_reloc_status_type ecoff_generic_reloc
PARAMS ((bfd
*abfd
,
113 static bfd_reloc_status_type ecoff_refhi_reloc
PARAMS ((bfd
*abfd
,
119 static bfd_reloc_status_type ecoff_reflo_reloc
PARAMS ((bfd
*abfd
,
125 static bfd_reloc_status_type ecoff_gprel_reloc
PARAMS ((bfd
*abfd
,
131 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
133 static unsigned int ecoff_canonicalize_reloc
PARAMS ((bfd
*abfd
,
137 static CONST
struct reloc_howto_struct
*ecoff_bfd_reloc_type_lookup
138 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
139 static boolean ecoff_find_nearest_line
PARAMS ((bfd
*abfd
,
143 CONST
char **filename_ptr
,
144 CONST
char **fnname_ptr
,
145 unsigned int *retline_ptr
));
146 static void ecoff_clear_output_flags
PARAMS ((bfd
*abfd
));
147 static boolean ecoff_rel
PARAMS ((bfd
*output_bfd
, bfd_seclet_type
*seclet
,
148 asection
*output_section
, PTR data
,
149 boolean relocateable
));
150 static boolean ecoff_dump_seclet
PARAMS ((bfd
*abfd
, bfd_seclet_type
*seclet
,
151 asection
*section
, PTR data
,
152 boolean relocateable
));
153 static long ecoff_add_string
PARAMS ((bfd
*output_bfd
, FDR
*fdr
,
154 CONST
char *string
, boolean external
));
155 static boolean ecoff_get_debug
PARAMS ((bfd
*output_bfd
,
156 bfd_seclet_type
*seclet
,
158 boolean relocateable
));
159 static boolean ecoff_bfd_seclet_link
PARAMS ((bfd
*abfd
, PTR data
,
160 boolean relocateable
));
161 static boolean ecoff_set_arch_mach
PARAMS ((bfd
*abfd
,
162 enum bfd_architecture arch
,
163 unsigned long machine
));
164 static int ecoff_sizeof_headers
PARAMS ((bfd
*abfd
, boolean reloc
));
165 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
166 static boolean ecoff_set_section_contents
PARAMS ((bfd
*abfd
,
170 bfd_size_type count
));
171 static boolean ecoff_write_object_contents
PARAMS ((bfd
*abfd
));
172 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
173 unsigned int *rehash
,
176 static boolean ecoff_slurp_armap
PARAMS ((bfd
*abfd
));
177 static boolean ecoff_write_armap
PARAMS ((bfd
*abfd
, unsigned int elength
,
179 unsigned int orl_count
,
181 static bfd_target
*ecoff_archive_p
PARAMS ((bfd
*abfd
));
183 /* Get the generic COFF swapping routines, except for the reloc,
184 symbol, and lineno ones. Give them ecoff names. */
186 #define NO_COFF_RELOCS
187 #define NO_COFF_SYMBOLS
188 #define NO_COFF_LINENOS
189 #define coff_swap_filehdr_in ecoff_swap_filehdr_in
190 #define coff_swap_filehdr_out ecoff_swap_filehdr_out
191 #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in
192 #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out
193 #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in
194 #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out
195 #include "coffswap.h"
197 /* This stuff is somewhat copied from coffcode.h. */
199 static asection bfd_debug_section
= { "*DEBUG*" };
201 /* See whether the magic number matches. */
204 ecoff_bad_format_hook (abfd
, filehdr
)
208 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
210 if (ECOFFBADMAG (*internal_f
))
216 /* This is a hook needed by SCO COFF, but we have nothing to do. */
219 ecoff_make_section_hook (abfd
, name
)
223 return (asection
*) NULL
;
226 /* Initialize a new section. */
229 ecoff_new_section_hook (abfd
, section
)
233 section
->alignment_power
= abfd
->xvec
->align_power_min
;
235 if (strcmp (section
->name
, _TEXT
) == 0)
236 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
237 else if (strcmp (section
->name
, _DATA
) == 0
238 || strcmp (section
->name
, _SDATA
) == 0)
239 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
240 else if (strcmp (section
->name
, _RDATA
) == 0
241 || strcmp (section
->name
, _LIT8
) == 0
242 || strcmp (section
->name
, _LIT4
) == 0)
243 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
244 else if (strcmp (section
->name
, _BSS
) == 0
245 || strcmp (section
->name
, _SBSS
) == 0)
246 section
->flags
|= SEC_ALLOC
;
248 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
249 uncertain about .init on some systems and I don't know how shared
255 /* Set the alignment of a section; we have nothing to do. */
257 #define ecoff_set_alignment_hook \
258 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
260 /* Create an ECOFF object. */
263 ecoff_mkobject (abfd
)
266 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
267 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
268 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
270 bfd_error
= no_memory
;
274 /* Always create a .scommon section for every BFD. This is a hack so
275 that the linker has something to attach scSCommon symbols to. */
276 bfd_make_section (abfd
, SCOMMON
);
281 /* Create the ECOFF backend specific information. */
284 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
289 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
290 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
291 ecoff_data_type
*ecoff
;
293 if (ecoff_mkobject (abfd
) == false)
296 ecoff
= ecoff_data (abfd
);
298 ecoff
->sym_filepos
= internal_f
->f_symptr
;
300 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
304 ecoff
->text_start
= internal_a
->text_start
;
305 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
306 ecoff
->gp
= internal_a
->gp_value
;
307 ecoff
->gprmask
= internal_a
->gprmask
;
308 for (i
= 0; i
< 4; i
++)
309 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
315 /* Determine the machine architecture and type. */
318 ecoff_set_arch_mach_hook (abfd
, filehdr
)
322 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
323 enum bfd_architecture arch
;
325 switch (internal_f
->f_magic
)
328 case MIPS_MAGIC_LITTLE
:
330 arch
= bfd_arch_mips
;
334 arch
= bfd_arch_obscure
;
338 bfd_default_set_arch_mach (abfd
, arch
, (unsigned long) 0);
343 /* Get the section s_flags to use for a section. */
346 ecoff_sec_to_styp_flags (name
, flags
)
354 if (strcmp (name
, _TEXT
) == 0)
356 else if (strcmp (name
, _DATA
) == 0)
358 else if (strcmp (name
, _SDATA
) == 0)
360 else if (strcmp (name
, _RDATA
) == 0)
362 else if (strcmp (name
, _LIT8
) == 0)
364 else if (strcmp (name
, _LIT4
) == 0)
366 else if (strcmp (name
, _BSS
) == 0)
368 else if (strcmp (name
, _SBSS
) == 0)
370 else if (flags
& SEC_CODE
)
372 else if (flags
& SEC_DATA
)
374 else if (flags
& SEC_READONLY
)
376 else if (flags
& SEC_LOAD
)
381 if (flags
& SEC_NEVER_LOAD
)
387 /* Get the BFD flags to use for a section. */
390 ecoff_styp_to_sec_flags (abfd
, hdr
)
394 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
395 long styp_flags
= internal_s
->s_flags
;
396 flagword sec_flags
=0;
398 if (styp_flags
& STYP_NOLOAD
)
399 sec_flags
|= SEC_NEVER_LOAD
;
401 /* For 386 COFF, at least, an unloadable text or data section is
402 actually a shared library section. */
403 if (styp_flags
& STYP_TEXT
)
405 if (sec_flags
& SEC_NEVER_LOAD
)
406 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
408 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
410 else if ((styp_flags
& STYP_DATA
)
411 || (styp_flags
& STYP_RDATA
)
412 || (styp_flags
& STYP_SDATA
))
414 if (sec_flags
& SEC_NEVER_LOAD
)
415 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
417 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
418 if (styp_flags
& STYP_RDATA
)
419 sec_flags
|= SEC_READONLY
;
421 else if ((styp_flags
& STYP_BSS
)
422 || (styp_flags
& STYP_SBSS
))
424 sec_flags
|= SEC_ALLOC
;
426 else if (styp_flags
& STYP_INFO
)
428 sec_flags
|= SEC_NEVER_LOAD
;
430 else if ((styp_flags
& STYP_LIT8
)
431 || (styp_flags
& STYP_LIT4
))
433 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
437 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
443 /* Read in and swap the important symbolic information for an ECOFF
444 object file. FIXME: This is called by gdb. If there is ever
445 another ECOFF target, it should be moved into some sort of target
446 specific structure. */
449 ecoff_slurp_symbolic_info (abfd
)
452 struct hdr_ext external_symhdr
;
453 HDRR
*internal_symhdr
;
454 bfd_size_type raw_base
;
455 bfd_size_type raw_size
;
457 struct fdr_ext
*fraw_src
;
458 struct fdr_ext
*fraw_end
;
461 /* Check whether we've already gotten it, and whether there's any to
463 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
465 if (ecoff_data (abfd
)->sym_filepos
== 0)
467 bfd_get_symcount (abfd
) = 0;
471 /* At this point bfd_get_symcount (abfd) holds the number of symbols
472 as read from the file header, but on ECOFF this is always the
473 size of the symbolic information header. It would be cleaner to
474 handle this when we first read the file in coffgen.c. */
475 if (bfd_get_symcount (abfd
) != sizeof (external_symhdr
))
477 bfd_error
= bad_value
;
481 /* Read the symbolic information header. */
482 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
483 || (bfd_read ((PTR
) &external_symhdr
, sizeof (external_symhdr
), 1, abfd
)
484 != sizeof (external_symhdr
)))
486 bfd_error
= system_call_error
;
489 internal_symhdr
= &ecoff_data (abfd
)->symbolic_header
;
490 ecoff_swap_hdr_in (abfd
, &external_symhdr
, internal_symhdr
);
492 if (internal_symhdr
->magic
!= magicSym
)
494 bfd_error
= bad_value
;
498 /* Now we can get the correct number of symbols. */
499 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
500 + internal_symhdr
->iextMax
);
502 /* Read all the symbolic information at once. */
503 raw_base
= ecoff_data (abfd
)->sym_filepos
+ sizeof (struct hdr_ext
);
505 if (internal_symhdr
->cbExtOffset
!= 0)
506 raw_size
= (internal_symhdr
->cbExtOffset
508 + internal_symhdr
->iextMax
* sizeof (struct ext_ext
));
511 long cbline
, issmax
, issextmax
;
513 cbline
= (internal_symhdr
->cbLine
+ 3) &~ 3;
514 issmax
= (internal_symhdr
->issMax
+ 3) &~ 3;
515 issextmax
= (internal_symhdr
->issExtMax
+ 3) &~ 3;
516 raw_size
= (cbline
* sizeof (unsigned char)
517 + internal_symhdr
->idnMax
* sizeof (struct dnr_ext
)
518 + internal_symhdr
->ipdMax
* sizeof (struct pdr_ext
)
519 + internal_symhdr
->isymMax
* sizeof (struct sym_ext
)
520 + internal_symhdr
->ioptMax
* sizeof (struct opt_ext
)
521 + internal_symhdr
->iauxMax
* sizeof (union aux_ext
)
522 + issmax
* sizeof (char)
523 + issextmax
* sizeof (char)
524 + internal_symhdr
->ifdMax
* sizeof (struct fdr_ext
)
525 + internal_symhdr
->crfd
* sizeof (struct rfd_ext
)
526 + internal_symhdr
->iextMax
* sizeof (struct ext_ext
));
531 ecoff_data (abfd
)->sym_filepos
= 0;
534 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
537 bfd_error
= no_memory
;
540 if (bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
542 bfd_error
= system_call_error
;
543 bfd_release (abfd
, raw
);
547 ecoff_data (abfd
)->raw_size
= raw_size
;
548 ecoff_data (abfd
)->raw_syments
= raw
;
550 /* Get pointers for the numeric offsets in the HDRR structure. */
551 #define FIX(off1, off2, type) \
552 if (internal_symhdr->off1 == 0) \
553 ecoff_data (abfd)->off2 = (type *) NULL; \
555 ecoff_data (abfd)->off2 = (type *) ((char *) raw \
556 + internal_symhdr->off1 \
558 FIX (cbLineOffset
, line
, unsigned char);
559 FIX (cbDnOffset
, external_dnr
, struct dnr_ext
);
560 FIX (cbPdOffset
, external_pdr
, struct pdr_ext
);
561 FIX (cbSymOffset
, external_sym
, struct sym_ext
);
562 FIX (cbOptOffset
, external_opt
, struct opt_ext
);
563 FIX (cbAuxOffset
, external_aux
, union aux_ext
);
564 FIX (cbSsOffset
, ss
, char);
565 FIX (cbSsExtOffset
, ssext
, char);
566 FIX (cbFdOffset
, external_fdr
, struct fdr_ext
);
567 FIX (cbRfdOffset
, external_rfd
, struct rfd_ext
);
568 FIX (cbExtOffset
, external_ext
, struct ext_ext
);
571 /* I don't want to always swap all the data, because it will just
572 waste time and most programs will never look at it. The only
573 time the linker needs most of the debugging information swapped
574 is when linking big-endian and little-endian MIPS object files
575 together, which is not a common occurrence.
577 We need to look at the fdr to deal with a lot of information in
578 the symbols, so we swap them here. */
579 ecoff_data (abfd
)->fdr
= (struct fdr
*) bfd_alloc (abfd
,
580 (internal_symhdr
->ifdMax
*
581 sizeof (struct fdr
)));
582 if (ecoff_data (abfd
)->fdr
== NULL
)
584 bfd_error
= no_memory
;
587 fdr_ptr
= ecoff_data (abfd
)->fdr
;
588 fraw_src
= ecoff_data (abfd
)->external_fdr
;
589 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
;
590 for (; fraw_src
< fraw_end
; fraw_src
++, fdr_ptr
++)
591 ecoff_swap_fdr_in (abfd
, fraw_src
, fdr_ptr
);
596 /* ECOFF symbol table routines. The ECOFF symbol table is described
597 in gcc/mips-tfile.c. */
599 /* ECOFF uses two common sections. One is the usual one, and the
600 other is for small objects. All the small objects are kept
601 together, and then referenced via the gp pointer, which yields
602 faster assembler code. This is what we use for the small common
604 static asection ecoff_scom_section
;
605 static asymbol ecoff_scom_symbol
;
606 static asymbol
*ecoff_scom_symbol_ptr
;
608 /* Create an empty symbol. */
611 ecoff_make_empty_symbol (abfd
)
614 ecoff_symbol_type
*new;
616 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
617 if (new == (ecoff_symbol_type
*) NULL
)
619 bfd_error
= no_memory
;
620 return (asymbol
*) NULL
;
622 memset (new, 0, sizeof *new);
623 new->symbol
.section
= (asection
*) NULL
;
624 new->fdr
= (FDR
*) NULL
;
626 new->native
.lnative
= (struct sym_ext
*) NULL
;
627 new->symbol
.the_bfd
= abfd
;
631 /* Set the BFD flags and section for an ECOFF symbol. */
634 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
)
640 asym
->the_bfd
= abfd
;
641 asym
->value
= ecoff_sym
->value
;
642 asym
->section
= &bfd_debug_section
;
645 /* Most symbol types are just for debugging. */
646 switch (ecoff_sym
->st
)
655 if (MIPS_IS_STAB (ecoff_sym
))
657 asym
->flags
= BSF_DEBUGGING
;
662 asym
->flags
= BSF_DEBUGGING
;
667 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
669 asym
->flags
= BSF_LOCAL
;
670 switch (ecoff_sym
->sc
)
673 /* Used for compiler generated labels. Leave them in the
674 debugging section, and mark them as local. If BSF_DEBUGGING
675 is set, then nm does not display them for some reason. If no
676 flags are set then the linker whines about them. */
677 asym
->flags
= BSF_LOCAL
;
680 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
681 asym
->value
-= asym
->section
->vma
;
684 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
685 asym
->value
-= asym
->section
->vma
;
690 asym
->section
= &bfd_com_section
;
695 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
696 asym
->value
-= asym
->section
->vma
;
700 asym
->flags
= BSF_DEBUGGING
;
703 asym
->section
= &bfd_abs_section
;
706 asym
->section
= &bfd_und_section
;
716 asym
->flags
= BSF_DEBUGGING
;
719 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
720 asym
->value
-= asym
->section
->vma
;
723 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
725 asym
->value
-= asym
->section
->vma
;
728 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
729 asym
->value
-= asym
->section
->vma
;
732 asym
->flags
= BSF_DEBUGGING
;
735 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
737 asym
->section
= &bfd_com_section
;
743 if (ecoff_scom_section
.name
== NULL
)
745 /* Initialize the small common section. */
746 ecoff_scom_section
.name
= SCOMMON
;
747 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
748 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
749 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
750 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
751 ecoff_scom_symbol
.name
= SCOMMON
;
752 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
753 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
754 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
756 asym
->section
= &ecoff_scom_section
;
761 asym
->flags
= BSF_DEBUGGING
;
764 asym
->section
= &bfd_und_section
;
769 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
770 asym
->value
-= asym
->section
->vma
;
775 asym
->flags
= BSF_DEBUGGING
;
778 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
779 asym
->value
-= asym
->section
->vma
;
786 /* Read an ECOFF symbol table. */
789 ecoff_slurp_symbol_table (abfd
)
792 bfd_size_type internal_size
;
793 ecoff_symbol_type
*internal
;
794 ecoff_symbol_type
*internal_ptr
;
795 struct ext_ext
*eraw_src
;
796 struct ext_ext
*eraw_end
;
800 /* If we've already read in the symbol table, do nothing. */
801 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
804 /* Get the symbolic information. */
805 if (ecoff_slurp_symbolic_info (abfd
) == false)
807 if (bfd_get_symcount (abfd
) == 0)
810 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
811 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
812 if (internal
== NULL
)
814 bfd_error
= no_memory
;
818 internal_ptr
= internal
;
819 eraw_src
= ecoff_data (abfd
)->external_ext
;
820 eraw_end
= eraw_src
+ ecoff_data (abfd
)->symbolic_header
.iextMax
;
821 for (; eraw_src
< eraw_end
; eraw_src
++, internal_ptr
++)
825 ecoff_swap_ext_in (abfd
, eraw_src
, &internal_esym
);
826 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ssext
827 + internal_esym
.asym
.iss
);
828 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
829 &internal_ptr
->symbol
, 1);
830 internal_ptr
->fdr
= ecoff_data (abfd
)->fdr
+ internal_esym
.ifd
;
831 internal_ptr
->local
= false;
832 internal_ptr
->native
.enative
= eraw_src
;
835 /* The local symbols must be accessed via the fdr's, because the
836 string and aux indices are relative to the fdr information. */
837 fdr_ptr
= ecoff_data (abfd
)->fdr
;
838 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
839 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
841 struct sym_ext
*lraw_src
;
842 struct sym_ext
*lraw_end
;
844 lraw_src
= ecoff_data (abfd
)->external_sym
+ fdr_ptr
->isymBase
;
845 lraw_end
= lraw_src
+ fdr_ptr
->csym
;
846 for (; lraw_src
< lraw_end
; lraw_src
++, internal_ptr
++)
850 ecoff_swap_sym_in (abfd
, lraw_src
, &internal_sym
);
851 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ss
854 ecoff_set_symbol_info (abfd
, &internal_sym
,
855 &internal_ptr
->symbol
, 0);
856 internal_ptr
->fdr
= fdr_ptr
;
857 internal_ptr
->local
= true;
858 internal_ptr
->native
.lnative
= lraw_src
;
862 ecoff_data (abfd
)->canonical_symbols
= internal
;
868 ecoff_get_symtab_upper_bound (abfd
)
871 if (ecoff_slurp_symbolic_info (abfd
) == false
872 || bfd_get_symcount (abfd
) == 0)
875 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
879 ecoff_get_symtab (abfd
, alocation
)
883 unsigned int counter
= 0;
884 ecoff_symbol_type
*symbase
;
885 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
887 if (ecoff_slurp_symbol_table (abfd
) == false
888 || bfd_get_symcount (abfd
) == 0)
891 symbase
= ecoff_data (abfd
)->canonical_symbols
;
892 while (counter
< bfd_get_symcount (abfd
))
894 *(location
++) = symbase
++;
897 *location
++ = (ecoff_symbol_type
*) NULL
;
898 return bfd_get_symcount (abfd
);
901 /* Turn ECOFF type information into a printable string.
902 ecoff_emit_aggregate and ecoff_type_to_string are from
903 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
905 /* Write aggregate information to a string. */
908 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
916 int indx
= rndx
->index
;
917 int sym_base
, ss_base
;
923 sym_base
= ecoff_data (abfd
)->fdr
[ifd
].isymBase
;
924 ss_base
= ecoff_data (abfd
)->fdr
[ifd
].issBase
;
926 if (indx
== indexNil
)
927 name
= "/* no name */";
933 ecoff_swap_sym_in (abfd
,
934 ecoff_data (abfd
)->external_sym
+ indx
,
936 name
= ecoff_data (abfd
)->ss
+ ss_base
+ sym
.iss
;
940 "%s %s { ifd = %d, index = %d }",
942 indx
+ ecoff_data (abfd
)->symbolic_header
.iextMax
);
945 /* Convert the type information to string format. */
948 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
950 union aux_ext
*aux_ptr
;
962 unsigned int basic_type
;
964 static char buffer1
[1024];
965 static char buffer2
[1024];
970 for (i
= 0; i
< 7; i
++)
972 qualifiers
[i
].low_bound
= 0;
973 qualifiers
[i
].high_bound
= 0;
974 qualifiers
[i
].stride
= 0;
977 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
978 return "-1 (no type)";
979 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
981 basic_type
= u
.ti
.bt
;
982 qualifiers
[0].type
= u
.ti
.tq0
;
983 qualifiers
[1].type
= u
.ti
.tq1
;
984 qualifiers
[2].type
= u
.ti
.tq2
;
985 qualifiers
[3].type
= u
.ti
.tq3
;
986 qualifiers
[4].type
= u
.ti
.tq4
;
987 qualifiers
[5].type
= u
.ti
.tq5
;
988 qualifiers
[6].type
= tqNil
;
991 * Go get the basic type.
995 case btNil
: /* undefined */
999 case btAdr
: /* address - integer same size as pointer */
1000 strcpy (p1
, "address");
1003 case btChar
: /* character */
1004 strcpy (p1
, "char");
1007 case btUChar
: /* unsigned character */
1008 strcpy (p1
, "unsigned char");
1011 case btShort
: /* short */
1012 strcpy (p1
, "short");
1015 case btUShort
: /* unsigned short */
1016 strcpy (p1
, "unsigned short");
1019 case btInt
: /* int */
1023 case btUInt
: /* unsigned int */
1024 strcpy (p1
, "unsigned int");
1027 case btLong
: /* long */
1028 strcpy (p1
, "long");
1031 case btULong
: /* unsigned long */
1032 strcpy (p1
, "unsigned long");
1035 case btFloat
: /* float (real) */
1036 strcpy (p1
, "float");
1039 case btDouble
: /* Double (real) */
1040 strcpy (p1
, "double");
1043 /* Structures add 1-2 aux words:
1044 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1045 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1047 case btStruct
: /* Structure (Record) */
1048 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1049 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1050 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1052 indx
++; /* skip aux words */
1055 /* Unions add 1-2 aux words:
1056 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1057 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1059 case btUnion
: /* Union */
1060 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1061 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1062 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1064 indx
++; /* skip aux words */
1067 /* Enumerations add 1-2 aux words:
1068 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1069 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1071 case btEnum
: /* Enumeration */
1072 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1073 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1074 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1076 indx
++; /* skip aux words */
1079 case btTypedef
: /* defined via a typedef, isymRef points */
1080 strcpy (p1
, "typedef");
1083 case btRange
: /* subrange of int */
1084 strcpy (p1
, "subrange");
1087 case btSet
: /* pascal sets */
1091 case btComplex
: /* fortran complex */
1092 strcpy (p1
, "complex");
1095 case btDComplex
: /* fortran double complex */
1096 strcpy (p1
, "double complex");
1099 case btIndirect
: /* forward or unnamed typedef */
1100 strcpy (p1
, "forward/unamed typedef");
1103 case btFixedDec
: /* Fixed Decimal */
1104 strcpy (p1
, "fixed decimal");
1107 case btFloatDec
: /* Float Decimal */
1108 strcpy (p1
, "float decimal");
1111 case btString
: /* Varying Length Character String */
1112 strcpy (p1
, "string");
1115 case btBit
: /* Aligned Bit String */
1119 case btPicture
: /* Picture */
1120 strcpy (p1
, "picture");
1123 case btVoid
: /* Void */
1124 strcpy (p1
, "void");
1128 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1132 p1
+= strlen (buffer1
);
1135 * If this is a bitfield, get the bitsize.
1141 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1142 sprintf (p1
, " : %d", bitsize
);
1143 p1
+= strlen (buffer1
);
1148 * Deal with any qualifiers.
1150 if (qualifiers
[0].type
!= tqNil
)
1153 * Snarf up any array bounds in the correct order. Arrays
1154 * store 5 successive words in the aux. table:
1155 * word 0 RNDXR to type of the bounds (ie, int)
1156 * word 1 Current file descriptor index
1158 * word 3 high bound (or -1 if [])
1159 * word 4 stride size in bits
1161 for (i
= 0; i
< 7; i
++)
1163 if (qualifiers
[i
].type
== tqArray
)
1165 qualifiers
[i
].low_bound
=
1166 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1167 qualifiers
[i
].high_bound
=
1168 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1169 qualifiers
[i
].stride
=
1170 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1176 * Now print out the qualifiers.
1178 for (i
= 0; i
< 6; i
++)
1180 switch (qualifiers
[i
].type
)
1187 strcpy (p2
, "ptr to ");
1188 p2
+= sizeof ("ptr to ")-1;
1192 strcpy (p2
, "volatile ");
1193 p2
+= sizeof ("volatile ")-1;
1197 strcpy (p2
, "far ");
1198 p2
+= sizeof ("far ")-1;
1202 strcpy (p2
, "func. ret. ");
1203 p2
+= sizeof ("func. ret. ");
1208 int first_array
= i
;
1211 /* Print array bounds reversed (ie, in the order the C
1212 programmer writes them). C is such a fun language.... */
1214 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1217 for (j
= i
; j
>= first_array
; j
--)
1219 strcpy (p2
, "array [");
1220 p2
+= sizeof ("array [")-1;
1221 if (qualifiers
[j
].low_bound
!= 0)
1223 "%ld:%ld {%ld bits}",
1224 (long) qualifiers
[j
].low_bound
,
1225 (long) qualifiers
[j
].high_bound
,
1226 (long) qualifiers
[j
].stride
);
1228 else if (qualifiers
[j
].high_bound
!= -1)
1231 (long) (qualifiers
[j
].high_bound
+ 1),
1232 (long) (qualifiers
[j
].stride
));
1235 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1238 strcpy (p2
, "] of ");
1239 p2
+= sizeof ("] of ")-1;
1247 strcpy (p2
, buffer1
);
1251 /* Print information about an ECOFF symbol. */
1254 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1258 bfd_print_symbol_type how
;
1260 FILE *file
= (FILE *)filep
;
1264 case bfd_print_symbol_name
:
1265 fprintf (file
, "%s", symbol
->name
);
1267 case bfd_print_symbol_more
:
1268 if (ecoffsymbol (symbol
)->local
)
1272 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1274 fprintf (file
, "ecoff local %lx %x %x",
1275 (unsigned long) ecoff_sym
.value
,
1276 (unsigned) ecoff_sym
.st
, (unsigned) ecoff_sym
.sc
);
1282 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1284 fprintf (file
, "ecoff extern %lx %x %x",
1285 (unsigned long) ecoff_ext
.asym
.value
,
1286 (unsigned) ecoff_ext
.asym
.st
,
1287 (unsigned) ecoff_ext
.asym
.sc
);
1290 case bfd_print_symbol_nm
:
1292 CONST
char *section_name
= symbol
->section
->name
;
1294 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
1295 fprintf (file
, " %-5s %s %s",
1297 ecoffsymbol (symbol
)->local
? "l" : "e",
1301 case bfd_print_symbol_all
:
1302 /* Print out the symbols in a reasonable way */
1311 if (ecoffsymbol (symbol
)->local
)
1313 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1316 pos
= (ecoffsymbol (symbol
)->native
.lnative
1317 - ecoff_data (abfd
)->external_sym
1318 + ecoff_data (abfd
)->symbolic_header
.iextMax
);
1325 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1328 pos
= (ecoffsymbol (symbol
)->native
.enative
1329 - ecoff_data (abfd
)->external_ext
);
1330 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1331 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1332 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1335 fprintf (file
, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s",
1336 pos
, type
, (unsigned long) ecoff_ext
.asym
.value
,
1337 (unsigned) ecoff_ext
.asym
.st
,
1338 (unsigned) ecoff_ext
.asym
.sc
,
1339 (unsigned) ecoff_ext
.asym
.index
,
1340 jmptbl
, cobol_main
, weakext
,
1343 if (ecoffsymbol (symbol
)->fdr
!= NULL
1344 && ecoff_ext
.asym
.index
!= indexNil
)
1349 union aux_ext
*aux_base
;
1351 indx
= ecoff_ext
.asym
.index
;
1353 /* sym_base is used to map the fdr relative indices which
1354 appear in the file to the position number which we are
1356 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1357 if (ecoffsymbol (symbol
)->local
)
1358 sym_base
+= ecoff_data (abfd
)->symbolic_header
.iextMax
;
1360 /* aux_base is the start of the aux entries for this file;
1361 asym.index is an offset from this. */
1362 aux_base
= (ecoff_data (abfd
)->external_aux
1363 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1365 /* The aux entries are stored in host byte order; the
1366 order is indicated by a bit in the fdr. */
1367 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1369 /* This switch is basically from gcc/mips-tdump.c */
1370 switch (ecoff_ext
.asym
.st
)
1378 printf ("\n End+1 symbol: %ld", indx
+ sym_base
);
1382 if (ecoff_ext
.asym
.sc
== scText
1383 || ecoff_ext
.asym
.sc
== scInfo
)
1384 printf ("\n First symbol: %ld", indx
+ sym_base
);
1386 printf ("\n First symbol: %ld",
1387 (AUX_GET_ISYM (bigendian
,
1388 &aux_base
[ecoff_ext
.asym
.index
])
1394 if (MIPS_IS_STAB (&ecoff_ext
.asym
))
1396 else if (ecoffsymbol (symbol
)->local
)
1397 printf ("\n End+1 symbol: %-7ld Type: %s",
1398 (AUX_GET_ISYM (bigendian
,
1399 &aux_base
[ecoff_ext
.asym
.index
])
1401 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1404 printf ("\n Local symbol: %d",
1407 + ecoff_data (abfd
)->symbolic_header
.iextMax
));
1411 if (!MIPS_IS_STAB (&ecoff_ext
.asym
))
1412 printf ("\n Type: %s",
1413 ecoff_type_to_string (abfd
, aux_base
, indx
,
1423 /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in
1424 external form. They use a bit which indicates whether the symbol
1427 /* Swap a reloc in. */
1430 ecoff_swap_reloc_in (abfd
, ext
, intern
)
1433 struct internal_reloc
*intern
;
1435 intern
->r_vaddr
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->r_vaddr
);
1436 if (abfd
->xvec
->header_byteorder_big_p
!= false)
1438 intern
->r_symndx
= (((int) ext
->r_bits
[0]
1439 << RELOC_BITS0_SYMNDX_SH_LEFT_BIG
)
1440 | ((int) ext
->r_bits
[1]
1441 << RELOC_BITS1_SYMNDX_SH_LEFT_BIG
)
1442 | ((int) ext
->r_bits
[2]
1443 << RELOC_BITS2_SYMNDX_SH_LEFT_BIG
));
1444 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_BIG
)
1445 >> RELOC_BITS3_TYPE_SH_BIG
);
1446 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_BIG
) != 0;
1450 intern
->r_symndx
= (((int) ext
->r_bits
[0]
1451 << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
)
1452 | ((int) ext
->r_bits
[1]
1453 << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
)
1454 | ((int) ext
->r_bits
[2]
1455 << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
));
1456 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_LITTLE
)
1457 >> RELOC_BITS3_TYPE_SH_LITTLE
);
1458 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_LITTLE
) != 0;
1462 /* Swap a reloc out. */
1465 ecoff_swap_reloc_out (abfd
, src
, dst
)
1470 struct internal_reloc
*intern
= (struct internal_reloc
*) src
;
1471 RELOC
*ext
= (RELOC
*) dst
;
1473 bfd_h_put_32 (abfd
, intern
->r_vaddr
, (bfd_byte
*) ext
->r_vaddr
);
1474 if (abfd
->xvec
->header_byteorder_big_p
!= false)
1476 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_BIG
;
1477 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_BIG
;
1478 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_BIG
;
1479 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_BIG
)
1480 & RELOC_BITS3_TYPE_BIG
)
1481 | (intern
->r_extern
? RELOC_BITS3_EXTERN_BIG
: 0));
1485 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
;
1486 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
;
1487 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
;
1488 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_LITTLE
)
1489 & RELOC_BITS3_TYPE_LITTLE
)
1490 | (intern
->r_extern
? RELOC_BITS3_EXTERN_LITTLE
: 0));
1496 /* ECOFF relocs are either against external symbols, or against
1497 sections. If we are producing relocateable output, and the reloc
1498 is against an external symbol, and nothing has given us any
1499 additional addend, the resulting reloc will also be against the
1500 same symbol. In such a case, we don't want to change anything
1501 about the way the reloc is handled, since it will all be done at
1502 final link time. Rather than put special case code into
1503 bfd_perform_relocation, all the reloc types use this howto
1504 function. It just short circuits the reloc if producing
1505 relocateable output against an external symbol. */
1507 static bfd_reloc_status_type
1508 ecoff_generic_reloc (abfd
,
1515 arelent
*reloc_entry
;
1518 asection
*input_section
;
1521 if (output_bfd
!= (bfd
*) NULL
1522 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1523 && reloc_entry
->addend
== 0)
1525 reloc_entry
->address
+= input_section
->output_offset
;
1526 return bfd_reloc_ok
;
1529 return bfd_reloc_continue
;
1532 /* Do a REFHI relocation. This has to be done in combination with a
1533 REFLO reloc, because there is a carry from the REFLO to the REFHI.
1534 Here we just save the information we need; we do the actual
1535 relocation when we see the REFLO. ECOFF requires that the REFLO
1536 immediately follow the REFHI, so this ought to work. */
1538 static bfd_byte
*ecoff_refhi_addr
;
1539 static bfd_vma ecoff_refhi_addend
;
1541 static bfd_reloc_status_type
1542 ecoff_refhi_reloc (abfd
,
1549 arelent
*reloc_entry
;
1552 asection
*input_section
;
1555 bfd_reloc_status_type ret
;
1558 /* If we're relocating, and this an external symbol, we don't want
1559 to change anything. */
1560 if (output_bfd
!= (bfd
*) NULL
1561 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1562 && reloc_entry
->addend
== 0)
1564 reloc_entry
->address
+= input_section
->output_offset
;
1565 return bfd_reloc_ok
;
1569 if (symbol
->section
== &bfd_und_section
1570 && output_bfd
== (bfd
*) NULL
)
1571 ret
= bfd_reloc_undefined
;
1573 if (bfd_is_com_section (symbol
->section
))
1576 relocation
= symbol
->value
;
1578 relocation
+= symbol
->section
->output_section
->vma
;
1579 relocation
+= symbol
->section
->output_offset
;
1580 relocation
+= reloc_entry
->addend
;
1582 if (reloc_entry
->address
> input_section
->_cooked_size
)
1583 return bfd_reloc_outofrange
;
1585 /* Save the information, and let REFLO do the actual relocation. */
1586 ecoff_refhi_addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1587 ecoff_refhi_addend
= relocation
;
1589 if (output_bfd
!= (bfd
*) NULL
)
1590 reloc_entry
->address
+= input_section
->output_offset
;
1595 /* Do a REFLO relocation. This is a straightforward 16 bit inplace
1596 relocation; this function exists in order to do the REFHI
1597 relocation described above. */
1599 static bfd_reloc_status_type
1600 ecoff_reflo_reloc (abfd
,
1607 arelent
*reloc_entry
;
1610 asection
*input_section
;
1613 if (ecoff_refhi_addr
!= (bfd_byte
*) NULL
)
1617 unsigned long vallo
;
1619 /* Do the REFHI relocation. Note that we actually don't need to
1620 know anything about the REFLO itself, except where to find
1621 the low 16 bits of the addend needed by the REFHI. */
1622 insn
= bfd_get_32 (abfd
, ecoff_refhi_addr
);
1623 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1625 val
= ((insn
& 0xffff) << 16) + vallo
;
1626 val
+= ecoff_refhi_addend
;
1628 /* The low order 16 bits are always treated as a signed value.
1629 Therefore, a negative value in the low order bits requires an
1630 adjustment in the high order bits. We need to make this
1631 adjustment in two ways: once for the bits we took from the
1632 data, and once for the bits we are putting back in to the
1634 if ((vallo
& 0x8000) != 0)
1636 if ((val
& 0x8000) != 0)
1639 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1640 bfd_put_32 (abfd
, insn
, ecoff_refhi_addr
);
1642 ecoff_refhi_addr
= (bfd_byte
*) NULL
;
1645 /* Now do the REFLO reloc in the usual way. */
1646 return ecoff_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1647 input_section
, output_bfd
);
1650 /* Do a GPREL relocation. This is a 16 bit value which must become
1651 the offset from the gp register. */
1653 static bfd_reloc_status_type
1654 ecoff_gprel_reloc (abfd
,
1661 arelent
*reloc_entry
;
1664 asection
*input_section
;
1667 boolean relocateable
;
1672 /* If we're relocating, and this is an external symbol with no
1673 addend, we don't want to change anything. We will only have an
1674 addend if this is a newly created reloc, not read from an ECOFF
1676 if (output_bfd
!= (bfd
*) NULL
1677 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1678 && reloc_entry
->addend
== 0)
1680 reloc_entry
->address
+= input_section
->output_offset
;
1681 return bfd_reloc_ok
;
1684 if (output_bfd
!= (bfd
*) NULL
)
1685 relocateable
= true;
1688 relocateable
= false;
1689 output_bfd
= symbol
->section
->output_section
->owner
;
1692 if (symbol
->section
== &bfd_und_section
1693 && relocateable
== false)
1694 return bfd_reloc_undefined
;
1696 /* We have to figure out the gp value, so that we can adjust the
1697 symbol value correctly. We look up the symbol _gp in the output
1698 BFD. If we can't find it, we're stuck. We cache it in the ECOFF
1699 target data. We don't need to adjust the symbol value for an
1700 external symbol if we are producing relocateable output. */
1701 if (ecoff_data (output_bfd
)->gp
== 0
1702 && (relocateable
== false
1703 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1705 if (relocateable
!= false)
1707 /* Make up a value. */
1708 ecoff_data (output_bfd
)->gp
=
1709 symbol
->section
->output_section
->vma
+ 0x4000;
1717 count
= bfd_get_symcount (output_bfd
);
1718 sym
= bfd_get_outsymbols (output_bfd
);
1720 /* We should do something more friendly here, but we don't
1721 have a good reloc status to return. */
1722 if (sym
== (asymbol
**) NULL
)
1725 for (i
= 0; i
< count
; i
++, sym
++)
1727 register CONST
char *name
;
1729 name
= bfd_asymbol_name (*sym
);
1730 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1732 ecoff_data (output_bfd
)->gp
= bfd_asymbol_value (*sym
);
1737 /* We should do something more friendly here, but we don't have
1738 a good reloc status to return. */
1744 if (bfd_is_com_section (symbol
->section
))
1747 relocation
= symbol
->value
;
1749 relocation
+= symbol
->section
->output_section
->vma
;
1750 relocation
+= symbol
->section
->output_offset
;
1752 if (reloc_entry
->address
> input_section
->_cooked_size
)
1753 return bfd_reloc_outofrange
;
1755 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1757 /* Set val to the offset into the section or symbol. */
1758 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1762 /* Adjust val for the final section location and GP value. If we
1763 are producing relocateable output, we don't want to do this for
1764 an external symbol. */
1765 if (relocateable
== false
1766 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1767 val
+= relocation
- ecoff_data (output_bfd
)->gp
;
1769 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1770 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1772 if (relocateable
!= false)
1773 reloc_entry
->address
+= input_section
->output_offset
;
1775 /* Make sure it fit in 16 bits. */
1776 if (val
>= 0x8000 && val
< 0xffff8000)
1777 return bfd_reloc_outofrange
;
1779 return bfd_reloc_ok
;
1782 /* How to process the various relocs types. */
1784 static reloc_howto_type ecoff_howto_table
[] =
1786 /* Reloc type 0 is ignored. The reloc reading code ensures that
1787 this is a reference to the .abs section, which will cause
1788 bfd_perform_relocation to do nothing. */
1789 HOWTO (ECOFF_R_IGNORE
, /* type */
1791 0, /* size (0 = byte, 1 = short, 2 = long) */
1792 8, /* bitsize (obsolete) */
1793 false, /* pc_relative */
1795 false, /* absolute (obsolete) */
1796 false, /* complain_on_overflow */
1797 0, /* special_function */
1798 "IGNORE", /* name */
1799 false, /* partial_inplace */
1802 false), /* pcrel_offset */
1804 /* A 16 bit reference to a symbol, normally from a data section. */
1805 HOWTO (ECOFF_R_REFHALF
, /* type */
1807 1, /* size (0 = byte, 1 = short, 2 = long) */
1808 16, /* bitsize (obsolete) */
1809 false, /* pc_relative */
1811 false, /* absolute (obsolete) */
1812 true, /* complain_on_overflow */
1813 ecoff_generic_reloc
, /* special_function */
1814 "REFHALF", /* name */
1815 true, /* partial_inplace */
1816 0xffff, /* src_mask */
1817 0xffff, /* dst_mask */
1818 false), /* pcrel_offset */
1820 /* A 32 bit reference to a symbol, normally from a data section. */
1821 HOWTO (ECOFF_R_REFWORD
, /* type */
1823 2, /* size (0 = byte, 1 = short, 2 = long) */
1824 32, /* bitsize (obsolete) */
1825 false, /* pc_relative */
1827 false, /* absolute (obsolete) */
1828 true, /* complain_on_overflow */
1829 ecoff_generic_reloc
, /* special_function */
1830 "REFWORD", /* name */
1831 true, /* partial_inplace */
1832 0xffffffff, /* src_mask */
1833 0xffffffff, /* dst_mask */
1834 false), /* pcrel_offset */
1836 /* A 26 bit absolute jump address. */
1837 HOWTO (ECOFF_R_JMPADDR
, /* type */
1839 2, /* size (0 = byte, 1 = short, 2 = long) */
1840 32, /* bitsize (obsolete) */
1841 false, /* pc_relative */
1843 false, /* absolute (obsolete) */
1844 true, /* complain_on_overflow */
1845 ecoff_generic_reloc
, /* special_function */
1846 "JMPADDR", /* name */
1847 true, /* partial_inplace */
1848 0x3ffffff, /* src_mask */
1849 0x3ffffff, /* dst_mask */
1850 false), /* pcrel_offset */
1852 /* The high 16 bits of a symbol value. Handled by the function
1853 ecoff_refhi_reloc. */
1854 HOWTO (ECOFF_R_REFHI
, /* type */
1855 16, /* rightshift */
1856 2, /* size (0 = byte, 1 = short, 2 = long) */
1857 32, /* bitsize (obsolete) */
1858 false, /* pc_relative */
1860 false, /* absolute (obsolete) */
1861 true, /* complain_on_overflow */
1862 ecoff_refhi_reloc
, /* special_function */
1864 true, /* partial_inplace */
1865 0xffff, /* src_mask */
1866 0xffff, /* dst_mask */
1867 false), /* pcrel_offset */
1869 /* The low 16 bits of a symbol value. */
1870 HOWTO (ECOFF_R_REFLO
, /* type */
1872 2, /* size (0 = byte, 1 = short, 2 = long) */
1873 32, /* bitsize (obsolete) */
1874 false, /* pc_relative */
1876 false, /* absolute (obsolete) */
1877 true, /* complain_on_overflow */
1878 ecoff_reflo_reloc
, /* special_function */
1880 true, /* partial_inplace */
1881 0xffff, /* src_mask */
1882 0xffff, /* dst_mask */
1883 false), /* pcrel_offset */
1885 /* A reference to an offset from the gp register. Handled by the
1886 function ecoff_gprel_reloc. */
1887 HOWTO (ECOFF_R_GPREL
, /* type */
1889 2, /* size (0 = byte, 1 = short, 2 = long) */
1890 32, /* bitsize (obsolete) */
1891 false, /* pc_relative */
1893 false, /* absolute (obsolete) */
1894 true, /* complain_on_overflow */
1895 ecoff_gprel_reloc
, /* special_function */
1897 true, /* partial_inplace */
1898 0xffff, /* src_mask */
1899 0xffff, /* dst_mask */
1900 false), /* pcrel_offset */
1902 /* A reference to a literal using an offset from the gp register.
1903 Handled by the function ecoff_gprel_reloc. */
1904 HOWTO (ECOFF_R_LITERAL
, /* type */
1906 2, /* size (0 = byte, 1 = short, 2 = long) */
1907 32, /* bitsize (obsolete) */
1908 false, /* pc_relative */
1910 false, /* absolute (obsolete) */
1911 true, /* complain_on_overflow */
1912 ecoff_gprel_reloc
, /* special_function */
1913 "LITERAL", /* name */
1914 true, /* partial_inplace */
1915 0xffff, /* src_mask */
1916 0xffff, /* dst_mask */
1917 false) /* pcrel_offset */
1920 #define ECOFF_HOWTO_COUNT \
1921 (sizeof ecoff_howto_table / sizeof ecoff_howto_table[0])
1923 /* Read in the relocs for a section. */
1926 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1931 RELOC
*external_relocs
;
1932 arelent
*internal_relocs
;
1936 if (section
->relocation
!= (arelent
*) NULL
1937 || section
->reloc_count
== 0
1938 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1941 if (ecoff_slurp_symbol_table (abfd
) == false)
1944 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1946 * section
->reloc_count
));
1947 external_relocs
= (RELOC
*) bfd_alloc (abfd
, RELSZ
* section
->reloc_count
);
1948 if (internal_relocs
== (arelent
*) NULL
1949 || external_relocs
== (RELOC
*) NULL
)
1951 bfd_error
= no_memory
;
1954 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1956 if (bfd_read (external_relocs
, 1, RELSZ
* section
->reloc_count
, abfd
)
1957 != RELSZ
* section
->reloc_count
)
1959 bfd_error
= system_call_error
;
1963 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1965 struct internal_reloc intern
;
1967 ecoff_swap_reloc_in (abfd
, external_relocs
+ i
, &intern
);
1969 if (intern
.r_type
> ECOFF_R_LITERAL
)
1972 if (intern
.r_extern
)
1974 /* r_symndx is an index into the external symbols. */
1975 BFD_ASSERT (intern
.r_symndx
>= 0
1977 < ecoff_data (abfd
)->symbolic_header
.iextMax
));
1978 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1983 CONST
char *sec_name
;
1986 /* r_symndx is a section key. */
1987 switch (intern
.r_symndx
)
1989 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1990 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1991 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1992 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1993 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1994 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1995 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1996 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1997 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
2001 sec
= bfd_get_section_by_name (abfd
, sec_name
);
2002 if (sec
== (asection
*) NULL
)
2004 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
2006 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
2007 if (intern
.r_type
== ECOFF_R_GPREL
2008 || intern
.r_type
== ECOFF_R_LITERAL
)
2009 rptr
->addend
+= ecoff_data (abfd
)->gp
;
2012 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
2013 rptr
->howto
= &ecoff_howto_table
[intern
.r_type
];
2015 /* If the type is ECOFF_R_IGNORE, make sure this is a reference
2016 to the absolute section so that the reloc is ignored. */
2017 if (intern
.r_type
== ECOFF_R_IGNORE
)
2018 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
2021 bfd_release (abfd
, external_relocs
);
2023 section
->relocation
= internal_relocs
;
2028 /* Get a canonical list of relocs. */
2031 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
2039 if (section
->flags
& SEC_CONSTRUCTOR
)
2041 arelent_chain
*chain
;
2043 /* This section has relocs made up by us, not the file, so take
2044 them out of their chain and place them into the data area
2046 for (count
= 0, chain
= section
->constructor_chain
;
2047 count
< section
->reloc_count
;
2048 count
++, chain
= chain
->next
)
2049 *relptr
++ = &chain
->relent
;
2055 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
2058 tblptr
= section
->relocation
;
2059 if (tblptr
== (arelent
*) NULL
)
2062 for (count
= 0; count
< section
->reloc_count
; count
++)
2063 *relptr
++ = tblptr
++;
2066 *relptr
= (arelent
*) NULL
;
2068 return section
->reloc_count
;
2071 /* Get the howto structure for a generic reloc type. */
2073 static CONST
struct reloc_howto_struct
*
2074 ecoff_bfd_reloc_type_lookup (abfd
, code
)
2076 bfd_reloc_code_real_type code
;
2083 ecoff_type
= ECOFF_R_REFHALF
;
2086 ecoff_type
= ECOFF_R_REFWORD
;
2088 case BFD_RELOC_MIPS_JMP
:
2089 ecoff_type
= ECOFF_R_JMPADDR
;
2091 case BFD_RELOC_HI16_S
:
2092 ecoff_type
= ECOFF_R_REFHI
;
2094 case BFD_RELOC_LO16
:
2095 ecoff_type
= ECOFF_R_REFLO
;
2097 case BFD_RELOC_MIPS_GPREL
:
2098 ecoff_type
= ECOFF_R_GPREL
;
2101 return (CONST
struct reloc_howto_struct
*) NULL
;
2104 return &ecoff_howto_table
[ecoff_type
];
2107 /* Provided a BFD, a section and an offset into the section, calculate
2108 and return the name of the source file and the line nearest to the
2112 ecoff_find_nearest_line (abfd
,
2121 asymbol
**ignore_symbols
;
2123 CONST
char **filename_ptr
;
2124 CONST
char **functionname_ptr
;
2125 unsigned int *retline_ptr
;
2131 struct pdr_ext
*pdr_ptr
;
2132 struct pdr_ext
*pdr_end
;
2134 unsigned char *line_ptr
;
2135 unsigned char *line_end
;
2138 /* If we're not in the .text section, we don't have any line
2140 if (strcmp (section
->name
, _TEXT
) != 0
2141 || offset
< ecoff_data (abfd
)->text_start
2142 || offset
>= ecoff_data (abfd
)->text_end
)
2145 /* Make sure we have the FDR's. */
2146 if (ecoff_slurp_symbolic_info (abfd
) == false
2147 || bfd_get_symcount (abfd
) == 0)
2150 /* Each file descriptor (FDR) has a memory address. Here we track
2151 down which FDR we want. The FDR's are stored in increasing
2152 memory order. If speed is ever important, this can become a
2153 binary search. We must ignore FDR's with no PDR entries; they
2154 will have the adr of the FDR before or after them. */
2155 fdr_start
= ecoff_data (abfd
)->fdr
;
2156 fdr_end
= fdr_start
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
2157 fdr_hold
= (FDR
*) NULL
;
2158 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2160 if (fdr_ptr
->cpd
== 0)
2162 if (offset
< fdr_ptr
->adr
)
2166 if (fdr_hold
== (FDR
*) NULL
)
2170 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2171 have an address, which is relative to the FDR address, and are
2172 also stored in increasing memory order. */
2173 offset
-= fdr_ptr
->adr
;
2174 pdr_ptr
= ecoff_data (abfd
)->external_pdr
+ fdr_ptr
->ipdFirst
;
2175 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
;
2176 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2177 if (offset
< pdr
.adr
)
2179 for (pdr_ptr
++; pdr_ptr
< pdr_end
; pdr_ptr
++)
2181 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2182 if (offset
< pdr
.adr
)
2186 /* Now we can look for the actual line number. The line numbers are
2187 stored in a very funky format, which I won't try to describe.
2188 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2189 we want; we need this to compute line_end. */
2190 line_end
= ecoff_data (abfd
)->line
;
2191 if (pdr_ptr
== pdr_end
)
2192 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2194 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2196 /* Now change pdr and pdr_ptr to the one we want. */
2198 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2202 line_ptr
= (ecoff_data (abfd
)->line
2203 + fdr_ptr
->cbLineOffset
2204 + pdr
.cbLineOffset
);
2205 while (line_ptr
< line_end
)
2210 delta
= *line_ptr
>> 4;
2213 count
= (*line_ptr
& 0xf) + 1;
2217 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2218 if (delta
>= 0x8000)
2223 if (offset
< count
* 4)
2225 offset
-= count
* 4;
2228 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2229 at least according to gdb/mipsread.c. */
2230 if (fdr_ptr
->rss
== -1)
2232 *filename_ptr
= NULL
;
2234 *functionname_ptr
= NULL
;
2239 ecoff_swap_ext_in (abfd
,
2240 (ecoff_data (abfd
)->external_ext
2243 *functionname_ptr
= ecoff_data (abfd
)->ssext
+ proc_ext
.asym
.iss
;
2250 *filename_ptr
= ecoff_data (abfd
)->ss
+ fdr_ptr
->issBase
+ fdr_ptr
->rss
;
2251 ecoff_swap_sym_in (abfd
,
2252 (ecoff_data (abfd
)->external_sym
2256 *functionname_ptr
= (ecoff_data (abfd
)->ss
2260 *retline_ptr
= lineno
;
2264 /* We can't use the generic linking routines for ECOFF, because we
2265 have to handle all the debugging information. The generic link
2266 routine just works out the section contents and attaches a list of
2269 We link by looping over all the seclets. We make two passes. On
2270 the first we set the actual section contents and determine the size
2271 of the debugging information. On the second we accumulate the
2272 debugging information and write it out.
2274 This currently always accumulates the debugging information, which
2275 is incorrect, because it ignores the -s and -S options of the
2276 linker. The linker needs to be modified to give us that
2277 information in a more useful format (currently it just provides a
2278 list of symbols which should appear in the output file). */
2280 /* Clear the output_has_begun flag for all the input BFD's. We use it
2281 to avoid linking in the debugging information for a BFD more than
2285 ecoff_clear_output_flags (abfd
)
2288 register asection
*o
;
2289 register bfd_seclet_type
*p
;
2291 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2292 for (p
= o
->seclets_head
;
2293 p
!= (bfd_seclet_type
*) NULL
;
2295 if (p
->type
== bfd_indirect_seclet
)
2296 p
->u
.indirect
.section
->owner
->output_has_begun
= false;
2299 /* Handle an indirect seclet on the first pass. Set the contents of
2300 the output section, and accumulate the debugging information if
2304 ecoff_rel (output_bfd
, seclet
, output_section
, data
, relocateable
)
2306 bfd_seclet_type
*seclet
;
2307 asection
*output_section
;
2309 boolean relocateable
;
2312 HDRR
*output_symhdr
;
2315 if ((output_section
->flags
& SEC_HAS_CONTENTS
)
2316 && !(output_section
->flags
& SEC_NEVER_LOAD
)
2317 && (output_section
->flags
& SEC_LOAD
)
2320 data
= (PTR
) bfd_get_relocated_section_contents (output_bfd
,
2324 if (bfd_set_section_contents (output_bfd
,
2335 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2337 /* We want to figure out how much space will be required to
2338 incorporate all the debugging information from input_bfd. We use
2339 the output_has_begun field to avoid adding it in more than once.
2340 The actual incorporation is done in the second pass, in
2341 ecoff_get_debug. The code has to parallel that code in its
2342 manipulations of output_symhdr. */
2344 if (input_bfd
->output_has_begun
)
2346 input_bfd
->output_has_begun
= true;
2348 output_symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2350 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2356 /* We just accumulate local symbols from a non-ECOFF BFD. The
2357 external symbols are handled separately. */
2359 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2360 get_symtab_upper_bound (input_bfd
));
2361 if (symbols
== (asymbol
**) NULL
)
2363 bfd_error
= no_memory
;
2366 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2368 for (sym_ptr
= symbols
; sym_ptr
< sym_end
; sym_ptr
++)
2372 len
= strlen ((*sym_ptr
)->name
);
2373 if (((*sym_ptr
)->flags
& BSF_EXPORT
) == 0)
2375 ++output_symhdr
->isymMax
;
2376 output_symhdr
->issMax
+= len
+ 1;
2380 bfd_release (output_bfd
, (PTR
) symbols
);
2382 ++output_symhdr
->ifdMax
;
2387 /* We simply add in the information from another ECOFF BFD. First
2388 we make sure we have the symbolic information. */
2389 if (ecoff_slurp_symbol_table (input_bfd
) == false)
2391 if (bfd_get_symcount (input_bfd
) == 0)
2394 input_symhdr
= &ecoff_data (input_bfd
)->symbolic_header
;
2396 /* Figure out how much information we are going to be putting in.
2397 The external symbols are handled separately. */
2398 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2399 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2400 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2401 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2402 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2403 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2404 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2405 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2406 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2408 /* The RFD's are special, since we create them if needed. */
2409 if (input_symhdr
->crfd
> 0)
2410 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2412 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2417 /* Handle an arbitrary seclet on the first pass. */
2420 ecoff_dump_seclet (abfd
, seclet
, section
, data
, relocateable
)
2422 bfd_seclet_type
*seclet
;
2425 boolean relocateable
;
2427 switch (seclet
->type
)
2429 case bfd_indirect_seclet
:
2430 /* The contents of this section come from another one somewhere
2432 return ecoff_rel (abfd
, seclet
, section
, data
, relocateable
);
2434 case bfd_fill_seclet
:
2435 /* Fill in the section with fill.value. This is used to pad out
2436 sections, but we must avoid padding the .bss section. */
2437 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
2439 if (seclet
->u
.fill
.value
!= 0)
2444 char *d
= (char *) bfd_alloc (abfd
, seclet
->size
);
2448 for (i
= 0; i
< seclet
->size
; i
+=2)
2449 d
[i
] = seclet
->u
.fill
.value
>> 8;
2450 for (i
= 1; i
< seclet
->size
; i
+=2)
2451 d
[i
] = seclet
->u
.fill
.value
;
2452 ret
= bfd_set_section_contents (abfd
, section
, d
, seclet
->offset
,
2454 bfd_release (abfd
, (PTR
) d
);
2466 /* Add a string to the debugging information we are accumulating for a
2467 file. Return the offset from the fdr string base or from the
2468 external string base. */
2471 ecoff_add_string (output_bfd
, fdr
, string
, external
)
2481 symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2482 len
= strlen (string
);
2485 strcpy (ecoff_data (output_bfd
)->ssext
+ symhdr
->issExtMax
, string
);
2486 ret
= symhdr
->issExtMax
;
2487 symhdr
->issExtMax
+= len
+ 1;
2491 strcpy (ecoff_data (output_bfd
)->ss
+ symhdr
->issMax
, string
);
2493 symhdr
->issMax
+= len
+ 1;
2494 fdr
->cbSs
+= len
+ 1;
2499 /* Accumulate the debugging information from an input section. */
2502 ecoff_get_debug (output_bfd
, seclet
, section
, relocateable
)
2504 bfd_seclet_type
*seclet
;
2506 boolean relocateable
;
2509 HDRR
*output_symhdr
;
2511 ecoff_data_type
*output_ecoff
;
2512 ecoff_data_type
*input_ecoff
;
2514 struct sym_ext
*sym_out
;
2515 ecoff_symbol_type
*esym_ptr
;
2516 ecoff_symbol_type
*esym_end
;
2517 unsigned long pdr_off
;
2520 struct fdr_ext
*fdr_out
;
2522 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2524 /* Don't get the information more than once. */
2525 if (input_bfd
->output_has_begun
)
2527 input_bfd
->output_has_begun
= true;
2529 output_ecoff
= ecoff_data (output_bfd
);
2530 output_symhdr
= &output_ecoff
->symbolic_header
;
2532 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2539 /* This is not an ECOFF BFD. Just gather the symbols. */
2541 memset (&fdr
, 0, sizeof fdr
);
2543 fdr
.adr
= bfd_get_section_vma (output_bfd
, section
) + seclet
->offset
;
2544 fdr
.issBase
= output_symhdr
->issMax
;
2546 fdr
.rss
= ecoff_add_string (output_bfd
,
2548 bfd_get_filename (input_bfd
),
2550 fdr
.isymBase
= output_symhdr
->isymMax
;
2552 /* Get the local symbols from the input BFD. */
2553 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2554 get_symtab_upper_bound (input_bfd
));
2555 if (symbols
== (asymbol
**) NULL
)
2557 bfd_error
= no_memory
;
2560 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2562 /* Handle the local symbols. Any external symbols are handled
2565 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
2569 if (((*sym_ptr
)->flags
& BSF_EXPORT
) != 0)
2571 memset (&internal_sym
, 0, sizeof internal_sym
);
2572 internal_sym
.iss
= ecoff_add_string (output_bfd
,
2577 if (bfd_is_com_section ((*sym_ptr
)->section
)
2578 || (*sym_ptr
)->section
== &bfd_und_section
)
2579 internal_sym
.value
= (*sym_ptr
)->value
;
2581 internal_sym
.value
= ((*sym_ptr
)->value
2582 + (*sym_ptr
)->section
->output_offset
2583 + (*sym_ptr
)->section
->output_section
->vma
);
2584 internal_sym
.st
= stNil
;
2585 internal_sym
.sc
= scUndefined
;
2586 internal_sym
.index
= indexNil
;
2587 ecoff_swap_sym_out (output_bfd
, &internal_sym
,
2588 (output_ecoff
->external_sym
2589 + output_symhdr
->isymMax
));
2591 ++output_symhdr
->isymMax
;
2594 bfd_release (output_bfd
, (PTR
) symbols
);
2596 /* Leave everything else in the FDR zeroed out. This will cause
2597 the lang field to be langC. The fBigendian field will
2598 indicate little endian format, but it doesn't matter because
2599 it only applies to aux fields and there are none. */
2601 ecoff_swap_fdr_out (output_bfd
, &fdr
,
2602 (output_ecoff
->external_fdr
2603 + output_symhdr
->ifdMax
));
2604 ++output_symhdr
->ifdMax
;
2608 /* This is an ECOFF BFD. We want to grab the information from
2609 input_bfd and attach it to output_bfd. */
2610 count
= bfd_get_symcount (input_bfd
);
2613 input_ecoff
= ecoff_data (input_bfd
);
2614 input_symhdr
= &input_ecoff
->symbolic_header
;
2616 /* I think that it is more efficient to simply copy the debugging
2617 information from the input BFD to the output BFD. Because ECOFF
2618 uses relative pointers for most of the debugging information,
2619 only a little of it has to be changed at all. */
2621 /* Swap in the local symbols, adjust their values, and swap them out
2622 again. The external symbols are handled separately. */
2623 sym_out
= output_ecoff
->external_sym
+ output_symhdr
->isymMax
;
2625 esym_ptr
= ecoff_data (input_bfd
)->canonical_symbols
;
2626 esym_end
= esym_ptr
+ count
;
2627 for (; esym_ptr
< esym_end
; esym_ptr
++)
2629 if (esym_ptr
->local
)
2633 ecoff_swap_sym_in (input_bfd
, esym_ptr
->native
.lnative
, &sym
);
2635 /* If we're producing an executable, move common symbols
2637 if (relocateable
== false)
2639 if (sym
.sc
== scCommon
)
2641 else if (sym
.sc
== scSCommon
)
2645 if (! bfd_is_com_section (esym_ptr
->symbol
.section
)
2646 && (esym_ptr
->symbol
.flags
& BSF_DEBUGGING
) == 0
2647 && esym_ptr
->symbol
.section
!= &bfd_und_section
)
2648 sym
.value
= (esym_ptr
->symbol
.value
2649 + esym_ptr
->symbol
.section
->output_offset
2650 + esym_ptr
->symbol
.section
->output_section
->vma
);
2651 ecoff_swap_sym_out (output_bfd
, &sym
, sym_out
);
2656 /* That should have accounted for all the local symbols in
2658 BFD_ASSERT ((sym_out
- output_ecoff
->external_sym
) - output_symhdr
->isymMax
2659 == input_symhdr
->isymMax
);
2661 /* Copy the information that does not need swapping. */
2662 memcpy (output_ecoff
->line
+ output_symhdr
->cbLine
,
2664 input_symhdr
->cbLine
* sizeof (unsigned char));
2665 memcpy (output_ecoff
->external_aux
+ output_symhdr
->iauxMax
,
2666 input_ecoff
->external_aux
,
2667 input_symhdr
->iauxMax
* sizeof (union aux_ext
));
2668 memcpy (output_ecoff
->ss
+ output_symhdr
->issMax
,
2670 input_symhdr
->issMax
* sizeof (char));
2672 /* Some of the information may need to be swapped. */
2673 if (output_bfd
->xvec
->header_byteorder_big_p
2674 == input_bfd
->xvec
->header_byteorder_big_p
)
2676 /* The two BFD's have the same endianness, so memcpy will
2678 memcpy (output_ecoff
->external_dnr
+ output_symhdr
->idnMax
,
2679 input_ecoff
->external_dnr
,
2680 input_symhdr
->idnMax
* sizeof (struct dnr_ext
));
2681 memcpy (output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
,
2682 input_ecoff
->external_pdr
,
2683 input_symhdr
->ipdMax
* sizeof (struct pdr_ext
));
2684 if (input_symhdr
->ipdMax
== 0)
2690 ecoff_swap_pdr_in (input_bfd
, input_ecoff
->external_pdr
, &pdr
);
2693 memcpy (output_ecoff
->external_opt
+ output_symhdr
->ioptMax
,
2694 input_ecoff
->external_opt
,
2695 input_symhdr
->ioptMax
* sizeof (struct opt_ext
));
2699 struct dnr_ext
*dnr_in
;
2700 struct dnr_ext
*dnr_end
;
2701 struct dnr_ext
*dnr_out
;
2702 struct pdr_ext
*pdr_in
;
2703 struct pdr_ext
*pdr_end
;
2704 struct pdr_ext
*pdr_out
;
2706 struct opt_ext
*opt_in
;
2707 struct opt_ext
*opt_end
;
2708 struct opt_ext
*opt_out
;
2710 /* The two BFD's have different endianness, so we must swap
2711 everything in and out. This code would always work, but it
2712 would be slow in the normal case. */
2713 dnr_in
= input_ecoff
->external_dnr
;
2714 dnr_end
= dnr_in
+ input_symhdr
->idnMax
;
2715 dnr_out
= output_ecoff
->external_dnr
+ output_symhdr
->idnMax
;
2716 for (; dnr_in
< dnr_end
; dnr_in
++, dnr_out
++)
2720 ecoff_swap_dnr_in (input_bfd
, dnr_in
, &dnr
);
2721 ecoff_swap_dnr_out (output_bfd
, &dnr
, dnr_out
);
2723 pdr_in
= input_ecoff
->external_pdr
;
2724 pdr_end
= pdr_in
+ input_symhdr
->ipdMax
;
2725 pdr_out
= output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
;
2728 for (; pdr_in
< pdr_end
; pdr_in
++, pdr_out
++)
2732 ecoff_swap_pdr_in (input_bfd
, pdr_in
, &pdr
);
2733 ecoff_swap_pdr_out (output_bfd
, &pdr
, pdr_out
);
2740 opt_in
= input_ecoff
->external_opt
;
2741 opt_end
= opt_in
+ input_symhdr
->ioptMax
;
2742 opt_out
= output_ecoff
->external_opt
+ output_symhdr
->ioptMax
;
2743 for (; opt_in
< opt_end
; opt_in
++, opt_out
++)
2747 ecoff_swap_opt_in (input_bfd
, opt_in
, &opt
);
2748 ecoff_swap_opt_out (output_bfd
, &opt
, opt_out
);
2752 /* Set ifdbase so that the external symbols know how to adjust their
2754 input_ecoff
->ifdbase
= output_symhdr
->ifdMax
;
2756 fdr_ptr
= input_ecoff
->fdr
;
2757 fdr_end
= fdr_ptr
+ input_symhdr
->ifdMax
;
2758 fdr_out
= output_ecoff
->external_fdr
+ output_symhdr
->ifdMax
;
2759 for (; fdr_ptr
< fdr_end
; fdr_ptr
++, fdr_out
++)
2765 /* The memory address for this fdr is the address for the seclet
2766 plus the offset to this fdr within input_bfd. For some
2767 reason the offset of the first procedure pointer is also
2769 fdr
.adr
= (bfd_get_section_vma (output_bfd
, section
)
2771 + (fdr_ptr
->adr
- input_ecoff
->fdr
->adr
)
2774 fdr
.issBase
+= output_symhdr
->issMax
;
2775 fdr
.isymBase
+= output_symhdr
->isymMax
;
2776 fdr
.ilineBase
+= output_symhdr
->ilineMax
;
2777 fdr
.ioptBase
+= output_symhdr
->ioptMax
;
2778 fdr
.ipdFirst
+= output_symhdr
->ipdMax
;
2779 fdr
.iauxBase
+= output_symhdr
->iauxMax
;
2780 fdr
.rfdBase
+= output_symhdr
->crfd
;
2782 /* If there are no RFD's, we are going to add some. We don't
2783 want to adjust irfd for this, so that all the FDR's can share
2785 if (input_symhdr
->crfd
== 0)
2786 fdr
.crfd
= input_symhdr
->ifdMax
;
2788 if (fdr
.cbLine
!= 0)
2789 fdr
.cbLineOffset
+= output_symhdr
->cbLine
;
2791 ecoff_swap_fdr_out (output_bfd
, &fdr
, fdr_out
);
2794 if (input_symhdr
->crfd
> 0)
2796 struct rfd_ext
*rfd_in
;
2797 struct rfd_ext
*rfd_end
;
2798 struct rfd_ext
*rfd_out
;
2800 /* Swap and adjust the RFD's. RFD's are only created by the
2801 linker, so this will only be necessary if one of the input
2802 files is the result of a partial link. Presumably all
2803 necessary RFD's are present. */
2804 rfd_in
= input_ecoff
->external_rfd
;
2805 rfd_end
= rfd_in
+ input_symhdr
->crfd
;
2806 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
2807 for (; rfd_in
< rfd_end
; rfd_in
++, rfd_out
++)
2811 ecoff_swap_rfd_in (input_bfd
, rfd_in
, &rfd
);
2812 rfd
+= output_symhdr
->ifdMax
;
2813 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
2815 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2819 struct rfd_ext
*rfd_out
;
2820 struct rfd_ext
*rfd_end
;
2823 /* Create RFD's. Some of the debugging information includes
2824 relative file indices. These indices are taken as indices to
2825 the RFD table if there is one, or to the global table if
2826 there is not. If we did not create RFD's, we would have to
2827 parse and adjust all the debugging information which contains
2829 rfd
= output_symhdr
->ifdMax
;
2830 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
2831 rfd_end
= rfd_out
+ input_symhdr
->ifdMax
;
2832 for (; rfd_out
< rfd_end
; rfd_out
++, rfd
++)
2833 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
2834 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2837 /* Combine the register masks. */
2841 output_ecoff
->gprmask
|= input_ecoff
->gprmask
;
2842 for (i
= 0; i
< 4; i
++)
2843 output_ecoff
->cprmask
[i
] |= input_ecoff
->cprmask
[i
];
2846 /* Update the counts. */
2847 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2848 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2849 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2850 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2851 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2852 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2853 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2854 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2855 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2860 /* This is the actual link routine. It makes two passes over all the
2864 ecoff_bfd_seclet_link (abfd
, data
, relocateable
)
2867 boolean relocateable
;
2871 register asection
*o
;
2872 register bfd_seclet_type
*p
;
2873 asymbol
**sym_ptr_ptr
;
2877 /* We accumulate the debugging information counts in the symbolic
2879 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
2880 symhdr
->magic
= magicSym
;
2881 /* FIXME: What should the version stamp be? */
2883 symhdr
->ilineMax
= 0;
2887 symhdr
->isymMax
= 0;
2888 symhdr
->ioptMax
= 0;
2889 symhdr
->iauxMax
= 0;
2891 symhdr
->issExtMax
= 0;
2894 symhdr
->iextMax
= 0;
2896 /* We need to copy over the debugging symbols from each input BFD.
2897 When we do this copying, we have to adjust the text address in
2898 the FDR structures, so we have to know the text address used for
2899 the input BFD. Since we only want to copy the symbols once per
2900 input BFD, but we are going to look at each input BFD multiple
2901 times (once for each section it provides), we arrange to always
2902 look at the text section first. That means that when we copy the
2903 debugging information, we always know the text address. So we
2904 actually do each pass in two sub passes; first the text sections,
2905 then the non-text sections. We use the output_has_begun flag to
2906 determine whether we have copied over the debugging information
2909 /* Do the first pass: set the output section contents and count the
2910 debugging information. */
2911 ecoff_clear_output_flags (abfd
);
2912 for (ipass
= 0; ipass
< 2; ipass
++)
2914 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2916 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2917 so they are done on pass 0. For other sections the
2918 expression is true, so they are done on pass 1. */
2919 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2922 for (p
= o
->seclets_head
;
2923 p
!= (bfd_seclet_type
*) NULL
;
2926 if (ecoff_dump_seclet (abfd
, p
, o
, data
, relocateable
)
2933 /* We handle the external symbols differently. We use the ones
2934 attached to the output_bfd. The linker will have already
2935 determined which symbols are to be attached. Here we just
2936 determine how much space we will need for them. */
2937 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2938 if (sym_ptr_ptr
!= NULL
)
2942 sym_end
= sym_ptr_ptr
+ bfd_get_symcount (abfd
);
2943 for (; sym_ptr_ptr
< sym_end
; sym_ptr_ptr
++)
2945 if (((*sym_ptr_ptr
)->flags
& BSF_DEBUGGING
) == 0
2946 && ((*sym_ptr_ptr
)->flags
& BSF_LOCAL
) == 0)
2949 symhdr
->issExtMax
+= strlen ((*sym_ptr_ptr
)->name
) + 1;
2954 /* Adjust the counts so that structures are longword aligned. */
2955 symhdr
->cbLine
= (symhdr
->cbLine
+ 3) &~ 3;
2956 symhdr
->issMax
= (symhdr
->issMax
+ 3) &~ 3;
2957 symhdr
->issExtMax
= (symhdr
->issExtMax
+ 3) &~ 3;
2959 /* Now the counts in symhdr are the correct size for the debugging
2960 information. We allocate the right amount of space, and reset
2961 the counts so that the second pass can use them as indices. It
2962 would be possible to output the debugging information directly to
2963 the file in pass 2, rather than to build it in memory and then
2964 write it out. Outputting to the file would require a lot of
2965 seeks and small writes, though, and I think this approach is
2967 size
= (symhdr
->cbLine
* sizeof (unsigned char)
2968 + symhdr
->idnMax
* sizeof (struct dnr_ext
)
2969 + symhdr
->ipdMax
* sizeof (struct pdr_ext
)
2970 + symhdr
->isymMax
* sizeof (struct sym_ext
)
2971 + symhdr
->ioptMax
* sizeof (struct opt_ext
)
2972 + symhdr
->iauxMax
* sizeof (union aux_ext
)
2973 + symhdr
->issMax
* sizeof (char)
2974 + symhdr
->issExtMax
* sizeof (char)
2975 + symhdr
->ifdMax
* sizeof (struct fdr_ext
)
2976 + symhdr
->crfd
* sizeof (struct rfd_ext
)
2977 + symhdr
->iextMax
* sizeof (struct ext_ext
));
2978 raw
= (char *) bfd_alloc (abfd
, size
);
2979 if (raw
== (char *) NULL
)
2981 bfd_error
= no_memory
;
2984 ecoff_data (abfd
)->raw_size
= size
;
2985 ecoff_data (abfd
)->raw_syments
= (PTR
) raw
;
2987 /* Initialize the raw pointers. */
2988 #define SET(field, count, type) \
2989 ecoff_data (abfd)->field = (type *) raw; \
2990 raw += symhdr->count * sizeof (type)
2992 SET (line
, cbLine
, unsigned char);
2993 SET (external_dnr
, idnMax
, struct dnr_ext
);
2994 SET (external_pdr
, ipdMax
, struct pdr_ext
);
2995 SET (external_sym
, isymMax
, struct sym_ext
);
2996 SET (external_opt
, ioptMax
, struct opt_ext
);
2997 SET (external_aux
, iauxMax
, union aux_ext
);
2998 SET (ss
, issMax
, char);
2999 SET (ssext
, issExtMax
, char);
3000 SET (external_fdr
, ifdMax
, struct fdr_ext
);
3001 SET (external_rfd
, crfd
, struct rfd_ext
);
3002 SET (external_ext
, iextMax
, struct ext_ext
);
3005 /* Reset the counts so the second pass can use them to know how far
3007 symhdr
->ilineMax
= 0;
3011 symhdr
->isymMax
= 0;
3012 symhdr
->ioptMax
= 0;
3013 symhdr
->iauxMax
= 0;
3015 symhdr
->issExtMax
= 0;
3018 symhdr
->iextMax
= 0;
3020 /* Do the second pass: accumulate the debugging information. */
3021 ecoff_clear_output_flags (abfd
);
3022 for (ipass
= 0; ipass
< 2; ipass
++)
3024 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3026 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
3028 for (p
= o
->seclets_head
;
3029 p
!= (bfd_seclet_type
*) NULL
;
3032 if (p
->type
== bfd_indirect_seclet
)
3034 if (ecoff_get_debug (abfd
, p
, o
, relocateable
) == false)
3041 /* Put in the external symbols. */
3042 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
3043 if (sym_ptr_ptr
!= NULL
)
3046 struct ext_ext
*external_ext
;
3048 ssext
= ecoff_data (abfd
)->ssext
;
3049 external_ext
= ecoff_data (abfd
)->external_ext
;
3050 for (; *sym_ptr_ptr
!= NULL
; sym_ptr_ptr
++)
3055 sym_ptr
= *sym_ptr_ptr
;
3057 if ((sym_ptr
->flags
& BSF_DEBUGGING
) != 0
3058 || (sym_ptr
->flags
& BSF_LOCAL
) != 0)
3061 /* The enative pointer can be NULL for a symbol created by
3062 the linker via ecoff_make_empty_symbol. */
3063 if (bfd_asymbol_flavour (sym_ptr
) != bfd_target_ecoff_flavour
3064 || (((ecoff_symbol_type
*) sym_ptr
)->native
.enative
3065 == (struct ext_ext
*) NULL
))
3068 esym
.cobol_main
= 0;
3072 /* FIXME: we can do better than this for st and sc. */
3073 esym
.asym
.st
= stGlobal
;
3074 esym
.asym
.sc
= scAbs
;
3075 esym
.asym
.reserved
= 0;
3076 esym
.asym
.index
= indexNil
;
3080 ecoff_symbol_type
*ecoff_sym_ptr
;
3082 ecoff_sym_ptr
= (ecoff_symbol_type
*) sym_ptr
;
3083 if (ecoff_sym_ptr
->local
)
3085 ecoff_swap_ext_in (abfd
, ecoff_sym_ptr
->native
.enative
, &esym
);
3087 /* If we're producing an executable, move common symbols
3089 if (relocateable
== false)
3091 if (esym
.asym
.sc
== scCommon
)
3092 esym
.asym
.sc
= scBss
;
3093 else if (esym
.asym
.sc
== scSCommon
)
3094 esym
.asym
.sc
= scSBss
;
3097 /* Adjust the FDR index for the symbol by that used for
3099 esym
.ifd
+= ecoff_data (bfd_asymbol_bfd (sym_ptr
))->ifdbase
;
3102 esym
.asym
.iss
= symhdr
->issExtMax
;
3104 if (bfd_is_com_section (sym_ptr
->section
)
3105 || sym_ptr
->section
== &bfd_und_section
)
3106 esym
.asym
.value
= sym_ptr
->value
;
3108 esym
.asym
.value
= (sym_ptr
->value
3109 + sym_ptr
->section
->output_offset
3110 + sym_ptr
->section
->output_section
->vma
);
3112 ecoff_swap_ext_out (abfd
, &esym
, external_ext
+ symhdr
->iextMax
);
3114 ecoff_set_sym_index (sym_ptr
, symhdr
->iextMax
);
3118 strcpy (ssext
+ symhdr
->issExtMax
, sym_ptr
->name
);
3119 symhdr
->issExtMax
+= strlen (sym_ptr
->name
) + 1;
3123 /* Adjust the counts so that structures are longword aligned. */
3124 symhdr
->cbLine
= (symhdr
->cbLine
+ 3) &~ 3;
3125 symhdr
->issMax
= (symhdr
->issMax
+ 3) &~ 3;
3126 symhdr
->issExtMax
= (symhdr
->issExtMax
+ 3) &~ 3;
3131 /* Set the architecture. The only architecture we support here is
3132 mips. We set the architecture anyhow, since many callers ignore
3133 the return value. */
3136 ecoff_set_arch_mach (abfd
, arch
, machine
)
3138 enum bfd_architecture arch
;
3139 unsigned long machine
;
3141 bfd_default_set_arch_mach (abfd
, arch
, machine
);
3142 return arch
== bfd_arch_mips
;
3145 /* Get the size of the section headers. We do not output the .scommon
3146 section which we created in ecoff_mkobject. */
3149 ecoff_sizeof_headers (abfd
, reloc
)
3153 return FILHSZ
+ AOUTSZ
+ (abfd
->section_count
- 1) * SCNHSZ
;
3156 /* Calculate the file position for each section, and set
3160 ecoff_compute_section_file_positions (abfd
)
3168 if (bfd_get_start_address (abfd
))
3169 abfd
->flags
|= EXEC_P
;
3171 sofar
= ecoff_sizeof_headers (abfd
, false);
3174 for (current
= abfd
->sections
;
3175 current
!= (asection
*) NULL
;
3176 current
= current
->next
)
3178 /* Only deal with sections which have contents */
3179 if (! (current
->flags
& SEC_HAS_CONTENTS
)
3180 || strcmp (current
->name
, SCOMMON
) == 0)
3183 /* On Ultrix, the data sections in an executable file must be
3184 aligned to a page boundary within the file. This does not
3185 affect the section size, though. FIXME: Does this work for
3187 if ((abfd
->flags
& EXEC_P
) != 0
3188 && first_data
!= false
3189 && (current
->flags
& SEC_CODE
) == 0)
3191 sofar
= (sofar
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
3195 /* Align the sections in the file to the same boundary on
3196 which they are aligned in virtual memory. */
3198 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3200 current
->filepos
= sofar
;
3202 sofar
+= current
->_raw_size
;
3204 /* make sure that this section is of the right size too */
3206 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3207 current
->_raw_size
+= sofar
- old_sofar
;
3210 ecoff_data (abfd
)->reloc_filepos
= sofar
;
3213 /* Set the contents of a section. */
3216 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
3221 bfd_size_type count
;
3223 if (abfd
->output_has_begun
== false)
3224 ecoff_compute_section_file_positions (abfd
);
3226 bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
3229 return (bfd_write (location
, 1, count
, abfd
) == count
) ? true : false;
3234 /* Write out an ECOFF file. */
3237 ecoff_write_object_contents (abfd
)
3243 file_ptr reloc_base
;
3245 unsigned long reloc_size
;
3246 unsigned long text_size
;
3247 unsigned long text_start
;
3248 unsigned long data_size
;
3249 unsigned long data_start
;
3250 unsigned long bss_size
;
3251 struct internal_filehdr internal_f
;
3252 struct internal_aouthdr internal_a
;
3255 bfd_error
= system_call_error
;
3257 if(abfd
->output_has_begun
== false)
3258 ecoff_compute_section_file_positions(abfd
);
3260 if (abfd
->sections
!= (asection
*) NULL
)
3261 scn_base
= abfd
->sections
->filepos
;
3264 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
3268 for (current
= abfd
->sections
;
3269 current
!= (asection
*)NULL
;
3270 current
= current
->next
)
3272 if (strcmp (current
->name
, SCOMMON
) == 0)
3274 current
->target_index
= count
;
3276 if (current
->reloc_count
!= 0)
3278 bfd_size_type relsize
;
3280 current
->rel_filepos
= reloc_base
;
3281 relsize
= current
->reloc_count
* RELSZ
;
3282 reloc_size
+= relsize
;
3283 reloc_base
+= relsize
;
3286 current
->rel_filepos
= 0;
3289 sym_base
= reloc_base
+ reloc_size
;
3291 /* At least on Ultrix, the symbol table of an executable file must
3292 be aligned to a page boundary. FIXME: Is this true on other
3294 if ((abfd
->flags
& EXEC_P
) != 0)
3295 sym_base
= (sym_base
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
3297 ecoff_data (abfd
)->sym_filepos
= sym_base
;
3299 text_size
= ecoff_sizeof_headers (abfd
, false);
3305 /* Write section headers to the file. */
3307 internal_f
.f_nscns
= 0;
3308 if (bfd_seek (abfd
, (file_ptr
) (FILHSZ
+ AOUTSZ
), SEEK_SET
) != 0)
3310 for (current
= abfd
->sections
;
3311 current
!= (asection
*) NULL
;
3312 current
= current
->next
)
3314 struct internal_scnhdr section
;
3317 if (strcmp (current
->name
, SCOMMON
) == 0)
3319 BFD_ASSERT (bfd_get_section_size_before_reloc (current
) == 0
3320 && current
->reloc_count
== 0);
3324 ++internal_f
.f_nscns
;
3326 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
3328 /* FIXME: is this correct for shared libraries? I think it is
3329 but I have no platform to check. Ian Lance Taylor. */
3330 vma
= bfd_get_section_vma (abfd
, current
);
3331 if (strcmp (current
->name
, _LIB
) == 0)
3332 section
.s_vaddr
= 0;
3334 section
.s_vaddr
= vma
;
3336 section
.s_paddr
= vma
;
3337 section
.s_size
= bfd_get_section_size_before_reloc (current
);
3339 /* If this section has no size or is unloadable then the scnptr
3341 if (current
->_raw_size
== 0
3342 || (current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
3343 section
.s_scnptr
= 0;
3345 section
.s_scnptr
= current
->filepos
;
3346 section
.s_relptr
= current
->rel_filepos
;
3348 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3349 object file produced by the assembler is supposed to point to
3350 information about how much room is required by objects of
3351 various different sizes. I think this only matters if we
3352 want the linker to compute the best size to use, or
3353 something. I don't know what happens if the information is
3355 section
.s_lnnoptr
= 0;
3357 section
.s_nreloc
= current
->reloc_count
;
3358 section
.s_nlnno
= 0;
3359 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
3365 ecoff_swap_scnhdr_out (abfd
, (PTR
) §ion
, (PTR
) &buff
);
3366 if (bfd_write ((PTR
) &buff
, 1, SCNHSZ
, abfd
) != SCNHSZ
)
3370 if ((section
.s_flags
& STYP_TEXT
) != 0)
3372 text_size
+= bfd_get_section_size_before_reloc (current
);
3373 if (text_start
== 0 || text_start
> vma
)
3376 else if ((section
.s_flags
& STYP_RDATA
) != 0
3377 || (section
.s_flags
& STYP_DATA
) != 0
3378 || (section
.s_flags
& STYP_LIT8
) != 0
3379 || (section
.s_flags
& STYP_LIT4
) != 0
3380 || (section
.s_flags
& STYP_SDATA
) != 0)
3382 data_size
+= bfd_get_section_size_before_reloc (current
);
3383 if (data_start
== 0 || data_start
> vma
)
3386 else if ((section
.s_flags
& STYP_BSS
) != 0
3387 || (section
.s_flags
& STYP_SBSS
) != 0)
3388 bss_size
+= bfd_get_section_size_before_reloc (current
);
3391 /* Set up the file header. */
3393 if (abfd
->xvec
->header_byteorder_big_p
!= false)
3394 internal_f
.f_magic
= MIPS_MAGIC_BIG
;
3396 internal_f
.f_magic
= MIPS_MAGIC_LITTLE
;
3399 We will NOT put a fucking timestamp in the header here. Every time you
3400 put it back, I will come in and take it out again. I'm sorry. This
3401 field does not belong here. We fill it with a 0 so it compares the
3402 same but is not a reasonable time. -- gnu@cygnus.com
3404 internal_f
.f_timdat
= 0;
3406 if (bfd_get_symcount (abfd
) != 0)
3408 /* The ECOFF f_nsyms field is not actually the number of
3409 symbols, it's the size of symbolic information header. */
3410 internal_f
.f_nsyms
= sizeof (struct hdr_ext
);
3411 internal_f
.f_symptr
= sym_base
;
3415 internal_f
.f_nsyms
= 0;
3416 internal_f
.f_symptr
= 0;
3419 internal_f
.f_opthdr
= AOUTSZ
;
3421 internal_f
.f_flags
= F_LNNO
;
3422 if (reloc_size
== 0)
3423 internal_f
.f_flags
|= F_RELFLG
;
3424 if (bfd_get_symcount (abfd
) == 0)
3425 internal_f
.f_flags
|= F_LSYMS
;
3426 if (abfd
->flags
& EXEC_P
)
3427 internal_f
.f_flags
|= F_EXEC
;
3429 if (! abfd
->xvec
->byteorder_big_p
)
3430 internal_f
.f_flags
|= F_AR32WR
;
3432 internal_f
.f_flags
|= F_AR32W
;
3434 /* Set up the ``optional'' header. */
3435 internal_a
.magic
= ZMAGIC
;
3437 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
3438 linker happy. But, is it right? */
3439 internal_a
.vstamp
= 0x20a;
3441 /* At least on Ultrix, these have to be rounded to page boundaries.
3442 FIXME: Is this true on other platforms? */
3443 internal_a
.tsize
= (text_size
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
3444 internal_a
.text_start
= text_start
&~ (PAGE_SIZE
- 1);
3445 internal_a
.dsize
= (data_size
+ PAGE_SIZE
- 1) &~ (PAGE_SIZE
- 1);
3446 internal_a
.data_start
= data_start
&~ (PAGE_SIZE
- 1);
3448 /* On Ultrix, the initial portions of the .sbss and .bss segments
3449 are at the end of the data section. The bsize field in the
3450 optional header records how many bss bytes are required beyond
3451 those in the data section. The value is not rounded to a page
3453 if (bss_size
< internal_a
.dsize
- data_size
)
3456 bss_size
-= internal_a
.dsize
- data_size
;
3457 internal_a
.bsize
= bss_size
;
3458 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
3460 internal_a
.entry
= bfd_get_start_address (abfd
);
3462 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
3464 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
3465 for (i
= 0; i
< 4; i
++)
3466 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
3468 /* Write out the file header and the optional header. */
3470 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3475 ecoff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, (PTR
) &buff
);
3476 if (bfd_write ((PTR
) &buff
, 1, FILHSZ
, abfd
) != FILHSZ
)
3483 ecoff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, (PTR
) &buff
);
3484 if (bfd_write ((PTR
) &buff
, 1, AOUTSZ
, abfd
) != AOUTSZ
)
3488 /* Write out the relocs. */
3489 for (current
= abfd
->sections
;
3490 current
!= (asection
*) NULL
;
3491 current
= current
->next
)
3494 arelent
**reloc_ptr_ptr
;
3495 arelent
**reloc_end
;
3498 if (current
->reloc_count
== 0)
3501 buff
= (RELOC
*) bfd_alloc (abfd
, current
->reloc_count
* RELSZ
);
3502 if (buff
== (RELOC
*) NULL
)
3504 bfd_error
= no_memory
;
3508 reloc_ptr_ptr
= current
->orelocation
;
3509 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
3511 for (; reloc_ptr_ptr
< reloc_end
; reloc_ptr_ptr
++, out_ptr
++)
3515 struct internal_reloc in
;
3517 memset (&in
, 0, sizeof in
);
3519 reloc
= *reloc_ptr_ptr
;
3520 sym
= *reloc
->sym_ptr_ptr
;
3522 /* This must be an ECOFF reloc. */
3523 BFD_ASSERT (reloc
->howto
!= (reloc_howto_type
*) NULL
3524 && reloc
->howto
>= ecoff_howto_table
3526 < (ecoff_howto_table
+ ECOFF_HOWTO_COUNT
)));
3528 in
.r_vaddr
= reloc
->address
+ bfd_get_section_vma (abfd
, current
);
3529 in
.r_type
= reloc
->howto
->type
;
3531 /* If this is a REFHI reloc, the next one must be a REFLO
3532 reloc for the same symbol. */
3533 BFD_ASSERT (in
.r_type
!= ECOFF_R_REFHI
3534 || (reloc_ptr_ptr
< reloc_end
3535 && (reloc_ptr_ptr
[1]->howto
3536 != (reloc_howto_type
*) NULL
)
3537 && (reloc_ptr_ptr
[1]->howto
->type
3539 && (sym
== *reloc_ptr_ptr
[1]->sym_ptr_ptr
)));
3541 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
3543 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
3550 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
3551 if (strcmp (name
, ".text") == 0)
3552 in
.r_symndx
= RELOC_SECTION_TEXT
;
3553 else if (strcmp (name
, ".rdata") == 0)
3554 in
.r_symndx
= RELOC_SECTION_RDATA
;
3555 else if (strcmp (name
, ".data") == 0)
3556 in
.r_symndx
= RELOC_SECTION_DATA
;
3557 else if (strcmp (name
, ".sdata") == 0)
3558 in
.r_symndx
= RELOC_SECTION_SDATA
;
3559 else if (strcmp (name
, ".sbss") == 0)
3560 in
.r_symndx
= RELOC_SECTION_SBSS
;
3561 else if (strcmp (name
, ".bss") == 0)
3562 in
.r_symndx
= RELOC_SECTION_BSS
;
3563 else if (strcmp (name
, ".init") == 0)
3564 in
.r_symndx
= RELOC_SECTION_INIT
;
3565 else if (strcmp (name
, ".lit8") == 0)
3566 in
.r_symndx
= RELOC_SECTION_LIT8
;
3567 else if (strcmp (name
, ".lit4") == 0)
3568 in
.r_symndx
= RELOC_SECTION_LIT4
;
3574 ecoff_swap_reloc_out (abfd
, (PTR
) &in
, (PTR
) out_ptr
);
3577 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3579 if (bfd_write ((PTR
) buff
, RELSZ
, current
->reloc_count
, abfd
)
3580 != RELSZ
* current
->reloc_count
)
3582 bfd_release (abfd
, (PTR
) buff
);
3585 /* Write out the symbolic debugging information. */
3586 if (bfd_get_symcount (abfd
) > 0)
3589 unsigned long sym_offset
;
3590 struct hdr_ext buff
;
3592 /* Set up the offsets in the symbolic header. */
3593 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
3594 sym_offset
= ecoff_data (abfd
)->sym_filepos
+ sizeof (struct hdr_ext
);
3596 #define SET(offset, size, ptr) \
3597 if (symhdr->size == 0) \
3598 symhdr->offset = 0; \
3600 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3601 - (char *) ecoff_data (abfd)->raw_syments) \
3604 SET (cbLineOffset
, cbLine
, line
);
3605 SET (cbDnOffset
, idnMax
, external_dnr
);
3606 SET (cbPdOffset
, ipdMax
, external_pdr
);
3607 SET (cbSymOffset
, isymMax
, external_sym
);
3608 SET (cbOptOffset
, ioptMax
, external_opt
);
3609 SET (cbAuxOffset
, iauxMax
, external_aux
);
3610 SET (cbSsOffset
, issMax
, ss
);
3611 SET (cbSsExtOffset
, issExtMax
, ssext
);
3612 SET (cbFdOffset
, ifdMax
, external_fdr
);
3613 SET (cbRfdOffset
, crfd
, external_rfd
);
3614 SET (cbExtOffset
, iextMax
, external_ext
);
3617 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
,
3620 ecoff_swap_hdr_out (abfd
, &ecoff_data (abfd
)->symbolic_header
, &buff
);
3621 if (bfd_write ((PTR
) &buff
, 1, sizeof buff
, abfd
) != sizeof buff
)
3623 if (bfd_write ((PTR
) ecoff_data (abfd
)->raw_syments
, 1,
3624 ecoff_data (abfd
)->raw_size
, abfd
)
3625 != ecoff_data (abfd
)->raw_size
)
3632 /* Archive handling. ECOFF uses what appears to be a unique type of
3633 archive header (which I call an armap). The byte ordering of the
3634 armap and the contents are encoded in the name of the armap itself.
3635 At least for now, we only support archives with the same byte
3636 ordering in the armap and the contents.
3638 The first four bytes in the armap are the number of symbol
3639 definitions. This is always a power of two.
3641 This is followed by the symbol definitions. Each symbol definition
3642 occupies 8 bytes. The first four bytes are the offset from the
3643 start of the armap strings to the null-terminated string naming
3644 this symbol. The second four bytes are the file offset to the
3645 archive member which defines this symbol. If the second four bytes
3646 are 0, then this is not actually a symbol definition, and it should
3649 The symbols are hashed into the armap with a closed hashing scheme.
3650 See the functions below for the details of the algorithm.
3652 We could use the hash table when looking up symbols in a library.
3653 This would require a new BFD target entry point to replace the
3654 bfd_get_next_mapent function used by the linker.
3656 After the symbol definitions comes four bytes holding the size of
3657 the string table, followed by the string table itself. */
3659 /* The name of an archive headers looks like this:
3660 __________E[BL]E[BL]_ (with a trailing space).
3661 The trailing space is changed to an X if the archive is changed to
3662 indicate that the armap is out of date. */
3664 #define ARMAP_BIG_ENDIAN 'B'
3665 #define ARMAP_LITTLE_ENDIAN 'L'
3666 #define ARMAP_MARKER 'E'
3667 #define ARMAP_START "__________"
3668 #define ARMAP_HEADER_MARKER_INDEX 10
3669 #define ARMAP_HEADER_ENDIAN_INDEX 11
3670 #define ARMAP_OBJECT_MARKER_INDEX 12
3671 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3672 #define ARMAP_END_INDEX 14
3673 #define ARMAP_END "_ "
3675 /* This is a magic number used in the hashing algorithm. */
3676 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3678 /* This returns the hash value to use for a string. It also sets
3679 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3680 is the number of entries in the hash table, and HLOG is the log
3684 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3686 unsigned int *rehash
;
3694 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3695 hash
*= ARMAP_HASH_MAGIC
;
3696 *rehash
= (hash
& (size
- 1)) | 1;
3697 return hash
>> (32 - hlog
);
3700 /* Read in the armap. */
3703 ecoff_slurp_armap (abfd
)
3708 struct areltdata
*mapdata
;
3709 bfd_size_type parsed_size
;
3711 struct artdata
*ardata
;
3714 struct symdef
*symdef_ptr
;
3717 /* Get the name of the first element. */
3718 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3724 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
3726 /* See if the first element is an armap. */
3727 if (strncmp (nextname
, ARMAP_START
, sizeof ARMAP_START
- 1) != 0
3728 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3729 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3730 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3731 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3732 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3733 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3734 || strncmp (nextname
+ ARMAP_END_INDEX
,
3735 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3737 bfd_has_map (abfd
) = false;
3741 /* Make sure we have the right byte ordering. */
3742 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3743 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3744 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3745 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3747 bfd_error
= wrong_format
;
3751 /* Read in the armap. */
3752 ardata
= bfd_ardata (abfd
);
3753 mapdata
= snarf_ar_hdr (abfd
);
3754 if (mapdata
== (struct areltdata
*) NULL
)
3756 parsed_size
= mapdata
->parsed_size
;
3757 bfd_release (abfd
, (PTR
) mapdata
);
3759 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3760 if (raw_armap
== (char *) NULL
)
3762 bfd_error
= no_memory
;
3766 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3768 bfd_error
= malformed_archive
;
3769 bfd_release (abfd
, (PTR
) raw_armap
);
3773 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3775 ardata
->symdef_count
= 0;
3776 ardata
->cache
= (struct ar_cache
*) NULL
;
3778 /* Hack: overlay the symdefs on top of the raw archive data. This
3779 is the way do_slurp_bsd_armap works. */
3780 raw_ptr
= raw_armap
+ LONG_SIZE
;
3781 symdef_ptr
= (struct symdef
*) raw_ptr
;
3782 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3783 stringbase
= raw_ptr
+ count
* (2 * LONG_SIZE
) + LONG_SIZE
;
3785 #ifdef CHECK_ARMAP_HASH
3789 /* Double check that I have the hashing algorithm right by making
3790 sure that every symbol can be looked up successfully. */
3792 for (i
= 1; i
< count
; i
<<= 1)
3794 BFD_ASSERT (i
== count
);
3796 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3798 unsigned int name_offset
, file_offset
;
3799 unsigned int hash
, rehash
, srch
;
3801 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3802 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3803 if (file_offset
== 0)
3805 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3810 /* See if we can rehash to this location. */
3811 for (srch
= (hash
+ rehash
) & (count
- 1);
3812 srch
!= hash
&& srch
!= i
;
3813 srch
= (srch
+ rehash
) & (count
- 1))
3814 BFD_ASSERT (bfd_h_get_32 (abfd
,
3817 + (srch
* 2 * LONG_SIZE
)
3820 BFD_ASSERT (srch
== i
);
3824 raw_ptr
= raw_armap
+ LONG_SIZE
;
3825 #endif /* CHECK_ARMAP_HASH */
3827 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3829 unsigned int name_offset
, file_offset
;
3831 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3832 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3833 if (file_offset
== 0)
3835 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3836 symdef_ptr
->file_offset
= file_offset
;
3838 ++ardata
->symdef_count
;
3841 ardata
->first_file_filepos
= bfd_tell (abfd
);
3842 /* Pad to an even boundary. */
3843 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3845 bfd_has_map (abfd
) = true;
3850 /* Write out an armap. */
3853 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3855 unsigned int elength
;
3857 unsigned int orl_count
;
3860 unsigned int hashsize
, hashlog
;
3861 unsigned int symdefsize
;
3863 unsigned int stringsize
;
3864 unsigned int mapsize
;
3867 struct stat statbuf
;
3869 bfd_byte temp
[LONG_SIZE
];
3870 bfd_byte
*hashtable
;
3874 /* Ultrix appears to use as a hash table size the least power of two
3875 greater than twice the number of entries. */
3876 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3878 hashsize
= 1 << hashlog
;
3880 symdefsize
= hashsize
* 2 * LONG_SIZE
;
3882 stringsize
= stridx
+ padit
;
3884 /* Include 8 bytes to store symdefsize and stringsize in output. */
3885 mapsize
= LONG_SIZE
+ symdefsize
+ stringsize
+ LONG_SIZE
;
3887 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3889 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3891 /* Work out the ECOFF armap name. */
3892 strcpy (hdr
.ar_name
, ARMAP_START
);
3893 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3894 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3895 (abfd
->xvec
->header_byteorder_big_p
3897 : ARMAP_LITTLE_ENDIAN
);
3898 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3899 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3900 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3901 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3903 /* Write the timestamp of the archive header to be just a little bit
3904 later than the timestamp of the file, otherwise the linker will
3905 complain that the index is out of date. Actually, the Ultrix
3906 linker just checks the archive name; the GNU linker may check the
3908 stat (abfd
->filename
, &statbuf
);
3909 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3911 /* The DECstation uses zeroes for the uid, gid and mode of the
3913 hdr
.ar_uid
[0] = '0';
3914 hdr
.ar_gid
[0] = '0';
3915 hdr
.ar_mode
[0] = '0';
3917 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3919 hdr
.ar_fmag
[0] = '`';
3920 hdr
.ar_fmag
[1] = '\n';
3922 /* Turn all null bytes in the header into spaces. */
3923 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3924 if (((char *)(&hdr
))[i
] == '\0')
3925 (((char *)(&hdr
))[i
]) = ' ';
3927 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3928 != sizeof (struct ar_hdr
))
3931 bfd_h_put_32 (abfd
, hashsize
, temp
);
3932 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
3935 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3937 current
= abfd
->archive_head
;
3939 for (i
= 0; i
< orl_count
; i
++)
3941 unsigned int hash
, rehash
;
3943 /* Advance firstreal to the file position of this archive
3945 if (((bfd
*) map
[i
].pos
) != last_elt
)
3949 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3950 firstreal
+= firstreal
% 2;
3951 current
= current
->next
;
3953 while (current
!= (bfd
*) map
[i
].pos
);
3958 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3959 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
3960 + (hash
* 2 * LONG_SIZE
)
3966 /* The desired slot is already taken. */
3967 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3969 srch
= (srch
+ rehash
) & (hashsize
- 1))
3970 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
3971 + (srch
* 2 * LONG_SIZE
)
3976 BFD_ASSERT (srch
!= hash
);
3981 bfd_h_put_32 (abfd
, map
[i
].namidx
,
3982 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
));
3983 bfd_h_put_32 (abfd
, firstreal
,
3984 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
+ LONG_SIZE
));
3987 if (bfd_write (hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3990 bfd_release (abfd
, hashtable
);
3992 /* Now write the strings. */
3993 bfd_h_put_32 (abfd
, stringsize
, temp
);
3994 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
3996 for (i
= 0; i
< orl_count
; i
++)
4000 len
= strlen (*map
[i
].name
) + 1;
4001 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
4005 /* The spec sez this should be a newline. But in order to be
4006 bug-compatible for DECstation ar we use a null. */
4009 if (bfd_write ("\0", 1, 1, abfd
) != 1)
4016 /* We just use the generic extended name support. This is a GNU
4018 #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
4020 /* See whether this BFD is an archive. If it is, read in the armap
4021 and the extended name table. */
4024 ecoff_archive_p (abfd
)
4027 char armag
[SARMAG
+ 1];
4029 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
4030 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
4032 bfd_error
= wrong_format
;
4033 return (bfd_target
*) NULL
;
4036 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
4037 involves a cast, we can't do it as the left operand of
4039 abfd
->tdata
.aout_ar_data
=
4040 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
4042 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
4044 bfd_error
= no_memory
;
4045 return (bfd_target
*) NULL
;
4048 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
4050 if (ecoff_slurp_armap (abfd
) == false
4051 || ecoff_slurp_extended_name_table (abfd
) == false)
4053 bfd_release (abfd
, bfd_ardata (abfd
));
4054 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
4055 return (bfd_target
*) NULL
;
4061 /* This is the COFF backend structure. The backend_data field of the
4062 bfd_target structure is set to this. The section reading code in
4063 coffgen.c uses this structure. */
4065 static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table
= {
4066 (void (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_in */
4067 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_in */
4068 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_in */
4069 (unsigned (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_out */
4070 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_out */
4071 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_out */
4072 ecoff_swap_reloc_out
, ecoff_swap_filehdr_out
, ecoff_swap_aouthdr_out
,
4073 ecoff_swap_scnhdr_out
,
4074 FILHSZ
, AOUTSZ
, SCNHSZ
, 0, 0, 0, true,
4075 ecoff_swap_filehdr_in
, ecoff_swap_aouthdr_in
, ecoff_swap_scnhdr_in
,
4076 ecoff_bad_format_hook
, ecoff_set_arch_mach_hook
, ecoff_mkobject_hook
,
4077 ecoff_styp_to_sec_flags
, ecoff_make_section_hook
, ecoff_set_alignment_hook
,
4078 ecoff_slurp_symbol_table
4081 /* get_lineno could be written for ECOFF, but it would currently only
4082 be useful for linking ECOFF and COFF files together, which doesn't
4084 #define ecoff_get_lineno \
4085 ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr)
4087 /* These bfd_target functions are defined in other files. */
4089 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
4090 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
4091 #define ecoff_core_file_matches_executable_p \
4092 _bfd_dummy_core_file_matches_executable_p
4093 #define ecoff_truncate_arname bfd_dont_truncate_arname
4094 #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file
4095 #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
4096 #define ecoff_get_section_contents bfd_generic_get_section_contents
4097 #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4098 #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup
4099 #define ecoff_bfd_debug_info_start bfd_void
4100 #define ecoff_bfd_debug_info_end bfd_void
4101 #define ecoff_bfd_debug_info_accumulate \
4102 ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void)
4103 #define ecoff_bfd_get_relocated_section_contents \
4104 bfd_generic_get_relocated_section_contents
4105 #define ecoff_bfd_relax_section bfd_generic_relax_section
4106 #define ecoff_bfd_make_debug_symbol \
4107 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
4109 bfd_target ecoff_little_vec
=
4111 "ecoff-littlemips", /* name */
4112 bfd_target_ecoff_flavour
,
4113 false, /* data byte order is little */
4114 false, /* header byte order is little */
4116 (HAS_RELOC
| EXEC_P
| /* object flags */
4117 HAS_LINENO
| HAS_DEBUG
|
4118 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
),
4120 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect
4122 0, /* leading underscore */
4123 '/', /* ar_pad_char */
4124 15, /* ar_max_namelen */
4125 3, /* minimum alignment power */
4126 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* data */
4127 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* hdrs */
4129 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
4130 ecoff_archive_p
, _bfd_dummy_target
},
4131 {bfd_false
, ecoff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
4133 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
4134 _bfd_write_archive_contents
, bfd_false
},
4136 (PTR
) &bfd_ecoff_std_swap_table
4139 bfd_target ecoff_big_vec
=
4141 "ecoff-bigmips", /* name */
4142 bfd_target_ecoff_flavour
,
4143 true, /* data byte order is big */
4144 true, /* header byte order is big */
4146 (HAS_RELOC
| EXEC_P
| /* object flags */
4147 HAS_LINENO
| HAS_DEBUG
|
4148 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
),
4150 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect flags */
4151 0, /* leading underscore */
4152 ' ', /* ar_pad_char */
4153 16, /* ar_max_namelen */
4154 3, /* minimum alignment power */
4155 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
,
4156 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
,
4157 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
4158 ecoff_archive_p
, _bfd_dummy_target
},
4159 {bfd_false
, ecoff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
4161 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
4162 _bfd_write_archive_contents
, bfd_false
},
4164 (PTR
) &bfd_ecoff_std_swap_table
4165 /* Note that there is another bfd_target just above this one. If
4166 you are adding initializers here, you should be adding them there