1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
3 2002, 2003 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 /* sec_info_type, use_rela_p, has_tls_reloc, */
86 /* need_finalize_relax, has_gp_reloc, */
88 /* flag13, flag14, flag15, flag16, flag20, flag24, */
90 /* vma, lma, _cooked_size, _raw_size, */
92 /* output_offset, output_section, alignment_power, */
94 /* relocation, orelocation, reloc_count, filepos, rel_filepos, */
96 /* line_filepos, userdata, contents, lineno, lineno_count, */
97 0, NULL
, NULL
, NULL
, 0,
98 /* entsize, comdat, kept_section, moving_line_filepos, */
100 /* target_index, used_by_bfd, constructor_chain, owner, */
103 (struct bfd_symbol
*) NULL
,
104 /* symbol_ptr_ptr, */
105 (struct bfd_symbol
**) NULL
,
106 /* link_order_head, link_order_tail */
110 /* Create an ECOFF object. */
113 _bfd_ecoff_mkobject (abfd
)
116 bfd_size_type amt
= sizeof (ecoff_data_type
);
118 abfd
->tdata
.ecoff_obj_data
= (struct ecoff_tdata
*) bfd_zalloc (abfd
, amt
);
119 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
125 /* This is a hook called by coff_real_object_p to create any backend
126 specific information. */
129 _bfd_ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
134 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
135 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
136 ecoff_data_type
*ecoff
;
138 if (! _bfd_ecoff_mkobject (abfd
))
141 ecoff
= ecoff_data (abfd
);
143 ecoff
->sym_filepos
= internal_f
->f_symptr
;
145 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
149 ecoff
->text_start
= internal_a
->text_start
;
150 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
151 ecoff
->gp
= internal_a
->gp_value
;
152 ecoff
->gprmask
= internal_a
->gprmask
;
153 for (i
= 0; i
< 4; i
++)
154 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
155 ecoff
->fprmask
= internal_a
->fprmask
;
156 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
157 abfd
->flags
|= D_PAGED
;
159 abfd
->flags
&=~ D_PAGED
;
162 /* It turns out that no special action is required by the MIPS or
163 Alpha ECOFF backends. They have different information in the
164 a.out header, but we just copy it all (e.g., gprmask, cprmask and
165 fprmask) and let the swapping routines ensure that only relevant
166 information is written out. */
171 /* Initialize a new section. */
174 _bfd_ecoff_new_section_hook (abfd
, section
)
175 bfd
*abfd ATTRIBUTE_UNUSED
;
178 section
->alignment_power
= 4;
180 if (strcmp (section
->name
, _TEXT
) == 0
181 || strcmp (section
->name
, _INIT
) == 0
182 || strcmp (section
->name
, _FINI
) == 0)
183 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
184 else if (strcmp (section
->name
, _DATA
) == 0
185 || strcmp (section
->name
, _SDATA
) == 0)
186 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
187 else if (strcmp (section
->name
, _RDATA
) == 0
188 || strcmp (section
->name
, _LIT8
) == 0
189 || strcmp (section
->name
, _LIT4
) == 0
190 || strcmp (section
->name
, _RCONST
) == 0
191 || strcmp (section
->name
, _PDATA
) == 0)
192 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
193 else if (strcmp (section
->name
, _BSS
) == 0
194 || strcmp (section
->name
, _SBSS
) == 0)
195 section
->flags
|= SEC_ALLOC
;
196 else if (strcmp (section
->name
, _LIB
) == 0)
197 /* An Irix 4 shared libary. */
198 section
->flags
|= SEC_COFF_SHARED_LIBRARY
;
200 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
201 uncertain about .init on some systems and I don't know how shared
207 /* Determine the machine architecture and type. This is called from
208 the generic COFF routines. It is the inverse of ecoff_get_magic,
209 below. This could be an ECOFF backend routine, with one version
210 for each target, but there aren't all that many ECOFF targets. */
213 _bfd_ecoff_set_arch_mach_hook (abfd
, filehdr
)
217 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
218 enum bfd_architecture arch
;
221 switch (internal_f
->f_magic
)
224 case MIPS_MAGIC_LITTLE
:
226 arch
= bfd_arch_mips
;
227 mach
= bfd_mach_mips3000
;
230 case MIPS_MAGIC_LITTLE2
:
231 case MIPS_MAGIC_BIG2
:
232 /* MIPS ISA level 2: the r6000. */
233 arch
= bfd_arch_mips
;
234 mach
= bfd_mach_mips6000
;
237 case MIPS_MAGIC_LITTLE3
:
238 case MIPS_MAGIC_BIG3
:
239 /* MIPS ISA level 3: the r4000. */
240 arch
= bfd_arch_mips
;
241 mach
= bfd_mach_mips4000
;
245 arch
= bfd_arch_alpha
;
250 arch
= bfd_arch_obscure
;
255 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
258 /* Get the magic number to use based on the architecture and machine.
259 This is the inverse of _bfd_ecoff_set_arch_mach_hook, above. */
262 ecoff_get_magic (abfd
)
267 switch (bfd_get_arch (abfd
))
270 switch (bfd_get_mach (abfd
))
274 case bfd_mach_mips3000
:
275 big
= MIPS_MAGIC_BIG
;
276 little
= MIPS_MAGIC_LITTLE
;
279 case bfd_mach_mips6000
:
280 big
= MIPS_MAGIC_BIG2
;
281 little
= MIPS_MAGIC_LITTLE2
;
284 case bfd_mach_mips4000
:
285 big
= MIPS_MAGIC_BIG3
;
286 little
= MIPS_MAGIC_LITTLE3
;
290 return bfd_big_endian (abfd
) ? big
: little
;
301 /* Get the section s_flags to use for a section. */
304 ecoff_sec_to_styp_flags (name
, flags
)
312 if (strcmp (name
, _TEXT
) == 0)
314 else if (strcmp (name
, _DATA
) == 0)
316 else if (strcmp (name
, _SDATA
) == 0)
318 else if (strcmp (name
, _RDATA
) == 0)
320 else if (strcmp (name
, _LITA
) == 0)
322 else if (strcmp (name
, _LIT8
) == 0)
324 else if (strcmp (name
, _LIT4
) == 0)
326 else if (strcmp (name
, _BSS
) == 0)
328 else if (strcmp (name
, _SBSS
) == 0)
330 else if (strcmp (name
, _INIT
) == 0)
331 styp
= STYP_ECOFF_INIT
;
332 else if (strcmp (name
, _FINI
) == 0)
333 styp
= STYP_ECOFF_FINI
;
334 else if (strcmp (name
, _PDATA
) == 0)
336 else if (strcmp (name
, _XDATA
) == 0)
338 else if (strcmp (name
, _LIB
) == 0)
339 styp
= STYP_ECOFF_LIB
;
340 else if (strcmp (name
, _GOT
) == 0)
342 else if (strcmp (name
, _HASH
) == 0)
344 else if (strcmp (name
, _DYNAMIC
) == 0)
346 else if (strcmp (name
, _LIBLIST
) == 0)
348 else if (strcmp (name
, _RELDYN
) == 0)
350 else if (strcmp (name
, _CONFLIC
) == 0)
352 else if (strcmp (name
, _DYNSTR
) == 0)
354 else if (strcmp (name
, _DYNSYM
) == 0)
356 else if (strcmp (name
, _COMMENT
) == 0)
359 flags
&=~ SEC_NEVER_LOAD
;
361 else if (strcmp (name
, _RCONST
) == 0)
363 else if (flags
& SEC_CODE
)
365 else if (flags
& SEC_DATA
)
367 else if (flags
& SEC_READONLY
)
369 else if (flags
& SEC_LOAD
)
374 if (flags
& SEC_NEVER_LOAD
)
380 /* Get the BFD flags to use for a section. */
383 _bfd_ecoff_styp_to_sec_flags (abfd
, hdr
, name
, section
, flags_ptr
)
384 bfd
*abfd ATTRIBUTE_UNUSED
;
386 const char *name ATTRIBUTE_UNUSED
;
387 asection
*section ATTRIBUTE_UNUSED
;
388 flagword
* flags_ptr
;
390 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
391 long styp_flags
= internal_s
->s_flags
;
392 flagword sec_flags
= 0;
394 if (styp_flags
& STYP_NOLOAD
)
395 sec_flags
|= SEC_NEVER_LOAD
;
397 /* For 386 COFF, at least, an unloadable text or data section is
398 actually a shared library section. */
399 if ((styp_flags
& STYP_TEXT
)
400 || (styp_flags
& STYP_ECOFF_INIT
)
401 || (styp_flags
& STYP_ECOFF_FINI
)
402 || (styp_flags
& STYP_DYNAMIC
)
403 || (styp_flags
& STYP_LIBLIST
)
404 || (styp_flags
& STYP_RELDYN
)
405 || styp_flags
== STYP_CONFLIC
406 || (styp_flags
& STYP_DYNSTR
)
407 || (styp_flags
& STYP_DYNSYM
)
408 || (styp_flags
& STYP_HASH
))
410 if (sec_flags
& SEC_NEVER_LOAD
)
411 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
413 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
415 else if ((styp_flags
& STYP_DATA
)
416 || (styp_flags
& STYP_RDATA
)
417 || (styp_flags
& STYP_SDATA
)
418 || styp_flags
== STYP_PDATA
419 || styp_flags
== STYP_XDATA
420 || (styp_flags
& STYP_GOT
)
421 || styp_flags
== STYP_RCONST
)
423 if (sec_flags
& SEC_NEVER_LOAD
)
424 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
426 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
427 if ((styp_flags
& STYP_RDATA
)
428 || styp_flags
== STYP_PDATA
429 || styp_flags
== STYP_RCONST
)
430 sec_flags
|= SEC_READONLY
;
432 else if ((styp_flags
& STYP_BSS
)
433 || (styp_flags
& STYP_SBSS
))
434 sec_flags
|= SEC_ALLOC
;
435 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
436 sec_flags
|= SEC_NEVER_LOAD
;
437 else if ((styp_flags
& STYP_LITA
)
438 || (styp_flags
& STYP_LIT8
)
439 || (styp_flags
& STYP_LIT4
))
440 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
441 else if (styp_flags
& STYP_ECOFF_LIB
)
442 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
444 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
446 * flags_ptr
= sec_flags
;
450 /* Read in the symbolic header for an ECOFF object file. */
453 ecoff_slurp_symbolic_header (abfd
)
456 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
457 bfd_size_type external_hdr_size
;
459 HDRR
*internal_symhdr
;
461 /* See if we've already read it in. */
462 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
463 backend
->debug_swap
.sym_magic
)
466 /* See whether there is a symbolic header. */
467 if (ecoff_data (abfd
)->sym_filepos
== 0)
469 bfd_get_symcount (abfd
) = 0;
473 /* At this point bfd_get_symcount (abfd) holds the number of symbols
474 as read from the file header, but on ECOFF this is always the
475 size of the symbolic information header. It would be cleaner to
476 handle this when we first read the file in coffgen.c. */
477 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
478 if (bfd_get_symcount (abfd
) != external_hdr_size
)
480 bfd_set_error (bfd_error_bad_value
);
484 /* Read the symbolic information header. */
485 raw
= (PTR
) bfd_malloc (external_hdr_size
);
489 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) != 0
490 || bfd_bread (raw
, external_hdr_size
, abfd
) != external_hdr_size
)
492 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
493 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
495 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
497 bfd_set_error (bfd_error_bad_value
);
501 /* Now we can get the correct number of symbols. */
502 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
503 + internal_symhdr
->iextMax
);
514 /* Read in and swap the important symbolic information for an ECOFF
515 object file. This is called by gdb via the read_debug_info entry
516 point in the backend structure. */
519 _bfd_ecoff_slurp_symbolic_info (abfd
, ignore
, debug
)
521 asection
*ignore ATTRIBUTE_UNUSED
;
522 struct ecoff_debug_info
*debug
;
524 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
525 HDRR
*internal_symhdr
;
526 bfd_size_type raw_base
;
527 bfd_size_type raw_size
;
529 bfd_size_type external_fdr_size
;
533 bfd_size_type raw_end
;
534 bfd_size_type cb_end
;
538 BFD_ASSERT (debug
== &ecoff_data (abfd
)->debug_info
);
540 /* Check whether we've already gotten it, and whether there's any to
542 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
544 if (ecoff_data (abfd
)->sym_filepos
== 0)
546 bfd_get_symcount (abfd
) = 0;
550 if (! ecoff_slurp_symbolic_header (abfd
))
553 internal_symhdr
= &debug
->symbolic_header
;
555 /* Read all the symbolic information at once. */
556 raw_base
= (ecoff_data (abfd
)->sym_filepos
557 + backend
->debug_swap
.external_hdr_size
);
559 /* Alpha ecoff makes the determination of raw_size difficult. It has
560 an undocumented debug data section between the symhdr and the first
561 documented section. And the ordering of the sections varies between
562 statically and dynamically linked executables.
563 If bfd supports SEEK_END someday, this code could be simplified. */
566 #define UPDATE_RAW_END(start, count, size) \
567 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
568 if (cb_end > raw_end) \
571 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
572 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
573 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
574 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
575 /* eraxxon@alumni.rice.edu: ioptMax refers to the size of the
576 optimization symtab, not the number of entries */
577 UPDATE_RAW_END (cbOptOffset
, ioptMax
, sizeof (char));
578 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
579 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
580 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
581 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
582 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
583 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
585 #undef UPDATE_RAW_END
587 raw_size
= raw_end
- raw_base
;
590 ecoff_data (abfd
)->sym_filepos
= 0;
593 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
597 pos
= ecoff_data (abfd
)->sym_filepos
;
598 pos
+= backend
->debug_swap
.external_hdr_size
;
599 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
600 || bfd_bread (raw
, raw_size
, abfd
) != raw_size
)
602 bfd_release (abfd
, raw
);
606 ecoff_data (abfd
)->raw_syments
= raw
;
608 /* Get pointers for the numeric offsets in the HDRR structure. */
609 #define FIX(off1, off2, type) \
610 if (internal_symhdr->off1 == 0) \
611 debug->off2 = (type) NULL; \
613 debug->off2 = (type) ((char *) raw \
614 + (internal_symhdr->off1 \
617 FIX (cbLineOffset
, line
, unsigned char *);
618 FIX (cbDnOffset
, external_dnr
, PTR
);
619 FIX (cbPdOffset
, external_pdr
, PTR
);
620 FIX (cbSymOffset
, external_sym
, PTR
);
621 FIX (cbOptOffset
, external_opt
, PTR
);
622 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
623 FIX (cbSsOffset
, ss
, char *);
624 FIX (cbSsExtOffset
, ssext
, char *);
625 FIX (cbFdOffset
, external_fdr
, PTR
);
626 FIX (cbRfdOffset
, external_rfd
, PTR
);
627 FIX (cbExtOffset
, external_ext
, PTR
);
630 /* I don't want to always swap all the data, because it will just
631 waste time and most programs will never look at it. The only
632 time the linker needs most of the debugging information swapped
633 is when linking big-endian and little-endian MIPS object files
634 together, which is not a common occurrence.
636 We need to look at the fdr to deal with a lot of information in
637 the symbols, so we swap them here. */
638 amt
= internal_symhdr
->ifdMax
;
639 amt
*= sizeof (struct fdr
);
640 debug
->fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
641 if (debug
->fdr
== NULL
)
643 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
644 fdr_ptr
= debug
->fdr
;
645 fraw_src
= (char *) debug
->external_fdr
;
646 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
647 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
648 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
653 /* ECOFF symbol table routines. The ECOFF symbol table is described
654 in gcc/mips-tfile.c. */
656 /* ECOFF uses two common sections. One is the usual one, and the
657 other is for small objects. All the small objects are kept
658 together, and then referenced via the gp pointer, which yields
659 faster assembler code. This is what we use for the small common
661 static asection ecoff_scom_section
;
662 static asymbol ecoff_scom_symbol
;
663 static asymbol
*ecoff_scom_symbol_ptr
;
665 /* Create an empty symbol. */
668 _bfd_ecoff_make_empty_symbol (abfd
)
671 ecoff_symbol_type
*new;
672 bfd_size_type amt
= sizeof (ecoff_symbol_type
);
674 new = (ecoff_symbol_type
*) bfd_zalloc (abfd
, amt
);
675 if (new == (ecoff_symbol_type
*) NULL
)
676 return (asymbol
*) NULL
;
677 new->symbol
.section
= (asection
*) NULL
;
678 new->fdr
= (FDR
*) NULL
;
681 new->symbol
.the_bfd
= abfd
;
685 /* Set the BFD flags and section for an ECOFF symbol. */
688 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, weak
)
695 asym
->the_bfd
= abfd
;
696 asym
->value
= ecoff_sym
->value
;
697 asym
->section
= &bfd_debug_section
;
700 /* Most symbol types are just for debugging. */
701 switch (ecoff_sym
->st
)
710 if (ECOFF_IS_STAB (ecoff_sym
))
712 asym
->flags
= BSF_DEBUGGING
;
717 asym
->flags
= BSF_DEBUGGING
;
722 asym
->flags
= BSF_EXPORT
| BSF_WEAK
;
724 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
727 asym
->flags
= BSF_LOCAL
;
728 /* Normally, a local stProc symbol will have a corresponding
729 external symbol. We mark the local symbol as a debugging
730 symbol, in order to prevent nm from printing both out.
731 Similarly, we mark stLabel and stabs symbols as debugging
732 symbols. In both cases, we do want to set the value
733 correctly based on the symbol class. */
734 if (ecoff_sym
->st
== stProc
735 || ecoff_sym
->st
== stLabel
736 || ECOFF_IS_STAB (ecoff_sym
))
737 asym
->flags
|= BSF_DEBUGGING
;
740 if (ecoff_sym
->st
== stProc
|| ecoff_sym
->st
== stStaticProc
)
741 asym
->flags
|= BSF_FUNCTION
;
743 switch (ecoff_sym
->sc
)
746 /* Used for compiler generated labels. Leave them in the
747 debugging section, and mark them as local. If BSF_DEBUGGING
748 is set, then nm does not display them for some reason. If no
749 flags are set then the linker whines about them. */
750 asym
->flags
= BSF_LOCAL
;
753 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
754 asym
->value
-= asym
->section
->vma
;
757 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
758 asym
->value
-= asym
->section
->vma
;
761 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
762 asym
->value
-= asym
->section
->vma
;
765 asym
->flags
= BSF_DEBUGGING
;
768 asym
->section
= bfd_abs_section_ptr
;
771 asym
->section
= bfd_und_section_ptr
;
781 asym
->flags
= BSF_DEBUGGING
;
784 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
785 asym
->value
-= asym
->section
->vma
;
788 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
789 asym
->value
-= asym
->section
->vma
;
792 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
793 asym
->value
-= asym
->section
->vma
;
796 asym
->flags
= BSF_DEBUGGING
;
799 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
801 asym
->section
= bfd_com_section_ptr
;
807 if (ecoff_scom_section
.name
== NULL
)
809 /* Initialize the small common section. */
810 ecoff_scom_section
.name
= SCOMMON
;
811 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
812 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
813 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
814 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
815 ecoff_scom_symbol
.name
= SCOMMON
;
816 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
817 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
818 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
820 asym
->section
= &ecoff_scom_section
;
825 asym
->flags
= BSF_DEBUGGING
;
828 asym
->section
= bfd_und_section_ptr
;
833 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
834 asym
->value
-= asym
->section
->vma
;
839 asym
->flags
= BSF_DEBUGGING
;
842 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
843 asym
->value
-= asym
->section
->vma
;
846 asym
->section
= bfd_make_section_old_way (abfd
, ".rconst");
847 asym
->value
-= asym
->section
->vma
;
853 /* Look for special constructors symbols and make relocation entries
854 in a special construction section. These are produced by the
855 -fgnu-linker argument to g++. */
856 if (ECOFF_IS_STAB (ecoff_sym
))
858 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
868 /* This code is no longer needed. It used to be used to
869 make the linker handle set symbols, but they are now
870 handled in the add_symbols routine instead. */
874 arelent_chain
*reloc_chain
;
875 unsigned int bitsize
;
878 /* Get a section with the same name as the symbol (usually
879 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
880 name ___CTOR_LIST (three underscores). We need
881 __CTOR_LIST (two underscores), since ECOFF doesn't use
882 a leading underscore. This should be handled by gcc,
883 but instead we do it here. Actually, this should all
884 be done differently anyhow. */
885 name
= bfd_asymbol_name (asym
);
886 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
891 section
= bfd_get_section_by_name (abfd
, name
);
892 if (section
== (asection
*) NULL
)
896 amt
= strlen (name
) + 1;
897 copy
= (char *) bfd_alloc (abfd
, amt
);
901 section
= bfd_make_section (abfd
, copy
);
904 /* Build a reloc pointing to this constructor. */
905 amt
= sizeof (arelent_chain
);
906 reloc_chain
= (arelent_chain
*) bfd_alloc (abfd
, amt
);
909 reloc_chain
->relent
.sym_ptr_ptr
=
910 bfd_get_section (asym
)->symbol_ptr_ptr
;
911 reloc_chain
->relent
.address
= section
->_raw_size
;
912 reloc_chain
->relent
.addend
= asym
->value
;
913 reloc_chain
->relent
.howto
=
914 ecoff_backend (abfd
)->constructor_reloc
;
916 /* Set up the constructor section to hold the reloc. */
917 section
->flags
= SEC_CONSTRUCTOR
;
918 ++section
->reloc_count
;
920 /* Constructor sections must be rounded to a boundary
921 based on the bitsize. These are not real sections--
922 they are handled specially by the linker--so the ECOFF
923 16 byte alignment restriction does not apply. */
924 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
925 section
->alignment_power
= 1;
926 while ((1 << section
->alignment_power
) < bitsize
/ 8)
927 ++section
->alignment_power
;
929 reloc_chain
->next
= section
->constructor_chain
;
930 section
->constructor_chain
= reloc_chain
;
931 section
->_raw_size
+= bitsize
/ 8;
935 /* Mark the symbol as a constructor. */
936 asym
->flags
|= BSF_CONSTRUCTOR
;
944 /* Read an ECOFF symbol table. */
947 _bfd_ecoff_slurp_symbol_table (abfd
)
950 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
951 const bfd_size_type external_ext_size
952 = backend
->debug_swap
.external_ext_size
;
953 const bfd_size_type external_sym_size
954 = backend
->debug_swap
.external_sym_size
;
955 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
956 = backend
->debug_swap
.swap_ext_in
;
957 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
958 = backend
->debug_swap
.swap_sym_in
;
959 bfd_size_type internal_size
;
960 ecoff_symbol_type
*internal
;
961 ecoff_symbol_type
*internal_ptr
;
967 /* If we've already read in the symbol table, do nothing. */
968 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
971 /* Get the symbolic information. */
972 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
973 &ecoff_data (abfd
)->debug_info
))
975 if (bfd_get_symcount (abfd
) == 0)
978 internal_size
= bfd_get_symcount (abfd
);
979 internal_size
*= sizeof (ecoff_symbol_type
);
980 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
981 if (internal
== NULL
)
984 internal_ptr
= internal
;
985 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
987 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
988 * external_ext_size
));
989 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
993 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
994 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
995 + internal_esym
.asym
.iss
);
996 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
997 &internal_ptr
->symbol
, 1,
998 internal_esym
.weakext
))
1000 /* The alpha uses a negative ifd field for section symbols. */
1001 if (internal_esym
.ifd
>= 0)
1002 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1003 + internal_esym
.ifd
);
1005 internal_ptr
->fdr
= NULL
;
1006 internal_ptr
->local
= FALSE
;
1007 internal_ptr
->native
= (PTR
) eraw_src
;
1010 /* The local symbols must be accessed via the fdr's, because the
1011 string and aux indices are relative to the fdr information. */
1012 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1013 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1014 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1019 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1020 + fdr_ptr
->isymBase
* external_sym_size
);
1021 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1023 lraw_src
< lraw_end
;
1024 lraw_src
+= external_sym_size
, internal_ptr
++)
1028 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1029 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1031 + internal_sym
.iss
);
1032 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1033 &internal_ptr
->symbol
, 0, 0))
1035 internal_ptr
->fdr
= fdr_ptr
;
1036 internal_ptr
->local
= TRUE
;
1037 internal_ptr
->native
= (PTR
) lraw_src
;
1041 ecoff_data (abfd
)->canonical_symbols
= internal
;
1046 /* Return the amount of space needed for the canonical symbols. */
1049 _bfd_ecoff_get_symtab_upper_bound (abfd
)
1052 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
1053 &ecoff_data (abfd
)->debug_info
))
1056 if (bfd_get_symcount (abfd
) == 0)
1059 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1062 /* Get the canonical symbols. */
1065 _bfd_ecoff_canonicalize_symtab (abfd
, alocation
)
1067 asymbol
**alocation
;
1069 unsigned int counter
= 0;
1070 ecoff_symbol_type
*symbase
;
1071 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1073 if (! _bfd_ecoff_slurp_symbol_table (abfd
))
1075 if (bfd_get_symcount (abfd
) == 0)
1078 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1079 while (counter
< bfd_get_symcount (abfd
))
1081 *(location
++) = symbase
++;
1084 *location
++ = (ecoff_symbol_type
*) NULL
;
1085 return bfd_get_symcount (abfd
);
1088 /* Turn ECOFF type information into a printable string.
1089 ecoff_emit_aggregate and ecoff_type_to_string are from
1090 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1092 /* Write aggregate information to a string. */
1095 ecoff_emit_aggregate (abfd
, fdr
, string
, rndx
, isym
, which
)
1103 const struct ecoff_debug_swap
* const debug_swap
=
1104 &ecoff_backend (abfd
)->debug_swap
;
1105 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1106 unsigned int ifd
= rndx
->rfd
;
1107 unsigned int indx
= rndx
->index
;
1113 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1114 struct return type of a procedure compiled without -g. */
1115 if (ifd
== 0xffffffff
1116 || (rndx
->rfd
== 0xfff && indx
== 0))
1117 name
= "<undefined>";
1118 else if (indx
== indexNil
)
1124 if (debug_info
->external_rfd
== NULL
)
1125 fdr
= debug_info
->fdr
+ ifd
;
1130 (*debug_swap
->swap_rfd_in
) (abfd
,
1131 ((char *) debug_info
->external_rfd
1132 + ((fdr
->rfdBase
+ ifd
)
1133 * debug_swap
->external_rfd_size
)),
1135 fdr
= debug_info
->fdr
+ rfd
;
1138 indx
+= fdr
->isymBase
;
1140 (*debug_swap
->swap_sym_in
) (abfd
,
1141 ((char *) debug_info
->external_sym
1142 + indx
* debug_swap
->external_sym_size
),
1145 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1149 "%s %s { ifd = %u, index = %lu }",
1152 + debug_info
->symbolic_header
.iextMax
));
1155 /* Convert the type information to string format. */
1158 ecoff_type_to_string (abfd
, fdr
, indx
)
1163 union aux_ext
*aux_ptr
;
1172 unsigned int basic_type
;
1175 static char buffer2
[1024];
1180 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1181 bigendian
= fdr
->fBigendian
;
1183 for (i
= 0; i
< 7; i
++)
1185 qualifiers
[i
].low_bound
= 0;
1186 qualifiers
[i
].high_bound
= 0;
1187 qualifiers
[i
].stride
= 0;
1190 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == (bfd_vma
) -1)
1191 return "-1 (no type)";
1192 _bfd_ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1194 basic_type
= u
.ti
.bt
;
1195 qualifiers
[0].type
= u
.ti
.tq0
;
1196 qualifiers
[1].type
= u
.ti
.tq1
;
1197 qualifiers
[2].type
= u
.ti
.tq2
;
1198 qualifiers
[3].type
= u
.ti
.tq3
;
1199 qualifiers
[4].type
= u
.ti
.tq4
;
1200 qualifiers
[5].type
= u
.ti
.tq5
;
1201 qualifiers
[6].type
= tqNil
;
1203 /* Go get the basic type. */
1206 case btNil
: /* Undefined. */
1210 case btAdr
: /* Address - integer same size as pointer. */
1211 strcpy (p1
, "address");
1214 case btChar
: /* Character. */
1215 strcpy (p1
, "char");
1218 case btUChar
: /* Unsigned character. */
1219 strcpy (p1
, "unsigned char");
1222 case btShort
: /* Short. */
1223 strcpy (p1
, "short");
1226 case btUShort
: /* Unsigned short. */
1227 strcpy (p1
, "unsigned short");
1230 case btInt
: /* Int. */
1234 case btUInt
: /* Unsigned int. */
1235 strcpy (p1
, "unsigned int");
1238 case btLong
: /* Long. */
1239 strcpy (p1
, "long");
1242 case btULong
: /* Unsigned long. */
1243 strcpy (p1
, "unsigned long");
1246 case btFloat
: /* Float (real). */
1247 strcpy (p1
, "float");
1250 case btDouble
: /* Double (real). */
1251 strcpy (p1
, "double");
1254 /* Structures add 1-2 aux words:
1255 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1256 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1258 case btStruct
: /* Structure (Record). */
1259 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1260 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1261 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1263 indx
++; /* Skip aux words. */
1266 /* Unions add 1-2 aux words:
1267 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1268 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1270 case btUnion
: /* Union. */
1271 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1272 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1273 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1275 indx
++; /* Skip aux words. */
1278 /* Enumerations add 1-2 aux words:
1279 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1280 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1282 case btEnum
: /* Enumeration. */
1283 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1284 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1285 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1287 indx
++; /* Skip aux words. */
1290 case btTypedef
: /* Defined via a typedef, isymRef points. */
1291 strcpy (p1
, "typedef");
1294 case btRange
: /* Subrange of int. */
1295 strcpy (p1
, "subrange");
1298 case btSet
: /* Pascal sets. */
1302 case btComplex
: /* Fortran complex. */
1303 strcpy (p1
, "complex");
1306 case btDComplex
: /* Fortran double complex. */
1307 strcpy (p1
, "double complex");
1310 case btIndirect
: /* Forward or unnamed typedef. */
1311 strcpy (p1
, "forward/unamed typedef");
1314 case btFixedDec
: /* Fixed Decimal. */
1315 strcpy (p1
, "fixed decimal");
1318 case btFloatDec
: /* Float Decimal. */
1319 strcpy (p1
, "float decimal");
1322 case btString
: /* Varying Length Character String. */
1323 strcpy (p1
, "string");
1326 case btBit
: /* Aligned Bit String. */
1330 case btPicture
: /* Picture. */
1331 strcpy (p1
, "picture");
1334 case btVoid
: /* Void. */
1335 strcpy (p1
, "void");
1339 sprintf (p1
, _("Unknown basic type %d"), (int) basic_type
);
1343 p1
+= strlen (buffer1
);
1345 /* If this is a bitfield, get the bitsize. */
1350 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1351 sprintf (p1
, " : %d", bitsize
);
1352 p1
+= strlen (buffer1
);
1355 /* Deal with any qualifiers. */
1356 if (qualifiers
[0].type
!= tqNil
)
1358 /* Snarf up any array bounds in the correct order. Arrays
1359 store 5 successive words in the aux. table:
1360 word 0 RNDXR to type of the bounds (ie, int)
1361 word 1 Current file descriptor index
1363 word 3 high bound (or -1 if [])
1364 word 4 stride size in bits. */
1365 for (i
= 0; i
< 7; i
++)
1367 if (qualifiers
[i
].type
== tqArray
)
1369 qualifiers
[i
].low_bound
=
1370 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1371 qualifiers
[i
].high_bound
=
1372 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1373 qualifiers
[i
].stride
=
1374 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1379 /* Now print out the qualifiers. */
1380 for (i
= 0; i
< 6; i
++)
1382 switch (qualifiers
[i
].type
)
1389 strcpy (p2
, "ptr to ");
1390 p2
+= sizeof ("ptr to ")-1;
1394 strcpy (p2
, "volatile ");
1395 p2
+= sizeof ("volatile ")-1;
1399 strcpy (p2
, "far ");
1400 p2
+= sizeof ("far ")-1;
1404 strcpy (p2
, "func. ret. ");
1405 p2
+= sizeof ("func. ret. ");
1410 int first_array
= i
;
1413 /* Print array bounds reversed (ie, in the order the C
1414 programmer writes them). C is such a fun language.... */
1415 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1418 for (j
= i
; j
>= first_array
; j
--)
1420 strcpy (p2
, "array [");
1421 p2
+= sizeof ("array [")-1;
1422 if (qualifiers
[j
].low_bound
!= 0)
1424 "%ld:%ld {%ld bits}",
1425 (long) qualifiers
[j
].low_bound
,
1426 (long) qualifiers
[j
].high_bound
,
1427 (long) qualifiers
[j
].stride
);
1429 else if (qualifiers
[j
].high_bound
!= -1)
1432 (long) (qualifiers
[j
].high_bound
+ 1),
1433 (long) (qualifiers
[j
].stride
));
1436 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1439 strcpy (p2
, "] of ");
1440 p2
+= sizeof ("] of ")-1;
1448 strcpy (p2
, buffer1
);
1452 /* Return information about ECOFF symbol SYMBOL in RET. */
1455 _bfd_ecoff_get_symbol_info (abfd
, symbol
, ret
)
1456 bfd
*abfd ATTRIBUTE_UNUSED
;
1460 bfd_symbol_info (symbol
, ret
);
1463 /* Return whether this is a local label. */
1466 _bfd_ecoff_bfd_is_local_label_name (abfd
, name
)
1467 bfd
*abfd ATTRIBUTE_UNUSED
;
1470 return name
[0] == '$';
1473 /* Print information about an ECOFF symbol. */
1476 _bfd_ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1480 bfd_print_symbol_type how
;
1482 const struct ecoff_debug_swap
* const debug_swap
1483 = &ecoff_backend (abfd
)->debug_swap
;
1484 FILE *file
= (FILE *)filep
;
1488 case bfd_print_symbol_name
:
1489 fprintf (file
, "%s", symbol
->name
);
1491 case bfd_print_symbol_more
:
1492 if (ecoffsymbol (symbol
)->local
)
1496 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1498 fprintf (file
, "ecoff local ");
1499 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1500 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1501 (unsigned) ecoff_sym
.sc
);
1507 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1509 fprintf (file
, "ecoff extern ");
1510 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1511 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1512 (unsigned) ecoff_ext
.asym
.sc
);
1515 case bfd_print_symbol_all
:
1516 /* Print out the symbols in a reasonable way. */
1525 if (ecoffsymbol (symbol
)->local
)
1527 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1530 pos
= ((((char *) ecoffsymbol (symbol
)->native
1531 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1532 / debug_swap
->external_sym_size
)
1533 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1540 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1543 pos
= (((char *) ecoffsymbol (symbol
)->native
1544 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1545 / debug_swap
->external_ext_size
);
1546 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1547 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1548 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1551 fprintf (file
, "[%3d] %c ",
1553 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1554 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1555 (unsigned) ecoff_ext
.asym
.st
,
1556 (unsigned) ecoff_ext
.asym
.sc
,
1557 (unsigned) ecoff_ext
.asym
.index
,
1558 jmptbl
, cobol_main
, weakext
,
1561 if (ecoffsymbol (symbol
)->fdr
!= NULL
1562 && ecoff_ext
.asym
.index
!= indexNil
)
1567 bfd_size_type sym_base
;
1568 union aux_ext
*aux_base
;
1570 fdr
= ecoffsymbol (symbol
)->fdr
;
1571 indx
= ecoff_ext
.asym
.index
;
1573 /* sym_base is used to map the fdr relative indices which
1574 appear in the file to the position number which we are
1576 sym_base
= fdr
->isymBase
;
1577 if (ecoffsymbol (symbol
)->local
)
1579 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1581 /* aux_base is the start of the aux entries for this file;
1582 asym.index is an offset from this. */
1583 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1586 /* The aux entries are stored in host byte order; the
1587 order is indicated by a bit in the fdr. */
1588 bigendian
= fdr
->fBigendian
;
1590 /* This switch is basically from gcc/mips-tdump.c. */
1591 switch (ecoff_ext
.asym
.st
)
1599 fprintf (file
, _("\n End+1 symbol: %ld"),
1600 (long) (indx
+ sym_base
));
1604 if (ecoff_ext
.asym
.sc
== scText
1605 || ecoff_ext
.asym
.sc
== scInfo
)
1606 fprintf (file
, _("\n First symbol: %ld"),
1607 (long) (indx
+ sym_base
));
1609 fprintf (file
, _("\n First symbol: %ld"),
1611 (AUX_GET_ISYM (bigendian
,
1612 &aux_base
[ecoff_ext
.asym
.index
])
1618 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1620 else if (ecoffsymbol (symbol
)->local
)
1621 fprintf (file
, _("\n End+1 symbol: %-7ld Type: %s"),
1623 (AUX_GET_ISYM (bigendian
,
1624 &aux_base
[ecoff_ext
.asym
.index
])
1626 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1628 fprintf (file
, _("\n Local symbol: %ld"),
1631 + (ecoff_data (abfd
)
1632 ->debug_info
.symbolic_header
.iextMax
)));
1636 fprintf (file
, _("\n struct; End+1 symbol: %ld"),
1637 (long) (indx
+ sym_base
));
1641 fprintf (file
, _("\n union; End+1 symbol: %ld"),
1642 (long) (indx
+ sym_base
));
1646 fprintf (file
, _("\n enum; End+1 symbol: %ld"),
1647 (long) (indx
+ sym_base
));
1651 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1652 fprintf (file
, _("\n Type: %s"),
1653 ecoff_type_to_string (abfd
, fdr
, indx
));
1662 /* Read in the relocs for a section. */
1665 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1670 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1671 arelent
*internal_relocs
;
1672 bfd_size_type external_reloc_size
;
1674 char *external_relocs
;
1678 if (section
->relocation
!= (arelent
*) NULL
1679 || section
->reloc_count
== 0
1680 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1683 if (! _bfd_ecoff_slurp_symbol_table (abfd
))
1686 amt
= section
->reloc_count
;
1687 amt
*= sizeof (arelent
);
1688 internal_relocs
= (arelent
*) bfd_alloc (abfd
, amt
);
1690 external_reloc_size
= backend
->external_reloc_size
;
1691 amt
= external_reloc_size
* section
->reloc_count
;
1692 external_relocs
= (char *) bfd_alloc (abfd
, amt
);
1693 if (internal_relocs
== (arelent
*) NULL
1694 || external_relocs
== (char *) NULL
)
1696 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1698 if (bfd_bread (external_relocs
, amt
, abfd
) != amt
)
1701 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1703 struct internal_reloc intern
;
1705 (*backend
->swap_reloc_in
) (abfd
,
1706 external_relocs
+ i
* external_reloc_size
,
1709 if (intern
.r_extern
)
1711 /* r_symndx is an index into the external symbols. */
1712 BFD_ASSERT (intern
.r_symndx
>= 0
1714 < (ecoff_data (abfd
)
1715 ->debug_info
.symbolic_header
.iextMax
)));
1716 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1719 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1720 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1722 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
1727 const char *sec_name
;
1730 /* r_symndx is a section key. */
1731 switch (intern
.r_symndx
)
1733 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1734 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1735 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1736 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1737 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1738 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1739 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1740 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1741 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1742 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1743 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1744 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1745 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1746 case RELOC_SECTION_RCONST
: sec_name
= ".rconst"; break;
1750 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1751 if (sec
== (asection
*) NULL
)
1753 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1755 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1758 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1760 /* Let the backend select the howto field and do any other
1761 required processing. */
1762 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1765 bfd_release (abfd
, external_relocs
);
1767 section
->relocation
= internal_relocs
;
1772 /* Get a canonical list of relocs. */
1775 _bfd_ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1783 if (section
->flags
& SEC_CONSTRUCTOR
)
1785 arelent_chain
*chain
;
1787 /* This section has relocs made up by us, not the file, so take
1788 them out of their chain and place them into the data area
1790 for (count
= 0, chain
= section
->constructor_chain
;
1791 count
< section
->reloc_count
;
1792 count
++, chain
= chain
->next
)
1793 *relptr
++ = &chain
->relent
;
1799 if (! ecoff_slurp_reloc_table (abfd
, section
, symbols
))
1802 tblptr
= section
->relocation
;
1804 for (count
= 0; count
< section
->reloc_count
; count
++)
1805 *relptr
++ = tblptr
++;
1808 *relptr
= (arelent
*) NULL
;
1810 return section
->reloc_count
;
1813 /* Provided a BFD, a section and an offset into the section, calculate
1814 and return the name of the source file and the line nearest to the
1818 _bfd_ecoff_find_nearest_line (abfd
, section
, ignore_symbols
, offset
,
1819 filename_ptr
, functionname_ptr
, retline_ptr
)
1822 asymbol
**ignore_symbols ATTRIBUTE_UNUSED
;
1824 const char **filename_ptr
;
1825 const char **functionname_ptr
;
1826 unsigned int *retline_ptr
;
1828 const struct ecoff_debug_swap
* const debug_swap
1829 = &ecoff_backend (abfd
)->debug_swap
;
1830 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1831 struct ecoff_find_line
*line_info
;
1833 /* Make sure we have the FDR's. */
1834 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
, debug_info
)
1835 || bfd_get_symcount (abfd
) == 0)
1838 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1840 bfd_size_type amt
= sizeof (struct ecoff_find_line
);
1841 ecoff_data (abfd
)->find_line_info
1842 = (struct ecoff_find_line
*) bfd_zalloc (abfd
, amt
);
1843 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1846 line_info
= ecoff_data (abfd
)->find_line_info
;
1848 return _bfd_ecoff_locate_line (abfd
, section
, offset
, debug_info
,
1849 debug_swap
, line_info
, filename_ptr
,
1850 functionname_ptr
, retline_ptr
);
1853 /* Copy private BFD data. This is called by objcopy and strip. We
1854 use it to copy the ECOFF debugging information from one BFD to the
1855 other. It would be theoretically possible to represent the ECOFF
1856 debugging information in the symbol table. However, it would be a
1857 lot of work, and there would be little gain (gas, gdb, and ld
1858 already access the ECOFF debugging information via the
1859 ecoff_debug_info structure, and that structure would have to be
1860 retained in order to support ECOFF debugging in MIPS ELF).
1862 The debugging information for the ECOFF external symbols comes from
1863 the symbol table, so this function only handles the other debugging
1867 _bfd_ecoff_bfd_copy_private_bfd_data (ibfd
, obfd
)
1871 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
1872 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
1874 asymbol
**sym_ptr_ptr
;
1878 /* We only want to copy information over if both BFD's use ECOFF
1880 if (bfd_get_flavour (ibfd
) != bfd_target_ecoff_flavour
1881 || bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
1884 /* Copy the GP value and the register masks. */
1885 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
1886 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
1887 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
1888 for (i
= 0; i
< 3; i
++)
1889 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
1891 /* Copy the version stamp. */
1892 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
1894 /* If there are no symbols, don't copy any debugging information. */
1895 c
= bfd_get_symcount (obfd
);
1896 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1897 if (c
== 0 || sym_ptr_ptr
== (asymbol
**) NULL
)
1900 /* See if there are any local symbols. */
1902 for (; c
> 0; c
--, sym_ptr_ptr
++)
1904 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
1913 /* There are some local symbols. We just bring over all the
1914 debugging information. FIXME: This is not quite the right
1915 thing to do. If the user has asked us to discard all
1916 debugging information, then we are probably going to wind up
1917 keeping it because there will probably be some local symbol
1918 which objcopy did not discard. We should actually break
1919 apart the debugging information and only keep that which
1920 applies to the symbols we want to keep. */
1921 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
1922 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
1923 oinfo
->line
= iinfo
->line
;
1925 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
1926 oinfo
->external_dnr
= iinfo
->external_dnr
;
1928 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
1929 oinfo
->external_pdr
= iinfo
->external_pdr
;
1931 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
1932 oinfo
->external_sym
= iinfo
->external_sym
;
1934 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
1935 oinfo
->external_opt
= iinfo
->external_opt
;
1937 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
1938 oinfo
->external_aux
= iinfo
->external_aux
;
1940 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
1941 oinfo
->ss
= iinfo
->ss
;
1943 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
1944 oinfo
->external_fdr
= iinfo
->external_fdr
;
1946 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
1947 oinfo
->external_rfd
= iinfo
->external_rfd
;
1951 /* We are discarding all the local symbol information. Look
1952 through the external symbols and remove all references to FDR
1953 or aux information. */
1954 c
= bfd_get_symcount (obfd
);
1955 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1956 for (; c
> 0; c
--, sym_ptr_ptr
++)
1960 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
1961 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
1963 esym
.asym
.index
= indexNil
;
1964 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
1965 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
1972 /* Set the architecture. The supported architecture is stored in the
1973 backend pointer. We always set the architecture anyhow, since many
1974 callers ignore the return value. */
1977 _bfd_ecoff_set_arch_mach (abfd
, arch
, machine
)
1979 enum bfd_architecture arch
;
1980 unsigned long machine
;
1982 bfd_default_set_arch_mach (abfd
, arch
, machine
);
1983 return arch
== ecoff_backend (abfd
)->arch
;
1986 /* Get the size of the section headers. */
1989 _bfd_ecoff_sizeof_headers (abfd
, reloc
)
1991 bfd_boolean reloc ATTRIBUTE_UNUSED
;
1998 for (current
= abfd
->sections
;
1999 current
!= (asection
*)NULL
;
2000 current
= current
->next
)
2003 ret
= (bfd_coff_filhsz (abfd
)
2004 + bfd_coff_aoutsz (abfd
)
2005 + c
* bfd_coff_scnhsz (abfd
));
2006 return BFD_ALIGN (ret
, 16);
2009 /* Get the contents of a section. */
2012 _bfd_ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2017 bfd_size_type count
;
2019 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2023 /* Sort sections by VMA, but put SEC_ALLOC sections first. This is
2024 called via qsort. */
2027 ecoff_sort_hdrs (arg1
, arg2
)
2031 const asection
*hdr1
= *(const asection
**) arg1
;
2032 const asection
*hdr2
= *(const asection
**) arg2
;
2034 if ((hdr1
->flags
& SEC_ALLOC
) != 0)
2036 if ((hdr2
->flags
& SEC_ALLOC
) == 0)
2041 if ((hdr2
->flags
& SEC_ALLOC
) != 0)
2044 if (hdr1
->vma
< hdr2
->vma
)
2046 else if (hdr1
->vma
> hdr2
->vma
)
2052 /* Calculate the file position for each section, and set
2056 ecoff_compute_section_file_positions (abfd
)
2059 file_ptr sofar
, file_sofar
;
2060 asection
**sorted_hdrs
;
2064 bfd_boolean rdata_in_text
;
2065 bfd_boolean first_data
, first_nonalloc
;
2066 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2069 sofar
= _bfd_ecoff_sizeof_headers (abfd
, FALSE
);
2072 /* Sort the sections by VMA. */
2073 amt
= abfd
->section_count
;
2074 amt
*= sizeof (asection
*);
2075 sorted_hdrs
= (asection
**) bfd_malloc (amt
);
2076 if (sorted_hdrs
== NULL
)
2078 for (current
= abfd
->sections
, i
= 0;
2080 current
= current
->next
, i
++)
2081 sorted_hdrs
[i
] = current
;
2082 BFD_ASSERT (i
== abfd
->section_count
);
2084 qsort (sorted_hdrs
, abfd
->section_count
, sizeof (asection
*),
2087 /* Some versions of the OSF linker put the .rdata section in the
2088 text segment, and some do not. */
2089 rdata_in_text
= ecoff_backend (abfd
)->rdata_in_text
;
2092 for (i
= 0; i
< abfd
->section_count
; i
++)
2094 current
= sorted_hdrs
[i
];
2095 if (strcmp (current
->name
, _RDATA
) == 0)
2097 if ((current
->flags
& SEC_CODE
) == 0
2098 && strcmp (current
->name
, _PDATA
) != 0
2099 && strcmp (current
->name
, _RCONST
) != 0)
2101 rdata_in_text
= FALSE
;
2106 ecoff_data (abfd
)->rdata_in_text
= rdata_in_text
;
2109 first_nonalloc
= TRUE
;
2110 for (i
= 0; i
< abfd
->section_count
; i
++)
2112 unsigned int alignment_power
;
2114 current
= sorted_hdrs
[i
];
2116 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2117 supposed to indicate the number of .pdata entries that are
2118 really in the section. Each entry is 8 bytes. We store this
2119 away in line_filepos before increasing the section size. */
2120 if (strcmp (current
->name
, _PDATA
) == 0)
2121 current
->line_filepos
= current
->_raw_size
/ 8;
2123 alignment_power
= current
->alignment_power
;
2125 /* On Ultrix, the data sections in an executable file must be
2126 aligned to a page boundary within the file. This does not
2127 affect the section size, though. FIXME: Does this work for
2128 other platforms? It requires some modification for the
2129 Alpha, because .rdata on the Alpha goes with the text, not
2131 if ((abfd
->flags
& EXEC_P
) != 0
2132 && (abfd
->flags
& D_PAGED
) != 0
2134 && (current
->flags
& SEC_CODE
) == 0
2136 || strcmp (current
->name
, _RDATA
) != 0)
2137 && strcmp (current
->name
, _PDATA
) != 0
2138 && strcmp (current
->name
, _RCONST
) != 0)
2140 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2141 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2144 else if (strcmp (current
->name
, _LIB
) == 0)
2146 /* On Irix 4, the location of contents of the .lib section
2147 from a shared library section is also rounded up to a
2150 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2151 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2153 else if (first_nonalloc
2154 && (current
->flags
& SEC_ALLOC
) == 0
2155 && (abfd
->flags
& D_PAGED
) != 0)
2157 /* Skip up to the next page for an unallocated section, such
2158 as the .comment section on the Alpha. This leaves room
2159 for the .bss section. */
2160 first_nonalloc
= FALSE
;
2161 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2162 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2165 /* Align the sections in the file to the same boundary on
2166 which they are aligned in virtual memory. */
2167 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2168 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2169 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2171 if ((abfd
->flags
& D_PAGED
) != 0
2172 && (current
->flags
& SEC_ALLOC
) != 0)
2174 sofar
+= (current
->vma
- sofar
) % round
;
2175 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2176 file_sofar
+= (current
->vma
- file_sofar
) % round
;
2179 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) != 0)
2180 current
->filepos
= file_sofar
;
2182 sofar
+= current
->_raw_size
;
2183 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2184 file_sofar
+= current
->_raw_size
;
2186 /* Make sure that this section is of the right size too. */
2188 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2189 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2190 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2191 current
->_raw_size
+= sofar
- old_sofar
;
2197 ecoff_data (abfd
)->reloc_filepos
= file_sofar
;
2202 /* Determine the location of the relocs for all the sections in the
2203 output file, as well as the location of the symbolic debugging
2206 static bfd_size_type
2207 ecoff_compute_reloc_file_positions (abfd
)
2210 const bfd_size_type external_reloc_size
=
2211 ecoff_backend (abfd
)->external_reloc_size
;
2212 file_ptr reloc_base
;
2213 bfd_size_type reloc_size
;
2217 if (! abfd
->output_has_begun
)
2219 if (! ecoff_compute_section_file_positions (abfd
))
2221 abfd
->output_has_begun
= TRUE
;
2224 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2227 for (current
= abfd
->sections
;
2228 current
!= (asection
*)NULL
;
2229 current
= current
->next
)
2231 if (current
->reloc_count
== 0)
2232 current
->rel_filepos
= 0;
2235 bfd_size_type relsize
;
2237 current
->rel_filepos
= reloc_base
;
2238 relsize
= current
->reloc_count
* external_reloc_size
;
2239 reloc_size
+= relsize
;
2240 reloc_base
+= relsize
;
2244 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2246 /* At least on Ultrix, the symbol table of an executable file must
2247 be aligned to a page boundary. FIXME: Is this true on other
2249 if ((abfd
->flags
& EXEC_P
) != 0
2250 && (abfd
->flags
& D_PAGED
) != 0)
2251 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2252 &~ (ecoff_backend (abfd
)->round
- 1));
2254 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2259 /* Set the contents of a section. */
2262 _bfd_ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2267 bfd_size_type count
;
2271 /* This must be done first, because bfd_set_section_contents is
2272 going to set output_has_begun to TRUE. */
2273 if (! abfd
->output_has_begun
)
2275 if (! ecoff_compute_section_file_positions (abfd
))
2279 /* Handle the .lib section specially so that Irix 4 shared libraries
2280 work out. See coff_set_section_contents in coffcode.h. */
2281 if (strcmp (section
->name
, _LIB
) == 0)
2283 bfd_byte
*rec
, *recend
;
2285 rec
= (bfd_byte
*) location
;
2286 recend
= rec
+ count
;
2287 while (rec
< recend
)
2290 rec
+= bfd_get_32 (abfd
, rec
) * 4;
2293 BFD_ASSERT (rec
== recend
);
2299 pos
= section
->filepos
+ offset
;
2300 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
2301 || bfd_bwrite (location
, count
, abfd
) != count
)
2307 /* Get the GP value for an ECOFF file. This is a hook used by
2311 bfd_ecoff_get_gp_value (abfd
)
2314 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2315 || bfd_get_format (abfd
) != bfd_object
)
2317 bfd_set_error (bfd_error_invalid_operation
);
2321 return ecoff_data (abfd
)->gp
;
2324 /* Set the GP value for an ECOFF file. This is a hook used by the
2328 bfd_ecoff_set_gp_value (abfd
, gp_value
)
2332 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2333 || bfd_get_format (abfd
) != bfd_object
)
2335 bfd_set_error (bfd_error_invalid_operation
);
2339 ecoff_data (abfd
)->gp
= gp_value
;
2344 /* Set the register masks for an ECOFF file. This is a hook used by
2348 bfd_ecoff_set_regmasks (abfd
, gprmask
, fprmask
, cprmask
)
2350 unsigned long gprmask
;
2351 unsigned long fprmask
;
2352 unsigned long *cprmask
;
2354 ecoff_data_type
*tdata
;
2356 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2357 || bfd_get_format (abfd
) != bfd_object
)
2359 bfd_set_error (bfd_error_invalid_operation
);
2363 tdata
= ecoff_data (abfd
);
2364 tdata
->gprmask
= gprmask
;
2365 tdata
->fprmask
= fprmask
;
2366 if (cprmask
!= (unsigned long *) NULL
)
2370 for (i
= 0; i
< 3; i
++)
2371 tdata
->cprmask
[i
] = cprmask
[i
];
2377 /* Get ECOFF EXTR information for an external symbol. This function
2378 is passed to bfd_ecoff_debug_externals. */
2381 ecoff_get_extr (sym
, esym
)
2385 ecoff_symbol_type
*ecoff_sym_ptr
;
2388 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2389 || ecoffsymbol (sym
)->native
== NULL
)
2391 /* Don't include debugging, local, or section symbols. */
2392 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2393 || (sym
->flags
& BSF_LOCAL
) != 0
2394 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2398 esym
->cobol_main
= 0;
2399 esym
->weakext
= (sym
->flags
& BSF_WEAK
) != 0;
2402 /* FIXME: we can do better than this for st and sc. */
2403 esym
->asym
.st
= stGlobal
;
2404 esym
->asym
.sc
= scAbs
;
2405 esym
->asym
.reserved
= 0;
2406 esym
->asym
.index
= indexNil
;
2410 ecoff_sym_ptr
= ecoffsymbol (sym
);
2412 if (ecoff_sym_ptr
->local
)
2415 input_bfd
= bfd_asymbol_bfd (sym
);
2416 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2417 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2419 /* If the symbol was defined by the linker, then esym will be
2420 undefined but sym will not be. Get a better class for such a
2422 if ((esym
->asym
.sc
== scUndefined
2423 || esym
->asym
.sc
== scSUndefined
)
2424 && ! bfd_is_und_section (bfd_get_section (sym
)))
2425 esym
->asym
.sc
= scAbs
;
2427 /* Adjust the FDR index for the symbol by that used for the input
2429 if (esym
->ifd
!= -1)
2431 struct ecoff_debug_info
*input_debug
;
2433 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2434 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2435 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2436 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2442 /* Set the external symbol index. This routine is passed to
2443 bfd_ecoff_debug_externals. */
2446 ecoff_set_index (sym
, indx
)
2450 ecoff_set_sym_index (sym
, indx
);
2453 /* Write out an ECOFF file. */
2456 _bfd_ecoff_write_object_contents (abfd
)
2459 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2460 const bfd_vma round
= backend
->round
;
2461 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2462 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2463 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2464 const bfd_size_type external_hdr_size
2465 = backend
->debug_swap
.external_hdr_size
;
2466 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2467 void (* const adjust_reloc_out
)
2468 PARAMS ((bfd
*, const arelent
*, struct internal_reloc
*))
2469 = backend
->adjust_reloc_out
;
2470 void (* const swap_reloc_out
)
2471 PARAMS ((bfd
*, const struct internal_reloc
*, PTR
))
2472 = backend
->swap_reloc_out
;
2473 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2474 HDRR
* const symhdr
= &debug
->symbolic_header
;
2477 bfd_size_type reloc_size
;
2478 bfd_size_type text_size
;
2480 bfd_boolean set_text_start
;
2481 bfd_size_type data_size
;
2483 bfd_boolean set_data_start
;
2484 bfd_size_type bss_size
;
2486 PTR reloc_buff
= NULL
;
2487 struct internal_filehdr internal_f
;
2488 struct internal_aouthdr internal_a
;
2491 /* Determine where the sections and relocs will go in the output
2493 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2496 for (current
= abfd
->sections
;
2497 current
!= (asection
*)NULL
;
2498 current
= current
->next
)
2500 current
->target_index
= count
;
2504 if ((abfd
->flags
& D_PAGED
) != 0)
2505 text_size
= _bfd_ecoff_sizeof_headers (abfd
, FALSE
);
2509 set_text_start
= FALSE
;
2512 set_data_start
= FALSE
;
2515 /* Write section headers to the file. */
2517 /* Allocate buff big enough to hold a section header,
2518 file header, or a.out header. */
2526 buff
= (PTR
) bfd_malloc (siz
);
2531 internal_f
.f_nscns
= 0;
2532 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2534 for (current
= abfd
->sections
;
2535 current
!= (asection
*) NULL
;
2536 current
= current
->next
)
2538 struct internal_scnhdr section
;
2541 ++internal_f
.f_nscns
;
2543 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2545 /* This seems to be correct for Irix 4 shared libraries. */
2546 vma
= bfd_get_section_vma (abfd
, current
);
2547 if (strcmp (current
->name
, _LIB
) == 0)
2548 section
.s_vaddr
= 0;
2550 section
.s_vaddr
= vma
;
2552 section
.s_paddr
= current
->lma
;
2553 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2555 /* If this section is unloadable then the scnptr will be 0. */
2556 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2557 section
.s_scnptr
= 0;
2559 section
.s_scnptr
= current
->filepos
;
2560 section
.s_relptr
= current
->rel_filepos
;
2562 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2563 object file produced by the assembler is supposed to point to
2564 information about how much room is required by objects of
2565 various different sizes. I think this only matters if we
2566 want the linker to compute the best size to use, or
2567 something. I don't know what happens if the information is
2569 if (strcmp (current
->name
, _PDATA
) != 0)
2570 section
.s_lnnoptr
= 0;
2573 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2574 hold the number of entries in the section (each entry is
2575 8 bytes). We stored this in the line_filepos field in
2576 ecoff_compute_section_file_positions. */
2577 section
.s_lnnoptr
= current
->line_filepos
;
2580 section
.s_nreloc
= current
->reloc_count
;
2581 section
.s_nlnno
= 0;
2582 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2585 if (bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
) == 0
2586 || bfd_bwrite (buff
, scnhsz
, abfd
) != scnhsz
)
2589 if ((section
.s_flags
& STYP_TEXT
) != 0
2590 || ((section
.s_flags
& STYP_RDATA
) != 0
2591 && ecoff_data (abfd
)->rdata_in_text
)
2592 || section
.s_flags
== STYP_PDATA
2593 || (section
.s_flags
& STYP_DYNAMIC
) != 0
2594 || (section
.s_flags
& STYP_LIBLIST
) != 0
2595 || (section
.s_flags
& STYP_RELDYN
) != 0
2596 || section
.s_flags
== STYP_CONFLIC
2597 || (section
.s_flags
& STYP_DYNSTR
) != 0
2598 || (section
.s_flags
& STYP_DYNSYM
) != 0
2599 || (section
.s_flags
& STYP_HASH
) != 0
2600 || (section
.s_flags
& STYP_ECOFF_INIT
) != 0
2601 || (section
.s_flags
& STYP_ECOFF_FINI
) != 0
2602 || section
.s_flags
== STYP_RCONST
)
2604 text_size
+= bfd_get_section_size_before_reloc (current
);
2605 if (! set_text_start
|| text_start
> vma
)
2608 set_text_start
= TRUE
;
2611 else if ((section
.s_flags
& STYP_RDATA
) != 0
2612 || (section
.s_flags
& STYP_DATA
) != 0
2613 || (section
.s_flags
& STYP_LITA
) != 0
2614 || (section
.s_flags
& STYP_LIT8
) != 0
2615 || (section
.s_flags
& STYP_LIT4
) != 0
2616 || (section
.s_flags
& STYP_SDATA
) != 0
2617 || section
.s_flags
== STYP_XDATA
2618 || (section
.s_flags
& STYP_GOT
) != 0)
2620 data_size
+= bfd_get_section_size_before_reloc (current
);
2621 if (! set_data_start
|| data_start
> vma
)
2624 set_data_start
= TRUE
;
2627 else if ((section
.s_flags
& STYP_BSS
) != 0
2628 || (section
.s_flags
& STYP_SBSS
) != 0)
2629 bss_size
+= bfd_get_section_size_before_reloc (current
);
2630 else if (section
.s_flags
== 0
2631 || (section
.s_flags
& STYP_ECOFF_LIB
) != 0
2632 || section
.s_flags
== STYP_COMMENT
)
2638 /* Set up the file header. */
2639 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2641 /* We will NOT put a fucking timestamp in the header here. Every
2642 time you put it back, I will come in and take it out again. I'm
2643 sorry. This field does not belong here. We fill it with a 0 so
2644 it compares the same but is not a reasonable time. --
2646 internal_f
.f_timdat
= 0;
2648 if (bfd_get_symcount (abfd
) != 0)
2650 /* The ECOFF f_nsyms field is not actually the number of
2651 symbols, it's the size of symbolic information header. */
2652 internal_f
.f_nsyms
= external_hdr_size
;
2653 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2657 internal_f
.f_nsyms
= 0;
2658 internal_f
.f_symptr
= 0;
2661 internal_f
.f_opthdr
= aoutsz
;
2663 internal_f
.f_flags
= F_LNNO
;
2664 if (reloc_size
== 0)
2665 internal_f
.f_flags
|= F_RELFLG
;
2666 if (bfd_get_symcount (abfd
) == 0)
2667 internal_f
.f_flags
|= F_LSYMS
;
2668 if (abfd
->flags
& EXEC_P
)
2669 internal_f
.f_flags
|= F_EXEC
;
2671 if (bfd_little_endian (abfd
))
2672 internal_f
.f_flags
|= F_AR32WR
;
2674 internal_f
.f_flags
|= F_AR32W
;
2676 /* Set up the ``optional'' header. */
2677 if ((abfd
->flags
& D_PAGED
) != 0)
2678 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2680 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2682 /* FIXME: Is this really correct? */
2683 internal_a
.vstamp
= symhdr
->vstamp
;
2685 /* At least on Ultrix, these have to be rounded to page boundaries.
2686 FIXME: Is this true on other platforms? */
2687 if ((abfd
->flags
& D_PAGED
) != 0)
2689 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2690 internal_a
.text_start
= text_start
&~ (round
- 1);
2691 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2692 internal_a
.data_start
= data_start
&~ (round
- 1);
2696 internal_a
.tsize
= text_size
;
2697 internal_a
.text_start
= text_start
;
2698 internal_a
.dsize
= data_size
;
2699 internal_a
.data_start
= data_start
;
2702 /* On Ultrix, the initial portions of the .sbss and .bss segments
2703 are at the end of the data section. The bsize field in the
2704 optional header records how many bss bytes are required beyond
2705 those in the data section. The value is not rounded to a page
2707 if (bss_size
< internal_a
.dsize
- data_size
)
2710 bss_size
-= internal_a
.dsize
- data_size
;
2711 internal_a
.bsize
= bss_size
;
2712 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2714 internal_a
.entry
= bfd_get_start_address (abfd
);
2716 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2718 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2719 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2720 for (i
= 0; i
< 4; i
++)
2721 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2723 /* Let the backend adjust the headers if necessary. */
2724 if (backend
->adjust_headers
)
2726 if (! (*backend
->adjust_headers
) (abfd
, &internal_f
, &internal_a
))
2730 /* Write out the file header and the optional header. */
2731 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2734 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2735 if (bfd_bwrite (buff
, filhsz
, abfd
) != filhsz
)
2738 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2739 if (bfd_bwrite (buff
, aoutsz
, abfd
) != aoutsz
)
2742 /* Build the external symbol information. This must be done before
2743 writing out the relocs so that we know the symbol indices. We
2744 don't do this if this BFD was created by the backend linker,
2745 since it will have already handled the symbols and relocs. */
2746 if (! ecoff_data (abfd
)->linker
)
2748 symhdr
->iextMax
= 0;
2749 symhdr
->issExtMax
= 0;
2750 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2751 debug
->ssext
= debug
->ssext_end
= NULL
;
2752 if (! bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2753 (abfd
->flags
& EXEC_P
) == 0,
2754 ecoff_get_extr
, ecoff_set_index
))
2757 /* Write out the relocs. */
2758 for (current
= abfd
->sections
;
2759 current
!= (asection
*) NULL
;
2760 current
= current
->next
)
2762 arelent
**reloc_ptr_ptr
;
2763 arelent
**reloc_end
;
2767 if (current
->reloc_count
== 0)
2770 amt
= current
->reloc_count
* external_reloc_size
;
2771 reloc_buff
= bfd_alloc (abfd
, amt
);
2772 if (reloc_buff
== NULL
)
2775 reloc_ptr_ptr
= current
->orelocation
;
2776 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2777 out_ptr
= (char *) reloc_buff
;
2779 reloc_ptr_ptr
< reloc_end
;
2780 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2784 struct internal_reloc in
;
2786 memset ((PTR
) &in
, 0, sizeof in
);
2788 reloc
= *reloc_ptr_ptr
;
2789 sym
= *reloc
->sym_ptr_ptr
;
2791 in
.r_vaddr
= (reloc
->address
2792 + bfd_get_section_vma (abfd
, current
));
2793 in
.r_type
= reloc
->howto
->type
;
2795 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2797 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2804 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2805 if (strcmp (name
, ".text") == 0)
2806 in
.r_symndx
= RELOC_SECTION_TEXT
;
2807 else if (strcmp (name
, ".rdata") == 0)
2808 in
.r_symndx
= RELOC_SECTION_RDATA
;
2809 else if (strcmp (name
, ".data") == 0)
2810 in
.r_symndx
= RELOC_SECTION_DATA
;
2811 else if (strcmp (name
, ".sdata") == 0)
2812 in
.r_symndx
= RELOC_SECTION_SDATA
;
2813 else if (strcmp (name
, ".sbss") == 0)
2814 in
.r_symndx
= RELOC_SECTION_SBSS
;
2815 else if (strcmp (name
, ".bss") == 0)
2816 in
.r_symndx
= RELOC_SECTION_BSS
;
2817 else if (strcmp (name
, ".init") == 0)
2818 in
.r_symndx
= RELOC_SECTION_INIT
;
2819 else if (strcmp (name
, ".lit8") == 0)
2820 in
.r_symndx
= RELOC_SECTION_LIT8
;
2821 else if (strcmp (name
, ".lit4") == 0)
2822 in
.r_symndx
= RELOC_SECTION_LIT4
;
2823 else if (strcmp (name
, ".xdata") == 0)
2824 in
.r_symndx
= RELOC_SECTION_XDATA
;
2825 else if (strcmp (name
, ".pdata") == 0)
2826 in
.r_symndx
= RELOC_SECTION_PDATA
;
2827 else if (strcmp (name
, ".fini") == 0)
2828 in
.r_symndx
= RELOC_SECTION_FINI
;
2829 else if (strcmp (name
, ".lita") == 0)
2830 in
.r_symndx
= RELOC_SECTION_LITA
;
2831 else if (strcmp (name
, "*ABS*") == 0)
2832 in
.r_symndx
= RELOC_SECTION_ABS
;
2833 else if (strcmp (name
, ".rconst") == 0)
2834 in
.r_symndx
= RELOC_SECTION_RCONST
;
2840 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2842 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2845 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2847 amt
= current
->reloc_count
* external_reloc_size
;
2848 if (bfd_bwrite (reloc_buff
, amt
, abfd
) != amt
)
2850 bfd_release (abfd
, reloc_buff
);
2854 /* Write out the symbolic debugging information. */
2855 if (bfd_get_symcount (abfd
) > 0)
2857 /* Write out the debugging information. */
2858 if (! bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2859 ecoff_data (abfd
)->sym_filepos
))
2864 /* The .bss section of a demand paged executable must receive an
2865 entire page. If there are symbols, the symbols will start on the
2866 next page. If there are no symbols, we must fill out the page by
2868 if (bfd_get_symcount (abfd
) == 0
2869 && (abfd
->flags
& EXEC_P
) != 0
2870 && (abfd
->flags
& D_PAGED
) != 0)
2874 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2877 if (bfd_bread (&c
, (bfd_size_type
) 1, abfd
) == 0)
2879 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2882 if (bfd_bwrite (&c
, (bfd_size_type
) 1, abfd
) != 1)
2886 if (reloc_buff
!= NULL
)
2887 bfd_release (abfd
, reloc_buff
);
2892 if (reloc_buff
!= NULL
)
2893 bfd_release (abfd
, reloc_buff
);
2899 /* Archive handling. ECOFF uses what appears to be a unique type of
2900 archive header (armap). The byte ordering of the armap and the
2901 contents are encoded in the name of the armap itself. At least for
2902 now, we only support archives with the same byte ordering in the
2903 armap and the contents.
2905 The first four bytes in the armap are the number of symbol
2906 definitions. This is always a power of two.
2908 This is followed by the symbol definitions. Each symbol definition
2909 occupies 8 bytes. The first four bytes are the offset from the
2910 start of the armap strings to the null-terminated string naming
2911 this symbol. The second four bytes are the file offset to the
2912 archive member which defines this symbol. If the second four bytes
2913 are 0, then this is not actually a symbol definition, and it should
2916 The symbols are hashed into the armap with a closed hashing scheme.
2917 See the functions below for the details of the algorithm.
2919 After the symbol definitions comes four bytes holding the size of
2920 the string table, followed by the string table itself. */
2922 /* The name of an archive headers looks like this:
2923 __________E[BL]E[BL]_ (with a trailing space).
2924 The trailing space is changed to an X if the archive is changed to
2925 indicate that the armap is out of date.
2927 The Alpha seems to use ________64E[BL]E[BL]_. */
2929 #define ARMAP_BIG_ENDIAN 'B'
2930 #define ARMAP_LITTLE_ENDIAN 'L'
2931 #define ARMAP_MARKER 'E'
2932 #define ARMAP_START_LENGTH 10
2933 #define ARMAP_HEADER_MARKER_INDEX 10
2934 #define ARMAP_HEADER_ENDIAN_INDEX 11
2935 #define ARMAP_OBJECT_MARKER_INDEX 12
2936 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2937 #define ARMAP_END_INDEX 14
2938 #define ARMAP_END "_ "
2940 /* This is a magic number used in the hashing algorithm. */
2941 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2943 /* This returns the hash value to use for a string. It also sets
2944 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2945 is the number of entries in the hash table, and HLOG is the log
2949 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2951 unsigned int *rehash
;
2961 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2962 hash
*= ARMAP_HASH_MAGIC
;
2963 *rehash
= (hash
& (size
- 1)) | 1;
2964 return hash
>> (32 - hlog
);
2967 /* Read in the armap. */
2970 _bfd_ecoff_slurp_armap (abfd
)
2975 struct areltdata
*mapdata
;
2976 bfd_size_type parsed_size
;
2978 struct artdata
*ardata
;
2981 struct symdef
*symdef_ptr
;
2985 /* Get the name of the first element. */
2986 i
= bfd_bread ((PTR
) nextname
, (bfd_size_type
) 16, abfd
);
2992 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
2995 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2996 standard COFF armap. We could move the ECOFF armap stuff into
2997 bfd_slurp_armap, but that seems inappropriate since no other
2998 target uses this format. Instead, we check directly for a COFF
3000 if (strncmp (nextname
, "/ ", 16) == 0)
3001 return bfd_slurp_armap (abfd
);
3003 /* See if the first element is an armap. */
3004 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3005 ARMAP_START_LENGTH
) != 0
3006 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3007 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3008 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3009 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3010 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3011 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3012 || strncmp (nextname
+ ARMAP_END_INDEX
,
3013 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3015 bfd_has_map (abfd
) = FALSE
;
3019 /* Make sure we have the right byte ordering. */
3020 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3021 ^ (bfd_header_big_endian (abfd
)))
3022 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3023 ^ (bfd_big_endian (abfd
))))
3025 bfd_set_error (bfd_error_wrong_format
);
3029 /* Read in the armap. */
3030 ardata
= bfd_ardata (abfd
);
3031 mapdata
= (struct areltdata
*) _bfd_read_ar_hdr (abfd
);
3032 if (mapdata
== (struct areltdata
*) NULL
)
3034 parsed_size
= mapdata
->parsed_size
;
3035 bfd_release (abfd
, (PTR
) mapdata
);
3037 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3038 if (raw_armap
== (char *) NULL
)
3041 if (bfd_bread ((PTR
) raw_armap
, parsed_size
, abfd
) != parsed_size
)
3043 if (bfd_get_error () != bfd_error_system_call
)
3044 bfd_set_error (bfd_error_malformed_archive
);
3045 bfd_release (abfd
, (PTR
) raw_armap
);
3049 ardata
->tdata
= (PTR
) raw_armap
;
3051 count
= H_GET_32 (abfd
, raw_armap
);
3053 ardata
->symdef_count
= 0;
3054 ardata
->cache
= (struct ar_cache
*) NULL
;
3056 /* This code used to overlay the symdefs over the raw archive data,
3057 but that doesn't work on a 64 bit host. */
3058 stringbase
= raw_armap
+ count
* 8 + 8;
3060 #ifdef CHECK_ARMAP_HASH
3064 /* Double check that I have the hashing algorithm right by making
3065 sure that every symbol can be looked up successfully. */
3067 for (i
= 1; i
< count
; i
<<= 1)
3069 BFD_ASSERT (i
== count
);
3071 raw_ptr
= raw_armap
+ 4;
3072 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3074 unsigned int name_offset
, file_offset
;
3075 unsigned int hash
, rehash
, srch
;
3077 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3078 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3079 if (file_offset
== 0)
3081 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3086 /* See if we can rehash to this location. */
3087 for (srch
= (hash
+ rehash
) & (count
- 1);
3088 srch
!= hash
&& srch
!= i
;
3089 srch
= (srch
+ rehash
) & (count
- 1))
3090 BFD_ASSERT (H_GET_32 (abfd
, (raw_armap
+ 8 + srch
* 8)) != 0);
3091 BFD_ASSERT (srch
== i
);
3095 #endif /* CHECK_ARMAP_HASH */
3097 raw_ptr
= raw_armap
+ 4;
3098 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3099 if (H_GET_32 (abfd
, (raw_ptr
+ 4)) != 0)
3100 ++ardata
->symdef_count
;
3102 amt
= ardata
->symdef_count
;
3103 amt
*= sizeof (struct symdef
);
3104 symdef_ptr
= (struct symdef
*) bfd_alloc (abfd
, amt
);
3108 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3110 raw_ptr
= raw_armap
+ 4;
3111 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3113 unsigned int name_offset
, file_offset
;
3115 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3116 if (file_offset
== 0)
3118 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3119 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3120 symdef_ptr
->file_offset
= file_offset
;
3124 ardata
->first_file_filepos
= bfd_tell (abfd
);
3125 /* Pad to an even boundary. */
3126 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3128 bfd_has_map (abfd
) = TRUE
;
3133 /* Write out an armap. */
3136 _bfd_ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3138 unsigned int elength
;
3140 unsigned int orl_count
;
3143 unsigned int hashsize
, hashlog
;
3144 bfd_size_type symdefsize
;
3146 unsigned int stringsize
;
3147 unsigned int mapsize
;
3150 struct stat statbuf
;
3153 bfd_byte
*hashtable
;
3157 /* Ultrix appears to use as a hash table size the least power of two
3158 greater than twice the number of entries. */
3159 for (hashlog
= 0; ((unsigned int) 1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3161 hashsize
= 1 << hashlog
;
3163 symdefsize
= hashsize
* 8;
3165 stringsize
= stridx
+ padit
;
3167 /* Include 8 bytes to store symdefsize and stringsize in output. */
3168 mapsize
= symdefsize
+ stringsize
+ 8;
3170 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3172 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3174 /* Work out the ECOFF armap name. */
3175 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3176 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3177 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3178 (bfd_header_big_endian (abfd
)
3180 : ARMAP_LITTLE_ENDIAN
);
3181 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3182 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3183 bfd_big_endian (abfd
) ? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3184 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3186 /* Write the timestamp of the archive header to be just a little bit
3187 later than the timestamp of the file, otherwise the linker will
3188 complain that the index is out of date. Actually, the Ultrix
3189 linker just checks the archive name; the GNU linker may check the
3191 stat (abfd
->filename
, &statbuf
);
3192 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3194 /* The DECstation uses zeroes for the uid, gid and mode of the
3196 hdr
.ar_uid
[0] = '0';
3197 hdr
.ar_gid
[0] = '0';
3199 hdr
.ar_mode
[0] = '0';
3201 /* Building gcc ends up extracting the armap as a file - twice. */
3202 hdr
.ar_mode
[0] = '6';
3203 hdr
.ar_mode
[1] = '4';
3204 hdr
.ar_mode
[2] = '4';
3207 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3209 hdr
.ar_fmag
[0] = '`';
3210 hdr
.ar_fmag
[1] = '\012';
3212 /* Turn all null bytes in the header into spaces. */
3213 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3214 if (((char *) (&hdr
))[i
] == '\0')
3215 (((char *) (&hdr
))[i
]) = ' ';
3217 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) sizeof (struct ar_hdr
), abfd
)
3218 != sizeof (struct ar_hdr
))
3221 H_PUT_32 (abfd
, hashsize
, temp
);
3222 if (bfd_bwrite ((PTR
) temp
, (bfd_size_type
) 4, abfd
) != 4)
3225 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3229 current
= abfd
->archive_head
;
3231 for (i
= 0; i
< orl_count
; i
++)
3233 unsigned int hash
, rehash
;
3235 /* Advance firstreal to the file position of this archive
3237 if (map
[i
].u
.abfd
!= last_elt
)
3241 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3242 firstreal
+= firstreal
% 2;
3243 current
= current
->next
;
3245 while (current
!= map
[i
].u
.abfd
);
3250 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3251 if (H_GET_32 (abfd
, (hashtable
+ (hash
* 8) + 4)) != 0)
3255 /* The desired slot is already taken. */
3256 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3258 srch
= (srch
+ rehash
) & (hashsize
- 1))
3259 if (H_GET_32 (abfd
, (hashtable
+ (srch
* 8) + 4)) == 0)
3262 BFD_ASSERT (srch
!= hash
);
3267 H_PUT_32 (abfd
, map
[i
].namidx
, (hashtable
+ hash
* 8));
3268 H_PUT_32 (abfd
, firstreal
, (hashtable
+ hash
* 8 + 4));
3271 if (bfd_bwrite ((PTR
) hashtable
, symdefsize
, abfd
) != symdefsize
)
3274 bfd_release (abfd
, hashtable
);
3276 /* Now write the strings. */
3277 H_PUT_32 (abfd
, stringsize
, temp
);
3278 if (bfd_bwrite ((PTR
) temp
, (bfd_size_type
) 4, abfd
) != 4)
3280 for (i
= 0; i
< orl_count
; i
++)
3284 len
= strlen (*map
[i
].name
) + 1;
3285 if (bfd_bwrite ((PTR
) (*map
[i
].name
), len
, abfd
) != len
)
3289 /* The spec sez this should be a newline. But in order to be
3290 bug-compatible for DECstation ar we use a null. */
3293 if (bfd_bwrite ("", (bfd_size_type
) 1, abfd
) != 1)
3300 /* See whether this BFD is an archive. If it is, read in the armap
3301 and the extended name table. */
3304 _bfd_ecoff_archive_p (abfd
)
3307 struct artdata
*tdata_hold
;
3308 char armag
[SARMAG
+ 1];
3311 if (bfd_bread ((PTR
) armag
, (bfd_size_type
) SARMAG
, abfd
) != SARMAG
)
3313 if (bfd_get_error () != bfd_error_system_call
)
3314 bfd_set_error (bfd_error_wrong_format
);
3315 return (const bfd_target
*) NULL
;
3318 if (strncmp (armag
, ARMAG
, SARMAG
) != 0)
3320 bfd_set_error (bfd_error_wrong_format
);
3324 tdata_hold
= bfd_ardata (abfd
);
3326 amt
= sizeof (struct artdata
);
3327 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
3328 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3330 bfd_ardata (abfd
) = tdata_hold
;
3331 return (const bfd_target
*) NULL
;
3334 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3335 bfd_ardata (abfd
)->cache
= NULL
;
3336 bfd_ardata (abfd
)->archive_head
= NULL
;
3337 bfd_ardata (abfd
)->symdefs
= NULL
;
3338 bfd_ardata (abfd
)->extended_names
= NULL
;
3339 bfd_ardata (abfd
)->tdata
= NULL
;
3341 if (! _bfd_ecoff_slurp_armap (abfd
)
3342 || ! _bfd_ecoff_slurp_extended_name_table (abfd
))
3344 bfd_release (abfd
, bfd_ardata (abfd
));
3345 bfd_ardata (abfd
) = tdata_hold
;
3346 return (const bfd_target
*) NULL
;
3349 if (bfd_has_map (abfd
))
3353 /* This archive has a map, so we may presume that the contents
3354 are object files. Make sure that if the first file in the
3355 archive can be recognized as an object file, it is for this
3356 target. If not, assume that this is the wrong format. If
3357 the first file is not an object file, somebody is doing
3358 something weird, and we permit it so that ar -t will work. */
3360 first
= bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
);
3363 first
->target_defaulted
= FALSE
;
3364 if (bfd_check_format (first
, bfd_object
)
3365 && first
->xvec
!= abfd
->xvec
)
3368 /* We ought to close `first' here, but we can't, because
3369 we have no way to remove it from the archive cache.
3370 It's close to impossible to figure out when we can
3371 release bfd_ardata. FIXME. */
3372 (void) bfd_close (first
);
3373 bfd_release (abfd
, bfd_ardata (abfd
));
3375 bfd_set_error (bfd_error_wrong_object_format
);
3376 bfd_ardata (abfd
) = tdata_hold
;
3379 /* And we ought to close `first' here too. */
3386 /* ECOFF linker code. */
3388 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3389 PARAMS ((struct bfd_hash_entry
*entry
,
3390 struct bfd_hash_table
*table
,
3391 const char *string
));
3392 static bfd_boolean ecoff_link_add_archive_symbols
3393 PARAMS ((bfd
*, struct bfd_link_info
*));
3394 static bfd_boolean ecoff_link_check_archive_element
3395 PARAMS ((bfd
*, struct bfd_link_info
*, bfd_boolean
*pneeded
));
3396 static bfd_boolean ecoff_link_add_object_symbols
3397 PARAMS ((bfd
*, struct bfd_link_info
*));
3398 static bfd_boolean ecoff_link_add_externals
3399 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3401 /* Routine to create an entry in an ECOFF link hash table. */
3403 static struct bfd_hash_entry
*
3404 ecoff_link_hash_newfunc (entry
, table
, string
)
3405 struct bfd_hash_entry
*entry
;
3406 struct bfd_hash_table
*table
;
3409 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3411 /* Allocate the structure if it has not already been allocated by a
3413 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3414 ret
= ((struct ecoff_link_hash_entry
*)
3415 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3416 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3419 /* Call the allocation method of the superclass. */
3420 ret
= ((struct ecoff_link_hash_entry
*)
3421 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3426 /* Set local fields. */
3432 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3434 return (struct bfd_hash_entry
*) ret
;
3437 /* Create an ECOFF link hash table. */
3439 struct bfd_link_hash_table
*
3440 _bfd_ecoff_bfd_link_hash_table_create (abfd
)
3443 struct ecoff_link_hash_table
*ret
;
3444 bfd_size_type amt
= sizeof (struct ecoff_link_hash_table
);
3446 ret
= (struct ecoff_link_hash_table
*) bfd_malloc (amt
);
3449 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3450 ecoff_link_hash_newfunc
))
3453 return (struct bfd_link_hash_table
*) NULL
;
3458 /* Look up an entry in an ECOFF link hash table. */
3460 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3461 ((struct ecoff_link_hash_entry *) \
3462 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3464 /* Traverse an ECOFF link hash table. */
3466 #define ecoff_link_hash_traverse(table, func, info) \
3467 (bfd_link_hash_traverse \
3469 (bfd_boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3472 /* Get the ECOFF link hash table from the info structure. This is
3475 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3477 /* Given an ECOFF BFD, add symbols to the global hash table as
3481 _bfd_ecoff_bfd_link_add_symbols (abfd
, info
)
3483 struct bfd_link_info
*info
;
3485 switch (bfd_get_format (abfd
))
3488 return ecoff_link_add_object_symbols (abfd
, info
);
3490 return ecoff_link_add_archive_symbols (abfd
, info
);
3492 bfd_set_error (bfd_error_wrong_format
);
3497 /* Add the symbols from an archive file to the global hash table.
3498 This looks through the undefined symbols, looks each one up in the
3499 archive hash table, and adds any associated object file. We do not
3500 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3501 already have a hash table, so there is no reason to construct
3505 ecoff_link_add_archive_symbols (abfd
, info
)
3507 struct bfd_link_info
*info
;
3509 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3510 const bfd_byte
*raw_armap
;
3511 struct bfd_link_hash_entry
**pundef
;
3512 unsigned int armap_count
;
3513 unsigned int armap_log
;
3515 const bfd_byte
*hashtable
;
3516 const char *stringbase
;
3518 if (! bfd_has_map (abfd
))
3520 /* An empty archive is a special case. */
3521 if (bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
) == NULL
)
3523 bfd_set_error (bfd_error_no_armap
);
3527 /* If we don't have any raw data for this archive, as can happen on
3528 Irix 4.0.5F, we call the generic routine.
3529 FIXME: We should be more clever about this, since someday tdata
3530 may get to something for a generic archive. */
3531 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3532 if (raw_armap
== (bfd_byte
*) NULL
)
3533 return (_bfd_generic_link_add_archive_symbols
3534 (abfd
, info
, ecoff_link_check_archive_element
));
3536 armap_count
= H_GET_32 (abfd
, raw_armap
);
3539 for (i
= 1; i
< armap_count
; i
<<= 1)
3541 BFD_ASSERT (i
== armap_count
);
3543 hashtable
= raw_armap
+ 4;
3544 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3546 /* Look through the list of undefined symbols. */
3547 pundef
= &info
->hash
->undefs
;
3548 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3550 struct bfd_link_hash_entry
*h
;
3551 unsigned int hash
, rehash
;
3552 unsigned int file_offset
;
3558 /* When a symbol is defined, it is not necessarily removed from
3560 if (h
->type
!= bfd_link_hash_undefined
3561 && h
->type
!= bfd_link_hash_common
)
3563 /* Remove this entry from the list, for general cleanliness
3564 and because we are going to look through the list again
3565 if we search any more libraries. We can't remove the
3566 entry if it is the tail, because that would lose any
3567 entries we add to the list later on. */
3568 if (*pundef
!= info
->hash
->undefs_tail
)
3569 *pundef
= (*pundef
)->und_next
;
3571 pundef
= &(*pundef
)->und_next
;
3575 /* Native ECOFF linkers do not pull in archive elements merely
3576 to satisfy common definitions, so neither do we. We leave
3577 them on the list, though, in case we are linking against some
3578 other object format. */
3579 if (h
->type
!= bfd_link_hash_undefined
)
3581 pundef
= &(*pundef
)->und_next
;
3585 /* Look for this symbol in the archive hash table. */
3586 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3589 file_offset
= H_GET_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3590 if (file_offset
== 0)
3592 /* Nothing in this slot. */
3593 pundef
= &(*pundef
)->und_next
;
3597 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (hash
* 8));
3598 if (name
[0] != h
->root
.string
[0]
3599 || strcmp (name
, h
->root
.string
) != 0)
3604 /* That was the wrong symbol. Try rehashing. */
3606 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3608 srch
= (srch
+ rehash
) & (armap_count
- 1))
3610 file_offset
= H_GET_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3611 if (file_offset
== 0)
3613 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (srch
* 8));
3614 if (name
[0] == h
->root
.string
[0]
3615 && strcmp (name
, h
->root
.string
) == 0)
3624 pundef
= &(*pundef
)->und_next
;
3631 element
= (*backend
->get_elt_at_filepos
) (abfd
, (file_ptr
) file_offset
);
3632 if (element
== (bfd
*) NULL
)
3635 if (! bfd_check_format (element
, bfd_object
))
3638 /* Unlike the generic linker, we know that this element provides
3639 a definition for an undefined symbol and we know that we want
3640 to include it. We don't need to check anything. */
3641 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3643 if (! ecoff_link_add_object_symbols (element
, info
))
3646 pundef
= &(*pundef
)->und_next
;
3652 /* This is called if we used _bfd_generic_link_add_archive_symbols
3653 because we were not dealing with an ECOFF archive. */
3656 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3658 struct bfd_link_info
*info
;
3659 bfd_boolean
*pneeded
;
3661 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3662 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3663 = backend
->debug_swap
.swap_ext_in
;
3665 bfd_size_type external_ext_size
;
3666 PTR external_ext
= NULL
;
3667 bfd_size_type esize
;
3674 if (! ecoff_slurp_symbolic_header (abfd
))
3677 /* If there are no symbols, we don't want it. */
3678 if (bfd_get_symcount (abfd
) == 0)
3679 goto successful_return
;
3681 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3683 /* Read in the external symbols and external strings. */
3684 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3685 esize
= symhdr
->iextMax
* external_ext_size
;
3686 external_ext
= (PTR
) bfd_malloc (esize
);
3687 if (external_ext
== NULL
&& esize
!= 0)
3690 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbExtOffset
, SEEK_SET
) != 0
3691 || bfd_bread (external_ext
, esize
, abfd
) != esize
)
3694 ssext
= (char *) bfd_malloc ((bfd_size_type
) symhdr
->issExtMax
);
3695 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3698 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3699 || (bfd_bread (ssext
, (bfd_size_type
) symhdr
->issExtMax
, abfd
)
3700 != (bfd_size_type
) symhdr
->issExtMax
))
3703 /* Look through the external symbols to see if they define some
3704 symbol that is currently undefined. */
3705 ext_ptr
= (char *) external_ext
;
3706 ext_end
= ext_ptr
+ esize
;
3707 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3712 struct bfd_link_hash_entry
*h
;
3714 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3716 /* See if this symbol defines something. */
3717 if (esym
.asym
.st
!= stGlobal
3718 && esym
.asym
.st
!= stLabel
3719 && esym
.asym
.st
!= stProc
)
3722 switch (esym
.asym
.sc
)
3746 name
= ssext
+ esym
.asym
.iss
;
3747 h
= bfd_link_hash_lookup (info
->hash
, name
, FALSE
, FALSE
, TRUE
);
3749 /* Unlike the generic linker, we do not pull in elements because
3750 of common symbols. */
3751 if (h
== (struct bfd_link_hash_entry
*) NULL
3752 || h
->type
!= bfd_link_hash_undefined
)
3755 /* Include this element. */
3756 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3758 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3762 goto successful_return
;
3766 if (external_ext
!= NULL
)
3767 free (external_ext
);
3772 if (external_ext
!= NULL
)
3773 free (external_ext
);
3779 /* Add symbols from an ECOFF object file to the global linker hash
3783 ecoff_link_add_object_symbols (abfd
, info
)
3785 struct bfd_link_info
*info
;
3788 bfd_size_type external_ext_size
;
3789 PTR external_ext
= NULL
;
3790 bfd_size_type esize
;
3794 if (! ecoff_slurp_symbolic_header (abfd
))
3797 /* If there are no symbols, we don't want it. */
3798 if (bfd_get_symcount (abfd
) == 0)
3801 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3803 /* Read in the external symbols and external strings. */
3804 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3805 esize
= symhdr
->iextMax
* external_ext_size
;
3806 external_ext
= (PTR
) bfd_malloc (esize
);
3807 if (external_ext
== NULL
&& esize
!= 0)
3810 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbExtOffset
, SEEK_SET
) != 0
3811 || bfd_bread (external_ext
, esize
, abfd
) != esize
)
3814 ssext
= (char *) bfd_malloc ((bfd_size_type
) symhdr
->issExtMax
);
3815 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3818 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3819 || (bfd_bread (ssext
, (bfd_size_type
) symhdr
->issExtMax
, abfd
)
3820 != (bfd_size_type
) symhdr
->issExtMax
))
3823 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3827 if (external_ext
!= NULL
)
3828 free (external_ext
);
3834 if (external_ext
!= NULL
)
3835 free (external_ext
);
3839 /* Add the external symbols of an object file to the global linker
3840 hash table. The external symbols and strings we are passed are
3841 just allocated on the stack, and will be discarded. We must
3842 explicitly save any information we may need later on in the link.
3843 We do not want to read the external symbol information again. */
3846 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3848 struct bfd_link_info
*info
;
3852 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3853 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3854 = backend
->debug_swap
.swap_ext_in
;
3855 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3856 unsigned long ext_count
;
3857 struct bfd_link_hash_entry
**sym_hash
;
3862 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3865 amt
*= sizeof (struct bfd_link_hash_entry
*);
3866 sym_hash
= (struct bfd_link_hash_entry
**) bfd_alloc (abfd
, amt
);
3869 ecoff_data (abfd
)->sym_hashes
= (struct ecoff_link_hash_entry
**) sym_hash
;
3871 ext_ptr
= (char *) external_ext
;
3872 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3873 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3880 struct ecoff_link_hash_entry
*h
;
3884 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3886 /* Skip debugging symbols. */
3888 switch (esym
.asym
.st
)
3904 /* Get the information for this symbol. */
3905 value
= esym
.asym
.value
;
3906 switch (esym
.asym
.sc
)
3926 section
= bfd_make_section_old_way (abfd
, ".text");
3927 value
-= section
->vma
;
3930 section
= bfd_make_section_old_way (abfd
, ".data");
3931 value
-= section
->vma
;
3934 section
= bfd_make_section_old_way (abfd
, ".bss");
3935 value
-= section
->vma
;
3938 section
= bfd_abs_section_ptr
;
3941 section
= bfd_und_section_ptr
;
3944 section
= bfd_make_section_old_way (abfd
, ".sdata");
3945 value
-= section
->vma
;
3948 section
= bfd_make_section_old_way (abfd
, ".sbss");
3949 value
-= section
->vma
;
3952 section
= bfd_make_section_old_way (abfd
, ".rdata");
3953 value
-= section
->vma
;
3956 if (value
> ecoff_data (abfd
)->gp_size
)
3958 section
= bfd_com_section_ptr
;
3963 if (ecoff_scom_section
.name
== NULL
)
3965 /* Initialize the small common section. */
3966 ecoff_scom_section
.name
= SCOMMON
;
3967 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3968 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3969 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3970 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3971 ecoff_scom_symbol
.name
= SCOMMON
;
3972 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3973 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3974 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3976 section
= &ecoff_scom_section
;
3979 section
= bfd_und_section_ptr
;
3982 section
= bfd_make_section_old_way (abfd
, ".init");
3983 value
-= section
->vma
;
3986 section
= bfd_make_section_old_way (abfd
, ".fini");
3987 value
-= section
->vma
;
3990 section
= bfd_make_section_old_way (abfd
, ".rconst");
3991 value
-= section
->vma
;
3995 if (section
== (asection
*) NULL
)
3998 name
= ssext
+ esym
.asym
.iss
;
4000 if (! (_bfd_generic_link_add_one_symbol
4002 (flagword
) (esym
.weakext
? BSF_WEAK
: BSF_GLOBAL
),
4003 section
, value
, (const char *) NULL
, TRUE
, TRUE
, sym_hash
)))
4006 h
= (struct ecoff_link_hash_entry
*) *sym_hash
;
4008 /* If we are building an ECOFF hash table, save the external
4009 symbol information. */
4010 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
4012 if (h
->abfd
== (bfd
*) NULL
4013 || (! bfd_is_und_section (section
)
4014 && (! bfd_is_com_section (section
)
4015 || (h
->root
.type
!= bfd_link_hash_defined
4016 && h
->root
.type
!= bfd_link_hash_defweak
))))
4022 /* Remember whether this symbol was small undefined. */
4023 if (esym
.asym
.sc
== scSUndefined
)
4026 /* If this symbol was ever small undefined, it needs to wind
4027 up in a GP relative section. We can't control the
4028 section of a defined symbol, but we can control the
4029 section of a common symbol. This case is actually needed
4030 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
4032 && h
->root
.type
== bfd_link_hash_common
4033 && strcmp (h
->root
.u
.c
.p
->section
->name
, SCOMMON
) != 0)
4035 h
->root
.u
.c
.p
->section
= bfd_make_section_old_way (abfd
,
4037 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4038 if (h
->esym
.asym
.sc
== scCommon
)
4039 h
->esym
.asym
.sc
= scSCommon
;
4047 /* ECOFF final link routines. */
4049 static bfd_boolean ecoff_final_link_debug_accumulate
4050 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4052 static bfd_boolean ecoff_link_write_external
4053 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4054 static bfd_boolean ecoff_indirect_link_order
4055 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4056 struct bfd_link_order
*));
4057 static bfd_boolean ecoff_reloc_link_order
4058 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4059 struct bfd_link_order
*));
4061 /* Structure used to pass information to ecoff_link_write_external. */
4066 struct bfd_link_info
*info
;
4069 /* ECOFF final link routine. This looks through all the input BFDs
4070 and gathers together all the debugging information, and then
4071 processes all the link order information. This may cause it to
4072 close and reopen some input BFDs; I'll see how bad this is. */
4075 _bfd_ecoff_bfd_final_link (abfd
, info
)
4077 struct bfd_link_info
*info
;
4079 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4080 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4083 register bfd
*input_bfd
;
4085 struct bfd_link_order
*p
;
4086 struct extsym_info einfo
;
4088 /* We accumulate the debugging information counts in the symbolic
4090 symhdr
= &debug
->symbolic_header
;
4092 symhdr
->ilineMax
= 0;
4096 symhdr
->isymMax
= 0;
4097 symhdr
->ioptMax
= 0;
4098 symhdr
->iauxMax
= 0;
4100 symhdr
->issExtMax
= 0;
4103 symhdr
->iextMax
= 0;
4105 /* We accumulate the debugging information itself in the debug_info
4108 debug
->external_dnr
= NULL
;
4109 debug
->external_pdr
= NULL
;
4110 debug
->external_sym
= NULL
;
4111 debug
->external_opt
= NULL
;
4112 debug
->external_aux
= NULL
;
4114 debug
->ssext
= debug
->ssext_end
= NULL
;
4115 debug
->external_fdr
= NULL
;
4116 debug
->external_rfd
= NULL
;
4117 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4119 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4120 if (handle
== (PTR
) NULL
)
4123 /* Accumulate the debugging symbols from each input BFD. */
4124 for (input_bfd
= info
->input_bfds
;
4125 input_bfd
!= (bfd
*) NULL
;
4126 input_bfd
= input_bfd
->link_next
)
4130 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4132 /* Arbitrarily set the symbolic header vstamp to the vstamp
4133 of the first object file in the link. */
4134 if (symhdr
->vstamp
== 0)
4136 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4137 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4141 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4142 debug
, &backend
->debug_swap
,
4147 /* Combine the register masks. */
4148 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4149 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4150 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4151 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4152 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4153 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4156 /* Write out the external symbols. */
4159 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4160 ecoff_link_write_external
,
4163 if (info
->relocatable
)
4165 /* We need to make a pass over the link_orders to count up the
4166 number of relocations we will need to output, so that we know
4167 how much space they will take up. */
4168 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4171 for (p
= o
->link_order_head
;
4172 p
!= (struct bfd_link_order
*) NULL
;
4174 if (p
->type
== bfd_indirect_link_order
)
4175 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4176 else if (p
->type
== bfd_section_reloc_link_order
4177 || p
->type
== bfd_symbol_reloc_link_order
)
4182 /* Compute the reloc and symbol file positions. */
4183 ecoff_compute_reloc_file_positions (abfd
);
4185 /* Write out the debugging information. */
4186 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4187 &backend
->debug_swap
, info
,
4188 ecoff_data (abfd
)->sym_filepos
))
4191 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4193 if (info
->relocatable
)
4195 /* Now reset the reloc_count field of the sections in the output
4196 BFD to 0, so that we can use them to keep track of how many
4197 relocs we have output thus far. */
4198 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4202 /* Get a value for the GP register. */
4203 if (ecoff_data (abfd
)->gp
== 0)
4205 struct bfd_link_hash_entry
*h
;
4207 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
4208 if (h
!= (struct bfd_link_hash_entry
*) NULL
4209 && h
->type
== bfd_link_hash_defined
)
4210 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4211 + h
->u
.def
.section
->output_section
->vma
4212 + h
->u
.def
.section
->output_offset
);
4213 else if (info
->relocatable
)
4217 /* Make up a value. */
4219 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4222 && (strcmp (o
->name
, _SBSS
) == 0
4223 || strcmp (o
->name
, _SDATA
) == 0
4224 || strcmp (o
->name
, _LIT4
) == 0
4225 || strcmp (o
->name
, _LIT8
) == 0
4226 || strcmp (o
->name
, _LITA
) == 0))
4229 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4233 /* If the relocate_section function needs to do a reloc
4234 involving the GP value, it should make a reloc_dangerous
4235 callback to warn that GP is not defined. */
4239 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4241 for (p
= o
->link_order_head
;
4242 p
!= (struct bfd_link_order
*) NULL
;
4245 if (p
->type
== bfd_indirect_link_order
4246 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4247 == bfd_target_ecoff_flavour
))
4249 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4252 else if (p
->type
== bfd_section_reloc_link_order
4253 || p
->type
== bfd_symbol_reloc_link_order
)
4255 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4260 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4266 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4268 ecoff_data (abfd
)->linker
= TRUE
;
4273 /* Accumulate the debugging information for an input BFD into the
4274 output BFD. This must read in the symbolic information of the
4278 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4281 struct bfd_link_info
*info
;
4284 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4285 const struct ecoff_debug_swap
* const swap
=
4286 &ecoff_backend (input_bfd
)->debug_swap
;
4287 HDRR
*symhdr
= &debug
->symbolic_header
;
4290 #define READ(ptr, offset, count, size, type) \
4291 if (symhdr->count == 0) \
4292 debug->ptr = NULL; \
4295 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
4296 debug->ptr = (type) bfd_malloc (amt); \
4297 if (debug->ptr == NULL) \
4300 goto return_something; \
4302 if (bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
4303 || bfd_bread (debug->ptr, amt, input_bfd) != amt) \
4306 goto return_something; \
4310 /* If raw_syments is not NULL, then the data was already by read by
4311 _bfd_ecoff_slurp_symbolic_info. */
4312 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4314 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4316 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4317 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4318 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4319 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4320 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4322 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4323 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4324 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4328 /* We do not read the external strings or the external symbols. */
4330 ret
= (bfd_ecoff_debug_accumulate
4331 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4332 &ecoff_backend (output_bfd
)->debug_swap
,
4333 input_bfd
, debug
, swap
, info
));
4336 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4338 if (debug
->line
!= NULL
)
4340 if (debug
->external_dnr
!= NULL
)
4341 free (debug
->external_dnr
);
4342 if (debug
->external_pdr
!= NULL
)
4343 free (debug
->external_pdr
);
4344 if (debug
->external_sym
!= NULL
)
4345 free (debug
->external_sym
);
4346 if (debug
->external_opt
!= NULL
)
4347 free (debug
->external_opt
);
4348 if (debug
->external_aux
!= NULL
)
4349 free (debug
->external_aux
);
4350 if (debug
->ss
!= NULL
)
4352 if (debug
->external_fdr
!= NULL
)
4353 free (debug
->external_fdr
);
4354 if (debug
->external_rfd
!= NULL
)
4355 free (debug
->external_rfd
);
4357 /* Make sure we don't accidentally follow one of these pointers
4358 into freed memory. */
4360 debug
->external_dnr
= NULL
;
4361 debug
->external_pdr
= NULL
;
4362 debug
->external_sym
= NULL
;
4363 debug
->external_opt
= NULL
;
4364 debug
->external_aux
= NULL
;
4366 debug
->external_fdr
= NULL
;
4367 debug
->external_rfd
= NULL
;
4373 /* Put out information for an external symbol. These come only from
4377 ecoff_link_write_external (h
, data
)
4378 struct ecoff_link_hash_entry
*h
;
4381 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4382 bfd
*output_bfd
= einfo
->abfd
;
4385 if (h
->root
.type
== bfd_link_hash_warning
)
4387 h
= (struct ecoff_link_hash_entry
*) h
->root
.u
.i
.link
;
4388 if (h
->root
.type
== bfd_link_hash_new
)
4392 /* We need to check if this symbol is being stripped. */
4393 if (h
->root
.type
== bfd_link_hash_undefined
4394 || h
->root
.type
== bfd_link_hash_undefweak
)
4396 else if (einfo
->info
->strip
== strip_all
4397 || (einfo
->info
->strip
== strip_some
4398 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4399 h
->root
.root
.string
,
4400 FALSE
, FALSE
) == NULL
))
4405 if (strip
|| h
->written
)
4408 if (h
->abfd
== (bfd
*) NULL
)
4411 h
->esym
.cobol_main
= 0;
4412 h
->esym
.weakext
= 0;
4413 h
->esym
.reserved
= 0;
4414 h
->esym
.ifd
= ifdNil
;
4415 h
->esym
.asym
.value
= 0;
4416 h
->esym
.asym
.st
= stGlobal
;
4418 if (h
->root
.type
!= bfd_link_hash_defined
4419 && h
->root
.type
!= bfd_link_hash_defweak
)
4420 h
->esym
.asym
.sc
= scAbs
;
4423 asection
*output_section
;
4426 output_section
= h
->root
.u
.def
.section
->output_section
;
4427 name
= bfd_section_name (output_section
->owner
, output_section
);
4429 if (strcmp (name
, _TEXT
) == 0)
4430 h
->esym
.asym
.sc
= scText
;
4431 else if (strcmp (name
, _DATA
) == 0)
4432 h
->esym
.asym
.sc
= scData
;
4433 else if (strcmp (name
, _SDATA
) == 0)
4434 h
->esym
.asym
.sc
= scSData
;
4435 else if (strcmp (name
, _RDATA
) == 0)
4436 h
->esym
.asym
.sc
= scRData
;
4437 else if (strcmp (name
, _BSS
) == 0)
4438 h
->esym
.asym
.sc
= scBss
;
4439 else if (strcmp (name
, _SBSS
) == 0)
4440 h
->esym
.asym
.sc
= scSBss
;
4441 else if (strcmp (name
, _INIT
) == 0)
4442 h
->esym
.asym
.sc
= scInit
;
4443 else if (strcmp (name
, _FINI
) == 0)
4444 h
->esym
.asym
.sc
= scFini
;
4445 else if (strcmp (name
, _PDATA
) == 0)
4446 h
->esym
.asym
.sc
= scPData
;
4447 else if (strcmp (name
, _XDATA
) == 0)
4448 h
->esym
.asym
.sc
= scXData
;
4449 else if (strcmp (name
, _RCONST
) == 0)
4450 h
->esym
.asym
.sc
= scRConst
;
4452 h
->esym
.asym
.sc
= scAbs
;
4455 h
->esym
.asym
.reserved
= 0;
4456 h
->esym
.asym
.index
= indexNil
;
4458 else if (h
->esym
.ifd
!= -1)
4460 struct ecoff_debug_info
*debug
;
4462 /* Adjust the FDR index for the symbol by that used for the
4464 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4465 BFD_ASSERT (h
->esym
.ifd
>= 0
4466 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4467 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4470 switch (h
->root
.type
)
4473 case bfd_link_hash_warning
:
4474 case bfd_link_hash_new
:
4476 case bfd_link_hash_undefined
:
4477 case bfd_link_hash_undefweak
:
4478 if (h
->esym
.asym
.sc
!= scUndefined
4479 && h
->esym
.asym
.sc
!= scSUndefined
)
4480 h
->esym
.asym
.sc
= scUndefined
;
4482 case bfd_link_hash_defined
:
4483 case bfd_link_hash_defweak
:
4484 if (h
->esym
.asym
.sc
== scUndefined
4485 || h
->esym
.asym
.sc
== scSUndefined
)
4486 h
->esym
.asym
.sc
= scAbs
;
4487 else if (h
->esym
.asym
.sc
== scCommon
)
4488 h
->esym
.asym
.sc
= scBss
;
4489 else if (h
->esym
.asym
.sc
== scSCommon
)
4490 h
->esym
.asym
.sc
= scSBss
;
4491 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4492 + h
->root
.u
.def
.section
->output_section
->vma
4493 + h
->root
.u
.def
.section
->output_offset
);
4495 case bfd_link_hash_common
:
4496 if (h
->esym
.asym
.sc
!= scCommon
4497 && h
->esym
.asym
.sc
!= scSCommon
)
4498 h
->esym
.asym
.sc
= scCommon
;
4499 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4501 case bfd_link_hash_indirect
:
4502 /* We ignore these symbols, since the indirected symbol is
4503 already in the hash table. */
4507 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4509 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4512 return (bfd_ecoff_debug_one_external
4513 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4514 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4518 /* Relocate and write an ECOFF section into an ECOFF output file. */
4521 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4523 struct bfd_link_info
*info
;
4524 asection
*output_section
;
4525 struct bfd_link_order
*link_order
;
4527 asection
*input_section
;
4529 struct ecoff_section_tdata
*section_tdata
;
4530 bfd_size_type raw_size
;
4531 bfd_size_type cooked_size
;
4532 bfd_byte
*contents
= NULL
;
4533 bfd_size_type external_reloc_size
;
4534 bfd_size_type external_relocs_size
;
4535 PTR external_relocs
= NULL
;
4538 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4540 if (link_order
->size
== 0)
4543 input_section
= link_order
->u
.indirect
.section
;
4544 input_bfd
= input_section
->owner
;
4545 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4547 raw_size
= input_section
->_raw_size
;
4548 cooked_size
= input_section
->_cooked_size
;
4549 if (cooked_size
== 0)
4550 cooked_size
= raw_size
;
4552 BFD_ASSERT (input_section
->output_section
== output_section
);
4553 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4554 BFD_ASSERT (cooked_size
== link_order
->size
);
4556 /* Get the section contents. We allocate memory for the larger of
4557 the size before relocating and the size after relocating. */
4558 amt
= raw_size
>= cooked_size
? raw_size
: cooked_size
;
4559 contents
= (bfd_byte
*) bfd_malloc (amt
);
4560 if (contents
== NULL
&& amt
!= 0)
4563 /* If we are relaxing, the contents may have already been read into
4564 memory, in which case we copy them into our new buffer. We don't
4565 simply reuse the old buffer in case cooked_size > raw_size. */
4566 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4567 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4568 memcpy (contents
, section_tdata
->contents
, (size_t) raw_size
);
4571 if (! bfd_get_section_contents (input_bfd
, input_section
,
4573 (file_ptr
) 0, raw_size
))
4577 /* Get the relocs. If we are relaxing MIPS code, they will already
4578 have been read in. Otherwise, we read them in now. */
4579 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4580 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4582 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4583 && section_tdata
->external_relocs
!= NULL
)
4584 external_relocs
= section_tdata
->external_relocs
;
4587 external_relocs
= (PTR
) bfd_malloc (external_relocs_size
);
4588 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4591 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4592 || (bfd_bread (external_relocs
, external_relocs_size
, input_bfd
)
4593 != external_relocs_size
))
4597 /* Relocate the section contents. */
4598 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4599 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4603 /* Write out the relocated section. */
4604 if (! bfd_set_section_contents (output_bfd
,
4607 (file_ptr
) input_section
->output_offset
,
4611 /* If we are producing relocatable output, the relocs were
4612 modified, and we write them out now. We use the reloc_count
4613 field of output_section to keep track of the number of relocs we
4614 have output so far. */
4615 if (info
->relocatable
)
4617 file_ptr pos
= (output_section
->rel_filepos
4618 + output_section
->reloc_count
* external_reloc_size
);
4619 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
4620 || (bfd_bwrite (external_relocs
, external_relocs_size
, output_bfd
)
4621 != external_relocs_size
))
4623 output_section
->reloc_count
+= input_section
->reloc_count
;
4626 if (contents
!= NULL
)
4628 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4629 free (external_relocs
);
4633 if (contents
!= NULL
)
4635 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4636 free (external_relocs
);
4640 /* Generate a reloc when linking an ECOFF file. This is a reloc
4641 requested by the linker, and does come from any input file. This
4642 is used to build constructor and destructor tables when linking
4646 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4648 struct bfd_link_info
*info
;
4649 asection
*output_section
;
4650 struct bfd_link_order
*link_order
;
4652 enum bfd_link_order_type type
;
4656 struct internal_reloc in
;
4657 bfd_size_type external_reloc_size
;
4662 type
= link_order
->type
;
4664 addend
= link_order
->u
.reloc
.p
->addend
;
4666 /* We set up an arelent to pass to the backend adjust_reloc_out
4668 rel
.address
= link_order
->offset
;
4670 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4673 bfd_set_error (bfd_error_bad_value
);
4677 if (type
== bfd_section_reloc_link_order
)
4679 section
= link_order
->u
.reloc
.p
->u
.section
;
4680 rel
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
4684 struct bfd_link_hash_entry
*h
;
4686 /* Treat a reloc against a defined symbol as though it were
4687 actually against the section. */
4688 h
= bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4689 link_order
->u
.reloc
.p
->u
.name
,
4690 FALSE
, FALSE
, FALSE
);
4692 && (h
->type
== bfd_link_hash_defined
4693 || h
->type
== bfd_link_hash_defweak
))
4695 type
= bfd_section_reloc_link_order
;
4696 section
= h
->u
.def
.section
->output_section
;
4697 /* It seems that we ought to add the symbol value to the
4698 addend here, but in practice it has already been added
4699 because it was passed to constructor_callback. */
4700 addend
+= section
->vma
+ h
->u
.def
.section
->output_offset
;
4704 /* We can't set up a reloc against a symbol correctly,
4705 because we have no asymbol structure. Currently no
4706 adjust_reloc_out routine cares. */
4707 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4711 /* All ECOFF relocs are in-place. Put the addend into the object
4714 BFD_ASSERT (rel
.howto
->partial_inplace
);
4718 bfd_reloc_status_type rstat
;
4721 size
= bfd_get_reloc_size (rel
.howto
);
4722 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4723 if (buf
== (bfd_byte
*) NULL
)
4725 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4726 (bfd_vma
) addend
, buf
);
4732 case bfd_reloc_outofrange
:
4734 case bfd_reloc_overflow
:
4735 if (! ((*info
->callbacks
->reloc_overflow
)
4737 (link_order
->type
== bfd_section_reloc_link_order
4738 ? bfd_section_name (output_bfd
, section
)
4739 : link_order
->u
.reloc
.p
->u
.name
),
4740 rel
.howto
->name
, addend
, (bfd
*) NULL
,
4741 (asection
*) NULL
, (bfd_vma
) 0)))
4748 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4749 (file_ptr
) link_order
->offset
, size
);
4757 /* Move the information into an internal_reloc structure. */
4758 in
.r_vaddr
= (rel
.address
4759 + bfd_get_section_vma (output_bfd
, output_section
));
4760 in
.r_type
= rel
.howto
->type
;
4762 if (type
== bfd_symbol_reloc_link_order
)
4764 struct ecoff_link_hash_entry
*h
;
4766 h
= ((struct ecoff_link_hash_entry
*)
4767 bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4768 link_order
->u
.reloc
.p
->u
.name
,
4769 FALSE
, FALSE
, TRUE
));
4770 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4772 in
.r_symndx
= h
->indx
;
4775 if (! ((*info
->callbacks
->unattached_reloc
)
4776 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4777 (asection
*) NULL
, (bfd_vma
) 0)))
4787 name
= bfd_get_section_name (output_bfd
, section
);
4788 if (strcmp (name
, ".text") == 0)
4789 in
.r_symndx
= RELOC_SECTION_TEXT
;
4790 else if (strcmp (name
, ".rdata") == 0)
4791 in
.r_symndx
= RELOC_SECTION_RDATA
;
4792 else if (strcmp (name
, ".data") == 0)
4793 in
.r_symndx
= RELOC_SECTION_DATA
;
4794 else if (strcmp (name
, ".sdata") == 0)
4795 in
.r_symndx
= RELOC_SECTION_SDATA
;
4796 else if (strcmp (name
, ".sbss") == 0)
4797 in
.r_symndx
= RELOC_SECTION_SBSS
;
4798 else if (strcmp (name
, ".bss") == 0)
4799 in
.r_symndx
= RELOC_SECTION_BSS
;
4800 else if (strcmp (name
, ".init") == 0)
4801 in
.r_symndx
= RELOC_SECTION_INIT
;
4802 else if (strcmp (name
, ".lit8") == 0)
4803 in
.r_symndx
= RELOC_SECTION_LIT8
;
4804 else if (strcmp (name
, ".lit4") == 0)
4805 in
.r_symndx
= RELOC_SECTION_LIT4
;
4806 else if (strcmp (name
, ".xdata") == 0)
4807 in
.r_symndx
= RELOC_SECTION_XDATA
;
4808 else if (strcmp (name
, ".pdata") == 0)
4809 in
.r_symndx
= RELOC_SECTION_PDATA
;
4810 else if (strcmp (name
, ".fini") == 0)
4811 in
.r_symndx
= RELOC_SECTION_FINI
;
4812 else if (strcmp (name
, ".lita") == 0)
4813 in
.r_symndx
= RELOC_SECTION_LITA
;
4814 else if (strcmp (name
, "*ABS*") == 0)
4815 in
.r_symndx
= RELOC_SECTION_ABS
;
4816 else if (strcmp (name
, ".rconst") == 0)
4817 in
.r_symndx
= RELOC_SECTION_RCONST
;
4823 /* Let the BFD backend adjust the reloc. */
4824 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4826 /* Get some memory and swap out the reloc. */
4827 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4828 rbuf
= (bfd_byte
*) bfd_malloc (external_reloc_size
);
4829 if (rbuf
== (bfd_byte
*) NULL
)
4832 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4834 pos
= (output_section
->rel_filepos
4835 + output_section
->reloc_count
* external_reloc_size
);
4836 ok
= (bfd_seek (output_bfd
, pos
, SEEK_SET
) == 0
4837 && (bfd_bwrite ((PTR
) rbuf
, external_reloc_size
, output_bfd
)
4838 == external_reloc_size
));
4841 ++output_section
->reloc_count
;