1 /* BFD back-end for Alpha Extended-Coff files.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 Original version by Per Bothner
5 Full support added by Ian Lance Taylor, ian@cygnus.com.
7 Modified from MIPS version by Steve Chamberlain (sac@cygnus.com)
10 This file is part of BFD, the Binary File Descriptor library.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
31 #include "aout/ranlib.h"
32 #include "coff/alpha.h"
33 #include "coff/internal.h"
35 #include "coff/symconst.h"
36 #include "coff/ecoff-ext.h"
40 /* Each canonical asymbol really looks like this. */
42 typedef struct ecoff_symbol_struct
44 /* The actual symbol which the rest of BFD works with */
47 /* The fdr for this symbol. */
50 /* true if this is a local symbol rather than an external one. */
53 /* A pointer to the unswapped hidden information for this symbol */
56 struct sym_ext
*lnative
;
57 struct ext_ext
*enative
;
62 /* We take the address of the first element of a asymbol to ensure that the
63 macro is only ever applied to an asymbol. */
64 #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd)))
66 /* The page boundary used to align sections in the executable file. */
67 #define ROUND_SIZE 0x10000
69 /* The linker needs a section to hold small common variables while
70 linking. There is no convenient way to create it when the linker
71 needs it, so we always create one for each BFD. We then avoid
73 #define SCOMMON ".scommon"
75 /* Alpha ECOFF has COFF sections, but the debugging information is
76 stored in a completely different format. This files uses the some
77 of the swapping routines from coffswap.h, and some of the generic
78 COFF routines in coffgen.c, but, unlike the real COFF targets, does
79 not use coffcode.h itself. */
81 /* Prototypes for static functions. */
83 static boolean ecoff_bad_format_hook
PARAMS ((bfd
*abfd
, PTR filehdr
));
84 static asection
*ecoff_make_section_hook
PARAMS ((bfd
*abfd
, char *name
));
85 static boolean ecoff_new_section_hook
PARAMS ((bfd
*abfd
, asection
*section
));
86 static boolean ecoff_mkobject
PARAMS ((bfd
*abfd
));
87 static PTR ecoff_mkobject_hook
PARAMS ((bfd
*abfd
, PTR filehdr
, PTR aouthdr
));
88 static boolean ecoff_set_arch_mach_hook
PARAMS ((bfd
*abfd
, PTR filehdr
));
89 static long ecoff_sec_to_styp_flags
PARAMS ((CONST
char *name
,
91 static flagword ecoff_styp_to_sec_flags
PARAMS ((bfd
*abfd
, PTR hdr
));
92 static asymbol
*ecoff_make_empty_symbol
PARAMS ((bfd
*abfd
));
93 static void ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
94 asymbol
*asym
, int ext
));
95 static boolean ecoff_slurp_symbol_table
PARAMS ((bfd
*abfd
));
96 static unsigned int ecoff_get_symtab_upper_bound
PARAMS ((bfd
*abfd
));
97 static unsigned int ecoff_get_symtab
PARAMS ((bfd
*abfd
,
98 asymbol
**alocation
));
99 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, char *string
,
100 RNDXR
*rndx
, long isym
,
102 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, union aux_ext
*aux_ptr
,
103 int indx
, int bigendian
));
104 static void ecoff_print_symbol
PARAMS ((bfd
*abfd
, PTR filep
,
106 bfd_print_symbol_type how
));
107 static void ecoff_swap_reloc_in
PARAMS ((bfd
*abfd
, RELOC
*ext
,
108 struct internal_reloc
*intern
));
109 static unsigned int ecoff_swap_reloc_out
PARAMS ((bfd
*abfd
, PTR src
,
111 static bfd_reloc_status_type ecoff_generic_reloc
PARAMS ((bfd
*abfd
,
117 static bfd_reloc_status_type ecoff_refhi_reloc
PARAMS ((bfd
*abfd
,
123 static bfd_reloc_status_type ecoff_reflo_reloc
PARAMS ((bfd
*abfd
,
129 static bfd_reloc_status_type ecoff_gprel_reloc
PARAMS ((bfd
*abfd
,
135 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
137 static unsigned int ecoff_canonicalize_reloc
PARAMS ((bfd
*abfd
,
141 static CONST
struct reloc_howto_struct
*ecoff_bfd_reloc_type_lookup
142 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
143 static boolean ecoff_find_nearest_line
PARAMS ((bfd
*abfd
,
147 CONST
char **filename_ptr
,
148 CONST
char **fnname_ptr
,
149 unsigned int *retline_ptr
));
150 static void ecoff_clear_output_flags
PARAMS ((bfd
*abfd
));
151 static boolean ecoff_rel
PARAMS ((bfd
*output_bfd
, bfd_seclet_type
*seclet
,
152 asection
*output_section
, PTR data
,
153 boolean relocateable
));
154 static boolean ecoff_dump_seclet
PARAMS ((bfd
*abfd
, bfd_seclet_type
*seclet
,
155 asection
*section
, PTR data
,
156 boolean relocateable
));
157 static long ecoff_add_string
PARAMS ((bfd
*output_bfd
, FDR
*fdr
,
158 CONST
char *string
, boolean external
));
159 static boolean ecoff_get_debug
PARAMS ((bfd
*output_bfd
,
160 bfd_seclet_type
*seclet
,
162 boolean relocateable
));
163 static boolean ecoff_bfd_seclet_link
PARAMS ((bfd
*abfd
, PTR data
,
164 boolean relocateable
));
165 static boolean ecoff_set_arch_mach
PARAMS ((bfd
*abfd
,
166 enum bfd_architecture arch
,
167 unsigned long machine
));
168 static int ecoff_sizeof_headers
PARAMS ((bfd
*abfd
, boolean reloc
));
169 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
170 static boolean ecoff_set_section_contents
PARAMS ((bfd
*abfd
,
174 bfd_size_type count
));
175 static boolean ecoff_write_object_contents
PARAMS ((bfd
*abfd
));
176 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
177 unsigned int *rehash
,
180 static boolean ecoff_slurp_armap
PARAMS ((bfd
*abfd
));
181 static boolean ecoff_write_armap
PARAMS ((bfd
*abfd
, unsigned int elength
,
183 unsigned int orl_count
,
185 static bfd_target
*ecoff_archive_p
PARAMS ((bfd
*abfd
));
187 /* Get the generic COFF swapping routines, except for the reloc,
188 symbol, and lineno ones. Give them ecoff names. */
190 #define NO_COFF_RELOCS
191 #define NO_COFF_SYMBOLS
192 #define NO_COFF_LINENOS
193 #define coff_swap_filehdr_in ecoff_swap_filehdr_in
194 #define coff_swap_filehdr_out ecoff_swap_filehdr_out
195 #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in
196 #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out
197 #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in
198 #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out
199 #include "coffswap.h"
201 /* This stuff is somewhat copied from coffcode.h. */
203 static asection bfd_debug_section
= { "*DEBUG*" };
205 /* See whether the magic number matches. */
208 ecoff_bad_format_hook (abfd
, filehdr
)
212 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
214 if (ECOFFBADMAG (*internal_f
))
220 /* This is a hook needed by SCO COFF, but we have nothing to do. */
223 ecoff_make_section_hook (abfd
, name
)
227 return (asection
*) NULL
;
230 /* Initialize a new section. */
233 ecoff_new_section_hook (abfd
, section
)
237 section
->alignment_power
= abfd
->xvec
->align_power_min
;
239 if (strcmp (section
->name
, _TEXT
) == 0)
240 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
241 else if (strcmp (section
->name
, _DATA
) == 0
242 || strcmp (section
->name
, _SDATA
) == 0)
243 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
244 else if (strcmp (section
->name
, _RDATA
) == 0
245 || strcmp (section
->name
, _LIT8
) == 0
246 || strcmp (section
->name
, _LIT4
) == 0)
247 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
248 else if (strcmp (section
->name
, _BSS
) == 0
249 || strcmp (section
->name
, _SBSS
) == 0)
250 section
->flags
|= SEC_ALLOC
;
252 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
253 uncertain about .init on some systems and I don't know how shared
259 /* Set the alignment of a section; we have nothing to do. */
261 #define ecoff_set_alignment_hook \
262 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
264 /* Create an ECOFF object. */
267 ecoff_mkobject (abfd
)
270 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
271 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
272 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
274 bfd_error
= no_memory
;
278 /* Always create a .scommon section for every BFD. This is a hack so
279 that the linker has something to attach scSCommon symbols to. */
280 bfd_make_section (abfd
, SCOMMON
);
285 /* Create the ECOFF backend specific information. */
288 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
293 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
294 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
295 ecoff_data_type
*ecoff
;
297 if (ecoff_mkobject (abfd
) == false)
300 ecoff
= ecoff_data (abfd
);
302 ecoff
->sym_filepos
= internal_f
->f_symptr
;
304 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
308 ecoff
->text_start
= internal_a
->text_start
;
309 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
310 ecoff
->gp
= internal_a
->gp_value
;
311 ecoff
->gprmask
= internal_a
->gprmask
;
312 for (i
= 0; i
< 4; i
++)
313 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
319 /* Determine the machine architecture and type. */
322 ecoff_set_arch_mach_hook (abfd
, filehdr
)
326 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
327 enum bfd_architecture arch
;
329 switch (internal_f
->f_magic
)
332 arch
= bfd_arch_alpha
;
336 arch
= bfd_arch_obscure
;
340 bfd_default_set_arch_mach (abfd
, arch
, (unsigned long) 0);
345 /* Get the section s_flags to use for a section. */
348 ecoff_sec_to_styp_flags (name
, flags
)
356 if (strcmp (name
, _TEXT
) == 0)
358 else if (strcmp (name
, _DATA
) == 0)
360 else if (strcmp (name
, _SDATA
) == 0)
362 else if (strcmp (name
, _RDATA
) == 0)
364 else if (strcmp (name
, _LIT8
) == 0)
366 else if (strcmp (name
, _LIT4
) == 0)
368 else if (strcmp (name
, _BSS
) == 0)
370 else if (strcmp (name
, _SBSS
) == 0)
372 else if (flags
& SEC_CODE
)
374 else if (flags
& SEC_DATA
)
376 else if (flags
& SEC_READONLY
)
378 else if (flags
& SEC_LOAD
)
383 if (flags
& SEC_NEVER_LOAD
)
389 /* Get the BFD flags to use for a section. */
392 ecoff_styp_to_sec_flags (abfd
, hdr
)
396 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
397 long styp_flags
= internal_s
->s_flags
;
398 flagword sec_flags
=0;
400 if (styp_flags
& STYP_NOLOAD
)
401 sec_flags
|= SEC_NEVER_LOAD
;
403 /* For 386 COFF, at least, an unloadable text or data section is
404 actually a shared library section. */
405 if (styp_flags
& STYP_TEXT
)
407 if (sec_flags
& SEC_NEVER_LOAD
)
408 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
410 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
412 else if ((styp_flags
& STYP_DATA
)
413 || (styp_flags
& STYP_RDATA
)
414 || (styp_flags
& STYP_SDATA
))
416 if (sec_flags
& SEC_NEVER_LOAD
)
417 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
419 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
420 if (styp_flags
& STYP_RDATA
)
421 sec_flags
|= SEC_READONLY
;
423 else if ((styp_flags
& STYP_BSS
)
424 || (styp_flags
& STYP_SBSS
))
426 sec_flags
|= SEC_ALLOC
;
428 else if (styp_flags
& STYP_INFO
)
430 sec_flags
|= SEC_NEVER_LOAD
;
432 else if ((styp_flags
& STYP_LIT8
)
433 || (styp_flags
& STYP_LIT4
))
435 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
439 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
445 /* Read in and swap the important symbolic information for an ECOFF
446 object file. FIXME: This is called by gdb. If there is ever
447 another ECOFF target, it should be moved into some sort of target
448 specific structure. */
451 ecoff_slurp_symbolic_info (abfd
)
454 struct hdr_ext external_symhdr
;
455 HDRR
*internal_symhdr
;
456 bfd_size_type raw_base
;
457 bfd_size_type raw_size
;
459 struct fdr_ext
*fraw_src
;
460 struct fdr_ext
*fraw_end
;
463 /* Check whether we've already gotten it, and whether there's any to
465 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
467 if (ecoff_data (abfd
)->sym_filepos
== 0)
469 bfd_get_symcount (abfd
) = 0;
473 /* At this point bfd_get_symcount (abfd) holds the number of symbols
474 as read from the file header, but on ECOFF this is always the
475 size of the symbolic information header. It would be cleaner to
476 handle this when we first read the file in coffgen.c. */
477 if (bfd_get_symcount (abfd
) != sizeof (external_symhdr
))
479 bfd_error
= bad_value
;
483 /* Read the symbolic information header. */
484 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
485 || (bfd_read ((PTR
) &external_symhdr
, sizeof (external_symhdr
), 1, abfd
)
486 != sizeof (external_symhdr
)))
488 bfd_error
= system_call_error
;
491 internal_symhdr
= &ecoff_data (abfd
)->symbolic_header
;
492 ecoff_swap_hdr_in (abfd
, &external_symhdr
, internal_symhdr
);
494 if (internal_symhdr
->magic
!= magicSym
)
496 bfd_error
= bad_value
;
500 /* Now we can get the correct number of symbols. */
501 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
502 + internal_symhdr
->iextMax
);
504 /* Read all the symbolic information at once. */
505 raw_base
= ecoff_data (abfd
)->sym_filepos
+ sizeof (struct hdr_ext
);
507 if (internal_symhdr
->cbExtOffset
!= 0)
508 raw_size
= (internal_symhdr
->cbExtOffset
510 + internal_symhdr
->iextMax
* sizeof (struct ext_ext
));
513 long cbline
, issmax
, issextmax
;
515 cbline
= (internal_symhdr
->cbLine
+ 3) &~ 3;
516 issmax
= (internal_symhdr
->issMax
+ 3) &~ 3;
517 issextmax
= (internal_symhdr
->issExtMax
+ 3) &~ 3;
518 raw_size
= (cbline
* sizeof (unsigned char)
519 + internal_symhdr
->idnMax
* sizeof (struct dnr_ext
)
520 + internal_symhdr
->ipdMax
* sizeof (struct pdr_ext
)
521 + internal_symhdr
->isymMax
* sizeof (struct sym_ext
)
522 + internal_symhdr
->ioptMax
* sizeof (struct opt_ext
)
523 + internal_symhdr
->iauxMax
* sizeof (union aux_ext
)
524 + issmax
* sizeof (char)
525 + issextmax
* sizeof (char)
526 + internal_symhdr
->ifdMax
* sizeof (struct fdr_ext
)
527 + internal_symhdr
->crfd
* sizeof (struct rfd_ext
)
528 + internal_symhdr
->iextMax
* sizeof (struct ext_ext
));
533 ecoff_data (abfd
)->sym_filepos
= 0;
536 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
539 bfd_error
= no_memory
;
542 if (bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
544 bfd_error
= system_call_error
;
545 bfd_release (abfd
, raw
);
549 ecoff_data (abfd
)->raw_size
= raw_size
;
550 ecoff_data (abfd
)->raw_syments
= raw
;
552 /* Get pointers for the numeric offsets in the HDRR structure. */
553 #define FIX(off1, off2, type) \
554 if (internal_symhdr->off1 == 0) \
555 ecoff_data (abfd)->off2 = (type *) NULL; \
557 ecoff_data (abfd)->off2 = (type *) ((char *) raw \
558 + internal_symhdr->off1 \
560 FIX (cbLineOffset
, line
, unsigned char);
561 FIX (cbDnOffset
, external_dnr
, struct dnr_ext
);
562 FIX (cbPdOffset
, external_pdr
, struct pdr_ext
);
563 FIX (cbSymOffset
, external_sym
, struct sym_ext
);
564 FIX (cbOptOffset
, external_opt
, struct opt_ext
);
565 FIX (cbAuxOffset
, external_aux
, union aux_ext
);
566 FIX (cbSsOffset
, ss
, char);
567 FIX (cbSsExtOffset
, ssext
, char);
568 FIX (cbFdOffset
, external_fdr
, struct fdr_ext
);
569 FIX (cbRfdOffset
, external_rfd
, struct rfd_ext
);
570 FIX (cbExtOffset
, external_ext
, struct ext_ext
);
573 /* I don't want to always swap all the data, because it will just
574 waste time and most programs will never look at it. The only
575 time the linker needs most of the debugging information swapped
576 is when linking big-endian and little-endian MIPS object files
577 together, which is not a common occurrence.
579 We need to look at the fdr to deal with a lot of information in
580 the symbols, so we swap them here. */
581 ecoff_data (abfd
)->fdr
= (struct fdr
*) bfd_alloc (abfd
,
582 (internal_symhdr
->ifdMax
*
583 sizeof (struct fdr
)));
584 if (ecoff_data (abfd
)->fdr
== NULL
)
586 bfd_error
= no_memory
;
589 fdr_ptr
= ecoff_data (abfd
)->fdr
;
590 fraw_src
= ecoff_data (abfd
)->external_fdr
;
591 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
;
592 for (; fraw_src
< fraw_end
; fraw_src
++, fdr_ptr
++)
593 ecoff_swap_fdr_in (abfd
, fraw_src
, fdr_ptr
);
598 /* ECOFF symbol table routines. The ECOFF symbol table is described
599 in gcc/mips-tfile.c. */
601 /* ECOFF uses two common sections. One is the usual one, and the
602 other is for small objects. All the small objects are kept
603 together, and then referenced via the gp pointer, which yields
604 faster assembler code. This is what we use for the small common
606 static asection ecoff_scom_section
;
607 static asymbol ecoff_scom_symbol
;
608 static asymbol
*ecoff_scom_symbol_ptr
;
610 /* Create an empty symbol. */
613 ecoff_make_empty_symbol (abfd
)
616 ecoff_symbol_type
*new;
618 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
619 if (new == (ecoff_symbol_type
*) NULL
)
621 bfd_error
= no_memory
;
622 return (asymbol
*) NULL
;
624 memset (new, 0, sizeof *new);
625 new->symbol
.section
= (asection
*) NULL
;
626 new->fdr
= (FDR
*) NULL
;
628 new->native
.lnative
= (struct sym_ext
*) NULL
;
629 new->symbol
.the_bfd
= abfd
;
633 /* Set the BFD flags and section for an ECOFF symbol. */
636 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
)
642 asym
->the_bfd
= abfd
;
643 asym
->value
= ecoff_sym
->value
;
644 asym
->section
= &bfd_debug_section
;
647 /* Most symbol types are just for debugging. */
648 switch (ecoff_sym
->st
)
657 if (MIPS_IS_STAB (ecoff_sym
))
659 asym
->flags
= BSF_DEBUGGING
;
664 asym
->flags
= BSF_DEBUGGING
;
669 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
671 asym
->flags
= BSF_LOCAL
;
672 switch (ecoff_sym
->sc
)
675 /* Used for compiler generated labels. Leave them in the
676 debugging section, and mark them as local. If BSF_DEBUGGING
677 is set, then nm does not display them for some reason. If no
678 flags are set then the linker whines about them. */
679 asym
->flags
= BSF_LOCAL
;
682 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
683 asym
->value
-= asym
->section
->vma
;
686 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
687 asym
->value
-= asym
->section
->vma
;
692 asym
->section
= &bfd_com_section
;
697 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
698 asym
->value
-= asym
->section
->vma
;
702 asym
->flags
= BSF_DEBUGGING
;
705 asym
->section
= &bfd_abs_section
;
708 asym
->section
= &bfd_und_section
;
718 asym
->flags
= BSF_DEBUGGING
;
721 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
722 asym
->value
-= asym
->section
->vma
;
725 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
727 asym
->value
-= asym
->section
->vma
;
730 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
731 asym
->value
-= asym
->section
->vma
;
734 asym
->flags
= BSF_DEBUGGING
;
737 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
739 asym
->section
= &bfd_com_section
;
745 if (ecoff_scom_section
.name
== NULL
)
747 /* Initialize the small common section. */
748 ecoff_scom_section
.name
= SCOMMON
;
749 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
750 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
751 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
752 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
753 ecoff_scom_symbol
.name
= SCOMMON
;
754 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
755 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
756 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
758 asym
->section
= &ecoff_scom_section
;
763 asym
->flags
= BSF_DEBUGGING
;
766 asym
->section
= &bfd_und_section
;
771 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
772 asym
->value
-= asym
->section
->vma
;
777 asym
->flags
= BSF_DEBUGGING
;
780 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
781 asym
->value
-= asym
->section
->vma
;
788 /* Read an ECOFF symbol table. */
791 ecoff_slurp_symbol_table (abfd
)
794 bfd_size_type internal_size
;
795 ecoff_symbol_type
*internal
;
796 ecoff_symbol_type
*internal_ptr
;
797 struct ext_ext
*eraw_src
;
798 struct ext_ext
*eraw_end
;
802 /* If we've already read in the symbol table, do nothing. */
803 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
806 /* Get the symbolic information. */
807 if (ecoff_slurp_symbolic_info (abfd
) == false)
809 if (bfd_get_symcount (abfd
) == 0)
812 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
813 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
814 if (internal
== NULL
)
816 bfd_error
= no_memory
;
820 internal_ptr
= internal
;
821 eraw_src
= ecoff_data (abfd
)->external_ext
;
822 eraw_end
= eraw_src
+ ecoff_data (abfd
)->symbolic_header
.iextMax
;
823 for (; eraw_src
< eraw_end
; eraw_src
++, internal_ptr
++)
827 ecoff_swap_ext_in (abfd
, eraw_src
, &internal_esym
);
828 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ssext
829 + internal_esym
.asym
.iss
);
830 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
831 &internal_ptr
->symbol
, 1);
832 internal_ptr
->fdr
= ecoff_data (abfd
)->fdr
+ internal_esym
.ifd
;
833 internal_ptr
->local
= false;
834 internal_ptr
->native
.enative
= eraw_src
;
837 /* The local symbols must be accessed via the fdr's, because the
838 string and aux indices are relative to the fdr information. */
839 fdr_ptr
= ecoff_data (abfd
)->fdr
;
840 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
841 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
843 struct sym_ext
*lraw_src
;
844 struct sym_ext
*lraw_end
;
846 lraw_src
= ecoff_data (abfd
)->external_sym
+ fdr_ptr
->isymBase
;
847 lraw_end
= lraw_src
+ fdr_ptr
->csym
;
848 for (; lraw_src
< lraw_end
; lraw_src
++, internal_ptr
++)
852 ecoff_swap_sym_in (abfd
, lraw_src
, &internal_sym
);
853 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->ss
856 ecoff_set_symbol_info (abfd
, &internal_sym
,
857 &internal_ptr
->symbol
, 0);
858 internal_ptr
->fdr
= fdr_ptr
;
859 internal_ptr
->local
= true;
860 internal_ptr
->native
.lnative
= lraw_src
;
864 ecoff_data (abfd
)->canonical_symbols
= internal
;
870 ecoff_get_symtab_upper_bound (abfd
)
873 if (ecoff_slurp_symbolic_info (abfd
) == false
874 || bfd_get_symcount (abfd
) == 0)
877 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
881 ecoff_get_symtab (abfd
, alocation
)
885 unsigned int counter
= 0;
886 ecoff_symbol_type
*symbase
;
887 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
889 if (ecoff_slurp_symbol_table (abfd
) == false
890 || bfd_get_symcount (abfd
) == 0)
893 symbase
= ecoff_data (abfd
)->canonical_symbols
;
894 while (counter
< bfd_get_symcount (abfd
))
896 *(location
++) = symbase
++;
899 *location
++ = (ecoff_symbol_type
*) NULL
;
900 return bfd_get_symcount (abfd
);
903 /* Turn ECOFF type information into a printable string.
904 ecoff_emit_aggregate and ecoff_type_to_string are from
905 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
907 /* Write aggregate information to a string. */
910 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
918 int indx
= rndx
->index
;
919 int sym_base
, ss_base
;
925 sym_base
= ecoff_data (abfd
)->fdr
[ifd
].isymBase
;
926 ss_base
= ecoff_data (abfd
)->fdr
[ifd
].issBase
;
928 if (indx
== indexNil
)
929 name
= "/* no name */";
935 ecoff_swap_sym_in (abfd
,
936 ecoff_data (abfd
)->external_sym
+ indx
,
938 name
= ecoff_data (abfd
)->ss
+ ss_base
+ sym
.iss
;
942 "%s %s { ifd = %d, index = %d }",
944 indx
+ ecoff_data (abfd
)->symbolic_header
.iextMax
);
947 /* Convert the type information to string format. */
950 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
952 union aux_ext
*aux_ptr
;
964 unsigned int basic_type
;
966 static char buffer1
[1024];
967 static char buffer2
[1024];
972 for (i
= 0; i
< 7; i
++)
974 qualifiers
[i
].low_bound
= 0;
975 qualifiers
[i
].high_bound
= 0;
976 qualifiers
[i
].stride
= 0;
979 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
980 return "-1 (no type)";
981 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
983 basic_type
= u
.ti
.bt
;
984 qualifiers
[0].type
= u
.ti
.tq0
;
985 qualifiers
[1].type
= u
.ti
.tq1
;
986 qualifiers
[2].type
= u
.ti
.tq2
;
987 qualifiers
[3].type
= u
.ti
.tq3
;
988 qualifiers
[4].type
= u
.ti
.tq4
;
989 qualifiers
[5].type
= u
.ti
.tq5
;
990 qualifiers
[6].type
= tqNil
;
993 * Go get the basic type.
997 case btNil
: /* undefined */
1001 case btAdr
: /* address - integer same size as pointer */
1002 strcpy (p1
, "address");
1005 case btChar
: /* character */
1006 strcpy (p1
, "char");
1009 case btUChar
: /* unsigned character */
1010 strcpy (p1
, "unsigned char");
1013 case btShort
: /* short */
1014 strcpy (p1
, "short");
1017 case btUShort
: /* unsigned short */
1018 strcpy (p1
, "unsigned short");
1021 case btInt
: /* int */
1025 case btUInt
: /* unsigned int */
1026 strcpy (p1
, "unsigned int");
1029 case btLong
: /* long */
1030 strcpy (p1
, "long");
1033 case btULong
: /* unsigned long */
1034 strcpy (p1
, "unsigned long");
1037 case btFloat
: /* float (real) */
1038 strcpy (p1
, "float");
1041 case btDouble
: /* Double (real) */
1042 strcpy (p1
, "double");
1045 /* Structures add 1-2 aux words:
1046 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1047 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1049 case btStruct
: /* Structure (Record) */
1050 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1051 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1052 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1054 indx
++; /* skip aux words */
1057 /* Unions add 1-2 aux words:
1058 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1059 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1061 case btUnion
: /* Union */
1062 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1063 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1064 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1066 indx
++; /* skip aux words */
1069 /* Enumerations add 1-2 aux words:
1070 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1071 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1073 case btEnum
: /* Enumeration */
1074 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1075 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1076 AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1078 indx
++; /* skip aux words */
1081 case btTypedef
: /* defined via a typedef, isymRef points */
1082 strcpy (p1
, "typedef");
1085 case btRange
: /* subrange of int */
1086 strcpy (p1
, "subrange");
1089 case btSet
: /* pascal sets */
1093 case btComplex
: /* fortran complex */
1094 strcpy (p1
, "complex");
1097 case btDComplex
: /* fortran double complex */
1098 strcpy (p1
, "double complex");
1101 case btIndirect
: /* forward or unnamed typedef */
1102 strcpy (p1
, "forward/unamed typedef");
1105 case btFixedDec
: /* Fixed Decimal */
1106 strcpy (p1
, "fixed decimal");
1109 case btFloatDec
: /* Float Decimal */
1110 strcpy (p1
, "float decimal");
1113 case btString
: /* Varying Length Character String */
1114 strcpy (p1
, "string");
1117 case btBit
: /* Aligned Bit String */
1121 case btPicture
: /* Picture */
1122 strcpy (p1
, "picture");
1125 case btVoid
: /* Void */
1126 strcpy (p1
, "void");
1130 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1134 p1
+= strlen (buffer1
);
1137 * If this is a bitfield, get the bitsize.
1143 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1144 sprintf (p1
, " : %d", bitsize
);
1145 p1
+= strlen (buffer1
);
1150 * Deal with any qualifiers.
1152 if (qualifiers
[0].type
!= tqNil
)
1155 * Snarf up any array bounds in the correct order. Arrays
1156 * store 5 successive words in the aux. table:
1157 * word 0 RNDXR to type of the bounds (ie, int)
1158 * word 1 Current file descriptor index
1160 * word 3 high bound (or -1 if [])
1161 * word 4 stride size in bits
1163 for (i
= 0; i
< 7; i
++)
1165 if (qualifiers
[i
].type
== tqArray
)
1167 qualifiers
[i
].low_bound
=
1168 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1169 qualifiers
[i
].high_bound
=
1170 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1171 qualifiers
[i
].stride
=
1172 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1178 * Now print out the qualifiers.
1180 for (i
= 0; i
< 6; i
++)
1182 switch (qualifiers
[i
].type
)
1189 strcpy (p2
, "ptr to ");
1190 p2
+= sizeof ("ptr to ")-1;
1194 strcpy (p2
, "volatile ");
1195 p2
+= sizeof ("volatile ")-1;
1199 strcpy (p2
, "far ");
1200 p2
+= sizeof ("far ")-1;
1204 strcpy (p2
, "func. ret. ");
1205 p2
+= sizeof ("func. ret. ");
1210 int first_array
= i
;
1213 /* Print array bounds reversed (ie, in the order the C
1214 programmer writes them). C is such a fun language.... */
1216 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1219 for (j
= i
; j
>= first_array
; j
--)
1221 strcpy (p2
, "array [");
1222 p2
+= sizeof ("array [")-1;
1223 if (qualifiers
[j
].low_bound
!= 0)
1225 "%ld:%ld {%ld bits}",
1226 (long) qualifiers
[j
].low_bound
,
1227 (long) qualifiers
[j
].high_bound
,
1228 (long) qualifiers
[j
].stride
);
1230 else if (qualifiers
[j
].high_bound
!= -1)
1233 (long) (qualifiers
[j
].high_bound
+ 1),
1234 (long) (qualifiers
[j
].stride
));
1237 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1240 strcpy (p2
, "] of ");
1241 p2
+= sizeof ("] of ")-1;
1249 strcpy (p2
, buffer1
);
1253 /* Print information about an ECOFF symbol. */
1256 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1260 bfd_print_symbol_type how
;
1262 FILE *file
= (FILE *)filep
;
1266 case bfd_print_symbol_name
:
1267 fprintf (file
, "%s", symbol
->name
);
1269 case bfd_print_symbol_more
:
1270 if (ecoffsymbol (symbol
)->local
)
1274 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1276 fprintf (file
, "ecoff local %lx %x %x",
1277 (unsigned long) ecoff_sym
.value
,
1278 (unsigned) ecoff_sym
.st
, (unsigned) ecoff_sym
.sc
);
1284 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1286 fprintf (file
, "ecoff extern %lx %x %x",
1287 (unsigned long) ecoff_ext
.asym
.value
,
1288 (unsigned) ecoff_ext
.asym
.st
,
1289 (unsigned) ecoff_ext
.asym
.sc
);
1292 case bfd_print_symbol_nm
:
1294 CONST
char *section_name
= symbol
->section
->name
;
1296 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
1297 fprintf (file
, " %-5s %s %s",
1299 ecoffsymbol (symbol
)->local
? "l" : "e",
1303 case bfd_print_symbol_all
:
1304 /* Print out the symbols in a reasonable way */
1313 if (ecoffsymbol (symbol
)->local
)
1315 ecoff_swap_sym_in (abfd
, ecoffsymbol (symbol
)->native
.lnative
,
1318 pos
= (ecoffsymbol (symbol
)->native
.lnative
1319 - ecoff_data (abfd
)->external_sym
1320 + ecoff_data (abfd
)->symbolic_header
.iextMax
);
1327 ecoff_swap_ext_in (abfd
, ecoffsymbol (symbol
)->native
.enative
,
1330 pos
= (ecoffsymbol (symbol
)->native
.enative
1331 - ecoff_data (abfd
)->external_ext
);
1332 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1333 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1334 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1337 fprintf (file
, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s",
1338 pos
, type
, (unsigned long) ecoff_ext
.asym
.value
,
1339 (unsigned) ecoff_ext
.asym
.st
,
1340 (unsigned) ecoff_ext
.asym
.sc
,
1341 (unsigned) ecoff_ext
.asym
.index
,
1342 jmptbl
, cobol_main
, weakext
,
1345 if (ecoffsymbol (symbol
)->fdr
!= NULL
1346 && ecoff_ext
.asym
.index
!= indexNil
)
1351 union aux_ext
*aux_base
;
1353 indx
= ecoff_ext
.asym
.index
;
1355 /* sym_base is used to map the fdr relative indices which
1356 appear in the file to the position number which we are
1358 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1359 if (ecoffsymbol (symbol
)->local
)
1360 sym_base
+= ecoff_data (abfd
)->symbolic_header
.iextMax
;
1362 /* aux_base is the start of the aux entries for this file;
1363 asym.index is an offset from this. */
1364 aux_base
= (ecoff_data (abfd
)->external_aux
1365 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1367 /* The aux entries are stored in host byte order; the
1368 order is indicated by a bit in the fdr. */
1369 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1371 /* This switch is basically from gcc/mips-tdump.c */
1372 switch (ecoff_ext
.asym
.st
)
1380 printf ("\n End+1 symbol: %ld", indx
+ sym_base
);
1384 if (ecoff_ext
.asym
.sc
== scText
1385 || ecoff_ext
.asym
.sc
== scInfo
)
1386 printf ("\n First symbol: %ld", indx
+ sym_base
);
1388 printf ("\n First symbol: %ld",
1389 (AUX_GET_ISYM (bigendian
,
1390 &aux_base
[ecoff_ext
.asym
.index
])
1396 if (MIPS_IS_STAB (&ecoff_ext
.asym
))
1398 else if (ecoffsymbol (symbol
)->local
)
1399 printf ("\n End+1 symbol: %-7ld Type: %s",
1400 (AUX_GET_ISYM (bigendian
,
1401 &aux_base
[ecoff_ext
.asym
.index
])
1403 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1406 printf ("\n Local symbol: %d",
1409 + ecoff_data (abfd
)->symbolic_header
.iextMax
));
1413 if (!MIPS_IS_STAB (&ecoff_ext
.asym
))
1414 printf ("\n Type: %s",
1415 ecoff_type_to_string (abfd
, aux_base
, indx
,
1425 /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in
1426 external form. They use a bit which indicates whether the symbol
1429 /* Swap a reloc in. */
1432 ecoff_swap_reloc_in (abfd
, ext
, intern
)
1435 struct internal_reloc
*intern
;
1437 intern
->r_vaddr
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->r_vaddr
);
1438 if (abfd
->xvec
->header_byteorder_big_p
!= false)
1440 intern
->r_symndx
= (((int) ext
->r_bits
[0]
1441 << RELOC_BITS0_SYMNDX_SH_LEFT_BIG
)
1442 | ((int) ext
->r_bits
[1]
1443 << RELOC_BITS1_SYMNDX_SH_LEFT_BIG
)
1444 | ((int) ext
->r_bits
[2]
1445 << RELOC_BITS2_SYMNDX_SH_LEFT_BIG
));
1446 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_BIG
)
1447 >> RELOC_BITS3_TYPE_SH_BIG
);
1448 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_BIG
) != 0;
1452 intern
->r_symndx
= (((int) ext
->r_bits
[0]
1453 << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
)
1454 | ((int) ext
->r_bits
[1]
1455 << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
)
1456 | ((int) ext
->r_bits
[2]
1457 << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
));
1458 intern
->r_type
= ((ext
->r_bits
[3] & RELOC_BITS3_TYPE_LITTLE
)
1459 >> RELOC_BITS3_TYPE_SH_LITTLE
);
1460 intern
->r_extern
= (ext
->r_bits
[3] & RELOC_BITS3_EXTERN_LITTLE
) != 0;
1464 /* Swap a reloc out. */
1467 ecoff_swap_reloc_out (abfd
, src
, dst
)
1472 struct internal_reloc
*intern
= (struct internal_reloc
*) src
;
1473 RELOC
*ext
= (RELOC
*) dst
;
1475 bfd_h_put_32 (abfd
, intern
->r_vaddr
, (bfd_byte
*) ext
->r_vaddr
);
1476 if (abfd
->xvec
->header_byteorder_big_p
!= false)
1478 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_BIG
;
1479 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_BIG
;
1480 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_BIG
;
1481 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_BIG
)
1482 & RELOC_BITS3_TYPE_BIG
)
1483 | (intern
->r_extern
? RELOC_BITS3_EXTERN_BIG
: 0));
1487 ext
->r_bits
[0] = intern
->r_symndx
>> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE
;
1488 ext
->r_bits
[1] = intern
->r_symndx
>> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE
;
1489 ext
->r_bits
[2] = intern
->r_symndx
>> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE
;
1490 ext
->r_bits
[3] = (((intern
->r_type
<< RELOC_BITS3_TYPE_SH_LITTLE
)
1491 & RELOC_BITS3_TYPE_LITTLE
)
1492 | (intern
->r_extern
? RELOC_BITS3_EXTERN_LITTLE
: 0));
1498 /* ECOFF relocs are either against external symbols, or against
1499 sections. If we are producing relocateable output, and the reloc
1500 is against an external symbol, and nothing has given us any
1501 additional addend, the resulting reloc will also be against the
1502 same symbol. In such a case, we don't want to change anything
1503 about the way the reloc is handled, since it will all be done at
1504 final link time. Rather than put special case code into
1505 bfd_perform_relocation, all the reloc types use this howto
1506 function. It just short circuits the reloc if producing
1507 relocateable output against an external symbol. */
1509 static bfd_reloc_status_type
1510 ecoff_generic_reloc (abfd
,
1517 arelent
*reloc_entry
;
1520 asection
*input_section
;
1523 if (output_bfd
!= (bfd
*) NULL
1524 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1525 && reloc_entry
->addend
== 0)
1527 reloc_entry
->address
+= input_section
->output_offset
;
1528 return bfd_reloc_ok
;
1531 return bfd_reloc_continue
;
1534 /* Do a REFHI relocation. This has to be done in combination with a
1535 REFLO reloc, because there is a carry from the REFLO to the REFHI.
1536 Here we just save the information we need; we do the actual
1537 relocation when we see the REFLO. ECOFF requires that the REFLO
1538 immediately follow the REFHI, so this ought to work. */
1540 static bfd_byte
*ecoff_refhi_addr
;
1541 static bfd_vma ecoff_refhi_addend
;
1543 static bfd_reloc_status_type
1544 ecoff_refhi_reloc (abfd
,
1551 arelent
*reloc_entry
;
1554 asection
*input_section
;
1557 bfd_reloc_status_type ret
;
1560 /* If we're relocating, and this an external symbol, we don't want
1561 to change anything. */
1562 if (output_bfd
!= (bfd
*) NULL
1563 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1564 && reloc_entry
->addend
== 0)
1566 reloc_entry
->address
+= input_section
->output_offset
;
1567 return bfd_reloc_ok
;
1571 if (symbol
->section
== &bfd_und_section
1572 && output_bfd
== (bfd
*) NULL
)
1573 ret
= bfd_reloc_undefined
;
1575 if (bfd_is_com_section (symbol
->section
))
1578 relocation
= symbol
->value
;
1580 relocation
+= symbol
->section
->output_section
->vma
;
1581 relocation
+= symbol
->section
->output_offset
;
1582 relocation
+= reloc_entry
->addend
;
1584 if (reloc_entry
->address
> input_section
->_cooked_size
)
1585 return bfd_reloc_outofrange
;
1587 /* Save the information, and let REFLO do the actual relocation. */
1588 ecoff_refhi_addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1589 ecoff_refhi_addend
= relocation
;
1591 if (output_bfd
!= (bfd
*) NULL
)
1592 reloc_entry
->address
+= input_section
->output_offset
;
1597 /* Do a REFLO relocation. This is a straightforward 16 bit inplace
1598 relocation; this function exists in order to do the REFHI
1599 relocation described above. */
1601 static bfd_reloc_status_type
1602 ecoff_reflo_reloc (abfd
,
1609 arelent
*reloc_entry
;
1612 asection
*input_section
;
1615 if (ecoff_refhi_addr
!= (bfd_byte
*) NULL
)
1619 unsigned long vallo
;
1621 /* Do the REFHI relocation. Note that we actually don't need to
1622 know anything about the REFLO itself, except where to find
1623 the low 16 bits of the addend needed by the REFHI. */
1624 insn
= bfd_get_32 (abfd
, ecoff_refhi_addr
);
1625 vallo
= (bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1627 val
= ((insn
& 0xffff) << 16) + vallo
;
1628 val
+= ecoff_refhi_addend
;
1630 /* The low order 16 bits are always treated as a signed value.
1631 Therefore, a negative value in the low order bits requires an
1632 adjustment in the high order bits. We need to make this
1633 adjustment in two ways: once for the bits we took from the
1634 data, and once for the bits we are putting back in to the
1636 if ((vallo
& 0x8000) != 0)
1638 if ((val
& 0x8000) != 0)
1641 insn
= (insn
&~ 0xffff) | ((val
>> 16) & 0xffff);
1642 bfd_put_32 (abfd
, insn
, ecoff_refhi_addr
);
1644 ecoff_refhi_addr
= (bfd_byte
*) NULL
;
1647 /* Now do the REFLO reloc in the usual way. */
1648 return ecoff_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1649 input_section
, output_bfd
);
1652 /* Do a GPREL relocation. This is a 16 bit value which must become
1653 the offset from the gp register. */
1655 static bfd_reloc_status_type
1656 ecoff_gprel_reloc (abfd
,
1663 arelent
*reloc_entry
;
1666 asection
*input_section
;
1669 boolean relocateable
;
1674 /* If we're relocating, and this is an external symbol with no
1675 addend, we don't want to change anything. We will only have an
1676 addend if this is a newly created reloc, not read from an ECOFF
1678 if (output_bfd
!= (bfd
*) NULL
1679 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1680 && reloc_entry
->addend
== 0)
1682 reloc_entry
->address
+= input_section
->output_offset
;
1683 return bfd_reloc_ok
;
1686 if (output_bfd
!= (bfd
*) NULL
)
1687 relocateable
= true;
1690 relocateable
= false;
1691 output_bfd
= symbol
->section
->output_section
->owner
;
1694 if (symbol
->section
== &bfd_und_section
1695 && relocateable
== false)
1696 return bfd_reloc_undefined
;
1698 /* We have to figure out the gp value, so that we can adjust the
1699 symbol value correctly. We look up the symbol _gp in the output
1700 BFD. If we can't find it, we're stuck. We cache it in the ECOFF
1701 target data. We don't need to adjust the symbol value for an
1702 external symbol if we are producing relocateable output. */
1703 if (ecoff_data (output_bfd
)->gp
== 0
1704 && (relocateable
== false
1705 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1707 if (relocateable
!= false)
1709 /* Make up a value. */
1710 ecoff_data (output_bfd
)->gp
=
1711 symbol
->section
->output_section
->vma
+ 0x4000;
1719 count
= bfd_get_symcount (output_bfd
);
1720 sym
= bfd_get_outsymbols (output_bfd
);
1722 /* We should do something more friendly here, but we don't
1723 have a good reloc status to return. */
1724 if (sym
== (asymbol
**) NULL
)
1727 for (i
= 0; i
< count
; i
++, sym
++)
1729 register CONST
char *name
;
1731 name
= bfd_asymbol_name (*sym
);
1732 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1734 ecoff_data (output_bfd
)->gp
= bfd_asymbol_value (*sym
);
1739 /* We should do something more friendly here, but we don't have
1740 a good reloc status to return. */
1746 if (bfd_is_com_section (symbol
->section
))
1749 relocation
= symbol
->value
;
1751 relocation
+= symbol
->section
->output_section
->vma
;
1752 relocation
+= symbol
->section
->output_offset
;
1754 if (reloc_entry
->address
> input_section
->_cooked_size
)
1755 return bfd_reloc_outofrange
;
1757 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1759 /* Set val to the offset into the section or symbol. */
1760 val
= ((insn
& 0xffff) + reloc_entry
->addend
) & 0xffff;
1764 /* Adjust val for the final section location and GP value. If we
1765 are producing relocateable output, we don't want to do this for
1766 an external symbol. */
1767 if (relocateable
== false
1768 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1769 val
+= relocation
- ecoff_data (output_bfd
)->gp
;
1771 insn
= (insn
&~ 0xffff) | (val
& 0xffff);
1772 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
1774 if (relocateable
!= false)
1775 reloc_entry
->address
+= input_section
->output_offset
;
1777 /* Make sure it fit in 16 bits. */
1778 if (val
>= 0x8000 && val
< 0xffff8000)
1779 return bfd_reloc_outofrange
;
1781 return bfd_reloc_ok
;
1784 /* How to process the various relocs types. */
1786 static reloc_howto_type ecoff_howto_table
[] =
1788 /* Reloc type 0 is ignored. The reloc reading code ensures that
1789 this is a reference to the .abs section, which will cause
1790 bfd_perform_relocation to do nothing. */
1791 HOWTO (ECOFF_R_IGNORE
, /* type */
1793 0, /* size (0 = byte, 1 = short, 2 = long) */
1794 8, /* bitsize (obsolete) */
1795 false, /* pc_relative */
1797 false, /* absolute (obsolete) */
1798 false, /* complain_on_overflow */
1799 0, /* special_function */
1800 "IGNORE", /* name */
1801 false, /* partial_inplace */
1804 false), /* pcrel_offset */
1806 /* A 16 bit reference to a symbol, normally from a data section. */
1807 HOWTO (ECOFF_R_REFHALF
, /* type */
1809 1, /* size (0 = byte, 1 = short, 2 = long) */
1810 16, /* bitsize (obsolete) */
1811 false, /* pc_relative */
1813 false, /* absolute (obsolete) */
1814 true, /* complain_on_overflow */
1815 ecoff_generic_reloc
, /* special_function */
1816 "REFHALF", /* name */
1817 true, /* partial_inplace */
1818 0xffff, /* src_mask */
1819 0xffff, /* dst_mask */
1820 false), /* pcrel_offset */
1822 /* A 32 bit reference to a symbol, normally from a data section. */
1823 HOWTO (ECOFF_R_REFWORD
, /* type */
1825 2, /* size (0 = byte, 1 = short, 2 = long) */
1826 32, /* bitsize (obsolete) */
1827 false, /* pc_relative */
1829 false, /* absolute (obsolete) */
1830 true, /* complain_on_overflow */
1831 ecoff_generic_reloc
, /* special_function */
1832 "REFWORD", /* name */
1833 true, /* partial_inplace */
1834 0xffffffff, /* src_mask */
1835 0xffffffff, /* dst_mask */
1836 false), /* pcrel_offset */
1838 /* A 26 bit absolute jump address. */
1839 HOWTO (ECOFF_R_JMPADDR
, /* type */
1841 2, /* size (0 = byte, 1 = short, 2 = long) */
1842 32, /* bitsize (obsolete) */
1843 false, /* pc_relative */
1845 false, /* absolute (obsolete) */
1846 true, /* complain_on_overflow */
1847 ecoff_generic_reloc
, /* special_function */
1848 "JMPADDR", /* name */
1849 true, /* partial_inplace */
1850 0x3ffffff, /* src_mask */
1851 0x3ffffff, /* dst_mask */
1852 false), /* pcrel_offset */
1854 /* The high 16 bits of a symbol value. Handled by the function
1855 ecoff_refhi_reloc. */
1856 HOWTO (ECOFF_R_REFHI
, /* type */
1857 16, /* rightshift */
1858 2, /* size (0 = byte, 1 = short, 2 = long) */
1859 32, /* bitsize (obsolete) */
1860 false, /* pc_relative */
1862 false, /* absolute (obsolete) */
1863 true, /* complain_on_overflow */
1864 ecoff_refhi_reloc
, /* special_function */
1866 true, /* partial_inplace */
1867 0xffff, /* src_mask */
1868 0xffff, /* dst_mask */
1869 false), /* pcrel_offset */
1871 /* The low 16 bits of a symbol value. */
1872 HOWTO (ECOFF_R_REFLO
, /* type */
1874 2, /* size (0 = byte, 1 = short, 2 = long) */
1875 32, /* bitsize (obsolete) */
1876 false, /* pc_relative */
1878 false, /* absolute (obsolete) */
1879 true, /* complain_on_overflow */
1880 ecoff_reflo_reloc
, /* special_function */
1882 true, /* partial_inplace */
1883 0xffff, /* src_mask */
1884 0xffff, /* dst_mask */
1885 false), /* pcrel_offset */
1887 /* A reference to an offset from the gp register. Handled by the
1888 function ecoff_gprel_reloc. */
1889 HOWTO (ECOFF_R_GPREL
, /* type */
1891 2, /* size (0 = byte, 1 = short, 2 = long) */
1892 32, /* bitsize (obsolete) */
1893 false, /* pc_relative */
1895 false, /* absolute (obsolete) */
1896 true, /* complain_on_overflow */
1897 ecoff_gprel_reloc
, /* special_function */
1899 true, /* partial_inplace */
1900 0xffff, /* src_mask */
1901 0xffff, /* dst_mask */
1902 false), /* pcrel_offset */
1904 /* A reference to a literal using an offset from the gp register.
1905 Handled by the function ecoff_gprel_reloc. */
1906 HOWTO (ECOFF_R_LITERAL
, /* type */
1908 2, /* size (0 = byte, 1 = short, 2 = long) */
1909 32, /* bitsize (obsolete) */
1910 false, /* pc_relative */
1912 false, /* absolute (obsolete) */
1913 true, /* complain_on_overflow */
1914 ecoff_gprel_reloc
, /* special_function */
1915 "LITERAL", /* name */
1916 true, /* partial_inplace */
1917 0xffff, /* src_mask */
1918 0xffff, /* dst_mask */
1919 false) /* pcrel_offset */
1922 #define ECOFF_HOWTO_COUNT \
1923 (sizeof ecoff_howto_table / sizeof ecoff_howto_table[0])
1925 /* Read in the relocs for a section. */
1928 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1933 RELOC
*external_relocs
;
1934 arelent
*internal_relocs
;
1938 if (section
->relocation
!= (arelent
*) NULL
1939 || section
->reloc_count
== 0
1940 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1943 if (ecoff_slurp_symbol_table (abfd
) == false)
1946 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1948 * section
->reloc_count
));
1949 external_relocs
= (RELOC
*) bfd_alloc (abfd
, RELSZ
* section
->reloc_count
);
1950 if (internal_relocs
== (arelent
*) NULL
1951 || external_relocs
== (RELOC
*) NULL
)
1953 bfd_error
= no_memory
;
1956 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1958 if (bfd_read (external_relocs
, 1, RELSZ
* section
->reloc_count
, abfd
)
1959 != RELSZ
* section
->reloc_count
)
1961 bfd_error
= system_call_error
;
1965 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1967 struct internal_reloc intern
;
1969 ecoff_swap_reloc_in (abfd
, external_relocs
+ i
, &intern
);
1971 if (intern
.r_type
> ECOFF_R_LITERAL
)
1974 if (intern
.r_extern
)
1976 /* r_symndx is an index into the external symbols. */
1977 BFD_ASSERT (intern
.r_symndx
>= 0
1979 < ecoff_data (abfd
)->symbolic_header
.iextMax
));
1980 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1985 CONST
char *sec_name
;
1988 /* r_symndx is a section key. */
1989 switch (intern
.r_symndx
)
1991 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1992 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1993 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1994 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1995 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1996 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1997 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1998 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1999 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
2003 sec
= bfd_get_section_by_name (abfd
, sec_name
);
2004 if (sec
== (asection
*) NULL
)
2006 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
2008 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
2009 if (intern
.r_type
== ECOFF_R_GPREL
2010 || intern
.r_type
== ECOFF_R_LITERAL
)
2011 rptr
->addend
+= ecoff_data (abfd
)->gp
;
2014 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
2015 rptr
->howto
= &ecoff_howto_table
[intern
.r_type
];
2017 /* If the type is ECOFF_R_IGNORE, make sure this is a reference
2018 to the absolute section so that the reloc is ignored. */
2019 if (intern
.r_type
== ECOFF_R_IGNORE
)
2020 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
2023 bfd_release (abfd
, external_relocs
);
2025 section
->relocation
= internal_relocs
;
2030 /* Get a canonical list of relocs. */
2033 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
2041 if (section
->flags
& SEC_CONSTRUCTOR
)
2043 arelent_chain
*chain
;
2045 /* This section has relocs made up by us, not the file, so take
2046 them out of their chain and place them into the data area
2048 for (count
= 0, chain
= section
->constructor_chain
;
2049 count
< section
->reloc_count
;
2050 count
++, chain
= chain
->next
)
2051 *relptr
++ = &chain
->relent
;
2057 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
2060 tblptr
= section
->relocation
;
2061 if (tblptr
== (arelent
*) NULL
)
2064 for (count
= 0; count
< section
->reloc_count
; count
++)
2065 *relptr
++ = tblptr
++;
2068 *relptr
= (arelent
*) NULL
;
2070 return section
->reloc_count
;
2073 /* Get the howto structure for a generic reloc type. */
2075 static CONST
struct reloc_howto_struct
*
2076 ecoff_bfd_reloc_type_lookup (abfd
, code
)
2078 bfd_reloc_code_real_type code
;
2085 ecoff_type
= ECOFF_R_REFHALF
;
2088 ecoff_type
= ECOFF_R_REFWORD
;
2090 case BFD_RELOC_MIPS_JMP
:
2091 ecoff_type
= ECOFF_R_JMPADDR
;
2093 case BFD_RELOC_HI16_S
:
2094 ecoff_type
= ECOFF_R_REFHI
;
2096 case BFD_RELOC_LO16
:
2097 ecoff_type
= ECOFF_R_REFLO
;
2099 case BFD_RELOC_MIPS_GPREL
:
2100 ecoff_type
= ECOFF_R_GPREL
;
2103 return (CONST
struct reloc_howto_struct
*) NULL
;
2106 return &ecoff_howto_table
[ecoff_type
];
2109 /* Provided a BFD, a section and an offset into the section, calculate
2110 and return the name of the source file and the line nearest to the
2114 ecoff_find_nearest_line (abfd
,
2123 asymbol
**ignore_symbols
;
2125 CONST
char **filename_ptr
;
2126 CONST
char **functionname_ptr
;
2127 unsigned int *retline_ptr
;
2133 struct pdr_ext
*pdr_ptr
;
2134 struct pdr_ext
*pdr_end
;
2136 unsigned char *line_ptr
;
2137 unsigned char *line_end
;
2140 /* If we're not in the .text section, we don't have any line
2142 if (strcmp (section
->name
, _TEXT
) != 0
2143 || offset
< ecoff_data (abfd
)->text_start
2144 || offset
>= ecoff_data (abfd
)->text_end
)
2147 /* Make sure we have the FDR's. */
2148 if (ecoff_slurp_symbolic_info (abfd
) == false
2149 || bfd_get_symcount (abfd
) == 0)
2152 /* Each file descriptor (FDR) has a memory address. Here we track
2153 down which FDR we want. The FDR's are stored in increasing
2154 memory order. If speed is ever important, this can become a
2155 binary search. We must ignore FDR's with no PDR entries; they
2156 will have the adr of the FDR before or after them. */
2157 fdr_start
= ecoff_data (abfd
)->fdr
;
2158 fdr_end
= fdr_start
+ ecoff_data (abfd
)->symbolic_header
.ifdMax
;
2159 fdr_hold
= (FDR
*) NULL
;
2160 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
2162 if (fdr_ptr
->cpd
== 0)
2164 if (offset
< fdr_ptr
->adr
)
2168 if (fdr_hold
== (FDR
*) NULL
)
2172 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2173 have an address, which is relative to the FDR address, and are
2174 also stored in increasing memory order. */
2175 offset
-= fdr_ptr
->adr
;
2176 pdr_ptr
= ecoff_data (abfd
)->external_pdr
+ fdr_ptr
->ipdFirst
;
2177 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
;
2178 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2180 /* The address of the first PDR is an offset which applies to the
2181 addresses of all the PDR's. */
2184 for (pdr_ptr
++; pdr_ptr
< pdr_end
; pdr_ptr
++)
2186 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2187 if (offset
< pdr
.adr
)
2191 /* Now we can look for the actual line number. The line numbers are
2192 stored in a very funky format, which I won't try to describe.
2193 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2194 we want; we need this to compute line_end. */
2195 line_end
= ecoff_data (abfd
)->line
;
2196 if (pdr_ptr
== pdr_end
)
2197 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2199 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2201 /* Now change pdr and pdr_ptr to the one we want. */
2203 ecoff_swap_pdr_in (abfd
, pdr_ptr
, &pdr
);
2207 line_ptr
= (ecoff_data (abfd
)->line
2208 + fdr_ptr
->cbLineOffset
2209 + pdr
.cbLineOffset
);
2210 while (line_ptr
< line_end
)
2215 delta
= *line_ptr
>> 4;
2218 count
= (*line_ptr
& 0xf) + 1;
2222 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2223 if (delta
>= 0x8000)
2228 if (offset
< count
* 4)
2230 offset
-= count
* 4;
2233 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2234 at least according to gdb/mipsread.c. */
2235 if (fdr_ptr
->rss
== -1)
2237 *filename_ptr
= NULL
;
2239 *functionname_ptr
= NULL
;
2244 ecoff_swap_ext_in (abfd
,
2245 (ecoff_data (abfd
)->external_ext
2248 *functionname_ptr
= ecoff_data (abfd
)->ssext
+ proc_ext
.asym
.iss
;
2255 *filename_ptr
= ecoff_data (abfd
)->ss
+ fdr_ptr
->issBase
+ fdr_ptr
->rss
;
2256 ecoff_swap_sym_in (abfd
,
2257 (ecoff_data (abfd
)->external_sym
2261 *functionname_ptr
= (ecoff_data (abfd
)->ss
2265 *retline_ptr
= lineno
;
2269 /* We can't use the generic linking routines for ECOFF, because we
2270 have to handle all the debugging information. The generic link
2271 routine just works out the section contents and attaches a list of
2274 We link by looping over all the seclets. We make two passes. On
2275 the first we set the actual section contents and determine the size
2276 of the debugging information. On the second we accumulate the
2277 debugging information and write it out.
2279 This currently always accumulates the debugging information, which
2280 is incorrect, because it ignores the -s and -S options of the
2281 linker. The linker needs to be modified to give us that
2282 information in a more useful format (currently it just provides a
2283 list of symbols which should appear in the output file). */
2285 /* Clear the output_has_begun flag for all the input BFD's. We use it
2286 to avoid linking in the debugging information for a BFD more than
2290 ecoff_clear_output_flags (abfd
)
2293 register asection
*o
;
2294 register bfd_seclet_type
*p
;
2296 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2297 for (p
= o
->seclets_head
;
2298 p
!= (bfd_seclet_type
*) NULL
;
2300 if (p
->type
== bfd_indirect_seclet
)
2301 p
->u
.indirect
.section
->owner
->output_has_begun
= false;
2304 /* Handle an indirect seclet on the first pass. Set the contents of
2305 the output section, and accumulate the debugging information if
2309 ecoff_rel (output_bfd
, seclet
, output_section
, data
, relocateable
)
2311 bfd_seclet_type
*seclet
;
2312 asection
*output_section
;
2314 boolean relocateable
;
2317 HDRR
*output_symhdr
;
2320 if ((output_section
->flags
& SEC_HAS_CONTENTS
)
2321 && !(output_section
->flags
& SEC_NEVER_LOAD
)
2322 && (output_section
->flags
& SEC_LOAD
)
2325 data
= (PTR
) bfd_get_relocated_section_contents (output_bfd
,
2329 if (bfd_set_section_contents (output_bfd
,
2340 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2342 /* We want to figure out how much space will be required to
2343 incorporate all the debugging information from input_bfd. We use
2344 the output_has_begun field to avoid adding it in more than once.
2345 The actual incorporation is done in the second pass, in
2346 ecoff_get_debug. The code has to parallel that code in its
2347 manipulations of output_symhdr. */
2349 if (input_bfd
->output_has_begun
)
2351 input_bfd
->output_has_begun
= true;
2353 output_symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2355 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2361 /* We just accumulate local symbols from a non-ECOFF BFD. The
2362 external symbols are handled separately. */
2364 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2365 get_symtab_upper_bound (input_bfd
));
2366 if (symbols
== (asymbol
**) NULL
)
2368 bfd_error
= no_memory
;
2371 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2373 for (sym_ptr
= symbols
; sym_ptr
< sym_end
; sym_ptr
++)
2377 len
= strlen ((*sym_ptr
)->name
);
2378 if (((*sym_ptr
)->flags
& BSF_EXPORT
) == 0)
2380 ++output_symhdr
->isymMax
;
2381 output_symhdr
->issMax
+= len
+ 1;
2385 bfd_release (output_bfd
, (PTR
) symbols
);
2387 ++output_symhdr
->ifdMax
;
2392 /* We simply add in the information from another ECOFF BFD. First
2393 we make sure we have the symbolic information. */
2394 if (ecoff_slurp_symbol_table (input_bfd
) == false)
2396 if (bfd_get_symcount (input_bfd
) == 0)
2399 input_symhdr
= &ecoff_data (input_bfd
)->symbolic_header
;
2401 /* Figure out how much information we are going to be putting in.
2402 The external symbols are handled separately. */
2403 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2404 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2405 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2406 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2407 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2408 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2409 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2410 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2411 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2413 /* The RFD's are special, since we create them if needed. */
2414 if (input_symhdr
->crfd
> 0)
2415 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2417 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2422 /* Handle an arbitrary seclet on the first pass. */
2425 ecoff_dump_seclet (abfd
, seclet
, section
, data
, relocateable
)
2427 bfd_seclet_type
*seclet
;
2430 boolean relocateable
;
2432 switch (seclet
->type
)
2434 case bfd_indirect_seclet
:
2435 /* The contents of this section come from another one somewhere
2437 return ecoff_rel (abfd
, seclet
, section
, data
, relocateable
);
2439 case bfd_fill_seclet
:
2440 /* Fill in the section with fill.value. This is used to pad out
2441 sections, but we must avoid padding the .bss section. */
2442 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
2444 if (seclet
->u
.fill
.value
!= 0)
2449 char *d
= (char *) bfd_alloc (abfd
, seclet
->size
);
2453 for (i
= 0; i
< seclet
->size
; i
+=2)
2454 d
[i
] = seclet
->u
.fill
.value
>> 8;
2455 for (i
= 1; i
< seclet
->size
; i
+=2)
2456 d
[i
] = seclet
->u
.fill
.value
;
2457 ret
= bfd_set_section_contents (abfd
, section
, d
, seclet
->offset
,
2459 bfd_release (abfd
, (PTR
) d
);
2471 /* Add a string to the debugging information we are accumulating for a
2472 file. Return the offset from the fdr string base or from the
2473 external string base. */
2476 ecoff_add_string (output_bfd
, fdr
, string
, external
)
2486 symhdr
= &ecoff_data (output_bfd
)->symbolic_header
;
2487 len
= strlen (string
);
2490 strcpy (ecoff_data (output_bfd
)->ssext
+ symhdr
->issExtMax
, string
);
2491 ret
= symhdr
->issExtMax
;
2492 symhdr
->issExtMax
+= len
+ 1;
2496 strcpy (ecoff_data (output_bfd
)->ss
+ symhdr
->issMax
, string
);
2498 symhdr
->issMax
+= len
+ 1;
2499 fdr
->cbSs
+= len
+ 1;
2504 /* Accumulate the debugging information from an input section. */
2507 ecoff_get_debug (output_bfd
, seclet
, section
, relocateable
)
2509 bfd_seclet_type
*seclet
;
2511 boolean relocateable
;
2514 HDRR
*output_symhdr
;
2516 ecoff_data_type
*output_ecoff
;
2517 ecoff_data_type
*input_ecoff
;
2519 struct sym_ext
*sym_out
;
2520 ecoff_symbol_type
*esym_ptr
;
2521 ecoff_symbol_type
*esym_end
;
2522 unsigned long pdr_off
;
2525 struct fdr_ext
*fdr_out
;
2527 input_bfd
= seclet
->u
.indirect
.section
->owner
;
2529 /* Don't get the information more than once. */
2530 if (input_bfd
->output_has_begun
)
2532 input_bfd
->output_has_begun
= true;
2534 output_ecoff
= ecoff_data (output_bfd
);
2535 output_symhdr
= &output_ecoff
->symbolic_header
;
2537 if (input_bfd
->xvec
->flavour
!= bfd_target_ecoff_flavour
)
2544 /* This is not an ECOFF BFD. Just gather the symbols. */
2546 memset (&fdr
, 0, sizeof fdr
);
2548 fdr
.adr
= bfd_get_section_vma (output_bfd
, section
) + seclet
->offset
;
2549 fdr
.issBase
= output_symhdr
->issMax
;
2551 fdr
.rss
= ecoff_add_string (output_bfd
,
2553 bfd_get_filename (input_bfd
),
2555 fdr
.isymBase
= output_symhdr
->isymMax
;
2557 /* Get the local symbols from the input BFD. */
2558 symbols
= (asymbol
**) bfd_alloc (output_bfd
,
2559 get_symtab_upper_bound (input_bfd
));
2560 if (symbols
== (asymbol
**) NULL
)
2562 bfd_error
= no_memory
;
2565 sym_end
= symbols
+ bfd_canonicalize_symtab (input_bfd
, symbols
);
2567 /* Handle the local symbols. Any external symbols are handled
2570 for (sym_ptr
= symbols
; sym_ptr
!= sym_end
; sym_ptr
++)
2574 if (((*sym_ptr
)->flags
& BSF_EXPORT
) != 0)
2576 memset (&internal_sym
, 0, sizeof internal_sym
);
2577 internal_sym
.iss
= ecoff_add_string (output_bfd
,
2582 if (bfd_is_com_section ((*sym_ptr
)->section
)
2583 || (*sym_ptr
)->section
== &bfd_und_section
)
2584 internal_sym
.value
= (*sym_ptr
)->value
;
2586 internal_sym
.value
= ((*sym_ptr
)->value
2587 + (*sym_ptr
)->section
->output_offset
2588 + (*sym_ptr
)->section
->output_section
->vma
);
2589 internal_sym
.st
= stNil
;
2590 internal_sym
.sc
= scUndefined
;
2591 internal_sym
.index
= indexNil
;
2592 ecoff_swap_sym_out (output_bfd
, &internal_sym
,
2593 (output_ecoff
->external_sym
2594 + output_symhdr
->isymMax
));
2596 ++output_symhdr
->isymMax
;
2599 bfd_release (output_bfd
, (PTR
) symbols
);
2601 /* Leave everything else in the FDR zeroed out. This will cause
2602 the lang field to be langC. The fBigendian field will
2603 indicate little endian format, but it doesn't matter because
2604 it only applies to aux fields and there are none. */
2606 ecoff_swap_fdr_out (output_bfd
, &fdr
,
2607 (output_ecoff
->external_fdr
2608 + output_symhdr
->ifdMax
));
2609 ++output_symhdr
->ifdMax
;
2613 /* This is an ECOFF BFD. We want to grab the information from
2614 input_bfd and attach it to output_bfd. */
2615 count
= bfd_get_symcount (input_bfd
);
2618 input_ecoff
= ecoff_data (input_bfd
);
2619 input_symhdr
= &input_ecoff
->symbolic_header
;
2621 /* I think that it is more efficient to simply copy the debugging
2622 information from the input BFD to the output BFD. Because ECOFF
2623 uses relative pointers for most of the debugging information,
2624 only a little of it has to be changed at all. */
2626 /* Swap in the local symbols, adjust their values, and swap them out
2627 again. The external symbols are handled separately. */
2628 sym_out
= output_ecoff
->external_sym
+ output_symhdr
->isymMax
;
2630 esym_ptr
= ecoff_data (input_bfd
)->canonical_symbols
;
2631 esym_end
= esym_ptr
+ count
;
2632 for (; esym_ptr
< esym_end
; esym_ptr
++)
2634 if (esym_ptr
->local
)
2638 ecoff_swap_sym_in (input_bfd
, esym_ptr
->native
.lnative
, &sym
);
2640 /* If we're producing an executable, move common symbols
2642 if (relocateable
== false)
2644 if (sym
.sc
== scCommon
)
2646 else if (sym
.sc
== scSCommon
)
2650 if (! bfd_is_com_section (esym_ptr
->symbol
.section
)
2651 && (esym_ptr
->symbol
.flags
& BSF_DEBUGGING
) == 0
2652 && esym_ptr
->symbol
.section
!= &bfd_und_section
)
2653 sym
.value
= (esym_ptr
->symbol
.value
2654 + esym_ptr
->symbol
.section
->output_offset
2655 + esym_ptr
->symbol
.section
->output_section
->vma
);
2656 ecoff_swap_sym_out (output_bfd
, &sym
, sym_out
);
2661 /* That should have accounted for all the local symbols in
2663 BFD_ASSERT ((sym_out
- output_ecoff
->external_sym
) - output_symhdr
->isymMax
2664 == input_symhdr
->isymMax
);
2666 /* Copy the information that does not need swapping. */
2667 memcpy (output_ecoff
->line
+ output_symhdr
->cbLine
,
2669 input_symhdr
->cbLine
* sizeof (unsigned char));
2670 memcpy (output_ecoff
->external_aux
+ output_symhdr
->iauxMax
,
2671 input_ecoff
->external_aux
,
2672 input_symhdr
->iauxMax
* sizeof (union aux_ext
));
2673 memcpy (output_ecoff
->ss
+ output_symhdr
->issMax
,
2675 input_symhdr
->issMax
* sizeof (char));
2677 /* Some of the information may need to be swapped. */
2678 if (output_bfd
->xvec
->header_byteorder_big_p
2679 == input_bfd
->xvec
->header_byteorder_big_p
)
2681 /* The two BFD's have the same endianness, so memcpy will
2683 memcpy (output_ecoff
->external_dnr
+ output_symhdr
->idnMax
,
2684 input_ecoff
->external_dnr
,
2685 input_symhdr
->idnMax
* sizeof (struct dnr_ext
));
2686 memcpy (output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
,
2687 input_ecoff
->external_pdr
,
2688 input_symhdr
->ipdMax
* sizeof (struct pdr_ext
));
2689 if (input_symhdr
->ipdMax
== 0)
2695 ecoff_swap_pdr_in (input_bfd
, input_ecoff
->external_pdr
, &pdr
);
2698 memcpy (output_ecoff
->external_opt
+ output_symhdr
->ioptMax
,
2699 input_ecoff
->external_opt
,
2700 input_symhdr
->ioptMax
* sizeof (struct opt_ext
));
2704 struct dnr_ext
*dnr_in
;
2705 struct dnr_ext
*dnr_end
;
2706 struct dnr_ext
*dnr_out
;
2707 struct pdr_ext
*pdr_in
;
2708 struct pdr_ext
*pdr_end
;
2709 struct pdr_ext
*pdr_out
;
2711 struct opt_ext
*opt_in
;
2712 struct opt_ext
*opt_end
;
2713 struct opt_ext
*opt_out
;
2715 /* The two BFD's have different endianness, so we must swap
2716 everything in and out. This code would always work, but it
2717 would be slow in the normal case. */
2718 dnr_in
= input_ecoff
->external_dnr
;
2719 dnr_end
= dnr_in
+ input_symhdr
->idnMax
;
2720 dnr_out
= output_ecoff
->external_dnr
+ output_symhdr
->idnMax
;
2721 for (; dnr_in
< dnr_end
; dnr_in
++, dnr_out
++)
2725 ecoff_swap_dnr_in (input_bfd
, dnr_in
, &dnr
);
2726 ecoff_swap_dnr_out (output_bfd
, &dnr
, dnr_out
);
2728 pdr_in
= input_ecoff
->external_pdr
;
2729 pdr_end
= pdr_in
+ input_symhdr
->ipdMax
;
2730 pdr_out
= output_ecoff
->external_pdr
+ output_symhdr
->ipdMax
;
2733 for (; pdr_in
< pdr_end
; pdr_in
++, pdr_out
++)
2737 ecoff_swap_pdr_in (input_bfd
, pdr_in
, &pdr
);
2738 ecoff_swap_pdr_out (output_bfd
, &pdr
, pdr_out
);
2745 opt_in
= input_ecoff
->external_opt
;
2746 opt_end
= opt_in
+ input_symhdr
->ioptMax
;
2747 opt_out
= output_ecoff
->external_opt
+ output_symhdr
->ioptMax
;
2748 for (; opt_in
< opt_end
; opt_in
++, opt_out
++)
2752 ecoff_swap_opt_in (input_bfd
, opt_in
, &opt
);
2753 ecoff_swap_opt_out (output_bfd
, &opt
, opt_out
);
2757 /* Set ifdbase so that the external symbols know how to adjust their
2759 input_ecoff
->ifdbase
= output_symhdr
->ifdMax
;
2761 fdr_ptr
= input_ecoff
->fdr
;
2762 fdr_end
= fdr_ptr
+ input_symhdr
->ifdMax
;
2763 fdr_out
= output_ecoff
->external_fdr
+ output_symhdr
->ifdMax
;
2764 for (; fdr_ptr
< fdr_end
; fdr_ptr
++, fdr_out
++)
2770 /* The memory address for this fdr is the address for the seclet
2771 plus the offset to this fdr within input_bfd. For some
2772 reason the offset of the first procedure pointer is also
2774 fdr
.adr
= (bfd_get_section_vma (output_bfd
, section
)
2776 + (fdr_ptr
->adr
- input_ecoff
->fdr
->adr
)
2779 fdr
.issBase
+= output_symhdr
->issMax
;
2780 fdr
.isymBase
+= output_symhdr
->isymMax
;
2781 fdr
.ilineBase
+= output_symhdr
->ilineMax
;
2782 fdr
.ioptBase
+= output_symhdr
->ioptMax
;
2783 fdr
.ipdFirst
+= output_symhdr
->ipdMax
;
2784 fdr
.iauxBase
+= output_symhdr
->iauxMax
;
2785 fdr
.rfdBase
+= output_symhdr
->crfd
;
2787 /* If there are no RFD's, we are going to add some. We don't
2788 want to adjust irfd for this, so that all the FDR's can share
2790 if (input_symhdr
->crfd
== 0)
2791 fdr
.crfd
= input_symhdr
->ifdMax
;
2793 if (fdr
.cbLine
!= 0)
2794 fdr
.cbLineOffset
+= output_symhdr
->cbLine
;
2796 ecoff_swap_fdr_out (output_bfd
, &fdr
, fdr_out
);
2799 if (input_symhdr
->crfd
> 0)
2801 struct rfd_ext
*rfd_in
;
2802 struct rfd_ext
*rfd_end
;
2803 struct rfd_ext
*rfd_out
;
2805 /* Swap and adjust the RFD's. RFD's are only created by the
2806 linker, so this will only be necessary if one of the input
2807 files is the result of a partial link. Presumably all
2808 necessary RFD's are present. */
2809 rfd_in
= input_ecoff
->external_rfd
;
2810 rfd_end
= rfd_in
+ input_symhdr
->crfd
;
2811 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
2812 for (; rfd_in
< rfd_end
; rfd_in
++, rfd_out
++)
2816 ecoff_swap_rfd_in (input_bfd
, rfd_in
, &rfd
);
2817 rfd
+= output_symhdr
->ifdMax
;
2818 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
2820 output_symhdr
->crfd
+= input_symhdr
->crfd
;
2824 struct rfd_ext
*rfd_out
;
2825 struct rfd_ext
*rfd_end
;
2828 /* Create RFD's. Some of the debugging information includes
2829 relative file indices. These indices are taken as indices to
2830 the RFD table if there is one, or to the global table if
2831 there is not. If we did not create RFD's, we would have to
2832 parse and adjust all the debugging information which contains
2834 rfd
= output_symhdr
->ifdMax
;
2835 rfd_out
= output_ecoff
->external_rfd
+ output_symhdr
->crfd
;
2836 rfd_end
= rfd_out
+ input_symhdr
->ifdMax
;
2837 for (; rfd_out
< rfd_end
; rfd_out
++, rfd
++)
2838 ecoff_swap_rfd_out (output_bfd
, &rfd
, rfd_out
);
2839 output_symhdr
->crfd
+= input_symhdr
->ifdMax
;
2842 /* Combine the register masks. */
2846 output_ecoff
->gprmask
|= input_ecoff
->gprmask
;
2847 for (i
= 0; i
< 4; i
++)
2848 output_ecoff
->cprmask
[i
] |= input_ecoff
->cprmask
[i
];
2851 /* Update the counts. */
2852 output_symhdr
->ilineMax
+= input_symhdr
->ilineMax
;
2853 output_symhdr
->cbLine
+= input_symhdr
->cbLine
;
2854 output_symhdr
->idnMax
+= input_symhdr
->idnMax
;
2855 output_symhdr
->ipdMax
+= input_symhdr
->ipdMax
;
2856 output_symhdr
->isymMax
+= input_symhdr
->isymMax
;
2857 output_symhdr
->ioptMax
+= input_symhdr
->ioptMax
;
2858 output_symhdr
->iauxMax
+= input_symhdr
->iauxMax
;
2859 output_symhdr
->issMax
+= input_symhdr
->issMax
;
2860 output_symhdr
->ifdMax
+= input_symhdr
->ifdMax
;
2865 /* This is the actual link routine. It makes two passes over all the
2869 ecoff_bfd_seclet_link (abfd
, data
, relocateable
)
2872 boolean relocateable
;
2876 register asection
*o
;
2877 register bfd_seclet_type
*p
;
2878 asymbol
**sym_ptr_ptr
;
2882 /* We accumulate the debugging information counts in the symbolic
2884 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
2885 symhdr
->magic
= magicSym
;
2886 /* FIXME: What should the version stamp be? */
2888 symhdr
->ilineMax
= 0;
2892 symhdr
->isymMax
= 0;
2893 symhdr
->ioptMax
= 0;
2894 symhdr
->iauxMax
= 0;
2896 symhdr
->issExtMax
= 0;
2899 symhdr
->iextMax
= 0;
2901 /* We need to copy over the debugging symbols from each input BFD.
2902 When we do this copying, we have to adjust the text address in
2903 the FDR structures, so we have to know the text address used for
2904 the input BFD. Since we only want to copy the symbols once per
2905 input BFD, but we are going to look at each input BFD multiple
2906 times (once for each section it provides), we arrange to always
2907 look at the text section first. That means that when we copy the
2908 debugging information, we always know the text address. So we
2909 actually do each pass in two sub passes; first the text sections,
2910 then the non-text sections. We use the output_has_begun flag to
2911 determine whether we have copied over the debugging information
2914 /* Do the first pass: set the output section contents and count the
2915 debugging information. */
2916 ecoff_clear_output_flags (abfd
);
2917 for (ipass
= 0; ipass
< 2; ipass
++)
2919 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2921 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2922 so they are done on pass 0. For other sections the
2923 expression is true, so they are done on pass 1. */
2924 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
2927 for (p
= o
->seclets_head
;
2928 p
!= (bfd_seclet_type
*) NULL
;
2931 if (ecoff_dump_seclet (abfd
, p
, o
, data
, relocateable
)
2938 /* We handle the external symbols differently. We use the ones
2939 attached to the output_bfd. The linker will have already
2940 determined which symbols are to be attached. Here we just
2941 determine how much space we will need for them. */
2942 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
2943 if (sym_ptr_ptr
!= NULL
)
2947 sym_end
= sym_ptr_ptr
+ bfd_get_symcount (abfd
);
2948 for (; sym_ptr_ptr
< sym_end
; sym_ptr_ptr
++)
2950 if (((*sym_ptr_ptr
)->flags
& BSF_DEBUGGING
) == 0
2951 && ((*sym_ptr_ptr
)->flags
& BSF_LOCAL
) == 0)
2954 symhdr
->issExtMax
+= strlen ((*sym_ptr_ptr
)->name
) + 1;
2959 /* Adjust the counts so that structures are longword aligned. */
2960 symhdr
->cbLine
= (symhdr
->cbLine
+ 3) &~ 3;
2961 symhdr
->issMax
= (symhdr
->issMax
+ 3) &~ 3;
2962 symhdr
->issExtMax
= (symhdr
->issExtMax
+ 3) &~ 3;
2964 /* Now the counts in symhdr are the correct size for the debugging
2965 information. We allocate the right amount of space, and reset
2966 the counts so that the second pass can use them as indices. It
2967 would be possible to output the debugging information directly to
2968 the file in pass 2, rather than to build it in memory and then
2969 write it out. Outputting to the file would require a lot of
2970 seeks and small writes, though, and I think this approach is
2972 size
= (symhdr
->cbLine
* sizeof (unsigned char)
2973 + symhdr
->idnMax
* sizeof (struct dnr_ext
)
2974 + symhdr
->ipdMax
* sizeof (struct pdr_ext
)
2975 + symhdr
->isymMax
* sizeof (struct sym_ext
)
2976 + symhdr
->ioptMax
* sizeof (struct opt_ext
)
2977 + symhdr
->iauxMax
* sizeof (union aux_ext
)
2978 + symhdr
->issMax
* sizeof (char)
2979 + symhdr
->issExtMax
* sizeof (char)
2980 + symhdr
->ifdMax
* sizeof (struct fdr_ext
)
2981 + symhdr
->crfd
* sizeof (struct rfd_ext
)
2982 + symhdr
->iextMax
* sizeof (struct ext_ext
));
2983 raw
= (char *) bfd_alloc (abfd
, size
);
2984 if (raw
== (char *) NULL
)
2986 bfd_error
= no_memory
;
2989 ecoff_data (abfd
)->raw_size
= size
;
2990 ecoff_data (abfd
)->raw_syments
= (PTR
) raw
;
2992 /* Initialize the raw pointers. */
2993 #define SET(field, count, type) \
2994 ecoff_data (abfd)->field = (type *) raw; \
2995 raw += symhdr->count * sizeof (type)
2997 SET (line
, cbLine
, unsigned char);
2998 SET (external_dnr
, idnMax
, struct dnr_ext
);
2999 SET (external_pdr
, ipdMax
, struct pdr_ext
);
3000 SET (external_sym
, isymMax
, struct sym_ext
);
3001 SET (external_opt
, ioptMax
, struct opt_ext
);
3002 SET (external_aux
, iauxMax
, union aux_ext
);
3003 SET (ss
, issMax
, char);
3004 SET (ssext
, issExtMax
, char);
3005 SET (external_fdr
, ifdMax
, struct fdr_ext
);
3006 SET (external_rfd
, crfd
, struct rfd_ext
);
3007 SET (external_ext
, iextMax
, struct ext_ext
);
3010 /* Reset the counts so the second pass can use them to know how far
3012 symhdr
->ilineMax
= 0;
3016 symhdr
->isymMax
= 0;
3017 symhdr
->ioptMax
= 0;
3018 symhdr
->iauxMax
= 0;
3020 symhdr
->issExtMax
= 0;
3023 symhdr
->iextMax
= 0;
3025 /* Do the second pass: accumulate the debugging information. */
3026 ecoff_clear_output_flags (abfd
);
3027 for (ipass
= 0; ipass
< 2; ipass
++)
3029 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3031 if (((o
->flags
& SEC_CODE
) == 0) != ipass
)
3033 for (p
= o
->seclets_head
;
3034 p
!= (bfd_seclet_type
*) NULL
;
3037 if (p
->type
== bfd_indirect_seclet
)
3039 if (ecoff_get_debug (abfd
, p
, o
, relocateable
) == false)
3046 /* Put in the external symbols. */
3047 sym_ptr_ptr
= bfd_get_outsymbols (abfd
);
3048 if (sym_ptr_ptr
!= NULL
)
3051 struct ext_ext
*external_ext
;
3053 ssext
= ecoff_data (abfd
)->ssext
;
3054 external_ext
= ecoff_data (abfd
)->external_ext
;
3055 for (; *sym_ptr_ptr
!= NULL
; sym_ptr_ptr
++)
3060 sym_ptr
= *sym_ptr_ptr
;
3062 if ((sym_ptr
->flags
& BSF_DEBUGGING
) != 0
3063 || (sym_ptr
->flags
& BSF_LOCAL
) != 0)
3066 /* The enative pointer can be NULL for a symbol created by
3067 the linker via ecoff_make_empty_symbol. */
3068 if (bfd_asymbol_flavour (sym_ptr
) != bfd_target_ecoff_flavour
3069 || (((ecoff_symbol_type
*) sym_ptr
)->native
.enative
3070 == (struct ext_ext
*) NULL
))
3073 esym
.cobol_main
= 0;
3077 /* FIXME: we can do better than this for st and sc. */
3078 esym
.asym
.st
= stGlobal
;
3079 esym
.asym
.sc
= scAbs
;
3080 esym
.asym
.reserved
= 0;
3081 esym
.asym
.index
= indexNil
;
3085 ecoff_symbol_type
*ecoff_sym_ptr
;
3087 ecoff_sym_ptr
= (ecoff_symbol_type
*) sym_ptr
;
3088 if (ecoff_sym_ptr
->local
)
3090 ecoff_swap_ext_in (abfd
, ecoff_sym_ptr
->native
.enative
, &esym
);
3092 /* If we're producing an executable, move common symbols
3094 if (relocateable
== false)
3096 if (esym
.asym
.sc
== scCommon
)
3097 esym
.asym
.sc
= scBss
;
3098 else if (esym
.asym
.sc
== scSCommon
)
3099 esym
.asym
.sc
= scSBss
;
3102 /* Adjust the FDR index for the symbol by that used for
3104 esym
.ifd
+= ecoff_data (bfd_asymbol_bfd (sym_ptr
))->ifdbase
;
3107 esym
.asym
.iss
= symhdr
->issExtMax
;
3109 if (bfd_is_com_section (sym_ptr
->section
)
3110 || sym_ptr
->section
== &bfd_und_section
)
3111 esym
.asym
.value
= sym_ptr
->value
;
3113 esym
.asym
.value
= (sym_ptr
->value
3114 + sym_ptr
->section
->output_offset
3115 + sym_ptr
->section
->output_section
->vma
);
3117 ecoff_swap_ext_out (abfd
, &esym
, external_ext
+ symhdr
->iextMax
);
3119 ecoff_set_sym_index (sym_ptr
, symhdr
->iextMax
);
3123 strcpy (ssext
+ symhdr
->issExtMax
, sym_ptr
->name
);
3124 symhdr
->issExtMax
+= strlen (sym_ptr
->name
) + 1;
3128 /* Adjust the counts so that structures are longword aligned. */
3129 symhdr
->cbLine
= (symhdr
->cbLine
+ 3) &~ 3;
3130 symhdr
->issMax
= (symhdr
->issMax
+ 3) &~ 3;
3131 symhdr
->issExtMax
= (symhdr
->issExtMax
+ 3) &~ 3;
3136 /* Set the architecture. The only architecture we support here is
3137 mips. We set the architecture anyhow, since many callers ignore
3138 the return value. */
3141 ecoff_set_arch_mach (abfd
, arch
, machine
)
3143 enum bfd_architecture arch
;
3144 unsigned long machine
;
3146 bfd_default_set_arch_mach (abfd
, arch
, machine
);
3147 return arch
== bfd_arch_mips
;
3150 /* Get the size of the section headers. We do not output the .scommon
3151 section which we created in ecoff_mkobject. */
3154 ecoff_sizeof_headers (abfd
, reloc
)
3158 return FILHSZ
+ AOUTSZ
+ (abfd
->section_count
- 1) * SCNHSZ
;
3161 /* Calculate the file position for each section, and set
3165 ecoff_compute_section_file_positions (abfd
)
3173 if (bfd_get_start_address (abfd
))
3174 abfd
->flags
|= EXEC_P
;
3176 sofar
= ecoff_sizeof_headers (abfd
, false);
3179 for (current
= abfd
->sections
;
3180 current
!= (asection
*) NULL
;
3181 current
= current
->next
)
3183 /* Only deal with sections which have contents */
3184 if (! (current
->flags
& SEC_HAS_CONTENTS
)
3185 || strcmp (current
->name
, SCOMMON
) == 0)
3188 /* On Ultrix, the data sections in an executable file must be
3189 aligned to a page boundary within the file. This does not
3190 affect the section size, though. FIXME: Does this work for
3192 if ((abfd
->flags
& EXEC_P
) != 0
3193 && first_data
!= false
3194 && (current
->flags
& SEC_CODE
) == 0)
3196 sofar
= (sofar
+ ROUND_SIZE
- 1) &~ (ROUND_SIZE
- 1);
3200 /* Align the sections in the file to the same boundary on
3201 which they are aligned in virtual memory. */
3203 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3205 current
->filepos
= sofar
;
3207 sofar
+= current
->_raw_size
;
3209 /* make sure that this section is of the right size too */
3211 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
3212 current
->_raw_size
+= sofar
- old_sofar
;
3215 ecoff_data (abfd
)->reloc_filepos
= sofar
;
3218 /* Set the contents of a section. */
3221 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
3226 bfd_size_type count
;
3228 if (abfd
->output_has_begun
== false)
3229 ecoff_compute_section_file_positions (abfd
);
3231 bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
3234 return (bfd_write (location
, 1, count
, abfd
) == count
) ? true : false;
3239 /* Write out an ECOFF file. */
3242 ecoff_write_object_contents (abfd
)
3248 file_ptr reloc_base
;
3250 unsigned long reloc_size
;
3251 unsigned long text_size
;
3252 unsigned long text_start
;
3253 unsigned long data_size
;
3254 unsigned long data_start
;
3255 unsigned long bss_size
;
3256 struct internal_filehdr internal_f
;
3257 struct internal_aouthdr internal_a
;
3260 bfd_error
= system_call_error
;
3262 if(abfd
->output_has_begun
== false)
3263 ecoff_compute_section_file_positions(abfd
);
3265 if (abfd
->sections
!= (asection
*) NULL
)
3266 scn_base
= abfd
->sections
->filepos
;
3269 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
3273 for (current
= abfd
->sections
;
3274 current
!= (asection
*)NULL
;
3275 current
= current
->next
)
3277 if (strcmp (current
->name
, SCOMMON
) == 0)
3279 current
->target_index
= count
;
3281 if (current
->reloc_count
!= 0)
3283 bfd_size_type relsize
;
3285 current
->rel_filepos
= reloc_base
;
3286 relsize
= current
->reloc_count
* RELSZ
;
3287 reloc_size
+= relsize
;
3288 reloc_base
+= relsize
;
3291 current
->rel_filepos
= 0;
3294 sym_base
= reloc_base
+ reloc_size
;
3296 /* At least on Ultrix, the symbol table of an executable file must
3297 be aligned to a page boundary. FIXME: Is this true on other
3299 if ((abfd
->flags
& EXEC_P
) != 0)
3300 sym_base
= (sym_base
+ ROUND_SIZE
- 1) &~ (ROUND_SIZE
- 1);
3302 ecoff_data (abfd
)->sym_filepos
= sym_base
;
3304 text_size
= ecoff_sizeof_headers (abfd
, false);
3310 /* Write section headers to the file. */
3312 internal_f
.f_nscns
= 0;
3313 if (bfd_seek (abfd
, (file_ptr
) (FILHSZ
+ AOUTSZ
), SEEK_SET
) != 0)
3315 for (current
= abfd
->sections
;
3316 current
!= (asection
*) NULL
;
3317 current
= current
->next
)
3319 struct internal_scnhdr section
;
3322 if (strcmp (current
->name
, SCOMMON
) == 0)
3324 BFD_ASSERT (bfd_get_section_size_before_reloc (current
) == 0
3325 && current
->reloc_count
== 0);
3329 ++internal_f
.f_nscns
;
3331 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
3333 /* FIXME: is this correct for shared libraries? I think it is
3334 but I have no platform to check. Ian Lance Taylor. */
3335 vma
= bfd_get_section_vma (abfd
, current
);
3336 if (strcmp (current
->name
, _LIB
) == 0)
3337 section
.s_vaddr
= 0;
3339 section
.s_vaddr
= vma
;
3341 section
.s_paddr
= vma
;
3342 section
.s_size
= bfd_get_section_size_before_reloc (current
);
3344 /* If this section has no size or is unloadable then the scnptr
3346 if (current
->_raw_size
== 0
3347 || (current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
3348 section
.s_scnptr
= 0;
3350 section
.s_scnptr
= current
->filepos
;
3351 section
.s_relptr
= current
->rel_filepos
;
3353 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3354 object file produced by the assembler is supposed to point to
3355 information about how much room is required by objects of
3356 various different sizes. I think this only matters if we
3357 want the linker to compute the best size to use, or
3358 something. I don't know what happens if the information is
3360 section
.s_lnnoptr
= 0;
3362 section
.s_nreloc
= current
->reloc_count
;
3363 section
.s_nlnno
= 0;
3364 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
3370 ecoff_swap_scnhdr_out (abfd
, (PTR
) §ion
, (PTR
) &buff
);
3371 if (bfd_write ((PTR
) &buff
, 1, SCNHSZ
, abfd
) != SCNHSZ
)
3375 if ((section
.s_flags
& STYP_TEXT
) != 0)
3377 text_size
+= bfd_get_section_size_before_reloc (current
);
3378 if (text_start
== 0 || text_start
> vma
)
3381 else if ((section
.s_flags
& STYP_RDATA
) != 0
3382 || (section
.s_flags
& STYP_DATA
) != 0
3383 || (section
.s_flags
& STYP_LIT8
) != 0
3384 || (section
.s_flags
& STYP_LIT4
) != 0
3385 || (section
.s_flags
& STYP_SDATA
) != 0)
3387 data_size
+= bfd_get_section_size_before_reloc (current
);
3388 if (data_start
== 0 || data_start
> vma
)
3391 else if ((section
.s_flags
& STYP_BSS
) != 0
3392 || (section
.s_flags
& STYP_SBSS
) != 0)
3393 bss_size
+= bfd_get_section_size_before_reloc (current
);
3396 /* Set up the file header. */
3398 if (abfd
->xvec
->header_byteorder_big_p
!= false)
3401 internal_f
.f_magic
= ALPHAMAGIC
;
3404 We will NOT put a fucking timestamp in the header here. Every time you
3405 put it back, I will come in and take it out again. I'm sorry. This
3406 field does not belong here. We fill it with a 0 so it compares the
3407 same but is not a reasonable time. -- gnu@cygnus.com
3409 internal_f
.f_timdat
= 0;
3411 if (bfd_get_symcount (abfd
) != 0)
3413 /* The ECOFF f_nsyms field is not actually the number of
3414 symbols, it's the size of symbolic information header. */
3415 internal_f
.f_nsyms
= sizeof (struct hdr_ext
);
3416 internal_f
.f_symptr
= sym_base
;
3420 internal_f
.f_nsyms
= 0;
3421 internal_f
.f_symptr
= 0;
3424 internal_f
.f_opthdr
= AOUTSZ
;
3426 internal_f
.f_flags
= F_LNNO
;
3427 if (reloc_size
== 0)
3428 internal_f
.f_flags
|= F_RELFLG
;
3429 if (bfd_get_symcount (abfd
) == 0)
3430 internal_f
.f_flags
|= F_LSYMS
;
3431 if (abfd
->flags
& EXEC_P
)
3432 internal_f
.f_flags
|= F_EXEC
;
3434 if (! abfd
->xvec
->byteorder_big_p
)
3435 internal_f
.f_flags
|= F_AR32WR
;
3437 internal_f
.f_flags
|= F_AR32W
;
3439 /* Set up the ``optional'' header. */
3440 internal_a
.magic
= ZMAGIC
;
3442 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
3443 linker happy. But, is it right? */
3444 internal_a
.vstamp
= 0x20a;
3446 /* At least on Ultrix, these have to be rounded to page boundaries.
3447 FIXME: Is this true on other platforms? */
3448 internal_a
.tsize
= (text_size
+ ROUND_SIZE
- 1) &~ (ROUND_SIZE
- 1);
3449 internal_a
.text_start
= text_start
&~ (ROUND_SIZE
- 1);
3450 internal_a
.dsize
= (data_size
+ ROUND_SIZE
- 1) &~ (ROUND_SIZE
- 1);
3451 internal_a
.data_start
= data_start
&~ (ROUND_SIZE
- 1);
3453 /* On Ultrix, the initial portions of the .sbss and .bss segments
3454 are at the end of the data section. The bsize field in the
3455 optional header records how many bss bytes are required beyond
3456 those in the data section. The value is not rounded to a page
3458 if (bss_size
< internal_a
.dsize
- data_size
)
3461 bss_size
-= internal_a
.dsize
- data_size
;
3462 internal_a
.bsize
= bss_size
;
3463 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
3465 internal_a
.entry
= bfd_get_start_address (abfd
);
3467 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
3469 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
3470 for (i
= 0; i
< 4; i
++)
3471 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
3473 /* Write out the file header and the optional header. */
3475 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3480 ecoff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, (PTR
) &buff
);
3481 if (bfd_write ((PTR
) &buff
, 1, FILHSZ
, abfd
) != FILHSZ
)
3488 ecoff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, (PTR
) &buff
);
3489 if (bfd_write ((PTR
) &buff
, 1, AOUTSZ
, abfd
) != AOUTSZ
)
3493 /* Write out the relocs. */
3494 for (current
= abfd
->sections
;
3495 current
!= (asection
*) NULL
;
3496 current
= current
->next
)
3499 arelent
**reloc_ptr_ptr
;
3500 arelent
**reloc_end
;
3503 if (current
->reloc_count
== 0)
3506 buff
= (RELOC
*) bfd_alloc (abfd
, current
->reloc_count
* RELSZ
);
3507 if (buff
== (RELOC
*) NULL
)
3509 bfd_error
= no_memory
;
3513 reloc_ptr_ptr
= current
->orelocation
;
3514 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
3516 for (; reloc_ptr_ptr
< reloc_end
; reloc_ptr_ptr
++, out_ptr
++)
3520 struct internal_reloc in
;
3522 memset (&in
, 0, sizeof in
);
3524 reloc
= *reloc_ptr_ptr
;
3525 sym
= *reloc
->sym_ptr_ptr
;
3527 /* This must be an ECOFF reloc. */
3528 BFD_ASSERT (reloc
->howto
!= (reloc_howto_type
*) NULL
3529 && reloc
->howto
>= ecoff_howto_table
3531 < (ecoff_howto_table
+ ECOFF_HOWTO_COUNT
)));
3533 in
.r_vaddr
= reloc
->address
+ bfd_get_section_vma (abfd
, current
);
3534 in
.r_type
= reloc
->howto
->type
;
3536 /* If this is a REFHI reloc, the next one must be a REFLO
3537 reloc for the same symbol. */
3538 BFD_ASSERT (in
.r_type
!= ECOFF_R_REFHI
3539 || (reloc_ptr_ptr
< reloc_end
3540 && (reloc_ptr_ptr
[1]->howto
3541 != (reloc_howto_type
*) NULL
)
3542 && (reloc_ptr_ptr
[1]->howto
->type
3544 && (sym
== *reloc_ptr_ptr
[1]->sym_ptr_ptr
)));
3546 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
3548 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
3555 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
3556 if (strcmp (name
, ".text") == 0)
3557 in
.r_symndx
= RELOC_SECTION_TEXT
;
3558 else if (strcmp (name
, ".rdata") == 0)
3559 in
.r_symndx
= RELOC_SECTION_RDATA
;
3560 else if (strcmp (name
, ".data") == 0)
3561 in
.r_symndx
= RELOC_SECTION_DATA
;
3562 else if (strcmp (name
, ".sdata") == 0)
3563 in
.r_symndx
= RELOC_SECTION_SDATA
;
3564 else if (strcmp (name
, ".sbss") == 0)
3565 in
.r_symndx
= RELOC_SECTION_SBSS
;
3566 else if (strcmp (name
, ".bss") == 0)
3567 in
.r_symndx
= RELOC_SECTION_BSS
;
3568 else if (strcmp (name
, ".init") == 0)
3569 in
.r_symndx
= RELOC_SECTION_INIT
;
3570 else if (strcmp (name
, ".lit8") == 0)
3571 in
.r_symndx
= RELOC_SECTION_LIT8
;
3572 else if (strcmp (name
, ".lit4") == 0)
3573 in
.r_symndx
= RELOC_SECTION_LIT4
;
3579 ecoff_swap_reloc_out (abfd
, (PTR
) &in
, (PTR
) out_ptr
);
3582 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
3584 if (bfd_write ((PTR
) buff
, RELSZ
, current
->reloc_count
, abfd
)
3585 != RELSZ
* current
->reloc_count
)
3587 bfd_release (abfd
, (PTR
) buff
);
3590 /* Write out the symbolic debugging information. */
3591 if (bfd_get_symcount (abfd
) > 0)
3594 unsigned long sym_offset
;
3595 struct hdr_ext buff
;
3597 /* Set up the offsets in the symbolic header. */
3598 symhdr
= &ecoff_data (abfd
)->symbolic_header
;
3599 sym_offset
= ecoff_data (abfd
)->sym_filepos
+ sizeof (struct hdr_ext
);
3601 #define SET(offset, size, ptr) \
3602 if (symhdr->size == 0) \
3603 symhdr->offset = 0; \
3605 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3606 - (char *) ecoff_data (abfd)->raw_syments) \
3609 SET (cbLineOffset
, cbLine
, line
);
3610 SET (cbDnOffset
, idnMax
, external_dnr
);
3611 SET (cbPdOffset
, ipdMax
, external_pdr
);
3612 SET (cbSymOffset
, isymMax
, external_sym
);
3613 SET (cbOptOffset
, ioptMax
, external_opt
);
3614 SET (cbAuxOffset
, iauxMax
, external_aux
);
3615 SET (cbSsOffset
, issMax
, ss
);
3616 SET (cbSsExtOffset
, issExtMax
, ssext
);
3617 SET (cbFdOffset
, ifdMax
, external_fdr
);
3618 SET (cbRfdOffset
, crfd
, external_rfd
);
3619 SET (cbExtOffset
, iextMax
, external_ext
);
3622 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
,
3625 ecoff_swap_hdr_out (abfd
, &ecoff_data (abfd
)->symbolic_header
, &buff
);
3626 if (bfd_write ((PTR
) &buff
, 1, sizeof buff
, abfd
) != sizeof buff
)
3628 if (bfd_write ((PTR
) ecoff_data (abfd
)->raw_syments
, 1,
3629 ecoff_data (abfd
)->raw_size
, abfd
)
3630 != ecoff_data (abfd
)->raw_size
)
3637 /* Archive handling. ECOFF uses what appears to be a unique type of
3638 archive header (which I call an armap). The byte ordering of the
3639 armap and the contents are encoded in the name of the armap itself.
3640 At least for now, we only support archives with the same byte
3641 ordering in the armap and the contents.
3643 The first four bytes in the armap are the number of symbol
3644 definitions. This is always a power of two.
3646 This is followed by the symbol definitions. Each symbol definition
3647 occupies 8 bytes. The first four bytes are the offset from the
3648 start of the armap strings to the null-terminated string naming
3649 this symbol. The second four bytes are the file offset to the
3650 archive member which defines this symbol. If the second four bytes
3651 are 0, then this is not actually a symbol definition, and it should
3654 The symbols are hashed into the armap with a closed hashing scheme.
3655 See the functions below for the details of the algorithm.
3657 We could use the hash table when looking up symbols in a library.
3658 This would require a new BFD target entry point to replace the
3659 bfd_get_next_mapent function used by the linker.
3661 After the symbol definitions comes four bytes holding the size of
3662 the string table, followed by the string table itself. */
3664 /* The name of an archive headers looks like this:
3665 __________E[BL]E[BL]_ (with a trailing space).
3666 The trailing space is changed to an X if the archive is changed to
3667 indicate that the armap is out of date. */
3669 #define ARMAP_BIG_ENDIAN 'B'
3670 #define ARMAP_LITTLE_ENDIAN 'L'
3671 #define ARMAP_MARKER 'E'
3672 #define ARMAP_START "__________"
3673 #define ARMAP_HEADER_MARKER_INDEX 10
3674 #define ARMAP_HEADER_ENDIAN_INDEX 11
3675 #define ARMAP_OBJECT_MARKER_INDEX 12
3676 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3677 #define ARMAP_END_INDEX 14
3678 #define ARMAP_END "_ "
3680 /* This is a magic number used in the hashing algorithm. */
3681 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3683 /* This returns the hash value to use for a string. It also sets
3684 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3685 is the number of entries in the hash table, and HLOG is the log
3689 ecoff_armap_hash (s
, rehash
, size
, hlog
)
3691 unsigned int *rehash
;
3699 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
3700 hash
*= ARMAP_HASH_MAGIC
;
3701 *rehash
= (hash
& (size
- 1)) | 1;
3702 return hash
>> (32 - hlog
);
3705 /* Read in the armap. */
3708 ecoff_slurp_armap (abfd
)
3713 struct areltdata
*mapdata
;
3714 bfd_size_type parsed_size
;
3716 struct artdata
*ardata
;
3719 struct symdef
*symdef_ptr
;
3722 /* Get the name of the first element. */
3723 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
3729 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
3731 /* See if the first element is an armap. */
3732 if (strncmp (nextname
, ARMAP_START
, sizeof ARMAP_START
- 1) != 0
3733 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3734 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3735 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3736 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3737 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3738 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3739 || strncmp (nextname
+ ARMAP_END_INDEX
,
3740 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3742 bfd_has_map (abfd
) = false;
3746 /* Make sure we have the right byte ordering. */
3747 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3748 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
3749 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3750 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
3752 bfd_error
= wrong_format
;
3756 /* Read in the armap. */
3757 ardata
= bfd_ardata (abfd
);
3758 mapdata
= snarf_ar_hdr (abfd
);
3759 if (mapdata
== (struct areltdata
*) NULL
)
3761 parsed_size
= mapdata
->parsed_size
;
3762 bfd_release (abfd
, (PTR
) mapdata
);
3764 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3765 if (raw_armap
== (char *) NULL
)
3767 bfd_error
= no_memory
;
3771 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
3773 bfd_error
= malformed_archive
;
3774 bfd_release (abfd
, (PTR
) raw_armap
);
3778 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
3780 ardata
->symdef_count
= 0;
3781 ardata
->cache
= (struct ar_cache
*) NULL
;
3783 /* Hack: overlay the symdefs on top of the raw archive data. This
3784 is the way do_slurp_bsd_armap works. */
3785 raw_ptr
= raw_armap
+ LONG_SIZE
;
3786 symdef_ptr
= (struct symdef
*) raw_ptr
;
3787 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3788 stringbase
= raw_ptr
+ count
* (2 * LONG_SIZE
) + LONG_SIZE
;
3790 #ifdef CHECK_ARMAP_HASH
3794 /* Double check that I have the hashing algorithm right by making
3795 sure that every symbol can be looked up successfully. */
3797 for (i
= 1; i
< count
; i
<<= 1)
3799 BFD_ASSERT (i
== count
);
3801 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3803 unsigned int name_offset
, file_offset
;
3804 unsigned int hash
, rehash
, srch
;
3806 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3807 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3808 if (file_offset
== 0)
3810 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3815 /* See if we can rehash to this location. */
3816 for (srch
= (hash
+ rehash
) & (count
- 1);
3817 srch
!= hash
&& srch
!= i
;
3818 srch
= (srch
+ rehash
) & (count
- 1))
3819 BFD_ASSERT (bfd_h_get_32 (abfd
,
3822 + (srch
* 2 * LONG_SIZE
)
3825 BFD_ASSERT (srch
== i
);
3829 raw_ptr
= raw_armap
+ LONG_SIZE
;
3830 #endif /* CHECK_ARMAP_HASH */
3832 for (i
= 0; i
< count
; i
++, raw_ptr
+= 2 * LONG_SIZE
)
3834 unsigned int name_offset
, file_offset
;
3836 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3837 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ LONG_SIZE
));
3838 if (file_offset
== 0)
3840 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3841 symdef_ptr
->file_offset
= file_offset
;
3843 ++ardata
->symdef_count
;
3846 ardata
->first_file_filepos
= bfd_tell (abfd
);
3847 /* Pad to an even boundary. */
3848 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3850 bfd_has_map (abfd
) = true;
3855 /* Write out an armap. */
3858 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3860 unsigned int elength
;
3862 unsigned int orl_count
;
3865 unsigned int hashsize
, hashlog
;
3866 unsigned int symdefsize
;
3868 unsigned int stringsize
;
3869 unsigned int mapsize
;
3872 struct stat statbuf
;
3874 bfd_byte temp
[LONG_SIZE
];
3875 bfd_byte
*hashtable
;
3879 /* Ultrix appears to use as a hash table size the least power of two
3880 greater than twice the number of entries. */
3881 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3883 hashsize
= 1 << hashlog
;
3885 symdefsize
= hashsize
* 2 * LONG_SIZE
;
3887 stringsize
= stridx
+ padit
;
3889 /* Include 8 bytes to store symdefsize and stringsize in output. */
3890 mapsize
= LONG_SIZE
+ symdefsize
+ stringsize
+ LONG_SIZE
;
3892 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3894 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3896 /* Work out the ECOFF armap name. */
3897 strcpy (hdr
.ar_name
, ARMAP_START
);
3898 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3899 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3900 (abfd
->xvec
->header_byteorder_big_p
3902 : ARMAP_LITTLE_ENDIAN
);
3903 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3904 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3905 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3906 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3908 /* Write the timestamp of the archive header to be just a little bit
3909 later than the timestamp of the file, otherwise the linker will
3910 complain that the index is out of date. Actually, the Ultrix
3911 linker just checks the archive name; the GNU linker may check the
3913 stat (abfd
->filename
, &statbuf
);
3914 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3916 /* The DECstation uses zeroes for the uid, gid and mode of the
3918 hdr
.ar_uid
[0] = '0';
3919 hdr
.ar_gid
[0] = '0';
3920 hdr
.ar_mode
[0] = '0';
3922 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3924 hdr
.ar_fmag
[0] = '`';
3925 hdr
.ar_fmag
[1] = '\n';
3927 /* Turn all null bytes in the header into spaces. */
3928 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3929 if (((char *)(&hdr
))[i
] == '\0')
3930 (((char *)(&hdr
))[i
]) = ' ';
3932 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3933 != sizeof (struct ar_hdr
))
3936 bfd_h_put_32 (abfd
, hashsize
, temp
);
3937 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
3940 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3942 current
= abfd
->archive_head
;
3944 for (i
= 0; i
< orl_count
; i
++)
3946 unsigned int hash
, rehash
;
3948 /* Advance firstreal to the file position of this archive
3950 if (((bfd
*) map
[i
].pos
) != last_elt
)
3954 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3955 firstreal
+= firstreal
% 2;
3956 current
= current
->next
;
3958 while (current
!= (bfd
*) map
[i
].pos
);
3963 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3964 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
3965 + (hash
* 2 * LONG_SIZE
)
3971 /* The desired slot is already taken. */
3972 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3974 srch
= (srch
+ rehash
) & (hashsize
- 1))
3975 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
3976 + (srch
* 2 * LONG_SIZE
)
3981 BFD_ASSERT (srch
!= hash
);
3986 bfd_h_put_32 (abfd
, map
[i
].namidx
,
3987 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
));
3988 bfd_h_put_32 (abfd
, firstreal
,
3989 (PTR
) (hashtable
+ hash
* 2 * LONG_SIZE
+ LONG_SIZE
));
3992 if (bfd_write (hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3995 bfd_release (abfd
, hashtable
);
3997 /* Now write the strings. */
3998 bfd_h_put_32 (abfd
, stringsize
, temp
);
3999 if (bfd_write (temp
, 1, LONG_SIZE
, abfd
) != LONG_SIZE
)
4001 for (i
= 0; i
< orl_count
; i
++)
4005 len
= strlen (*map
[i
].name
) + 1;
4006 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
4010 /* The spec sez this should be a newline. But in order to be
4011 bug-compatible for DECstation ar we use a null. */
4014 if (bfd_write ("\0", 1, 1, abfd
) != 1)
4021 /* We just use the generic extended name support. This is a GNU
4023 #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
4025 /* See whether this BFD is an archive. If it is, read in the armap
4026 and the extended name table. */
4029 ecoff_archive_p (abfd
)
4032 char armag
[SARMAG
+ 1];
4034 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
4035 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
4037 bfd_error
= wrong_format
;
4038 return (bfd_target
*) NULL
;
4041 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
4042 involves a cast, we can't do it as the left operand of
4044 abfd
->tdata
.aout_ar_data
=
4045 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
4047 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
4049 bfd_error
= no_memory
;
4050 return (bfd_target
*) NULL
;
4053 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
4055 if (ecoff_slurp_armap (abfd
) == false
4056 || ecoff_slurp_extended_name_table (abfd
) == false)
4058 bfd_release (abfd
, bfd_ardata (abfd
));
4059 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
4060 return (bfd_target
*) NULL
;
4066 /* This is the COFF backend structure. The backend_data field of the
4067 bfd_target structure is set to this. The section reading code in
4068 coffgen.c uses this structure. */
4070 static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table
= {
4071 (void (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_in */
4072 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_in */
4073 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_in */
4074 (unsigned (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_out */
4075 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_out */
4076 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_out */
4077 ecoff_swap_reloc_out
, ecoff_swap_filehdr_out
, ecoff_swap_aouthdr_out
,
4078 ecoff_swap_scnhdr_out
,
4079 FILHSZ
, AOUTSZ
, SCNHSZ
, 0, 0, 0, true,
4080 ecoff_swap_filehdr_in
, ecoff_swap_aouthdr_in
, ecoff_swap_scnhdr_in
,
4081 ecoff_bad_format_hook
, ecoff_set_arch_mach_hook
, ecoff_mkobject_hook
,
4082 ecoff_styp_to_sec_flags
, ecoff_make_section_hook
, ecoff_set_alignment_hook
,
4083 ecoff_slurp_symbol_table
4086 /* get_lineno could be written for ECOFF, but it would currently only
4087 be useful for linking ECOFF and COFF files together, which doesn't
4089 #define ecoff_get_lineno \
4090 ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr)
4092 /* These bfd_target functions are defined in other files. */
4094 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
4095 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
4096 #define ecoff_core_file_matches_executable_p \
4097 _bfd_dummy_core_file_matches_executable_p
4098 #define ecoff_truncate_arname bfd_dont_truncate_arname
4099 #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file
4100 #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
4101 #define ecoff_get_section_contents bfd_generic_get_section_contents
4102 #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4103 #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup
4104 #define ecoff_bfd_debug_info_start bfd_void
4105 #define ecoff_bfd_debug_info_end bfd_void
4106 #define ecoff_bfd_debug_info_accumulate \
4107 ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void)
4108 #define ecoff_bfd_get_relocated_section_contents \
4109 bfd_generic_get_relocated_section_contents
4110 #define ecoff_bfd_relax_section bfd_generic_relax_section
4111 #define ecoff_bfd_make_debug_symbol \
4112 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
4114 bfd_target ecoffalpha_little_vec
=
4116 "ecoff-littlealpha", /* name */
4117 bfd_target_ecoff_flavour
,
4118 false, /* data byte order is little */
4119 false, /* header byte order is little */
4121 (HAS_RELOC
| EXEC_P
| /* object flags */
4122 HAS_LINENO
| HAS_DEBUG
|
4123 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
),
4125 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect
4127 0, /* leading underscore */
4128 '/', /* ar_pad_char */
4129 15, /* ar_max_namelen */
4130 3, /* minimum alignment power */
4131 _do_getl64
, _do_getl_signed_64
, _do_putl64
,
4132 _do_getl32
, _do_getl_signed_32
, _do_putl32
,
4133 _do_getl16
, _do_getl_signed_16
, _do_putl16
, /* data */
4134 _do_getl64
, _do_getl_signed_64
, _do_putl64
,
4135 _do_getl32
, _do_getl_signed_32
, _do_putl32
,
4136 _do_getl16
, _do_getl_signed_16
, _do_putl16
, /* hdrs */
4138 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
4139 ecoff_archive_p
, _bfd_dummy_target
},
4140 {bfd_false
, ecoff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
4142 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
4143 _bfd_write_archive_contents
, bfd_false
},
4145 (PTR
) &bfd_ecoff_std_swap_table