1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Original version by Per Bothner.
5 Full support added by Ian Lance Taylor, ian@cygnus.com.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "aout/ranlib.h"
29 #include "aout/stab_gnu.h"
31 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
32 some other stuff which we don't want and which conflicts with stuff
35 #include "aout/aout64.h"
38 #undef obj_sym_filepos
40 #include "coff/internal.h"
42 #include "coff/symconst.h"
43 #include "coff/ecoff.h"
47 /* Prototypes for static functions. */
49 static int ecoff_get_magic
51 static long ecoff_sec_to_styp_flags
52 PARAMS ((const char *, flagword
));
53 static bfd_boolean ecoff_slurp_symbolic_header
55 static bfd_boolean ecoff_set_symbol_info
56 PARAMS ((bfd
*, SYMR
*, asymbol
*, int, int));
57 static void ecoff_emit_aggregate
58 PARAMS ((bfd
*, FDR
*, char *, RNDXR
*, long, const char *));
59 static char *ecoff_type_to_string
60 PARAMS ((bfd
*, FDR
*, unsigned int));
61 static bfd_boolean ecoff_slurp_reloc_table
62 PARAMS ((bfd
*, asection
*, asymbol
**));
63 static int ecoff_sort_hdrs
64 PARAMS ((const PTR
, const PTR
));
65 static bfd_boolean ecoff_compute_section_file_positions
67 static bfd_size_type ecoff_compute_reloc_file_positions
69 static bfd_boolean ecoff_get_extr
70 PARAMS ((asymbol
*, EXTR
*));
71 static void ecoff_set_index
72 PARAMS ((asymbol
*, bfd_size_type
));
73 static unsigned int ecoff_armap_hash
74 PARAMS ((const char *, unsigned int *, unsigned int, unsigned int));
76 /* This stuff is somewhat copied from coffcode.h. */
78 static asection bfd_debug_section
=
80 /* name, id, index, next, flags, user_set_vma, reloc_done, */
81 "*DEBUG*", 0, 0, NULL
, 0, 0, 0,
82 /* linker_mark, linker_has_input, gc_mark, segment_mark, */
84 /* vma, lma, _cooked_size, _raw_size, */
86 /* output_offset, output_section, alignment_power, */
88 /* relocation, orelocation, reloc_count, filepos, rel_filepos, */
90 /* line_filepos, userdata, contents, lineno, lineno_count, */
91 0, NULL
, NULL
, NULL
, 0,
92 /* entsize, comdat, moving_line_filepos, */
94 /* target_index, used_by_bfd, constructor_chain, owner, */
97 (struct symbol_cache_entry
*) NULL
,
99 (struct symbol_cache_entry
**) NULL
,
100 /* link_order_head, link_order_tail */
104 /* Create an ECOFF object. */
107 _bfd_ecoff_mkobject (abfd
)
110 bfd_size_type amt
= sizeof (ecoff_data_type
);
112 abfd
->tdata
.ecoff_obj_data
= (struct ecoff_tdata
*) bfd_zalloc (abfd
, amt
);
113 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
119 /* This is a hook called by coff_real_object_p to create any backend
120 specific information. */
123 _bfd_ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
128 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
129 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
130 ecoff_data_type
*ecoff
;
132 if (! _bfd_ecoff_mkobject (abfd
))
135 ecoff
= ecoff_data (abfd
);
137 ecoff
->sym_filepos
= internal_f
->f_symptr
;
139 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
143 ecoff
->text_start
= internal_a
->text_start
;
144 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
145 ecoff
->gp
= internal_a
->gp_value
;
146 ecoff
->gprmask
= internal_a
->gprmask
;
147 for (i
= 0; i
< 4; i
++)
148 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
149 ecoff
->fprmask
= internal_a
->fprmask
;
150 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
151 abfd
->flags
|= D_PAGED
;
153 abfd
->flags
&=~ D_PAGED
;
156 /* It turns out that no special action is required by the MIPS or
157 Alpha ECOFF backends. They have different information in the
158 a.out header, but we just copy it all (e.g., gprmask, cprmask and
159 fprmask) and let the swapping routines ensure that only relevant
160 information is written out. */
165 /* Initialize a new section. */
168 _bfd_ecoff_new_section_hook (abfd
, section
)
169 bfd
*abfd ATTRIBUTE_UNUSED
;
172 section
->alignment_power
= 4;
174 if (strcmp (section
->name
, _TEXT
) == 0
175 || strcmp (section
->name
, _INIT
) == 0
176 || strcmp (section
->name
, _FINI
) == 0)
177 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
178 else if (strcmp (section
->name
, _DATA
) == 0
179 || strcmp (section
->name
, _SDATA
) == 0)
180 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
181 else if (strcmp (section
->name
, _RDATA
) == 0
182 || strcmp (section
->name
, _LIT8
) == 0
183 || strcmp (section
->name
, _LIT4
) == 0
184 || strcmp (section
->name
, _RCONST
) == 0
185 || strcmp (section
->name
, _PDATA
) == 0)
186 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
187 else if (strcmp (section
->name
, _BSS
) == 0
188 || strcmp (section
->name
, _SBSS
) == 0)
189 section
->flags
|= SEC_ALLOC
;
190 else if (strcmp (section
->name
, _LIB
) == 0)
191 /* An Irix 4 shared libary. */
192 section
->flags
|= SEC_COFF_SHARED_LIBRARY
;
194 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
195 uncertain about .init on some systems and I don't know how shared
201 /* Determine the machine architecture and type. This is called from
202 the generic COFF routines. It is the inverse of ecoff_get_magic,
203 below. This could be an ECOFF backend routine, with one version
204 for each target, but there aren't all that many ECOFF targets. */
207 _bfd_ecoff_set_arch_mach_hook (abfd
, filehdr
)
211 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
212 enum bfd_architecture arch
;
215 switch (internal_f
->f_magic
)
218 case MIPS_MAGIC_LITTLE
:
220 arch
= bfd_arch_mips
;
221 mach
= bfd_mach_mips3000
;
224 case MIPS_MAGIC_LITTLE2
:
225 case MIPS_MAGIC_BIG2
:
226 /* MIPS ISA level 2: the r6000. */
227 arch
= bfd_arch_mips
;
228 mach
= bfd_mach_mips6000
;
231 case MIPS_MAGIC_LITTLE3
:
232 case MIPS_MAGIC_BIG3
:
233 /* MIPS ISA level 3: the r4000. */
234 arch
= bfd_arch_mips
;
235 mach
= bfd_mach_mips4000
;
239 arch
= bfd_arch_alpha
;
244 arch
= bfd_arch_obscure
;
249 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
252 /* Get the magic number to use based on the architecture and machine.
253 This is the inverse of _bfd_ecoff_set_arch_mach_hook, above. */
256 ecoff_get_magic (abfd
)
261 switch (bfd_get_arch (abfd
))
264 switch (bfd_get_mach (abfd
))
268 case bfd_mach_mips3000
:
269 big
= MIPS_MAGIC_BIG
;
270 little
= MIPS_MAGIC_LITTLE
;
273 case bfd_mach_mips6000
:
274 big
= MIPS_MAGIC_BIG2
;
275 little
= MIPS_MAGIC_LITTLE2
;
278 case bfd_mach_mips4000
:
279 big
= MIPS_MAGIC_BIG3
;
280 little
= MIPS_MAGIC_LITTLE3
;
284 return bfd_big_endian (abfd
) ? big
: little
;
295 /* Get the section s_flags to use for a section. */
298 ecoff_sec_to_styp_flags (name
, flags
)
306 if (strcmp (name
, _TEXT
) == 0)
308 else if (strcmp (name
, _DATA
) == 0)
310 else if (strcmp (name
, _SDATA
) == 0)
312 else if (strcmp (name
, _RDATA
) == 0)
314 else if (strcmp (name
, _LITA
) == 0)
316 else if (strcmp (name
, _LIT8
) == 0)
318 else if (strcmp (name
, _LIT4
) == 0)
320 else if (strcmp (name
, _BSS
) == 0)
322 else if (strcmp (name
, _SBSS
) == 0)
324 else if (strcmp (name
, _INIT
) == 0)
325 styp
= STYP_ECOFF_INIT
;
326 else if (strcmp (name
, _FINI
) == 0)
327 styp
= STYP_ECOFF_FINI
;
328 else if (strcmp (name
, _PDATA
) == 0)
330 else if (strcmp (name
, _XDATA
) == 0)
332 else if (strcmp (name
, _LIB
) == 0)
333 styp
= STYP_ECOFF_LIB
;
334 else if (strcmp (name
, _GOT
) == 0)
336 else if (strcmp (name
, _HASH
) == 0)
338 else if (strcmp (name
, _DYNAMIC
) == 0)
340 else if (strcmp (name
, _LIBLIST
) == 0)
342 else if (strcmp (name
, _RELDYN
) == 0)
344 else if (strcmp (name
, _CONFLIC
) == 0)
346 else if (strcmp (name
, _DYNSTR
) == 0)
348 else if (strcmp (name
, _DYNSYM
) == 0)
350 else if (strcmp (name
, _COMMENT
) == 0)
353 flags
&=~ SEC_NEVER_LOAD
;
355 else if (strcmp (name
, _RCONST
) == 0)
357 else if (flags
& SEC_CODE
)
359 else if (flags
& SEC_DATA
)
361 else if (flags
& SEC_READONLY
)
363 else if (flags
& SEC_LOAD
)
368 if (flags
& SEC_NEVER_LOAD
)
374 /* Get the BFD flags to use for a section. */
377 _bfd_ecoff_styp_to_sec_flags (abfd
, hdr
, name
, section
, flags_ptr
)
378 bfd
*abfd ATTRIBUTE_UNUSED
;
380 const char *name ATTRIBUTE_UNUSED
;
381 asection
*section ATTRIBUTE_UNUSED
;
382 flagword
* flags_ptr
;
384 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
385 long styp_flags
= internal_s
->s_flags
;
386 flagword sec_flags
= 0;
388 if (styp_flags
& STYP_NOLOAD
)
389 sec_flags
|= SEC_NEVER_LOAD
;
391 /* For 386 COFF, at least, an unloadable text or data section is
392 actually a shared library section. */
393 if ((styp_flags
& STYP_TEXT
)
394 || (styp_flags
& STYP_ECOFF_INIT
)
395 || (styp_flags
& STYP_ECOFF_FINI
)
396 || (styp_flags
& STYP_DYNAMIC
)
397 || (styp_flags
& STYP_LIBLIST
)
398 || (styp_flags
& STYP_RELDYN
)
399 || styp_flags
== STYP_CONFLIC
400 || (styp_flags
& STYP_DYNSTR
)
401 || (styp_flags
& STYP_DYNSYM
)
402 || (styp_flags
& STYP_HASH
))
404 if (sec_flags
& SEC_NEVER_LOAD
)
405 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
407 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
409 else if ((styp_flags
& STYP_DATA
)
410 || (styp_flags
& STYP_RDATA
)
411 || (styp_flags
& STYP_SDATA
)
412 || styp_flags
== STYP_PDATA
413 || styp_flags
== STYP_XDATA
414 || (styp_flags
& STYP_GOT
)
415 || styp_flags
== STYP_RCONST
)
417 if (sec_flags
& SEC_NEVER_LOAD
)
418 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
420 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
421 if ((styp_flags
& STYP_RDATA
)
422 || styp_flags
== STYP_PDATA
423 || styp_flags
== STYP_RCONST
)
424 sec_flags
|= SEC_READONLY
;
426 else if ((styp_flags
& STYP_BSS
)
427 || (styp_flags
& STYP_SBSS
))
428 sec_flags
|= SEC_ALLOC
;
429 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
430 sec_flags
|= SEC_NEVER_LOAD
;
431 else if ((styp_flags
& STYP_LITA
)
432 || (styp_flags
& STYP_LIT8
)
433 || (styp_flags
& STYP_LIT4
))
434 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
435 else if (styp_flags
& STYP_ECOFF_LIB
)
436 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
438 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
440 * flags_ptr
= sec_flags
;
444 /* Read in the symbolic header for an ECOFF object file. */
447 ecoff_slurp_symbolic_header (abfd
)
450 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
451 bfd_size_type external_hdr_size
;
453 HDRR
*internal_symhdr
;
455 /* See if we've already read it in. */
456 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
457 backend
->debug_swap
.sym_magic
)
460 /* See whether there is a symbolic header. */
461 if (ecoff_data (abfd
)->sym_filepos
== 0)
463 bfd_get_symcount (abfd
) = 0;
467 /* At this point bfd_get_symcount (abfd) holds the number of symbols
468 as read from the file header, but on ECOFF this is always the
469 size of the symbolic information header. It would be cleaner to
470 handle this when we first read the file in coffgen.c. */
471 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
472 if (bfd_get_symcount (abfd
) != external_hdr_size
)
474 bfd_set_error (bfd_error_bad_value
);
478 /* Read the symbolic information header. */
479 raw
= (PTR
) bfd_malloc (external_hdr_size
);
483 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) != 0
484 || bfd_bread (raw
, external_hdr_size
, abfd
) != external_hdr_size
)
486 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
487 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
489 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
491 bfd_set_error (bfd_error_bad_value
);
495 /* Now we can get the correct number of symbols. */
496 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
497 + internal_symhdr
->iextMax
);
508 /* Read in and swap the important symbolic information for an ECOFF
509 object file. This is called by gdb via the read_debug_info entry
510 point in the backend structure. */
513 _bfd_ecoff_slurp_symbolic_info (abfd
, ignore
, debug
)
515 asection
*ignore ATTRIBUTE_UNUSED
;
516 struct ecoff_debug_info
*debug
;
518 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
519 HDRR
*internal_symhdr
;
520 bfd_size_type raw_base
;
521 bfd_size_type raw_size
;
523 bfd_size_type external_fdr_size
;
527 bfd_size_type raw_end
;
528 bfd_size_type cb_end
;
532 BFD_ASSERT (debug
== &ecoff_data (abfd
)->debug_info
);
534 /* Check whether we've already gotten it, and whether there's any to
536 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
538 if (ecoff_data (abfd
)->sym_filepos
== 0)
540 bfd_get_symcount (abfd
) = 0;
544 if (! ecoff_slurp_symbolic_header (abfd
))
547 internal_symhdr
= &debug
->symbolic_header
;
549 /* Read all the symbolic information at once. */
550 raw_base
= (ecoff_data (abfd
)->sym_filepos
551 + backend
->debug_swap
.external_hdr_size
);
553 /* Alpha ecoff makes the determination of raw_size difficult. It has
554 an undocumented debug data section between the symhdr and the first
555 documented section. And the ordering of the sections varies between
556 statically and dynamically linked executables.
557 If bfd supports SEEK_END someday, this code could be simplified. */
560 #define UPDATE_RAW_END(start, count, size) \
561 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
562 if (cb_end > raw_end) \
565 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
566 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
567 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
568 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
569 /* eraxxon@alumni.rice.edu: ioptMax refers to the size of the
570 optimization symtab, not the number of entries */
571 UPDATE_RAW_END (cbOptOffset
, ioptMax
, sizeof (char));
572 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
573 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
574 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
575 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
576 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
577 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
579 #undef UPDATE_RAW_END
581 raw_size
= raw_end
- raw_base
;
584 ecoff_data (abfd
)->sym_filepos
= 0;
587 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
591 pos
= ecoff_data (abfd
)->sym_filepos
;
592 pos
+= backend
->debug_swap
.external_hdr_size
;
593 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
594 || bfd_bread (raw
, raw_size
, abfd
) != raw_size
)
596 bfd_release (abfd
, raw
);
600 ecoff_data (abfd
)->raw_syments
= raw
;
602 /* Get pointers for the numeric offsets in the HDRR structure. */
603 #define FIX(off1, off2, type) \
604 if (internal_symhdr->off1 == 0) \
605 debug->off2 = (type) NULL; \
607 debug->off2 = (type) ((char *) raw \
608 + (internal_symhdr->off1 \
611 FIX (cbLineOffset
, line
, unsigned char *);
612 FIX (cbDnOffset
, external_dnr
, PTR
);
613 FIX (cbPdOffset
, external_pdr
, PTR
);
614 FIX (cbSymOffset
, external_sym
, PTR
);
615 FIX (cbOptOffset
, external_opt
, PTR
);
616 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
617 FIX (cbSsOffset
, ss
, char *);
618 FIX (cbSsExtOffset
, ssext
, char *);
619 FIX (cbFdOffset
, external_fdr
, PTR
);
620 FIX (cbRfdOffset
, external_rfd
, PTR
);
621 FIX (cbExtOffset
, external_ext
, PTR
);
624 /* I don't want to always swap all the data, because it will just
625 waste time and most programs will never look at it. The only
626 time the linker needs most of the debugging information swapped
627 is when linking big-endian and little-endian MIPS object files
628 together, which is not a common occurrence.
630 We need to look at the fdr to deal with a lot of information in
631 the symbols, so we swap them here. */
632 amt
= internal_symhdr
->ifdMax
;
633 amt
*= sizeof (struct fdr
);
634 debug
->fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
635 if (debug
->fdr
== NULL
)
637 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
638 fdr_ptr
= debug
->fdr
;
639 fraw_src
= (char *) debug
->external_fdr
;
640 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
641 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
642 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
647 /* ECOFF symbol table routines. The ECOFF symbol table is described
648 in gcc/mips-tfile.c. */
650 /* ECOFF uses two common sections. One is the usual one, and the
651 other is for small objects. All the small objects are kept
652 together, and then referenced via the gp pointer, which yields
653 faster assembler code. This is what we use for the small common
655 static asection ecoff_scom_section
;
656 static asymbol ecoff_scom_symbol
;
657 static asymbol
*ecoff_scom_symbol_ptr
;
659 /* Create an empty symbol. */
662 _bfd_ecoff_make_empty_symbol (abfd
)
665 ecoff_symbol_type
*new;
666 bfd_size_type amt
= sizeof (ecoff_symbol_type
);
668 new = (ecoff_symbol_type
*) bfd_zalloc (abfd
, amt
);
669 if (new == (ecoff_symbol_type
*) NULL
)
670 return (asymbol
*) NULL
;
671 new->symbol
.section
= (asection
*) NULL
;
672 new->fdr
= (FDR
*) NULL
;
675 new->symbol
.the_bfd
= abfd
;
679 /* Set the BFD flags and section for an ECOFF symbol. */
682 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, weak
)
689 asym
->the_bfd
= abfd
;
690 asym
->value
= ecoff_sym
->value
;
691 asym
->section
= &bfd_debug_section
;
694 /* Most symbol types are just for debugging. */
695 switch (ecoff_sym
->st
)
704 if (ECOFF_IS_STAB (ecoff_sym
))
706 asym
->flags
= BSF_DEBUGGING
;
711 asym
->flags
= BSF_DEBUGGING
;
716 asym
->flags
= BSF_EXPORT
| BSF_WEAK
;
718 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
721 asym
->flags
= BSF_LOCAL
;
722 /* Normally, a local stProc symbol will have a corresponding
723 external symbol. We mark the local symbol as a debugging
724 symbol, in order to prevent nm from printing both out.
725 Similarly, we mark stLabel and stabs symbols as debugging
726 symbols. In both cases, we do want to set the value
727 correctly based on the symbol class. */
728 if (ecoff_sym
->st
== stProc
729 || ecoff_sym
->st
== stLabel
730 || ECOFF_IS_STAB (ecoff_sym
))
731 asym
->flags
|= BSF_DEBUGGING
;
734 if (ecoff_sym
->st
== stProc
|| ecoff_sym
->st
== stStaticProc
)
735 asym
->flags
|= BSF_FUNCTION
;
737 switch (ecoff_sym
->sc
)
740 /* Used for compiler generated labels. Leave them in the
741 debugging section, and mark them as local. If BSF_DEBUGGING
742 is set, then nm does not display them for some reason. If no
743 flags are set then the linker whines about them. */
744 asym
->flags
= BSF_LOCAL
;
747 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
748 asym
->value
-= asym
->section
->vma
;
751 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
752 asym
->value
-= asym
->section
->vma
;
755 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
756 asym
->value
-= asym
->section
->vma
;
759 asym
->flags
= BSF_DEBUGGING
;
762 asym
->section
= bfd_abs_section_ptr
;
765 asym
->section
= bfd_und_section_ptr
;
775 asym
->flags
= BSF_DEBUGGING
;
778 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
779 asym
->value
-= asym
->section
->vma
;
782 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
783 asym
->value
-= asym
->section
->vma
;
786 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
787 asym
->value
-= asym
->section
->vma
;
790 asym
->flags
= BSF_DEBUGGING
;
793 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
795 asym
->section
= bfd_com_section_ptr
;
801 if (ecoff_scom_section
.name
== NULL
)
803 /* Initialize the small common section. */
804 ecoff_scom_section
.name
= SCOMMON
;
805 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
806 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
807 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
808 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
809 ecoff_scom_symbol
.name
= SCOMMON
;
810 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
811 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
812 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
814 asym
->section
= &ecoff_scom_section
;
819 asym
->flags
= BSF_DEBUGGING
;
822 asym
->section
= bfd_und_section_ptr
;
827 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
828 asym
->value
-= asym
->section
->vma
;
833 asym
->flags
= BSF_DEBUGGING
;
836 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
837 asym
->value
-= asym
->section
->vma
;
840 asym
->section
= bfd_make_section_old_way (abfd
, ".rconst");
841 asym
->value
-= asym
->section
->vma
;
847 /* Look for special constructors symbols and make relocation entries
848 in a special construction section. These are produced by the
849 -fgnu-linker argument to g++. */
850 if (ECOFF_IS_STAB (ecoff_sym
))
852 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
862 /* This code is no longer needed. It used to be used to
863 make the linker handle set symbols, but they are now
864 handled in the add_symbols routine instead. */
868 arelent_chain
*reloc_chain
;
869 unsigned int bitsize
;
872 /* Get a section with the same name as the symbol (usually
873 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
874 name ___CTOR_LIST (three underscores). We need
875 __CTOR_LIST (two underscores), since ECOFF doesn't use
876 a leading underscore. This should be handled by gcc,
877 but instead we do it here. Actually, this should all
878 be done differently anyhow. */
879 name
= bfd_asymbol_name (asym
);
880 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
885 section
= bfd_get_section_by_name (abfd
, name
);
886 if (section
== (asection
*) NULL
)
890 amt
= strlen (name
) + 1;
891 copy
= (char *) bfd_alloc (abfd
, amt
);
895 section
= bfd_make_section (abfd
, copy
);
898 /* Build a reloc pointing to this constructor. */
899 amt
= sizeof (arelent_chain
);
900 reloc_chain
= (arelent_chain
*) bfd_alloc (abfd
, amt
);
903 reloc_chain
->relent
.sym_ptr_ptr
=
904 bfd_get_section (asym
)->symbol_ptr_ptr
;
905 reloc_chain
->relent
.address
= section
->_raw_size
;
906 reloc_chain
->relent
.addend
= asym
->value
;
907 reloc_chain
->relent
.howto
=
908 ecoff_backend (abfd
)->constructor_reloc
;
910 /* Set up the constructor section to hold the reloc. */
911 section
->flags
= SEC_CONSTRUCTOR
;
912 ++section
->reloc_count
;
914 /* Constructor sections must be rounded to a boundary
915 based on the bitsize. These are not real sections--
916 they are handled specially by the linker--so the ECOFF
917 16 byte alignment restriction does not apply. */
918 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
919 section
->alignment_power
= 1;
920 while ((1 << section
->alignment_power
) < bitsize
/ 8)
921 ++section
->alignment_power
;
923 reloc_chain
->next
= section
->constructor_chain
;
924 section
->constructor_chain
= reloc_chain
;
925 section
->_raw_size
+= bitsize
/ 8;
929 /* Mark the symbol as a constructor. */
930 asym
->flags
|= BSF_CONSTRUCTOR
;
938 /* Read an ECOFF symbol table. */
941 _bfd_ecoff_slurp_symbol_table (abfd
)
944 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
945 const bfd_size_type external_ext_size
946 = backend
->debug_swap
.external_ext_size
;
947 const bfd_size_type external_sym_size
948 = backend
->debug_swap
.external_sym_size
;
949 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
950 = backend
->debug_swap
.swap_ext_in
;
951 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
952 = backend
->debug_swap
.swap_sym_in
;
953 bfd_size_type internal_size
;
954 ecoff_symbol_type
*internal
;
955 ecoff_symbol_type
*internal_ptr
;
961 /* If we've already read in the symbol table, do nothing. */
962 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
965 /* Get the symbolic information. */
966 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
967 &ecoff_data (abfd
)->debug_info
))
969 if (bfd_get_symcount (abfd
) == 0)
972 internal_size
= bfd_get_symcount (abfd
);
973 internal_size
*= sizeof (ecoff_symbol_type
);
974 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
975 if (internal
== NULL
)
978 internal_ptr
= internal
;
979 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
981 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
982 * external_ext_size
));
983 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
987 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
988 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
989 + internal_esym
.asym
.iss
);
990 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
991 &internal_ptr
->symbol
, 1,
992 internal_esym
.weakext
))
994 /* The alpha uses a negative ifd field for section symbols. */
995 if (internal_esym
.ifd
>= 0)
996 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
997 + internal_esym
.ifd
);
999 internal_ptr
->fdr
= NULL
;
1000 internal_ptr
->local
= FALSE
;
1001 internal_ptr
->native
= (PTR
) eraw_src
;
1004 /* The local symbols must be accessed via the fdr's, because the
1005 string and aux indices are relative to the fdr information. */
1006 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1007 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1008 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1013 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1014 + fdr_ptr
->isymBase
* external_sym_size
);
1015 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1017 lraw_src
< lraw_end
;
1018 lraw_src
+= external_sym_size
, internal_ptr
++)
1022 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1023 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1025 + internal_sym
.iss
);
1026 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1027 &internal_ptr
->symbol
, 0, 0))
1029 internal_ptr
->fdr
= fdr_ptr
;
1030 internal_ptr
->local
= TRUE
;
1031 internal_ptr
->native
= (PTR
) lraw_src
;
1035 ecoff_data (abfd
)->canonical_symbols
= internal
;
1040 /* Return the amount of space needed for the canonical symbols. */
1043 _bfd_ecoff_get_symtab_upper_bound (abfd
)
1046 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
1047 &ecoff_data (abfd
)->debug_info
))
1050 if (bfd_get_symcount (abfd
) == 0)
1053 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1056 /* Get the canonical symbols. */
1059 _bfd_ecoff_get_symtab (abfd
, alocation
)
1061 asymbol
**alocation
;
1063 unsigned int counter
= 0;
1064 ecoff_symbol_type
*symbase
;
1065 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1067 if (! _bfd_ecoff_slurp_symbol_table (abfd
))
1069 if (bfd_get_symcount (abfd
) == 0)
1072 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1073 while (counter
< bfd_get_symcount (abfd
))
1075 *(location
++) = symbase
++;
1078 *location
++ = (ecoff_symbol_type
*) NULL
;
1079 return bfd_get_symcount (abfd
);
1082 /* Turn ECOFF type information into a printable string.
1083 ecoff_emit_aggregate and ecoff_type_to_string are from
1084 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1086 /* Write aggregate information to a string. */
1089 ecoff_emit_aggregate (abfd
, fdr
, string
, rndx
, isym
, which
)
1097 const struct ecoff_debug_swap
* const debug_swap
=
1098 &ecoff_backend (abfd
)->debug_swap
;
1099 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1100 unsigned int ifd
= rndx
->rfd
;
1101 unsigned int indx
= rndx
->index
;
1107 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1108 struct return type of a procedure compiled without -g. */
1109 if (ifd
== 0xffffffff
1110 || (rndx
->rfd
== 0xfff && indx
== 0))
1111 name
= "<undefined>";
1112 else if (indx
== indexNil
)
1118 if (debug_info
->external_rfd
== NULL
)
1119 fdr
= debug_info
->fdr
+ ifd
;
1124 (*debug_swap
->swap_rfd_in
) (abfd
,
1125 ((char *) debug_info
->external_rfd
1126 + ((fdr
->rfdBase
+ ifd
)
1127 * debug_swap
->external_rfd_size
)),
1129 fdr
= debug_info
->fdr
+ rfd
;
1132 indx
+= fdr
->isymBase
;
1134 (*debug_swap
->swap_sym_in
) (abfd
,
1135 ((char *) debug_info
->external_sym
1136 + indx
* debug_swap
->external_sym_size
),
1139 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1143 "%s %s { ifd = %u, index = %lu }",
1146 + debug_info
->symbolic_header
.iextMax
));
1149 /* Convert the type information to string format. */
1152 ecoff_type_to_string (abfd
, fdr
, indx
)
1157 union aux_ext
*aux_ptr
;
1166 unsigned int basic_type
;
1169 static char buffer2
[1024];
1174 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1175 bigendian
= fdr
->fBigendian
;
1177 for (i
= 0; i
< 7; i
++)
1179 qualifiers
[i
].low_bound
= 0;
1180 qualifiers
[i
].high_bound
= 0;
1181 qualifiers
[i
].stride
= 0;
1184 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == (bfd_vma
) -1)
1185 return "-1 (no type)";
1186 _bfd_ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1188 basic_type
= u
.ti
.bt
;
1189 qualifiers
[0].type
= u
.ti
.tq0
;
1190 qualifiers
[1].type
= u
.ti
.tq1
;
1191 qualifiers
[2].type
= u
.ti
.tq2
;
1192 qualifiers
[3].type
= u
.ti
.tq3
;
1193 qualifiers
[4].type
= u
.ti
.tq4
;
1194 qualifiers
[5].type
= u
.ti
.tq5
;
1195 qualifiers
[6].type
= tqNil
;
1197 /* Go get the basic type. */
1200 case btNil
: /* Undefined. */
1204 case btAdr
: /* Address - integer same size as pointer. */
1205 strcpy (p1
, "address");
1208 case btChar
: /* Character. */
1209 strcpy (p1
, "char");
1212 case btUChar
: /* Unsigned character. */
1213 strcpy (p1
, "unsigned char");
1216 case btShort
: /* Short. */
1217 strcpy (p1
, "short");
1220 case btUShort
: /* Unsigned short. */
1221 strcpy (p1
, "unsigned short");
1224 case btInt
: /* Int. */
1228 case btUInt
: /* Unsigned int. */
1229 strcpy (p1
, "unsigned int");
1232 case btLong
: /* Long. */
1233 strcpy (p1
, "long");
1236 case btULong
: /* Unsigned long. */
1237 strcpy (p1
, "unsigned long");
1240 case btFloat
: /* Float (real). */
1241 strcpy (p1
, "float");
1244 case btDouble
: /* Double (real). */
1245 strcpy (p1
, "double");
1248 /* Structures add 1-2 aux words:
1249 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1250 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1252 case btStruct
: /* Structure (Record). */
1253 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1254 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1255 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1257 indx
++; /* Skip aux words. */
1260 /* Unions add 1-2 aux words:
1261 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1262 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1264 case btUnion
: /* Union. */
1265 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1266 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1267 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1269 indx
++; /* Skip aux words. */
1272 /* Enumerations add 1-2 aux words:
1273 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1274 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1276 case btEnum
: /* Enumeration. */
1277 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1278 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1279 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1281 indx
++; /* Skip aux words. */
1284 case btTypedef
: /* Defined via a typedef, isymRef points. */
1285 strcpy (p1
, "typedef");
1288 case btRange
: /* Subrange of int. */
1289 strcpy (p1
, "subrange");
1292 case btSet
: /* Pascal sets. */
1296 case btComplex
: /* Fortran complex. */
1297 strcpy (p1
, "complex");
1300 case btDComplex
: /* Fortran double complex. */
1301 strcpy (p1
, "double complex");
1304 case btIndirect
: /* Forward or unnamed typedef. */
1305 strcpy (p1
, "forward/unamed typedef");
1308 case btFixedDec
: /* Fixed Decimal. */
1309 strcpy (p1
, "fixed decimal");
1312 case btFloatDec
: /* Float Decimal. */
1313 strcpy (p1
, "float decimal");
1316 case btString
: /* Varying Length Character String. */
1317 strcpy (p1
, "string");
1320 case btBit
: /* Aligned Bit String. */
1324 case btPicture
: /* Picture. */
1325 strcpy (p1
, "picture");
1328 case btVoid
: /* Void. */
1329 strcpy (p1
, "void");
1333 sprintf (p1
, _("Unknown basic type %d"), (int) basic_type
);
1337 p1
+= strlen (buffer1
);
1339 /* If this is a bitfield, get the bitsize. */
1344 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1345 sprintf (p1
, " : %d", bitsize
);
1346 p1
+= strlen (buffer1
);
1349 /* Deal with any qualifiers. */
1350 if (qualifiers
[0].type
!= tqNil
)
1352 /* Snarf up any array bounds in the correct order. Arrays
1353 store 5 successive words in the aux. table:
1354 word 0 RNDXR to type of the bounds (ie, int)
1355 word 1 Current file descriptor index
1357 word 3 high bound (or -1 if [])
1358 word 4 stride size in bits. */
1359 for (i
= 0; i
< 7; i
++)
1361 if (qualifiers
[i
].type
== tqArray
)
1363 qualifiers
[i
].low_bound
=
1364 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1365 qualifiers
[i
].high_bound
=
1366 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1367 qualifiers
[i
].stride
=
1368 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1373 /* Now print out the qualifiers. */
1374 for (i
= 0; i
< 6; i
++)
1376 switch (qualifiers
[i
].type
)
1383 strcpy (p2
, "ptr to ");
1384 p2
+= sizeof ("ptr to ")-1;
1388 strcpy (p2
, "volatile ");
1389 p2
+= sizeof ("volatile ")-1;
1393 strcpy (p2
, "far ");
1394 p2
+= sizeof ("far ")-1;
1398 strcpy (p2
, "func. ret. ");
1399 p2
+= sizeof ("func. ret. ");
1404 int first_array
= i
;
1407 /* Print array bounds reversed (ie, in the order the C
1408 programmer writes them). C is such a fun language.... */
1409 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1412 for (j
= i
; j
>= first_array
; j
--)
1414 strcpy (p2
, "array [");
1415 p2
+= sizeof ("array [")-1;
1416 if (qualifiers
[j
].low_bound
!= 0)
1418 "%ld:%ld {%ld bits}",
1419 (long) qualifiers
[j
].low_bound
,
1420 (long) qualifiers
[j
].high_bound
,
1421 (long) qualifiers
[j
].stride
);
1423 else if (qualifiers
[j
].high_bound
!= -1)
1426 (long) (qualifiers
[j
].high_bound
+ 1),
1427 (long) (qualifiers
[j
].stride
));
1430 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1433 strcpy (p2
, "] of ");
1434 p2
+= sizeof ("] of ")-1;
1442 strcpy (p2
, buffer1
);
1446 /* Return information about ECOFF symbol SYMBOL in RET. */
1449 _bfd_ecoff_get_symbol_info (abfd
, symbol
, ret
)
1450 bfd
*abfd ATTRIBUTE_UNUSED
;
1454 bfd_symbol_info (symbol
, ret
);
1457 /* Return whether this is a local label. */
1460 _bfd_ecoff_bfd_is_local_label_name (abfd
, name
)
1461 bfd
*abfd ATTRIBUTE_UNUSED
;
1464 return name
[0] == '$';
1467 /* Print information about an ECOFF symbol. */
1470 _bfd_ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1474 bfd_print_symbol_type how
;
1476 const struct ecoff_debug_swap
* const debug_swap
1477 = &ecoff_backend (abfd
)->debug_swap
;
1478 FILE *file
= (FILE *)filep
;
1482 case bfd_print_symbol_name
:
1483 fprintf (file
, "%s", symbol
->name
);
1485 case bfd_print_symbol_more
:
1486 if (ecoffsymbol (symbol
)->local
)
1490 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1492 fprintf (file
, "ecoff local ");
1493 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1494 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1495 (unsigned) ecoff_sym
.sc
);
1501 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1503 fprintf (file
, "ecoff extern ");
1504 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1505 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1506 (unsigned) ecoff_ext
.asym
.sc
);
1509 case bfd_print_symbol_all
:
1510 /* Print out the symbols in a reasonable way. */
1519 if (ecoffsymbol (symbol
)->local
)
1521 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1524 pos
= ((((char *) ecoffsymbol (symbol
)->native
1525 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1526 / debug_swap
->external_sym_size
)
1527 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1534 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1537 pos
= (((char *) ecoffsymbol (symbol
)->native
1538 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1539 / debug_swap
->external_ext_size
);
1540 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1541 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1542 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1545 fprintf (file
, "[%3d] %c ",
1547 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1548 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1549 (unsigned) ecoff_ext
.asym
.st
,
1550 (unsigned) ecoff_ext
.asym
.sc
,
1551 (unsigned) ecoff_ext
.asym
.index
,
1552 jmptbl
, cobol_main
, weakext
,
1555 if (ecoffsymbol (symbol
)->fdr
!= NULL
1556 && ecoff_ext
.asym
.index
!= indexNil
)
1561 bfd_size_type sym_base
;
1562 union aux_ext
*aux_base
;
1564 fdr
= ecoffsymbol (symbol
)->fdr
;
1565 indx
= ecoff_ext
.asym
.index
;
1567 /* sym_base is used to map the fdr relative indices which
1568 appear in the file to the position number which we are
1570 sym_base
= fdr
->isymBase
;
1571 if (ecoffsymbol (symbol
)->local
)
1573 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1575 /* aux_base is the start of the aux entries for this file;
1576 asym.index is an offset from this. */
1577 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1580 /* The aux entries are stored in host byte order; the
1581 order is indicated by a bit in the fdr. */
1582 bigendian
= fdr
->fBigendian
;
1584 /* This switch is basically from gcc/mips-tdump.c. */
1585 switch (ecoff_ext
.asym
.st
)
1593 fprintf (file
, _("\n End+1 symbol: %ld"),
1594 (long) (indx
+ sym_base
));
1598 if (ecoff_ext
.asym
.sc
== scText
1599 || ecoff_ext
.asym
.sc
== scInfo
)
1600 fprintf (file
, _("\n First symbol: %ld"),
1601 (long) (indx
+ sym_base
));
1603 fprintf (file
, _("\n First symbol: %ld"),
1605 (AUX_GET_ISYM (bigendian
,
1606 &aux_base
[ecoff_ext
.asym
.index
])
1612 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1614 else if (ecoffsymbol (symbol
)->local
)
1615 fprintf (file
, _("\n End+1 symbol: %-7ld Type: %s"),
1617 (AUX_GET_ISYM (bigendian
,
1618 &aux_base
[ecoff_ext
.asym
.index
])
1620 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1622 fprintf (file
, _("\n Local symbol: %ld"),
1625 + (ecoff_data (abfd
)
1626 ->debug_info
.symbolic_header
.iextMax
)));
1630 fprintf (file
, _("\n struct; End+1 symbol: %ld"),
1631 (long) (indx
+ sym_base
));
1635 fprintf (file
, _("\n union; End+1 symbol: %ld"),
1636 (long) (indx
+ sym_base
));
1640 fprintf (file
, _("\n enum; End+1 symbol: %ld"),
1641 (long) (indx
+ sym_base
));
1645 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1646 fprintf (file
, _("\n Type: %s"),
1647 ecoff_type_to_string (abfd
, fdr
, indx
));
1656 /* Read in the relocs for a section. */
1659 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1664 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1665 arelent
*internal_relocs
;
1666 bfd_size_type external_reloc_size
;
1668 char *external_relocs
;
1672 if (section
->relocation
!= (arelent
*) NULL
1673 || section
->reloc_count
== 0
1674 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1677 if (! _bfd_ecoff_slurp_symbol_table (abfd
))
1680 amt
= section
->reloc_count
;
1681 amt
*= sizeof (arelent
);
1682 internal_relocs
= (arelent
*) bfd_alloc (abfd
, amt
);
1684 external_reloc_size
= backend
->external_reloc_size
;
1685 amt
= external_reloc_size
* section
->reloc_count
;
1686 external_relocs
= (char *) bfd_alloc (abfd
, amt
);
1687 if (internal_relocs
== (arelent
*) NULL
1688 || external_relocs
== (char *) NULL
)
1690 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1692 if (bfd_bread (external_relocs
, amt
, abfd
) != amt
)
1695 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1697 struct internal_reloc intern
;
1699 (*backend
->swap_reloc_in
) (abfd
,
1700 external_relocs
+ i
* external_reloc_size
,
1703 if (intern
.r_extern
)
1705 /* r_symndx is an index into the external symbols. */
1706 BFD_ASSERT (intern
.r_symndx
>= 0
1708 < (ecoff_data (abfd
)
1709 ->debug_info
.symbolic_header
.iextMax
)));
1710 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1713 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1714 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1716 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
1721 const char *sec_name
;
1724 /* r_symndx is a section key. */
1725 switch (intern
.r_symndx
)
1727 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1728 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1729 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1730 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1731 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1732 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1733 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1734 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1735 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1736 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1737 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1738 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1739 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1740 case RELOC_SECTION_RCONST
: sec_name
= ".rconst"; break;
1744 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1745 if (sec
== (asection
*) NULL
)
1747 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1749 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1752 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1754 /* Let the backend select the howto field and do any other
1755 required processing. */
1756 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1759 bfd_release (abfd
, external_relocs
);
1761 section
->relocation
= internal_relocs
;
1766 /* Get a canonical list of relocs. */
1769 _bfd_ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1777 if (section
->flags
& SEC_CONSTRUCTOR
)
1779 arelent_chain
*chain
;
1781 /* This section has relocs made up by us, not the file, so take
1782 them out of their chain and place them into the data area
1784 for (count
= 0, chain
= section
->constructor_chain
;
1785 count
< section
->reloc_count
;
1786 count
++, chain
= chain
->next
)
1787 *relptr
++ = &chain
->relent
;
1793 if (! ecoff_slurp_reloc_table (abfd
, section
, symbols
))
1796 tblptr
= section
->relocation
;
1798 for (count
= 0; count
< section
->reloc_count
; count
++)
1799 *relptr
++ = tblptr
++;
1802 *relptr
= (arelent
*) NULL
;
1804 return section
->reloc_count
;
1807 /* Provided a BFD, a section and an offset into the section, calculate
1808 and return the name of the source file and the line nearest to the
1812 _bfd_ecoff_find_nearest_line (abfd
, section
, ignore_symbols
, offset
,
1813 filename_ptr
, functionname_ptr
, retline_ptr
)
1816 asymbol
**ignore_symbols ATTRIBUTE_UNUSED
;
1818 const char **filename_ptr
;
1819 const char **functionname_ptr
;
1820 unsigned int *retline_ptr
;
1822 const struct ecoff_debug_swap
* const debug_swap
1823 = &ecoff_backend (abfd
)->debug_swap
;
1824 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1825 struct ecoff_find_line
*line_info
;
1827 /* Make sure we have the FDR's. */
1828 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
, debug_info
)
1829 || bfd_get_symcount (abfd
) == 0)
1832 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1834 bfd_size_type amt
= sizeof (struct ecoff_find_line
);
1835 ecoff_data (abfd
)->find_line_info
1836 = (struct ecoff_find_line
*) bfd_zalloc (abfd
, amt
);
1837 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1840 line_info
= ecoff_data (abfd
)->find_line_info
;
1842 return _bfd_ecoff_locate_line (abfd
, section
, offset
, debug_info
,
1843 debug_swap
, line_info
, filename_ptr
,
1844 functionname_ptr
, retline_ptr
);
1847 /* Copy private BFD data. This is called by objcopy and strip. We
1848 use it to copy the ECOFF debugging information from one BFD to the
1849 other. It would be theoretically possible to represent the ECOFF
1850 debugging information in the symbol table. However, it would be a
1851 lot of work, and there would be little gain (gas, gdb, and ld
1852 already access the ECOFF debugging information via the
1853 ecoff_debug_info structure, and that structure would have to be
1854 retained in order to support ECOFF debugging in MIPS ELF).
1856 The debugging information for the ECOFF external symbols comes from
1857 the symbol table, so this function only handles the other debugging
1861 _bfd_ecoff_bfd_copy_private_bfd_data (ibfd
, obfd
)
1865 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
1866 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
1868 asymbol
**sym_ptr_ptr
;
1872 /* We only want to copy information over if both BFD's use ECOFF
1874 if (bfd_get_flavour (ibfd
) != bfd_target_ecoff_flavour
1875 || bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
1878 /* Copy the GP value and the register masks. */
1879 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
1880 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
1881 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
1882 for (i
= 0; i
< 3; i
++)
1883 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
1885 /* Copy the version stamp. */
1886 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
1888 /* If there are no symbols, don't copy any debugging information. */
1889 c
= bfd_get_symcount (obfd
);
1890 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1891 if (c
== 0 || sym_ptr_ptr
== (asymbol
**) NULL
)
1894 /* See if there are any local symbols. */
1896 for (; c
> 0; c
--, sym_ptr_ptr
++)
1898 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
1907 /* There are some local symbols. We just bring over all the
1908 debugging information. FIXME: This is not quite the right
1909 thing to do. If the user has asked us to discard all
1910 debugging information, then we are probably going to wind up
1911 keeping it because there will probably be some local symbol
1912 which objcopy did not discard. We should actually break
1913 apart the debugging information and only keep that which
1914 applies to the symbols we want to keep. */
1915 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
1916 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
1917 oinfo
->line
= iinfo
->line
;
1919 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
1920 oinfo
->external_dnr
= iinfo
->external_dnr
;
1922 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
1923 oinfo
->external_pdr
= iinfo
->external_pdr
;
1925 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
1926 oinfo
->external_sym
= iinfo
->external_sym
;
1928 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
1929 oinfo
->external_opt
= iinfo
->external_opt
;
1931 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
1932 oinfo
->external_aux
= iinfo
->external_aux
;
1934 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
1935 oinfo
->ss
= iinfo
->ss
;
1937 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
1938 oinfo
->external_fdr
= iinfo
->external_fdr
;
1940 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
1941 oinfo
->external_rfd
= iinfo
->external_rfd
;
1945 /* We are discarding all the local symbol information. Look
1946 through the external symbols and remove all references to FDR
1947 or aux information. */
1948 c
= bfd_get_symcount (obfd
);
1949 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1950 for (; c
> 0; c
--, sym_ptr_ptr
++)
1954 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
1955 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
1957 esym
.asym
.index
= indexNil
;
1958 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
1959 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
1966 /* Set the architecture. The supported architecture is stored in the
1967 backend pointer. We always set the architecture anyhow, since many
1968 callers ignore the return value. */
1971 _bfd_ecoff_set_arch_mach (abfd
, arch
, machine
)
1973 enum bfd_architecture arch
;
1974 unsigned long machine
;
1976 bfd_default_set_arch_mach (abfd
, arch
, machine
);
1977 return arch
== ecoff_backend (abfd
)->arch
;
1980 /* Get the size of the section headers. */
1983 _bfd_ecoff_sizeof_headers (abfd
, reloc
)
1985 bfd_boolean reloc ATTRIBUTE_UNUSED
;
1992 for (current
= abfd
->sections
;
1993 current
!= (asection
*)NULL
;
1994 current
= current
->next
)
1997 ret
= (bfd_coff_filhsz (abfd
)
1998 + bfd_coff_aoutsz (abfd
)
1999 + c
* bfd_coff_scnhsz (abfd
));
2000 return BFD_ALIGN (ret
, 16);
2003 /* Get the contents of a section. */
2006 _bfd_ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2011 bfd_size_type count
;
2013 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2017 /* Sort sections by VMA, but put SEC_ALLOC sections first. This is
2018 called via qsort. */
2021 ecoff_sort_hdrs (arg1
, arg2
)
2025 const asection
*hdr1
= *(const asection
**) arg1
;
2026 const asection
*hdr2
= *(const asection
**) arg2
;
2028 if ((hdr1
->flags
& SEC_ALLOC
) != 0)
2030 if ((hdr2
->flags
& SEC_ALLOC
) == 0)
2035 if ((hdr2
->flags
& SEC_ALLOC
) != 0)
2038 if (hdr1
->vma
< hdr2
->vma
)
2040 else if (hdr1
->vma
> hdr2
->vma
)
2046 /* Calculate the file position for each section, and set
2050 ecoff_compute_section_file_positions (abfd
)
2053 file_ptr sofar
, file_sofar
;
2054 asection
**sorted_hdrs
;
2058 bfd_boolean rdata_in_text
;
2059 bfd_boolean first_data
, first_nonalloc
;
2060 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2063 sofar
= _bfd_ecoff_sizeof_headers (abfd
, FALSE
);
2066 /* Sort the sections by VMA. */
2067 amt
= abfd
->section_count
;
2068 amt
*= sizeof (asection
*);
2069 sorted_hdrs
= (asection
**) bfd_malloc (amt
);
2070 if (sorted_hdrs
== NULL
)
2072 for (current
= abfd
->sections
, i
= 0;
2074 current
= current
->next
, i
++)
2075 sorted_hdrs
[i
] = current
;
2076 BFD_ASSERT (i
== abfd
->section_count
);
2078 qsort (sorted_hdrs
, abfd
->section_count
, sizeof (asection
*),
2081 /* Some versions of the OSF linker put the .rdata section in the
2082 text segment, and some do not. */
2083 rdata_in_text
= ecoff_backend (abfd
)->rdata_in_text
;
2086 for (i
= 0; i
< abfd
->section_count
; i
++)
2088 current
= sorted_hdrs
[i
];
2089 if (strcmp (current
->name
, _RDATA
) == 0)
2091 if ((current
->flags
& SEC_CODE
) == 0
2092 && strcmp (current
->name
, _PDATA
) != 0
2093 && strcmp (current
->name
, _RCONST
) != 0)
2095 rdata_in_text
= FALSE
;
2100 ecoff_data (abfd
)->rdata_in_text
= rdata_in_text
;
2103 first_nonalloc
= TRUE
;
2104 for (i
= 0; i
< abfd
->section_count
; i
++)
2106 unsigned int alignment_power
;
2108 current
= sorted_hdrs
[i
];
2110 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2111 supposed to indicate the number of .pdata entries that are
2112 really in the section. Each entry is 8 bytes. We store this
2113 away in line_filepos before increasing the section size. */
2114 if (strcmp (current
->name
, _PDATA
) == 0)
2115 current
->line_filepos
= current
->_raw_size
/ 8;
2117 alignment_power
= current
->alignment_power
;
2119 /* On Ultrix, the data sections in an executable file must be
2120 aligned to a page boundary within the file. This does not
2121 affect the section size, though. FIXME: Does this work for
2122 other platforms? It requires some modification for the
2123 Alpha, because .rdata on the Alpha goes with the text, not
2125 if ((abfd
->flags
& EXEC_P
) != 0
2126 && (abfd
->flags
& D_PAGED
) != 0
2128 && (current
->flags
& SEC_CODE
) == 0
2130 || strcmp (current
->name
, _RDATA
) != 0)
2131 && strcmp (current
->name
, _PDATA
) != 0
2132 && strcmp (current
->name
, _RCONST
) != 0)
2134 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2135 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2138 else if (strcmp (current
->name
, _LIB
) == 0)
2140 /* On Irix 4, the location of contents of the .lib section
2141 from a shared library section is also rounded up to a
2144 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2145 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2147 else if (first_nonalloc
2148 && (current
->flags
& SEC_ALLOC
) == 0
2149 && (abfd
->flags
& D_PAGED
) != 0)
2151 /* Skip up to the next page for an unallocated section, such
2152 as the .comment section on the Alpha. This leaves room
2153 for the .bss section. */
2154 first_nonalloc
= FALSE
;
2155 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2156 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2159 /* Align the sections in the file to the same boundary on
2160 which they are aligned in virtual memory. */
2161 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2162 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2163 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2165 if ((abfd
->flags
& D_PAGED
) != 0
2166 && (current
->flags
& SEC_ALLOC
) != 0)
2168 sofar
+= (current
->vma
- sofar
) % round
;
2169 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2170 file_sofar
+= (current
->vma
- file_sofar
) % round
;
2173 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) != 0)
2174 current
->filepos
= file_sofar
;
2176 sofar
+= current
->_raw_size
;
2177 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2178 file_sofar
+= current
->_raw_size
;
2180 /* Make sure that this section is of the right size too. */
2182 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2183 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2184 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2185 current
->_raw_size
+= sofar
- old_sofar
;
2191 ecoff_data (abfd
)->reloc_filepos
= file_sofar
;
2196 /* Determine the location of the relocs for all the sections in the
2197 output file, as well as the location of the symbolic debugging
2200 static bfd_size_type
2201 ecoff_compute_reloc_file_positions (abfd
)
2204 const bfd_size_type external_reloc_size
=
2205 ecoff_backend (abfd
)->external_reloc_size
;
2206 file_ptr reloc_base
;
2207 bfd_size_type reloc_size
;
2211 if (! abfd
->output_has_begun
)
2213 if (! ecoff_compute_section_file_positions (abfd
))
2215 abfd
->output_has_begun
= TRUE
;
2218 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2221 for (current
= abfd
->sections
;
2222 current
!= (asection
*)NULL
;
2223 current
= current
->next
)
2225 if (current
->reloc_count
== 0)
2226 current
->rel_filepos
= 0;
2229 bfd_size_type relsize
;
2231 current
->rel_filepos
= reloc_base
;
2232 relsize
= current
->reloc_count
* external_reloc_size
;
2233 reloc_size
+= relsize
;
2234 reloc_base
+= relsize
;
2238 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2240 /* At least on Ultrix, the symbol table of an executable file must
2241 be aligned to a page boundary. FIXME: Is this true on other
2243 if ((abfd
->flags
& EXEC_P
) != 0
2244 && (abfd
->flags
& D_PAGED
) != 0)
2245 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2246 &~ (ecoff_backend (abfd
)->round
- 1));
2248 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2253 /* Set the contents of a section. */
2256 _bfd_ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2261 bfd_size_type count
;
2265 /* This must be done first, because bfd_set_section_contents is
2266 going to set output_has_begun to TRUE. */
2267 if (! abfd
->output_has_begun
)
2269 if (! ecoff_compute_section_file_positions (abfd
))
2273 /* Handle the .lib section specially so that Irix 4 shared libraries
2274 work out. See coff_set_section_contents in coffcode.h. */
2275 if (strcmp (section
->name
, _LIB
) == 0)
2277 bfd_byte
*rec
, *recend
;
2279 rec
= (bfd_byte
*) location
;
2280 recend
= rec
+ count
;
2281 while (rec
< recend
)
2284 rec
+= bfd_get_32 (abfd
, rec
) * 4;
2287 BFD_ASSERT (rec
== recend
);
2293 pos
= section
->filepos
+ offset
;
2294 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
2295 || bfd_bwrite (location
, count
, abfd
) != count
)
2301 /* Get the GP value for an ECOFF file. This is a hook used by
2305 bfd_ecoff_get_gp_value (abfd
)
2308 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2309 || bfd_get_format (abfd
) != bfd_object
)
2311 bfd_set_error (bfd_error_invalid_operation
);
2315 return ecoff_data (abfd
)->gp
;
2318 /* Set the GP value for an ECOFF file. This is a hook used by the
2322 bfd_ecoff_set_gp_value (abfd
, gp_value
)
2326 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2327 || bfd_get_format (abfd
) != bfd_object
)
2329 bfd_set_error (bfd_error_invalid_operation
);
2333 ecoff_data (abfd
)->gp
= gp_value
;
2338 /* Set the register masks for an ECOFF file. This is a hook used by
2342 bfd_ecoff_set_regmasks (abfd
, gprmask
, fprmask
, cprmask
)
2344 unsigned long gprmask
;
2345 unsigned long fprmask
;
2346 unsigned long *cprmask
;
2348 ecoff_data_type
*tdata
;
2350 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2351 || bfd_get_format (abfd
) != bfd_object
)
2353 bfd_set_error (bfd_error_invalid_operation
);
2357 tdata
= ecoff_data (abfd
);
2358 tdata
->gprmask
= gprmask
;
2359 tdata
->fprmask
= fprmask
;
2360 if (cprmask
!= (unsigned long *) NULL
)
2364 for (i
= 0; i
< 3; i
++)
2365 tdata
->cprmask
[i
] = cprmask
[i
];
2371 /* Get ECOFF EXTR information for an external symbol. This function
2372 is passed to bfd_ecoff_debug_externals. */
2375 ecoff_get_extr (sym
, esym
)
2379 ecoff_symbol_type
*ecoff_sym_ptr
;
2382 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2383 || ecoffsymbol (sym
)->native
== NULL
)
2385 /* Don't include debugging, local, or section symbols. */
2386 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2387 || (sym
->flags
& BSF_LOCAL
) != 0
2388 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2392 esym
->cobol_main
= 0;
2393 esym
->weakext
= (sym
->flags
& BSF_WEAK
) != 0;
2396 /* FIXME: we can do better than this for st and sc. */
2397 esym
->asym
.st
= stGlobal
;
2398 esym
->asym
.sc
= scAbs
;
2399 esym
->asym
.reserved
= 0;
2400 esym
->asym
.index
= indexNil
;
2404 ecoff_sym_ptr
= ecoffsymbol (sym
);
2406 if (ecoff_sym_ptr
->local
)
2409 input_bfd
= bfd_asymbol_bfd (sym
);
2410 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2411 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2413 /* If the symbol was defined by the linker, then esym will be
2414 undefined but sym will not be. Get a better class for such a
2416 if ((esym
->asym
.sc
== scUndefined
2417 || esym
->asym
.sc
== scSUndefined
)
2418 && ! bfd_is_und_section (bfd_get_section (sym
)))
2419 esym
->asym
.sc
= scAbs
;
2421 /* Adjust the FDR index for the symbol by that used for the input
2423 if (esym
->ifd
!= -1)
2425 struct ecoff_debug_info
*input_debug
;
2427 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2428 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2429 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2430 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2436 /* Set the external symbol index. This routine is passed to
2437 bfd_ecoff_debug_externals. */
2440 ecoff_set_index (sym
, indx
)
2444 ecoff_set_sym_index (sym
, indx
);
2447 /* Write out an ECOFF file. */
2450 _bfd_ecoff_write_object_contents (abfd
)
2453 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2454 const bfd_vma round
= backend
->round
;
2455 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2456 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2457 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2458 const bfd_size_type external_hdr_size
2459 = backend
->debug_swap
.external_hdr_size
;
2460 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2461 void (* const adjust_reloc_out
)
2462 PARAMS ((bfd
*, const arelent
*, struct internal_reloc
*))
2463 = backend
->adjust_reloc_out
;
2464 void (* const swap_reloc_out
)
2465 PARAMS ((bfd
*, const struct internal_reloc
*, PTR
))
2466 = backend
->swap_reloc_out
;
2467 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2468 HDRR
* const symhdr
= &debug
->symbolic_header
;
2471 bfd_size_type reloc_size
;
2472 bfd_size_type text_size
;
2474 bfd_boolean set_text_start
;
2475 bfd_size_type data_size
;
2477 bfd_boolean set_data_start
;
2478 bfd_size_type bss_size
;
2480 PTR reloc_buff
= NULL
;
2481 struct internal_filehdr internal_f
;
2482 struct internal_aouthdr internal_a
;
2485 /* Determine where the sections and relocs will go in the output
2487 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2490 for (current
= abfd
->sections
;
2491 current
!= (asection
*)NULL
;
2492 current
= current
->next
)
2494 current
->target_index
= count
;
2498 if ((abfd
->flags
& D_PAGED
) != 0)
2499 text_size
= _bfd_ecoff_sizeof_headers (abfd
, FALSE
);
2503 set_text_start
= FALSE
;
2506 set_data_start
= FALSE
;
2509 /* Write section headers to the file. */
2511 /* Allocate buff big enough to hold a section header,
2512 file header, or a.out header. */
2520 buff
= (PTR
) bfd_malloc (siz
);
2525 internal_f
.f_nscns
= 0;
2526 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2528 for (current
= abfd
->sections
;
2529 current
!= (asection
*) NULL
;
2530 current
= current
->next
)
2532 struct internal_scnhdr section
;
2535 ++internal_f
.f_nscns
;
2537 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2539 /* This seems to be correct for Irix 4 shared libraries. */
2540 vma
= bfd_get_section_vma (abfd
, current
);
2541 if (strcmp (current
->name
, _LIB
) == 0)
2542 section
.s_vaddr
= 0;
2544 section
.s_vaddr
= vma
;
2546 section
.s_paddr
= current
->lma
;
2547 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2549 /* If this section is unloadable then the scnptr will be 0. */
2550 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2551 section
.s_scnptr
= 0;
2553 section
.s_scnptr
= current
->filepos
;
2554 section
.s_relptr
= current
->rel_filepos
;
2556 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2557 object file produced by the assembler is supposed to point to
2558 information about how much room is required by objects of
2559 various different sizes. I think this only matters if we
2560 want the linker to compute the best size to use, or
2561 something. I don't know what happens if the information is
2563 if (strcmp (current
->name
, _PDATA
) != 0)
2564 section
.s_lnnoptr
= 0;
2567 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2568 hold the number of entries in the section (each entry is
2569 8 bytes). We stored this in the line_filepos field in
2570 ecoff_compute_section_file_positions. */
2571 section
.s_lnnoptr
= current
->line_filepos
;
2574 section
.s_nreloc
= current
->reloc_count
;
2575 section
.s_nlnno
= 0;
2576 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2579 if (bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
) == 0
2580 || bfd_bwrite (buff
, scnhsz
, abfd
) != scnhsz
)
2583 if ((section
.s_flags
& STYP_TEXT
) != 0
2584 || ((section
.s_flags
& STYP_RDATA
) != 0
2585 && ecoff_data (abfd
)->rdata_in_text
)
2586 || section
.s_flags
== STYP_PDATA
2587 || (section
.s_flags
& STYP_DYNAMIC
) != 0
2588 || (section
.s_flags
& STYP_LIBLIST
) != 0
2589 || (section
.s_flags
& STYP_RELDYN
) != 0
2590 || section
.s_flags
== STYP_CONFLIC
2591 || (section
.s_flags
& STYP_DYNSTR
) != 0
2592 || (section
.s_flags
& STYP_DYNSYM
) != 0
2593 || (section
.s_flags
& STYP_HASH
) != 0
2594 || (section
.s_flags
& STYP_ECOFF_INIT
) != 0
2595 || (section
.s_flags
& STYP_ECOFF_FINI
) != 0
2596 || section
.s_flags
== STYP_RCONST
)
2598 text_size
+= bfd_get_section_size_before_reloc (current
);
2599 if (! set_text_start
|| text_start
> vma
)
2602 set_text_start
= TRUE
;
2605 else if ((section
.s_flags
& STYP_RDATA
) != 0
2606 || (section
.s_flags
& STYP_DATA
) != 0
2607 || (section
.s_flags
& STYP_LITA
) != 0
2608 || (section
.s_flags
& STYP_LIT8
) != 0
2609 || (section
.s_flags
& STYP_LIT4
) != 0
2610 || (section
.s_flags
& STYP_SDATA
) != 0
2611 || section
.s_flags
== STYP_XDATA
2612 || (section
.s_flags
& STYP_GOT
) != 0)
2614 data_size
+= bfd_get_section_size_before_reloc (current
);
2615 if (! set_data_start
|| data_start
> vma
)
2618 set_data_start
= TRUE
;
2621 else if ((section
.s_flags
& STYP_BSS
) != 0
2622 || (section
.s_flags
& STYP_SBSS
) != 0)
2623 bss_size
+= bfd_get_section_size_before_reloc (current
);
2624 else if (section
.s_flags
== 0
2625 || (section
.s_flags
& STYP_ECOFF_LIB
) != 0
2626 || section
.s_flags
== STYP_COMMENT
)
2632 /* Set up the file header. */
2633 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2635 /* We will NOT put a fucking timestamp in the header here. Every
2636 time you put it back, I will come in and take it out again. I'm
2637 sorry. This field does not belong here. We fill it with a 0 so
2638 it compares the same but is not a reasonable time. --
2640 internal_f
.f_timdat
= 0;
2642 if (bfd_get_symcount (abfd
) != 0)
2644 /* The ECOFF f_nsyms field is not actually the number of
2645 symbols, it's the size of symbolic information header. */
2646 internal_f
.f_nsyms
= external_hdr_size
;
2647 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2651 internal_f
.f_nsyms
= 0;
2652 internal_f
.f_symptr
= 0;
2655 internal_f
.f_opthdr
= aoutsz
;
2657 internal_f
.f_flags
= F_LNNO
;
2658 if (reloc_size
== 0)
2659 internal_f
.f_flags
|= F_RELFLG
;
2660 if (bfd_get_symcount (abfd
) == 0)
2661 internal_f
.f_flags
|= F_LSYMS
;
2662 if (abfd
->flags
& EXEC_P
)
2663 internal_f
.f_flags
|= F_EXEC
;
2665 if (bfd_little_endian (abfd
))
2666 internal_f
.f_flags
|= F_AR32WR
;
2668 internal_f
.f_flags
|= F_AR32W
;
2670 /* Set up the ``optional'' header. */
2671 if ((abfd
->flags
& D_PAGED
) != 0)
2672 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2674 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2676 /* FIXME: Is this really correct? */
2677 internal_a
.vstamp
= symhdr
->vstamp
;
2679 /* At least on Ultrix, these have to be rounded to page boundaries.
2680 FIXME: Is this true on other platforms? */
2681 if ((abfd
->flags
& D_PAGED
) != 0)
2683 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2684 internal_a
.text_start
= text_start
&~ (round
- 1);
2685 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2686 internal_a
.data_start
= data_start
&~ (round
- 1);
2690 internal_a
.tsize
= text_size
;
2691 internal_a
.text_start
= text_start
;
2692 internal_a
.dsize
= data_size
;
2693 internal_a
.data_start
= data_start
;
2696 /* On Ultrix, the initial portions of the .sbss and .bss segments
2697 are at the end of the data section. The bsize field in the
2698 optional header records how many bss bytes are required beyond
2699 those in the data section. The value is not rounded to a page
2701 if (bss_size
< internal_a
.dsize
- data_size
)
2704 bss_size
-= internal_a
.dsize
- data_size
;
2705 internal_a
.bsize
= bss_size
;
2706 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2708 internal_a
.entry
= bfd_get_start_address (abfd
);
2710 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2712 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2713 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2714 for (i
= 0; i
< 4; i
++)
2715 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2717 /* Let the backend adjust the headers if necessary. */
2718 if (backend
->adjust_headers
)
2720 if (! (*backend
->adjust_headers
) (abfd
, &internal_f
, &internal_a
))
2724 /* Write out the file header and the optional header. */
2725 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2728 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2729 if (bfd_bwrite (buff
, filhsz
, abfd
) != filhsz
)
2732 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2733 if (bfd_bwrite (buff
, aoutsz
, abfd
) != aoutsz
)
2736 /* Build the external symbol information. This must be done before
2737 writing out the relocs so that we know the symbol indices. We
2738 don't do this if this BFD was created by the backend linker,
2739 since it will have already handled the symbols and relocs. */
2740 if (! ecoff_data (abfd
)->linker
)
2742 symhdr
->iextMax
= 0;
2743 symhdr
->issExtMax
= 0;
2744 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2745 debug
->ssext
= debug
->ssext_end
= NULL
;
2746 if (! bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2747 (abfd
->flags
& EXEC_P
) == 0,
2748 ecoff_get_extr
, ecoff_set_index
))
2751 /* Write out the relocs. */
2752 for (current
= abfd
->sections
;
2753 current
!= (asection
*) NULL
;
2754 current
= current
->next
)
2756 arelent
**reloc_ptr_ptr
;
2757 arelent
**reloc_end
;
2761 if (current
->reloc_count
== 0)
2764 amt
= current
->reloc_count
* external_reloc_size
;
2765 reloc_buff
= bfd_alloc (abfd
, amt
);
2766 if (reloc_buff
== NULL
)
2769 reloc_ptr_ptr
= current
->orelocation
;
2770 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2771 out_ptr
= (char *) reloc_buff
;
2773 reloc_ptr_ptr
< reloc_end
;
2774 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2778 struct internal_reloc in
;
2780 memset ((PTR
) &in
, 0, sizeof in
);
2782 reloc
= *reloc_ptr_ptr
;
2783 sym
= *reloc
->sym_ptr_ptr
;
2785 in
.r_vaddr
= (reloc
->address
2786 + bfd_get_section_vma (abfd
, current
));
2787 in
.r_type
= reloc
->howto
->type
;
2789 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2791 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2798 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2799 if (strcmp (name
, ".text") == 0)
2800 in
.r_symndx
= RELOC_SECTION_TEXT
;
2801 else if (strcmp (name
, ".rdata") == 0)
2802 in
.r_symndx
= RELOC_SECTION_RDATA
;
2803 else if (strcmp (name
, ".data") == 0)
2804 in
.r_symndx
= RELOC_SECTION_DATA
;
2805 else if (strcmp (name
, ".sdata") == 0)
2806 in
.r_symndx
= RELOC_SECTION_SDATA
;
2807 else if (strcmp (name
, ".sbss") == 0)
2808 in
.r_symndx
= RELOC_SECTION_SBSS
;
2809 else if (strcmp (name
, ".bss") == 0)
2810 in
.r_symndx
= RELOC_SECTION_BSS
;
2811 else if (strcmp (name
, ".init") == 0)
2812 in
.r_symndx
= RELOC_SECTION_INIT
;
2813 else if (strcmp (name
, ".lit8") == 0)
2814 in
.r_symndx
= RELOC_SECTION_LIT8
;
2815 else if (strcmp (name
, ".lit4") == 0)
2816 in
.r_symndx
= RELOC_SECTION_LIT4
;
2817 else if (strcmp (name
, ".xdata") == 0)
2818 in
.r_symndx
= RELOC_SECTION_XDATA
;
2819 else if (strcmp (name
, ".pdata") == 0)
2820 in
.r_symndx
= RELOC_SECTION_PDATA
;
2821 else if (strcmp (name
, ".fini") == 0)
2822 in
.r_symndx
= RELOC_SECTION_FINI
;
2823 else if (strcmp (name
, ".lita") == 0)
2824 in
.r_symndx
= RELOC_SECTION_LITA
;
2825 else if (strcmp (name
, "*ABS*") == 0)
2826 in
.r_symndx
= RELOC_SECTION_ABS
;
2827 else if (strcmp (name
, ".rconst") == 0)
2828 in
.r_symndx
= RELOC_SECTION_RCONST
;
2834 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2836 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2839 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2841 amt
= current
->reloc_count
* external_reloc_size
;
2842 if (bfd_bwrite (reloc_buff
, amt
, abfd
) != amt
)
2844 bfd_release (abfd
, reloc_buff
);
2848 /* Write out the symbolic debugging information. */
2849 if (bfd_get_symcount (abfd
) > 0)
2851 /* Write out the debugging information. */
2852 if (! bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2853 ecoff_data (abfd
)->sym_filepos
))
2858 /* The .bss section of a demand paged executable must receive an
2859 entire page. If there are symbols, the symbols will start on the
2860 next page. If there are no symbols, we must fill out the page by
2862 if (bfd_get_symcount (abfd
) == 0
2863 && (abfd
->flags
& EXEC_P
) != 0
2864 && (abfd
->flags
& D_PAGED
) != 0)
2868 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2871 if (bfd_bread (&c
, (bfd_size_type
) 1, abfd
) == 0)
2873 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2876 if (bfd_bwrite (&c
, (bfd_size_type
) 1, abfd
) != 1)
2880 if (reloc_buff
!= NULL
)
2881 bfd_release (abfd
, reloc_buff
);
2886 if (reloc_buff
!= NULL
)
2887 bfd_release (abfd
, reloc_buff
);
2893 /* Archive handling. ECOFF uses what appears to be a unique type of
2894 archive header (armap). The byte ordering of the armap and the
2895 contents are encoded in the name of the armap itself. At least for
2896 now, we only support archives with the same byte ordering in the
2897 armap and the contents.
2899 The first four bytes in the armap are the number of symbol
2900 definitions. This is always a power of two.
2902 This is followed by the symbol definitions. Each symbol definition
2903 occupies 8 bytes. The first four bytes are the offset from the
2904 start of the armap strings to the null-terminated string naming
2905 this symbol. The second four bytes are the file offset to the
2906 archive member which defines this symbol. If the second four bytes
2907 are 0, then this is not actually a symbol definition, and it should
2910 The symbols are hashed into the armap with a closed hashing scheme.
2911 See the functions below for the details of the algorithm.
2913 After the symbol definitions comes four bytes holding the size of
2914 the string table, followed by the string table itself. */
2916 /* The name of an archive headers looks like this:
2917 __________E[BL]E[BL]_ (with a trailing space).
2918 The trailing space is changed to an X if the archive is changed to
2919 indicate that the armap is out of date.
2921 The Alpha seems to use ________64E[BL]E[BL]_. */
2923 #define ARMAP_BIG_ENDIAN 'B'
2924 #define ARMAP_LITTLE_ENDIAN 'L'
2925 #define ARMAP_MARKER 'E'
2926 #define ARMAP_START_LENGTH 10
2927 #define ARMAP_HEADER_MARKER_INDEX 10
2928 #define ARMAP_HEADER_ENDIAN_INDEX 11
2929 #define ARMAP_OBJECT_MARKER_INDEX 12
2930 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2931 #define ARMAP_END_INDEX 14
2932 #define ARMAP_END "_ "
2934 /* This is a magic number used in the hashing algorithm. */
2935 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2937 /* This returns the hash value to use for a string. It also sets
2938 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2939 is the number of entries in the hash table, and HLOG is the log
2943 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2945 unsigned int *rehash
;
2955 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2956 hash
*= ARMAP_HASH_MAGIC
;
2957 *rehash
= (hash
& (size
- 1)) | 1;
2958 return hash
>> (32 - hlog
);
2961 /* Read in the armap. */
2964 _bfd_ecoff_slurp_armap (abfd
)
2969 struct areltdata
*mapdata
;
2970 bfd_size_type parsed_size
;
2972 struct artdata
*ardata
;
2975 struct symdef
*symdef_ptr
;
2979 /* Get the name of the first element. */
2980 i
= bfd_bread ((PTR
) nextname
, (bfd_size_type
) 16, abfd
);
2986 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
2989 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2990 standard COFF armap. We could move the ECOFF armap stuff into
2991 bfd_slurp_armap, but that seems inappropriate since no other
2992 target uses this format. Instead, we check directly for a COFF
2994 if (strncmp (nextname
, "/ ", 16) == 0)
2995 return bfd_slurp_armap (abfd
);
2997 /* See if the first element is an armap. */
2998 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
2999 ARMAP_START_LENGTH
) != 0
3000 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3001 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3002 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3003 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3004 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3005 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3006 || strncmp (nextname
+ ARMAP_END_INDEX
,
3007 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3009 bfd_has_map (abfd
) = FALSE
;
3013 /* Make sure we have the right byte ordering. */
3014 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3015 ^ (bfd_header_big_endian (abfd
)))
3016 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3017 ^ (bfd_big_endian (abfd
))))
3019 bfd_set_error (bfd_error_wrong_format
);
3023 /* Read in the armap. */
3024 ardata
= bfd_ardata (abfd
);
3025 mapdata
= (struct areltdata
*) _bfd_read_ar_hdr (abfd
);
3026 if (mapdata
== (struct areltdata
*) NULL
)
3028 parsed_size
= mapdata
->parsed_size
;
3029 bfd_release (abfd
, (PTR
) mapdata
);
3031 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3032 if (raw_armap
== (char *) NULL
)
3035 if (bfd_bread ((PTR
) raw_armap
, parsed_size
, abfd
) != parsed_size
)
3037 if (bfd_get_error () != bfd_error_system_call
)
3038 bfd_set_error (bfd_error_malformed_archive
);
3039 bfd_release (abfd
, (PTR
) raw_armap
);
3043 ardata
->tdata
= (PTR
) raw_armap
;
3045 count
= H_GET_32 (abfd
, raw_armap
);
3047 ardata
->symdef_count
= 0;
3048 ardata
->cache
= (struct ar_cache
*) NULL
;
3050 /* This code used to overlay the symdefs over the raw archive data,
3051 but that doesn't work on a 64 bit host. */
3052 stringbase
= raw_armap
+ count
* 8 + 8;
3054 #ifdef CHECK_ARMAP_HASH
3058 /* Double check that I have the hashing algorithm right by making
3059 sure that every symbol can be looked up successfully. */
3061 for (i
= 1; i
< count
; i
<<= 1)
3063 BFD_ASSERT (i
== count
);
3065 raw_ptr
= raw_armap
+ 4;
3066 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3068 unsigned int name_offset
, file_offset
;
3069 unsigned int hash
, rehash
, srch
;
3071 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3072 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3073 if (file_offset
== 0)
3075 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3080 /* See if we can rehash to this location. */
3081 for (srch
= (hash
+ rehash
) & (count
- 1);
3082 srch
!= hash
&& srch
!= i
;
3083 srch
= (srch
+ rehash
) & (count
- 1))
3084 BFD_ASSERT (H_GET_32 (abfd
, (raw_armap
+ 8 + srch
* 8)) != 0);
3085 BFD_ASSERT (srch
== i
);
3089 #endif /* CHECK_ARMAP_HASH */
3091 raw_ptr
= raw_armap
+ 4;
3092 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3093 if (H_GET_32 (abfd
, (raw_ptr
+ 4)) != 0)
3094 ++ardata
->symdef_count
;
3096 amt
= ardata
->symdef_count
;
3097 amt
*= sizeof (struct symdef
);
3098 symdef_ptr
= (struct symdef
*) bfd_alloc (abfd
, amt
);
3102 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3104 raw_ptr
= raw_armap
+ 4;
3105 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3107 unsigned int name_offset
, file_offset
;
3109 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3110 if (file_offset
== 0)
3112 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3113 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3114 symdef_ptr
->file_offset
= file_offset
;
3118 ardata
->first_file_filepos
= bfd_tell (abfd
);
3119 /* Pad to an even boundary. */
3120 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3122 bfd_has_map (abfd
) = TRUE
;
3127 /* Write out an armap. */
3130 _bfd_ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3132 unsigned int elength
;
3134 unsigned int orl_count
;
3137 unsigned int hashsize
, hashlog
;
3138 bfd_size_type symdefsize
;
3140 unsigned int stringsize
;
3141 unsigned int mapsize
;
3144 struct stat statbuf
;
3147 bfd_byte
*hashtable
;
3151 /* Ultrix appears to use as a hash table size the least power of two
3152 greater than twice the number of entries. */
3153 for (hashlog
= 0; ((unsigned int) 1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3155 hashsize
= 1 << hashlog
;
3157 symdefsize
= hashsize
* 8;
3159 stringsize
= stridx
+ padit
;
3161 /* Include 8 bytes to store symdefsize and stringsize in output. */
3162 mapsize
= symdefsize
+ stringsize
+ 8;
3164 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3166 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3168 /* Work out the ECOFF armap name. */
3169 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3170 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3171 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3172 (bfd_header_big_endian (abfd
)
3174 : ARMAP_LITTLE_ENDIAN
);
3175 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3176 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3177 bfd_big_endian (abfd
) ? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3178 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3180 /* Write the timestamp of the archive header to be just a little bit
3181 later than the timestamp of the file, otherwise the linker will
3182 complain that the index is out of date. Actually, the Ultrix
3183 linker just checks the archive name; the GNU linker may check the
3185 stat (abfd
->filename
, &statbuf
);
3186 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3188 /* The DECstation uses zeroes for the uid, gid and mode of the
3190 hdr
.ar_uid
[0] = '0';
3191 hdr
.ar_gid
[0] = '0';
3193 hdr
.ar_mode
[0] = '0';
3195 /* Building gcc ends up extracting the armap as a file - twice. */
3196 hdr
.ar_mode
[0] = '6';
3197 hdr
.ar_mode
[1] = '4';
3198 hdr
.ar_mode
[2] = '4';
3201 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3203 hdr
.ar_fmag
[0] = '`';
3204 hdr
.ar_fmag
[1] = '\012';
3206 /* Turn all null bytes in the header into spaces. */
3207 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3208 if (((char *) (&hdr
))[i
] == '\0')
3209 (((char *) (&hdr
))[i
]) = ' ';
3211 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) sizeof (struct ar_hdr
), abfd
)
3212 != sizeof (struct ar_hdr
))
3215 H_PUT_32 (abfd
, hashsize
, temp
);
3216 if (bfd_bwrite ((PTR
) temp
, (bfd_size_type
) 4, abfd
) != 4)
3219 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3223 current
= abfd
->archive_head
;
3225 for (i
= 0; i
< orl_count
; i
++)
3227 unsigned int hash
, rehash
;
3229 /* Advance firstreal to the file position of this archive
3231 if (map
[i
].u
.abfd
!= last_elt
)
3235 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3236 firstreal
+= firstreal
% 2;
3237 current
= current
->next
;
3239 while (current
!= map
[i
].u
.abfd
);
3244 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3245 if (H_GET_32 (abfd
, (hashtable
+ (hash
* 8) + 4)) != 0)
3249 /* The desired slot is already taken. */
3250 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3252 srch
= (srch
+ rehash
) & (hashsize
- 1))
3253 if (H_GET_32 (abfd
, (hashtable
+ (srch
* 8) + 4)) == 0)
3256 BFD_ASSERT (srch
!= hash
);
3261 H_PUT_32 (abfd
, map
[i
].namidx
, (hashtable
+ hash
* 8));
3262 H_PUT_32 (abfd
, firstreal
, (hashtable
+ hash
* 8 + 4));
3265 if (bfd_bwrite ((PTR
) hashtable
, symdefsize
, abfd
) != symdefsize
)
3268 bfd_release (abfd
, hashtable
);
3270 /* Now write the strings. */
3271 H_PUT_32 (abfd
, stringsize
, temp
);
3272 if (bfd_bwrite ((PTR
) temp
, (bfd_size_type
) 4, abfd
) != 4)
3274 for (i
= 0; i
< orl_count
; i
++)
3278 len
= strlen (*map
[i
].name
) + 1;
3279 if (bfd_bwrite ((PTR
) (*map
[i
].name
), len
, abfd
) != len
)
3283 /* The spec sez this should be a newline. But in order to be
3284 bug-compatible for DECstation ar we use a null. */
3287 if (bfd_bwrite ("", (bfd_size_type
) 1, abfd
) != 1)
3294 /* See whether this BFD is an archive. If it is, read in the armap
3295 and the extended name table. */
3298 _bfd_ecoff_archive_p (abfd
)
3301 struct artdata
*tdata_hold
;
3302 char armag
[SARMAG
+ 1];
3305 if (bfd_bread ((PTR
) armag
, (bfd_size_type
) SARMAG
, abfd
) != SARMAG
)
3307 if (bfd_get_error () != bfd_error_system_call
)
3308 bfd_set_error (bfd_error_wrong_format
);
3309 return (const bfd_target
*) NULL
;
3312 if (strncmp (armag
, ARMAG
, SARMAG
) != 0)
3314 bfd_set_error (bfd_error_wrong_format
);
3318 tdata_hold
= bfd_ardata (abfd
);
3320 amt
= sizeof (struct artdata
);
3321 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
3322 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3324 bfd_ardata (abfd
) = tdata_hold
;
3325 return (const bfd_target
*) NULL
;
3328 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3329 bfd_ardata (abfd
)->cache
= NULL
;
3330 bfd_ardata (abfd
)->archive_head
= NULL
;
3331 bfd_ardata (abfd
)->symdefs
= NULL
;
3332 bfd_ardata (abfd
)->extended_names
= NULL
;
3333 bfd_ardata (abfd
)->tdata
= NULL
;
3335 if (! _bfd_ecoff_slurp_armap (abfd
)
3336 || ! _bfd_ecoff_slurp_extended_name_table (abfd
))
3338 bfd_release (abfd
, bfd_ardata (abfd
));
3339 bfd_ardata (abfd
) = tdata_hold
;
3340 return (const bfd_target
*) NULL
;
3343 if (bfd_has_map (abfd
))
3347 /* This archive has a map, so we may presume that the contents
3348 are object files. Make sure that if the first file in the
3349 archive can be recognized as an object file, it is for this
3350 target. If not, assume that this is the wrong format. If
3351 the first file is not an object file, somebody is doing
3352 something weird, and we permit it so that ar -t will work. */
3354 first
= bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
);
3357 first
->target_defaulted
= FALSE
;
3358 if (bfd_check_format (first
, bfd_object
)
3359 && first
->xvec
!= abfd
->xvec
)
3362 /* We ought to close `first' here, but we can't, because
3363 we have no way to remove it from the archive cache.
3364 It's close to impossible to figure out when we can
3365 release bfd_ardata. FIXME. */
3366 (void) bfd_close (first
);
3367 bfd_release (abfd
, bfd_ardata (abfd
));
3369 bfd_set_error (bfd_error_wrong_object_format
);
3370 bfd_ardata (abfd
) = tdata_hold
;
3373 /* And we ought to close `first' here too. */
3380 /* ECOFF linker code. */
3382 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3383 PARAMS ((struct bfd_hash_entry
*entry
,
3384 struct bfd_hash_table
*table
,
3385 const char *string
));
3386 static bfd_boolean ecoff_link_add_archive_symbols
3387 PARAMS ((bfd
*, struct bfd_link_info
*));
3388 static bfd_boolean ecoff_link_check_archive_element
3389 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_boolean
*pneeded
));
3390 static bfd_boolean ecoff_link_add_object_symbols
3391 PARAMS ((bfd
*, struct bfd_link_info
*));
3392 static bfd_boolean ecoff_link_add_externals
3393 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3395 /* Routine to create an entry in an ECOFF link hash table. */
3397 static struct bfd_hash_entry
*
3398 ecoff_link_hash_newfunc (entry
, table
, string
)
3399 struct bfd_hash_entry
*entry
;
3400 struct bfd_hash_table
*table
;
3403 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3405 /* Allocate the structure if it has not already been allocated by a
3407 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3408 ret
= ((struct ecoff_link_hash_entry
*)
3409 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3410 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3413 /* Call the allocation method of the superclass. */
3414 ret
= ((struct ecoff_link_hash_entry
*)
3415 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3420 /* Set local fields. */
3426 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3428 return (struct bfd_hash_entry
*) ret
;
3431 /* Create an ECOFF link hash table. */
3433 struct bfd_link_hash_table
*
3434 _bfd_ecoff_bfd_link_hash_table_create (abfd
)
3437 struct ecoff_link_hash_table
*ret
;
3438 bfd_size_type amt
= sizeof (struct ecoff_link_hash_table
);
3440 ret
= (struct ecoff_link_hash_table
*) bfd_malloc (amt
);
3443 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3444 ecoff_link_hash_newfunc
))
3447 return (struct bfd_link_hash_table
*) NULL
;
3452 /* Look up an entry in an ECOFF link hash table. */
3454 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3455 ((struct ecoff_link_hash_entry *) \
3456 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3458 /* Traverse an ECOFF link hash table. */
3460 #define ecoff_link_hash_traverse(table, func, info) \
3461 (bfd_link_hash_traverse \
3463 (bfd_boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3466 /* Get the ECOFF link hash table from the info structure. This is
3469 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3471 /* Given an ECOFF BFD, add symbols to the global hash table as
3475 _bfd_ecoff_bfd_link_add_symbols (abfd
, info
)
3477 struct bfd_link_info
*info
;
3479 switch (bfd_get_format (abfd
))
3482 return ecoff_link_add_object_symbols (abfd
, info
);
3484 return ecoff_link_add_archive_symbols (abfd
, info
);
3486 bfd_set_error (bfd_error_wrong_format
);
3491 /* Add the symbols from an archive file to the global hash table.
3492 This looks through the undefined symbols, looks each one up in the
3493 archive hash table, and adds any associated object file. We do not
3494 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3495 already have a hash table, so there is no reason to construct
3499 ecoff_link_add_archive_symbols (abfd
, info
)
3501 struct bfd_link_info
*info
;
3503 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3504 const bfd_byte
*raw_armap
;
3505 struct bfd_link_hash_entry
**pundef
;
3506 unsigned int armap_count
;
3507 unsigned int armap_log
;
3509 const bfd_byte
*hashtable
;
3510 const char *stringbase
;
3512 if (! bfd_has_map (abfd
))
3514 /* An empty archive is a special case. */
3515 if (bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
) == NULL
)
3517 bfd_set_error (bfd_error_no_armap
);
3521 /* If we don't have any raw data for this archive, as can happen on
3522 Irix 4.0.5F, we call the generic routine.
3523 FIXME: We should be more clever about this, since someday tdata
3524 may get to something for a generic archive. */
3525 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3526 if (raw_armap
== (bfd_byte
*) NULL
)
3527 return (_bfd_generic_link_add_archive_symbols
3528 (abfd
, info
, ecoff_link_check_archive_element
));
3530 armap_count
= H_GET_32 (abfd
, raw_armap
);
3533 for (i
= 1; i
< armap_count
; i
<<= 1)
3535 BFD_ASSERT (i
== armap_count
);
3537 hashtable
= raw_armap
+ 4;
3538 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3540 /* Look through the list of undefined symbols. */
3541 pundef
= &info
->hash
->undefs
;
3542 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3544 struct bfd_link_hash_entry
*h
;
3545 unsigned int hash
, rehash
;
3546 unsigned int file_offset
;
3552 /* When a symbol is defined, it is not necessarily removed from
3554 if (h
->type
!= bfd_link_hash_undefined
3555 && h
->type
!= bfd_link_hash_common
)
3557 /* Remove this entry from the list, for general cleanliness
3558 and because we are going to look through the list again
3559 if we search any more libraries. We can't remove the
3560 entry if it is the tail, because that would lose any
3561 entries we add to the list later on. */
3562 if (*pundef
!= info
->hash
->undefs_tail
)
3563 *pundef
= (*pundef
)->next
;
3565 pundef
= &(*pundef
)->next
;
3569 /* Native ECOFF linkers do not pull in archive elements merely
3570 to satisfy common definitions, so neither do we. We leave
3571 them on the list, though, in case we are linking against some
3572 other object format. */
3573 if (h
->type
!= bfd_link_hash_undefined
)
3575 pundef
= &(*pundef
)->next
;
3579 /* Look for this symbol in the archive hash table. */
3580 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3583 file_offset
= H_GET_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3584 if (file_offset
== 0)
3586 /* Nothing in this slot. */
3587 pundef
= &(*pundef
)->next
;
3591 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (hash
* 8));
3592 if (name
[0] != h
->root
.string
[0]
3593 || strcmp (name
, h
->root
.string
) != 0)
3598 /* That was the wrong symbol. Try rehashing. */
3600 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3602 srch
= (srch
+ rehash
) & (armap_count
- 1))
3604 file_offset
= H_GET_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3605 if (file_offset
== 0)
3607 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (srch
* 8));
3608 if (name
[0] == h
->root
.string
[0]
3609 && strcmp (name
, h
->root
.string
) == 0)
3618 pundef
= &(*pundef
)->next
;
3625 element
= (*backend
->get_elt_at_filepos
) (abfd
, (file_ptr
) file_offset
);
3626 if (element
== (bfd
*) NULL
)
3629 if (! bfd_check_format (element
, bfd_object
))
3632 /* Unlike the generic linker, we know that this element provides
3633 a definition for an undefined symbol and we know that we want
3634 to include it. We don't need to check anything. */
3635 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3637 if (! ecoff_link_add_object_symbols (element
, info
))
3640 pundef
= &(*pundef
)->next
;
3646 /* This is called if we used _bfd_generic_link_add_archive_symbols
3647 because we were not dealing with an ECOFF archive. */
3650 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3652 struct bfd_link_info
*info
;
3653 bfd_boolean
*pneeded
;
3655 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3656 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3657 = backend
->debug_swap
.swap_ext_in
;
3659 bfd_size_type external_ext_size
;
3660 PTR external_ext
= NULL
;
3661 bfd_size_type esize
;
3668 if (! ecoff_slurp_symbolic_header (abfd
))
3671 /* If there are no symbols, we don't want it. */
3672 if (bfd_get_symcount (abfd
) == 0)
3673 goto successful_return
;
3675 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3677 /* Read in the external symbols and external strings. */
3678 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3679 esize
= symhdr
->iextMax
* external_ext_size
;
3680 external_ext
= (PTR
) bfd_malloc (esize
);
3681 if (external_ext
== NULL
&& esize
!= 0)
3684 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbExtOffset
, SEEK_SET
) != 0
3685 || bfd_bread (external_ext
, esize
, abfd
) != esize
)
3688 ssext
= (char *) bfd_malloc ((bfd_size_type
) symhdr
->issExtMax
);
3689 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3692 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3693 || (bfd_bread (ssext
, (bfd_size_type
) symhdr
->issExtMax
, abfd
)
3694 != (bfd_size_type
) symhdr
->issExtMax
))
3697 /* Look through the external symbols to see if they define some
3698 symbol that is currently undefined. */
3699 ext_ptr
= (char *) external_ext
;
3700 ext_end
= ext_ptr
+ esize
;
3701 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3706 struct bfd_link_hash_entry
*h
;
3708 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3710 /* See if this symbol defines something. */
3711 if (esym
.asym
.st
!= stGlobal
3712 && esym
.asym
.st
!= stLabel
3713 && esym
.asym
.st
!= stProc
)
3716 switch (esym
.asym
.sc
)
3740 name
= ssext
+ esym
.asym
.iss
;
3741 h
= bfd_link_hash_lookup (info
->hash
, name
, FALSE
, FALSE
, TRUE
);
3743 /* Unlike the generic linker, we do not pull in elements because
3744 of common symbols. */
3745 if (h
== (struct bfd_link_hash_entry
*) NULL
3746 || h
->type
!= bfd_link_hash_undefined
)
3749 /* Include this element. */
3750 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3752 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3756 goto successful_return
;
3760 if (external_ext
!= NULL
)
3761 free (external_ext
);
3766 if (external_ext
!= NULL
)
3767 free (external_ext
);
3773 /* Add symbols from an ECOFF object file to the global linker hash
3777 ecoff_link_add_object_symbols (abfd
, info
)
3779 struct bfd_link_info
*info
;
3782 bfd_size_type external_ext_size
;
3783 PTR external_ext
= NULL
;
3784 bfd_size_type esize
;
3788 if (! ecoff_slurp_symbolic_header (abfd
))
3791 /* If there are no symbols, we don't want it. */
3792 if (bfd_get_symcount (abfd
) == 0)
3795 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3797 /* Read in the external symbols and external strings. */
3798 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3799 esize
= symhdr
->iextMax
* external_ext_size
;
3800 external_ext
= (PTR
) bfd_malloc (esize
);
3801 if (external_ext
== NULL
&& esize
!= 0)
3804 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbExtOffset
, SEEK_SET
) != 0
3805 || bfd_bread (external_ext
, esize
, abfd
) != esize
)
3808 ssext
= (char *) bfd_malloc ((bfd_size_type
) symhdr
->issExtMax
);
3809 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3812 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3813 || (bfd_bread (ssext
, (bfd_size_type
) symhdr
->issExtMax
, abfd
)
3814 != (bfd_size_type
) symhdr
->issExtMax
))
3817 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3821 if (external_ext
!= NULL
)
3822 free (external_ext
);
3828 if (external_ext
!= NULL
)
3829 free (external_ext
);
3833 /* Add the external symbols of an object file to the global linker
3834 hash table. The external symbols and strings we are passed are
3835 just allocated on the stack, and will be discarded. We must
3836 explicitly save any information we may need later on in the link.
3837 We do not want to read the external symbol information again. */
3840 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3842 struct bfd_link_info
*info
;
3846 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3847 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3848 = backend
->debug_swap
.swap_ext_in
;
3849 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3850 unsigned long ext_count
;
3851 struct bfd_link_hash_entry
**sym_hash
;
3856 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3859 amt
*= sizeof (struct bfd_link_hash_entry
*);
3860 sym_hash
= (struct bfd_link_hash_entry
**) bfd_alloc (abfd
, amt
);
3863 ecoff_data (abfd
)->sym_hashes
= (struct ecoff_link_hash_entry
**) sym_hash
;
3865 ext_ptr
= (char *) external_ext
;
3866 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3867 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3874 struct ecoff_link_hash_entry
*h
;
3878 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3880 /* Skip debugging symbols. */
3882 switch (esym
.asym
.st
)
3898 /* Get the information for this symbol. */
3899 value
= esym
.asym
.value
;
3900 switch (esym
.asym
.sc
)
3920 section
= bfd_make_section_old_way (abfd
, ".text");
3921 value
-= section
->vma
;
3924 section
= bfd_make_section_old_way (abfd
, ".data");
3925 value
-= section
->vma
;
3928 section
= bfd_make_section_old_way (abfd
, ".bss");
3929 value
-= section
->vma
;
3932 section
= bfd_abs_section_ptr
;
3935 section
= bfd_und_section_ptr
;
3938 section
= bfd_make_section_old_way (abfd
, ".sdata");
3939 value
-= section
->vma
;
3942 section
= bfd_make_section_old_way (abfd
, ".sbss");
3943 value
-= section
->vma
;
3946 section
= bfd_make_section_old_way (abfd
, ".rdata");
3947 value
-= section
->vma
;
3950 if (value
> ecoff_data (abfd
)->gp_size
)
3952 section
= bfd_com_section_ptr
;
3957 if (ecoff_scom_section
.name
== NULL
)
3959 /* Initialize the small common section. */
3960 ecoff_scom_section
.name
= SCOMMON
;
3961 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3962 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3963 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3964 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3965 ecoff_scom_symbol
.name
= SCOMMON
;
3966 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3967 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3968 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3970 section
= &ecoff_scom_section
;
3973 section
= bfd_und_section_ptr
;
3976 section
= bfd_make_section_old_way (abfd
, ".init");
3977 value
-= section
->vma
;
3980 section
= bfd_make_section_old_way (abfd
, ".fini");
3981 value
-= section
->vma
;
3984 section
= bfd_make_section_old_way (abfd
, ".rconst");
3985 value
-= section
->vma
;
3989 if (section
== (asection
*) NULL
)
3992 name
= ssext
+ esym
.asym
.iss
;
3994 if (! (_bfd_generic_link_add_one_symbol
3996 (flagword
) (esym
.weakext
? BSF_WEAK
: BSF_GLOBAL
),
3997 section
, value
, (const char *) NULL
, TRUE
, TRUE
, sym_hash
)))
4000 h
= (struct ecoff_link_hash_entry
*) *sym_hash
;
4002 /* If we are building an ECOFF hash table, save the external
4003 symbol information. */
4004 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
4006 if (h
->abfd
== (bfd
*) NULL
4007 || (! bfd_is_und_section (section
)
4008 && (! bfd_is_com_section (section
)
4009 || (h
->root
.type
!= bfd_link_hash_defined
4010 && h
->root
.type
!= bfd_link_hash_defweak
))))
4016 /* Remember whether this symbol was small undefined. */
4017 if (esym
.asym
.sc
== scSUndefined
)
4020 /* If this symbol was ever small undefined, it needs to wind
4021 up in a GP relative section. We can't control the
4022 section of a defined symbol, but we can control the
4023 section of a common symbol. This case is actually needed
4024 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
4026 && h
->root
.type
== bfd_link_hash_common
4027 && strcmp (h
->root
.u
.c
.p
->section
->name
, SCOMMON
) != 0)
4029 h
->root
.u
.c
.p
->section
= bfd_make_section_old_way (abfd
,
4031 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4032 if (h
->esym
.asym
.sc
== scCommon
)
4033 h
->esym
.asym
.sc
= scSCommon
;
4041 /* ECOFF final link routines. */
4043 static bfd_boolean ecoff_final_link_debug_accumulate
4044 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4046 static bfd_boolean ecoff_link_write_external
4047 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4048 static bfd_boolean ecoff_indirect_link_order
4049 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4050 struct bfd_link_order
*));
4051 static bfd_boolean ecoff_reloc_link_order
4052 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4053 struct bfd_link_order
*));
4055 /* Structure used to pass information to ecoff_link_write_external. */
4060 struct bfd_link_info
*info
;
4063 /* ECOFF final link routine. This looks through all the input BFDs
4064 and gathers together all the debugging information, and then
4065 processes all the link order information. This may cause it to
4066 close and reopen some input BFDs; I'll see how bad this is. */
4069 _bfd_ecoff_bfd_final_link (abfd
, info
)
4071 struct bfd_link_info
*info
;
4073 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4074 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4077 register bfd
*input_bfd
;
4079 struct bfd_link_order
*p
;
4080 struct extsym_info einfo
;
4082 /* We accumulate the debugging information counts in the symbolic
4084 symhdr
= &debug
->symbolic_header
;
4086 symhdr
->ilineMax
= 0;
4090 symhdr
->isymMax
= 0;
4091 symhdr
->ioptMax
= 0;
4092 symhdr
->iauxMax
= 0;
4094 symhdr
->issExtMax
= 0;
4097 symhdr
->iextMax
= 0;
4099 /* We accumulate the debugging information itself in the debug_info
4102 debug
->external_dnr
= NULL
;
4103 debug
->external_pdr
= NULL
;
4104 debug
->external_sym
= NULL
;
4105 debug
->external_opt
= NULL
;
4106 debug
->external_aux
= NULL
;
4108 debug
->ssext
= debug
->ssext_end
= NULL
;
4109 debug
->external_fdr
= NULL
;
4110 debug
->external_rfd
= NULL
;
4111 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4113 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4114 if (handle
== (PTR
) NULL
)
4117 /* Accumulate the debugging symbols from each input BFD. */
4118 for (input_bfd
= info
->input_bfds
;
4119 input_bfd
!= (bfd
*) NULL
;
4120 input_bfd
= input_bfd
->link_next
)
4124 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4126 /* Abitrarily set the symbolic header vstamp to the vstamp
4127 of the first object file in the link. */
4128 if (symhdr
->vstamp
== 0)
4130 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4131 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4135 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4136 debug
, &backend
->debug_swap
,
4141 /* Combine the register masks. */
4142 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4143 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4144 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4145 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4146 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4147 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4150 /* Write out the external symbols. */
4153 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4154 ecoff_link_write_external
,
4157 if (info
->relocateable
)
4159 /* We need to make a pass over the link_orders to count up the
4160 number of relocations we will need to output, so that we know
4161 how much space they will take up. */
4162 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4165 for (p
= o
->link_order_head
;
4166 p
!= (struct bfd_link_order
*) NULL
;
4168 if (p
->type
== bfd_indirect_link_order
)
4169 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4170 else if (p
->type
== bfd_section_reloc_link_order
4171 || p
->type
== bfd_symbol_reloc_link_order
)
4176 /* Compute the reloc and symbol file positions. */
4177 ecoff_compute_reloc_file_positions (abfd
);
4179 /* Write out the debugging information. */
4180 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4181 &backend
->debug_swap
, info
,
4182 ecoff_data (abfd
)->sym_filepos
))
4185 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4187 if (info
->relocateable
)
4189 /* Now reset the reloc_count field of the sections in the output
4190 BFD to 0, so that we can use them to keep track of how many
4191 relocs we have output thus far. */
4192 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4196 /* Get a value for the GP register. */
4197 if (ecoff_data (abfd
)->gp
== 0)
4199 struct bfd_link_hash_entry
*h
;
4201 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
4202 if (h
!= (struct bfd_link_hash_entry
*) NULL
4203 && h
->type
== bfd_link_hash_defined
)
4204 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4205 + h
->u
.def
.section
->output_section
->vma
4206 + h
->u
.def
.section
->output_offset
);
4207 else if (info
->relocateable
)
4211 /* Make up a value. */
4213 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4216 && (strcmp (o
->name
, _SBSS
) == 0
4217 || strcmp (o
->name
, _SDATA
) == 0
4218 || strcmp (o
->name
, _LIT4
) == 0
4219 || strcmp (o
->name
, _LIT8
) == 0
4220 || strcmp (o
->name
, _LITA
) == 0))
4223 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4227 /* If the relocate_section function needs to do a reloc
4228 involving the GP value, it should make a reloc_dangerous
4229 callback to warn that GP is not defined. */
4233 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4235 for (p
= o
->link_order_head
;
4236 p
!= (struct bfd_link_order
*) NULL
;
4239 if (p
->type
== bfd_indirect_link_order
4240 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4241 == bfd_target_ecoff_flavour
))
4243 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4246 else if (p
->type
== bfd_section_reloc_link_order
4247 || p
->type
== bfd_symbol_reloc_link_order
)
4249 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4254 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4260 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4262 ecoff_data (abfd
)->linker
= TRUE
;
4267 /* Accumulate the debugging information for an input BFD into the
4268 output BFD. This must read in the symbolic information of the
4272 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4275 struct bfd_link_info
*info
;
4278 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4279 const struct ecoff_debug_swap
* const swap
=
4280 &ecoff_backend (input_bfd
)->debug_swap
;
4281 HDRR
*symhdr
= &debug
->symbolic_header
;
4284 #define READ(ptr, offset, count, size, type) \
4285 if (symhdr->count == 0) \
4286 debug->ptr = NULL; \
4289 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
4290 debug->ptr = (type) bfd_malloc (amt); \
4291 if (debug->ptr == NULL) \
4294 goto return_something; \
4296 if (bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
4297 || bfd_bread (debug->ptr, amt, input_bfd) != amt) \
4300 goto return_something; \
4304 /* If raw_syments is not NULL, then the data was already by read by
4305 _bfd_ecoff_slurp_symbolic_info. */
4306 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4308 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4310 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4311 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4312 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4313 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4314 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4316 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4317 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4318 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4322 /* We do not read the external strings or the external symbols. */
4324 ret
= (bfd_ecoff_debug_accumulate
4325 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4326 &ecoff_backend (output_bfd
)->debug_swap
,
4327 input_bfd
, debug
, swap
, info
));
4330 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4332 if (debug
->line
!= NULL
)
4334 if (debug
->external_dnr
!= NULL
)
4335 free (debug
->external_dnr
);
4336 if (debug
->external_pdr
!= NULL
)
4337 free (debug
->external_pdr
);
4338 if (debug
->external_sym
!= NULL
)
4339 free (debug
->external_sym
);
4340 if (debug
->external_opt
!= NULL
)
4341 free (debug
->external_opt
);
4342 if (debug
->external_aux
!= NULL
)
4343 free (debug
->external_aux
);
4344 if (debug
->ss
!= NULL
)
4346 if (debug
->external_fdr
!= NULL
)
4347 free (debug
->external_fdr
);
4348 if (debug
->external_rfd
!= NULL
)
4349 free (debug
->external_rfd
);
4351 /* Make sure we don't accidentally follow one of these pointers
4352 into freed memory. */
4354 debug
->external_dnr
= NULL
;
4355 debug
->external_pdr
= NULL
;
4356 debug
->external_sym
= NULL
;
4357 debug
->external_opt
= NULL
;
4358 debug
->external_aux
= NULL
;
4360 debug
->external_fdr
= NULL
;
4361 debug
->external_rfd
= NULL
;
4367 /* Put out information for an external symbol. These come only from
4371 ecoff_link_write_external (h
, data
)
4372 struct ecoff_link_hash_entry
*h
;
4375 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4376 bfd
*output_bfd
= einfo
->abfd
;
4379 if (h
->root
.type
== bfd_link_hash_warning
)
4381 h
= (struct ecoff_link_hash_entry
*) h
->root
.u
.i
.link
;
4382 if (h
->root
.type
== bfd_link_hash_new
)
4386 /* We need to check if this symbol is being stripped. */
4387 if (h
->root
.type
== bfd_link_hash_undefined
4388 || h
->root
.type
== bfd_link_hash_undefweak
)
4390 else if (einfo
->info
->strip
== strip_all
4391 || (einfo
->info
->strip
== strip_some
4392 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4393 h
->root
.root
.string
,
4394 FALSE
, FALSE
) == NULL
))
4399 if (strip
|| h
->written
)
4402 if (h
->abfd
== (bfd
*) NULL
)
4405 h
->esym
.cobol_main
= 0;
4406 h
->esym
.weakext
= 0;
4407 h
->esym
.reserved
= 0;
4408 h
->esym
.ifd
= ifdNil
;
4409 h
->esym
.asym
.value
= 0;
4410 h
->esym
.asym
.st
= stGlobal
;
4412 if (h
->root
.type
!= bfd_link_hash_defined
4413 && h
->root
.type
!= bfd_link_hash_defweak
)
4414 h
->esym
.asym
.sc
= scAbs
;
4417 asection
*output_section
;
4420 output_section
= h
->root
.u
.def
.section
->output_section
;
4421 name
= bfd_section_name (output_section
->owner
, output_section
);
4423 if (strcmp (name
, _TEXT
) == 0)
4424 h
->esym
.asym
.sc
= scText
;
4425 else if (strcmp (name
, _DATA
) == 0)
4426 h
->esym
.asym
.sc
= scData
;
4427 else if (strcmp (name
, _SDATA
) == 0)
4428 h
->esym
.asym
.sc
= scSData
;
4429 else if (strcmp (name
, _RDATA
) == 0)
4430 h
->esym
.asym
.sc
= scRData
;
4431 else if (strcmp (name
, _BSS
) == 0)
4432 h
->esym
.asym
.sc
= scBss
;
4433 else if (strcmp (name
, _SBSS
) == 0)
4434 h
->esym
.asym
.sc
= scSBss
;
4435 else if (strcmp (name
, _INIT
) == 0)
4436 h
->esym
.asym
.sc
= scInit
;
4437 else if (strcmp (name
, _FINI
) == 0)
4438 h
->esym
.asym
.sc
= scFini
;
4439 else if (strcmp (name
, _PDATA
) == 0)
4440 h
->esym
.asym
.sc
= scPData
;
4441 else if (strcmp (name
, _XDATA
) == 0)
4442 h
->esym
.asym
.sc
= scXData
;
4443 else if (strcmp (name
, _RCONST
) == 0)
4444 h
->esym
.asym
.sc
= scRConst
;
4446 h
->esym
.asym
.sc
= scAbs
;
4449 h
->esym
.asym
.reserved
= 0;
4450 h
->esym
.asym
.index
= indexNil
;
4452 else if (h
->esym
.ifd
!= -1)
4454 struct ecoff_debug_info
*debug
;
4456 /* Adjust the FDR index for the symbol by that used for the
4458 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4459 BFD_ASSERT (h
->esym
.ifd
>= 0
4460 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4461 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4464 switch (h
->root
.type
)
4467 case bfd_link_hash_warning
:
4468 case bfd_link_hash_new
:
4470 case bfd_link_hash_undefined
:
4471 case bfd_link_hash_undefweak
:
4472 if (h
->esym
.asym
.sc
!= scUndefined
4473 && h
->esym
.asym
.sc
!= scSUndefined
)
4474 h
->esym
.asym
.sc
= scUndefined
;
4476 case bfd_link_hash_defined
:
4477 case bfd_link_hash_defweak
:
4478 if (h
->esym
.asym
.sc
== scUndefined
4479 || h
->esym
.asym
.sc
== scSUndefined
)
4480 h
->esym
.asym
.sc
= scAbs
;
4481 else if (h
->esym
.asym
.sc
== scCommon
)
4482 h
->esym
.asym
.sc
= scBss
;
4483 else if (h
->esym
.asym
.sc
== scSCommon
)
4484 h
->esym
.asym
.sc
= scSBss
;
4485 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4486 + h
->root
.u
.def
.section
->output_section
->vma
4487 + h
->root
.u
.def
.section
->output_offset
);
4489 case bfd_link_hash_common
:
4490 if (h
->esym
.asym
.sc
!= scCommon
4491 && h
->esym
.asym
.sc
!= scSCommon
)
4492 h
->esym
.asym
.sc
= scCommon
;
4493 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4495 case bfd_link_hash_indirect
:
4496 /* We ignore these symbols, since the indirected symbol is
4497 already in the hash table. */
4501 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4503 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4506 return (bfd_ecoff_debug_one_external
4507 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4508 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4512 /* Relocate and write an ECOFF section into an ECOFF output file. */
4515 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4517 struct bfd_link_info
*info
;
4518 asection
*output_section
;
4519 struct bfd_link_order
*link_order
;
4521 asection
*input_section
;
4523 struct ecoff_section_tdata
*section_tdata
;
4524 bfd_size_type raw_size
;
4525 bfd_size_type cooked_size
;
4526 bfd_byte
*contents
= NULL
;
4527 bfd_size_type external_reloc_size
;
4528 bfd_size_type external_relocs_size
;
4529 PTR external_relocs
= NULL
;
4532 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4534 if (link_order
->size
== 0)
4537 input_section
= link_order
->u
.indirect
.section
;
4538 input_bfd
= input_section
->owner
;
4539 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4541 raw_size
= input_section
->_raw_size
;
4542 cooked_size
= input_section
->_cooked_size
;
4543 if (cooked_size
== 0)
4544 cooked_size
= raw_size
;
4546 BFD_ASSERT (input_section
->output_section
== output_section
);
4547 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4548 BFD_ASSERT (cooked_size
== link_order
->size
);
4550 /* Get the section contents. We allocate memory for the larger of
4551 the size before relocating and the size after relocating. */
4552 amt
= raw_size
>= cooked_size
? raw_size
: cooked_size
;
4553 contents
= (bfd_byte
*) bfd_malloc (amt
);
4554 if (contents
== NULL
&& amt
!= 0)
4557 /* If we are relaxing, the contents may have already been read into
4558 memory, in which case we copy them into our new buffer. We don't
4559 simply reuse the old buffer in case cooked_size > raw_size. */
4560 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4561 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4562 memcpy (contents
, section_tdata
->contents
, (size_t) raw_size
);
4565 if (! bfd_get_section_contents (input_bfd
, input_section
,
4567 (file_ptr
) 0, raw_size
))
4571 /* Get the relocs. If we are relaxing MIPS code, they will already
4572 have been read in. Otherwise, we read them in now. */
4573 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4574 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4576 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4577 && section_tdata
->external_relocs
!= NULL
)
4578 external_relocs
= section_tdata
->external_relocs
;
4581 external_relocs
= (PTR
) bfd_malloc (external_relocs_size
);
4582 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4585 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4586 || (bfd_bread (external_relocs
, external_relocs_size
, input_bfd
)
4587 != external_relocs_size
))
4591 /* Relocate the section contents. */
4592 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4593 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4597 /* Write out the relocated section. */
4598 if (! bfd_set_section_contents (output_bfd
,
4601 (file_ptr
) input_section
->output_offset
,
4605 /* If we are producing relocateable output, the relocs were
4606 modified, and we write them out now. We use the reloc_count
4607 field of output_section to keep track of the number of relocs we
4608 have output so far. */
4609 if (info
->relocateable
)
4611 file_ptr pos
= (output_section
->rel_filepos
4612 + output_section
->reloc_count
* external_reloc_size
);
4613 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
4614 || (bfd_bwrite (external_relocs
, external_relocs_size
, output_bfd
)
4615 != external_relocs_size
))
4617 output_section
->reloc_count
+= input_section
->reloc_count
;
4620 if (contents
!= NULL
)
4622 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4623 free (external_relocs
);
4627 if (contents
!= NULL
)
4629 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4630 free (external_relocs
);
4634 /* Generate a reloc when linking an ECOFF file. This is a reloc
4635 requested by the linker, and does come from any input file. This
4636 is used to build constructor and destructor tables when linking
4640 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4642 struct bfd_link_info
*info
;
4643 asection
*output_section
;
4644 struct bfd_link_order
*link_order
;
4646 enum bfd_link_order_type type
;
4650 struct internal_reloc in
;
4651 bfd_size_type external_reloc_size
;
4656 type
= link_order
->type
;
4658 addend
= link_order
->u
.reloc
.p
->addend
;
4660 /* We set up an arelent to pass to the backend adjust_reloc_out
4662 rel
.address
= link_order
->offset
;
4664 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4667 bfd_set_error (bfd_error_bad_value
);
4671 if (type
== bfd_section_reloc_link_order
)
4673 section
= link_order
->u
.reloc
.p
->u
.section
;
4674 rel
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
4678 struct bfd_link_hash_entry
*h
;
4680 /* Treat a reloc against a defined symbol as though it were
4681 actually against the section. */
4682 h
= bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4683 link_order
->u
.reloc
.p
->u
.name
,
4684 FALSE
, FALSE
, FALSE
);
4686 && (h
->type
== bfd_link_hash_defined
4687 || h
->type
== bfd_link_hash_defweak
))
4689 type
= bfd_section_reloc_link_order
;
4690 section
= h
->u
.def
.section
->output_section
;
4691 /* It seems that we ought to add the symbol value to the
4692 addend here, but in practice it has already been added
4693 because it was passed to constructor_callback. */
4694 addend
+= section
->vma
+ h
->u
.def
.section
->output_offset
;
4698 /* We can't set up a reloc against a symbol correctly,
4699 because we have no asymbol structure. Currently no
4700 adjust_reloc_out routine cares. */
4701 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4705 /* All ECOFF relocs are in-place. Put the addend into the object
4708 BFD_ASSERT (rel
.howto
->partial_inplace
);
4712 bfd_reloc_status_type rstat
;
4715 size
= bfd_get_reloc_size (rel
.howto
);
4716 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4717 if (buf
== (bfd_byte
*) NULL
)
4719 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4720 (bfd_vma
) addend
, buf
);
4726 case bfd_reloc_outofrange
:
4728 case bfd_reloc_overflow
:
4729 if (! ((*info
->callbacks
->reloc_overflow
)
4731 (link_order
->type
== bfd_section_reloc_link_order
4732 ? bfd_section_name (output_bfd
, section
)
4733 : link_order
->u
.reloc
.p
->u
.name
),
4734 rel
.howto
->name
, addend
, (bfd
*) NULL
,
4735 (asection
*) NULL
, (bfd_vma
) 0)))
4742 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4743 (file_ptr
) link_order
->offset
, size
);
4751 /* Move the information into an internal_reloc structure. */
4752 in
.r_vaddr
= (rel
.address
4753 + bfd_get_section_vma (output_bfd
, output_section
));
4754 in
.r_type
= rel
.howto
->type
;
4756 if (type
== bfd_symbol_reloc_link_order
)
4758 struct ecoff_link_hash_entry
*h
;
4760 h
= ((struct ecoff_link_hash_entry
*)
4761 bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4762 link_order
->u
.reloc
.p
->u
.name
,
4763 FALSE
, FALSE
, TRUE
));
4764 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4766 in
.r_symndx
= h
->indx
;
4769 if (! ((*info
->callbacks
->unattached_reloc
)
4770 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4771 (asection
*) NULL
, (bfd_vma
) 0)))
4781 name
= bfd_get_section_name (output_bfd
, section
);
4782 if (strcmp (name
, ".text") == 0)
4783 in
.r_symndx
= RELOC_SECTION_TEXT
;
4784 else if (strcmp (name
, ".rdata") == 0)
4785 in
.r_symndx
= RELOC_SECTION_RDATA
;
4786 else if (strcmp (name
, ".data") == 0)
4787 in
.r_symndx
= RELOC_SECTION_DATA
;
4788 else if (strcmp (name
, ".sdata") == 0)
4789 in
.r_symndx
= RELOC_SECTION_SDATA
;
4790 else if (strcmp (name
, ".sbss") == 0)
4791 in
.r_symndx
= RELOC_SECTION_SBSS
;
4792 else if (strcmp (name
, ".bss") == 0)
4793 in
.r_symndx
= RELOC_SECTION_BSS
;
4794 else if (strcmp (name
, ".init") == 0)
4795 in
.r_symndx
= RELOC_SECTION_INIT
;
4796 else if (strcmp (name
, ".lit8") == 0)
4797 in
.r_symndx
= RELOC_SECTION_LIT8
;
4798 else if (strcmp (name
, ".lit4") == 0)
4799 in
.r_symndx
= RELOC_SECTION_LIT4
;
4800 else if (strcmp (name
, ".xdata") == 0)
4801 in
.r_symndx
= RELOC_SECTION_XDATA
;
4802 else if (strcmp (name
, ".pdata") == 0)
4803 in
.r_symndx
= RELOC_SECTION_PDATA
;
4804 else if (strcmp (name
, ".fini") == 0)
4805 in
.r_symndx
= RELOC_SECTION_FINI
;
4806 else if (strcmp (name
, ".lita") == 0)
4807 in
.r_symndx
= RELOC_SECTION_LITA
;
4808 else if (strcmp (name
, "*ABS*") == 0)
4809 in
.r_symndx
= RELOC_SECTION_ABS
;
4810 else if (strcmp (name
, ".rconst") == 0)
4811 in
.r_symndx
= RELOC_SECTION_RCONST
;
4817 /* Let the BFD backend adjust the reloc. */
4818 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4820 /* Get some memory and swap out the reloc. */
4821 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4822 rbuf
= (bfd_byte
*) bfd_malloc (external_reloc_size
);
4823 if (rbuf
== (bfd_byte
*) NULL
)
4826 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4828 pos
= (output_section
->rel_filepos
4829 + output_section
->reloc_count
* external_reloc_size
);
4830 ok
= (bfd_seek (output_bfd
, pos
, SEEK_SET
) == 0
4831 && (bfd_bwrite ((PTR
) rbuf
, external_reloc_size
, output_bfd
)
4832 == external_reloc_size
));
4835 ++output_section
->reloc_count
;