1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Original version by Per Bothner.
5 Full support added by Ian Lance Taylor, ian@cygnus.com.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "aout/ranlib.h"
29 #include "aout/stab_gnu.h"
31 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
32 some other stuff which we don't want and which conflicts with stuff
35 #include "aout/aout64.h"
38 #undef obj_sym_filepos
40 #include "coff/internal.h"
42 #include "coff/symconst.h"
43 #include "coff/ecoff.h"
47 /* Prototypes for static functions. */
49 static int ecoff_get_magic
PARAMS ((bfd
*));
50 static long ecoff_sec_to_styp_flags
PARAMS ((const char *, flagword
));
51 static boolean ecoff_slurp_symbolic_header
PARAMS ((bfd
*));
52 static boolean ecoff_set_symbol_info
PARAMS ((bfd
*, SYMR
*, asymbol
*, int, int));
53 static void ecoff_emit_aggregate
PARAMS ((bfd
*, FDR
*, char *, RNDXR
*, long, const char *));
54 static char *ecoff_type_to_string
PARAMS ((bfd
*, FDR
*, unsigned int));
55 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*, asection
*, asymbol
**));
56 static int ecoff_sort_hdrs
PARAMS ((const PTR
, const PTR
));
57 static boolean ecoff_compute_section_file_positions
PARAMS ((bfd
*));
58 static bfd_size_type ecoff_compute_reloc_file_positions
PARAMS ((bfd
*));
59 static boolean ecoff_get_extr
PARAMS ((asymbol
*, EXTR
*));
60 static void ecoff_set_index
PARAMS ((asymbol
*, bfd_size_type
));
61 static unsigned int ecoff_armap_hash
PARAMS ((const char *, unsigned int *, unsigned int, unsigned int));
63 /* This stuff is somewhat copied from coffcode.h. */
65 static asection bfd_debug_section
=
67 /* name, id, index, next, flags, user_set_vma, reloc_done, */
68 "*DEBUG*", 0, 0, NULL
, 0, 0, 0,
69 /* linker_mark, linker_has_input, gc_mark, segment_mark, */
71 /* vma, lma, _cooked_size, _raw_size, */
73 /* output_offset, output_section, alignment_power, */
75 /* relocation, orelocation, reloc_count, filepos, rel_filepos, */
77 /* line_filepos, userdata, contents, lineno, lineno_count, */
78 0, NULL
, NULL
, NULL
, 0,
79 /* entsize, comdat, moving_line_filepos, */
81 /* target_index, used_by_bfd, constructor_chain, owner, */
84 (struct symbol_cache_entry
*) NULL
,
86 (struct symbol_cache_entry
**) NULL
,
87 /* link_order_head, link_order_tail */
91 /* Create an ECOFF object. */
94 _bfd_ecoff_mkobject (abfd
)
97 bfd_size_type amt
= sizeof (ecoff_data_type
);
99 abfd
->tdata
.ecoff_obj_data
= (struct ecoff_tdata
*) bfd_zalloc (abfd
, amt
);
100 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
106 /* This is a hook called by coff_real_object_p to create any backend
107 specific information. */
110 _bfd_ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
115 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
116 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
117 ecoff_data_type
*ecoff
;
119 if (! _bfd_ecoff_mkobject (abfd
))
122 ecoff
= ecoff_data (abfd
);
124 ecoff
->sym_filepos
= internal_f
->f_symptr
;
126 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
130 ecoff
->text_start
= internal_a
->text_start
;
131 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
132 ecoff
->gp
= internal_a
->gp_value
;
133 ecoff
->gprmask
= internal_a
->gprmask
;
134 for (i
= 0; i
< 4; i
++)
135 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
136 ecoff
->fprmask
= internal_a
->fprmask
;
137 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
138 abfd
->flags
|= D_PAGED
;
140 abfd
->flags
&=~ D_PAGED
;
143 /* It turns out that no special action is required by the MIPS or
144 Alpha ECOFF backends. They have different information in the
145 a.out header, but we just copy it all (e.g., gprmask, cprmask and
146 fprmask) and let the swapping routines ensure that only relevant
147 information is written out. */
152 /* Initialize a new section. */
155 _bfd_ecoff_new_section_hook (abfd
, section
)
156 bfd
*abfd ATTRIBUTE_UNUSED
;
159 section
->alignment_power
= 4;
161 if (strcmp (section
->name
, _TEXT
) == 0
162 || strcmp (section
->name
, _INIT
) == 0
163 || strcmp (section
->name
, _FINI
) == 0)
164 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
165 else if (strcmp (section
->name
, _DATA
) == 0
166 || strcmp (section
->name
, _SDATA
) == 0)
167 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
168 else if (strcmp (section
->name
, _RDATA
) == 0
169 || strcmp (section
->name
, _LIT8
) == 0
170 || strcmp (section
->name
, _LIT4
) == 0
171 || strcmp (section
->name
, _RCONST
) == 0
172 || strcmp (section
->name
, _PDATA
) == 0)
173 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
174 else if (strcmp (section
->name
, _BSS
) == 0
175 || strcmp (section
->name
, _SBSS
) == 0)
176 section
->flags
|= SEC_ALLOC
;
177 else if (strcmp (section
->name
, _LIB
) == 0)
178 /* An Irix 4 shared libary. */
179 section
->flags
|= SEC_COFF_SHARED_LIBRARY
;
181 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
182 uncertain about .init on some systems and I don't know how shared
188 /* Determine the machine architecture and type. This is called from
189 the generic COFF routines. It is the inverse of ecoff_get_magic,
190 below. This could be an ECOFF backend routine, with one version
191 for each target, but there aren't all that many ECOFF targets. */
194 _bfd_ecoff_set_arch_mach_hook (abfd
, filehdr
)
198 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
199 enum bfd_architecture arch
;
202 switch (internal_f
->f_magic
)
205 case MIPS_MAGIC_LITTLE
:
207 arch
= bfd_arch_mips
;
208 mach
= bfd_mach_mips3000
;
211 case MIPS_MAGIC_LITTLE2
:
212 case MIPS_MAGIC_BIG2
:
213 /* MIPS ISA level 2: the r6000. */
214 arch
= bfd_arch_mips
;
215 mach
= bfd_mach_mips6000
;
218 case MIPS_MAGIC_LITTLE3
:
219 case MIPS_MAGIC_BIG3
:
220 /* MIPS ISA level 3: the r4000. */
221 arch
= bfd_arch_mips
;
222 mach
= bfd_mach_mips4000
;
226 arch
= bfd_arch_alpha
;
231 arch
= bfd_arch_obscure
;
236 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
239 /* Get the magic number to use based on the architecture and machine.
240 This is the inverse of _bfd_ecoff_set_arch_mach_hook, above. */
243 ecoff_get_magic (abfd
)
248 switch (bfd_get_arch (abfd
))
251 switch (bfd_get_mach (abfd
))
255 case bfd_mach_mips3000
:
256 big
= MIPS_MAGIC_BIG
;
257 little
= MIPS_MAGIC_LITTLE
;
260 case bfd_mach_mips6000
:
261 big
= MIPS_MAGIC_BIG2
;
262 little
= MIPS_MAGIC_LITTLE2
;
265 case bfd_mach_mips4000
:
266 big
= MIPS_MAGIC_BIG3
;
267 little
= MIPS_MAGIC_LITTLE3
;
271 return bfd_big_endian (abfd
) ? big
: little
;
282 /* Get the section s_flags to use for a section. */
285 ecoff_sec_to_styp_flags (name
, flags
)
293 if (strcmp (name
, _TEXT
) == 0)
295 else if (strcmp (name
, _DATA
) == 0)
297 else if (strcmp (name
, _SDATA
) == 0)
299 else if (strcmp (name
, _RDATA
) == 0)
301 else if (strcmp (name
, _LITA
) == 0)
303 else if (strcmp (name
, _LIT8
) == 0)
305 else if (strcmp (name
, _LIT4
) == 0)
307 else if (strcmp (name
, _BSS
) == 0)
309 else if (strcmp (name
, _SBSS
) == 0)
311 else if (strcmp (name
, _INIT
) == 0)
312 styp
= STYP_ECOFF_INIT
;
313 else if (strcmp (name
, _FINI
) == 0)
314 styp
= STYP_ECOFF_FINI
;
315 else if (strcmp (name
, _PDATA
) == 0)
317 else if (strcmp (name
, _XDATA
) == 0)
319 else if (strcmp (name
, _LIB
) == 0)
320 styp
= STYP_ECOFF_LIB
;
321 else if (strcmp (name
, _GOT
) == 0)
323 else if (strcmp (name
, _HASH
) == 0)
325 else if (strcmp (name
, _DYNAMIC
) == 0)
327 else if (strcmp (name
, _LIBLIST
) == 0)
329 else if (strcmp (name
, _RELDYN
) == 0)
331 else if (strcmp (name
, _CONFLIC
) == 0)
333 else if (strcmp (name
, _DYNSTR
) == 0)
335 else if (strcmp (name
, _DYNSYM
) == 0)
337 else if (strcmp (name
, _COMMENT
) == 0)
340 flags
&=~ SEC_NEVER_LOAD
;
342 else if (strcmp (name
, _RCONST
) == 0)
344 else if (flags
& SEC_CODE
)
346 else if (flags
& SEC_DATA
)
348 else if (flags
& SEC_READONLY
)
350 else if (flags
& SEC_LOAD
)
355 if (flags
& SEC_NEVER_LOAD
)
361 /* Get the BFD flags to use for a section. */
364 _bfd_ecoff_styp_to_sec_flags (abfd
, hdr
, name
, section
, flags_ptr
)
365 bfd
*abfd ATTRIBUTE_UNUSED
;
367 const char *name ATTRIBUTE_UNUSED
;
368 asection
*section ATTRIBUTE_UNUSED
;
369 flagword
* flags_ptr
;
371 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
372 long styp_flags
= internal_s
->s_flags
;
373 flagword sec_flags
= 0;
375 if (styp_flags
& STYP_NOLOAD
)
376 sec_flags
|= SEC_NEVER_LOAD
;
378 /* For 386 COFF, at least, an unloadable text or data section is
379 actually a shared library section. */
380 if ((styp_flags
& STYP_TEXT
)
381 || (styp_flags
& STYP_ECOFF_INIT
)
382 || (styp_flags
& STYP_ECOFF_FINI
)
383 || (styp_flags
& STYP_DYNAMIC
)
384 || (styp_flags
& STYP_LIBLIST
)
385 || (styp_flags
& STYP_RELDYN
)
386 || styp_flags
== STYP_CONFLIC
387 || (styp_flags
& STYP_DYNSTR
)
388 || (styp_flags
& STYP_DYNSYM
)
389 || (styp_flags
& STYP_HASH
))
391 if (sec_flags
& SEC_NEVER_LOAD
)
392 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
394 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
396 else if ((styp_flags
& STYP_DATA
)
397 || (styp_flags
& STYP_RDATA
)
398 || (styp_flags
& STYP_SDATA
)
399 || styp_flags
== STYP_PDATA
400 || styp_flags
== STYP_XDATA
401 || (styp_flags
& STYP_GOT
)
402 || styp_flags
== STYP_RCONST
)
404 if (sec_flags
& SEC_NEVER_LOAD
)
405 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
407 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
408 if ((styp_flags
& STYP_RDATA
)
409 || styp_flags
== STYP_PDATA
410 || styp_flags
== STYP_RCONST
)
411 sec_flags
|= SEC_READONLY
;
413 else if ((styp_flags
& STYP_BSS
)
414 || (styp_flags
& STYP_SBSS
))
415 sec_flags
|= SEC_ALLOC
;
416 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
417 sec_flags
|= SEC_NEVER_LOAD
;
418 else if ((styp_flags
& STYP_LITA
)
419 || (styp_flags
& STYP_LIT8
)
420 || (styp_flags
& STYP_LIT4
))
421 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
422 else if (styp_flags
& STYP_ECOFF_LIB
)
423 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
425 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
427 * flags_ptr
= sec_flags
;
431 /* Read in the symbolic header for an ECOFF object file. */
434 ecoff_slurp_symbolic_header (abfd
)
437 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
438 bfd_size_type external_hdr_size
;
440 HDRR
*internal_symhdr
;
442 /* See if we've already read it in. */
443 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
444 backend
->debug_swap
.sym_magic
)
447 /* See whether there is a symbolic header. */
448 if (ecoff_data (abfd
)->sym_filepos
== 0)
450 bfd_get_symcount (abfd
) = 0;
454 /* At this point bfd_get_symcount (abfd) holds the number of symbols
455 as read from the file header, but on ECOFF this is always the
456 size of the symbolic information header. It would be cleaner to
457 handle this when we first read the file in coffgen.c. */
458 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
459 if (bfd_get_symcount (abfd
) != external_hdr_size
)
461 bfd_set_error (bfd_error_bad_value
);
465 /* Read the symbolic information header. */
466 raw
= (PTR
) bfd_malloc (external_hdr_size
);
470 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) != 0
471 || bfd_bread (raw
, external_hdr_size
, abfd
) != external_hdr_size
)
473 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
474 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
476 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
478 bfd_set_error (bfd_error_bad_value
);
482 /* Now we can get the correct number of symbols. */
483 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
484 + internal_symhdr
->iextMax
);
495 /* Read in and swap the important symbolic information for an ECOFF
496 object file. This is called by gdb via the read_debug_info entry
497 point in the backend structure. */
500 _bfd_ecoff_slurp_symbolic_info (abfd
, ignore
, debug
)
502 asection
*ignore ATTRIBUTE_UNUSED
;
503 struct ecoff_debug_info
*debug
;
505 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
506 HDRR
*internal_symhdr
;
507 bfd_size_type raw_base
;
508 bfd_size_type raw_size
;
510 bfd_size_type external_fdr_size
;
514 bfd_size_type raw_end
;
515 bfd_size_type cb_end
;
519 BFD_ASSERT (debug
== &ecoff_data (abfd
)->debug_info
);
521 /* Check whether we've already gotten it, and whether there's any to
523 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
525 if (ecoff_data (abfd
)->sym_filepos
== 0)
527 bfd_get_symcount (abfd
) = 0;
531 if (! ecoff_slurp_symbolic_header (abfd
))
534 internal_symhdr
= &debug
->symbolic_header
;
536 /* Read all the symbolic information at once. */
537 raw_base
= (ecoff_data (abfd
)->sym_filepos
538 + backend
->debug_swap
.external_hdr_size
);
540 /* Alpha ecoff makes the determination of raw_size difficult. It has
541 an undocumented debug data section between the symhdr and the first
542 documented section. And the ordering of the sections varies between
543 statically and dynamically linked executables.
544 If bfd supports SEEK_END someday, this code could be simplified. */
547 #define UPDATE_RAW_END(start, count, size) \
548 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
549 if (cb_end > raw_end) \
552 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
553 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
554 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
555 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
556 /* eraxxon@alumni.rice.edu: ioptMax refers to the size of the
557 optimization symtab, not the number of entries */
558 UPDATE_RAW_END (cbOptOffset
, ioptMax
, sizeof (char));
559 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
560 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
561 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
562 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
563 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
564 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
566 #undef UPDATE_RAW_END
568 raw_size
= raw_end
- raw_base
;
571 ecoff_data (abfd
)->sym_filepos
= 0;
574 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
578 pos
= ecoff_data (abfd
)->sym_filepos
;
579 pos
+= backend
->debug_swap
.external_hdr_size
;
580 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
581 || bfd_bread (raw
, raw_size
, abfd
) != raw_size
)
583 bfd_release (abfd
, raw
);
587 ecoff_data (abfd
)->raw_syments
= raw
;
589 /* Get pointers for the numeric offsets in the HDRR structure. */
590 #define FIX(off1, off2, type) \
591 if (internal_symhdr->off1 == 0) \
592 debug->off2 = (type) NULL; \
594 debug->off2 = (type) ((char *) raw \
595 + (internal_symhdr->off1 \
598 FIX (cbLineOffset
, line
, unsigned char *);
599 FIX (cbDnOffset
, external_dnr
, PTR
);
600 FIX (cbPdOffset
, external_pdr
, PTR
);
601 FIX (cbSymOffset
, external_sym
, PTR
);
602 FIX (cbOptOffset
, external_opt
, PTR
);
603 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
604 FIX (cbSsOffset
, ss
, char *);
605 FIX (cbSsExtOffset
, ssext
, char *);
606 FIX (cbFdOffset
, external_fdr
, PTR
);
607 FIX (cbRfdOffset
, external_rfd
, PTR
);
608 FIX (cbExtOffset
, external_ext
, PTR
);
611 /* I don't want to always swap all the data, because it will just
612 waste time and most programs will never look at it. The only
613 time the linker needs most of the debugging information swapped
614 is when linking big-endian and little-endian MIPS object files
615 together, which is not a common occurrence.
617 We need to look at the fdr to deal with a lot of information in
618 the symbols, so we swap them here. */
619 amt
= internal_symhdr
->ifdMax
;
620 amt
*= sizeof (struct fdr
);
621 debug
->fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
622 if (debug
->fdr
== NULL
)
624 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
625 fdr_ptr
= debug
->fdr
;
626 fraw_src
= (char *) debug
->external_fdr
;
627 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
628 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
629 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
634 /* ECOFF symbol table routines. The ECOFF symbol table is described
635 in gcc/mips-tfile.c. */
637 /* ECOFF uses two common sections. One is the usual one, and the
638 other is for small objects. All the small objects are kept
639 together, and then referenced via the gp pointer, which yields
640 faster assembler code. This is what we use for the small common
642 static asection ecoff_scom_section
;
643 static asymbol ecoff_scom_symbol
;
644 static asymbol
*ecoff_scom_symbol_ptr
;
646 /* Create an empty symbol. */
649 _bfd_ecoff_make_empty_symbol (abfd
)
652 ecoff_symbol_type
*new;
653 bfd_size_type amt
= sizeof (ecoff_symbol_type
);
655 new = (ecoff_symbol_type
*) bfd_zalloc (abfd
, amt
);
656 if (new == (ecoff_symbol_type
*) NULL
)
657 return (asymbol
*) NULL
;
658 new->symbol
.section
= (asection
*) NULL
;
659 new->fdr
= (FDR
*) NULL
;
662 new->symbol
.the_bfd
= abfd
;
666 /* Set the BFD flags and section for an ECOFF symbol. */
669 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, weak
)
676 asym
->the_bfd
= abfd
;
677 asym
->value
= ecoff_sym
->value
;
678 asym
->section
= &bfd_debug_section
;
681 /* Most symbol types are just for debugging. */
682 switch (ecoff_sym
->st
)
691 if (ECOFF_IS_STAB (ecoff_sym
))
693 asym
->flags
= BSF_DEBUGGING
;
698 asym
->flags
= BSF_DEBUGGING
;
703 asym
->flags
= BSF_EXPORT
| BSF_WEAK
;
705 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
708 asym
->flags
= BSF_LOCAL
;
709 /* Normally, a local stProc symbol will have a corresponding
710 external symbol. We mark the local symbol as a debugging
711 symbol, in order to prevent nm from printing both out.
712 Similarly, we mark stLabel and stabs symbols as debugging
713 symbols. In both cases, we do want to set the value
714 correctly based on the symbol class. */
715 if (ecoff_sym
->st
== stProc
716 || ecoff_sym
->st
== stLabel
717 || ECOFF_IS_STAB (ecoff_sym
))
718 asym
->flags
|= BSF_DEBUGGING
;
721 if (ecoff_sym
->st
== stProc
|| ecoff_sym
->st
== stStaticProc
)
722 asym
->flags
|= BSF_FUNCTION
;
724 switch (ecoff_sym
->sc
)
727 /* Used for compiler generated labels. Leave them in the
728 debugging section, and mark them as local. If BSF_DEBUGGING
729 is set, then nm does not display them for some reason. If no
730 flags are set then the linker whines about them. */
731 asym
->flags
= BSF_LOCAL
;
734 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
735 asym
->value
-= asym
->section
->vma
;
738 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
739 asym
->value
-= asym
->section
->vma
;
742 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
743 asym
->value
-= asym
->section
->vma
;
746 asym
->flags
= BSF_DEBUGGING
;
749 asym
->section
= bfd_abs_section_ptr
;
752 asym
->section
= bfd_und_section_ptr
;
762 asym
->flags
= BSF_DEBUGGING
;
765 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
766 asym
->value
-= asym
->section
->vma
;
769 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
770 asym
->value
-= asym
->section
->vma
;
773 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
774 asym
->value
-= asym
->section
->vma
;
777 asym
->flags
= BSF_DEBUGGING
;
780 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
782 asym
->section
= bfd_com_section_ptr
;
788 if (ecoff_scom_section
.name
== NULL
)
790 /* Initialize the small common section. */
791 ecoff_scom_section
.name
= SCOMMON
;
792 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
793 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
794 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
795 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
796 ecoff_scom_symbol
.name
= SCOMMON
;
797 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
798 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
799 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
801 asym
->section
= &ecoff_scom_section
;
806 asym
->flags
= BSF_DEBUGGING
;
809 asym
->section
= bfd_und_section_ptr
;
814 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
815 asym
->value
-= asym
->section
->vma
;
820 asym
->flags
= BSF_DEBUGGING
;
823 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
824 asym
->value
-= asym
->section
->vma
;
827 asym
->section
= bfd_make_section_old_way (abfd
, ".rconst");
828 asym
->value
-= asym
->section
->vma
;
834 /* Look for special constructors symbols and make relocation entries
835 in a special construction section. These are produced by the
836 -fgnu-linker argument to g++. */
837 if (ECOFF_IS_STAB (ecoff_sym
))
839 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
849 /* This code is no longer needed. It used to be used to
850 make the linker handle set symbols, but they are now
851 handled in the add_symbols routine instead. */
855 arelent_chain
*reloc_chain
;
856 unsigned int bitsize
;
859 /* Get a section with the same name as the symbol (usually
860 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
861 name ___CTOR_LIST (three underscores). We need
862 __CTOR_LIST (two underscores), since ECOFF doesn't use
863 a leading underscore. This should be handled by gcc,
864 but instead we do it here. Actually, this should all
865 be done differently anyhow. */
866 name
= bfd_asymbol_name (asym
);
867 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
872 section
= bfd_get_section_by_name (abfd
, name
);
873 if (section
== (asection
*) NULL
)
877 amt
= strlen (name
) + 1;
878 copy
= (char *) bfd_alloc (abfd
, amt
);
882 section
= bfd_make_section (abfd
, copy
);
885 /* Build a reloc pointing to this constructor. */
886 amt
= sizeof (arelent_chain
);
887 reloc_chain
= (arelent_chain
*) bfd_alloc (abfd
, amt
);
890 reloc_chain
->relent
.sym_ptr_ptr
=
891 bfd_get_section (asym
)->symbol_ptr_ptr
;
892 reloc_chain
->relent
.address
= section
->_raw_size
;
893 reloc_chain
->relent
.addend
= asym
->value
;
894 reloc_chain
->relent
.howto
=
895 ecoff_backend (abfd
)->constructor_reloc
;
897 /* Set up the constructor section to hold the reloc. */
898 section
->flags
= SEC_CONSTRUCTOR
;
899 ++section
->reloc_count
;
901 /* Constructor sections must be rounded to a boundary
902 based on the bitsize. These are not real sections--
903 they are handled specially by the linker--so the ECOFF
904 16 byte alignment restriction does not apply. */
905 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
906 section
->alignment_power
= 1;
907 while ((1 << section
->alignment_power
) < bitsize
/ 8)
908 ++section
->alignment_power
;
910 reloc_chain
->next
= section
->constructor_chain
;
911 section
->constructor_chain
= reloc_chain
;
912 section
->_raw_size
+= bitsize
/ 8;
916 /* Mark the symbol as a constructor. */
917 asym
->flags
|= BSF_CONSTRUCTOR
;
925 /* Read an ECOFF symbol table. */
928 _bfd_ecoff_slurp_symbol_table (abfd
)
931 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
932 const bfd_size_type external_ext_size
933 = backend
->debug_swap
.external_ext_size
;
934 const bfd_size_type external_sym_size
935 = backend
->debug_swap
.external_sym_size
;
936 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
937 = backend
->debug_swap
.swap_ext_in
;
938 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
939 = backend
->debug_swap
.swap_sym_in
;
940 bfd_size_type internal_size
;
941 ecoff_symbol_type
*internal
;
942 ecoff_symbol_type
*internal_ptr
;
948 /* If we've already read in the symbol table, do nothing. */
949 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
952 /* Get the symbolic information. */
953 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
954 &ecoff_data (abfd
)->debug_info
))
956 if (bfd_get_symcount (abfd
) == 0)
959 internal_size
= bfd_get_symcount (abfd
);
960 internal_size
*= sizeof (ecoff_symbol_type
);
961 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
962 if (internal
== NULL
)
965 internal_ptr
= internal
;
966 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
968 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
969 * external_ext_size
));
970 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
974 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
975 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
976 + internal_esym
.asym
.iss
);
977 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
978 &internal_ptr
->symbol
, 1,
979 internal_esym
.weakext
))
981 /* The alpha uses a negative ifd field for section symbols. */
982 if (internal_esym
.ifd
>= 0)
983 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
984 + internal_esym
.ifd
);
986 internal_ptr
->fdr
= NULL
;
987 internal_ptr
->local
= false;
988 internal_ptr
->native
= (PTR
) eraw_src
;
991 /* The local symbols must be accessed via the fdr's, because the
992 string and aux indices are relative to the fdr information. */
993 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
994 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
995 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1000 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1001 + fdr_ptr
->isymBase
* external_sym_size
);
1002 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1004 lraw_src
< lraw_end
;
1005 lraw_src
+= external_sym_size
, internal_ptr
++)
1009 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1010 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1012 + internal_sym
.iss
);
1013 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1014 &internal_ptr
->symbol
, 0, 0))
1016 internal_ptr
->fdr
= fdr_ptr
;
1017 internal_ptr
->local
= true;
1018 internal_ptr
->native
= (PTR
) lraw_src
;
1022 ecoff_data (abfd
)->canonical_symbols
= internal
;
1027 /* Return the amount of space needed for the canonical symbols. */
1030 _bfd_ecoff_get_symtab_upper_bound (abfd
)
1033 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
1034 &ecoff_data (abfd
)->debug_info
))
1037 if (bfd_get_symcount (abfd
) == 0)
1040 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1043 /* Get the canonical symbols. */
1046 _bfd_ecoff_get_symtab (abfd
, alocation
)
1048 asymbol
**alocation
;
1050 unsigned int counter
= 0;
1051 ecoff_symbol_type
*symbase
;
1052 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1054 if (! _bfd_ecoff_slurp_symbol_table (abfd
))
1056 if (bfd_get_symcount (abfd
) == 0)
1059 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1060 while (counter
< bfd_get_symcount (abfd
))
1062 *(location
++) = symbase
++;
1065 *location
++ = (ecoff_symbol_type
*) NULL
;
1066 return bfd_get_symcount (abfd
);
1069 /* Turn ECOFF type information into a printable string.
1070 ecoff_emit_aggregate and ecoff_type_to_string are from
1071 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1073 /* Write aggregate information to a string. */
1076 ecoff_emit_aggregate (abfd
, fdr
, string
, rndx
, isym
, which
)
1084 const struct ecoff_debug_swap
* const debug_swap
=
1085 &ecoff_backend (abfd
)->debug_swap
;
1086 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1087 unsigned int ifd
= rndx
->rfd
;
1088 unsigned int indx
= rndx
->index
;
1094 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1095 struct return type of a procedure compiled without -g. */
1096 if (ifd
== 0xffffffff
1097 || (rndx
->rfd
== 0xfff && indx
== 0))
1098 name
= "<undefined>";
1099 else if (indx
== indexNil
)
1105 if (debug_info
->external_rfd
== NULL
)
1106 fdr
= debug_info
->fdr
+ ifd
;
1111 (*debug_swap
->swap_rfd_in
) (abfd
,
1112 ((char *) debug_info
->external_rfd
1113 + ((fdr
->rfdBase
+ ifd
)
1114 * debug_swap
->external_rfd_size
)),
1116 fdr
= debug_info
->fdr
+ rfd
;
1119 indx
+= fdr
->isymBase
;
1121 (*debug_swap
->swap_sym_in
) (abfd
,
1122 ((char *) debug_info
->external_sym
1123 + indx
* debug_swap
->external_sym_size
),
1126 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1130 "%s %s { ifd = %u, index = %lu }",
1133 + debug_info
->symbolic_header
.iextMax
));
1136 /* Convert the type information to string format. */
1139 ecoff_type_to_string (abfd
, fdr
, indx
)
1144 union aux_ext
*aux_ptr
;
1153 unsigned int basic_type
;
1156 static char buffer2
[1024];
1161 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1162 bigendian
= fdr
->fBigendian
;
1164 for (i
= 0; i
< 7; i
++)
1166 qualifiers
[i
].low_bound
= 0;
1167 qualifiers
[i
].high_bound
= 0;
1168 qualifiers
[i
].stride
= 0;
1171 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == (bfd_vma
) -1)
1172 return "-1 (no type)";
1173 _bfd_ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1175 basic_type
= u
.ti
.bt
;
1176 qualifiers
[0].type
= u
.ti
.tq0
;
1177 qualifiers
[1].type
= u
.ti
.tq1
;
1178 qualifiers
[2].type
= u
.ti
.tq2
;
1179 qualifiers
[3].type
= u
.ti
.tq3
;
1180 qualifiers
[4].type
= u
.ti
.tq4
;
1181 qualifiers
[5].type
= u
.ti
.tq5
;
1182 qualifiers
[6].type
= tqNil
;
1184 /* Go get the basic type. */
1187 case btNil
: /* Undefined. */
1191 case btAdr
: /* Address - integer same size as pointer. */
1192 strcpy (p1
, "address");
1195 case btChar
: /* Character. */
1196 strcpy (p1
, "char");
1199 case btUChar
: /* Unsigned character. */
1200 strcpy (p1
, "unsigned char");
1203 case btShort
: /* Short. */
1204 strcpy (p1
, "short");
1207 case btUShort
: /* Unsigned short. */
1208 strcpy (p1
, "unsigned short");
1211 case btInt
: /* Int. */
1215 case btUInt
: /* Unsigned int. */
1216 strcpy (p1
, "unsigned int");
1219 case btLong
: /* Long. */
1220 strcpy (p1
, "long");
1223 case btULong
: /* Unsigned long. */
1224 strcpy (p1
, "unsigned long");
1227 case btFloat
: /* Float (real). */
1228 strcpy (p1
, "float");
1231 case btDouble
: /* Double (real). */
1232 strcpy (p1
, "double");
1235 /* Structures add 1-2 aux words:
1236 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1237 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1239 case btStruct
: /* Structure (Record). */
1240 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1241 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1242 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1244 indx
++; /* Skip aux words. */
1247 /* Unions add 1-2 aux words:
1248 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1249 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1251 case btUnion
: /* Union. */
1252 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1253 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1254 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1256 indx
++; /* Skip aux words. */
1259 /* Enumerations add 1-2 aux words:
1260 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1261 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1263 case btEnum
: /* Enumeration. */
1264 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1265 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1266 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1268 indx
++; /* Skip aux words. */
1271 case btTypedef
: /* Defined via a typedef, isymRef points. */
1272 strcpy (p1
, "typedef");
1275 case btRange
: /* Subrange of int. */
1276 strcpy (p1
, "subrange");
1279 case btSet
: /* Pascal sets. */
1283 case btComplex
: /* Fortran complex. */
1284 strcpy (p1
, "complex");
1287 case btDComplex
: /* Fortran double complex. */
1288 strcpy (p1
, "double complex");
1291 case btIndirect
: /* Forward or unnamed typedef. */
1292 strcpy (p1
, "forward/unamed typedef");
1295 case btFixedDec
: /* Fixed Decimal. */
1296 strcpy (p1
, "fixed decimal");
1299 case btFloatDec
: /* Float Decimal. */
1300 strcpy (p1
, "float decimal");
1303 case btString
: /* Varying Length Character String. */
1304 strcpy (p1
, "string");
1307 case btBit
: /* Aligned Bit String. */
1311 case btPicture
: /* Picture. */
1312 strcpy (p1
, "picture");
1315 case btVoid
: /* Void. */
1316 strcpy (p1
, "void");
1320 sprintf (p1
, _("Unknown basic type %d"), (int) basic_type
);
1324 p1
+= strlen (buffer1
);
1326 /* If this is a bitfield, get the bitsize. */
1331 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1332 sprintf (p1
, " : %d", bitsize
);
1333 p1
+= strlen (buffer1
);
1336 /* Deal with any qualifiers. */
1337 if (qualifiers
[0].type
!= tqNil
)
1339 /* Snarf up any array bounds in the correct order. Arrays
1340 store 5 successive words in the aux. table:
1341 word 0 RNDXR to type of the bounds (ie, int)
1342 word 1 Current file descriptor index
1344 word 3 high bound (or -1 if [])
1345 word 4 stride size in bits. */
1346 for (i
= 0; i
< 7; i
++)
1348 if (qualifiers
[i
].type
== tqArray
)
1350 qualifiers
[i
].low_bound
=
1351 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1352 qualifiers
[i
].high_bound
=
1353 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1354 qualifiers
[i
].stride
=
1355 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1360 /* Now print out the qualifiers. */
1361 for (i
= 0; i
< 6; i
++)
1363 switch (qualifiers
[i
].type
)
1370 strcpy (p2
, "ptr to ");
1371 p2
+= sizeof ("ptr to ")-1;
1375 strcpy (p2
, "volatile ");
1376 p2
+= sizeof ("volatile ")-1;
1380 strcpy (p2
, "far ");
1381 p2
+= sizeof ("far ")-1;
1385 strcpy (p2
, "func. ret. ");
1386 p2
+= sizeof ("func. ret. ");
1391 int first_array
= i
;
1394 /* Print array bounds reversed (ie, in the order the C
1395 programmer writes them). C is such a fun language.... */
1396 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1399 for (j
= i
; j
>= first_array
; j
--)
1401 strcpy (p2
, "array [");
1402 p2
+= sizeof ("array [")-1;
1403 if (qualifiers
[j
].low_bound
!= 0)
1405 "%ld:%ld {%ld bits}",
1406 (long) qualifiers
[j
].low_bound
,
1407 (long) qualifiers
[j
].high_bound
,
1408 (long) qualifiers
[j
].stride
);
1410 else if (qualifiers
[j
].high_bound
!= -1)
1413 (long) (qualifiers
[j
].high_bound
+ 1),
1414 (long) (qualifiers
[j
].stride
));
1417 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1420 strcpy (p2
, "] of ");
1421 p2
+= sizeof ("] of ")-1;
1429 strcpy (p2
, buffer1
);
1433 /* Return information about ECOFF symbol SYMBOL in RET. */
1436 _bfd_ecoff_get_symbol_info (abfd
, symbol
, ret
)
1437 bfd
*abfd ATTRIBUTE_UNUSED
;
1441 bfd_symbol_info (symbol
, ret
);
1444 /* Return whether this is a local label. */
1447 _bfd_ecoff_bfd_is_local_label_name (abfd
, name
)
1448 bfd
*abfd ATTRIBUTE_UNUSED
;
1451 return name
[0] == '$';
1454 /* Print information about an ECOFF symbol. */
1457 _bfd_ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1461 bfd_print_symbol_type how
;
1463 const struct ecoff_debug_swap
* const debug_swap
1464 = &ecoff_backend (abfd
)->debug_swap
;
1465 FILE *file
= (FILE *)filep
;
1469 case bfd_print_symbol_name
:
1470 fprintf (file
, "%s", symbol
->name
);
1472 case bfd_print_symbol_more
:
1473 if (ecoffsymbol (symbol
)->local
)
1477 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1479 fprintf (file
, "ecoff local ");
1480 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1481 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1482 (unsigned) ecoff_sym
.sc
);
1488 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1490 fprintf (file
, "ecoff extern ");
1491 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1492 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1493 (unsigned) ecoff_ext
.asym
.sc
);
1496 case bfd_print_symbol_all
:
1497 /* Print out the symbols in a reasonable way. */
1506 if (ecoffsymbol (symbol
)->local
)
1508 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1511 pos
= ((((char *) ecoffsymbol (symbol
)->native
1512 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1513 / debug_swap
->external_sym_size
)
1514 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1521 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1524 pos
= (((char *) ecoffsymbol (symbol
)->native
1525 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1526 / debug_swap
->external_ext_size
);
1527 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1528 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1529 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1532 fprintf (file
, "[%3d] %c ",
1534 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1535 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1536 (unsigned) ecoff_ext
.asym
.st
,
1537 (unsigned) ecoff_ext
.asym
.sc
,
1538 (unsigned) ecoff_ext
.asym
.index
,
1539 jmptbl
, cobol_main
, weakext
,
1542 if (ecoffsymbol (symbol
)->fdr
!= NULL
1543 && ecoff_ext
.asym
.index
!= indexNil
)
1548 bfd_size_type sym_base
;
1549 union aux_ext
*aux_base
;
1551 fdr
= ecoffsymbol (symbol
)->fdr
;
1552 indx
= ecoff_ext
.asym
.index
;
1554 /* sym_base is used to map the fdr relative indices which
1555 appear in the file to the position number which we are
1557 sym_base
= fdr
->isymBase
;
1558 if (ecoffsymbol (symbol
)->local
)
1560 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1562 /* aux_base is the start of the aux entries for this file;
1563 asym.index is an offset from this. */
1564 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1567 /* The aux entries are stored in host byte order; the
1568 order is indicated by a bit in the fdr. */
1569 bigendian
= fdr
->fBigendian
;
1571 /* This switch is basically from gcc/mips-tdump.c. */
1572 switch (ecoff_ext
.asym
.st
)
1580 fprintf (file
, _("\n End+1 symbol: %ld"),
1581 (long) (indx
+ sym_base
));
1585 if (ecoff_ext
.asym
.sc
== scText
1586 || ecoff_ext
.asym
.sc
== scInfo
)
1587 fprintf (file
, _("\n First symbol: %ld"),
1588 (long) (indx
+ sym_base
));
1590 fprintf (file
, _("\n First symbol: %ld"),
1592 (AUX_GET_ISYM (bigendian
,
1593 &aux_base
[ecoff_ext
.asym
.index
])
1599 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1601 else if (ecoffsymbol (symbol
)->local
)
1602 fprintf (file
, _("\n End+1 symbol: %-7ld Type: %s"),
1604 (AUX_GET_ISYM (bigendian
,
1605 &aux_base
[ecoff_ext
.asym
.index
])
1607 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1609 fprintf (file
, _("\n Local symbol: %ld"),
1612 + (ecoff_data (abfd
)
1613 ->debug_info
.symbolic_header
.iextMax
)));
1617 fprintf (file
, _("\n struct; End+1 symbol: %ld"),
1618 (long) (indx
+ sym_base
));
1622 fprintf (file
, _("\n union; End+1 symbol: %ld"),
1623 (long) (indx
+ sym_base
));
1627 fprintf (file
, _("\n enum; End+1 symbol: %ld"),
1628 (long) (indx
+ sym_base
));
1632 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1633 fprintf (file
, _("\n Type: %s"),
1634 ecoff_type_to_string (abfd
, fdr
, indx
));
1643 /* Read in the relocs for a section. */
1646 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1651 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1652 arelent
*internal_relocs
;
1653 bfd_size_type external_reloc_size
;
1655 char *external_relocs
;
1659 if (section
->relocation
!= (arelent
*) NULL
1660 || section
->reloc_count
== 0
1661 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1664 if (! _bfd_ecoff_slurp_symbol_table (abfd
))
1667 amt
= section
->reloc_count
;
1668 amt
*= sizeof (arelent
);
1669 internal_relocs
= (arelent
*) bfd_alloc (abfd
, amt
);
1671 external_reloc_size
= backend
->external_reloc_size
;
1672 amt
= external_reloc_size
* section
->reloc_count
;
1673 external_relocs
= (char *) bfd_alloc (abfd
, amt
);
1674 if (internal_relocs
== (arelent
*) NULL
1675 || external_relocs
== (char *) NULL
)
1677 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1679 if (bfd_bread (external_relocs
, amt
, abfd
) != amt
)
1682 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1684 struct internal_reloc intern
;
1686 (*backend
->swap_reloc_in
) (abfd
,
1687 external_relocs
+ i
* external_reloc_size
,
1690 if (intern
.r_extern
)
1692 /* r_symndx is an index into the external symbols. */
1693 BFD_ASSERT (intern
.r_symndx
>= 0
1695 < (ecoff_data (abfd
)
1696 ->debug_info
.symbolic_header
.iextMax
)));
1697 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1700 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1701 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1703 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
1708 const char *sec_name
;
1711 /* r_symndx is a section key. */
1712 switch (intern
.r_symndx
)
1714 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1715 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1716 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1717 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1718 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1719 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1720 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1721 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1722 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1723 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1724 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1725 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1726 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1727 case RELOC_SECTION_RCONST
: sec_name
= ".rconst"; break;
1731 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1732 if (sec
== (asection
*) NULL
)
1734 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1736 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1739 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1741 /* Let the backend select the howto field and do any other
1742 required processing. */
1743 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1746 bfd_release (abfd
, external_relocs
);
1748 section
->relocation
= internal_relocs
;
1753 /* Get a canonical list of relocs. */
1756 _bfd_ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1764 if (section
->flags
& SEC_CONSTRUCTOR
)
1766 arelent_chain
*chain
;
1768 /* This section has relocs made up by us, not the file, so take
1769 them out of their chain and place them into the data area
1771 for (count
= 0, chain
= section
->constructor_chain
;
1772 count
< section
->reloc_count
;
1773 count
++, chain
= chain
->next
)
1774 *relptr
++ = &chain
->relent
;
1780 if (! ecoff_slurp_reloc_table (abfd
, section
, symbols
))
1783 tblptr
= section
->relocation
;
1785 for (count
= 0; count
< section
->reloc_count
; count
++)
1786 *relptr
++ = tblptr
++;
1789 *relptr
= (arelent
*) NULL
;
1791 return section
->reloc_count
;
1794 /* Provided a BFD, a section and an offset into the section, calculate
1795 and return the name of the source file and the line nearest to the
1799 _bfd_ecoff_find_nearest_line (abfd
, section
, ignore_symbols
, offset
,
1800 filename_ptr
, functionname_ptr
, retline_ptr
)
1803 asymbol
**ignore_symbols ATTRIBUTE_UNUSED
;
1805 const char **filename_ptr
;
1806 const char **functionname_ptr
;
1807 unsigned int *retline_ptr
;
1809 const struct ecoff_debug_swap
* const debug_swap
1810 = &ecoff_backend (abfd
)->debug_swap
;
1811 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1812 struct ecoff_find_line
*line_info
;
1814 /* Make sure we have the FDR's. */
1815 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
, debug_info
)
1816 || bfd_get_symcount (abfd
) == 0)
1819 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1821 bfd_size_type amt
= sizeof (struct ecoff_find_line
);
1822 ecoff_data (abfd
)->find_line_info
1823 = (struct ecoff_find_line
*) bfd_zalloc (abfd
, amt
);
1824 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1827 line_info
= ecoff_data (abfd
)->find_line_info
;
1829 return _bfd_ecoff_locate_line (abfd
, section
, offset
, debug_info
,
1830 debug_swap
, line_info
, filename_ptr
,
1831 functionname_ptr
, retline_ptr
);
1834 /* Copy private BFD data. This is called by objcopy and strip. We
1835 use it to copy the ECOFF debugging information from one BFD to the
1836 other. It would be theoretically possible to represent the ECOFF
1837 debugging information in the symbol table. However, it would be a
1838 lot of work, and there would be little gain (gas, gdb, and ld
1839 already access the ECOFF debugging information via the
1840 ecoff_debug_info structure, and that structure would have to be
1841 retained in order to support ECOFF debugging in MIPS ELF).
1843 The debugging information for the ECOFF external symbols comes from
1844 the symbol table, so this function only handles the other debugging
1848 _bfd_ecoff_bfd_copy_private_bfd_data (ibfd
, obfd
)
1852 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
1853 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
1855 asymbol
**sym_ptr_ptr
;
1859 /* We only want to copy information over if both BFD's use ECOFF
1861 if (bfd_get_flavour (ibfd
) != bfd_target_ecoff_flavour
1862 || bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
1865 /* Copy the GP value and the register masks. */
1866 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
1867 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
1868 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
1869 for (i
= 0; i
< 3; i
++)
1870 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
1872 /* Copy the version stamp. */
1873 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
1875 /* If there are no symbols, don't copy any debugging information. */
1876 c
= bfd_get_symcount (obfd
);
1877 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1878 if (c
== 0 || sym_ptr_ptr
== (asymbol
**) NULL
)
1881 /* See if there are any local symbols. */
1883 for (; c
> 0; c
--, sym_ptr_ptr
++)
1885 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
1894 /* There are some local symbols. We just bring over all the
1895 debugging information. FIXME: This is not quite the right
1896 thing to do. If the user has asked us to discard all
1897 debugging information, then we are probably going to wind up
1898 keeping it because there will probably be some local symbol
1899 which objcopy did not discard. We should actually break
1900 apart the debugging information and only keep that which
1901 applies to the symbols we want to keep. */
1902 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
1903 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
1904 oinfo
->line
= iinfo
->line
;
1906 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
1907 oinfo
->external_dnr
= iinfo
->external_dnr
;
1909 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
1910 oinfo
->external_pdr
= iinfo
->external_pdr
;
1912 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
1913 oinfo
->external_sym
= iinfo
->external_sym
;
1915 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
1916 oinfo
->external_opt
= iinfo
->external_opt
;
1918 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
1919 oinfo
->external_aux
= iinfo
->external_aux
;
1921 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
1922 oinfo
->ss
= iinfo
->ss
;
1924 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
1925 oinfo
->external_fdr
= iinfo
->external_fdr
;
1927 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
1928 oinfo
->external_rfd
= iinfo
->external_rfd
;
1932 /* We are discarding all the local symbol information. Look
1933 through the external symbols and remove all references to FDR
1934 or aux information. */
1935 c
= bfd_get_symcount (obfd
);
1936 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1937 for (; c
> 0; c
--, sym_ptr_ptr
++)
1941 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
1942 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
1944 esym
.asym
.index
= indexNil
;
1945 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
1946 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
1953 /* Set the architecture. The supported architecture is stored in the
1954 backend pointer. We always set the architecture anyhow, since many
1955 callers ignore the return value. */
1958 _bfd_ecoff_set_arch_mach (abfd
, arch
, machine
)
1960 enum bfd_architecture arch
;
1961 unsigned long machine
;
1963 bfd_default_set_arch_mach (abfd
, arch
, machine
);
1964 return arch
== ecoff_backend (abfd
)->arch
;
1967 /* Get the size of the section headers. */
1970 _bfd_ecoff_sizeof_headers (abfd
, reloc
)
1972 boolean reloc ATTRIBUTE_UNUSED
;
1979 for (current
= abfd
->sections
;
1980 current
!= (asection
*)NULL
;
1981 current
= current
->next
)
1984 ret
= (bfd_coff_filhsz (abfd
)
1985 + bfd_coff_aoutsz (abfd
)
1986 + c
* bfd_coff_scnhsz (abfd
));
1987 return BFD_ALIGN (ret
, 16);
1990 /* Get the contents of a section. */
1993 _bfd_ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
1998 bfd_size_type count
;
2000 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2004 /* Sort sections by VMA, but put SEC_ALLOC sections first. This is
2005 called via qsort. */
2008 ecoff_sort_hdrs (arg1
, arg2
)
2012 const asection
*hdr1
= *(const asection
**) arg1
;
2013 const asection
*hdr2
= *(const asection
**) arg2
;
2015 if ((hdr1
->flags
& SEC_ALLOC
) != 0)
2017 if ((hdr2
->flags
& SEC_ALLOC
) == 0)
2022 if ((hdr2
->flags
& SEC_ALLOC
) != 0)
2025 if (hdr1
->vma
< hdr2
->vma
)
2027 else if (hdr1
->vma
> hdr2
->vma
)
2033 /* Calculate the file position for each section, and set
2037 ecoff_compute_section_file_positions (abfd
)
2040 file_ptr sofar
, file_sofar
;
2041 asection
**sorted_hdrs
;
2045 boolean rdata_in_text
;
2046 boolean first_data
, first_nonalloc
;
2047 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2050 sofar
= _bfd_ecoff_sizeof_headers (abfd
, false);
2053 /* Sort the sections by VMA. */
2054 amt
= abfd
->section_count
;
2055 amt
*= sizeof (asection
*);
2056 sorted_hdrs
= (asection
**) bfd_malloc (amt
);
2057 if (sorted_hdrs
== NULL
)
2059 for (current
= abfd
->sections
, i
= 0;
2061 current
= current
->next
, i
++)
2062 sorted_hdrs
[i
] = current
;
2063 BFD_ASSERT (i
== abfd
->section_count
);
2065 qsort (sorted_hdrs
, abfd
->section_count
, sizeof (asection
*),
2068 /* Some versions of the OSF linker put the .rdata section in the
2069 text segment, and some do not. */
2070 rdata_in_text
= ecoff_backend (abfd
)->rdata_in_text
;
2073 for (i
= 0; i
< abfd
->section_count
; i
++)
2075 current
= sorted_hdrs
[i
];
2076 if (strcmp (current
->name
, _RDATA
) == 0)
2078 if ((current
->flags
& SEC_CODE
) == 0
2079 && strcmp (current
->name
, _PDATA
) != 0
2080 && strcmp (current
->name
, _RCONST
) != 0)
2082 rdata_in_text
= false;
2087 ecoff_data (abfd
)->rdata_in_text
= rdata_in_text
;
2090 first_nonalloc
= true;
2091 for (i
= 0; i
< abfd
->section_count
; i
++)
2093 unsigned int alignment_power
;
2095 current
= sorted_hdrs
[i
];
2097 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2098 supposed to indicate the number of .pdata entries that are
2099 really in the section. Each entry is 8 bytes. We store this
2100 away in line_filepos before increasing the section size. */
2101 if (strcmp (current
->name
, _PDATA
) == 0)
2102 current
->line_filepos
= current
->_raw_size
/ 8;
2104 alignment_power
= current
->alignment_power
;
2106 /* On Ultrix, the data sections in an executable file must be
2107 aligned to a page boundary within the file. This does not
2108 affect the section size, though. FIXME: Does this work for
2109 other platforms? It requires some modification for the
2110 Alpha, because .rdata on the Alpha goes with the text, not
2112 if ((abfd
->flags
& EXEC_P
) != 0
2113 && (abfd
->flags
& D_PAGED
) != 0
2115 && (current
->flags
& SEC_CODE
) == 0
2117 || strcmp (current
->name
, _RDATA
) != 0)
2118 && strcmp (current
->name
, _PDATA
) != 0
2119 && strcmp (current
->name
, _RCONST
) != 0)
2121 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2122 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2125 else if (strcmp (current
->name
, _LIB
) == 0)
2127 /* On Irix 4, the location of contents of the .lib section
2128 from a shared library section is also rounded up to a
2131 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2132 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2134 else if (first_nonalloc
2135 && (current
->flags
& SEC_ALLOC
) == 0
2136 && (abfd
->flags
& D_PAGED
) != 0)
2138 /* Skip up to the next page for an unallocated section, such
2139 as the .comment section on the Alpha. This leaves room
2140 for the .bss section. */
2141 first_nonalloc
= false;
2142 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2143 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2146 /* Align the sections in the file to the same boundary on
2147 which they are aligned in virtual memory. */
2148 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2149 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2150 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2152 if ((abfd
->flags
& D_PAGED
) != 0
2153 && (current
->flags
& SEC_ALLOC
) != 0)
2155 sofar
+= (current
->vma
- sofar
) % round
;
2156 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2157 file_sofar
+= (current
->vma
- file_sofar
) % round
;
2160 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) != 0)
2161 current
->filepos
= file_sofar
;
2163 sofar
+= current
->_raw_size
;
2164 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2165 file_sofar
+= current
->_raw_size
;
2167 /* Make sure that this section is of the right size too. */
2169 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2170 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2171 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2172 current
->_raw_size
+= sofar
- old_sofar
;
2178 ecoff_data (abfd
)->reloc_filepos
= file_sofar
;
2183 /* Determine the location of the relocs for all the sections in the
2184 output file, as well as the location of the symbolic debugging
2187 static bfd_size_type
2188 ecoff_compute_reloc_file_positions (abfd
)
2191 const bfd_size_type external_reloc_size
=
2192 ecoff_backend (abfd
)->external_reloc_size
;
2193 file_ptr reloc_base
;
2194 bfd_size_type reloc_size
;
2198 if (! abfd
->output_has_begun
)
2200 if (! ecoff_compute_section_file_positions (abfd
))
2202 abfd
->output_has_begun
= true;
2205 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2208 for (current
= abfd
->sections
;
2209 current
!= (asection
*)NULL
;
2210 current
= current
->next
)
2212 if (current
->reloc_count
== 0)
2213 current
->rel_filepos
= 0;
2216 bfd_size_type relsize
;
2218 current
->rel_filepos
= reloc_base
;
2219 relsize
= current
->reloc_count
* external_reloc_size
;
2220 reloc_size
+= relsize
;
2221 reloc_base
+= relsize
;
2225 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2227 /* At least on Ultrix, the symbol table of an executable file must
2228 be aligned to a page boundary. FIXME: Is this true on other
2230 if ((abfd
->flags
& EXEC_P
) != 0
2231 && (abfd
->flags
& D_PAGED
) != 0)
2232 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2233 &~ (ecoff_backend (abfd
)->round
- 1));
2235 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2240 /* Set the contents of a section. */
2243 _bfd_ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2248 bfd_size_type count
;
2252 /* This must be done first, because bfd_set_section_contents is
2253 going to set output_has_begun to true. */
2254 if (! abfd
->output_has_begun
)
2256 if (! ecoff_compute_section_file_positions (abfd
))
2260 /* Handle the .lib section specially so that Irix 4 shared libraries
2261 work out. See coff_set_section_contents in coffcode.h. */
2262 if (strcmp (section
->name
, _LIB
) == 0)
2264 bfd_byte
*rec
, *recend
;
2266 rec
= (bfd_byte
*) location
;
2267 recend
= rec
+ count
;
2268 while (rec
< recend
)
2271 rec
+= bfd_get_32 (abfd
, rec
) * 4;
2274 BFD_ASSERT (rec
== recend
);
2280 pos
= section
->filepos
+ offset
;
2281 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
2282 || bfd_bwrite (location
, count
, abfd
) != count
)
2288 /* Get the GP value for an ECOFF file. This is a hook used by
2292 bfd_ecoff_get_gp_value (abfd
)
2295 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2296 || bfd_get_format (abfd
) != bfd_object
)
2298 bfd_set_error (bfd_error_invalid_operation
);
2302 return ecoff_data (abfd
)->gp
;
2305 /* Set the GP value for an ECOFF file. This is a hook used by the
2309 bfd_ecoff_set_gp_value (abfd
, gp_value
)
2313 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2314 || bfd_get_format (abfd
) != bfd_object
)
2316 bfd_set_error (bfd_error_invalid_operation
);
2320 ecoff_data (abfd
)->gp
= gp_value
;
2325 /* Set the register masks for an ECOFF file. This is a hook used by
2329 bfd_ecoff_set_regmasks (abfd
, gprmask
, fprmask
, cprmask
)
2331 unsigned long gprmask
;
2332 unsigned long fprmask
;
2333 unsigned long *cprmask
;
2335 ecoff_data_type
*tdata
;
2337 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2338 || bfd_get_format (abfd
) != bfd_object
)
2340 bfd_set_error (bfd_error_invalid_operation
);
2344 tdata
= ecoff_data (abfd
);
2345 tdata
->gprmask
= gprmask
;
2346 tdata
->fprmask
= fprmask
;
2347 if (cprmask
!= (unsigned long *) NULL
)
2351 for (i
= 0; i
< 3; i
++)
2352 tdata
->cprmask
[i
] = cprmask
[i
];
2358 /* Get ECOFF EXTR information for an external symbol. This function
2359 is passed to bfd_ecoff_debug_externals. */
2362 ecoff_get_extr (sym
, esym
)
2366 ecoff_symbol_type
*ecoff_sym_ptr
;
2369 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2370 || ecoffsymbol (sym
)->native
== NULL
)
2372 /* Don't include debugging, local, or section symbols. */
2373 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2374 || (sym
->flags
& BSF_LOCAL
) != 0
2375 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2379 esym
->cobol_main
= 0;
2380 esym
->weakext
= (sym
->flags
& BSF_WEAK
) != 0;
2383 /* FIXME: we can do better than this for st and sc. */
2384 esym
->asym
.st
= stGlobal
;
2385 esym
->asym
.sc
= scAbs
;
2386 esym
->asym
.reserved
= 0;
2387 esym
->asym
.index
= indexNil
;
2391 ecoff_sym_ptr
= ecoffsymbol (sym
);
2393 if (ecoff_sym_ptr
->local
)
2396 input_bfd
= bfd_asymbol_bfd (sym
);
2397 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2398 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2400 /* If the symbol was defined by the linker, then esym will be
2401 undefined but sym will not be. Get a better class for such a
2403 if ((esym
->asym
.sc
== scUndefined
2404 || esym
->asym
.sc
== scSUndefined
)
2405 && ! bfd_is_und_section (bfd_get_section (sym
)))
2406 esym
->asym
.sc
= scAbs
;
2408 /* Adjust the FDR index for the symbol by that used for the input
2410 if (esym
->ifd
!= -1)
2412 struct ecoff_debug_info
*input_debug
;
2414 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2415 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2416 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2417 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2423 /* Set the external symbol index. This routine is passed to
2424 bfd_ecoff_debug_externals. */
2427 ecoff_set_index (sym
, indx
)
2431 ecoff_set_sym_index (sym
, indx
);
2434 /* Write out an ECOFF file. */
2437 _bfd_ecoff_write_object_contents (abfd
)
2440 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2441 const bfd_vma round
= backend
->round
;
2442 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2443 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2444 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2445 const bfd_size_type external_hdr_size
2446 = backend
->debug_swap
.external_hdr_size
;
2447 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2448 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2450 struct internal_reloc
*))
2451 = backend
->adjust_reloc_out
;
2452 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2453 const struct internal_reloc
*,
2455 = backend
->swap_reloc_out
;
2456 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2457 HDRR
* const symhdr
= &debug
->symbolic_header
;
2460 bfd_size_type reloc_size
;
2461 bfd_size_type text_size
;
2463 boolean set_text_start
;
2464 bfd_size_type data_size
;
2466 boolean set_data_start
;
2467 bfd_size_type bss_size
;
2469 PTR reloc_buff
= NULL
;
2470 struct internal_filehdr internal_f
;
2471 struct internal_aouthdr internal_a
;
2474 /* Determine where the sections and relocs will go in the output
2476 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2479 for (current
= abfd
->sections
;
2480 current
!= (asection
*)NULL
;
2481 current
= current
->next
)
2483 current
->target_index
= count
;
2487 if ((abfd
->flags
& D_PAGED
) != 0)
2488 text_size
= _bfd_ecoff_sizeof_headers (abfd
, false);
2492 set_text_start
= false;
2495 set_data_start
= false;
2498 /* Write section headers to the file. */
2500 /* Allocate buff big enough to hold a section header,
2501 file header, or a.out header. */
2509 buff
= (PTR
) bfd_malloc (siz
);
2514 internal_f
.f_nscns
= 0;
2515 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2517 for (current
= abfd
->sections
;
2518 current
!= (asection
*) NULL
;
2519 current
= current
->next
)
2521 struct internal_scnhdr section
;
2524 ++internal_f
.f_nscns
;
2526 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2528 /* This seems to be correct for Irix 4 shared libraries. */
2529 vma
= bfd_get_section_vma (abfd
, current
);
2530 if (strcmp (current
->name
, _LIB
) == 0)
2531 section
.s_vaddr
= 0;
2533 section
.s_vaddr
= vma
;
2535 section
.s_paddr
= current
->lma
;
2536 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2538 /* If this section is unloadable then the scnptr will be 0. */
2539 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2540 section
.s_scnptr
= 0;
2542 section
.s_scnptr
= current
->filepos
;
2543 section
.s_relptr
= current
->rel_filepos
;
2545 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2546 object file produced by the assembler is supposed to point to
2547 information about how much room is required by objects of
2548 various different sizes. I think this only matters if we
2549 want the linker to compute the best size to use, or
2550 something. I don't know what happens if the information is
2552 if (strcmp (current
->name
, _PDATA
) != 0)
2553 section
.s_lnnoptr
= 0;
2556 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2557 hold the number of entries in the section (each entry is
2558 8 bytes). We stored this in the line_filepos field in
2559 ecoff_compute_section_file_positions. */
2560 section
.s_lnnoptr
= current
->line_filepos
;
2563 section
.s_nreloc
= current
->reloc_count
;
2564 section
.s_nlnno
= 0;
2565 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2568 if (bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
) == 0
2569 || bfd_bwrite (buff
, scnhsz
, abfd
) != scnhsz
)
2572 if ((section
.s_flags
& STYP_TEXT
) != 0
2573 || ((section
.s_flags
& STYP_RDATA
) != 0
2574 && ecoff_data (abfd
)->rdata_in_text
)
2575 || section
.s_flags
== STYP_PDATA
2576 || (section
.s_flags
& STYP_DYNAMIC
) != 0
2577 || (section
.s_flags
& STYP_LIBLIST
) != 0
2578 || (section
.s_flags
& STYP_RELDYN
) != 0
2579 || section
.s_flags
== STYP_CONFLIC
2580 || (section
.s_flags
& STYP_DYNSTR
) != 0
2581 || (section
.s_flags
& STYP_DYNSYM
) != 0
2582 || (section
.s_flags
& STYP_HASH
) != 0
2583 || (section
.s_flags
& STYP_ECOFF_INIT
) != 0
2584 || (section
.s_flags
& STYP_ECOFF_FINI
) != 0
2585 || section
.s_flags
== STYP_RCONST
)
2587 text_size
+= bfd_get_section_size_before_reloc (current
);
2588 if (! set_text_start
|| text_start
> vma
)
2591 set_text_start
= true;
2594 else if ((section
.s_flags
& STYP_RDATA
) != 0
2595 || (section
.s_flags
& STYP_DATA
) != 0
2596 || (section
.s_flags
& STYP_LITA
) != 0
2597 || (section
.s_flags
& STYP_LIT8
) != 0
2598 || (section
.s_flags
& STYP_LIT4
) != 0
2599 || (section
.s_flags
& STYP_SDATA
) != 0
2600 || section
.s_flags
== STYP_XDATA
2601 || (section
.s_flags
& STYP_GOT
) != 0)
2603 data_size
+= bfd_get_section_size_before_reloc (current
);
2604 if (! set_data_start
|| data_start
> vma
)
2607 set_data_start
= true;
2610 else if ((section
.s_flags
& STYP_BSS
) != 0
2611 || (section
.s_flags
& STYP_SBSS
) != 0)
2612 bss_size
+= bfd_get_section_size_before_reloc (current
);
2613 else if (section
.s_flags
== 0
2614 || (section
.s_flags
& STYP_ECOFF_LIB
) != 0
2615 || section
.s_flags
== STYP_COMMENT
)
2621 /* Set up the file header. */
2622 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2624 /* We will NOT put a fucking timestamp in the header here. Every
2625 time you put it back, I will come in and take it out again. I'm
2626 sorry. This field does not belong here. We fill it with a 0 so
2627 it compares the same but is not a reasonable time. --
2629 internal_f
.f_timdat
= 0;
2631 if (bfd_get_symcount (abfd
) != 0)
2633 /* The ECOFF f_nsyms field is not actually the number of
2634 symbols, it's the size of symbolic information header. */
2635 internal_f
.f_nsyms
= external_hdr_size
;
2636 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2640 internal_f
.f_nsyms
= 0;
2641 internal_f
.f_symptr
= 0;
2644 internal_f
.f_opthdr
= aoutsz
;
2646 internal_f
.f_flags
= F_LNNO
;
2647 if (reloc_size
== 0)
2648 internal_f
.f_flags
|= F_RELFLG
;
2649 if (bfd_get_symcount (abfd
) == 0)
2650 internal_f
.f_flags
|= F_LSYMS
;
2651 if (abfd
->flags
& EXEC_P
)
2652 internal_f
.f_flags
|= F_EXEC
;
2654 if (bfd_little_endian (abfd
))
2655 internal_f
.f_flags
|= F_AR32WR
;
2657 internal_f
.f_flags
|= F_AR32W
;
2659 /* Set up the ``optional'' header. */
2660 if ((abfd
->flags
& D_PAGED
) != 0)
2661 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2663 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2665 /* FIXME: Is this really correct? */
2666 internal_a
.vstamp
= symhdr
->vstamp
;
2668 /* At least on Ultrix, these have to be rounded to page boundaries.
2669 FIXME: Is this true on other platforms? */
2670 if ((abfd
->flags
& D_PAGED
) != 0)
2672 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2673 internal_a
.text_start
= text_start
&~ (round
- 1);
2674 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2675 internal_a
.data_start
= data_start
&~ (round
- 1);
2679 internal_a
.tsize
= text_size
;
2680 internal_a
.text_start
= text_start
;
2681 internal_a
.dsize
= data_size
;
2682 internal_a
.data_start
= data_start
;
2685 /* On Ultrix, the initial portions of the .sbss and .bss segments
2686 are at the end of the data section. The bsize field in the
2687 optional header records how many bss bytes are required beyond
2688 those in the data section. The value is not rounded to a page
2690 if (bss_size
< internal_a
.dsize
- data_size
)
2693 bss_size
-= internal_a
.dsize
- data_size
;
2694 internal_a
.bsize
= bss_size
;
2695 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2697 internal_a
.entry
= bfd_get_start_address (abfd
);
2699 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2701 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2702 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2703 for (i
= 0; i
< 4; i
++)
2704 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2706 /* Let the backend adjust the headers if necessary. */
2707 if (backend
->adjust_headers
)
2709 if (! (*backend
->adjust_headers
) (abfd
, &internal_f
, &internal_a
))
2713 /* Write out the file header and the optional header. */
2714 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2717 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2718 if (bfd_bwrite (buff
, filhsz
, abfd
) != filhsz
)
2721 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2722 if (bfd_bwrite (buff
, aoutsz
, abfd
) != aoutsz
)
2725 /* Build the external symbol information. This must be done before
2726 writing out the relocs so that we know the symbol indices. We
2727 don't do this if this BFD was created by the backend linker,
2728 since it will have already handled the symbols and relocs. */
2729 if (! ecoff_data (abfd
)->linker
)
2731 symhdr
->iextMax
= 0;
2732 symhdr
->issExtMax
= 0;
2733 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2734 debug
->ssext
= debug
->ssext_end
= NULL
;
2735 if (! bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2736 (abfd
->flags
& EXEC_P
) == 0,
2737 ecoff_get_extr
, ecoff_set_index
))
2740 /* Write out the relocs. */
2741 for (current
= abfd
->sections
;
2742 current
!= (asection
*) NULL
;
2743 current
= current
->next
)
2745 arelent
**reloc_ptr_ptr
;
2746 arelent
**reloc_end
;
2750 if (current
->reloc_count
== 0)
2753 amt
= current
->reloc_count
* external_reloc_size
;
2754 reloc_buff
= bfd_alloc (abfd
, amt
);
2755 if (reloc_buff
== NULL
)
2758 reloc_ptr_ptr
= current
->orelocation
;
2759 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2760 out_ptr
= (char *) reloc_buff
;
2762 reloc_ptr_ptr
< reloc_end
;
2763 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2767 struct internal_reloc in
;
2769 memset ((PTR
) &in
, 0, sizeof in
);
2771 reloc
= *reloc_ptr_ptr
;
2772 sym
= *reloc
->sym_ptr_ptr
;
2774 in
.r_vaddr
= (reloc
->address
2775 + bfd_get_section_vma (abfd
, current
));
2776 in
.r_type
= reloc
->howto
->type
;
2778 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2780 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2787 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2788 if (strcmp (name
, ".text") == 0)
2789 in
.r_symndx
= RELOC_SECTION_TEXT
;
2790 else if (strcmp (name
, ".rdata") == 0)
2791 in
.r_symndx
= RELOC_SECTION_RDATA
;
2792 else if (strcmp (name
, ".data") == 0)
2793 in
.r_symndx
= RELOC_SECTION_DATA
;
2794 else if (strcmp (name
, ".sdata") == 0)
2795 in
.r_symndx
= RELOC_SECTION_SDATA
;
2796 else if (strcmp (name
, ".sbss") == 0)
2797 in
.r_symndx
= RELOC_SECTION_SBSS
;
2798 else if (strcmp (name
, ".bss") == 0)
2799 in
.r_symndx
= RELOC_SECTION_BSS
;
2800 else if (strcmp (name
, ".init") == 0)
2801 in
.r_symndx
= RELOC_SECTION_INIT
;
2802 else if (strcmp (name
, ".lit8") == 0)
2803 in
.r_symndx
= RELOC_SECTION_LIT8
;
2804 else if (strcmp (name
, ".lit4") == 0)
2805 in
.r_symndx
= RELOC_SECTION_LIT4
;
2806 else if (strcmp (name
, ".xdata") == 0)
2807 in
.r_symndx
= RELOC_SECTION_XDATA
;
2808 else if (strcmp (name
, ".pdata") == 0)
2809 in
.r_symndx
= RELOC_SECTION_PDATA
;
2810 else if (strcmp (name
, ".fini") == 0)
2811 in
.r_symndx
= RELOC_SECTION_FINI
;
2812 else if (strcmp (name
, ".lita") == 0)
2813 in
.r_symndx
= RELOC_SECTION_LITA
;
2814 else if (strcmp (name
, "*ABS*") == 0)
2815 in
.r_symndx
= RELOC_SECTION_ABS
;
2816 else if (strcmp (name
, ".rconst") == 0)
2817 in
.r_symndx
= RELOC_SECTION_RCONST
;
2823 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2825 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2828 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2830 amt
= current
->reloc_count
* external_reloc_size
;
2831 if (bfd_bwrite (reloc_buff
, amt
, abfd
) != amt
)
2833 bfd_release (abfd
, reloc_buff
);
2837 /* Write out the symbolic debugging information. */
2838 if (bfd_get_symcount (abfd
) > 0)
2840 /* Write out the debugging information. */
2841 if (! bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2842 ecoff_data (abfd
)->sym_filepos
))
2847 /* The .bss section of a demand paged executable must receive an
2848 entire page. If there are symbols, the symbols will start on the
2849 next page. If there are no symbols, we must fill out the page by
2851 if (bfd_get_symcount (abfd
) == 0
2852 && (abfd
->flags
& EXEC_P
) != 0
2853 && (abfd
->flags
& D_PAGED
) != 0)
2857 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2860 if (bfd_bread (&c
, (bfd_size_type
) 1, abfd
) == 0)
2862 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2865 if (bfd_bwrite (&c
, (bfd_size_type
) 1, abfd
) != 1)
2869 if (reloc_buff
!= NULL
)
2870 bfd_release (abfd
, reloc_buff
);
2875 if (reloc_buff
!= NULL
)
2876 bfd_release (abfd
, reloc_buff
);
2882 /* Archive handling. ECOFF uses what appears to be a unique type of
2883 archive header (armap). The byte ordering of the armap and the
2884 contents are encoded in the name of the armap itself. At least for
2885 now, we only support archives with the same byte ordering in the
2886 armap and the contents.
2888 The first four bytes in the armap are the number of symbol
2889 definitions. This is always a power of two.
2891 This is followed by the symbol definitions. Each symbol definition
2892 occupies 8 bytes. The first four bytes are the offset from the
2893 start of the armap strings to the null-terminated string naming
2894 this symbol. The second four bytes are the file offset to the
2895 archive member which defines this symbol. If the second four bytes
2896 are 0, then this is not actually a symbol definition, and it should
2899 The symbols are hashed into the armap with a closed hashing scheme.
2900 See the functions below for the details of the algorithm.
2902 After the symbol definitions comes four bytes holding the size of
2903 the string table, followed by the string table itself. */
2905 /* The name of an archive headers looks like this:
2906 __________E[BL]E[BL]_ (with a trailing space).
2907 The trailing space is changed to an X if the archive is changed to
2908 indicate that the armap is out of date.
2910 The Alpha seems to use ________64E[BL]E[BL]_. */
2912 #define ARMAP_BIG_ENDIAN 'B'
2913 #define ARMAP_LITTLE_ENDIAN 'L'
2914 #define ARMAP_MARKER 'E'
2915 #define ARMAP_START_LENGTH 10
2916 #define ARMAP_HEADER_MARKER_INDEX 10
2917 #define ARMAP_HEADER_ENDIAN_INDEX 11
2918 #define ARMAP_OBJECT_MARKER_INDEX 12
2919 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2920 #define ARMAP_END_INDEX 14
2921 #define ARMAP_END "_ "
2923 /* This is a magic number used in the hashing algorithm. */
2924 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2926 /* This returns the hash value to use for a string. It also sets
2927 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2928 is the number of entries in the hash table, and HLOG is the log
2932 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2934 unsigned int *rehash
;
2944 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2945 hash
*= ARMAP_HASH_MAGIC
;
2946 *rehash
= (hash
& (size
- 1)) | 1;
2947 return hash
>> (32 - hlog
);
2950 /* Read in the armap. */
2953 _bfd_ecoff_slurp_armap (abfd
)
2958 struct areltdata
*mapdata
;
2959 bfd_size_type parsed_size
;
2961 struct artdata
*ardata
;
2964 struct symdef
*symdef_ptr
;
2968 /* Get the name of the first element. */
2969 i
= bfd_bread ((PTR
) nextname
, (bfd_size_type
) 16, abfd
);
2975 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
2978 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2979 standard COFF armap. We could move the ECOFF armap stuff into
2980 bfd_slurp_armap, but that seems inappropriate since no other
2981 target uses this format. Instead, we check directly for a COFF
2983 if (strncmp (nextname
, "/ ", 16) == 0)
2984 return bfd_slurp_armap (abfd
);
2986 /* See if the first element is an armap. */
2987 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
2988 ARMAP_START_LENGTH
) != 0
2989 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2990 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2991 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2992 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
2993 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2994 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2995 || strncmp (nextname
+ ARMAP_END_INDEX
,
2996 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
2998 bfd_has_map (abfd
) = false;
3002 /* Make sure we have the right byte ordering. */
3003 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3004 ^ (bfd_header_big_endian (abfd
)))
3005 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3006 ^ (bfd_big_endian (abfd
))))
3008 bfd_set_error (bfd_error_wrong_format
);
3012 /* Read in the armap. */
3013 ardata
= bfd_ardata (abfd
);
3014 mapdata
= (struct areltdata
*) _bfd_read_ar_hdr (abfd
);
3015 if (mapdata
== (struct areltdata
*) NULL
)
3017 parsed_size
= mapdata
->parsed_size
;
3018 bfd_release (abfd
, (PTR
) mapdata
);
3020 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3021 if (raw_armap
== (char *) NULL
)
3024 if (bfd_bread ((PTR
) raw_armap
, parsed_size
, abfd
) != parsed_size
)
3026 if (bfd_get_error () != bfd_error_system_call
)
3027 bfd_set_error (bfd_error_malformed_archive
);
3028 bfd_release (abfd
, (PTR
) raw_armap
);
3032 ardata
->tdata
= (PTR
) raw_armap
;
3034 count
= H_GET_32 (abfd
, raw_armap
);
3036 ardata
->symdef_count
= 0;
3037 ardata
->cache
= (struct ar_cache
*) NULL
;
3039 /* This code used to overlay the symdefs over the raw archive data,
3040 but that doesn't work on a 64 bit host. */
3041 stringbase
= raw_armap
+ count
* 8 + 8;
3043 #ifdef CHECK_ARMAP_HASH
3047 /* Double check that I have the hashing algorithm right by making
3048 sure that every symbol can be looked up successfully. */
3050 for (i
= 1; i
< count
; i
<<= 1)
3052 BFD_ASSERT (i
== count
);
3054 raw_ptr
= raw_armap
+ 4;
3055 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3057 unsigned int name_offset
, file_offset
;
3058 unsigned int hash
, rehash
, srch
;
3060 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3061 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3062 if (file_offset
== 0)
3064 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3069 /* See if we can rehash to this location. */
3070 for (srch
= (hash
+ rehash
) & (count
- 1);
3071 srch
!= hash
&& srch
!= i
;
3072 srch
= (srch
+ rehash
) & (count
- 1))
3073 BFD_ASSERT (H_GET_32 (abfd
, (raw_armap
+ 8 + srch
* 8)) != 0);
3074 BFD_ASSERT (srch
== i
);
3078 #endif /* CHECK_ARMAP_HASH */
3080 raw_ptr
= raw_armap
+ 4;
3081 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3082 if (H_GET_32 (abfd
, (raw_ptr
+ 4)) != 0)
3083 ++ardata
->symdef_count
;
3085 amt
= ardata
->symdef_count
;
3086 amt
*= sizeof (struct symdef
);
3087 symdef_ptr
= (struct symdef
*) bfd_alloc (abfd
, amt
);
3091 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3093 raw_ptr
= raw_armap
+ 4;
3094 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3096 unsigned int name_offset
, file_offset
;
3098 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3099 if (file_offset
== 0)
3101 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3102 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3103 symdef_ptr
->file_offset
= file_offset
;
3107 ardata
->first_file_filepos
= bfd_tell (abfd
);
3108 /* Pad to an even boundary. */
3109 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3111 bfd_has_map (abfd
) = true;
3116 /* Write out an armap. */
3119 _bfd_ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3121 unsigned int elength
;
3123 unsigned int orl_count
;
3126 unsigned int hashsize
, hashlog
;
3127 bfd_size_type symdefsize
;
3129 unsigned int stringsize
;
3130 unsigned int mapsize
;
3133 struct stat statbuf
;
3136 bfd_byte
*hashtable
;
3140 /* Ultrix appears to use as a hash table size the least power of two
3141 greater than twice the number of entries. */
3142 for (hashlog
= 0; ((unsigned int) 1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3144 hashsize
= 1 << hashlog
;
3146 symdefsize
= hashsize
* 8;
3148 stringsize
= stridx
+ padit
;
3150 /* Include 8 bytes to store symdefsize and stringsize in output. */
3151 mapsize
= symdefsize
+ stringsize
+ 8;
3153 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3155 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3157 /* Work out the ECOFF armap name. */
3158 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3159 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3160 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3161 (bfd_header_big_endian (abfd
)
3163 : ARMAP_LITTLE_ENDIAN
);
3164 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3165 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3166 bfd_big_endian (abfd
) ? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3167 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3169 /* Write the timestamp of the archive header to be just a little bit
3170 later than the timestamp of the file, otherwise the linker will
3171 complain that the index is out of date. Actually, the Ultrix
3172 linker just checks the archive name; the GNU linker may check the
3174 stat (abfd
->filename
, &statbuf
);
3175 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3177 /* The DECstation uses zeroes for the uid, gid and mode of the
3179 hdr
.ar_uid
[0] = '0';
3180 hdr
.ar_gid
[0] = '0';
3182 hdr
.ar_mode
[0] = '0';
3184 /* Building gcc ends up extracting the armap as a file - twice. */
3185 hdr
.ar_mode
[0] = '6';
3186 hdr
.ar_mode
[1] = '4';
3187 hdr
.ar_mode
[2] = '4';
3190 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3192 hdr
.ar_fmag
[0] = '`';
3193 hdr
.ar_fmag
[1] = '\012';
3195 /* Turn all null bytes in the header into spaces. */
3196 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3197 if (((char *) (&hdr
))[i
] == '\0')
3198 (((char *) (&hdr
))[i
]) = ' ';
3200 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) sizeof (struct ar_hdr
), abfd
)
3201 != sizeof (struct ar_hdr
))
3204 H_PUT_32 (abfd
, hashsize
, temp
);
3205 if (bfd_bwrite ((PTR
) temp
, (bfd_size_type
) 4, abfd
) != 4)
3208 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3212 current
= abfd
->archive_head
;
3214 for (i
= 0; i
< orl_count
; i
++)
3216 unsigned int hash
, rehash
;
3218 /* Advance firstreal to the file position of this archive
3220 if (map
[i
].u
.abfd
!= last_elt
)
3224 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3225 firstreal
+= firstreal
% 2;
3226 current
= current
->next
;
3228 while (current
!= map
[i
].u
.abfd
);
3233 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3234 if (H_GET_32 (abfd
, (hashtable
+ (hash
* 8) + 4)) != 0)
3238 /* The desired slot is already taken. */
3239 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3241 srch
= (srch
+ rehash
) & (hashsize
- 1))
3242 if (H_GET_32 (abfd
, (hashtable
+ (srch
* 8) + 4)) == 0)
3245 BFD_ASSERT (srch
!= hash
);
3250 H_PUT_32 (abfd
, map
[i
].namidx
, (hashtable
+ hash
* 8));
3251 H_PUT_32 (abfd
, firstreal
, (hashtable
+ hash
* 8 + 4));
3254 if (bfd_bwrite ((PTR
) hashtable
, symdefsize
, abfd
) != symdefsize
)
3257 bfd_release (abfd
, hashtable
);
3259 /* Now write the strings. */
3260 H_PUT_32 (abfd
, stringsize
, temp
);
3261 if (bfd_bwrite ((PTR
) temp
, (bfd_size_type
) 4, abfd
) != 4)
3263 for (i
= 0; i
< orl_count
; i
++)
3267 len
= strlen (*map
[i
].name
) + 1;
3268 if (bfd_bwrite ((PTR
) (*map
[i
].name
), len
, abfd
) != len
)
3272 /* The spec sez this should be a newline. But in order to be
3273 bug-compatible for DECstation ar we use a null. */
3276 if (bfd_bwrite ("", (bfd_size_type
) 1, abfd
) != 1)
3283 /* See whether this BFD is an archive. If it is, read in the armap
3284 and the extended name table. */
3287 _bfd_ecoff_archive_p (abfd
)
3290 struct artdata
*tdata_hold
;
3291 char armag
[SARMAG
+ 1];
3294 if (bfd_bread ((PTR
) armag
, (bfd_size_type
) SARMAG
, abfd
) != SARMAG
)
3296 if (bfd_get_error () != bfd_error_system_call
)
3297 bfd_set_error (bfd_error_wrong_format
);
3298 return (const bfd_target
*) NULL
;
3301 if (strncmp (armag
, ARMAG
, SARMAG
) != 0)
3303 bfd_set_error (bfd_error_wrong_format
);
3307 tdata_hold
= bfd_ardata (abfd
);
3309 amt
= sizeof (struct artdata
);
3310 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
3311 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3313 bfd_ardata (abfd
) = tdata_hold
;
3314 return (const bfd_target
*) NULL
;
3317 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3318 bfd_ardata (abfd
)->cache
= NULL
;
3319 bfd_ardata (abfd
)->archive_head
= NULL
;
3320 bfd_ardata (abfd
)->symdefs
= NULL
;
3321 bfd_ardata (abfd
)->extended_names
= NULL
;
3322 bfd_ardata (abfd
)->tdata
= NULL
;
3324 if (! _bfd_ecoff_slurp_armap (abfd
)
3325 || ! _bfd_ecoff_slurp_extended_name_table (abfd
))
3327 bfd_release (abfd
, bfd_ardata (abfd
));
3328 bfd_ardata (abfd
) = tdata_hold
;
3329 return (const bfd_target
*) NULL
;
3332 if (bfd_has_map (abfd
))
3336 /* This archive has a map, so we may presume that the contents
3337 are object files. Make sure that if the first file in the
3338 archive can be recognized as an object file, it is for this
3339 target. If not, assume that this is the wrong format. If
3340 the first file is not an object file, somebody is doing
3341 something weird, and we permit it so that ar -t will work. */
3343 first
= bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
);
3346 first
->target_defaulted
= false;
3347 if (bfd_check_format (first
, bfd_object
)
3348 && first
->xvec
!= abfd
->xvec
)
3351 /* We ought to close `first' here, but we can't, because
3352 we have no way to remove it from the archive cache.
3353 It's close to impossible to figure out when we can
3354 release bfd_ardata. FIXME. */
3355 (void) bfd_close (first
);
3356 bfd_release (abfd
, bfd_ardata (abfd
));
3358 bfd_set_error (bfd_error_wrong_object_format
);
3359 bfd_ardata (abfd
) = tdata_hold
;
3362 /* And we ought to close `first' here too. */
3369 /* ECOFF linker code. */
3371 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3372 PARAMS ((struct bfd_hash_entry
*entry
,
3373 struct bfd_hash_table
*table
,
3374 const char *string
));
3375 static boolean ecoff_link_add_archive_symbols
3376 PARAMS ((bfd
*, struct bfd_link_info
*));
3377 static boolean ecoff_link_check_archive_element
3378 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3379 static boolean ecoff_link_add_object_symbols
3380 PARAMS ((bfd
*, struct bfd_link_info
*));
3381 static boolean ecoff_link_add_externals
3382 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3384 /* Routine to create an entry in an ECOFF link hash table. */
3386 static struct bfd_hash_entry
*
3387 ecoff_link_hash_newfunc (entry
, table
, string
)
3388 struct bfd_hash_entry
*entry
;
3389 struct bfd_hash_table
*table
;
3392 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3394 /* Allocate the structure if it has not already been allocated by a
3396 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3397 ret
= ((struct ecoff_link_hash_entry
*)
3398 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3399 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3402 /* Call the allocation method of the superclass. */
3403 ret
= ((struct ecoff_link_hash_entry
*)
3404 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3409 /* Set local fields. */
3415 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3417 return (struct bfd_hash_entry
*) ret
;
3420 /* Create an ECOFF link hash table. */
3422 struct bfd_link_hash_table
*
3423 _bfd_ecoff_bfd_link_hash_table_create (abfd
)
3426 struct ecoff_link_hash_table
*ret
;
3427 bfd_size_type amt
= sizeof (struct ecoff_link_hash_table
);
3429 ret
= (struct ecoff_link_hash_table
*) bfd_malloc (amt
);
3432 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3433 ecoff_link_hash_newfunc
))
3436 return (struct bfd_link_hash_table
*) NULL
;
3441 /* Look up an entry in an ECOFF link hash table. */
3443 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3444 ((struct ecoff_link_hash_entry *) \
3445 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3447 /* Traverse an ECOFF link hash table. */
3449 #define ecoff_link_hash_traverse(table, func, info) \
3450 (bfd_link_hash_traverse \
3452 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3455 /* Get the ECOFF link hash table from the info structure. This is
3458 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3460 /* Given an ECOFF BFD, add symbols to the global hash table as
3464 _bfd_ecoff_bfd_link_add_symbols (abfd
, info
)
3466 struct bfd_link_info
*info
;
3468 switch (bfd_get_format (abfd
))
3471 return ecoff_link_add_object_symbols (abfd
, info
);
3473 return ecoff_link_add_archive_symbols (abfd
, info
);
3475 bfd_set_error (bfd_error_wrong_format
);
3480 /* Add the symbols from an archive file to the global hash table.
3481 This looks through the undefined symbols, looks each one up in the
3482 archive hash table, and adds any associated object file. We do not
3483 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3484 already have a hash table, so there is no reason to construct
3488 ecoff_link_add_archive_symbols (abfd
, info
)
3490 struct bfd_link_info
*info
;
3492 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3493 const bfd_byte
*raw_armap
;
3494 struct bfd_link_hash_entry
**pundef
;
3495 unsigned int armap_count
;
3496 unsigned int armap_log
;
3498 const bfd_byte
*hashtable
;
3499 const char *stringbase
;
3501 if (! bfd_has_map (abfd
))
3503 /* An empty archive is a special case. */
3504 if (bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
) == NULL
)
3506 bfd_set_error (bfd_error_no_armap
);
3510 /* If we don't have any raw data for this archive, as can happen on
3511 Irix 4.0.5F, we call the generic routine.
3512 FIXME: We should be more clever about this, since someday tdata
3513 may get to something for a generic archive. */
3514 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3515 if (raw_armap
== (bfd_byte
*) NULL
)
3516 return (_bfd_generic_link_add_archive_symbols
3517 (abfd
, info
, ecoff_link_check_archive_element
));
3519 armap_count
= H_GET_32 (abfd
, raw_armap
);
3522 for (i
= 1; i
< armap_count
; i
<<= 1)
3524 BFD_ASSERT (i
== armap_count
);
3526 hashtable
= raw_armap
+ 4;
3527 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3529 /* Look through the list of undefined symbols. */
3530 pundef
= &info
->hash
->undefs
;
3531 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3533 struct bfd_link_hash_entry
*h
;
3534 unsigned int hash
, rehash
;
3535 unsigned int file_offset
;
3541 /* When a symbol is defined, it is not necessarily removed from
3543 if (h
->type
!= bfd_link_hash_undefined
3544 && h
->type
!= bfd_link_hash_common
)
3546 /* Remove this entry from the list, for general cleanliness
3547 and because we are going to look through the list again
3548 if we search any more libraries. We can't remove the
3549 entry if it is the tail, because that would lose any
3550 entries we add to the list later on. */
3551 if (*pundef
!= info
->hash
->undefs_tail
)
3552 *pundef
= (*pundef
)->next
;
3554 pundef
= &(*pundef
)->next
;
3558 /* Native ECOFF linkers do not pull in archive elements merely
3559 to satisfy common definitions, so neither do we. We leave
3560 them on the list, though, in case we are linking against some
3561 other object format. */
3562 if (h
->type
!= bfd_link_hash_undefined
)
3564 pundef
= &(*pundef
)->next
;
3568 /* Look for this symbol in the archive hash table. */
3569 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3572 file_offset
= H_GET_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3573 if (file_offset
== 0)
3575 /* Nothing in this slot. */
3576 pundef
= &(*pundef
)->next
;
3580 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (hash
* 8));
3581 if (name
[0] != h
->root
.string
[0]
3582 || strcmp (name
, h
->root
.string
) != 0)
3587 /* That was the wrong symbol. Try rehashing. */
3589 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3591 srch
= (srch
+ rehash
) & (armap_count
- 1))
3593 file_offset
= H_GET_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3594 if (file_offset
== 0)
3596 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (srch
* 8));
3597 if (name
[0] == h
->root
.string
[0]
3598 && strcmp (name
, h
->root
.string
) == 0)
3607 pundef
= &(*pundef
)->next
;
3614 element
= (*backend
->get_elt_at_filepos
) (abfd
, (file_ptr
) file_offset
);
3615 if (element
== (bfd
*) NULL
)
3618 if (! bfd_check_format (element
, bfd_object
))
3621 /* Unlike the generic linker, we know that this element provides
3622 a definition for an undefined symbol and we know that we want
3623 to include it. We don't need to check anything. */
3624 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3626 if (! ecoff_link_add_object_symbols (element
, info
))
3629 pundef
= &(*pundef
)->next
;
3635 /* This is called if we used _bfd_generic_link_add_archive_symbols
3636 because we were not dealing with an ECOFF archive. */
3639 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3641 struct bfd_link_info
*info
;
3644 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3645 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3646 = backend
->debug_swap
.swap_ext_in
;
3648 bfd_size_type external_ext_size
;
3649 PTR external_ext
= NULL
;
3650 bfd_size_type esize
;
3657 if (! ecoff_slurp_symbolic_header (abfd
))
3660 /* If there are no symbols, we don't want it. */
3661 if (bfd_get_symcount (abfd
) == 0)
3662 goto successful_return
;
3664 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3666 /* Read in the external symbols and external strings. */
3667 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3668 esize
= symhdr
->iextMax
* external_ext_size
;
3669 external_ext
= (PTR
) bfd_malloc (esize
);
3670 if (external_ext
== NULL
&& esize
!= 0)
3673 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbExtOffset
, SEEK_SET
) != 0
3674 || bfd_bread (external_ext
, esize
, abfd
) != esize
)
3677 ssext
= (char *) bfd_malloc ((bfd_size_type
) symhdr
->issExtMax
);
3678 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3681 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3682 || (bfd_bread (ssext
, (bfd_size_type
) symhdr
->issExtMax
, abfd
)
3683 != (bfd_size_type
) symhdr
->issExtMax
))
3686 /* Look through the external symbols to see if they define some
3687 symbol that is currently undefined. */
3688 ext_ptr
= (char *) external_ext
;
3689 ext_end
= ext_ptr
+ esize
;
3690 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3695 struct bfd_link_hash_entry
*h
;
3697 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3699 /* See if this symbol defines something. */
3700 if (esym
.asym
.st
!= stGlobal
3701 && esym
.asym
.st
!= stLabel
3702 && esym
.asym
.st
!= stProc
)
3705 switch (esym
.asym
.sc
)
3729 name
= ssext
+ esym
.asym
.iss
;
3730 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3732 /* Unlike the generic linker, we do not pull in elements because
3733 of common symbols. */
3734 if (h
== (struct bfd_link_hash_entry
*) NULL
3735 || h
->type
!= bfd_link_hash_undefined
)
3738 /* Include this element. */
3739 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3741 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3745 goto successful_return
;
3749 if (external_ext
!= NULL
)
3750 free (external_ext
);
3755 if (external_ext
!= NULL
)
3756 free (external_ext
);
3762 /* Add symbols from an ECOFF object file to the global linker hash
3766 ecoff_link_add_object_symbols (abfd
, info
)
3768 struct bfd_link_info
*info
;
3771 bfd_size_type external_ext_size
;
3772 PTR external_ext
= NULL
;
3773 bfd_size_type esize
;
3777 if (! ecoff_slurp_symbolic_header (abfd
))
3780 /* If there are no symbols, we don't want it. */
3781 if (bfd_get_symcount (abfd
) == 0)
3784 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3786 /* Read in the external symbols and external strings. */
3787 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3788 esize
= symhdr
->iextMax
* external_ext_size
;
3789 external_ext
= (PTR
) bfd_malloc (esize
);
3790 if (external_ext
== NULL
&& esize
!= 0)
3793 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbExtOffset
, SEEK_SET
) != 0
3794 || bfd_bread (external_ext
, esize
, abfd
) != esize
)
3797 ssext
= (char *) bfd_malloc ((bfd_size_type
) symhdr
->issExtMax
);
3798 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3801 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3802 || (bfd_bread (ssext
, (bfd_size_type
) symhdr
->issExtMax
, abfd
)
3803 != (bfd_size_type
) symhdr
->issExtMax
))
3806 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3810 if (external_ext
!= NULL
)
3811 free (external_ext
);
3817 if (external_ext
!= NULL
)
3818 free (external_ext
);
3822 /* Add the external symbols of an object file to the global linker
3823 hash table. The external symbols and strings we are passed are
3824 just allocated on the stack, and will be discarded. We must
3825 explicitly save any information we may need later on in the link.
3826 We do not want to read the external symbol information again. */
3829 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3831 struct bfd_link_info
*info
;
3835 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3836 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3837 = backend
->debug_swap
.swap_ext_in
;
3838 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3839 unsigned long ext_count
;
3840 struct ecoff_link_hash_entry
**sym_hash
;
3845 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3848 amt
*= sizeof (struct bfd_link_hash_entry
*);
3849 sym_hash
= (struct ecoff_link_hash_entry
**) bfd_alloc (abfd
, amt
);
3852 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3854 ext_ptr
= (char *) external_ext
;
3855 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3856 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3863 struct ecoff_link_hash_entry
*h
;
3867 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3869 /* Skip debugging symbols. */
3871 switch (esym
.asym
.st
)
3887 /* Get the information for this symbol. */
3888 value
= esym
.asym
.value
;
3889 switch (esym
.asym
.sc
)
3909 section
= bfd_make_section_old_way (abfd
, ".text");
3910 value
-= section
->vma
;
3913 section
= bfd_make_section_old_way (abfd
, ".data");
3914 value
-= section
->vma
;
3917 section
= bfd_make_section_old_way (abfd
, ".bss");
3918 value
-= section
->vma
;
3921 section
= bfd_abs_section_ptr
;
3924 section
= bfd_und_section_ptr
;
3927 section
= bfd_make_section_old_way (abfd
, ".sdata");
3928 value
-= section
->vma
;
3931 section
= bfd_make_section_old_way (abfd
, ".sbss");
3932 value
-= section
->vma
;
3935 section
= bfd_make_section_old_way (abfd
, ".rdata");
3936 value
-= section
->vma
;
3939 if (value
> ecoff_data (abfd
)->gp_size
)
3941 section
= bfd_com_section_ptr
;
3946 if (ecoff_scom_section
.name
== NULL
)
3948 /* Initialize the small common section. */
3949 ecoff_scom_section
.name
= SCOMMON
;
3950 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3951 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3952 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3953 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3954 ecoff_scom_symbol
.name
= SCOMMON
;
3955 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3956 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3957 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3959 section
= &ecoff_scom_section
;
3962 section
= bfd_und_section_ptr
;
3965 section
= bfd_make_section_old_way (abfd
, ".init");
3966 value
-= section
->vma
;
3969 section
= bfd_make_section_old_way (abfd
, ".fini");
3970 value
-= section
->vma
;
3973 section
= bfd_make_section_old_way (abfd
, ".rconst");
3974 value
-= section
->vma
;
3978 if (section
== (asection
*) NULL
)
3981 name
= ssext
+ esym
.asym
.iss
;
3984 if (! (_bfd_generic_link_add_one_symbol
3986 (flagword
) (esym
.weakext
? BSF_WEAK
: BSF_GLOBAL
),
3987 section
, value
, (const char *) NULL
, true, true,
3988 (struct bfd_link_hash_entry
**) &h
)))
3993 /* If we are building an ECOFF hash table, save the external
3994 symbol information. */
3995 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3997 if (h
->abfd
== (bfd
*) NULL
3998 || (! bfd_is_und_section (section
)
3999 && (! bfd_is_com_section (section
)
4000 || (h
->root
.type
!= bfd_link_hash_defined
4001 && h
->root
.type
!= bfd_link_hash_defweak
))))
4007 /* Remember whether this symbol was small undefined. */
4008 if (esym
.asym
.sc
== scSUndefined
)
4011 /* If this symbol was ever small undefined, it needs to wind
4012 up in a GP relative section. We can't control the
4013 section of a defined symbol, but we can control the
4014 section of a common symbol. This case is actually needed
4015 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
4017 && h
->root
.type
== bfd_link_hash_common
4018 && strcmp (h
->root
.u
.c
.p
->section
->name
, SCOMMON
) != 0)
4020 h
->root
.u
.c
.p
->section
= bfd_make_section_old_way (abfd
,
4022 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4023 if (h
->esym
.asym
.sc
== scCommon
)
4024 h
->esym
.asym
.sc
= scSCommon
;
4032 /* ECOFF final link routines. */
4034 static boolean ecoff_final_link_debug_accumulate
4035 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4037 static boolean ecoff_link_write_external
4038 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4039 static boolean ecoff_indirect_link_order
4040 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4041 struct bfd_link_order
*));
4042 static boolean ecoff_reloc_link_order
4043 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4044 struct bfd_link_order
*));
4046 /* Structure used to pass information to ecoff_link_write_external. */
4051 struct bfd_link_info
*info
;
4054 /* ECOFF final link routine. This looks through all the input BFDs
4055 and gathers together all the debugging information, and then
4056 processes all the link order information. This may cause it to
4057 close and reopen some input BFDs; I'll see how bad this is. */
4060 _bfd_ecoff_bfd_final_link (abfd
, info
)
4062 struct bfd_link_info
*info
;
4064 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4065 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4068 register bfd
*input_bfd
;
4070 struct bfd_link_order
*p
;
4071 struct extsym_info einfo
;
4073 /* We accumulate the debugging information counts in the symbolic
4075 symhdr
= &debug
->symbolic_header
;
4077 symhdr
->ilineMax
= 0;
4081 symhdr
->isymMax
= 0;
4082 symhdr
->ioptMax
= 0;
4083 symhdr
->iauxMax
= 0;
4085 symhdr
->issExtMax
= 0;
4088 symhdr
->iextMax
= 0;
4090 /* We accumulate the debugging information itself in the debug_info
4093 debug
->external_dnr
= NULL
;
4094 debug
->external_pdr
= NULL
;
4095 debug
->external_sym
= NULL
;
4096 debug
->external_opt
= NULL
;
4097 debug
->external_aux
= NULL
;
4099 debug
->ssext
= debug
->ssext_end
= NULL
;
4100 debug
->external_fdr
= NULL
;
4101 debug
->external_rfd
= NULL
;
4102 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4104 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4105 if (handle
== (PTR
) NULL
)
4108 /* Accumulate the debugging symbols from each input BFD. */
4109 for (input_bfd
= info
->input_bfds
;
4110 input_bfd
!= (bfd
*) NULL
;
4111 input_bfd
= input_bfd
->link_next
)
4115 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4117 /* Abitrarily set the symbolic header vstamp to the vstamp
4118 of the first object file in the link. */
4119 if (symhdr
->vstamp
== 0)
4121 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4122 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4126 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4127 debug
, &backend
->debug_swap
,
4132 /* Combine the register masks. */
4133 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4134 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4135 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4136 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4137 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4138 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4141 /* Write out the external symbols. */
4144 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4145 ecoff_link_write_external
,
4148 if (info
->relocateable
)
4150 /* We need to make a pass over the link_orders to count up the
4151 number of relocations we will need to output, so that we know
4152 how much space they will take up. */
4153 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4156 for (p
= o
->link_order_head
;
4157 p
!= (struct bfd_link_order
*) NULL
;
4159 if (p
->type
== bfd_indirect_link_order
)
4160 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4161 else if (p
->type
== bfd_section_reloc_link_order
4162 || p
->type
== bfd_symbol_reloc_link_order
)
4167 /* Compute the reloc and symbol file positions. */
4168 ecoff_compute_reloc_file_positions (abfd
);
4170 /* Write out the debugging information. */
4171 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4172 &backend
->debug_swap
, info
,
4173 ecoff_data (abfd
)->sym_filepos
))
4176 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4178 if (info
->relocateable
)
4180 /* Now reset the reloc_count field of the sections in the output
4181 BFD to 0, so that we can use them to keep track of how many
4182 relocs we have output thus far. */
4183 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4187 /* Get a value for the GP register. */
4188 if (ecoff_data (abfd
)->gp
== 0)
4190 struct bfd_link_hash_entry
*h
;
4192 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4193 if (h
!= (struct bfd_link_hash_entry
*) NULL
4194 && h
->type
== bfd_link_hash_defined
)
4195 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4196 + h
->u
.def
.section
->output_section
->vma
4197 + h
->u
.def
.section
->output_offset
);
4198 else if (info
->relocateable
)
4202 /* Make up a value. */
4204 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4207 && (strcmp (o
->name
, _SBSS
) == 0
4208 || strcmp (o
->name
, _SDATA
) == 0
4209 || strcmp (o
->name
, _LIT4
) == 0
4210 || strcmp (o
->name
, _LIT8
) == 0
4211 || strcmp (o
->name
, _LITA
) == 0))
4214 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4218 /* If the relocate_section function needs to do a reloc
4219 involving the GP value, it should make a reloc_dangerous
4220 callback to warn that GP is not defined. */
4224 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4226 for (p
= o
->link_order_head
;
4227 p
!= (struct bfd_link_order
*) NULL
;
4230 if (p
->type
== bfd_indirect_link_order
4231 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4232 == bfd_target_ecoff_flavour
))
4234 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4237 else if (p
->type
== bfd_section_reloc_link_order
4238 || p
->type
== bfd_symbol_reloc_link_order
)
4240 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4245 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4251 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4253 ecoff_data (abfd
)->linker
= true;
4258 /* Accumulate the debugging information for an input BFD into the
4259 output BFD. This must read in the symbolic information of the
4263 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4266 struct bfd_link_info
*info
;
4269 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4270 const struct ecoff_debug_swap
* const swap
=
4271 &ecoff_backend (input_bfd
)->debug_swap
;
4272 HDRR
*symhdr
= &debug
->symbolic_header
;
4275 #define READ(ptr, offset, count, size, type) \
4276 if (symhdr->count == 0) \
4277 debug->ptr = NULL; \
4280 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
4281 debug->ptr = (type) bfd_malloc (amt); \
4282 if (debug->ptr == NULL) \
4285 goto return_something; \
4287 if (bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
4288 || bfd_bread (debug->ptr, amt, input_bfd) != amt) \
4291 goto return_something; \
4295 /* If raw_syments is not NULL, then the data was already by read by
4296 _bfd_ecoff_slurp_symbolic_info. */
4297 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4299 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4301 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4302 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4303 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4304 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4305 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4307 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4308 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4309 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4313 /* We do not read the external strings or the external symbols. */
4315 ret
= (bfd_ecoff_debug_accumulate
4316 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4317 &ecoff_backend (output_bfd
)->debug_swap
,
4318 input_bfd
, debug
, swap
, info
));
4321 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4323 if (debug
->line
!= NULL
)
4325 if (debug
->external_dnr
!= NULL
)
4326 free (debug
->external_dnr
);
4327 if (debug
->external_pdr
!= NULL
)
4328 free (debug
->external_pdr
);
4329 if (debug
->external_sym
!= NULL
)
4330 free (debug
->external_sym
);
4331 if (debug
->external_opt
!= NULL
)
4332 free (debug
->external_opt
);
4333 if (debug
->external_aux
!= NULL
)
4334 free (debug
->external_aux
);
4335 if (debug
->ss
!= NULL
)
4337 if (debug
->external_fdr
!= NULL
)
4338 free (debug
->external_fdr
);
4339 if (debug
->external_rfd
!= NULL
)
4340 free (debug
->external_rfd
);
4342 /* Make sure we don't accidentally follow one of these pointers
4343 into freed memory. */
4345 debug
->external_dnr
= NULL
;
4346 debug
->external_pdr
= NULL
;
4347 debug
->external_sym
= NULL
;
4348 debug
->external_opt
= NULL
;
4349 debug
->external_aux
= NULL
;
4351 debug
->external_fdr
= NULL
;
4352 debug
->external_rfd
= NULL
;
4358 /* Put out information for an external symbol. These come only from
4362 ecoff_link_write_external (h
, data
)
4363 struct ecoff_link_hash_entry
*h
;
4366 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4367 bfd
*output_bfd
= einfo
->abfd
;
4370 if (h
->root
.type
== bfd_link_hash_warning
)
4372 h
= (struct ecoff_link_hash_entry
*) h
->root
.u
.i
.link
;
4373 if (h
->root
.type
== bfd_link_hash_new
)
4377 /* We need to check if this symbol is being stripped. */
4378 if (h
->root
.type
== bfd_link_hash_undefined
4379 || h
->root
.type
== bfd_link_hash_undefweak
)
4381 else if (einfo
->info
->strip
== strip_all
4382 || (einfo
->info
->strip
== strip_some
4383 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4384 h
->root
.root
.string
,
4385 false, false) == NULL
))
4390 if (strip
|| h
->written
)
4393 if (h
->abfd
== (bfd
*) NULL
)
4396 h
->esym
.cobol_main
= 0;
4397 h
->esym
.weakext
= 0;
4398 h
->esym
.reserved
= 0;
4399 h
->esym
.ifd
= ifdNil
;
4400 h
->esym
.asym
.value
= 0;
4401 h
->esym
.asym
.st
= stGlobal
;
4403 if (h
->root
.type
!= bfd_link_hash_defined
4404 && h
->root
.type
!= bfd_link_hash_defweak
)
4405 h
->esym
.asym
.sc
= scAbs
;
4408 asection
*output_section
;
4411 output_section
= h
->root
.u
.def
.section
->output_section
;
4412 name
= bfd_section_name (output_section
->owner
, output_section
);
4414 if (strcmp (name
, _TEXT
) == 0)
4415 h
->esym
.asym
.sc
= scText
;
4416 else if (strcmp (name
, _DATA
) == 0)
4417 h
->esym
.asym
.sc
= scData
;
4418 else if (strcmp (name
, _SDATA
) == 0)
4419 h
->esym
.asym
.sc
= scSData
;
4420 else if (strcmp (name
, _RDATA
) == 0)
4421 h
->esym
.asym
.sc
= scRData
;
4422 else if (strcmp (name
, _BSS
) == 0)
4423 h
->esym
.asym
.sc
= scBss
;
4424 else if (strcmp (name
, _SBSS
) == 0)
4425 h
->esym
.asym
.sc
= scSBss
;
4426 else if (strcmp (name
, _INIT
) == 0)
4427 h
->esym
.asym
.sc
= scInit
;
4428 else if (strcmp (name
, _FINI
) == 0)
4429 h
->esym
.asym
.sc
= scFini
;
4430 else if (strcmp (name
, _PDATA
) == 0)
4431 h
->esym
.asym
.sc
= scPData
;
4432 else if (strcmp (name
, _XDATA
) == 0)
4433 h
->esym
.asym
.sc
= scXData
;
4434 else if (strcmp (name
, _RCONST
) == 0)
4435 h
->esym
.asym
.sc
= scRConst
;
4437 h
->esym
.asym
.sc
= scAbs
;
4440 h
->esym
.asym
.reserved
= 0;
4441 h
->esym
.asym
.index
= indexNil
;
4443 else if (h
->esym
.ifd
!= -1)
4445 struct ecoff_debug_info
*debug
;
4447 /* Adjust the FDR index for the symbol by that used for the
4449 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4450 BFD_ASSERT (h
->esym
.ifd
>= 0
4451 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4452 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4455 switch (h
->root
.type
)
4458 case bfd_link_hash_warning
:
4459 case bfd_link_hash_new
:
4461 case bfd_link_hash_undefined
:
4462 case bfd_link_hash_undefweak
:
4463 if (h
->esym
.asym
.sc
!= scUndefined
4464 && h
->esym
.asym
.sc
!= scSUndefined
)
4465 h
->esym
.asym
.sc
= scUndefined
;
4467 case bfd_link_hash_defined
:
4468 case bfd_link_hash_defweak
:
4469 if (h
->esym
.asym
.sc
== scUndefined
4470 || h
->esym
.asym
.sc
== scSUndefined
)
4471 h
->esym
.asym
.sc
= scAbs
;
4472 else if (h
->esym
.asym
.sc
== scCommon
)
4473 h
->esym
.asym
.sc
= scBss
;
4474 else if (h
->esym
.asym
.sc
== scSCommon
)
4475 h
->esym
.asym
.sc
= scSBss
;
4476 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4477 + h
->root
.u
.def
.section
->output_section
->vma
4478 + h
->root
.u
.def
.section
->output_offset
);
4480 case bfd_link_hash_common
:
4481 if (h
->esym
.asym
.sc
!= scCommon
4482 && h
->esym
.asym
.sc
!= scSCommon
)
4483 h
->esym
.asym
.sc
= scCommon
;
4484 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4486 case bfd_link_hash_indirect
:
4487 /* We ignore these symbols, since the indirected symbol is
4488 already in the hash table. */
4492 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4494 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4497 return (bfd_ecoff_debug_one_external
4498 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4499 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4503 /* Relocate and write an ECOFF section into an ECOFF output file. */
4506 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4508 struct bfd_link_info
*info
;
4509 asection
*output_section
;
4510 struct bfd_link_order
*link_order
;
4512 asection
*input_section
;
4514 struct ecoff_section_tdata
*section_tdata
;
4515 bfd_size_type raw_size
;
4516 bfd_size_type cooked_size
;
4517 bfd_byte
*contents
= NULL
;
4518 bfd_size_type external_reloc_size
;
4519 bfd_size_type external_relocs_size
;
4520 PTR external_relocs
= NULL
;
4523 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4525 if (link_order
->size
== 0)
4528 input_section
= link_order
->u
.indirect
.section
;
4529 input_bfd
= input_section
->owner
;
4530 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4532 raw_size
= input_section
->_raw_size
;
4533 cooked_size
= input_section
->_cooked_size
;
4534 if (cooked_size
== 0)
4535 cooked_size
= raw_size
;
4537 BFD_ASSERT (input_section
->output_section
== output_section
);
4538 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4539 BFD_ASSERT (cooked_size
== link_order
->size
);
4541 /* Get the section contents. We allocate memory for the larger of
4542 the size before relocating and the size after relocating. */
4543 amt
= raw_size
>= cooked_size
? raw_size
: cooked_size
;
4544 contents
= (bfd_byte
*) bfd_malloc (amt
);
4545 if (contents
== NULL
&& amt
!= 0)
4548 /* If we are relaxing, the contents may have already been read into
4549 memory, in which case we copy them into our new buffer. We don't
4550 simply reuse the old buffer in case cooked_size > raw_size. */
4551 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4552 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4553 memcpy (contents
, section_tdata
->contents
, (size_t) raw_size
);
4556 if (! bfd_get_section_contents (input_bfd
, input_section
,
4558 (file_ptr
) 0, raw_size
))
4562 /* Get the relocs. If we are relaxing MIPS code, they will already
4563 have been read in. Otherwise, we read them in now. */
4564 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4565 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4567 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4568 && section_tdata
->external_relocs
!= NULL
)
4569 external_relocs
= section_tdata
->external_relocs
;
4572 external_relocs
= (PTR
) bfd_malloc (external_relocs_size
);
4573 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4576 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4577 || (bfd_bread (external_relocs
, external_relocs_size
, input_bfd
)
4578 != external_relocs_size
))
4582 /* Relocate the section contents. */
4583 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4584 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4588 /* Write out the relocated section. */
4589 if (! bfd_set_section_contents (output_bfd
,
4592 (file_ptr
) input_section
->output_offset
,
4596 /* If we are producing relocateable output, the relocs were
4597 modified, and we write them out now. We use the reloc_count
4598 field of output_section to keep track of the number of relocs we
4599 have output so far. */
4600 if (info
->relocateable
)
4602 file_ptr pos
= (output_section
->rel_filepos
4603 + output_section
->reloc_count
* external_reloc_size
);
4604 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
4605 || (bfd_bwrite (external_relocs
, external_relocs_size
, output_bfd
)
4606 != external_relocs_size
))
4608 output_section
->reloc_count
+= input_section
->reloc_count
;
4611 if (contents
!= NULL
)
4613 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4614 free (external_relocs
);
4618 if (contents
!= NULL
)
4620 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4621 free (external_relocs
);
4625 /* Generate a reloc when linking an ECOFF file. This is a reloc
4626 requested by the linker, and does come from any input file. This
4627 is used to build constructor and destructor tables when linking
4631 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4633 struct bfd_link_info
*info
;
4634 asection
*output_section
;
4635 struct bfd_link_order
*link_order
;
4637 enum bfd_link_order_type type
;
4641 struct internal_reloc in
;
4642 bfd_size_type external_reloc_size
;
4647 type
= link_order
->type
;
4649 addend
= link_order
->u
.reloc
.p
->addend
;
4651 /* We set up an arelent to pass to the backend adjust_reloc_out
4653 rel
.address
= link_order
->offset
;
4655 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4658 bfd_set_error (bfd_error_bad_value
);
4662 if (type
== bfd_section_reloc_link_order
)
4664 section
= link_order
->u
.reloc
.p
->u
.section
;
4665 rel
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
4669 struct bfd_link_hash_entry
*h
;
4671 /* Treat a reloc against a defined symbol as though it were
4672 actually against the section. */
4673 h
= bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4674 link_order
->u
.reloc
.p
->u
.name
,
4675 false, false, false);
4677 && (h
->type
== bfd_link_hash_defined
4678 || h
->type
== bfd_link_hash_defweak
))
4680 type
= bfd_section_reloc_link_order
;
4681 section
= h
->u
.def
.section
->output_section
;
4682 /* It seems that we ought to add the symbol value to the
4683 addend here, but in practice it has already been added
4684 because it was passed to constructor_callback. */
4685 addend
+= section
->vma
+ h
->u
.def
.section
->output_offset
;
4689 /* We can't set up a reloc against a symbol correctly,
4690 because we have no asymbol structure. Currently no
4691 adjust_reloc_out routine cares. */
4692 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4696 /* All ECOFF relocs are in-place. Put the addend into the object
4699 BFD_ASSERT (rel
.howto
->partial_inplace
);
4703 bfd_reloc_status_type rstat
;
4706 size
= bfd_get_reloc_size (rel
.howto
);
4707 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4708 if (buf
== (bfd_byte
*) NULL
)
4710 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4711 (bfd_vma
) addend
, buf
);
4717 case bfd_reloc_outofrange
:
4719 case bfd_reloc_overflow
:
4720 if (! ((*info
->callbacks
->reloc_overflow
)
4722 (link_order
->type
== bfd_section_reloc_link_order
4723 ? bfd_section_name (output_bfd
, section
)
4724 : link_order
->u
.reloc
.p
->u
.name
),
4725 rel
.howto
->name
, addend
, (bfd
*) NULL
,
4726 (asection
*) NULL
, (bfd_vma
) 0)))
4733 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4734 (file_ptr
) link_order
->offset
, size
);
4742 /* Move the information into an internal_reloc structure. */
4743 in
.r_vaddr
= (rel
.address
4744 + bfd_get_section_vma (output_bfd
, output_section
));
4745 in
.r_type
= rel
.howto
->type
;
4747 if (type
== bfd_symbol_reloc_link_order
)
4749 struct ecoff_link_hash_entry
*h
;
4751 h
= ((struct ecoff_link_hash_entry
*)
4752 bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4753 link_order
->u
.reloc
.p
->u
.name
,
4754 false, false, true));
4755 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4757 in
.r_symndx
= h
->indx
;
4760 if (! ((*info
->callbacks
->unattached_reloc
)
4761 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4762 (asection
*) NULL
, (bfd_vma
) 0)))
4772 name
= bfd_get_section_name (output_bfd
, section
);
4773 if (strcmp (name
, ".text") == 0)
4774 in
.r_symndx
= RELOC_SECTION_TEXT
;
4775 else if (strcmp (name
, ".rdata") == 0)
4776 in
.r_symndx
= RELOC_SECTION_RDATA
;
4777 else if (strcmp (name
, ".data") == 0)
4778 in
.r_symndx
= RELOC_SECTION_DATA
;
4779 else if (strcmp (name
, ".sdata") == 0)
4780 in
.r_symndx
= RELOC_SECTION_SDATA
;
4781 else if (strcmp (name
, ".sbss") == 0)
4782 in
.r_symndx
= RELOC_SECTION_SBSS
;
4783 else if (strcmp (name
, ".bss") == 0)
4784 in
.r_symndx
= RELOC_SECTION_BSS
;
4785 else if (strcmp (name
, ".init") == 0)
4786 in
.r_symndx
= RELOC_SECTION_INIT
;
4787 else if (strcmp (name
, ".lit8") == 0)
4788 in
.r_symndx
= RELOC_SECTION_LIT8
;
4789 else if (strcmp (name
, ".lit4") == 0)
4790 in
.r_symndx
= RELOC_SECTION_LIT4
;
4791 else if (strcmp (name
, ".xdata") == 0)
4792 in
.r_symndx
= RELOC_SECTION_XDATA
;
4793 else if (strcmp (name
, ".pdata") == 0)
4794 in
.r_symndx
= RELOC_SECTION_PDATA
;
4795 else if (strcmp (name
, ".fini") == 0)
4796 in
.r_symndx
= RELOC_SECTION_FINI
;
4797 else if (strcmp (name
, ".lita") == 0)
4798 in
.r_symndx
= RELOC_SECTION_LITA
;
4799 else if (strcmp (name
, "*ABS*") == 0)
4800 in
.r_symndx
= RELOC_SECTION_ABS
;
4801 else if (strcmp (name
, ".rconst") == 0)
4802 in
.r_symndx
= RELOC_SECTION_RCONST
;
4808 /* Let the BFD backend adjust the reloc. */
4809 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4811 /* Get some memory and swap out the reloc. */
4812 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4813 rbuf
= (bfd_byte
*) bfd_malloc (external_reloc_size
);
4814 if (rbuf
== (bfd_byte
*) NULL
)
4817 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4819 pos
= (output_section
->rel_filepos
4820 + output_section
->reloc_count
* external_reloc_size
);
4821 ok
= (bfd_seek (output_bfd
, pos
, SEEK_SET
) == 0
4822 && (bfd_bwrite ((PTR
) rbuf
, external_reloc_size
, output_bfd
)
4823 == external_reloc_size
));
4826 ++output_section
->reloc_count
;