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
*abfd
));
50 static long ecoff_sec_to_styp_flags
PARAMS ((const char *name
,
52 static boolean ecoff_slurp_symbolic_header
PARAMS ((bfd
*abfd
));
53 static boolean ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
54 asymbol
*asym
, int ext
, int weak
));
55 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, FDR
*fdr
,
57 RNDXR
*rndx
, long isym
,
59 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, FDR
*fdr
,
61 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
63 static int ecoff_sort_hdrs
PARAMS ((const PTR
, const PTR
));
64 static boolean ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
65 static bfd_size_type ecoff_compute_reloc_file_positions
PARAMS ((bfd
*abfd
));
66 static boolean ecoff_get_extr
PARAMS ((asymbol
*, EXTR
*));
67 static void ecoff_set_index
PARAMS ((asymbol
*, bfd_size_type
));
68 static unsigned int ecoff_armap_hash
PARAMS ((const char *s
,
73 /* This stuff is somewhat copied from coffcode.h. */
75 static asection bfd_debug_section
=
77 /* name, id, index, next, flags, user_set_vma, reloc_done, */
78 "*DEBUG*", 0, 0, NULL
, 0, 0, 0,
79 /* linker_mark, linker_has_input, gc_mark, segment_mark, */
81 /* vma, lma, _cooked_size, _raw_size, */
83 /* output_offset, output_section, alignment_power, */
85 /* relocation, orelocation, reloc_count, filepos, rel_filepos, */
87 /* line_filepos, userdata, contents, lineno, lineno_count, */
88 0, NULL
, NULL
, NULL
, 0,
89 /* entsize, comdat, moving_line_filepos, */
91 /* target_index, used_by_bfd, constructor_chain, owner, */
94 (struct symbol_cache_entry
*) NULL
,
96 (struct symbol_cache_entry
**) NULL
,
97 /* link_order_head, link_order_tail */
101 /* Create an ECOFF object. */
104 _bfd_ecoff_mkobject (abfd
)
107 bfd_size_type amt
= sizeof (ecoff_data_type
);
108 abfd
->tdata
.ecoff_obj_data
= (struct ecoff_tdata
*) bfd_zalloc (abfd
, amt
);
109 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
115 /* This is a hook called by coff_real_object_p to create any backend
116 specific information. */
119 _bfd_ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
124 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
125 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
126 ecoff_data_type
*ecoff
;
128 if (_bfd_ecoff_mkobject (abfd
) == false)
131 ecoff
= ecoff_data (abfd
);
133 ecoff
->sym_filepos
= internal_f
->f_symptr
;
135 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
139 ecoff
->text_start
= internal_a
->text_start
;
140 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
141 ecoff
->gp
= internal_a
->gp_value
;
142 ecoff
->gprmask
= internal_a
->gprmask
;
143 for (i
= 0; i
< 4; i
++)
144 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
145 ecoff
->fprmask
= internal_a
->fprmask
;
146 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
147 abfd
->flags
|= D_PAGED
;
149 abfd
->flags
&=~ D_PAGED
;
152 /* It turns out that no special action is required by the MIPS or
153 Alpha ECOFF backends. They have different information in the
154 a.out header, but we just copy it all (e.g., gprmask, cprmask and
155 fprmask) and let the swapping routines ensure that only relevant
156 information is written out. */
161 /* Initialize a new section. */
164 _bfd_ecoff_new_section_hook (abfd
, section
)
165 bfd
*abfd ATTRIBUTE_UNUSED
;
168 section
->alignment_power
= 4;
170 if (strcmp (section
->name
, _TEXT
) == 0
171 || strcmp (section
->name
, _INIT
) == 0
172 || strcmp (section
->name
, _FINI
) == 0)
173 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
174 else if (strcmp (section
->name
, _DATA
) == 0
175 || strcmp (section
->name
, _SDATA
) == 0)
176 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
177 else if (strcmp (section
->name
, _RDATA
) == 0
178 || strcmp (section
->name
, _LIT8
) == 0
179 || strcmp (section
->name
, _LIT4
) == 0
180 || strcmp (section
->name
, _RCONST
) == 0
181 || strcmp (section
->name
, _PDATA
) == 0)
182 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
183 else if (strcmp (section
->name
, _BSS
) == 0
184 || strcmp (section
->name
, _SBSS
) == 0)
185 section
->flags
|= SEC_ALLOC
;
186 else if (strcmp (section
->name
, _LIB
) == 0)
188 /* An Irix 4 shared libary. */
189 section
->flags
|= SEC_COFF_SHARED_LIBRARY
;
192 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
193 uncertain about .init on some systems and I don't know how shared
199 /* Determine the machine architecture and type. This is called from
200 the generic COFF routines. It is the inverse of ecoff_get_magic,
201 below. This could be an ECOFF backend routine, with one version
202 for each target, but there aren't all that many ECOFF targets. */
205 _bfd_ecoff_set_arch_mach_hook (abfd
, filehdr
)
209 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
210 enum bfd_architecture arch
;
213 switch (internal_f
->f_magic
)
216 case MIPS_MAGIC_LITTLE
:
218 arch
= bfd_arch_mips
;
222 case MIPS_MAGIC_LITTLE2
:
223 case MIPS_MAGIC_BIG2
:
224 /* MIPS ISA level 2: the r6000 */
225 arch
= bfd_arch_mips
;
229 case MIPS_MAGIC_LITTLE3
:
230 case MIPS_MAGIC_BIG3
:
231 /* MIPS ISA level 3: the r4000 */
232 arch
= bfd_arch_mips
;
237 arch
= bfd_arch_alpha
;
242 arch
= bfd_arch_obscure
;
247 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
250 /* Get the magic number to use based on the architecture and machine.
251 This is the inverse of _bfd_ecoff_set_arch_mach_hook, above. */
254 ecoff_get_magic (abfd
)
259 switch (bfd_get_arch (abfd
))
262 switch (bfd_get_mach (abfd
))
267 big
= MIPS_MAGIC_BIG
;
268 little
= MIPS_MAGIC_LITTLE
;
272 big
= MIPS_MAGIC_BIG2
;
273 little
= MIPS_MAGIC_LITTLE2
;
277 big
= MIPS_MAGIC_BIG3
;
278 little
= MIPS_MAGIC_LITTLE3
;
282 return bfd_big_endian (abfd
) ? big
: little
;
293 /* Get the section s_flags to use for a section. */
296 ecoff_sec_to_styp_flags (name
, flags
)
304 if (strcmp (name
, _TEXT
) == 0)
306 else if (strcmp (name
, _DATA
) == 0)
308 else if (strcmp (name
, _SDATA
) == 0)
310 else if (strcmp (name
, _RDATA
) == 0)
312 else if (strcmp (name
, _LITA
) == 0)
314 else if (strcmp (name
, _LIT8
) == 0)
316 else if (strcmp (name
, _LIT4
) == 0)
318 else if (strcmp (name
, _BSS
) == 0)
320 else if (strcmp (name
, _SBSS
) == 0)
322 else if (strcmp (name
, _INIT
) == 0)
323 styp
= STYP_ECOFF_INIT
;
324 else if (strcmp (name
, _FINI
) == 0)
325 styp
= STYP_ECOFF_FINI
;
326 else if (strcmp (name
, _PDATA
) == 0)
328 else if (strcmp (name
, _XDATA
) == 0)
330 else if (strcmp (name
, _LIB
) == 0)
331 styp
= STYP_ECOFF_LIB
;
332 else if (strcmp (name
, _GOT
) == 0)
334 else if (strcmp (name
, _HASH
) == 0)
336 else if (strcmp (name
, _DYNAMIC
) == 0)
338 else if (strcmp (name
, _LIBLIST
) == 0)
340 else if (strcmp (name
, _RELDYN
) == 0)
342 else if (strcmp (name
, _CONFLIC
) == 0)
344 else if (strcmp (name
, _DYNSTR
) == 0)
346 else if (strcmp (name
, _DYNSYM
) == 0)
348 else if (strcmp (name
, _COMMENT
) == 0)
351 flags
&=~ SEC_NEVER_LOAD
;
353 else if (strcmp (name
, _RCONST
) == 0)
355 else if (flags
& SEC_CODE
)
357 else if (flags
& SEC_DATA
)
359 else if (flags
& SEC_READONLY
)
361 else if (flags
& SEC_LOAD
)
366 if (flags
& SEC_NEVER_LOAD
)
372 /* Get the BFD flags to use for a section. */
375 _bfd_ecoff_styp_to_sec_flags (abfd
, hdr
, name
, section
, flags_ptr
)
376 bfd
*abfd ATTRIBUTE_UNUSED
;
378 const char *name ATTRIBUTE_UNUSED
;
379 asection
*section ATTRIBUTE_UNUSED
;
380 flagword
* flags_ptr
;
382 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
383 long styp_flags
= internal_s
->s_flags
;
384 flagword sec_flags
= 0;
386 if (styp_flags
& STYP_NOLOAD
)
387 sec_flags
|= SEC_NEVER_LOAD
;
389 /* For 386 COFF, at least, an unloadable text or data section is
390 actually a shared library section. */
391 if ((styp_flags
& STYP_TEXT
)
392 || (styp_flags
& STYP_ECOFF_INIT
)
393 || (styp_flags
& STYP_ECOFF_FINI
)
394 || (styp_flags
& STYP_DYNAMIC
)
395 || (styp_flags
& STYP_LIBLIST
)
396 || (styp_flags
& STYP_RELDYN
)
397 || styp_flags
== STYP_CONFLIC
398 || (styp_flags
& STYP_DYNSTR
)
399 || (styp_flags
& STYP_DYNSYM
)
400 || (styp_flags
& STYP_HASH
))
402 if (sec_flags
& SEC_NEVER_LOAD
)
403 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
405 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
407 else if ((styp_flags
& STYP_DATA
)
408 || (styp_flags
& STYP_RDATA
)
409 || (styp_flags
& STYP_SDATA
)
410 || styp_flags
== STYP_PDATA
411 || styp_flags
== STYP_XDATA
412 || (styp_flags
& STYP_GOT
)
413 || styp_flags
== STYP_RCONST
)
415 if (sec_flags
& SEC_NEVER_LOAD
)
416 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
418 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
419 if ((styp_flags
& STYP_RDATA
)
420 || styp_flags
== STYP_PDATA
421 || styp_flags
== STYP_RCONST
)
422 sec_flags
|= SEC_READONLY
;
424 else if ((styp_flags
& STYP_BSS
)
425 || (styp_flags
& STYP_SBSS
))
426 sec_flags
|= SEC_ALLOC
;
427 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
428 sec_flags
|= SEC_NEVER_LOAD
;
429 else if ((styp_flags
& STYP_LITA
)
430 || (styp_flags
& STYP_LIT8
)
431 || (styp_flags
& STYP_LIT4
))
432 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
433 else if (styp_flags
& STYP_ECOFF_LIB
)
434 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
436 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
438 * flags_ptr
= sec_flags
;
442 /* Read in the symbolic header for an ECOFF object file. */
445 ecoff_slurp_symbolic_header (abfd
)
448 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
449 bfd_size_type external_hdr_size
;
451 HDRR
*internal_symhdr
;
453 /* See if we've already read it in. */
454 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
455 backend
->debug_swap
.sym_magic
)
458 /* See whether there is a symbolic header. */
459 if (ecoff_data (abfd
)->sym_filepos
== 0)
461 bfd_get_symcount (abfd
) = 0;
465 /* At this point bfd_get_symcount (abfd) holds the number of symbols
466 as read from the file header, but on ECOFF this is always the
467 size of the symbolic information header. It would be cleaner to
468 handle this when we first read the file in coffgen.c. */
469 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
470 if (bfd_get_symcount (abfd
) != external_hdr_size
)
472 bfd_set_error (bfd_error_bad_value
);
476 /* Read the symbolic information header. */
477 raw
= (PTR
) bfd_malloc (external_hdr_size
);
481 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) != 0
482 || bfd_bread (raw
, external_hdr_size
, abfd
) != external_hdr_size
)
484 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
485 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
487 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
489 bfd_set_error (bfd_error_bad_value
);
493 /* Now we can get the correct number of symbols. */
494 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
495 + internal_symhdr
->iextMax
);
506 /* Read in and swap the important symbolic information for an ECOFF
507 object file. This is called by gdb via the read_debug_info entry
508 point in the backend structure. */
511 _bfd_ecoff_slurp_symbolic_info (abfd
, ignore
, debug
)
513 asection
*ignore ATTRIBUTE_UNUSED
;
514 struct ecoff_debug_info
*debug
;
516 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
517 HDRR
*internal_symhdr
;
518 bfd_size_type raw_base
;
519 bfd_size_type raw_size
;
521 bfd_size_type external_fdr_size
;
525 bfd_size_type raw_end
;
526 bfd_size_type cb_end
;
530 BFD_ASSERT (debug
== &ecoff_data (abfd
)->debug_info
);
532 /* Check whether we've already gotten it, and whether there's any to
534 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
536 if (ecoff_data (abfd
)->sym_filepos
== 0)
538 bfd_get_symcount (abfd
) = 0;
542 if (! ecoff_slurp_symbolic_header (abfd
))
545 internal_symhdr
= &debug
->symbolic_header
;
547 /* Read all the symbolic information at once. */
548 raw_base
= (ecoff_data (abfd
)->sym_filepos
549 + backend
->debug_swap
.external_hdr_size
);
551 /* Alpha ecoff makes the determination of raw_size difficult. It has
552 an undocumented debug data section between the symhdr and the first
553 documented section. And the ordering of the sections varies between
554 statically and dynamically linked executables.
555 If bfd supports SEEK_END someday, this code could be simplified. */
559 #define UPDATE_RAW_END(start, count, size) \
560 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
561 if (cb_end > raw_end) \
564 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
565 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
566 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
567 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
568 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
569 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
570 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
571 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
572 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
573 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
574 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
576 #undef UPDATE_RAW_END
578 raw_size
= raw_end
- raw_base
;
581 ecoff_data (abfd
)->sym_filepos
= 0;
584 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
588 pos
= ecoff_data (abfd
)->sym_filepos
;
589 pos
+= backend
->debug_swap
.external_hdr_size
;
590 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
591 || bfd_bread (raw
, raw_size
, abfd
) != raw_size
)
593 bfd_release (abfd
, raw
);
597 ecoff_data (abfd
)->raw_syments
= raw
;
599 /* Get pointers for the numeric offsets in the HDRR structure. */
600 #define FIX(off1, off2, type) \
601 if (internal_symhdr->off1 == 0) \
602 debug->off2 = (type) NULL; \
604 debug->off2 = (type) ((char *) raw \
605 + (internal_symhdr->off1 \
607 FIX (cbLineOffset
, line
, unsigned char *);
608 FIX (cbDnOffset
, external_dnr
, PTR
);
609 FIX (cbPdOffset
, external_pdr
, PTR
);
610 FIX (cbSymOffset
, external_sym
, PTR
);
611 FIX (cbOptOffset
, external_opt
, PTR
);
612 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
613 FIX (cbSsOffset
, ss
, char *);
614 FIX (cbSsExtOffset
, ssext
, char *);
615 FIX (cbFdOffset
, external_fdr
, PTR
);
616 FIX (cbRfdOffset
, external_rfd
, PTR
);
617 FIX (cbExtOffset
, external_ext
, PTR
);
620 /* I don't want to always swap all the data, because it will just
621 waste time and most programs will never look at it. The only
622 time the linker needs most of the debugging information swapped
623 is when linking big-endian and little-endian MIPS object files
624 together, which is not a common occurrence.
626 We need to look at the fdr to deal with a lot of information in
627 the symbols, so we swap them here. */
628 amt
= internal_symhdr
->ifdMax
;
629 amt
*= sizeof (struct fdr
);
630 debug
->fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
631 if (debug
->fdr
== NULL
)
633 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
634 fdr_ptr
= debug
->fdr
;
635 fraw_src
= (char *) debug
->external_fdr
;
636 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
637 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
638 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
643 /* ECOFF symbol table routines. The ECOFF symbol table is described
644 in gcc/mips-tfile.c. */
646 /* ECOFF uses two common sections. One is the usual one, and the
647 other is for small objects. All the small objects are kept
648 together, and then referenced via the gp pointer, which yields
649 faster assembler code. This is what we use for the small common
651 static asection ecoff_scom_section
;
652 static asymbol ecoff_scom_symbol
;
653 static asymbol
*ecoff_scom_symbol_ptr
;
655 /* Create an empty symbol. */
658 _bfd_ecoff_make_empty_symbol (abfd
)
661 ecoff_symbol_type
*new;
662 bfd_size_type amt
= sizeof (ecoff_symbol_type
);
664 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, amt
);
665 if (new == (ecoff_symbol_type
*) NULL
)
666 return (asymbol
*) NULL
;
667 memset ((PTR
) new, 0, sizeof *new);
668 new->symbol
.section
= (asection
*) NULL
;
669 new->fdr
= (FDR
*) NULL
;
672 new->symbol
.the_bfd
= abfd
;
676 /* Set the BFD flags and section for an ECOFF symbol. */
679 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, weak
)
686 asym
->the_bfd
= abfd
;
687 asym
->value
= ecoff_sym
->value
;
688 asym
->section
= &bfd_debug_section
;
691 /* Most symbol types are just for debugging. */
692 switch (ecoff_sym
->st
)
701 if (ECOFF_IS_STAB (ecoff_sym
))
703 asym
->flags
= BSF_DEBUGGING
;
708 asym
->flags
= BSF_DEBUGGING
;
713 asym
->flags
= BSF_EXPORT
| BSF_WEAK
;
715 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
718 asym
->flags
= BSF_LOCAL
;
719 /* Normally, a local stProc symbol will have a corresponding
720 external symbol. We mark the local symbol as a debugging
721 symbol, in order to prevent nm from printing both out.
722 Similarly, we mark stLabel and stabs symbols as debugging
723 symbols. In both cases, we do want to set the value
724 correctly based on the symbol class. */
725 if (ecoff_sym
->st
== stProc
726 || ecoff_sym
->st
== stLabel
727 || ECOFF_IS_STAB (ecoff_sym
))
728 asym
->flags
|= BSF_DEBUGGING
;
730 switch (ecoff_sym
->sc
)
733 /* Used for compiler generated labels. Leave them in the
734 debugging section, and mark them as local. If BSF_DEBUGGING
735 is set, then nm does not display them for some reason. If no
736 flags are set then the linker whines about them. */
737 asym
->flags
= BSF_LOCAL
;
740 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
741 asym
->value
-= asym
->section
->vma
;
744 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
745 asym
->value
-= asym
->section
->vma
;
748 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
749 asym
->value
-= asym
->section
->vma
;
752 asym
->flags
= BSF_DEBUGGING
;
755 asym
->section
= bfd_abs_section_ptr
;
758 asym
->section
= bfd_und_section_ptr
;
768 asym
->flags
= BSF_DEBUGGING
;
771 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
772 asym
->value
-= asym
->section
->vma
;
775 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
776 asym
->value
-= asym
->section
->vma
;
779 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
780 asym
->value
-= asym
->section
->vma
;
783 asym
->flags
= BSF_DEBUGGING
;
786 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
788 asym
->section
= bfd_com_section_ptr
;
794 if (ecoff_scom_section
.name
== NULL
)
796 /* Initialize the small common section. */
797 ecoff_scom_section
.name
= SCOMMON
;
798 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
799 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
800 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
801 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
802 ecoff_scom_symbol
.name
= SCOMMON
;
803 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
804 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
805 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
807 asym
->section
= &ecoff_scom_section
;
812 asym
->flags
= BSF_DEBUGGING
;
815 asym
->section
= bfd_und_section_ptr
;
820 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
821 asym
->value
-= asym
->section
->vma
;
826 asym
->flags
= BSF_DEBUGGING
;
829 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
830 asym
->value
-= asym
->section
->vma
;
833 asym
->section
= bfd_make_section_old_way (abfd
, ".rconst");
834 asym
->value
-= asym
->section
->vma
;
840 /* Look for special constructors symbols and make relocation entries
841 in a special construction section. These are produced by the
842 -fgnu-linker argument to g++. */
843 if (ECOFF_IS_STAB (ecoff_sym
))
845 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
855 /* This code is no longer needed. It used to be used to
856 make the linker handle set symbols, but they are now
857 handled in the add_symbols routine instead. */
861 arelent_chain
*reloc_chain
;
862 unsigned int bitsize
;
865 /* Get a section with the same name as the symbol (usually
866 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
867 name ___CTOR_LIST (three underscores). We need
868 __CTOR_LIST (two underscores), since ECOFF doesn't use
869 a leading underscore. This should be handled by gcc,
870 but instead we do it here. Actually, this should all
871 be done differently anyhow. */
872 name
= bfd_asymbol_name (asym
);
873 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
878 section
= bfd_get_section_by_name (abfd
, name
);
879 if (section
== (asection
*) NULL
)
883 amt
= strlen (name
) + 1;
884 copy
= (char *) bfd_alloc (abfd
, amt
);
888 section
= bfd_make_section (abfd
, copy
);
891 /* Build a reloc pointing to this constructor. */
892 amt
= sizeof (arelent_chain
);
893 reloc_chain
= (arelent_chain
*) bfd_alloc (abfd
, amt
);
896 reloc_chain
->relent
.sym_ptr_ptr
=
897 bfd_get_section (asym
)->symbol_ptr_ptr
;
898 reloc_chain
->relent
.address
= section
->_raw_size
;
899 reloc_chain
->relent
.addend
= asym
->value
;
900 reloc_chain
->relent
.howto
=
901 ecoff_backend (abfd
)->constructor_reloc
;
903 /* Set up the constructor section to hold the reloc. */
904 section
->flags
= SEC_CONSTRUCTOR
;
905 ++section
->reloc_count
;
907 /* Constructor sections must be rounded to a boundary
908 based on the bitsize. These are not real sections--
909 they are handled specially by the linker--so the ECOFF
910 16 byte alignment restriction does not apply. */
911 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
912 section
->alignment_power
= 1;
913 while ((1 << section
->alignment_power
) < bitsize
/ 8)
914 ++section
->alignment_power
;
916 reloc_chain
->next
= section
->constructor_chain
;
917 section
->constructor_chain
= reloc_chain
;
918 section
->_raw_size
+= bitsize
/ 8;
922 /* Mark the symbol as a constructor. */
923 asym
->flags
|= BSF_CONSTRUCTOR
;
931 /* Read an ECOFF symbol table. */
934 _bfd_ecoff_slurp_symbol_table (abfd
)
937 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
938 const bfd_size_type external_ext_size
939 = backend
->debug_swap
.external_ext_size
;
940 const bfd_size_type external_sym_size
941 = backend
->debug_swap
.external_sym_size
;
942 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
943 = backend
->debug_swap
.swap_ext_in
;
944 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
945 = backend
->debug_swap
.swap_sym_in
;
946 bfd_size_type internal_size
;
947 ecoff_symbol_type
*internal
;
948 ecoff_symbol_type
*internal_ptr
;
954 /* If we've already read in the symbol table, do nothing. */
955 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
958 /* Get the symbolic information. */
959 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
960 &ecoff_data (abfd
)->debug_info
))
962 if (bfd_get_symcount (abfd
) == 0)
965 internal_size
= bfd_get_symcount (abfd
);
966 internal_size
*= sizeof (ecoff_symbol_type
);
967 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
968 if (internal
== NULL
)
971 internal_ptr
= internal
;
972 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
974 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
975 * external_ext_size
));
976 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
980 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
981 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
982 + internal_esym
.asym
.iss
);
983 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
984 &internal_ptr
->symbol
, 1,
985 internal_esym
.weakext
))
987 /* The alpha uses a negative ifd field for section symbols. */
988 if (internal_esym
.ifd
>= 0)
989 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
990 + internal_esym
.ifd
);
992 internal_ptr
->fdr
= NULL
;
993 internal_ptr
->local
= false;
994 internal_ptr
->native
= (PTR
) eraw_src
;
997 /* The local symbols must be accessed via the fdr's, because the
998 string and aux indices are relative to the fdr information. */
999 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1000 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1001 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1006 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1007 + fdr_ptr
->isymBase
* external_sym_size
);
1008 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1010 lraw_src
< lraw_end
;
1011 lraw_src
+= external_sym_size
, internal_ptr
++)
1015 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1016 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1018 + internal_sym
.iss
);
1019 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
1020 &internal_ptr
->symbol
, 0, 0))
1022 internal_ptr
->fdr
= fdr_ptr
;
1023 internal_ptr
->local
= true;
1024 internal_ptr
->native
= (PTR
) lraw_src
;
1028 ecoff_data (abfd
)->canonical_symbols
= internal
;
1033 /* Return the amount of space needed for the canonical symbols. */
1036 _bfd_ecoff_get_symtab_upper_bound (abfd
)
1039 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
,
1040 &ecoff_data (abfd
)->debug_info
))
1043 if (bfd_get_symcount (abfd
) == 0)
1046 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1049 /* Get the canonical symbols. */
1052 _bfd_ecoff_get_symtab (abfd
, alocation
)
1054 asymbol
**alocation
;
1056 unsigned int counter
= 0;
1057 ecoff_symbol_type
*symbase
;
1058 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1060 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1062 if (bfd_get_symcount (abfd
) == 0)
1065 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1066 while (counter
< bfd_get_symcount (abfd
))
1068 *(location
++) = symbase
++;
1071 *location
++ = (ecoff_symbol_type
*) NULL
;
1072 return bfd_get_symcount (abfd
);
1075 /* Turn ECOFF type information into a printable string.
1076 ecoff_emit_aggregate and ecoff_type_to_string are from
1077 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1079 /* Write aggregate information to a string. */
1082 ecoff_emit_aggregate (abfd
, fdr
, string
, rndx
, isym
, which
)
1090 const struct ecoff_debug_swap
* const debug_swap
=
1091 &ecoff_backend (abfd
)->debug_swap
;
1092 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1093 unsigned int ifd
= rndx
->rfd
;
1094 unsigned int indx
= rndx
->index
;
1100 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1101 struct return type of a procedure compiled without -g. */
1102 if (ifd
== 0xffffffff
1103 || (rndx
->rfd
== 0xfff && indx
== 0))
1104 name
= "<undefined>";
1105 else if (indx
== indexNil
)
1111 if (debug_info
->external_rfd
== NULL
)
1112 fdr
= debug_info
->fdr
+ ifd
;
1117 (*debug_swap
->swap_rfd_in
) (abfd
,
1118 ((char *) debug_info
->external_rfd
1119 + ((fdr
->rfdBase
+ ifd
)
1120 * debug_swap
->external_rfd_size
)),
1122 fdr
= debug_info
->fdr
+ rfd
;
1125 indx
+= fdr
->isymBase
;
1127 (*debug_swap
->swap_sym_in
) (abfd
,
1128 ((char *) debug_info
->external_sym
1129 + indx
* debug_swap
->external_sym_size
),
1132 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1136 "%s %s { ifd = %u, index = %lu }",
1139 + debug_info
->symbolic_header
.iextMax
));
1142 /* Convert the type information to string format. */
1145 ecoff_type_to_string (abfd
, fdr
, indx
)
1150 union aux_ext
*aux_ptr
;
1159 unsigned int basic_type
;
1162 static char buffer2
[1024];
1167 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1168 bigendian
= fdr
->fBigendian
;
1170 for (i
= 0; i
< 7; i
++)
1172 qualifiers
[i
].low_bound
= 0;
1173 qualifiers
[i
].high_bound
= 0;
1174 qualifiers
[i
].stride
= 0;
1177 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == (bfd_vma
) -1)
1178 return "-1 (no type)";
1179 _bfd_ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1181 basic_type
= u
.ti
.bt
;
1182 qualifiers
[0].type
= u
.ti
.tq0
;
1183 qualifiers
[1].type
= u
.ti
.tq1
;
1184 qualifiers
[2].type
= u
.ti
.tq2
;
1185 qualifiers
[3].type
= u
.ti
.tq3
;
1186 qualifiers
[4].type
= u
.ti
.tq4
;
1187 qualifiers
[5].type
= u
.ti
.tq5
;
1188 qualifiers
[6].type
= tqNil
;
1191 * Go get the basic type.
1195 case btNil
: /* undefined */
1199 case btAdr
: /* address - integer same size as pointer */
1200 strcpy (p1
, "address");
1203 case btChar
: /* character */
1204 strcpy (p1
, "char");
1207 case btUChar
: /* unsigned character */
1208 strcpy (p1
, "unsigned char");
1211 case btShort
: /* short */
1212 strcpy (p1
, "short");
1215 case btUShort
: /* unsigned short */
1216 strcpy (p1
, "unsigned short");
1219 case btInt
: /* int */
1223 case btUInt
: /* unsigned int */
1224 strcpy (p1
, "unsigned int");
1227 case btLong
: /* long */
1228 strcpy (p1
, "long");
1231 case btULong
: /* unsigned long */
1232 strcpy (p1
, "unsigned long");
1235 case btFloat
: /* float (real) */
1236 strcpy (p1
, "float");
1239 case btDouble
: /* Double (real) */
1240 strcpy (p1
, "double");
1243 /* Structures add 1-2 aux words:
1244 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1245 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1247 case btStruct
: /* Structure (Record) */
1248 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1249 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1250 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1252 indx
++; /* skip aux words */
1255 /* Unions add 1-2 aux words:
1256 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1257 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1259 case btUnion
: /* Union */
1260 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1261 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1262 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1264 indx
++; /* skip aux words */
1267 /* Enumerations add 1-2 aux words:
1268 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1269 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1271 case btEnum
: /* Enumeration */
1272 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1273 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1274 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1276 indx
++; /* skip aux words */
1279 case btTypedef
: /* defined via a typedef, isymRef points */
1280 strcpy (p1
, "typedef");
1283 case btRange
: /* subrange of int */
1284 strcpy (p1
, "subrange");
1287 case btSet
: /* pascal sets */
1291 case btComplex
: /* fortran complex */
1292 strcpy (p1
, "complex");
1295 case btDComplex
: /* fortran double complex */
1296 strcpy (p1
, "double complex");
1299 case btIndirect
: /* forward or unnamed typedef */
1300 strcpy (p1
, "forward/unamed typedef");
1303 case btFixedDec
: /* Fixed Decimal */
1304 strcpy (p1
, "fixed decimal");
1307 case btFloatDec
: /* Float Decimal */
1308 strcpy (p1
, "float decimal");
1311 case btString
: /* Varying Length Character String */
1312 strcpy (p1
, "string");
1315 case btBit
: /* Aligned Bit String */
1319 case btPicture
: /* Picture */
1320 strcpy (p1
, "picture");
1323 case btVoid
: /* Void */
1324 strcpy (p1
, "void");
1328 sprintf (p1
, _("Unknown basic type %d"), (int) basic_type
);
1332 p1
+= strlen (buffer1
);
1335 * If this is a bitfield, get the bitsize.
1341 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1342 sprintf (p1
, " : %d", bitsize
);
1343 p1
+= strlen (buffer1
);
1347 * Deal with any qualifiers.
1349 if (qualifiers
[0].type
!= tqNil
)
1352 * Snarf up any array bounds in the correct order. Arrays
1353 * store 5 successive words in the aux. table:
1354 * word 0 RNDXR to type of the bounds (ie, int)
1355 * word 1 Current file descriptor index
1357 * word 3 high bound (or -1 if [])
1358 * word 4 stride size in bits
1360 for (i
= 0; i
< 7; i
++)
1362 if (qualifiers
[i
].type
== tqArray
)
1364 qualifiers
[i
].low_bound
=
1365 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1366 qualifiers
[i
].high_bound
=
1367 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1368 qualifiers
[i
].stride
=
1369 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1375 * Now print out the qualifiers.
1377 for (i
= 0; i
< 6; i
++)
1379 switch (qualifiers
[i
].type
)
1386 strcpy (p2
, "ptr to ");
1387 p2
+= sizeof ("ptr to ")-1;
1391 strcpy (p2
, "volatile ");
1392 p2
+= sizeof ("volatile ")-1;
1396 strcpy (p2
, "far ");
1397 p2
+= sizeof ("far ")-1;
1401 strcpy (p2
, "func. ret. ");
1402 p2
+= sizeof ("func. ret. ");
1407 int first_array
= i
;
1410 /* Print array bounds reversed (ie, in the order the C
1411 programmer writes them). C is such a fun language.... */
1413 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1416 for (j
= i
; j
>= first_array
; j
--)
1418 strcpy (p2
, "array [");
1419 p2
+= sizeof ("array [")-1;
1420 if (qualifiers
[j
].low_bound
!= 0)
1422 "%ld:%ld {%ld bits}",
1423 (long) qualifiers
[j
].low_bound
,
1424 (long) qualifiers
[j
].high_bound
,
1425 (long) qualifiers
[j
].stride
);
1427 else if (qualifiers
[j
].high_bound
!= -1)
1430 (long) (qualifiers
[j
].high_bound
+ 1),
1431 (long) (qualifiers
[j
].stride
));
1434 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1437 strcpy (p2
, "] of ");
1438 p2
+= sizeof ("] of ")-1;
1446 strcpy (p2
, buffer1
);
1450 /* Return information about ECOFF symbol SYMBOL in RET. */
1453 _bfd_ecoff_get_symbol_info (abfd
, symbol
, ret
)
1454 bfd
*abfd ATTRIBUTE_UNUSED
;
1458 bfd_symbol_info (symbol
, ret
);
1461 /* Return whether this is a local label. */
1464 _bfd_ecoff_bfd_is_local_label_name (abfd
, name
)
1465 bfd
*abfd ATTRIBUTE_UNUSED
;
1468 return name
[0] == '$';
1471 /* Print information about an ECOFF symbol. */
1474 _bfd_ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1478 bfd_print_symbol_type how
;
1480 const struct ecoff_debug_swap
* const debug_swap
1481 = &ecoff_backend (abfd
)->debug_swap
;
1482 FILE *file
= (FILE *)filep
;
1486 case bfd_print_symbol_name
:
1487 fprintf (file
, "%s", symbol
->name
);
1489 case bfd_print_symbol_more
:
1490 if (ecoffsymbol (symbol
)->local
)
1494 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1496 fprintf (file
, "ecoff local ");
1497 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1498 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1499 (unsigned) ecoff_sym
.sc
);
1505 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1507 fprintf (file
, "ecoff extern ");
1508 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1509 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1510 (unsigned) ecoff_ext
.asym
.sc
);
1513 case bfd_print_symbol_all
:
1514 /* Print out the symbols in a reasonable way */
1523 if (ecoffsymbol (symbol
)->local
)
1525 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1528 pos
= ((((char *) ecoffsymbol (symbol
)->native
1529 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1530 / debug_swap
->external_sym_size
)
1531 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1538 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1541 pos
= (((char *) ecoffsymbol (symbol
)->native
1542 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1543 / debug_swap
->external_ext_size
);
1544 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1545 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1546 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1549 fprintf (file
, "[%3d] %c ",
1551 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1552 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1553 (unsigned) ecoff_ext
.asym
.st
,
1554 (unsigned) ecoff_ext
.asym
.sc
,
1555 (unsigned) ecoff_ext
.asym
.index
,
1556 jmptbl
, cobol_main
, weakext
,
1559 if (ecoffsymbol (symbol
)->fdr
!= NULL
1560 && ecoff_ext
.asym
.index
!= indexNil
)
1565 bfd_size_type sym_base
;
1566 union aux_ext
*aux_base
;
1568 fdr
= ecoffsymbol (symbol
)->fdr
;
1569 indx
= ecoff_ext
.asym
.index
;
1571 /* sym_base is used to map the fdr relative indices which
1572 appear in the file to the position number which we are
1574 sym_base
= fdr
->isymBase
;
1575 if (ecoffsymbol (symbol
)->local
)
1577 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1579 /* aux_base is the start of the aux entries for this file;
1580 asym.index is an offset from this. */
1581 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1584 /* The aux entries are stored in host byte order; the
1585 order is indicated by a bit in the fdr. */
1586 bigendian
= fdr
->fBigendian
;
1588 /* This switch is basically from gcc/mips-tdump.c */
1589 switch (ecoff_ext
.asym
.st
)
1597 fprintf (file
, _("\n End+1 symbol: %ld"),
1598 (long) (indx
+ sym_base
));
1602 if (ecoff_ext
.asym
.sc
== scText
1603 || ecoff_ext
.asym
.sc
== scInfo
)
1604 fprintf (file
, _("\n First symbol: %ld"),
1605 (long) (indx
+ sym_base
));
1607 fprintf (file
, _("\n First symbol: %ld"),
1609 (AUX_GET_ISYM (bigendian
,
1610 &aux_base
[ecoff_ext
.asym
.index
])
1616 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1618 else if (ecoffsymbol (symbol
)->local
)
1619 fprintf (file
, _("\n End+1 symbol: %-7ld Type: %s"),
1621 (AUX_GET_ISYM (bigendian
,
1622 &aux_base
[ecoff_ext
.asym
.index
])
1624 ecoff_type_to_string (abfd
, fdr
, indx
+ 1));
1626 fprintf (file
, _("\n Local symbol: %ld"),
1629 + (ecoff_data (abfd
)
1630 ->debug_info
.symbolic_header
.iextMax
)));
1634 fprintf (file
, _("\n struct; End+1 symbol: %ld"),
1635 (long) (indx
+ sym_base
));
1639 fprintf (file
, _("\n union; End+1 symbol: %ld"),
1640 (long) (indx
+ sym_base
));
1644 fprintf (file
, _("\n enum; End+1 symbol: %ld"),
1645 (long) (indx
+ sym_base
));
1649 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1650 fprintf (file
, _("\n Type: %s"),
1651 ecoff_type_to_string (abfd
, fdr
, indx
));
1660 /* Read in the relocs for a section. */
1663 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1668 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1669 arelent
*internal_relocs
;
1670 bfd_size_type external_reloc_size
;
1672 char *external_relocs
;
1676 if (section
->relocation
!= (arelent
*) NULL
1677 || section
->reloc_count
== 0
1678 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1681 if (_bfd_ecoff_slurp_symbol_table (abfd
) == false)
1684 amt
= section
->reloc_count
;
1685 amt
*= sizeof (arelent
);
1686 internal_relocs
= (arelent
*) bfd_alloc (abfd
, amt
);
1688 external_reloc_size
= backend
->external_reloc_size
;
1689 amt
= external_reloc_size
* section
->reloc_count
;
1690 external_relocs
= (char *) bfd_alloc (abfd
, amt
);
1691 if (internal_relocs
== (arelent
*) NULL
1692 || external_relocs
== (char *) NULL
)
1694 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1696 if (bfd_bread (external_relocs
, amt
, abfd
) != amt
)
1699 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1701 struct internal_reloc intern
;
1703 (*backend
->swap_reloc_in
) (abfd
,
1704 external_relocs
+ i
* external_reloc_size
,
1707 if (intern
.r_extern
)
1709 /* r_symndx is an index into the external symbols. */
1710 BFD_ASSERT (intern
.r_symndx
>= 0
1712 < (ecoff_data (abfd
)
1713 ->debug_info
.symbolic_header
.iextMax
)));
1714 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1717 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1718 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1720 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
1725 const char *sec_name
;
1728 /* r_symndx is a section key. */
1729 switch (intern
.r_symndx
)
1731 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1732 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1733 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1734 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1735 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1736 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1737 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1738 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1739 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1740 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1741 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1742 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1743 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1744 case RELOC_SECTION_RCONST
: sec_name
= ".rconst"; break;
1748 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1749 if (sec
== (asection
*) NULL
)
1751 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1753 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1756 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1758 /* Let the backend select the howto field and do any other
1759 required processing. */
1760 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1763 bfd_release (abfd
, external_relocs
);
1765 section
->relocation
= internal_relocs
;
1770 /* Get a canonical list of relocs. */
1773 _bfd_ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1781 if (section
->flags
& SEC_CONSTRUCTOR
)
1783 arelent_chain
*chain
;
1785 /* This section has relocs made up by us, not the file, so take
1786 them out of their chain and place them into the data area
1788 for (count
= 0, chain
= section
->constructor_chain
;
1789 count
< section
->reloc_count
;
1790 count
++, chain
= chain
->next
)
1791 *relptr
++ = &chain
->relent
;
1797 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1800 tblptr
= section
->relocation
;
1802 for (count
= 0; count
< section
->reloc_count
; count
++)
1803 *relptr
++ = tblptr
++;
1806 *relptr
= (arelent
*) NULL
;
1808 return section
->reloc_count
;
1811 /* Provided a BFD, a section and an offset into the section, calculate
1812 and return the name of the source file and the line nearest to the
1816 _bfd_ecoff_find_nearest_line (abfd
, section
, ignore_symbols
, offset
,
1817 filename_ptr
, functionname_ptr
, retline_ptr
)
1820 asymbol
**ignore_symbols ATTRIBUTE_UNUSED
;
1822 const char **filename_ptr
;
1823 const char **functionname_ptr
;
1824 unsigned int *retline_ptr
;
1826 const struct ecoff_debug_swap
* const debug_swap
1827 = &ecoff_backend (abfd
)->debug_swap
;
1828 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1829 struct ecoff_find_line
*line_info
;
1831 /* Make sure we have the FDR's. */
1832 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, (asection
*) NULL
, debug_info
)
1833 || bfd_get_symcount (abfd
) == 0)
1836 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1838 bfd_size_type amt
= sizeof (struct ecoff_find_line
);
1839 ecoff_data (abfd
)->find_line_info
1840 = (struct ecoff_find_line
*) bfd_zalloc (abfd
, amt
);
1841 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1844 line_info
= ecoff_data (abfd
)->find_line_info
;
1846 return _bfd_ecoff_locate_line (abfd
, section
, offset
, debug_info
,
1847 debug_swap
, line_info
, filename_ptr
,
1848 functionname_ptr
, retline_ptr
);
1851 /* Copy private BFD data. This is called by objcopy and strip. We
1852 use it to copy the ECOFF debugging information from one BFD to the
1853 other. It would be theoretically possible to represent the ECOFF
1854 debugging information in the symbol table. However, it would be a
1855 lot of work, and there would be little gain (gas, gdb, and ld
1856 already access the ECOFF debugging information via the
1857 ecoff_debug_info structure, and that structure would have to be
1858 retained in order to support ECOFF debugging in MIPS ELF).
1860 The debugging information for the ECOFF external symbols comes from
1861 the symbol table, so this function only handles the other debugging
1865 _bfd_ecoff_bfd_copy_private_bfd_data (ibfd
, obfd
)
1869 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
1870 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
1872 asymbol
**sym_ptr_ptr
;
1876 /* We only want to copy information over if both BFD's use ECOFF
1878 if (bfd_get_flavour (ibfd
) != bfd_target_ecoff_flavour
1879 || bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
1882 /* Copy the GP value and the register masks. */
1883 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
1884 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
1885 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
1886 for (i
= 0; i
< 3; i
++)
1887 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
1889 /* Copy the version stamp. */
1890 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
1892 /* If there are no symbols, don't copy any debugging information. */
1893 c
= bfd_get_symcount (obfd
);
1894 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1895 if (c
== 0 || sym_ptr_ptr
== (asymbol
**) NULL
)
1898 /* See if there are any local symbols. */
1900 for (; c
> 0; c
--, sym_ptr_ptr
++)
1902 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
1911 /* There are some local symbols. We just bring over all the
1912 debugging information. FIXME: This is not quite the right
1913 thing to do. If the user has asked us to discard all
1914 debugging information, then we are probably going to wind up
1915 keeping it because there will probably be some local symbol
1916 which objcopy did not discard. We should actually break
1917 apart the debugging information and only keep that which
1918 applies to the symbols we want to keep. */
1919 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
1920 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
1921 oinfo
->line
= iinfo
->line
;
1923 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
1924 oinfo
->external_dnr
= iinfo
->external_dnr
;
1926 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
1927 oinfo
->external_pdr
= iinfo
->external_pdr
;
1929 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
1930 oinfo
->external_sym
= iinfo
->external_sym
;
1932 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
1933 oinfo
->external_opt
= iinfo
->external_opt
;
1935 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
1936 oinfo
->external_aux
= iinfo
->external_aux
;
1938 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
1939 oinfo
->ss
= iinfo
->ss
;
1941 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
1942 oinfo
->external_fdr
= iinfo
->external_fdr
;
1944 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
1945 oinfo
->external_rfd
= iinfo
->external_rfd
;
1949 /* We are discarding all the local symbol information. Look
1950 through the external symbols and remove all references to FDR
1951 or aux information. */
1952 c
= bfd_get_symcount (obfd
);
1953 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1954 for (; c
> 0; c
--, sym_ptr_ptr
++)
1958 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
1959 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
1961 esym
.asym
.index
= indexNil
;
1962 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
1963 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
1970 /* Set the architecture. The supported architecture is stored in the
1971 backend pointer. We always set the architecture anyhow, since many
1972 callers ignore the return value. */
1975 _bfd_ecoff_set_arch_mach (abfd
, arch
, machine
)
1977 enum bfd_architecture arch
;
1978 unsigned long machine
;
1980 bfd_default_set_arch_mach (abfd
, arch
, machine
);
1981 return arch
== ecoff_backend (abfd
)->arch
;
1984 /* Get the size of the section headers. */
1987 _bfd_ecoff_sizeof_headers (abfd
, reloc
)
1989 boolean reloc ATTRIBUTE_UNUSED
;
1996 for (current
= abfd
->sections
;
1997 current
!= (asection
*)NULL
;
1998 current
= current
->next
)
2001 ret
= (bfd_coff_filhsz (abfd
)
2002 + bfd_coff_aoutsz (abfd
)
2003 + c
* bfd_coff_scnhsz (abfd
));
2004 return BFD_ALIGN (ret
, 16);
2007 /* Get the contents of a section. */
2010 _bfd_ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2015 bfd_size_type count
;
2017 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2021 /* Sort sections by VMA, but put SEC_ALLOC sections first. This is
2022 called via qsort. */
2025 ecoff_sort_hdrs (arg1
, arg2
)
2029 const asection
*hdr1
= *(const asection
**) arg1
;
2030 const asection
*hdr2
= *(const asection
**) arg2
;
2032 if ((hdr1
->flags
& SEC_ALLOC
) != 0)
2034 if ((hdr2
->flags
& SEC_ALLOC
) == 0)
2039 if ((hdr2
->flags
& SEC_ALLOC
) != 0)
2042 if (hdr1
->vma
< hdr2
->vma
)
2044 else if (hdr1
->vma
> hdr2
->vma
)
2050 /* Calculate the file position for each section, and set
2054 ecoff_compute_section_file_positions (abfd
)
2057 file_ptr sofar
, file_sofar
;
2058 asection
**sorted_hdrs
;
2062 boolean rdata_in_text
;
2063 boolean first_data
, first_nonalloc
;
2064 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2067 sofar
= _bfd_ecoff_sizeof_headers (abfd
, false);
2070 /* Sort the sections by VMA. */
2071 amt
= abfd
->section_count
;
2072 amt
*= sizeof (asection
*);
2073 sorted_hdrs
= (asection
**) bfd_malloc (amt
);
2074 if (sorted_hdrs
== NULL
)
2076 for (current
= abfd
->sections
, i
= 0;
2078 current
= current
->next
, i
++)
2079 sorted_hdrs
[i
] = current
;
2080 BFD_ASSERT (i
== abfd
->section_count
);
2082 qsort (sorted_hdrs
, abfd
->section_count
, sizeof (asection
*),
2085 /* Some versions of the OSF linker put the .rdata section in the
2086 text segment, and some do not. */
2087 rdata_in_text
= ecoff_backend (abfd
)->rdata_in_text
;
2090 for (i
= 0; i
< abfd
->section_count
; i
++)
2092 current
= sorted_hdrs
[i
];
2093 if (strcmp (current
->name
, _RDATA
) == 0)
2095 if ((current
->flags
& SEC_CODE
) == 0
2096 && strcmp (current
->name
, _PDATA
) != 0
2097 && strcmp (current
->name
, _RCONST
) != 0)
2099 rdata_in_text
= false;
2104 ecoff_data (abfd
)->rdata_in_text
= rdata_in_text
;
2107 first_nonalloc
= true;
2108 for (i
= 0; i
< abfd
->section_count
; i
++)
2110 unsigned int alignment_power
;
2112 current
= sorted_hdrs
[i
];
2114 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2115 supposed to indicate the number of .pdata entries that are
2116 really in the section. Each entry is 8 bytes. We store this
2117 away in line_filepos before increasing the section size. */
2118 if (strcmp (current
->name
, _PDATA
) == 0)
2119 current
->line_filepos
= current
->_raw_size
/ 8;
2121 alignment_power
= current
->alignment_power
;
2123 /* On Ultrix, the data sections in an executable file must be
2124 aligned to a page boundary within the file. This does not
2125 affect the section size, though. FIXME: Does this work for
2126 other platforms? It requires some modification for the
2127 Alpha, because .rdata on the Alpha goes with the text, not
2129 if ((abfd
->flags
& EXEC_P
) != 0
2130 && (abfd
->flags
& D_PAGED
) != 0
2132 && (current
->flags
& SEC_CODE
) == 0
2134 || strcmp (current
->name
, _RDATA
) != 0)
2135 && strcmp (current
->name
, _PDATA
) != 0
2136 && strcmp (current
->name
, _RCONST
) != 0)
2138 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2139 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2142 else if (strcmp (current
->name
, _LIB
) == 0)
2144 /* On Irix 4, the location of contents of the .lib section
2145 from a shared library section is also rounded up to a
2148 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2149 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2151 else if (first_nonalloc
2152 && (current
->flags
& SEC_ALLOC
) == 0
2153 && (abfd
->flags
& D_PAGED
) != 0)
2155 /* Skip up to the next page for an unallocated section, such
2156 as the .comment section on the Alpha. This leaves room
2157 for the .bss section. */
2158 first_nonalloc
= false;
2159 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2160 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2163 /* Align the sections in the file to the same boundary on
2164 which they are aligned in virtual memory. */
2165 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2166 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2167 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2169 if ((abfd
->flags
& D_PAGED
) != 0
2170 && (current
->flags
& SEC_ALLOC
) != 0)
2172 sofar
+= (current
->vma
- sofar
) % round
;
2173 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2174 file_sofar
+= (current
->vma
- file_sofar
) % round
;
2177 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) != 0)
2178 current
->filepos
= file_sofar
;
2180 sofar
+= current
->_raw_size
;
2181 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2182 file_sofar
+= current
->_raw_size
;
2184 /* make sure that this section is of the right size too */
2186 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2187 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2188 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2189 current
->_raw_size
+= sofar
- old_sofar
;
2195 ecoff_data (abfd
)->reloc_filepos
= file_sofar
;
2200 /* Determine the location of the relocs for all the sections in the
2201 output file, as well as the location of the symbolic debugging
2204 static bfd_size_type
2205 ecoff_compute_reloc_file_positions (abfd
)
2208 const bfd_size_type external_reloc_size
=
2209 ecoff_backend (abfd
)->external_reloc_size
;
2210 file_ptr reloc_base
;
2211 bfd_size_type reloc_size
;
2215 if (! abfd
->output_has_begun
)
2217 if (! ecoff_compute_section_file_positions (abfd
))
2219 abfd
->output_has_begun
= true;
2222 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2225 for (current
= abfd
->sections
;
2226 current
!= (asection
*)NULL
;
2227 current
= current
->next
)
2229 if (current
->reloc_count
== 0)
2230 current
->rel_filepos
= 0;
2233 bfd_size_type relsize
;
2235 current
->rel_filepos
= reloc_base
;
2236 relsize
= current
->reloc_count
* external_reloc_size
;
2237 reloc_size
+= relsize
;
2238 reloc_base
+= relsize
;
2242 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2244 /* At least on Ultrix, the symbol table of an executable file must
2245 be aligned to a page boundary. FIXME: Is this true on other
2247 if ((abfd
->flags
& EXEC_P
) != 0
2248 && (abfd
->flags
& D_PAGED
) != 0)
2249 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2250 &~ (ecoff_backend (abfd
)->round
- 1));
2252 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2257 /* Set the contents of a section. */
2260 _bfd_ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2265 bfd_size_type count
;
2269 /* This must be done first, because bfd_set_section_contents is
2270 going to set output_has_begun to true. */
2271 if (abfd
->output_has_begun
== false)
2273 if (! ecoff_compute_section_file_positions (abfd
))
2277 /* Handle the .lib section specially so that Irix 4 shared libraries
2278 work out. See coff_set_section_contents in coffcode.h. */
2279 if (strcmp (section
->name
, _LIB
) == 0)
2281 bfd_byte
*rec
, *recend
;
2283 rec
= (bfd_byte
*) location
;
2284 recend
= rec
+ count
;
2285 while (rec
< recend
)
2288 rec
+= bfd_get_32 (abfd
, rec
) * 4;
2291 BFD_ASSERT (rec
== recend
);
2297 pos
= section
->filepos
+ offset
;
2298 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
2299 || bfd_bwrite (location
, count
, abfd
) != count
)
2305 /* Get the GP value for an ECOFF file. This is a hook used by
2309 bfd_ecoff_get_gp_value (abfd
)
2312 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2313 || bfd_get_format (abfd
) != bfd_object
)
2315 bfd_set_error (bfd_error_invalid_operation
);
2319 return ecoff_data (abfd
)->gp
;
2322 /* Set the GP value for an ECOFF file. This is a hook used by the
2326 bfd_ecoff_set_gp_value (abfd
, gp_value
)
2330 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2331 || bfd_get_format (abfd
) != bfd_object
)
2333 bfd_set_error (bfd_error_invalid_operation
);
2337 ecoff_data (abfd
)->gp
= gp_value
;
2342 /* Set the register masks for an ECOFF file. This is a hook used by
2346 bfd_ecoff_set_regmasks (abfd
, gprmask
, fprmask
, cprmask
)
2348 unsigned long gprmask
;
2349 unsigned long fprmask
;
2350 unsigned long *cprmask
;
2352 ecoff_data_type
*tdata
;
2354 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2355 || bfd_get_format (abfd
) != bfd_object
)
2357 bfd_set_error (bfd_error_invalid_operation
);
2361 tdata
= ecoff_data (abfd
);
2362 tdata
->gprmask
= gprmask
;
2363 tdata
->fprmask
= fprmask
;
2364 if (cprmask
!= (unsigned long *) NULL
)
2368 for (i
= 0; i
< 3; i
++)
2369 tdata
->cprmask
[i
] = cprmask
[i
];
2375 /* Get ECOFF EXTR information for an external symbol. This function
2376 is passed to bfd_ecoff_debug_externals. */
2379 ecoff_get_extr (sym
, esym
)
2383 ecoff_symbol_type
*ecoff_sym_ptr
;
2386 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2387 || ecoffsymbol (sym
)->native
== NULL
)
2389 /* Don't include debugging, local, or section symbols. */
2390 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2391 || (sym
->flags
& BSF_LOCAL
) != 0
2392 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2396 esym
->cobol_main
= 0;
2397 esym
->weakext
= (sym
->flags
& BSF_WEAK
) != 0;
2400 /* FIXME: we can do better than this for st and sc. */
2401 esym
->asym
.st
= stGlobal
;
2402 esym
->asym
.sc
= scAbs
;
2403 esym
->asym
.reserved
= 0;
2404 esym
->asym
.index
= indexNil
;
2408 ecoff_sym_ptr
= ecoffsymbol (sym
);
2410 if (ecoff_sym_ptr
->local
)
2413 input_bfd
= bfd_asymbol_bfd (sym
);
2414 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2415 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2417 /* If the symbol was defined by the linker, then esym will be
2418 undefined but sym will not be. Get a better class for such a
2420 if ((esym
->asym
.sc
== scUndefined
2421 || esym
->asym
.sc
== scSUndefined
)
2422 && ! bfd_is_und_section (bfd_get_section (sym
)))
2423 esym
->asym
.sc
= scAbs
;
2425 /* Adjust the FDR index for the symbol by that used for the input
2427 if (esym
->ifd
!= -1)
2429 struct ecoff_debug_info
*input_debug
;
2431 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2432 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2433 if (input_debug
->ifdmap
!= (RFDT
*) NULL
)
2434 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2440 /* Set the external symbol index. This routine is passed to
2441 bfd_ecoff_debug_externals. */
2444 ecoff_set_index (sym
, indx
)
2448 ecoff_set_sym_index (sym
, indx
);
2451 /* Write out an ECOFF file. */
2454 _bfd_ecoff_write_object_contents (abfd
)
2457 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2458 const bfd_vma round
= backend
->round
;
2459 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2460 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2461 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2462 const bfd_size_type external_hdr_size
2463 = backend
->debug_swap
.external_hdr_size
;
2464 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2465 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2467 struct internal_reloc
*))
2468 = backend
->adjust_reloc_out
;
2469 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2470 const struct internal_reloc
*,
2472 = backend
->swap_reloc_out
;
2473 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2474 HDRR
* const symhdr
= &debug
->symbolic_header
;
2477 bfd_size_type reloc_size
;
2478 bfd_size_type text_size
;
2480 boolean set_text_start
;
2481 bfd_size_type data_size
;
2483 boolean set_data_start
;
2484 bfd_size_type bss_size
;
2486 PTR reloc_buff
= NULL
;
2487 struct internal_filehdr internal_f
;
2488 struct internal_aouthdr internal_a
;
2491 /* Determine where the sections and relocs will go in the output
2493 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2496 for (current
= abfd
->sections
;
2497 current
!= (asection
*)NULL
;
2498 current
= current
->next
)
2500 current
->target_index
= count
;
2504 if ((abfd
->flags
& D_PAGED
) != 0)
2505 text_size
= _bfd_ecoff_sizeof_headers (abfd
, false);
2509 set_text_start
= false;
2512 set_data_start
= false;
2515 /* Write section headers to the file. */
2517 /* Allocate buff big enough to hold a section header,
2518 file header, or a.out header. */
2526 buff
= (PTR
) bfd_malloc (siz
);
2531 internal_f
.f_nscns
= 0;
2532 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2534 for (current
= abfd
->sections
;
2535 current
!= (asection
*) NULL
;
2536 current
= current
->next
)
2538 struct internal_scnhdr section
;
2541 ++internal_f
.f_nscns
;
2543 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2545 /* This seems to be correct for Irix 4 shared libraries. */
2546 vma
= bfd_get_section_vma (abfd
, current
);
2547 if (strcmp (current
->name
, _LIB
) == 0)
2548 section
.s_vaddr
= 0;
2550 section
.s_vaddr
= vma
;
2552 section
.s_paddr
= current
->lma
;
2553 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2555 /* If this section is unloadable then the scnptr will be 0. */
2556 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2557 section
.s_scnptr
= 0;
2559 section
.s_scnptr
= current
->filepos
;
2560 section
.s_relptr
= current
->rel_filepos
;
2562 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2563 object file produced by the assembler is supposed to point to
2564 information about how much room is required by objects of
2565 various different sizes. I think this only matters if we
2566 want the linker to compute the best size to use, or
2567 something. I don't know what happens if the information is
2569 if (strcmp (current
->name
, _PDATA
) != 0)
2570 section
.s_lnnoptr
= 0;
2573 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2574 hold the number of entries in the section (each entry is
2575 8 bytes). We stored this in the line_filepos field in
2576 ecoff_compute_section_file_positions. */
2577 section
.s_lnnoptr
= current
->line_filepos
;
2580 section
.s_nreloc
= current
->reloc_count
;
2581 section
.s_nlnno
= 0;
2582 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2585 if (bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
) == 0
2586 || bfd_bwrite (buff
, scnhsz
, abfd
) != scnhsz
)
2589 if ((section
.s_flags
& STYP_TEXT
) != 0
2590 || ((section
.s_flags
& STYP_RDATA
) != 0
2591 && ecoff_data (abfd
)->rdata_in_text
)
2592 || section
.s_flags
== STYP_PDATA
2593 || (section
.s_flags
& STYP_DYNAMIC
) != 0
2594 || (section
.s_flags
& STYP_LIBLIST
) != 0
2595 || (section
.s_flags
& STYP_RELDYN
) != 0
2596 || section
.s_flags
== STYP_CONFLIC
2597 || (section
.s_flags
& STYP_DYNSTR
) != 0
2598 || (section
.s_flags
& STYP_DYNSYM
) != 0
2599 || (section
.s_flags
& STYP_HASH
) != 0
2600 || (section
.s_flags
& STYP_ECOFF_INIT
) != 0
2601 || (section
.s_flags
& STYP_ECOFF_FINI
) != 0
2602 || section
.s_flags
== STYP_RCONST
)
2604 text_size
+= bfd_get_section_size_before_reloc (current
);
2605 if (! set_text_start
|| text_start
> vma
)
2608 set_text_start
= true;
2611 else if ((section
.s_flags
& STYP_RDATA
) != 0
2612 || (section
.s_flags
& STYP_DATA
) != 0
2613 || (section
.s_flags
& STYP_LITA
) != 0
2614 || (section
.s_flags
& STYP_LIT8
) != 0
2615 || (section
.s_flags
& STYP_LIT4
) != 0
2616 || (section
.s_flags
& STYP_SDATA
) != 0
2617 || section
.s_flags
== STYP_XDATA
2618 || (section
.s_flags
& STYP_GOT
) != 0)
2620 data_size
+= bfd_get_section_size_before_reloc (current
);
2621 if (! set_data_start
|| data_start
> vma
)
2624 set_data_start
= true;
2627 else if ((section
.s_flags
& STYP_BSS
) != 0
2628 || (section
.s_flags
& STYP_SBSS
) != 0)
2629 bss_size
+= bfd_get_section_size_before_reloc (current
);
2630 else if (section
.s_flags
== 0
2631 || (section
.s_flags
& STYP_ECOFF_LIB
) != 0
2632 || section
.s_flags
== STYP_COMMENT
)
2638 /* Set up the file header. */
2640 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2642 /* We will NOT put a fucking timestamp in the header here. Every
2643 time you put it back, I will come in and take it out again. I'm
2644 sorry. This field does not belong here. We fill it with a 0 so
2645 it compares the same but is not a reasonable time. --
2647 internal_f
.f_timdat
= 0;
2649 if (bfd_get_symcount (abfd
) != 0)
2651 /* The ECOFF f_nsyms field is not actually the number of
2652 symbols, it's the size of symbolic information header. */
2653 internal_f
.f_nsyms
= external_hdr_size
;
2654 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2658 internal_f
.f_nsyms
= 0;
2659 internal_f
.f_symptr
= 0;
2662 internal_f
.f_opthdr
= aoutsz
;
2664 internal_f
.f_flags
= F_LNNO
;
2665 if (reloc_size
== 0)
2666 internal_f
.f_flags
|= F_RELFLG
;
2667 if (bfd_get_symcount (abfd
) == 0)
2668 internal_f
.f_flags
|= F_LSYMS
;
2669 if (abfd
->flags
& EXEC_P
)
2670 internal_f
.f_flags
|= F_EXEC
;
2672 if (bfd_little_endian (abfd
))
2673 internal_f
.f_flags
|= F_AR32WR
;
2675 internal_f
.f_flags
|= F_AR32W
;
2677 /* Set up the ``optional'' header. */
2678 if ((abfd
->flags
& D_PAGED
) != 0)
2679 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2681 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2683 /* FIXME: Is this really correct? */
2684 internal_a
.vstamp
= symhdr
->vstamp
;
2686 /* At least on Ultrix, these have to be rounded to page boundaries.
2687 FIXME: Is this true on other platforms? */
2688 if ((abfd
->flags
& D_PAGED
) != 0)
2690 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2691 internal_a
.text_start
= text_start
&~ (round
- 1);
2692 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2693 internal_a
.data_start
= data_start
&~ (round
- 1);
2697 internal_a
.tsize
= text_size
;
2698 internal_a
.text_start
= text_start
;
2699 internal_a
.dsize
= data_size
;
2700 internal_a
.data_start
= data_start
;
2703 /* On Ultrix, the initial portions of the .sbss and .bss segments
2704 are at the end of the data section. The bsize field in the
2705 optional header records how many bss bytes are required beyond
2706 those in the data section. The value is not rounded to a page
2708 if (bss_size
< internal_a
.dsize
- data_size
)
2711 bss_size
-= internal_a
.dsize
- data_size
;
2712 internal_a
.bsize
= bss_size
;
2713 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2715 internal_a
.entry
= bfd_get_start_address (abfd
);
2717 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2719 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2720 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2721 for (i
= 0; i
< 4; i
++)
2722 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2724 /* Let the backend adjust the headers if necessary. */
2725 if (backend
->adjust_headers
)
2727 if (! (*backend
->adjust_headers
) (abfd
, &internal_f
, &internal_a
))
2731 /* Write out the file header and the optional header. */
2733 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2736 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2737 if (bfd_bwrite (buff
, filhsz
, abfd
) != filhsz
)
2740 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2741 if (bfd_bwrite (buff
, aoutsz
, abfd
) != aoutsz
)
2744 /* Build the external symbol information. This must be done before
2745 writing out the relocs so that we know the symbol indices. We
2746 don't do this if this BFD was created by the backend linker,
2747 since it will have already handled the symbols and relocs. */
2748 if (! ecoff_data (abfd
)->linker
)
2750 symhdr
->iextMax
= 0;
2751 symhdr
->issExtMax
= 0;
2752 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2753 debug
->ssext
= debug
->ssext_end
= NULL
;
2754 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2755 (((abfd
->flags
& EXEC_P
) == 0)
2757 ecoff_get_extr
, ecoff_set_index
)
2761 /* Write out the relocs. */
2762 for (current
= abfd
->sections
;
2763 current
!= (asection
*) NULL
;
2764 current
= current
->next
)
2766 arelent
**reloc_ptr_ptr
;
2767 arelent
**reloc_end
;
2771 if (current
->reloc_count
== 0)
2774 amt
= current
->reloc_count
* external_reloc_size
;
2775 reloc_buff
= bfd_alloc (abfd
, amt
);
2776 if (reloc_buff
== NULL
)
2779 reloc_ptr_ptr
= current
->orelocation
;
2780 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2781 out_ptr
= (char *) reloc_buff
;
2783 reloc_ptr_ptr
< reloc_end
;
2784 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2788 struct internal_reloc in
;
2790 memset ((PTR
) &in
, 0, sizeof in
);
2792 reloc
= *reloc_ptr_ptr
;
2793 sym
= *reloc
->sym_ptr_ptr
;
2795 in
.r_vaddr
= (reloc
->address
2796 + bfd_get_section_vma (abfd
, current
));
2797 in
.r_type
= reloc
->howto
->type
;
2799 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2801 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2808 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2809 if (strcmp (name
, ".text") == 0)
2810 in
.r_symndx
= RELOC_SECTION_TEXT
;
2811 else if (strcmp (name
, ".rdata") == 0)
2812 in
.r_symndx
= RELOC_SECTION_RDATA
;
2813 else if (strcmp (name
, ".data") == 0)
2814 in
.r_symndx
= RELOC_SECTION_DATA
;
2815 else if (strcmp (name
, ".sdata") == 0)
2816 in
.r_symndx
= RELOC_SECTION_SDATA
;
2817 else if (strcmp (name
, ".sbss") == 0)
2818 in
.r_symndx
= RELOC_SECTION_SBSS
;
2819 else if (strcmp (name
, ".bss") == 0)
2820 in
.r_symndx
= RELOC_SECTION_BSS
;
2821 else if (strcmp (name
, ".init") == 0)
2822 in
.r_symndx
= RELOC_SECTION_INIT
;
2823 else if (strcmp (name
, ".lit8") == 0)
2824 in
.r_symndx
= RELOC_SECTION_LIT8
;
2825 else if (strcmp (name
, ".lit4") == 0)
2826 in
.r_symndx
= RELOC_SECTION_LIT4
;
2827 else if (strcmp (name
, ".xdata") == 0)
2828 in
.r_symndx
= RELOC_SECTION_XDATA
;
2829 else if (strcmp (name
, ".pdata") == 0)
2830 in
.r_symndx
= RELOC_SECTION_PDATA
;
2831 else if (strcmp (name
, ".fini") == 0)
2832 in
.r_symndx
= RELOC_SECTION_FINI
;
2833 else if (strcmp (name
, ".lita") == 0)
2834 in
.r_symndx
= RELOC_SECTION_LITA
;
2835 else if (strcmp (name
, "*ABS*") == 0)
2836 in
.r_symndx
= RELOC_SECTION_ABS
;
2837 else if (strcmp (name
, ".rconst") == 0)
2838 in
.r_symndx
= RELOC_SECTION_RCONST
;
2844 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2846 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2849 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2851 amt
= current
->reloc_count
* external_reloc_size
;
2852 if (bfd_bwrite (reloc_buff
, amt
, abfd
) != amt
)
2854 bfd_release (abfd
, reloc_buff
);
2858 /* Write out the symbolic debugging information. */
2859 if (bfd_get_symcount (abfd
) > 0)
2861 /* Write out the debugging information. */
2862 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2863 ecoff_data (abfd
)->sym_filepos
)
2869 /* The .bss section of a demand paged executable must receive an
2870 entire page. If there are symbols, the symbols will start on the
2871 next page. If there are no symbols, we must fill out the page by
2873 if (bfd_get_symcount (abfd
) == 0
2874 && (abfd
->flags
& EXEC_P
) != 0
2875 && (abfd
->flags
& D_PAGED
) != 0)
2879 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2882 if (bfd_bread (&c
, (bfd_size_type
) 1, abfd
) == 0)
2884 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2887 if (bfd_bwrite (&c
, (bfd_size_type
) 1, abfd
) != 1)
2891 if (reloc_buff
!= NULL
)
2892 bfd_release (abfd
, reloc_buff
);
2897 if (reloc_buff
!= NULL
)
2898 bfd_release (abfd
, reloc_buff
);
2904 /* Archive handling. ECOFF uses what appears to be a unique type of
2905 archive header (armap). The byte ordering of the armap and the
2906 contents are encoded in the name of the armap itself. At least for
2907 now, we only support archives with the same byte ordering in the
2908 armap and the contents.
2910 The first four bytes in the armap are the number of symbol
2911 definitions. This is always a power of two.
2913 This is followed by the symbol definitions. Each symbol definition
2914 occupies 8 bytes. The first four bytes are the offset from the
2915 start of the armap strings to the null-terminated string naming
2916 this symbol. The second four bytes are the file offset to the
2917 archive member which defines this symbol. If the second four bytes
2918 are 0, then this is not actually a symbol definition, and it should
2921 The symbols are hashed into the armap with a closed hashing scheme.
2922 See the functions below for the details of the algorithm.
2924 After the symbol definitions comes four bytes holding the size of
2925 the string table, followed by the string table itself. */
2927 /* The name of an archive headers looks like this:
2928 __________E[BL]E[BL]_ (with a trailing space).
2929 The trailing space is changed to an X if the archive is changed to
2930 indicate that the armap is out of date.
2932 The Alpha seems to use ________64E[BL]E[BL]_. */
2934 #define ARMAP_BIG_ENDIAN 'B'
2935 #define ARMAP_LITTLE_ENDIAN 'L'
2936 #define ARMAP_MARKER 'E'
2937 #define ARMAP_START_LENGTH 10
2938 #define ARMAP_HEADER_MARKER_INDEX 10
2939 #define ARMAP_HEADER_ENDIAN_INDEX 11
2940 #define ARMAP_OBJECT_MARKER_INDEX 12
2941 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2942 #define ARMAP_END_INDEX 14
2943 #define ARMAP_END "_ "
2945 /* This is a magic number used in the hashing algorithm. */
2946 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2948 /* This returns the hash value to use for a string. It also sets
2949 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2950 is the number of entries in the hash table, and HLOG is the log
2954 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2956 unsigned int *rehash
;
2966 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2967 hash
*= ARMAP_HASH_MAGIC
;
2968 *rehash
= (hash
& (size
- 1)) | 1;
2969 return hash
>> (32 - hlog
);
2972 /* Read in the armap. */
2975 _bfd_ecoff_slurp_armap (abfd
)
2980 struct areltdata
*mapdata
;
2981 bfd_size_type parsed_size
;
2983 struct artdata
*ardata
;
2986 struct symdef
*symdef_ptr
;
2990 /* Get the name of the first element. */
2991 i
= bfd_bread ((PTR
) nextname
, (bfd_size_type
) 16, abfd
);
2997 if (bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
) != 0)
3000 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
3001 standard COFF armap. We could move the ECOFF armap stuff into
3002 bfd_slurp_armap, but that seems inappropriate since no other
3003 target uses this format. Instead, we check directly for a COFF
3005 if (strncmp (nextname
, "/ ", 16) == 0)
3006 return bfd_slurp_armap (abfd
);
3008 /* See if the first element is an armap. */
3009 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
3010 ARMAP_START_LENGTH
) != 0
3011 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
3012 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3013 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3014 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
3015 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
3016 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
3017 || strncmp (nextname
+ ARMAP_END_INDEX
,
3018 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
3020 bfd_has_map (abfd
) = false;
3024 /* Make sure we have the right byte ordering. */
3025 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3026 ^ (bfd_header_big_endian (abfd
)))
3027 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
3028 ^ (bfd_big_endian (abfd
))))
3030 bfd_set_error (bfd_error_wrong_format
);
3034 /* Read in the armap. */
3035 ardata
= bfd_ardata (abfd
);
3036 mapdata
= (struct areltdata
*) _bfd_read_ar_hdr (abfd
);
3037 if (mapdata
== (struct areltdata
*) NULL
)
3039 parsed_size
= mapdata
->parsed_size
;
3040 bfd_release (abfd
, (PTR
) mapdata
);
3042 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
3043 if (raw_armap
== (char *) NULL
)
3046 if (bfd_bread ((PTR
) raw_armap
, parsed_size
, abfd
) != parsed_size
)
3048 if (bfd_get_error () != bfd_error_system_call
)
3049 bfd_set_error (bfd_error_malformed_archive
);
3050 bfd_release (abfd
, (PTR
) raw_armap
);
3054 ardata
->tdata
= (PTR
) raw_armap
;
3056 count
= H_GET_32 (abfd
, raw_armap
);
3058 ardata
->symdef_count
= 0;
3059 ardata
->cache
= (struct ar_cache
*) NULL
;
3061 /* This code used to overlay the symdefs over the raw archive data,
3062 but that doesn't work on a 64 bit host. */
3064 stringbase
= raw_armap
+ count
* 8 + 8;
3066 #ifdef CHECK_ARMAP_HASH
3070 /* Double check that I have the hashing algorithm right by making
3071 sure that every symbol can be looked up successfully. */
3073 for (i
= 1; i
< count
; i
<<= 1)
3075 BFD_ASSERT (i
== count
);
3077 raw_ptr
= raw_armap
+ 4;
3078 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3080 unsigned int name_offset
, file_offset
;
3081 unsigned int hash
, rehash
, srch
;
3083 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3084 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3085 if (file_offset
== 0)
3087 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3092 /* See if we can rehash to this location. */
3093 for (srch
= (hash
+ rehash
) & (count
- 1);
3094 srch
!= hash
&& srch
!= i
;
3095 srch
= (srch
+ rehash
) & (count
- 1))
3096 BFD_ASSERT (H_GET_32 (abfd
, (raw_armap
+ 8 + srch
* 8)) != 0);
3097 BFD_ASSERT (srch
== i
);
3101 #endif /* CHECK_ARMAP_HASH */
3103 raw_ptr
= raw_armap
+ 4;
3104 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3105 if (H_GET_32 (abfd
, (raw_ptr
+ 4)) != 0)
3106 ++ardata
->symdef_count
;
3108 amt
= ardata
->symdef_count
;
3109 amt
*= sizeof (struct symdef
);
3110 symdef_ptr
= (struct symdef
*) bfd_alloc (abfd
, amt
);
3114 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3116 raw_ptr
= raw_armap
+ 4;
3117 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3119 unsigned int name_offset
, file_offset
;
3121 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3122 if (file_offset
== 0)
3124 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3125 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3126 symdef_ptr
->file_offset
= file_offset
;
3130 ardata
->first_file_filepos
= bfd_tell (abfd
);
3131 /* Pad to an even boundary. */
3132 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3134 bfd_has_map (abfd
) = true;
3139 /* Write out an armap. */
3142 _bfd_ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3144 unsigned int elength
;
3146 unsigned int orl_count
;
3149 unsigned int hashsize
, hashlog
;
3150 bfd_size_type symdefsize
;
3152 unsigned int stringsize
;
3153 unsigned int mapsize
;
3156 struct stat statbuf
;
3159 bfd_byte
*hashtable
;
3163 /* Ultrix appears to use as a hash table size the least power of two
3164 greater than twice the number of entries. */
3165 for (hashlog
= 0; ((unsigned int) 1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3167 hashsize
= 1 << hashlog
;
3169 symdefsize
= hashsize
* 8;
3171 stringsize
= stridx
+ padit
;
3173 /* Include 8 bytes to store symdefsize and stringsize in output. */
3174 mapsize
= symdefsize
+ stringsize
+ 8;
3176 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3178 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3180 /* Work out the ECOFF armap name. */
3181 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3182 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3183 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3184 (bfd_header_big_endian (abfd
)
3186 : ARMAP_LITTLE_ENDIAN
);
3187 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3188 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3189 bfd_big_endian (abfd
) ? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3190 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3192 /* Write the timestamp of the archive header to be just a little bit
3193 later than the timestamp of the file, otherwise the linker will
3194 complain that the index is out of date. Actually, the Ultrix
3195 linker just checks the archive name; the GNU linker may check the
3197 stat (abfd
->filename
, &statbuf
);
3198 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3200 /* The DECstation uses zeroes for the uid, gid and mode of the
3202 hdr
.ar_uid
[0] = '0';
3203 hdr
.ar_gid
[0] = '0';
3205 hdr
.ar_mode
[0] = '0';
3207 /* Building gcc ends up extracting the armap as a file - twice. */
3208 hdr
.ar_mode
[0] = '6';
3209 hdr
.ar_mode
[1] = '4';
3210 hdr
.ar_mode
[2] = '4';
3213 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3215 hdr
.ar_fmag
[0] = '`';
3216 hdr
.ar_fmag
[1] = '\012';
3218 /* Turn all null bytes in the header into spaces. */
3219 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3220 if (((char *) (&hdr
))[i
] == '\0')
3221 (((char *) (&hdr
))[i
]) = ' ';
3223 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) sizeof (struct ar_hdr
), abfd
)
3224 != sizeof (struct ar_hdr
))
3227 H_PUT_32 (abfd
, hashsize
, temp
);
3228 if (bfd_bwrite ((PTR
) temp
, (bfd_size_type
) 4, abfd
) != 4)
3231 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3235 current
= abfd
->archive_head
;
3237 for (i
= 0; i
< orl_count
; i
++)
3239 unsigned int hash
, rehash
;
3241 /* Advance firstreal to the file position of this archive
3243 if (map
[i
].u
.abfd
!= last_elt
)
3247 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3248 firstreal
+= firstreal
% 2;
3249 current
= current
->next
;
3251 while (current
!= map
[i
].u
.abfd
);
3256 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3257 if (H_GET_32 (abfd
, (hashtable
+ (hash
* 8) + 4)) != 0)
3261 /* The desired slot is already taken. */
3262 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3264 srch
= (srch
+ rehash
) & (hashsize
- 1))
3265 if (H_GET_32 (abfd
, (hashtable
+ (srch
* 8) + 4)) == 0)
3268 BFD_ASSERT (srch
!= hash
);
3273 H_PUT_32 (abfd
, map
[i
].namidx
, (hashtable
+ hash
* 8));
3274 H_PUT_32 (abfd
, firstreal
, (hashtable
+ hash
* 8 + 4));
3277 if (bfd_bwrite ((PTR
) hashtable
, symdefsize
, abfd
) != symdefsize
)
3280 bfd_release (abfd
, hashtable
);
3282 /* Now write the strings. */
3283 H_PUT_32 (abfd
, stringsize
, temp
);
3284 if (bfd_bwrite ((PTR
) temp
, (bfd_size_type
) 4, abfd
) != 4)
3286 for (i
= 0; i
< orl_count
; i
++)
3290 len
= strlen (*map
[i
].name
) + 1;
3291 if (bfd_bwrite ((PTR
) (*map
[i
].name
), len
, abfd
) != len
)
3295 /* The spec sez this should be a newline. But in order to be
3296 bug-compatible for DECstation ar we use a null. */
3299 if (bfd_bwrite ("", (bfd_size_type
) 1, abfd
) != 1)
3306 /* See whether this BFD is an archive. If it is, read in the armap
3307 and the extended name table. */
3310 _bfd_ecoff_archive_p (abfd
)
3313 struct artdata
*tdata_hold
;
3314 char armag
[SARMAG
+ 1];
3317 tdata_hold
= abfd
->tdata
.aout_ar_data
;
3319 if (bfd_bread ((PTR
) armag
, (bfd_size_type
) SARMAG
, abfd
) != SARMAG
)
3321 if (bfd_get_error () != bfd_error_system_call
)
3322 bfd_set_error (bfd_error_wrong_format
);
3323 return (const bfd_target
*) NULL
;
3326 if (strncmp (armag
, ARMAG
, SARMAG
) != 0)
3328 bfd_set_error (bfd_error_wrong_format
);
3332 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3333 involves a cast, we can't do it as the left operand of
3335 amt
= sizeof (struct artdata
);
3336 abfd
->tdata
.aout_ar_data
= (struct artdata
*) bfd_zalloc (abfd
, amt
);
3338 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3340 abfd
->tdata
.aout_ar_data
= tdata_hold
;
3341 return (const bfd_target
*) NULL
;
3344 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3345 bfd_ardata (abfd
)->cache
= NULL
;
3346 bfd_ardata (abfd
)->archive_head
= NULL
;
3347 bfd_ardata (abfd
)->symdefs
= NULL
;
3348 bfd_ardata (abfd
)->extended_names
= NULL
;
3349 bfd_ardata (abfd
)->tdata
= NULL
;
3351 if (_bfd_ecoff_slurp_armap (abfd
) == false
3352 || _bfd_ecoff_slurp_extended_name_table (abfd
) == false)
3354 bfd_release (abfd
, bfd_ardata (abfd
));
3355 abfd
->tdata
.aout_ar_data
= tdata_hold
;
3356 return (const bfd_target
*) NULL
;
3359 if (bfd_has_map (abfd
))
3363 /* This archive has a map, so we may presume that the contents
3364 are object files. Make sure that if the first file in the
3365 archive can be recognized as an object file, it is for this
3366 target. If not, assume that this is the wrong format. If
3367 the first file is not an object file, somebody is doing
3368 something weird, and we permit it so that ar -t will work. */
3370 first
= bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
);
3375 first
->target_defaulted
= false;
3377 if (bfd_check_format (first
, bfd_object
)
3378 && first
->xvec
!= abfd
->xvec
)
3380 (void) bfd_close (first
);
3381 bfd_release (abfd
, bfd_ardata (abfd
));
3382 abfd
->tdata
.aout_ar_data
= tdata_hold
;
3383 bfd_set_error (bfd_error_wrong_format
);
3387 /* We ought to close first here, but we can't, because we
3388 have no way to remove it from the archive cache. FIXME. */
3395 /* ECOFF linker code. */
3397 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3398 PARAMS ((struct bfd_hash_entry
*entry
,
3399 struct bfd_hash_table
*table
,
3400 const char *string
));
3401 static boolean ecoff_link_add_archive_symbols
3402 PARAMS ((bfd
*, struct bfd_link_info
*));
3403 static boolean ecoff_link_check_archive_element
3404 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3405 static boolean ecoff_link_add_object_symbols
3406 PARAMS ((bfd
*, struct bfd_link_info
*));
3407 static boolean ecoff_link_add_externals
3408 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3410 /* Routine to create an entry in an ECOFF link hash table. */
3412 static struct bfd_hash_entry
*
3413 ecoff_link_hash_newfunc (entry
, table
, string
)
3414 struct bfd_hash_entry
*entry
;
3415 struct bfd_hash_table
*table
;
3418 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3420 /* Allocate the structure if it has not already been allocated by a
3422 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3423 ret
= ((struct ecoff_link_hash_entry
*)
3424 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3425 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3428 /* Call the allocation method of the superclass. */
3429 ret
= ((struct ecoff_link_hash_entry
*)
3430 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3435 /* Set local fields. */
3441 memset ((PTR
) &ret
->esym
, 0, sizeof ret
->esym
);
3443 return (struct bfd_hash_entry
*) ret
;
3446 /* Create an ECOFF link hash table. */
3448 struct bfd_link_hash_table
*
3449 _bfd_ecoff_bfd_link_hash_table_create (abfd
)
3452 struct ecoff_link_hash_table
*ret
;
3453 bfd_size_type amt
= sizeof (struct ecoff_link_hash_table
);
3455 ret
= (struct ecoff_link_hash_table
*) bfd_malloc (amt
);
3458 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3459 ecoff_link_hash_newfunc
))
3462 return (struct bfd_link_hash_table
*) NULL
;
3467 /* Look up an entry in an ECOFF link hash table. */
3469 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3470 ((struct ecoff_link_hash_entry *) \
3471 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3473 /* Traverse an ECOFF link hash table. */
3475 #define ecoff_link_hash_traverse(table, func, info) \
3476 (bfd_link_hash_traverse \
3478 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
3481 /* Get the ECOFF link hash table from the info structure. This is
3484 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3486 /* Given an ECOFF BFD, add symbols to the global hash table as
3490 _bfd_ecoff_bfd_link_add_symbols (abfd
, info
)
3492 struct bfd_link_info
*info
;
3494 switch (bfd_get_format (abfd
))
3497 return ecoff_link_add_object_symbols (abfd
, info
);
3499 return ecoff_link_add_archive_symbols (abfd
, info
);
3501 bfd_set_error (bfd_error_wrong_format
);
3506 /* Add the symbols from an archive file to the global hash table.
3507 This looks through the undefined symbols, looks each one up in the
3508 archive hash table, and adds any associated object file. We do not
3509 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3510 already have a hash table, so there is no reason to construct
3514 ecoff_link_add_archive_symbols (abfd
, info
)
3516 struct bfd_link_info
*info
;
3518 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3519 const bfd_byte
*raw_armap
;
3520 struct bfd_link_hash_entry
**pundef
;
3521 unsigned int armap_count
;
3522 unsigned int armap_log
;
3524 const bfd_byte
*hashtable
;
3525 const char *stringbase
;
3527 if (! bfd_has_map (abfd
))
3529 /* An empty archive is a special case. */
3530 if (bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
) == NULL
)
3532 bfd_set_error (bfd_error_no_armap
);
3536 /* If we don't have any raw data for this archive, as can happen on
3537 Irix 4.0.5F, we call the generic routine.
3538 FIXME: We should be more clever about this, since someday tdata
3539 may get to something for a generic archive. */
3540 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3541 if (raw_armap
== (bfd_byte
*) NULL
)
3542 return (_bfd_generic_link_add_archive_symbols
3543 (abfd
, info
, ecoff_link_check_archive_element
));
3545 armap_count
= H_GET_32 (abfd
, raw_armap
);
3548 for (i
= 1; i
< armap_count
; i
<<= 1)
3550 BFD_ASSERT (i
== armap_count
);
3552 hashtable
= raw_armap
+ 4;
3553 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3555 /* Look through the list of undefined symbols. */
3556 pundef
= &info
->hash
->undefs
;
3557 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3559 struct bfd_link_hash_entry
*h
;
3560 unsigned int hash
, rehash
;
3561 unsigned int file_offset
;
3567 /* When a symbol is defined, it is not necessarily removed from
3569 if (h
->type
!= bfd_link_hash_undefined
3570 && h
->type
!= bfd_link_hash_common
)
3572 /* Remove this entry from the list, for general cleanliness
3573 and because we are going to look through the list again
3574 if we search any more libraries. We can't remove the
3575 entry if it is the tail, because that would lose any
3576 entries we add to the list later on. */
3577 if (*pundef
!= info
->hash
->undefs_tail
)
3578 *pundef
= (*pundef
)->next
;
3580 pundef
= &(*pundef
)->next
;
3584 /* Native ECOFF linkers do not pull in archive elements merely
3585 to satisfy common definitions, so neither do we. We leave
3586 them on the list, though, in case we are linking against some
3587 other object format. */
3588 if (h
->type
!= bfd_link_hash_undefined
)
3590 pundef
= &(*pundef
)->next
;
3594 /* Look for this symbol in the archive hash table. */
3595 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3598 file_offset
= H_GET_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3599 if (file_offset
== 0)
3601 /* Nothing in this slot. */
3602 pundef
= &(*pundef
)->next
;
3606 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (hash
* 8));
3607 if (name
[0] != h
->root
.string
[0]
3608 || strcmp (name
, h
->root
.string
) != 0)
3613 /* That was the wrong symbol. Try rehashing. */
3615 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3617 srch
= (srch
+ rehash
) & (armap_count
- 1))
3619 file_offset
= H_GET_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3620 if (file_offset
== 0)
3622 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (srch
* 8));
3623 if (name
[0] == h
->root
.string
[0]
3624 && strcmp (name
, h
->root
.string
) == 0)
3633 pundef
= &(*pundef
)->next
;
3640 element
= (*backend
->get_elt_at_filepos
) (abfd
, (file_ptr
) file_offset
);
3641 if (element
== (bfd
*) NULL
)
3644 if (! bfd_check_format (element
, bfd_object
))
3647 /* Unlike the generic linker, we know that this element provides
3648 a definition for an undefined symbol and we know that we want
3649 to include it. We don't need to check anything. */
3650 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3652 if (! ecoff_link_add_object_symbols (element
, info
))
3655 pundef
= &(*pundef
)->next
;
3661 /* This is called if we used _bfd_generic_link_add_archive_symbols
3662 because we were not dealing with an ECOFF archive. */
3665 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3667 struct bfd_link_info
*info
;
3670 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3671 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3672 = backend
->debug_swap
.swap_ext_in
;
3674 bfd_size_type external_ext_size
;
3675 PTR external_ext
= NULL
;
3676 bfd_size_type esize
;
3683 if (! ecoff_slurp_symbolic_header (abfd
))
3686 /* If there are no symbols, we don't want it. */
3687 if (bfd_get_symcount (abfd
) == 0)
3688 goto successful_return
;
3690 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3692 /* Read in the external symbols and external strings. */
3693 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3694 esize
= symhdr
->iextMax
* external_ext_size
;
3695 external_ext
= (PTR
) bfd_malloc (esize
);
3696 if (external_ext
== NULL
&& esize
!= 0)
3699 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbExtOffset
, SEEK_SET
) != 0
3700 || bfd_bread (external_ext
, esize
, abfd
) != esize
)
3703 ssext
= (char *) bfd_malloc ((bfd_size_type
) symhdr
->issExtMax
);
3704 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3707 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3708 || (bfd_bread (ssext
, (bfd_size_type
) symhdr
->issExtMax
, abfd
)
3709 != (bfd_size_type
) symhdr
->issExtMax
))
3712 /* Look through the external symbols to see if they define some
3713 symbol that is currently undefined. */
3714 ext_ptr
= (char *) external_ext
;
3715 ext_end
= ext_ptr
+ esize
;
3716 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3721 struct bfd_link_hash_entry
*h
;
3723 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3725 /* See if this symbol defines something. */
3726 if (esym
.asym
.st
!= stGlobal
3727 && esym
.asym
.st
!= stLabel
3728 && esym
.asym
.st
!= stProc
)
3731 switch (esym
.asym
.sc
)
3755 name
= ssext
+ esym
.asym
.iss
;
3756 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3758 /* Unlike the generic linker, we do not pull in elements because
3759 of common symbols. */
3760 if (h
== (struct bfd_link_hash_entry
*) NULL
3761 || h
->type
!= bfd_link_hash_undefined
)
3764 /* Include this element. */
3765 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3767 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3771 goto successful_return
;
3775 if (external_ext
!= NULL
)
3776 free (external_ext
);
3781 if (external_ext
!= NULL
)
3782 free (external_ext
);
3788 /* Add symbols from an ECOFF object file to the global linker hash
3792 ecoff_link_add_object_symbols (abfd
, info
)
3794 struct bfd_link_info
*info
;
3797 bfd_size_type external_ext_size
;
3798 PTR external_ext
= NULL
;
3799 bfd_size_type esize
;
3803 if (! ecoff_slurp_symbolic_header (abfd
))
3806 /* If there are no symbols, we don't want it. */
3807 if (bfd_get_symcount (abfd
) == 0)
3810 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3812 /* Read in the external symbols and external strings. */
3813 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3814 esize
= symhdr
->iextMax
* external_ext_size
;
3815 external_ext
= (PTR
) bfd_malloc (esize
);
3816 if (external_ext
== NULL
&& esize
!= 0)
3819 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbExtOffset
, SEEK_SET
) != 0
3820 || bfd_bread (external_ext
, esize
, abfd
) != esize
)
3823 ssext
= (char *) bfd_malloc ((bfd_size_type
) symhdr
->issExtMax
);
3824 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3827 if (bfd_seek (abfd
, (file_ptr
) symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3828 || (bfd_bread (ssext
, (bfd_size_type
) symhdr
->issExtMax
, abfd
)
3829 != (bfd_size_type
) symhdr
->issExtMax
))
3832 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3836 if (external_ext
!= NULL
)
3837 free (external_ext
);
3843 if (external_ext
!= NULL
)
3844 free (external_ext
);
3848 /* Add the external symbols of an object file to the global linker
3849 hash table. The external symbols and strings we are passed are
3850 just allocated on the stack, and will be discarded. We must
3851 explicitly save any information we may need later on in the link.
3852 We do not want to read the external symbol information again. */
3855 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3857 struct bfd_link_info
*info
;
3861 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3862 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3863 = backend
->debug_swap
.swap_ext_in
;
3864 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3865 unsigned long ext_count
;
3866 struct ecoff_link_hash_entry
**sym_hash
;
3871 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3874 amt
*= sizeof (struct bfd_link_hash_entry
*);
3875 sym_hash
= (struct ecoff_link_hash_entry
**) bfd_alloc (abfd
, amt
);
3878 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3880 ext_ptr
= (char *) external_ext
;
3881 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3882 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3889 struct ecoff_link_hash_entry
*h
;
3893 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3895 /* Skip debugging symbols. */
3897 switch (esym
.asym
.st
)
3913 /* Get the information for this symbol. */
3914 value
= esym
.asym
.value
;
3915 switch (esym
.asym
.sc
)
3935 section
= bfd_make_section_old_way (abfd
, ".text");
3936 value
-= section
->vma
;
3939 section
= bfd_make_section_old_way (abfd
, ".data");
3940 value
-= section
->vma
;
3943 section
= bfd_make_section_old_way (abfd
, ".bss");
3944 value
-= section
->vma
;
3947 section
= bfd_abs_section_ptr
;
3950 section
= bfd_und_section_ptr
;
3953 section
= bfd_make_section_old_way (abfd
, ".sdata");
3954 value
-= section
->vma
;
3957 section
= bfd_make_section_old_way (abfd
, ".sbss");
3958 value
-= section
->vma
;
3961 section
= bfd_make_section_old_way (abfd
, ".rdata");
3962 value
-= section
->vma
;
3965 if (value
> ecoff_data (abfd
)->gp_size
)
3967 section
= bfd_com_section_ptr
;
3972 if (ecoff_scom_section
.name
== NULL
)
3974 /* Initialize the small common section. */
3975 ecoff_scom_section
.name
= SCOMMON
;
3976 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3977 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3978 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3979 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3980 ecoff_scom_symbol
.name
= SCOMMON
;
3981 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3982 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3983 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3985 section
= &ecoff_scom_section
;
3988 section
= bfd_und_section_ptr
;
3991 section
= bfd_make_section_old_way (abfd
, ".init");
3992 value
-= section
->vma
;
3995 section
= bfd_make_section_old_way (abfd
, ".fini");
3996 value
-= section
->vma
;
3999 section
= bfd_make_section_old_way (abfd
, ".rconst");
4000 value
-= section
->vma
;
4004 if (section
== (asection
*) NULL
)
4007 name
= ssext
+ esym
.asym
.iss
;
4010 if (! (_bfd_generic_link_add_one_symbol
4012 (flagword
) (esym
.weakext
? BSF_WEAK
: BSF_GLOBAL
),
4013 section
, value
, (const char *) NULL
, true, true,
4014 (struct bfd_link_hash_entry
**) &h
)))
4019 /* If we are building an ECOFF hash table, save the external
4020 symbol information. */
4021 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
4023 if (h
->abfd
== (bfd
*) NULL
4024 || (! bfd_is_und_section (section
)
4025 && (! bfd_is_com_section (section
)
4026 || (h
->root
.type
!= bfd_link_hash_defined
4027 && h
->root
.type
!= bfd_link_hash_defweak
))))
4033 /* Remember whether this symbol was small undefined. */
4034 if (esym
.asym
.sc
== scSUndefined
)
4037 /* If this symbol was ever small undefined, it needs to wind
4038 up in a GP relative section. We can't control the
4039 section of a defined symbol, but we can control the
4040 section of a common symbol. This case is actually needed
4041 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
4043 && h
->root
.type
== bfd_link_hash_common
4044 && strcmp (h
->root
.u
.c
.p
->section
->name
, SCOMMON
) != 0)
4046 h
->root
.u
.c
.p
->section
= bfd_make_section_old_way (abfd
,
4048 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4049 if (h
->esym
.asym
.sc
== scCommon
)
4050 h
->esym
.asym
.sc
= scSCommon
;
4058 /* ECOFF final link routines. */
4060 static boolean ecoff_final_link_debug_accumulate
4061 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*,
4063 static boolean ecoff_link_write_external
4064 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
4065 static boolean ecoff_indirect_link_order
4066 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4067 struct bfd_link_order
*));
4068 static boolean ecoff_reloc_link_order
4069 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4070 struct bfd_link_order
*));
4072 /* Structure used to pass information to ecoff_link_write_external. */
4077 struct bfd_link_info
*info
;
4080 /* ECOFF final link routine. This looks through all the input BFDs
4081 and gathers together all the debugging information, and then
4082 processes all the link order information. This may cause it to
4083 close and reopen some input BFDs; I'll see how bad this is. */
4086 _bfd_ecoff_bfd_final_link (abfd
, info
)
4088 struct bfd_link_info
*info
;
4090 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4091 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4094 register bfd
*input_bfd
;
4096 struct bfd_link_order
*p
;
4097 struct extsym_info einfo
;
4099 /* We accumulate the debugging information counts in the symbolic
4101 symhdr
= &debug
->symbolic_header
;
4103 symhdr
->ilineMax
= 0;
4107 symhdr
->isymMax
= 0;
4108 symhdr
->ioptMax
= 0;
4109 symhdr
->iauxMax
= 0;
4111 symhdr
->issExtMax
= 0;
4114 symhdr
->iextMax
= 0;
4116 /* We accumulate the debugging information itself in the debug_info
4119 debug
->external_dnr
= NULL
;
4120 debug
->external_pdr
= NULL
;
4121 debug
->external_sym
= NULL
;
4122 debug
->external_opt
= NULL
;
4123 debug
->external_aux
= NULL
;
4125 debug
->ssext
= debug
->ssext_end
= NULL
;
4126 debug
->external_fdr
= NULL
;
4127 debug
->external_rfd
= NULL
;
4128 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4130 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4131 if (handle
== (PTR
) NULL
)
4134 /* Accumulate the debugging symbols from each input BFD. */
4135 for (input_bfd
= info
->input_bfds
;
4136 input_bfd
!= (bfd
*) NULL
;
4137 input_bfd
= input_bfd
->link_next
)
4141 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4143 /* Abitrarily set the symbolic header vstamp to the vstamp
4144 of the first object file in the link. */
4145 if (symhdr
->vstamp
== 0)
4147 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4148 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4152 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4153 debug
, &backend
->debug_swap
,
4158 /* Combine the register masks. */
4159 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4160 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4161 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4162 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4163 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4164 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4167 /* Write out the external symbols. */
4170 ecoff_link_hash_traverse (ecoff_hash_table (info
),
4171 ecoff_link_write_external
,
4174 if (info
->relocateable
)
4176 /* We need to make a pass over the link_orders to count up the
4177 number of relocations we will need to output, so that we know
4178 how much space they will take up. */
4179 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4182 for (p
= o
->link_order_head
;
4183 p
!= (struct bfd_link_order
*) NULL
;
4185 if (p
->type
== bfd_indirect_link_order
)
4186 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4187 else if (p
->type
== bfd_section_reloc_link_order
4188 || p
->type
== bfd_symbol_reloc_link_order
)
4193 /* Compute the reloc and symbol file positions. */
4194 ecoff_compute_reloc_file_positions (abfd
);
4196 /* Write out the debugging information. */
4197 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4198 &backend
->debug_swap
, info
,
4199 ecoff_data (abfd
)->sym_filepos
))
4202 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4204 if (info
->relocateable
)
4206 /* Now reset the reloc_count field of the sections in the output
4207 BFD to 0, so that we can use them to keep track of how many
4208 relocs we have output thus far. */
4209 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4213 /* Get a value for the GP register. */
4214 if (ecoff_data (abfd
)->gp
== 0)
4216 struct bfd_link_hash_entry
*h
;
4218 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4219 if (h
!= (struct bfd_link_hash_entry
*) NULL
4220 && h
->type
== bfd_link_hash_defined
)
4221 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4222 + h
->u
.def
.section
->output_section
->vma
4223 + h
->u
.def
.section
->output_offset
);
4224 else if (info
->relocateable
)
4228 /* Make up a value. */
4230 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4233 && (strcmp (o
->name
, _SBSS
) == 0
4234 || strcmp (o
->name
, _SDATA
) == 0
4235 || strcmp (o
->name
, _LIT4
) == 0
4236 || strcmp (o
->name
, _LIT8
) == 0
4237 || strcmp (o
->name
, _LITA
) == 0))
4240 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4244 /* If the relocate_section function needs to do a reloc
4245 involving the GP value, it should make a reloc_dangerous
4246 callback to warn that GP is not defined. */
4250 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4252 for (p
= o
->link_order_head
;
4253 p
!= (struct bfd_link_order
*) NULL
;
4256 if (p
->type
== bfd_indirect_link_order
4257 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4258 == bfd_target_ecoff_flavour
))
4260 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4263 else if (p
->type
== bfd_section_reloc_link_order
4264 || p
->type
== bfd_symbol_reloc_link_order
)
4266 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4271 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4277 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4279 ecoff_data (abfd
)->linker
= true;
4284 /* Accumulate the debugging information for an input BFD into the
4285 output BFD. This must read in the symbolic information of the
4289 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
, handle
)
4292 struct bfd_link_info
*info
;
4295 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4296 const struct ecoff_debug_swap
* const swap
=
4297 &ecoff_backend (input_bfd
)->debug_swap
;
4298 HDRR
*symhdr
= &debug
->symbolic_header
;
4301 #define READ(ptr, offset, count, size, type) \
4302 if (symhdr->count == 0) \
4303 debug->ptr = NULL; \
4306 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
4307 debug->ptr = (type) bfd_malloc (amt); \
4308 if (debug->ptr == NULL) \
4311 goto return_something; \
4313 if (bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
4314 || bfd_bread (debug->ptr, amt, input_bfd) != amt) \
4317 goto return_something; \
4321 /* If raw_syments is not NULL, then the data was already by read by
4322 _bfd_ecoff_slurp_symbolic_info. */
4323 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4325 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char),
4327 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4328 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4329 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4330 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4331 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4333 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4334 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4335 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4339 /* We do not read the external strings or the external symbols. */
4341 ret
= (bfd_ecoff_debug_accumulate
4342 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4343 &ecoff_backend (output_bfd
)->debug_swap
,
4344 input_bfd
, debug
, swap
, info
));
4347 if (ecoff_data (input_bfd
)->raw_syments
== NULL
)
4349 if (debug
->line
!= NULL
)
4351 if (debug
->external_dnr
!= NULL
)
4352 free (debug
->external_dnr
);
4353 if (debug
->external_pdr
!= NULL
)
4354 free (debug
->external_pdr
);
4355 if (debug
->external_sym
!= NULL
)
4356 free (debug
->external_sym
);
4357 if (debug
->external_opt
!= NULL
)
4358 free (debug
->external_opt
);
4359 if (debug
->external_aux
!= NULL
)
4360 free (debug
->external_aux
);
4361 if (debug
->ss
!= NULL
)
4363 if (debug
->external_fdr
!= NULL
)
4364 free (debug
->external_fdr
);
4365 if (debug
->external_rfd
!= NULL
)
4366 free (debug
->external_rfd
);
4368 /* Make sure we don't accidentally follow one of these pointers
4369 into freed memory. */
4371 debug
->external_dnr
= NULL
;
4372 debug
->external_pdr
= NULL
;
4373 debug
->external_sym
= NULL
;
4374 debug
->external_opt
= NULL
;
4375 debug
->external_aux
= NULL
;
4377 debug
->external_fdr
= NULL
;
4378 debug
->external_rfd
= NULL
;
4384 /* Put out information for an external symbol. These come only from
4388 ecoff_link_write_external (h
, data
)
4389 struct ecoff_link_hash_entry
*h
;
4392 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4393 bfd
*output_bfd
= einfo
->abfd
;
4396 if (h
->root
.type
== bfd_link_hash_warning
)
4398 h
= (struct ecoff_link_hash_entry
*) h
->root
.u
.i
.link
;
4399 if (h
->root
.type
== bfd_link_hash_new
)
4403 /* We need to check if this symbol is being stripped. */
4404 if (h
->root
.type
== bfd_link_hash_undefined
4405 || h
->root
.type
== bfd_link_hash_undefweak
)
4407 else if (einfo
->info
->strip
== strip_all
4408 || (einfo
->info
->strip
== strip_some
4409 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4410 h
->root
.root
.string
,
4411 false, false) == NULL
))
4416 if (strip
|| h
->written
)
4419 if (h
->abfd
== (bfd
*) NULL
)
4422 h
->esym
.cobol_main
= 0;
4423 h
->esym
.weakext
= 0;
4424 h
->esym
.reserved
= 0;
4425 h
->esym
.ifd
= ifdNil
;
4426 h
->esym
.asym
.value
= 0;
4427 h
->esym
.asym
.st
= stGlobal
;
4429 if (h
->root
.type
!= bfd_link_hash_defined
4430 && h
->root
.type
!= bfd_link_hash_defweak
)
4431 h
->esym
.asym
.sc
= scAbs
;
4434 asection
*output_section
;
4437 output_section
= h
->root
.u
.def
.section
->output_section
;
4438 name
= bfd_section_name (output_section
->owner
, output_section
);
4440 if (strcmp (name
, _TEXT
) == 0)
4441 h
->esym
.asym
.sc
= scText
;
4442 else if (strcmp (name
, _DATA
) == 0)
4443 h
->esym
.asym
.sc
= scData
;
4444 else if (strcmp (name
, _SDATA
) == 0)
4445 h
->esym
.asym
.sc
= scSData
;
4446 else if (strcmp (name
, _RDATA
) == 0)
4447 h
->esym
.asym
.sc
= scRData
;
4448 else if (strcmp (name
, _BSS
) == 0)
4449 h
->esym
.asym
.sc
= scBss
;
4450 else if (strcmp (name
, _SBSS
) == 0)
4451 h
->esym
.asym
.sc
= scSBss
;
4452 else if (strcmp (name
, _INIT
) == 0)
4453 h
->esym
.asym
.sc
= scInit
;
4454 else if (strcmp (name
, _FINI
) == 0)
4455 h
->esym
.asym
.sc
= scFini
;
4456 else if (strcmp (name
, _PDATA
) == 0)
4457 h
->esym
.asym
.sc
= scPData
;
4458 else if (strcmp (name
, _XDATA
) == 0)
4459 h
->esym
.asym
.sc
= scXData
;
4460 else if (strcmp (name
, _RCONST
) == 0)
4461 h
->esym
.asym
.sc
= scRConst
;
4463 h
->esym
.asym
.sc
= scAbs
;
4466 h
->esym
.asym
.reserved
= 0;
4467 h
->esym
.asym
.index
= indexNil
;
4469 else if (h
->esym
.ifd
!= -1)
4471 struct ecoff_debug_info
*debug
;
4473 /* Adjust the FDR index for the symbol by that used for the
4475 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4476 BFD_ASSERT (h
->esym
.ifd
>= 0
4477 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4478 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4481 switch (h
->root
.type
)
4484 case bfd_link_hash_warning
:
4485 case bfd_link_hash_new
:
4487 case bfd_link_hash_undefined
:
4488 case bfd_link_hash_undefweak
:
4489 if (h
->esym
.asym
.sc
!= scUndefined
4490 && h
->esym
.asym
.sc
!= scSUndefined
)
4491 h
->esym
.asym
.sc
= scUndefined
;
4493 case bfd_link_hash_defined
:
4494 case bfd_link_hash_defweak
:
4495 if (h
->esym
.asym
.sc
== scUndefined
4496 || h
->esym
.asym
.sc
== scSUndefined
)
4497 h
->esym
.asym
.sc
= scAbs
;
4498 else if (h
->esym
.asym
.sc
== scCommon
)
4499 h
->esym
.asym
.sc
= scBss
;
4500 else if (h
->esym
.asym
.sc
== scSCommon
)
4501 h
->esym
.asym
.sc
= scSBss
;
4502 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4503 + h
->root
.u
.def
.section
->output_section
->vma
4504 + h
->root
.u
.def
.section
->output_offset
);
4506 case bfd_link_hash_common
:
4507 if (h
->esym
.asym
.sc
!= scCommon
4508 && h
->esym
.asym
.sc
!= scSCommon
)
4509 h
->esym
.asym
.sc
= scCommon
;
4510 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4512 case bfd_link_hash_indirect
:
4513 /* We ignore these symbols, since the indirected symbol is
4514 already in the hash table. */
4518 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4520 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4523 return (bfd_ecoff_debug_one_external
4524 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4525 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4529 /* Relocate and write an ECOFF section into an ECOFF output file. */
4532 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4534 struct bfd_link_info
*info
;
4535 asection
*output_section
;
4536 struct bfd_link_order
*link_order
;
4538 asection
*input_section
;
4540 struct ecoff_section_tdata
*section_tdata
;
4541 bfd_size_type raw_size
;
4542 bfd_size_type cooked_size
;
4543 bfd_byte
*contents
= NULL
;
4544 bfd_size_type external_reloc_size
;
4545 bfd_size_type external_relocs_size
;
4546 PTR external_relocs
= NULL
;
4549 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4551 if (link_order
->size
== 0)
4554 input_section
= link_order
->u
.indirect
.section
;
4555 input_bfd
= input_section
->owner
;
4556 section_tdata
= ecoff_section_data (input_bfd
, input_section
);
4558 raw_size
= input_section
->_raw_size
;
4559 cooked_size
= input_section
->_cooked_size
;
4560 if (cooked_size
== 0)
4561 cooked_size
= raw_size
;
4563 BFD_ASSERT (input_section
->output_section
== output_section
);
4564 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4565 BFD_ASSERT (cooked_size
== link_order
->size
);
4567 /* Get the section contents. We allocate memory for the larger of
4568 the size before relocating and the size after relocating. */
4569 amt
= raw_size
>= cooked_size
? raw_size
: cooked_size
;
4570 contents
= (bfd_byte
*) bfd_malloc (amt
);
4571 if (contents
== NULL
&& amt
!= 0)
4574 /* If we are relaxing, the contents may have already been read into
4575 memory, in which case we copy them into our new buffer. We don't
4576 simply reuse the old buffer in case cooked_size > raw_size. */
4577 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4578 && section_tdata
->contents
!= (bfd_byte
*) NULL
)
4579 memcpy (contents
, section_tdata
->contents
, (size_t) raw_size
);
4582 if (! bfd_get_section_contents (input_bfd
, input_section
,
4584 (file_ptr
) 0, raw_size
))
4588 /* Get the relocs. If we are relaxing MIPS code, they will already
4589 have been read in. Otherwise, we read them in now. */
4590 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4591 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4593 if (section_tdata
!= (struct ecoff_section_tdata
*) NULL
4594 && section_tdata
->external_relocs
!= NULL
)
4595 external_relocs
= section_tdata
->external_relocs
;
4598 external_relocs
= (PTR
) bfd_malloc (external_relocs_size
);
4599 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
4602 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4603 || (bfd_bread (external_relocs
, external_relocs_size
, input_bfd
)
4604 != external_relocs_size
))
4608 /* Relocate the section contents. */
4609 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4610 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4614 /* Write out the relocated section. */
4615 if (! bfd_set_section_contents (output_bfd
,
4618 (file_ptr
) input_section
->output_offset
,
4622 /* If we are producing relocateable output, the relocs were
4623 modified, and we write them out now. We use the reloc_count
4624 field of output_section to keep track of the number of relocs we
4625 have output so far. */
4626 if (info
->relocateable
)
4628 file_ptr pos
= (output_section
->rel_filepos
4629 + output_section
->reloc_count
* external_reloc_size
);
4630 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
4631 || (bfd_bwrite (external_relocs
, external_relocs_size
, output_bfd
)
4632 != external_relocs_size
))
4634 output_section
->reloc_count
+= input_section
->reloc_count
;
4637 if (contents
!= NULL
)
4639 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4640 free (external_relocs
);
4644 if (contents
!= NULL
)
4646 if (external_relocs
!= NULL
&& section_tdata
== NULL
)
4647 free (external_relocs
);
4651 /* Generate a reloc when linking an ECOFF file. This is a reloc
4652 requested by the linker, and does come from any input file. This
4653 is used to build constructor and destructor tables when linking
4657 ecoff_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
4659 struct bfd_link_info
*info
;
4660 asection
*output_section
;
4661 struct bfd_link_order
*link_order
;
4663 enum bfd_link_order_type type
;
4667 struct internal_reloc in
;
4668 bfd_size_type external_reloc_size
;
4673 type
= link_order
->type
;
4675 addend
= link_order
->u
.reloc
.p
->addend
;
4677 /* We set up an arelent to pass to the backend adjust_reloc_out
4679 rel
.address
= link_order
->offset
;
4681 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4684 bfd_set_error (bfd_error_bad_value
);
4688 if (type
== bfd_section_reloc_link_order
)
4690 section
= link_order
->u
.reloc
.p
->u
.section
;
4691 rel
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
4695 struct bfd_link_hash_entry
*h
;
4697 /* Treat a reloc against a defined symbol as though it were
4698 actually against the section. */
4699 h
= bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4700 link_order
->u
.reloc
.p
->u
.name
,
4701 false, false, false);
4703 && (h
->type
== bfd_link_hash_defined
4704 || h
->type
== bfd_link_hash_defweak
))
4706 type
= bfd_section_reloc_link_order
;
4707 section
= h
->u
.def
.section
->output_section
;
4708 /* It seems that we ought to add the symbol value to the
4709 addend here, but in practice it has already been added
4710 because it was passed to constructor_callback. */
4711 addend
+= section
->vma
+ h
->u
.def
.section
->output_offset
;
4715 /* We can't set up a reloc against a symbol correctly,
4716 because we have no asymbol structure. Currently no
4717 adjust_reloc_out routine cares. */
4718 rel
.sym_ptr_ptr
= (asymbol
**) NULL
;
4722 /* All ECOFF relocs are in-place. Put the addend into the object
4725 BFD_ASSERT (rel
.howto
->partial_inplace
);
4729 bfd_reloc_status_type rstat
;
4732 size
= bfd_get_reloc_size (rel
.howto
);
4733 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4734 if (buf
== (bfd_byte
*) NULL
)
4736 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4737 (bfd_vma
) addend
, buf
);
4743 case bfd_reloc_outofrange
:
4745 case bfd_reloc_overflow
:
4746 if (! ((*info
->callbacks
->reloc_overflow
)
4748 (link_order
->type
== bfd_section_reloc_link_order
4749 ? bfd_section_name (output_bfd
, section
)
4750 : link_order
->u
.reloc
.p
->u
.name
),
4751 rel
.howto
->name
, addend
, (bfd
*) NULL
,
4752 (asection
*) NULL
, (bfd_vma
) 0)))
4759 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
4760 (file_ptr
) link_order
->offset
, size
);
4768 /* Move the information into an internal_reloc structure. */
4769 in
.r_vaddr
= (rel
.address
4770 + bfd_get_section_vma (output_bfd
, output_section
));
4771 in
.r_type
= rel
.howto
->type
;
4773 if (type
== bfd_symbol_reloc_link_order
)
4775 struct ecoff_link_hash_entry
*h
;
4777 h
= ((struct ecoff_link_hash_entry
*)
4778 bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4779 link_order
->u
.reloc
.p
->u
.name
,
4780 false, false, true));
4781 if (h
!= (struct ecoff_link_hash_entry
*) NULL
4783 in
.r_symndx
= h
->indx
;
4786 if (! ((*info
->callbacks
->unattached_reloc
)
4787 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4788 (asection
*) NULL
, (bfd_vma
) 0)))
4798 name
= bfd_get_section_name (output_bfd
, section
);
4799 if (strcmp (name
, ".text") == 0)
4800 in
.r_symndx
= RELOC_SECTION_TEXT
;
4801 else if (strcmp (name
, ".rdata") == 0)
4802 in
.r_symndx
= RELOC_SECTION_RDATA
;
4803 else if (strcmp (name
, ".data") == 0)
4804 in
.r_symndx
= RELOC_SECTION_DATA
;
4805 else if (strcmp (name
, ".sdata") == 0)
4806 in
.r_symndx
= RELOC_SECTION_SDATA
;
4807 else if (strcmp (name
, ".sbss") == 0)
4808 in
.r_symndx
= RELOC_SECTION_SBSS
;
4809 else if (strcmp (name
, ".bss") == 0)
4810 in
.r_symndx
= RELOC_SECTION_BSS
;
4811 else if (strcmp (name
, ".init") == 0)
4812 in
.r_symndx
= RELOC_SECTION_INIT
;
4813 else if (strcmp (name
, ".lit8") == 0)
4814 in
.r_symndx
= RELOC_SECTION_LIT8
;
4815 else if (strcmp (name
, ".lit4") == 0)
4816 in
.r_symndx
= RELOC_SECTION_LIT4
;
4817 else if (strcmp (name
, ".xdata") == 0)
4818 in
.r_symndx
= RELOC_SECTION_XDATA
;
4819 else if (strcmp (name
, ".pdata") == 0)
4820 in
.r_symndx
= RELOC_SECTION_PDATA
;
4821 else if (strcmp (name
, ".fini") == 0)
4822 in
.r_symndx
= RELOC_SECTION_FINI
;
4823 else if (strcmp (name
, ".lita") == 0)
4824 in
.r_symndx
= RELOC_SECTION_LITA
;
4825 else if (strcmp (name
, "*ABS*") == 0)
4826 in
.r_symndx
= RELOC_SECTION_ABS
;
4827 else if (strcmp (name
, ".rconst") == 0)
4828 in
.r_symndx
= RELOC_SECTION_RCONST
;
4834 /* Let the BFD backend adjust the reloc. */
4835 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4837 /* Get some memory and swap out the reloc. */
4838 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4839 rbuf
= (bfd_byte
*) bfd_malloc (external_reloc_size
);
4840 if (rbuf
== (bfd_byte
*) NULL
)
4843 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (PTR
) rbuf
);
4845 pos
= (output_section
->rel_filepos
4846 + output_section
->reloc_count
* external_reloc_size
);
4847 ok
= (bfd_seek (output_bfd
, pos
, SEEK_SET
) == 0
4848 && (bfd_bwrite ((PTR
) rbuf
, external_reloc_size
, output_bfd
)
4849 == external_reloc_size
));
4852 ++output_section
->reloc_count
;