1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright (C) 1990-2024 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support added by Ian Lance Taylor, ian@cygnus.com.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
27 #include "ecoff-bfd.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"
46 #include "libiberty.h"
48 #define streq(a, b) (strcmp ((a), (b)) == 0)
51 /* This stuff is somewhat copied from coffcode.h. */
52 static asection bfd_debug_section
=
53 BFD_FAKE_SECTION (bfd_debug_section
, NULL
, "*DEBUG*", 0, 0);
55 /* Create an ECOFF object. */
58 _bfd_ecoff_mkobject (bfd
*abfd
)
60 size_t amt
= sizeof (ecoff_data_type
);
62 abfd
->tdata
.ecoff_obj_data
= (struct ecoff_tdata
*) bfd_zalloc (abfd
, amt
);
63 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
69 /* This is a hook called by coff_real_object_p to create any backend
70 specific information. */
73 _bfd_ecoff_mkobject_hook (bfd
*abfd
, void * filehdr
, void * aouthdr
)
75 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
76 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
77 ecoff_data_type
*ecoff
;
79 if (! _bfd_ecoff_mkobject (abfd
))
82 ecoff
= ecoff_data (abfd
);
84 ecoff
->sym_filepos
= internal_f
->f_symptr
;
86 if (internal_a
!= NULL
)
90 ecoff
->text_start
= internal_a
->text_start
;
91 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
92 ecoff
->gp
= internal_a
->gp_value
;
93 ecoff
->gprmask
= internal_a
->gprmask
;
94 for (i
= 0; i
< 4; i
++)
95 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
96 ecoff
->fprmask
= internal_a
->fprmask
;
97 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
98 abfd
->flags
|= D_PAGED
;
100 abfd
->flags
&=~ D_PAGED
;
103 /* It turns out that no special action is required by the MIPS or
104 Alpha ECOFF backends. They have different information in the
105 a.out header, but we just copy it all (e.g., gprmask, cprmask and
106 fprmask) and let the swapping routines ensure that only relevant
107 information is written out. */
109 return (void *) ecoff
;
113 _bfd_ecoff_bfd_free_cached_info (bfd
*abfd
)
115 struct ecoff_tdata
*tdata
;
117 if ((bfd_get_format (abfd
) == bfd_object
118 || bfd_get_format (abfd
) == bfd_core
)
119 && (tdata
= ecoff_data (abfd
)) != NULL
)
121 while (tdata
->mips_refhi_list
!= NULL
)
123 struct mips_hi
*ref
= tdata
->mips_refhi_list
;
124 tdata
->mips_refhi_list
= ref
->next
;
127 _bfd_ecoff_free_ecoff_debug_info (&tdata
->debug_info
);
129 return _bfd_generic_bfd_free_cached_info (abfd
);
132 /* Initialize a new section. */
135 _bfd_ecoff_new_section_hook (bfd
*abfd
, asection
*section
)
145 { _TEXT
, SEC_ALLOC
| SEC_CODE
| SEC_LOAD
},
146 { _INIT
, SEC_ALLOC
| SEC_CODE
| SEC_LOAD
},
147 { _FINI
, SEC_ALLOC
| SEC_CODE
| SEC_LOAD
},
148 { _DATA
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
},
149 { _SDATA
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
| SEC_SMALL_DATA
},
150 { _RDATA
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
| SEC_READONLY
},
151 { _LIT8
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
| SEC_READONLY
| SEC_SMALL_DATA
},
152 { _LIT4
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
| SEC_READONLY
| SEC_SMALL_DATA
},
153 { _RCONST
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
| SEC_READONLY
},
154 { _PDATA
, SEC_ALLOC
| SEC_DATA
| SEC_LOAD
| SEC_READONLY
},
156 { _SBSS
, SEC_ALLOC
| SEC_SMALL_DATA
},
157 /* An Irix 4 shared libary. */
158 { _LIB
, SEC_COFF_SHARED_LIBRARY
}
161 section
->alignment_power
= 4;
163 for (i
= 0; i
< ARRAY_SIZE (section_flags
); i
++)
164 if (streq (section
->name
, section_flags
[i
].name
))
166 section
->flags
|= section_flags
[i
].flags
;
171 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
172 uncertain about .init on some systems and I don't know how shared
175 return _bfd_generic_new_section_hook (abfd
, section
);
179 _bfd_ecoff_set_alignment_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
180 asection
*section ATTRIBUTE_UNUSED
,
181 void *scnhdr ATTRIBUTE_UNUSED
)
185 /* Determine the machine architecture and type. This is called from
186 the generic COFF routines. It is the inverse of ecoff_get_magic,
187 below. This could be an ECOFF backend routine, with one version
188 for each target, but there aren't all that many ECOFF targets. */
191 _bfd_ecoff_set_arch_mach_hook (bfd
*abfd
, void * filehdr
)
193 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
194 enum bfd_architecture arch
;
197 switch (internal_f
->f_magic
)
200 case MIPS_MAGIC_LITTLE
:
202 arch
= bfd_arch_mips
;
203 mach
= bfd_mach_mips3000
;
206 case MIPS_MAGIC_LITTLE2
:
207 case MIPS_MAGIC_BIG2
:
208 /* MIPS ISA level 2: the r6000. */
209 arch
= bfd_arch_mips
;
210 mach
= bfd_mach_mips6000
;
213 case MIPS_MAGIC_LITTLE3
:
214 case MIPS_MAGIC_BIG3
:
215 /* MIPS ISA level 3: the r4000. */
216 arch
= bfd_arch_mips
;
217 mach
= bfd_mach_mips4000
;
221 arch
= bfd_arch_alpha
;
226 arch
= bfd_arch_obscure
;
231 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
235 _bfd_ecoff_no_long_sections (bfd
*abfd
, int enable
)
242 /* Get the magic number to use based on the architecture and machine.
243 This is the inverse of _bfd_ecoff_set_arch_mach_hook, above. */
246 ecoff_get_magic (bfd
*abfd
)
250 switch (bfd_get_arch (abfd
))
253 switch (bfd_get_mach (abfd
))
257 case bfd_mach_mips3000
:
258 big
= MIPS_MAGIC_BIG
;
259 little
= MIPS_MAGIC_LITTLE
;
262 case bfd_mach_mips6000
:
263 big
= MIPS_MAGIC_BIG2
;
264 little
= MIPS_MAGIC_LITTLE2
;
267 case bfd_mach_mips4000
:
268 big
= MIPS_MAGIC_BIG3
;
269 little
= MIPS_MAGIC_LITTLE3
;
273 return bfd_big_endian (abfd
) ? big
: little
;
284 /* Get the section s_flags to use for a section. */
287 ecoff_sec_to_styp_flags (const char *name
, flagword flags
)
297 { _TEXT
, STYP_TEXT
},
298 { _DATA
, STYP_DATA
},
299 { _SDATA
, STYP_SDATA
},
300 { _RDATA
, STYP_RDATA
},
301 { _LITA
, STYP_LITA
},
302 { _LIT8
, STYP_LIT8
},
303 { _LIT4
, STYP_LIT4
},
305 { _SBSS
, STYP_SBSS
},
306 { _INIT
, STYP_ECOFF_INIT
},
307 { _FINI
, STYP_ECOFF_FINI
},
308 { _PDATA
, STYP_PDATA
},
309 { _XDATA
, STYP_XDATA
},
310 { _LIB
, STYP_ECOFF_LIB
},
312 { _HASH
, STYP_HASH
},
313 { _DYNAMIC
, STYP_DYNAMIC
},
314 { _LIBLIST
, STYP_LIBLIST
},
315 { _RELDYN
, STYP_RELDYN
},
316 { _CONFLIC
, STYP_CONFLIC
},
317 { _DYNSTR
, STYP_DYNSTR
},
318 { _DYNSYM
, STYP_DYNSYM
},
319 { _RCONST
, STYP_RCONST
}
323 for (i
= 0; i
< ARRAY_SIZE (styp_flags
); i
++)
324 if (streq (name
, styp_flags
[i
].name
))
326 styp
= styp_flags
[i
].flags
;
332 if (streq (name
, _COMMENT
))
335 flags
&=~ SEC_NEVER_LOAD
;
337 else if (flags
& SEC_CODE
)
339 else if (flags
& SEC_DATA
)
341 else if (flags
& SEC_READONLY
)
343 else if (flags
& SEC_LOAD
)
349 if (flags
& SEC_NEVER_LOAD
)
355 /* Get the BFD flags to use for a section. */
358 _bfd_ecoff_styp_to_sec_flags (bfd
*abfd ATTRIBUTE_UNUSED
,
360 const char *name ATTRIBUTE_UNUSED
,
361 asection
*section ATTRIBUTE_UNUSED
,
362 flagword
* flags_ptr
)
364 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
365 long styp_flags
= internal_s
->s_flags
;
366 flagword sec_flags
= 0;
368 if (styp_flags
& STYP_NOLOAD
)
369 sec_flags
|= SEC_NEVER_LOAD
;
371 /* For 386 COFF, at least, an unloadable text or data section is
372 actually a shared library section. */
373 if ((styp_flags
& STYP_TEXT
)
374 || (styp_flags
& STYP_ECOFF_INIT
)
375 || (styp_flags
& STYP_ECOFF_FINI
)
376 || (styp_flags
& STYP_DYNAMIC
)
377 || (styp_flags
& STYP_LIBLIST
)
378 || (styp_flags
& STYP_RELDYN
)
379 || styp_flags
== STYP_CONFLIC
380 || (styp_flags
& STYP_DYNSTR
)
381 || (styp_flags
& STYP_DYNSYM
)
382 || (styp_flags
& STYP_HASH
))
384 if (sec_flags
& SEC_NEVER_LOAD
)
385 sec_flags
|= SEC_CODE
| SEC_COFF_SHARED_LIBRARY
;
387 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
389 else if ((styp_flags
& STYP_DATA
)
390 || (styp_flags
& STYP_RDATA
)
391 || (styp_flags
& STYP_SDATA
)
392 || styp_flags
== STYP_PDATA
393 || styp_flags
== STYP_XDATA
394 || (styp_flags
& STYP_GOT
)
395 || styp_flags
== STYP_RCONST
)
397 if (sec_flags
& SEC_NEVER_LOAD
)
398 sec_flags
|= SEC_DATA
| SEC_COFF_SHARED_LIBRARY
;
400 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
401 if ((styp_flags
& STYP_RDATA
)
402 || styp_flags
== STYP_PDATA
403 || styp_flags
== STYP_RCONST
)
404 sec_flags
|= SEC_READONLY
;
405 if (styp_flags
& STYP_SDATA
)
406 sec_flags
|= SEC_SMALL_DATA
;
408 else if (styp_flags
& STYP_SBSS
)
409 sec_flags
|= SEC_ALLOC
| SEC_SMALL_DATA
;
410 else if (styp_flags
& STYP_BSS
)
411 sec_flags
|= SEC_ALLOC
;
412 else if ((styp_flags
& STYP_INFO
) || styp_flags
== STYP_COMMENT
)
413 sec_flags
|= SEC_NEVER_LOAD
;
414 else if ((styp_flags
& STYP_LITA
)
415 || (styp_flags
& STYP_LIT8
)
416 || (styp_flags
& STYP_LIT4
))
417 sec_flags
|= SEC_DATA
|SEC_SMALL_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
418 else if (styp_flags
& STYP_ECOFF_LIB
)
419 sec_flags
|= SEC_COFF_SHARED_LIBRARY
;
421 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
423 * flags_ptr
= sec_flags
;
427 /* Read in the symbolic header for an ECOFF object file. */
430 ecoff_slurp_symbolic_header (bfd
*abfd
)
432 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
433 bfd_size_type external_hdr_size
;
435 HDRR
*internal_symhdr
;
437 /* See if we've already read it in. */
438 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
439 backend
->debug_swap
.sym_magic
)
442 /* See whether there is a symbolic header. */
443 if (ecoff_data (abfd
)->sym_filepos
== 0)
449 /* At this point bfd_get_symcount (abfd) holds the number of symbols
450 as read from the file header, but on ECOFF this is always the
451 size of the symbolic information header. It would be cleaner to
452 handle this when we first read the file in coffgen.c. */
453 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
454 if (bfd_get_symcount (abfd
) != external_hdr_size
)
456 bfd_set_error (bfd_error_bad_value
);
460 /* Read the symbolic information header. */
461 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) != 0)
463 raw
= _bfd_malloc_and_read (abfd
, external_hdr_size
, external_hdr_size
);
467 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
468 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
470 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
472 bfd_set_error (bfd_error_bad_value
);
476 #define FIX(start, count) \
477 if (internal_symhdr->start == 0) \
478 internal_symhdr->count = 0;
480 FIX (cbLineOffset
, cbLine
);
481 FIX (cbDnOffset
, idnMax
);
482 FIX (cbPdOffset
, ipdMax
);
483 FIX (cbSymOffset
, isymMax
);
484 FIX (cbOptOffset
, ioptMax
);
485 FIX (cbAuxOffset
, iauxMax
);
486 FIX (cbSsOffset
, issMax
);
487 FIX (cbSsExtOffset
, issExtMax
);
488 FIX (cbFdOffset
, ifdMax
);
489 FIX (cbRfdOffset
, crfd
);
490 FIX (cbExtOffset
, iextMax
);
493 /* Now we can get the correct number of symbols. */
494 abfd
->symcount
= internal_symhdr
->isymMax
+ internal_symhdr
->iextMax
;
503 /* Read in and swap the important symbolic information for an ECOFF
504 object file. This is called by gdb via the read_debug_info entry
505 point in the backend structure. */
508 _bfd_ecoff_slurp_symbolic_info (bfd
*abfd
,
509 asection
*ignore ATTRIBUTE_UNUSED
,
510 struct ecoff_debug_info
*debug
)
512 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
513 HDRR
*internal_symhdr
;
514 bfd_size_type raw_base
;
515 bfd_size_type raw_size
;
517 bfd_size_type external_fdr_size
;
521 bfd_size_type raw_end
;
522 bfd_size_type cb_end
;
526 BFD_ASSERT (debug
== &ecoff_data (abfd
)->debug_info
);
528 /* Check whether we've already gotten it, and whether there's any to
530 if (debug
->alloc_syments
)
532 if (ecoff_data (abfd
)->sym_filepos
== 0)
538 if (! ecoff_slurp_symbolic_header (abfd
))
541 internal_symhdr
= &debug
->symbolic_header
;
543 /* Read all the symbolic information at once. */
544 raw_base
= (ecoff_data (abfd
)->sym_filepos
545 + backend
->debug_swap
.external_hdr_size
);
547 /* Alpha ecoff makes the determination of raw_size difficult. It has
548 an undocumented debug data section between the symhdr and the first
549 documented section. And the ordering of the sections varies between
550 statically and dynamically linked executables.
551 If bfd supports SEEK_END someday, this code could be simplified. */
554 #define UPDATE_RAW_END(start, count, size) \
556 if (internal_symhdr->count != 0) \
558 if (internal_symhdr->start < raw_base) \
560 if (_bfd_mul_overflow ((unsigned long) internal_symhdr->count, \
563 cb_end = internal_symhdr->start + amt; \
564 if (cb_end < internal_symhdr->start) \
566 if (cb_end > raw_end) \
571 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
572 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
573 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
574 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
575 /* eraxxon@alumni.rice.edu: ioptMax refers to the size of the
576 optimization symtab, not the number of entries. */
577 UPDATE_RAW_END (cbOptOffset
, ioptMax
, sizeof (char));
578 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
579 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
580 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
581 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
582 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
583 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
585 #undef UPDATE_RAW_END
587 raw_size
= raw_end
- raw_base
;
590 ecoff_data (abfd
)->sym_filepos
= 0;
593 pos
= ecoff_data (abfd
)->sym_filepos
;
594 pos
+= backend
->debug_swap
.external_hdr_size
;
595 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0)
597 raw
= _bfd_alloc_and_read (abfd
, raw_size
, raw_size
);
601 debug
->alloc_syments
= true;
603 /* Get pointers for the numeric offsets in the HDRR structure. */
604 #define FIX(start, count, ptr, type) \
605 if (internal_symhdr->count == 0) \
608 debug->ptr = (type) ((char *) raw \
609 + (internal_symhdr->start - raw_base))
611 FIX (cbLineOffset
, cbLine
, line
, unsigned char *);
612 FIX (cbDnOffset
, idnMax
, external_dnr
, void *);
613 FIX (cbPdOffset
, ipdMax
, external_pdr
, void *);
614 FIX (cbSymOffset
, isymMax
, external_sym
, void *);
615 FIX (cbOptOffset
, ioptMax
, external_opt
, void *);
616 FIX (cbAuxOffset
, iauxMax
, external_aux
, union aux_ext
*);
617 FIX (cbSsOffset
, issMax
, ss
, char *);
618 FIX (cbSsExtOffset
, issExtMax
, ssext
, char *);
619 FIX (cbFdOffset
, ifdMax
, external_fdr
, void *);
620 FIX (cbRfdOffset
, crfd
, external_rfd
, void *);
621 FIX (cbExtOffset
, iextMax
, external_ext
, void *);
624 /* Ensure string sections are zero terminated. */
626 debug
->ss
[internal_symhdr
->issMax
- 1] = 0;
628 debug
->ssext
[internal_symhdr
->issExtMax
- 1] = 0;
630 /* I don't want to always swap all the data, because it will just
631 waste time and most programs will never look at it. The only
632 time the linker needs most of the debugging information swapped
633 is when linking big-endian and little-endian MIPS object files
634 together, which is not a common occurrence.
636 We need to look at the fdr to deal with a lot of information in
637 the symbols, so we swap them here. */
638 if (_bfd_mul_overflow ((unsigned long) internal_symhdr
->ifdMax
,
639 sizeof (struct fdr
), &amt
))
642 bfd_set_error (bfd_error_file_too_big
);
645 debug
->fdr
= (FDR
*) bfd_alloc (abfd
, amt
);
646 if (debug
->fdr
== NULL
)
648 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
649 fdr_ptr
= debug
->fdr
;
650 fraw_src
= (char *) debug
->external_fdr
;
651 /* PR 17512: file: 3372-1243-0.004. */
652 if (fraw_src
== NULL
&& internal_symhdr
->ifdMax
> 0)
654 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
655 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
656 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (void *) fraw_src
, fdr_ptr
);
661 /* ECOFF symbol table routines. The ECOFF symbol table is described
662 in gcc/mips-tfile.c. */
664 /* ECOFF uses two common sections. One is the usual one, and the
665 other is for small objects. All the small objects are kept
666 together, and then referenced via the gp pointer, which yields
667 faster assembler code. This is what we use for the small common
669 static asection ecoff_scom_section
;
670 static const asymbol ecoff_scom_symbol
=
671 GLOBAL_SYM_INIT (SCOMMON
, &ecoff_scom_section
);
672 static asection ecoff_scom_section
=
673 BFD_FAKE_SECTION (ecoff_scom_section
, &ecoff_scom_symbol
,
674 SCOMMON
, 0, SEC_IS_COMMON
| SEC_SMALL_DATA
);
676 /* Create an empty symbol. */
679 _bfd_ecoff_make_empty_symbol (bfd
*abfd
)
681 ecoff_symbol_type
*new_symbol
;
682 size_t amt
= sizeof (ecoff_symbol_type
);
684 new_symbol
= (ecoff_symbol_type
*) bfd_zalloc (abfd
, amt
);
685 if (new_symbol
== NULL
)
687 new_symbol
->symbol
.section
= NULL
;
688 new_symbol
->fdr
= NULL
;
689 new_symbol
->local
= false;
690 new_symbol
->native
= NULL
;
691 new_symbol
->symbol
.the_bfd
= abfd
;
692 return &new_symbol
->symbol
;
695 /* Set the BFD flags and section for an ECOFF symbol. */
698 ecoff_set_symbol_info (bfd
*abfd
,
704 asym
->the_bfd
= abfd
;
705 asym
->value
= ecoff_sym
->value
;
706 asym
->section
= &bfd_debug_section
;
709 /* Most symbol types are just for debugging. */
710 switch (ecoff_sym
->st
)
719 if (ECOFF_IS_STAB (ecoff_sym
))
721 asym
->flags
= BSF_DEBUGGING
;
726 asym
->flags
= BSF_DEBUGGING
;
731 asym
->flags
= BSF_EXPORT
| BSF_WEAK
;
733 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
736 asym
->flags
= BSF_LOCAL
;
737 /* Normally, a local stProc symbol will have a corresponding
738 external symbol. We mark the local symbol as a debugging
739 symbol, in order to prevent nm from printing both out.
740 Similarly, we mark stLabel and stabs symbols as debugging
741 symbols. In both cases, we do want to set the value
742 correctly based on the symbol class. */
743 if (ecoff_sym
->st
== stProc
744 || ecoff_sym
->st
== stLabel
745 || ECOFF_IS_STAB (ecoff_sym
))
746 asym
->flags
|= BSF_DEBUGGING
;
749 if (ecoff_sym
->st
== stProc
|| ecoff_sym
->st
== stStaticProc
)
750 asym
->flags
|= BSF_FUNCTION
;
752 switch (ecoff_sym
->sc
)
755 /* Used for compiler generated labels. Leave them in the
756 debugging section, and mark them as local. If BSF_DEBUGGING
757 is set, then nm does not display them for some reason. If no
758 flags are set then the linker whines about them. */
759 asym
->flags
= BSF_LOCAL
;
762 asym
->section
= bfd_make_section_old_way (abfd
, _TEXT
);
763 asym
->value
-= asym
->section
->vma
;
766 asym
->section
= bfd_make_section_old_way (abfd
, _DATA
);
767 asym
->value
-= asym
->section
->vma
;
770 asym
->section
= bfd_make_section_old_way (abfd
, _BSS
);
771 asym
->value
-= asym
->section
->vma
;
774 asym
->flags
= BSF_DEBUGGING
;
777 asym
->section
= bfd_abs_section_ptr
;
780 asym
->section
= bfd_und_section_ptr
;
790 asym
->flags
= BSF_DEBUGGING
;
793 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
794 asym
->value
-= asym
->section
->vma
;
797 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
798 asym
->value
-= asym
->section
->vma
;
801 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
802 asym
->value
-= asym
->section
->vma
;
805 asym
->flags
= BSF_DEBUGGING
;
808 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
810 asym
->section
= bfd_com_section_ptr
;
816 asym
->section
= &ecoff_scom_section
;
821 asym
->flags
= BSF_DEBUGGING
;
824 asym
->section
= bfd_und_section_ptr
;
829 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
830 asym
->value
-= asym
->section
->vma
;
835 asym
->flags
= BSF_DEBUGGING
;
838 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
839 asym
->value
-= asym
->section
->vma
;
842 asym
->section
= bfd_make_section_old_way (abfd
, ".rconst");
843 asym
->value
-= asym
->section
->vma
;
849 /* Look for special constructors symbols and make relocation entries
850 in a special construction section. These are produced by the
851 -fgnu-linker argument to g++. */
852 if (ECOFF_IS_STAB (ecoff_sym
))
854 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
863 /* Mark the symbol as a constructor. */
864 asym
->flags
|= BSF_CONSTRUCTOR
;
871 /* Read an ECOFF symbol table. */
874 _bfd_ecoff_slurp_symbol_table (bfd
*abfd
)
876 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
877 const bfd_size_type external_ext_size
878 = backend
->debug_swap
.external_ext_size
;
879 const bfd_size_type external_sym_size
880 = backend
->debug_swap
.external_sym_size
;
881 void (* const swap_ext_in
) (bfd
*, void *, EXTR
*)
882 = backend
->debug_swap
.swap_ext_in
;
883 void (* const swap_sym_in
) (bfd
*, void *, SYMR
*)
884 = backend
->debug_swap
.swap_sym_in
;
885 ecoff_symbol_type
*internal
;
886 ecoff_symbol_type
*internal_ptr
;
893 /* If we've already read in the symbol table, do nothing. */
894 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
897 /* Get the symbolic information. */
898 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, NULL
,
899 &ecoff_data (abfd
)->debug_info
))
901 if (bfd_get_symcount (abfd
) == 0)
904 if (_bfd_mul_overflow (bfd_get_symcount (abfd
),
905 sizeof (ecoff_symbol_type
), &amt
))
907 bfd_set_error (bfd_error_file_too_big
);
910 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, amt
);
911 if (internal
== NULL
)
914 internal_ptr
= internal
;
915 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
917 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
918 * external_ext_size
));
919 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
923 (*swap_ext_in
) (abfd
, (void *) eraw_src
, &internal_esym
);
925 /* PR 17512: file: 3372-1000-0.004. */
926 HDRR
*symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
927 if (internal_esym
.asym
.iss
>= symhdr
->issExtMax
928 || internal_esym
.asym
.iss
< 0)
930 bfd_set_error (bfd_error_bad_value
);
934 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
935 + internal_esym
.asym
.iss
);
937 if (!ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
938 &internal_ptr
->symbol
, 1,
939 internal_esym
.weakext
))
942 /* The alpha uses a negative ifd field for section symbols. */
943 /* PR 17512: file: 3372-1983-0.004. */
944 if (internal_esym
.ifd
>= symhdr
->ifdMax
945 || internal_esym
.ifd
< 0)
946 internal_ptr
->fdr
= NULL
;
948 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
949 + internal_esym
.ifd
);
950 internal_ptr
->local
= false;
951 internal_ptr
->native
= (void *) eraw_src
;
954 /* The local symbols must be accessed via the fdr's, because the
955 string and aux indices are relative to the fdr information. */
956 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
957 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
958 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
962 HDRR
*symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
964 if (fdr_ptr
->csym
== 0)
966 if (fdr_ptr
->isymBase
< 0
967 || fdr_ptr
->isymBase
> symhdr
->isymMax
969 || fdr_ptr
->csym
> symhdr
->isymMax
- fdr_ptr
->isymBase
970 || fdr_ptr
->csym
> ((long) bfd_get_symcount (abfd
)
971 - (internal_ptr
- internal
))
972 || fdr_ptr
->issBase
< 0
973 || fdr_ptr
->issBase
> symhdr
->issMax
)
975 bfd_set_error (bfd_error_bad_value
);
978 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
979 + fdr_ptr
->isymBase
* external_sym_size
);
980 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
983 lraw_src
+= external_sym_size
, internal_ptr
++)
987 (*swap_sym_in
) (abfd
, (void *) lraw_src
, &internal_sym
);
989 if (internal_sym
.iss
>= symhdr
->issMax
- fdr_ptr
->issBase
990 || internal_sym
.iss
< 0)
992 bfd_set_error (bfd_error_bad_value
);
995 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
998 if (!ecoff_set_symbol_info (abfd
, &internal_sym
,
999 &internal_ptr
->symbol
, 0, 0))
1001 internal_ptr
->fdr
= fdr_ptr
;
1002 internal_ptr
->local
= true;
1003 internal_ptr
->native
= (void *) lraw_src
;
1007 /* PR 17512: file: 3372-3080-0.004.
1008 A discrepancy between ecoff_data (abfd)->debug_info.symbolic_header.isymMax
1009 and ecoff_data (abfd)->debug_info.symbolic_header.ifdMax can mean that
1010 we have fewer symbols than we were expecting. Allow for this by updating
1011 the symbol count and warning the user. */
1012 if (internal_ptr
- internal
< (ptrdiff_t) bfd_get_symcount (abfd
))
1014 abfd
->symcount
= internal_ptr
- internal
;
1016 /* xgettext:c-format */
1017 (_("%pB: warning: isymMax (%ld) is greater than ifdMax (%ld)"),
1018 abfd
, ecoff_data (abfd
)->debug_info
.symbolic_header
.isymMax
,
1019 ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
);
1022 ecoff_data (abfd
)->canonical_symbols
= internal
;
1027 /* Return the amount of space needed for the canonical symbols. */
1030 _bfd_ecoff_get_symtab_upper_bound (bfd
*abfd
)
1032 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, NULL
,
1033 &ecoff_data (abfd
)->debug_info
))
1036 if (bfd_get_symcount (abfd
) == 0)
1039 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1042 /* Get the canonical symbols. */
1045 _bfd_ecoff_canonicalize_symtab (bfd
*abfd
, asymbol
**alocation
)
1047 unsigned int counter
= 0;
1048 ecoff_symbol_type
*symbase
;
1049 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1051 if (! _bfd_ecoff_slurp_symbol_table (abfd
))
1053 if (bfd_get_symcount (abfd
) == 0)
1056 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1057 while (counter
< bfd_get_symcount (abfd
))
1059 *(location
++) = symbase
++;
1063 return bfd_get_symcount (abfd
);
1066 /* Turn ECOFF type information into a printable string.
1067 ecoff_emit_aggregate and ecoff_type_to_string are from
1068 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1070 /* Write aggregate information to a string. */
1073 ecoff_emit_aggregate (bfd
*abfd
,
1080 const struct ecoff_debug_swap
* const debug_swap
=
1081 &ecoff_backend (abfd
)->debug_swap
;
1082 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1083 unsigned int ifd
= rndx
->rfd
;
1084 unsigned int indx
= rndx
->index
;
1090 /* An ifd of -1 is an opaque type. An escaped index of 0 is a
1091 struct return type of a procedure compiled without -g. */
1092 if (ifd
== 0xffffffff
1093 || (rndx
->rfd
== 0xfff && indx
== 0))
1094 name
= "<undefined>";
1095 else if (indx
== indexNil
)
1101 if (debug_info
->external_rfd
== NULL
)
1102 fdr
= debug_info
->fdr
+ ifd
;
1107 (*debug_swap
->swap_rfd_in
) (abfd
,
1108 ((char *) debug_info
->external_rfd
1109 + ((fdr
->rfdBase
+ ifd
)
1110 * debug_swap
->external_rfd_size
)),
1112 fdr
= debug_info
->fdr
+ rfd
;
1115 indx
+= fdr
->isymBase
;
1117 (*debug_swap
->swap_sym_in
) (abfd
,
1118 ((char *) debug_info
->external_sym
1119 + indx
* debug_swap
->external_sym_size
),
1122 name
= debug_info
->ss
+ fdr
->issBase
+ sym
.iss
;
1126 "%s %s { ifd = %u, index = %lu }",
1128 ((unsigned long) indx
1129 + debug_info
->symbolic_header
.iextMax
));
1132 /* Convert the type information to string format. */
1135 ecoff_type_to_string (bfd
*abfd
, FDR
*fdr
, unsigned int indx
, char *buff
)
1137 union aux_ext
*aux_ptr
;
1147 unsigned int basic_type
;
1154 aux_ptr
= ecoff_data (abfd
)->debug_info
.external_aux
+ fdr
->iauxBase
;
1155 bigendian
= fdr
->fBigendian
;
1157 for (i
= 0; i
< 7; i
++)
1159 qualifiers
[i
].low_bound
= 0;
1160 qualifiers
[i
].high_bound
= 0;
1161 qualifiers
[i
].stride
= 0;
1164 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == (bfd_vma
) -1)
1165 return "-1 (no type)";
1166 _bfd_ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1168 basic_type
= u
.ti
.bt
;
1169 qualifiers
[0].type
= u
.ti
.tq0
;
1170 qualifiers
[1].type
= u
.ti
.tq1
;
1171 qualifiers
[2].type
= u
.ti
.tq2
;
1172 qualifiers
[3].type
= u
.ti
.tq3
;
1173 qualifiers
[4].type
= u
.ti
.tq4
;
1174 qualifiers
[5].type
= u
.ti
.tq5
;
1175 qualifiers
[6].type
= tqNil
;
1177 /* Go get the basic type. */
1180 case btNil
: /* Undefined. */
1184 case btAdr
: /* Address - integer same size as pointer. */
1185 strcpy (p1
, "address");
1188 case btChar
: /* Character. */
1189 strcpy (p1
, "char");
1192 case btUChar
: /* Unsigned character. */
1193 strcpy (p1
, "unsigned char");
1196 case btShort
: /* Short. */
1197 strcpy (p1
, "short");
1200 case btUShort
: /* Unsigned short. */
1201 strcpy (p1
, "unsigned short");
1204 case btInt
: /* Int. */
1208 case btUInt
: /* Unsigned int. */
1209 strcpy (p1
, "unsigned int");
1212 case btLong
: /* Long. */
1213 strcpy (p1
, "long");
1216 case btULong
: /* Unsigned long. */
1217 strcpy (p1
, "unsigned long");
1220 case btFloat
: /* Float (real). */
1221 strcpy (p1
, "float");
1224 case btDouble
: /* Double (real). */
1225 strcpy (p1
, "double");
1228 /* Structures add 1-2 aux words:
1229 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1230 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1232 case btStruct
: /* Structure (Record). */
1233 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1234 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1235 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1237 indx
++; /* Skip aux words. */
1240 /* Unions add 1-2 aux words:
1241 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1242 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1244 case btUnion
: /* Union. */
1245 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1246 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1247 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1249 indx
++; /* Skip aux words. */
1252 /* Enumerations add 1-2 aux words:
1253 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1254 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1256 case btEnum
: /* Enumeration. */
1257 _bfd_ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1258 ecoff_emit_aggregate (abfd
, fdr
, p1
, &rndx
,
1259 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1261 indx
++; /* Skip aux words. */
1264 case btTypedef
: /* Defined via a typedef, isymRef points. */
1265 strcpy (p1
, "typedef");
1268 case btRange
: /* Subrange of int. */
1269 strcpy (p1
, "subrange");
1272 case btSet
: /* Pascal sets. */
1276 case btComplex
: /* Fortran complex. */
1277 strcpy (p1
, "complex");
1280 case btDComplex
: /* Fortran double complex. */
1281 strcpy (p1
, "double complex");
1284 case btIndirect
: /* Forward or unnamed typedef. */
1285 strcpy (p1
, "forward/unamed typedef");
1288 case btFixedDec
: /* Fixed Decimal. */
1289 strcpy (p1
, "fixed decimal");
1292 case btFloatDec
: /* Float Decimal. */
1293 strcpy (p1
, "float decimal");
1296 case btString
: /* Varying Length Character String. */
1297 strcpy (p1
, "string");
1300 case btBit
: /* Aligned Bit String. */
1304 case btPicture
: /* Picture. */
1305 strcpy (p1
, "picture");
1308 case btVoid
: /* Void. */
1309 strcpy (p1
, "void");
1313 sprintf (p1
, _("unknown basic type %d"), (int) basic_type
);
1319 /* If this is a bitfield, get the bitsize. */
1324 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1325 sprintf (p1
, " : %d", bitsize
);
1328 /* Deal with any qualifiers. */
1329 if (qualifiers
[0].type
!= tqNil
)
1331 /* Snarf up any array bounds in the correct order. Arrays
1332 store 5 successive words in the aux. table:
1333 word 0 RNDXR to type of the bounds (ie, int)
1334 word 1 Current file descriptor index
1336 word 3 high bound (or -1 if [])
1337 word 4 stride size in bits. */
1338 for (i
= 0; i
< 7; i
++)
1340 if (qualifiers
[i
].type
== tqArray
)
1342 qualifiers
[i
].low_bound
=
1343 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1344 qualifiers
[i
].high_bound
=
1345 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1346 qualifiers
[i
].stride
=
1347 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1352 /* Now print out the qualifiers. */
1353 for (i
= 0; i
< 6; i
++)
1355 switch (qualifiers
[i
].type
)
1362 strcpy (p2
, "ptr to ");
1363 p2
+= sizeof ("ptr to ")-1;
1367 strcpy (p2
, "volatile ");
1368 p2
+= sizeof ("volatile ")-1;
1372 strcpy (p2
, "far ");
1373 p2
+= sizeof ("far ")-1;
1377 strcpy (p2
, "func. ret. ");
1378 p2
+= sizeof ("func. ret. ");
1383 int first_array
= i
;
1386 /* Print array bounds reversed (ie, in the order the C
1387 programmer writes them). C is such a fun language.... */
1388 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1391 for (j
= i
; j
>= first_array
; j
--)
1393 strcpy (p2
, "array [");
1394 p2
+= sizeof ("array [")-1;
1395 if (qualifiers
[j
].low_bound
!= 0)
1397 "%ld:%ld {%ld bits}",
1398 (long) qualifiers
[j
].low_bound
,
1399 (long) qualifiers
[j
].high_bound
,
1400 (long) qualifiers
[j
].stride
);
1402 else if (qualifiers
[j
].high_bound
!= -1)
1405 (long) (qualifiers
[j
].high_bound
+ 1),
1406 (long) (qualifiers
[j
].stride
));
1409 sprintf (p2
, " {%ld bits}", (long) qualifiers
[j
].stride
);
1412 strcpy (p2
, "] of ");
1413 p2
+= sizeof ("] of ")-1;
1421 strcpy (p2
, buffer1
);
1425 /* Return information about ECOFF symbol SYMBOL in RET. */
1428 _bfd_ecoff_get_symbol_info (bfd
*abfd ATTRIBUTE_UNUSED
,
1432 bfd_symbol_info (symbol
, ret
);
1435 /* Return whether this is a local label. */
1438 _bfd_ecoff_bfd_is_local_label_name (bfd
*abfd ATTRIBUTE_UNUSED
,
1441 return name
[0] == '$';
1444 /* Print information about an ECOFF symbol. */
1447 _bfd_ecoff_print_symbol (bfd
*abfd
,
1450 bfd_print_symbol_type how
)
1452 const struct ecoff_debug_swap
* const debug_swap
1453 = &ecoff_backend (abfd
)->debug_swap
;
1454 FILE *file
= (FILE *)filep
;
1458 case bfd_print_symbol_name
:
1459 fprintf (file
, "%s", symbol
->name
);
1461 case bfd_print_symbol_more
:
1462 if (ecoffsymbol (symbol
)->local
)
1466 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1468 fprintf (file
, "ecoff local ");
1469 bfd_fprintf_vma (abfd
, file
, ecoff_sym
.value
);
1470 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1471 (unsigned) ecoff_sym
.sc
);
1477 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1479 fprintf (file
, "ecoff extern ");
1480 bfd_fprintf_vma (abfd
, file
, ecoff_ext
.asym
.value
);
1481 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1482 (unsigned) ecoff_ext
.asym
.sc
);
1485 case bfd_print_symbol_all
:
1486 /* Print out the symbols in a reasonable way. */
1495 if (ecoffsymbol (symbol
)->local
)
1497 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1500 pos
= ((((char *) ecoffsymbol (symbol
)->native
1501 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1502 / debug_swap
->external_sym_size
)
1503 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1510 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1513 pos
= (((char *) ecoffsymbol (symbol
)->native
1514 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1515 / debug_swap
->external_ext_size
);
1516 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1517 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1518 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1521 fprintf (file
, "[%3d] %c ",
1523 bfd_fprintf_vma (abfd
, file
, ecoff_ext
.asym
.value
);
1524 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1525 (unsigned) ecoff_ext
.asym
.st
,
1526 (unsigned) ecoff_ext
.asym
.sc
,
1527 (unsigned) ecoff_ext
.asym
.index
,
1528 jmptbl
, cobol_main
, weakext
,
1531 if (ecoffsymbol (symbol
)->fdr
!= NULL
1532 && ecoff_ext
.asym
.index
!= indexNil
)
1537 bfd_size_type sym_base
;
1538 union aux_ext
*aux_base
;
1540 fdr
= ecoffsymbol (symbol
)->fdr
;
1541 indx
= ecoff_ext
.asym
.index
;
1543 /* sym_base is used to map the fdr relative indices which
1544 appear in the file to the position number which we are
1546 sym_base
= fdr
->isymBase
;
1547 if (ecoffsymbol (symbol
)->local
)
1549 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1551 /* aux_base is the start of the aux entries for this file;
1552 asym.index is an offset from this. */
1553 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1556 /* The aux entries are stored in host byte order; the
1557 order is indicated by a bit in the fdr. */
1558 bigendian
= fdr
->fBigendian
;
1560 /* This switch is basically from gcc/mips-tdump.c. */
1561 switch (ecoff_ext
.asym
.st
)
1569 fprintf (file
, _("\n End+1 symbol: %ld"),
1570 (long) (indx
+ sym_base
));
1574 if (ecoff_ext
.asym
.sc
== scText
1575 || ecoff_ext
.asym
.sc
== scInfo
)
1576 fprintf (file
, _("\n First symbol: %ld"),
1577 (long) (indx
+ sym_base
));
1579 fprintf (file
, _("\n First symbol: %ld"),
1581 (AUX_GET_ISYM (bigendian
,
1582 &aux_base
[ecoff_ext
.asym
.index
])
1588 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1590 else if (ecoffsymbol (symbol
)->local
)
1593 /* xgettext:c-format */
1594 fprintf (file
, _("\n End+1 symbol: %-7ld Type: %s"),
1596 (AUX_GET_ISYM (bigendian
,
1597 &aux_base
[ecoff_ext
.asym
.index
])
1599 ecoff_type_to_string (abfd
, fdr
, indx
+ 1, buff
));
1602 fprintf (file
, _("\n Local symbol: %ld"),
1605 + (ecoff_data (abfd
)
1606 ->debug_info
.symbolic_header
.iextMax
)));
1610 fprintf (file
, _("\n struct; End+1 symbol: %ld"),
1611 (long) (indx
+ sym_base
));
1615 fprintf (file
, _("\n union; End+1 symbol: %ld"),
1616 (long) (indx
+ sym_base
));
1620 fprintf (file
, _("\n enum; End+1 symbol: %ld"),
1621 (long) (indx
+ sym_base
));
1625 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1628 fprintf (file
, _("\n Type: %s"),
1629 ecoff_type_to_string (abfd
, fdr
, indx
, buff
));
1639 /* Read in the relocs for a section. */
1642 ecoff_slurp_reloc_table (bfd
*abfd
,
1646 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1647 arelent
*internal_relocs
;
1648 bfd_size_type external_reloc_size
;
1650 bfd_byte
*external_relocs
;
1654 if (section
->relocation
!= NULL
1655 || section
->reloc_count
== 0
1656 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1659 if (! _bfd_ecoff_slurp_symbol_table (abfd
))
1662 external_reloc_size
= backend
->external_reloc_size
;
1663 amt
= external_reloc_size
* section
->reloc_count
;
1664 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1666 external_relocs
= _bfd_malloc_and_read (abfd
, amt
, amt
);
1667 if (external_relocs
== NULL
)
1670 amt
= section
->reloc_count
;
1671 amt
*= sizeof (arelent
);
1672 internal_relocs
= (arelent
*) bfd_alloc (abfd
, amt
);
1673 if (internal_relocs
== NULL
)
1675 free (external_relocs
);
1679 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1681 struct internal_reloc intern
;
1683 (*backend
->swap_reloc_in
) (abfd
,
1684 external_relocs
+ i
* external_reloc_size
,
1686 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
1689 if (intern
.r_extern
)
1691 /* r_symndx is an index into the external symbols. */
1693 && intern
.r_symndx
>= 0
1695 < (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
)))
1696 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1700 const char *sec_name
;
1703 /* r_symndx is a section key. */
1704 switch (intern
.r_symndx
)
1706 case RELOC_SECTION_TEXT
: sec_name
= _TEXT
; break;
1707 case RELOC_SECTION_RDATA
: sec_name
= _RDATA
; break;
1708 case RELOC_SECTION_DATA
: sec_name
= _DATA
; break;
1709 case RELOC_SECTION_SDATA
: sec_name
= _SDATA
; break;
1710 case RELOC_SECTION_SBSS
: sec_name
= _SBSS
; break;
1711 case RELOC_SECTION_BSS
: sec_name
= _BSS
; break;
1712 case RELOC_SECTION_INIT
: sec_name
= _INIT
; break;
1713 case RELOC_SECTION_LIT8
: sec_name
= _LIT8
; break;
1714 case RELOC_SECTION_LIT4
: sec_name
= _LIT4
; break;
1715 case RELOC_SECTION_XDATA
: sec_name
= _XDATA
; break;
1716 case RELOC_SECTION_PDATA
: sec_name
= _PDATA
; break;
1717 case RELOC_SECTION_FINI
: sec_name
= _FINI
; break;
1718 case RELOC_SECTION_LITA
: sec_name
= _LITA
; break;
1719 case RELOC_SECTION_RCONST
: sec_name
= _RCONST
; break;
1725 if (sec_name
!= NULL
)
1727 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1730 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1731 rptr
->addend
= - bfd_section_vma (sec
);
1736 rptr
->address
= intern
.r_vaddr
- bfd_section_vma (section
);
1738 /* Let the backend select the howto field and do any other
1739 required processing. */
1740 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1743 free (external_relocs
);
1745 section
->relocation
= internal_relocs
;
1750 /* Get a canonical list of relocs. */
1753 _bfd_ecoff_canonicalize_reloc (bfd
*abfd
,
1760 if (section
->flags
& SEC_CONSTRUCTOR
)
1762 arelent_chain
*chain
;
1764 /* This section has relocs made up by us, not the file, so take
1765 them out of their chain and place them into the data area
1767 for (count
= 0, chain
= section
->constructor_chain
;
1768 count
< section
->reloc_count
;
1769 count
++, chain
= chain
->next
)
1770 *relptr
++ = &chain
->relent
;
1776 if (! ecoff_slurp_reloc_table (abfd
, section
, symbols
))
1779 tblptr
= section
->relocation
;
1781 for (count
= 0; count
< section
->reloc_count
; count
++)
1782 *relptr
++ = tblptr
++;
1787 return section
->reloc_count
;
1790 /* Provided a BFD, a section and an offset into the section, calculate
1791 and return the name of the source file and the line nearest to the
1795 _bfd_ecoff_find_nearest_line (bfd
*abfd
,
1796 asymbol
**symbols ATTRIBUTE_UNUSED
,
1799 const char **filename_ptr
,
1800 const char **functionname_ptr
,
1801 unsigned int *retline_ptr
,
1802 unsigned int *discriminator_ptr
)
1804 const struct ecoff_debug_swap
* const debug_swap
1805 = &ecoff_backend (abfd
)->debug_swap
;
1806 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1807 struct ecoff_find_line
*line_info
;
1809 /* Make sure we have the FDR's. */
1810 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, NULL
, debug_info
)
1811 || bfd_get_symcount (abfd
) == 0)
1814 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1816 size_t amt
= sizeof (struct ecoff_find_line
);
1818 ecoff_data (abfd
)->find_line_info
=
1819 (struct ecoff_find_line
*) bfd_zalloc (abfd
, amt
);
1820 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1824 if (discriminator_ptr
)
1825 *discriminator_ptr
= 0;
1826 line_info
= ecoff_data (abfd
)->find_line_info
;
1827 return _bfd_ecoff_locate_line (abfd
, section
, offset
, debug_info
,
1828 debug_swap
, line_info
, filename_ptr
,
1829 functionname_ptr
, retline_ptr
);
1832 /* Copy private BFD data. This is called by objcopy and strip. We
1833 use it to copy the ECOFF debugging information from one BFD to the
1834 other. It would be theoretically possible to represent the ECOFF
1835 debugging information in the symbol table. However, it would be a
1836 lot of work, and there would be little gain (gas, gdb, and ld
1837 already access the ECOFF debugging information via the
1838 ecoff_debug_info structure, and that structure would have to be
1839 retained in order to support ECOFF debugging in MIPS ELF).
1841 The debugging information for the ECOFF external symbols comes from
1842 the symbol table, so this function only handles the other debugging
1846 _bfd_ecoff_bfd_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
1848 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
1849 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
1851 asymbol
**sym_ptr_ptr
;
1855 /* We only want to copy information over if both BFD's use ECOFF
1857 if (bfd_get_flavour (ibfd
) != bfd_target_ecoff_flavour
1858 || bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
1861 /* Copy the GP value and the register masks. */
1862 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
1863 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
1864 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
1865 for (i
= 0; i
< 3; i
++)
1866 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
1868 /* Copy the version stamp. */
1869 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
1871 /* If there are no symbols, don't copy any debugging information. */
1872 c
= bfd_get_symcount (obfd
);
1873 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1874 if (c
== 0 || sym_ptr_ptr
== NULL
)
1877 /* See if there are any local symbols. */
1879 for (; c
> 0; c
--, sym_ptr_ptr
++)
1881 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
1890 /* There are some local symbols. We just bring over all the
1891 debugging information. FIXME: This is not quite the right
1892 thing to do. If the user has asked us to discard all
1893 debugging information, then we are probably going to wind up
1894 keeping it because there will probably be some local symbol
1895 which objcopy did not discard. We should actually break
1896 apart the debugging information and only keep that which
1897 applies to the symbols we want to keep. */
1898 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
1899 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
1900 oinfo
->line
= iinfo
->line
;
1902 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
1903 oinfo
->external_dnr
= iinfo
->external_dnr
;
1905 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
1906 oinfo
->external_pdr
= iinfo
->external_pdr
;
1908 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
1909 oinfo
->external_sym
= iinfo
->external_sym
;
1911 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
1912 oinfo
->external_opt
= iinfo
->external_opt
;
1914 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
1915 oinfo
->external_aux
= iinfo
->external_aux
;
1917 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
1918 oinfo
->ss
= iinfo
->ss
;
1920 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
1921 oinfo
->external_fdr
= iinfo
->external_fdr
;
1923 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
1924 oinfo
->external_rfd
= iinfo
->external_rfd
;
1926 /* Flag that oinfo entries should not be freed. */
1927 oinfo
->alloc_syments
= true;
1931 /* We are discarding all the local symbol information. Look
1932 through the external symbols and remove all references to FDR
1933 or aux information. */
1934 c
= bfd_get_symcount (obfd
);
1935 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1936 for (; c
> 0; c
--, sym_ptr_ptr
++)
1940 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
1941 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
1943 esym
.asym
.index
= indexNil
;
1944 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
1945 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
1952 /* Set the architecture. The supported architecture is stored in the
1953 backend pointer. We always set the architecture anyhow, since many
1954 callers ignore the return value. */
1957 _bfd_ecoff_set_arch_mach (bfd
*abfd
,
1958 enum bfd_architecture arch
,
1959 unsigned long machine
)
1961 bfd_default_set_arch_mach (abfd
, arch
, machine
);
1962 return arch
== ecoff_backend (abfd
)->arch
;
1965 /* Get the size of the section headers. */
1968 _bfd_ecoff_sizeof_headers (bfd
*abfd
,
1969 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
1976 for (current
= abfd
->sections
;
1978 current
= current
->next
)
1981 ret
= (bfd_coff_filhsz (abfd
)
1982 + bfd_coff_aoutsz (abfd
)
1983 + c
* bfd_coff_scnhsz (abfd
));
1984 return (int) BFD_ALIGN (ret
, 16);
1987 /* Get the contents of a section. */
1990 _bfd_ecoff_get_section_contents (bfd
*abfd
,
1994 bfd_size_type count
)
1996 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2000 /* Sort sections by VMA, but put SEC_ALLOC sections first. This is
2001 called via qsort. */
2004 ecoff_sort_hdrs (const void * arg1
, const void * arg2
)
2006 const asection
*hdr1
= *(const asection
**) arg1
;
2007 const asection
*hdr2
= *(const asection
**) arg2
;
2009 if ((hdr1
->flags
& SEC_ALLOC
) != 0)
2011 if ((hdr2
->flags
& SEC_ALLOC
) == 0)
2016 if ((hdr2
->flags
& SEC_ALLOC
) != 0)
2019 if (hdr1
->vma
< hdr2
->vma
)
2021 else if (hdr1
->vma
> hdr2
->vma
)
2027 /* Calculate the file position for each section, and set
2031 ecoff_compute_section_file_positions (bfd
*abfd
)
2033 file_ptr sofar
, file_sofar
;
2034 asection
**sorted_hdrs
;
2039 bool first_data
, first_nonalloc
;
2040 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2043 sofar
= _bfd_ecoff_sizeof_headers (abfd
, NULL
);
2046 /* Sort the sections by VMA. */
2047 amt
= abfd
->section_count
;
2048 amt
*= sizeof (asection
*);
2049 sorted_hdrs
= (asection
**) bfd_malloc (amt
);
2050 if (sorted_hdrs
== NULL
)
2052 for (current
= abfd
->sections
, i
= 0;
2054 current
= current
->next
, i
++)
2055 sorted_hdrs
[i
] = current
;
2056 BFD_ASSERT (i
== abfd
->section_count
);
2058 qsort (sorted_hdrs
, abfd
->section_count
, sizeof (asection
*),
2061 /* Some versions of the OSF linker put the .rdata section in the
2062 text segment, and some do not. */
2063 rdata_in_text
= ecoff_backend (abfd
)->rdata_in_text
;
2066 for (i
= 0; i
< abfd
->section_count
; i
++)
2068 current
= sorted_hdrs
[i
];
2069 if (streq (current
->name
, _RDATA
))
2071 if ((current
->flags
& SEC_CODE
) == 0
2072 && ! streq (current
->name
, _PDATA
)
2073 && ! streq (current
->name
, _RCONST
))
2075 rdata_in_text
= false;
2080 ecoff_data (abfd
)->rdata_in_text
= rdata_in_text
;
2083 first_nonalloc
= true;
2084 for (i
= 0; i
< abfd
->section_count
; i
++)
2086 unsigned int alignment_power
;
2088 current
= sorted_hdrs
[i
];
2090 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2091 supposed to indicate the number of .pdata entries that are
2092 really in the section. Each entry is 8 bytes. We store this
2093 away in line_filepos before increasing the section size. */
2094 if (streq (current
->name
, _PDATA
))
2095 current
->line_filepos
= current
->size
/ 8;
2097 alignment_power
= current
->alignment_power
;
2099 /* On Ultrix, the data sections in an executable file must be
2100 aligned to a page boundary within the file. This does not
2101 affect the section size, though. FIXME: Does this work for
2102 other platforms? It requires some modification for the
2103 Alpha, because .rdata on the Alpha goes with the text, not
2105 if ((abfd
->flags
& EXEC_P
) != 0
2106 && (abfd
->flags
& D_PAGED
) != 0
2108 && (current
->flags
& SEC_CODE
) == 0
2110 || ! streq (current
->name
, _RDATA
))
2111 && ! streq (current
->name
, _PDATA
)
2112 && ! streq (current
->name
, _RCONST
))
2114 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2115 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2118 else if (streq (current
->name
, _LIB
))
2120 /* On Irix 4, the location of contents of the .lib section
2121 from a shared library section is also rounded up to a
2124 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2125 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2127 else if (first_nonalloc
2128 && (current
->flags
& SEC_ALLOC
) == 0
2129 && (abfd
->flags
& D_PAGED
) != 0)
2131 /* Skip up to the next page for an unallocated section, such
2132 as the .comment section on the Alpha. This leaves room
2133 for the .bss section. */
2134 first_nonalloc
= false;
2135 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2136 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2139 /* Align the sections in the file to the same boundary on
2140 which they are aligned in virtual memory. */
2141 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2142 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2143 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2145 if ((abfd
->flags
& D_PAGED
) != 0
2146 && (current
->flags
& SEC_ALLOC
) != 0)
2148 sofar
+= (current
->vma
- sofar
) % round
;
2149 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2150 file_sofar
+= (current
->vma
- file_sofar
) % round
;
2153 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) != 0)
2154 current
->filepos
= file_sofar
;
2156 sofar
+= current
->size
;
2157 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2158 file_sofar
+= current
->size
;
2160 /* Make sure that this section is of the right size too. */
2162 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2163 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2164 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2165 current
->size
+= sofar
- old_sofar
;
2171 ecoff_data (abfd
)->reloc_filepos
= file_sofar
;
2176 /* Determine the location of the relocs for all the sections in the
2177 output file, as well as the location of the symbolic debugging
2180 static bfd_size_type
2181 ecoff_compute_reloc_file_positions (bfd
*abfd
)
2183 const bfd_size_type external_reloc_size
=
2184 ecoff_backend (abfd
)->external_reloc_size
;
2185 file_ptr reloc_base
;
2186 bfd_size_type reloc_size
;
2190 if (! abfd
->output_has_begun
)
2192 if (! ecoff_compute_section_file_positions (abfd
))
2194 abfd
->output_has_begun
= true;
2197 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2200 for (current
= abfd
->sections
;
2202 current
= current
->next
)
2204 if (current
->reloc_count
== 0)
2205 current
->rel_filepos
= 0;
2208 bfd_size_type relsize
;
2210 current
->rel_filepos
= reloc_base
;
2211 relsize
= current
->reloc_count
* external_reloc_size
;
2212 reloc_size
+= relsize
;
2213 reloc_base
+= relsize
;
2217 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2219 /* At least on Ultrix, the symbol table of an executable file must
2220 be aligned to a page boundary. FIXME: Is this true on other
2222 if ((abfd
->flags
& EXEC_P
) != 0
2223 && (abfd
->flags
& D_PAGED
) != 0)
2224 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2225 &~ (ecoff_backend (abfd
)->round
- 1));
2227 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2232 /* Set the contents of a section. */
2235 _bfd_ecoff_set_section_contents (bfd
*abfd
,
2237 const void * location
,
2239 bfd_size_type count
)
2243 /* This must be done first, because bfd_set_section_contents is
2244 going to set output_has_begun to TRUE. */
2245 if (! abfd
->output_has_begun
2246 && ! ecoff_compute_section_file_positions (abfd
))
2249 /* Handle the .lib section specially so that Irix 4 shared libraries
2250 work out. See coff_set_section_contents in coffcode.h. */
2251 if (streq (section
->name
, _LIB
))
2253 bfd_byte
*rec
, *recend
;
2255 rec
= (bfd_byte
*) location
;
2256 recend
= rec
+ count
;
2257 while (rec
< recend
)
2260 rec
+= bfd_get_32 (abfd
, rec
) * 4;
2263 BFD_ASSERT (rec
== recend
);
2269 pos
= section
->filepos
+ offset
;
2270 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
2271 || bfd_write (location
, count
, abfd
) != count
)
2277 /* Set the GP value for an ECOFF file. This is a hook used by the
2281 bfd_ecoff_set_gp_value (bfd
*abfd
, bfd_vma gp_value
)
2283 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2284 || bfd_get_format (abfd
) != bfd_object
)
2286 bfd_set_error (bfd_error_invalid_operation
);
2290 ecoff_data (abfd
)->gp
= gp_value
;
2295 /* Set the register masks for an ECOFF file. This is a hook used by
2299 bfd_ecoff_set_regmasks (bfd
*abfd
,
2300 unsigned long gprmask
,
2301 unsigned long fprmask
,
2302 unsigned long *cprmask
)
2304 ecoff_data_type
*tdata
;
2306 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2307 || bfd_get_format (abfd
) != bfd_object
)
2309 bfd_set_error (bfd_error_invalid_operation
);
2313 tdata
= ecoff_data (abfd
);
2314 tdata
->gprmask
= gprmask
;
2315 tdata
->fprmask
= fprmask
;
2316 if (cprmask
!= NULL
)
2320 for (i
= 0; i
< 3; i
++)
2321 tdata
->cprmask
[i
] = cprmask
[i
];
2327 /* Get ECOFF EXTR information for an external symbol. This function
2328 is passed to bfd_ecoff_debug_externals. */
2331 ecoff_get_extr (asymbol
*sym
, EXTR
*esym
)
2333 ecoff_symbol_type
*ecoff_sym_ptr
;
2336 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2337 || ecoffsymbol (sym
)->native
== NULL
)
2339 /* Don't include debugging, local, or section symbols. */
2340 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2341 || (sym
->flags
& BSF_LOCAL
) != 0
2342 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2346 esym
->cobol_main
= 0;
2347 esym
->weakext
= (sym
->flags
& BSF_WEAK
) != 0;
2350 /* FIXME: we can do better than this for st and sc. */
2351 esym
->asym
.st
= stGlobal
;
2352 esym
->asym
.sc
= scAbs
;
2353 esym
->asym
.reserved
= 0;
2354 esym
->asym
.index
= indexNil
;
2358 ecoff_sym_ptr
= ecoffsymbol (sym
);
2360 if (ecoff_sym_ptr
->local
)
2363 input_bfd
= bfd_asymbol_bfd (sym
);
2364 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2365 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2367 /* If the symbol was defined by the linker, then esym will be
2368 undefined but sym will not be. Get a better class for such a
2370 if ((esym
->asym
.sc
== scUndefined
2371 || esym
->asym
.sc
== scSUndefined
)
2372 && ! bfd_is_und_section (bfd_asymbol_section (sym
)))
2373 esym
->asym
.sc
= scAbs
;
2375 /* Adjust the FDR index for the symbol by that used for the input
2377 if (esym
->ifd
!= -1)
2379 struct ecoff_debug_info
*input_debug
;
2381 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2382 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2383 if (input_debug
->ifdmap
!= NULL
)
2384 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2390 /* Set the external symbol index. This routine is passed to
2391 bfd_ecoff_debug_externals. */
2394 ecoff_set_index (asymbol
*sym
, bfd_size_type indx
)
2396 ecoff_set_sym_index (sym
, indx
);
2399 /* Write out an ECOFF file. */
2402 _bfd_ecoff_write_object_contents (bfd
*abfd
)
2404 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2405 const bfd_vma round
= backend
->round
;
2406 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2407 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2408 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2409 const bfd_size_type external_hdr_size
2410 = backend
->debug_swap
.external_hdr_size
;
2411 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2412 void (* const adjust_reloc_out
) (bfd
*, const arelent
*, struct internal_reloc
*)
2413 = backend
->adjust_reloc_out
;
2414 void (* const swap_reloc_out
) (bfd
*, const struct internal_reloc
*, void *)
2415 = backend
->swap_reloc_out
;
2416 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2417 HDRR
* const symhdr
= &debug
->symbolic_header
;
2420 bfd_size_type reloc_size
;
2421 bfd_size_type text_size
;
2423 bool set_text_start
;
2424 bfd_size_type data_size
;
2426 bool set_data_start
;
2427 bfd_size_type bss_size
;
2429 void * reloc_buff
= NULL
;
2430 struct internal_filehdr internal_f
;
2431 struct internal_aouthdr internal_a
;
2434 /* Determine where the sections and relocs will go in the output
2436 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2439 for (current
= abfd
->sections
;
2441 current
= current
->next
)
2443 current
->target_index
= count
;
2447 if ((abfd
->flags
& D_PAGED
) != 0)
2448 text_size
= _bfd_ecoff_sizeof_headers (abfd
, NULL
);
2452 set_text_start
= false;
2455 set_data_start
= false;
2458 /* Write section headers to the file. */
2460 /* Allocate buff big enough to hold a section header,
2461 file header, or a.out header. */
2470 buff
= bfd_malloc (siz
);
2475 internal_f
.f_nscns
= 0;
2476 if (bfd_seek (abfd
, filhsz
+ aoutsz
, SEEK_SET
) != 0)
2479 for (current
= abfd
->sections
;
2481 current
= current
->next
)
2483 struct internal_scnhdr section
;
2486 ++internal_f
.f_nscns
;
2488 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2490 /* This seems to be correct for Irix 4 shared libraries. */
2491 vma
= bfd_section_vma (current
);
2492 if (streq (current
->name
, _LIB
))
2493 section
.s_vaddr
= 0;
2495 section
.s_vaddr
= vma
;
2497 section
.s_paddr
= current
->lma
;
2498 section
.s_size
= current
->size
;
2500 /* If this section is unloadable then the scnptr will be 0. */
2501 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2502 section
.s_scnptr
= 0;
2504 section
.s_scnptr
= current
->filepos
;
2505 section
.s_relptr
= current
->rel_filepos
;
2507 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2508 object file produced by the assembler is supposed to point to
2509 information about how much room is required by objects of
2510 various different sizes. I think this only matters if we
2511 want the linker to compute the best size to use, or
2512 something. I don't know what happens if the information is
2514 if (! streq (current
->name
, _PDATA
))
2515 section
.s_lnnoptr
= 0;
2518 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2519 hold the number of entries in the section (each entry is
2520 8 bytes). We stored this in the line_filepos field in
2521 ecoff_compute_section_file_positions. */
2522 section
.s_lnnoptr
= current
->line_filepos
;
2525 section
.s_nreloc
= current
->reloc_count
;
2526 section
.s_nlnno
= 0;
2527 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2530 if (bfd_coff_swap_scnhdr_out (abfd
, (void *) §ion
, buff
) == 0
2531 || bfd_write (buff
, scnhsz
, abfd
) != scnhsz
)
2534 if ((section
.s_flags
& STYP_TEXT
) != 0
2535 || ((section
.s_flags
& STYP_RDATA
) != 0
2536 && ecoff_data (abfd
)->rdata_in_text
)
2537 || section
.s_flags
== STYP_PDATA
2538 || (section
.s_flags
& STYP_DYNAMIC
) != 0
2539 || (section
.s_flags
& STYP_LIBLIST
) != 0
2540 || (section
.s_flags
& STYP_RELDYN
) != 0
2541 || section
.s_flags
== STYP_CONFLIC
2542 || (section
.s_flags
& STYP_DYNSTR
) != 0
2543 || (section
.s_flags
& STYP_DYNSYM
) != 0
2544 || (section
.s_flags
& STYP_HASH
) != 0
2545 || (section
.s_flags
& STYP_ECOFF_INIT
) != 0
2546 || (section
.s_flags
& STYP_ECOFF_FINI
) != 0
2547 || section
.s_flags
== STYP_RCONST
)
2549 text_size
+= current
->size
;
2550 if (! set_text_start
|| text_start
> vma
)
2553 set_text_start
= true;
2556 else if ((section
.s_flags
& STYP_RDATA
) != 0
2557 || (section
.s_flags
& STYP_DATA
) != 0
2558 || (section
.s_flags
& STYP_LITA
) != 0
2559 || (section
.s_flags
& STYP_LIT8
) != 0
2560 || (section
.s_flags
& STYP_LIT4
) != 0
2561 || (section
.s_flags
& STYP_SDATA
) != 0
2562 || section
.s_flags
== STYP_XDATA
2563 || (section
.s_flags
& STYP_GOT
) != 0)
2565 data_size
+= current
->size
;
2566 if (! set_data_start
|| data_start
> vma
)
2569 set_data_start
= true;
2572 else if ((section
.s_flags
& STYP_BSS
) != 0
2573 || (section
.s_flags
& STYP_SBSS
) != 0)
2574 bss_size
+= current
->size
;
2575 else if (section
.s_flags
== 0
2576 || (section
.s_flags
& STYP_ECOFF_LIB
) != 0
2577 || section
.s_flags
== STYP_COMMENT
)
2583 /* Set up the file header. */
2584 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2586 /* We will NOT put a fucking timestamp in the header here. Every
2587 time you put it back, I will come in and take it out again. I'm
2588 sorry. This field does not belong here. We fill it with a 0 so
2589 it compares the same but is not a reasonable time. --
2591 internal_f
.f_timdat
= 0;
2593 if (bfd_get_symcount (abfd
) != 0)
2595 /* The ECOFF f_nsyms field is not actually the number of
2596 symbols, it's the size of symbolic information header. */
2597 internal_f
.f_nsyms
= external_hdr_size
;
2598 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2602 internal_f
.f_nsyms
= 0;
2603 internal_f
.f_symptr
= 0;
2606 internal_f
.f_opthdr
= aoutsz
;
2608 internal_f
.f_flags
= F_LNNO
;
2609 if (reloc_size
== 0)
2610 internal_f
.f_flags
|= F_RELFLG
;
2611 if (bfd_get_symcount (abfd
) == 0)
2612 internal_f
.f_flags
|= F_LSYMS
;
2613 if (abfd
->flags
& EXEC_P
)
2614 internal_f
.f_flags
|= F_EXEC
;
2616 if (bfd_little_endian (abfd
))
2617 internal_f
.f_flags
|= F_AR32WR
;
2619 internal_f
.f_flags
|= F_AR32W
;
2621 /* Set up the ``optional'' header. */
2622 if ((abfd
->flags
& D_PAGED
) != 0)
2623 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2625 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2627 /* FIXME: Is this really correct? */
2628 internal_a
.vstamp
= symhdr
->vstamp
;
2630 /* At least on Ultrix, these have to be rounded to page boundaries.
2631 FIXME: Is this true on other platforms? */
2632 if ((abfd
->flags
& D_PAGED
) != 0)
2634 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2635 internal_a
.text_start
= text_start
&~ (round
- 1);
2636 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2637 internal_a
.data_start
= data_start
&~ (round
- 1);
2641 internal_a
.tsize
= text_size
;
2642 internal_a
.text_start
= text_start
;
2643 internal_a
.dsize
= data_size
;
2644 internal_a
.data_start
= data_start
;
2647 /* On Ultrix, the initial portions of the .sbss and .bss segments
2648 are at the end of the data section. The bsize field in the
2649 optional header records how many bss bytes are required beyond
2650 those in the data section. The value is not rounded to a page
2652 if (bss_size
< internal_a
.dsize
- data_size
)
2655 bss_size
-= internal_a
.dsize
- data_size
;
2656 internal_a
.bsize
= bss_size
;
2657 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2659 internal_a
.entry
= bfd_get_start_address (abfd
);
2661 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2663 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2664 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2665 for (i
= 0; i
< 4; i
++)
2666 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2668 /* Let the backend adjust the headers if necessary. */
2669 if (backend
->adjust_headers
)
2671 if (! (*backend
->adjust_headers
) (abfd
, &internal_f
, &internal_a
))
2675 /* Write out the file header and the optional header. */
2676 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0)
2679 bfd_coff_swap_filehdr_out (abfd
, (void *) &internal_f
, buff
);
2680 if (bfd_write (buff
, filhsz
, abfd
) != filhsz
)
2683 bfd_coff_swap_aouthdr_out (abfd
, (void *) &internal_a
, buff
);
2684 if (bfd_write (buff
, aoutsz
, abfd
) != aoutsz
)
2687 /* Build the external symbol information. This must be done before
2688 writing out the relocs so that we know the symbol indices. We
2689 don't do this if this BFD was created by the backend linker,
2690 since it will have already handled the symbols and relocs. */
2691 if (! ecoff_data (abfd
)->linker
)
2693 symhdr
->iextMax
= 0;
2694 symhdr
->issExtMax
= 0;
2695 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2696 debug
->ssext
= debug
->ssext_end
= NULL
;
2697 if (! bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2698 (abfd
->flags
& EXEC_P
) == 0,
2699 ecoff_get_extr
, ecoff_set_index
))
2702 /* Write out the relocs. */
2703 for (current
= abfd
->sections
;
2705 current
= current
->next
)
2707 arelent
**reloc_ptr_ptr
;
2708 arelent
**reloc_end
;
2712 if (current
->reloc_count
== 0)
2715 amt
= current
->reloc_count
* external_reloc_size
;
2716 reloc_buff
= bfd_zalloc (abfd
, amt
);
2717 if (reloc_buff
== NULL
)
2720 reloc_ptr_ptr
= current
->orelocation
;
2721 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2722 out_ptr
= (char *) reloc_buff
;
2725 reloc_ptr_ptr
< reloc_end
;
2726 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2730 struct internal_reloc in
;
2732 memset ((void *) &in
, 0, sizeof in
);
2734 reloc
= *reloc_ptr_ptr
;
2735 sym
= *reloc
->sym_ptr_ptr
;
2737 /* If the howto field has not been initialised then skip this reloc.
2738 This assumes that an error message has been issued elsewhere. */
2739 if (reloc
->howto
== NULL
)
2742 in
.r_vaddr
= reloc
->address
+ bfd_section_vma (current
);
2743 in
.r_type
= reloc
->howto
->type
;
2745 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2747 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2761 { _TEXT
, RELOC_SECTION_TEXT
},
2762 { _RDATA
, RELOC_SECTION_RDATA
},
2763 { _DATA
, RELOC_SECTION_DATA
},
2764 { _SDATA
, RELOC_SECTION_SDATA
},
2765 { _SBSS
, RELOC_SECTION_SBSS
},
2766 { _BSS
, RELOC_SECTION_BSS
},
2767 { _INIT
, RELOC_SECTION_INIT
},
2768 { _LIT8
, RELOC_SECTION_LIT8
},
2769 { _LIT4
, RELOC_SECTION_LIT4
},
2770 { _XDATA
, RELOC_SECTION_XDATA
},
2771 { _PDATA
, RELOC_SECTION_PDATA
},
2772 { _FINI
, RELOC_SECTION_FINI
},
2773 { _LITA
, RELOC_SECTION_LITA
},
2774 { "*ABS*", RELOC_SECTION_ABS
},
2775 { _RCONST
, RELOC_SECTION_RCONST
}
2778 name
= bfd_section_name (bfd_asymbol_section (sym
));
2780 for (j
= 0; j
< ARRAY_SIZE (section_symndx
); j
++)
2781 if (streq (name
, section_symndx
[j
].name
))
2783 in
.r_symndx
= section_symndx
[j
].r_symndx
;
2787 if (j
== ARRAY_SIZE (section_symndx
))
2792 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2794 (*swap_reloc_out
) (abfd
, &in
, (void *) out_ptr
);
2797 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2799 amt
= current
->reloc_count
* external_reloc_size
;
2800 if (bfd_write (reloc_buff
, amt
, abfd
) != amt
)
2802 bfd_release (abfd
, reloc_buff
);
2806 /* Write out the symbolic debugging information. */
2807 if (bfd_get_symcount (abfd
) > 0)
2809 /* Write out the debugging information. */
2810 if (! bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2811 ecoff_data (abfd
)->sym_filepos
))
2816 /* The .bss section of a demand paged executable must receive an
2817 entire page. If there are symbols, the symbols will start on the
2818 next page. If there are no symbols, we must fill out the page by
2820 if (bfd_get_symcount (abfd
) == 0
2821 && (abfd
->flags
& EXEC_P
) != 0
2822 && (abfd
->flags
& D_PAGED
) != 0)
2826 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
- 1, SEEK_SET
) != 0)
2828 if (bfd_read (&c
, 1, abfd
) == 0)
2830 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
- 1, SEEK_SET
) != 0)
2832 if (bfd_write (&c
, 1, abfd
) != 1)
2836 if (reloc_buff
!= NULL
)
2837 bfd_release (abfd
, reloc_buff
);
2841 if (reloc_buff
!= NULL
)
2842 bfd_release (abfd
, reloc_buff
);
2847 /* Archive handling. ECOFF uses what appears to be a unique type of
2848 archive header (armap). The byte ordering of the armap and the
2849 contents are encoded in the name of the armap itself. At least for
2850 now, we only support archives with the same byte ordering in the
2851 armap and the contents.
2853 The first four bytes in the armap are the number of symbol
2854 definitions. This is always a power of two.
2856 This is followed by the symbol definitions. Each symbol definition
2857 occupies 8 bytes. The first four bytes are the offset from the
2858 start of the armap strings to the null-terminated string naming
2859 this symbol. The second four bytes are the file offset to the
2860 archive member which defines this symbol. If the second four bytes
2861 are 0, then this is not actually a symbol definition, and it should
2864 The symbols are hashed into the armap with a closed hashing scheme.
2865 See the functions below for the details of the algorithm.
2867 After the symbol definitions comes four bytes holding the size of
2868 the string table, followed by the string table itself. */
2870 /* The name of an archive headers looks like this:
2871 __________E[BL]E[BL]_ (with a trailing space).
2872 The trailing space is changed to an X if the archive is changed to
2873 indicate that the armap is out of date.
2875 The Alpha seems to use ________64E[BL]E[BL]_. */
2877 #define ARMAP_BIG_ENDIAN 'B'
2878 #define ARMAP_LITTLE_ENDIAN 'L'
2879 #define ARMAP_MARKER 'E'
2880 #define ARMAP_START_LENGTH 10
2881 #define ARMAP_HEADER_MARKER_INDEX 10
2882 #define ARMAP_HEADER_ENDIAN_INDEX 11
2883 #define ARMAP_OBJECT_MARKER_INDEX 12
2884 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2885 #define ARMAP_END_INDEX 14
2886 #define ARMAP_END "_ "
2888 /* This is a magic number used in the hashing algorithm. */
2889 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2891 /* This returns the hash value to use for a string. It also sets
2892 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2893 is the number of entries in the hash table, and HLOG is the log
2897 ecoff_armap_hash (const char *s
,
2898 unsigned int *rehash
,
2908 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2909 hash
*= ARMAP_HASH_MAGIC
;
2910 *rehash
= (hash
& (size
- 1)) | 1;
2911 return hash
>> (32 - hlog
);
2914 /* Read in the armap. */
2917 _bfd_ecoff_slurp_armap (bfd
*abfd
)
2921 struct areltdata
*mapdata
;
2922 bfd_size_type parsed_size
, stringsize
;
2924 struct artdata
*ardata
;
2931 /* Get the name of the first element. */
2932 i
= bfd_read (nextname
, 16, abfd
);
2938 if (bfd_seek (abfd
, -16, SEEK_CUR
) != 0)
2941 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2942 standard COFF armap. We could move the ECOFF armap stuff into
2943 bfd_slurp_armap, but that seems inappropriate since no other
2944 target uses this format. Instead, we check directly for a COFF
2946 if (startswith (nextname
, "/ "))
2947 return bfd_slurp_armap (abfd
);
2949 /* See if the first element is an armap. */
2950 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
, ARMAP_START_LENGTH
) != 0
2951 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2952 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2953 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2954 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
2955 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2956 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2957 || strncmp (nextname
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
2959 abfd
->has_armap
= false;
2963 /* Make sure we have the right byte ordering. */
2964 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2965 ^ (bfd_header_big_endian (abfd
)))
2966 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2967 ^ (bfd_big_endian (abfd
))))
2969 bfd_set_error (bfd_error_wrong_format
);
2973 /* Read in the armap. */
2974 ardata
= bfd_ardata (abfd
);
2975 mapdata
= (struct areltdata
*) _bfd_read_ar_hdr (abfd
);
2976 if (mapdata
== NULL
)
2978 parsed_size
= mapdata
->parsed_size
;
2981 if (parsed_size
+ 1 < 9)
2983 bfd_set_error (bfd_error_malformed_archive
);
2987 raw_armap
= (char *) _bfd_alloc_and_read (abfd
, parsed_size
+ 1, parsed_size
);
2988 if (raw_armap
== NULL
)
2990 raw_armap
[parsed_size
] = 0;
2992 ardata
->tdata
= (void *) raw_armap
;
2994 count
= H_GET_32 (abfd
, raw_armap
);
2995 if ((parsed_size
- 8) / 8 < count
)
2996 goto error_malformed
;
2998 ardata
->symdef_count
= 0;
2999 ardata
->cache
= NULL
;
3001 /* This code used to overlay the symdefs over the raw archive data,
3002 but that doesn't work on a 64 bit host. */
3003 stringbase
= raw_armap
+ count
* 8 + 8;
3004 stringsize
= parsed_size
- (count
* 8 + 8);
3006 #ifdef CHECK_ARMAP_HASH
3010 /* Double check that I have the hashing algorithm right by making
3011 sure that every symbol can be looked up successfully. */
3013 for (i
= 1; i
< count
; i
<<= 1)
3015 BFD_ASSERT (i
== count
);
3017 raw_ptr
= raw_armap
+ 4;
3018 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3020 unsigned int name_offset
, file_offset
;
3021 unsigned int hash
, rehash
, srch
;
3023 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3024 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3025 if (file_offset
== 0)
3027 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3032 /* See if we can rehash to this location. */
3033 for (srch
= (hash
+ rehash
) & (count
- 1);
3034 srch
!= hash
&& srch
!= i
;
3035 srch
= (srch
+ rehash
) & (count
- 1))
3036 BFD_ASSERT (H_GET_32 (abfd
, (raw_armap
+ 8 + srch
* 8)) != 0);
3037 BFD_ASSERT (srch
== i
);
3041 #endif /* CHECK_ARMAP_HASH */
3043 raw_ptr
= raw_armap
+ 4;
3044 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3045 if (H_GET_32 (abfd
, (raw_ptr
+ 4)) != 0)
3046 ++ardata
->symdef_count
;
3048 amt
= ardata
->symdef_count
;
3049 amt
*= sizeof (carsym
);
3050 symdef_ptr
= (carsym
*) bfd_alloc (abfd
, amt
);
3054 ardata
->symdefs
= symdef_ptr
;
3056 raw_ptr
= raw_armap
+ 4;
3057 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3059 unsigned int name_offset
, file_offset
;
3061 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3062 if (file_offset
== 0)
3064 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3065 if (name_offset
> stringsize
)
3066 goto error_malformed
;
3067 symdef_ptr
->name
= stringbase
+ name_offset
;
3068 symdef_ptr
->file_offset
= file_offset
;
3072 ardata
->first_file_filepos
= bfd_tell (abfd
);
3073 /* Pad to an even boundary. */
3074 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3075 abfd
->has_armap
= true;
3079 bfd_set_error (bfd_error_malformed_archive
);
3081 ardata
->symdef_count
= 0;
3082 ardata
->symdefs
= NULL
;
3083 ardata
->tdata
= NULL
;
3084 bfd_release (abfd
, raw_armap
);
3088 /* Write out an armap. */
3091 _bfd_ecoff_write_armap (bfd
*abfd
,
3092 unsigned int elength
,
3094 unsigned int orl_count
,
3097 unsigned int hashsize
, hashlog
;
3098 bfd_size_type symdefsize
;
3100 unsigned int stringsize
;
3101 unsigned int mapsize
;
3104 struct stat statbuf
;
3107 bfd_byte
*hashtable
;
3111 /* Ultrix appears to use as a hash table size the least power of two
3112 greater than twice the number of entries. */
3113 for (hashlog
= 0; ((unsigned int) 1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3115 hashsize
= 1 << hashlog
;
3117 symdefsize
= hashsize
* 8;
3119 stringsize
= stridx
+ padit
;
3121 /* Include 8 bytes to store symdefsize and stringsize in output. */
3122 mapsize
= symdefsize
+ stringsize
+ 8;
3124 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3126 memset ((void *) &hdr
, 0, sizeof hdr
);
3128 /* Work out the ECOFF armap name. */
3129 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3130 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3131 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3132 (bfd_header_big_endian (abfd
)
3134 : ARMAP_LITTLE_ENDIAN
);
3135 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3136 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3137 bfd_big_endian (abfd
) ? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3138 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3140 /* Write the timestamp of the archive header to be just a little bit
3141 later than the timestamp of the file, otherwise the linker will
3142 complain that the index is out of date. Actually, the Ultrix
3143 linker just checks the archive name; the GNU linker may check the
3145 stat (bfd_get_filename (abfd
), &statbuf
);
3146 _bfd_ar_spacepad (hdr
.ar_date
, sizeof (hdr
.ar_date
), "%ld",
3147 (long) (statbuf
.st_mtime
+ 60));
3149 /* The DECstation uses zeroes for the uid, gid and mode of the
3151 hdr
.ar_uid
[0] = '0';
3152 hdr
.ar_gid
[0] = '0';
3153 /* Building gcc ends up extracting the armap as a file - twice. */
3154 hdr
.ar_mode
[0] = '6';
3155 hdr
.ar_mode
[1] = '4';
3156 hdr
.ar_mode
[2] = '4';
3158 _bfd_ar_spacepad (hdr
.ar_size
, sizeof (hdr
.ar_size
), "%-10ld", mapsize
);
3160 hdr
.ar_fmag
[0] = '`';
3161 hdr
.ar_fmag
[1] = '\012';
3163 /* Turn all null bytes in the header into spaces. */
3164 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3165 if (((char *) (&hdr
))[i
] == '\0')
3166 (((char *) (&hdr
))[i
]) = ' ';
3168 if (bfd_write (&hdr
, sizeof (struct ar_hdr
), abfd
) != sizeof (struct ar_hdr
))
3171 H_PUT_32 (abfd
, hashsize
, temp
);
3172 if (bfd_write (temp
, 4, abfd
) != 4)
3175 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3179 current
= abfd
->archive_head
;
3181 for (i
= 0; i
< orl_count
; i
++)
3183 unsigned int hash
, rehash
= 0;
3185 /* Advance firstreal to the file position of this archive
3187 if (map
[i
].u
.abfd
!= last_elt
)
3191 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3192 firstreal
+= firstreal
% 2;
3193 current
= current
->archive_next
;
3195 while (current
!= map
[i
].u
.abfd
);
3200 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3201 if (H_GET_32 (abfd
, (hashtable
+ (hash
* 8) + 4)) != 0)
3205 /* The desired slot is already taken. */
3206 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3208 srch
= (srch
+ rehash
) & (hashsize
- 1))
3209 if (H_GET_32 (abfd
, (hashtable
+ (srch
* 8) + 4)) == 0)
3212 BFD_ASSERT (srch
!= hash
);
3217 H_PUT_32 (abfd
, map
[i
].namidx
, (hashtable
+ hash
* 8));
3218 H_PUT_32 (abfd
, firstreal
, (hashtable
+ hash
* 8 + 4));
3221 if (bfd_write (hashtable
, symdefsize
, abfd
) != symdefsize
)
3224 bfd_release (abfd
, hashtable
);
3226 /* Now write the strings. */
3227 H_PUT_32 (abfd
, stringsize
, temp
);
3228 if (bfd_write (temp
, 4, abfd
) != 4)
3230 for (i
= 0; i
< orl_count
; i
++)
3234 len
= strlen (*map
[i
].name
) + 1;
3235 if (bfd_write (*map
[i
].name
, len
, abfd
) != len
)
3239 /* The spec sez this should be a newline. But in order to be
3240 bug-compatible for DECstation ar we use a null. */
3243 if (bfd_write ("", 1, abfd
) != 1)
3250 /* ECOFF linker code. */
3252 /* Routine to create an entry in an ECOFF link hash table. */
3254 static struct bfd_hash_entry
*
3255 ecoff_link_hash_newfunc (struct bfd_hash_entry
*entry
,
3256 struct bfd_hash_table
*table
,
3259 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3261 /* Allocate the structure if it has not already been allocated by a
3264 ret
= ((struct ecoff_link_hash_entry
*)
3265 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3269 /* Call the allocation method of the superclass. */
3270 ret
= ((struct ecoff_link_hash_entry
*)
3271 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3276 /* Set local fields. */
3281 memset ((void *) &ret
->esym
, 0, sizeof ret
->esym
);
3284 return (struct bfd_hash_entry
*) ret
;
3287 /* Create an ECOFF link hash table. */
3289 struct bfd_link_hash_table
*
3290 _bfd_ecoff_bfd_link_hash_table_create (bfd
*abfd
)
3292 struct ecoff_link_hash_table
*ret
;
3293 size_t amt
= sizeof (struct ecoff_link_hash_table
);
3295 ret
= (struct ecoff_link_hash_table
*) bfd_malloc (amt
);
3298 if (!_bfd_link_hash_table_init (&ret
->root
, abfd
,
3299 ecoff_link_hash_newfunc
,
3300 sizeof (struct ecoff_link_hash_entry
)))
3308 /* Look up an entry in an ECOFF link hash table. */
3310 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3311 ((struct ecoff_link_hash_entry *) \
3312 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3314 /* Get the ECOFF link hash table from the info structure. This is
3317 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3319 /* Add the external symbols of an object file to the global linker
3320 hash table. The external symbols and strings we are passed are
3321 just allocated on the stack, and will be discarded. We must
3322 explicitly save any information we may need later on in the link.
3323 We do not want to read the external symbol information again. */
3326 ecoff_link_add_externals (bfd
*abfd
,
3327 struct bfd_link_info
*info
,
3328 void * external_ext
,
3331 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3332 void (* const swap_ext_in
) (bfd
*, void *, EXTR
*)
3333 = backend
->debug_swap
.swap_ext_in
;
3334 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3335 unsigned long ext_count
;
3336 struct bfd_link_hash_entry
**sym_hash
;
3341 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3344 amt
*= sizeof (struct bfd_link_hash_entry
*);
3345 sym_hash
= (struct bfd_link_hash_entry
**) bfd_alloc (abfd
, amt
);
3348 ecoff_data (abfd
)->sym_hashes
= (struct ecoff_link_hash_entry
**) sym_hash
;
3350 ext_ptr
= (char *) external_ext
;
3351 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3352 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3359 struct ecoff_link_hash_entry
*h
;
3363 (*swap_ext_in
) (abfd
, (void *) ext_ptr
, &esym
);
3365 /* Skip debugging symbols. */
3367 switch (esym
.asym
.st
)
3383 /* Get the information for this symbol. */
3384 value
= esym
.asym
.value
;
3385 switch (esym
.asym
.sc
)
3405 section
= bfd_make_section_old_way (abfd
, _TEXT
);
3406 value
-= section
->vma
;
3409 section
= bfd_make_section_old_way (abfd
, _DATA
);
3410 value
-= section
->vma
;
3413 section
= bfd_make_section_old_way (abfd
, _BSS
);
3414 value
-= section
->vma
;
3417 section
= bfd_abs_section_ptr
;
3420 section
= bfd_und_section_ptr
;
3423 section
= bfd_make_section_old_way (abfd
, _SDATA
);
3424 value
-= section
->vma
;
3427 section
= bfd_make_section_old_way (abfd
, _SBSS
);
3428 value
-= section
->vma
;
3431 section
= bfd_make_section_old_way (abfd
, _RDATA
);
3432 value
-= section
->vma
;
3435 if (value
> ecoff_data (abfd
)->gp_size
)
3437 section
= bfd_com_section_ptr
;
3442 section
= &ecoff_scom_section
;
3445 section
= bfd_und_section_ptr
;
3448 section
= bfd_make_section_old_way (abfd
, _INIT
);
3449 value
-= section
->vma
;
3452 section
= bfd_make_section_old_way (abfd
, _FINI
);
3453 value
-= section
->vma
;
3456 section
= bfd_make_section_old_way (abfd
, _RCONST
);
3457 value
-= section
->vma
;
3461 if (section
== NULL
)
3464 name
= ssext
+ esym
.asym
.iss
;
3466 if (! (_bfd_generic_link_add_one_symbol
3468 (flagword
) (esym
.weakext
? BSF_WEAK
: BSF_GLOBAL
),
3469 section
, value
, NULL
, true, true, sym_hash
)))
3472 h
= (struct ecoff_link_hash_entry
*) *sym_hash
;
3474 /* If we are building an ECOFF hash table, save the external
3475 symbol information. */
3476 if (bfd_get_flavour (info
->output_bfd
) == bfd_get_flavour (abfd
))
3479 || (! bfd_is_und_section (section
)
3480 && (! bfd_is_com_section (section
)
3481 || (h
->root
.type
!= bfd_link_hash_defined
3482 && h
->root
.type
!= bfd_link_hash_defweak
))))
3488 /* Remember whether this symbol was small undefined. */
3489 if (esym
.asym
.sc
== scSUndefined
)
3492 /* If this symbol was ever small undefined, it needs to wind
3493 up in a GP relative section. We can't control the
3494 section of a defined symbol, but we can control the
3495 section of a common symbol. This case is actually needed
3496 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
3498 && h
->root
.type
== bfd_link_hash_common
3499 && streq (h
->root
.u
.c
.p
->section
->name
, SCOMMON
))
3501 h
->root
.u
.c
.p
->section
= bfd_make_section_old_way (abfd
,
3503 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
3504 if (h
->esym
.asym
.sc
== scCommon
)
3505 h
->esym
.asym
.sc
= scSCommon
;
3513 /* Add symbols from an ECOFF object file to the global linker hash
3517 ecoff_link_add_object_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3520 bfd_size_type external_ext_size
;
3521 void * external_ext
= NULL
;
3522 bfd_size_type esize
;
3526 if (! ecoff_slurp_symbolic_header (abfd
))
3529 /* If there are no symbols, we don't want it. */
3530 if (bfd_get_symcount (abfd
) == 0)
3533 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3535 /* Read in the external symbols and external strings. */
3536 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0)
3538 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3539 esize
= symhdr
->iextMax
* external_ext_size
;
3540 external_ext
= _bfd_malloc_and_read (abfd
, esize
, esize
);
3541 if (external_ext
== NULL
&& esize
!= 0)
3544 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0)
3546 ssext
= (char *) _bfd_malloc_and_read (abfd
, symhdr
->issExtMax
,
3548 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3551 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3554 free (external_ext
);
3559 free (external_ext
);
3563 /* This is called if we used _bfd_generic_link_add_archive_symbols
3564 because we were not dealing with an ECOFF archive. */
3567 ecoff_link_check_archive_element (bfd
*abfd
,
3568 struct bfd_link_info
*info
,
3569 struct bfd_link_hash_entry
*h
,
3575 /* Unlike the generic linker, we do not pull in elements because
3576 of common symbols. */
3577 if (h
->type
!= bfd_link_hash_undefined
)
3580 /* Include this element? */
3581 if (!(*info
->callbacks
->add_archive_element
) (info
, abfd
, name
, &abfd
))
3585 return ecoff_link_add_object_symbols (abfd
, info
);
3588 /* Add the symbols from an archive file to the global hash table.
3589 This looks through the undefined symbols, looks each one up in the
3590 archive hash table, and adds any associated object file. We do not
3591 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3592 already have a hash table, so there is no reason to construct
3596 ecoff_link_add_archive_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3598 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3599 const bfd_byte
*raw_armap
;
3600 struct bfd_link_hash_entry
**pundef
;
3601 unsigned int armap_count
;
3602 unsigned int armap_log
;
3604 const bfd_byte
*hashtable
;
3605 const char *stringbase
;
3607 if (! bfd_has_map (abfd
))
3609 /* An empty archive is a special case. */
3610 if (bfd_openr_next_archived_file (abfd
, NULL
) == NULL
)
3612 bfd_set_error (bfd_error_no_armap
);
3616 /* If we don't have any raw data for this archive, as can happen on
3617 Irix 4.0.5F, we call the generic routine.
3618 FIXME: We should be more clever about this, since someday tdata
3619 may get to something for a generic archive. */
3620 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3621 if (raw_armap
== NULL
)
3622 return (_bfd_generic_link_add_archive_symbols
3623 (abfd
, info
, ecoff_link_check_archive_element
));
3625 armap_count
= H_GET_32 (abfd
, raw_armap
);
3628 for (i
= 1; i
< armap_count
; i
<<= 1)
3630 BFD_ASSERT (i
== armap_count
);
3632 hashtable
= raw_armap
+ 4;
3633 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3635 /* Look through the list of undefined symbols. */
3636 pundef
= &info
->hash
->undefs
;
3637 while (*pundef
!= NULL
)
3639 struct bfd_link_hash_entry
*h
;
3640 unsigned int hash
, rehash
= 0;
3641 unsigned int file_offset
;
3647 /* When a symbol is defined, it is not necessarily removed from
3649 if (h
->type
!= bfd_link_hash_undefined
3650 && h
->type
!= bfd_link_hash_common
)
3652 /* Remove this entry from the list, for general cleanliness
3653 and because we are going to look through the list again
3654 if we search any more libraries. We can't remove the
3655 entry if it is the tail, because that would lose any
3656 entries we add to the list later on. */
3657 if (*pundef
!= info
->hash
->undefs_tail
)
3658 *pundef
= (*pundef
)->u
.undef
.next
;
3660 pundef
= &(*pundef
)->u
.undef
.next
;
3664 /* Native ECOFF linkers do not pull in archive elements merely
3665 to satisfy common definitions, so neither do we. We leave
3666 them on the list, though, in case we are linking against some
3667 other object format. */
3668 if (h
->type
!= bfd_link_hash_undefined
)
3670 pundef
= &(*pundef
)->u
.undef
.next
;
3674 /* Look for this symbol in the archive hash table. */
3675 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3678 file_offset
= H_GET_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3679 if (file_offset
== 0)
3681 /* Nothing in this slot. */
3682 pundef
= &(*pundef
)->u
.undef
.next
;
3686 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (hash
* 8));
3687 if (name
[0] != h
->root
.string
[0]
3688 || ! streq (name
, h
->root
.string
))
3693 /* That was the wrong symbol. Try rehashing. */
3695 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3697 srch
= (srch
+ rehash
) & (armap_count
- 1))
3699 file_offset
= H_GET_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3700 if (file_offset
== 0)
3702 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (srch
* 8));
3703 if (name
[0] == h
->root
.string
[0]
3704 && streq (name
, h
->root
.string
))
3713 pundef
= &(*pundef
)->u
.undef
.next
;
3720 element
= (*backend
->get_elt_at_filepos
) (abfd
,
3721 (file_ptr
) file_offset
,
3723 if (element
== NULL
)
3726 if (! bfd_check_format (element
, bfd_object
))
3729 /* Unlike the generic linker, we know that this element provides
3730 a definition for an undefined symbol and we know that we want
3731 to include it. We don't need to check anything. */
3732 if (!(*info
->callbacks
3733 ->add_archive_element
) (info
, element
, name
, &element
))
3735 if (! ecoff_link_add_object_symbols (element
, info
))
3738 pundef
= &(*pundef
)->u
.undef
.next
;
3744 /* Given an ECOFF BFD, add symbols to the global hash table as
3748 _bfd_ecoff_bfd_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3750 switch (bfd_get_format (abfd
))
3753 return ecoff_link_add_object_symbols (abfd
, info
);
3755 return ecoff_link_add_archive_symbols (abfd
, info
);
3757 bfd_set_error (bfd_error_wrong_format
);
3763 /* ECOFF final link routines. */
3765 /* Structure used to pass information to ecoff_link_write_external. */
3770 struct bfd_link_info
*info
;
3773 /* Accumulate the debugging information for an input BFD into the
3774 output BFD. This must read in the symbolic information of the
3778 ecoff_final_link_debug_accumulate (bfd
*output_bfd
,
3780 struct bfd_link_info
*info
,
3783 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
3784 const struct ecoff_debug_swap
* const swap
=
3785 &ecoff_backend (input_bfd
)->debug_swap
;
3786 HDRR
*symhdr
= &debug
->symbolic_header
;
3789 #define READ(ptr, offset, count, size) \
3793 debug->ptr = NULL; \
3794 if (symhdr->count == 0) \
3796 if (_bfd_mul_overflow (size, symhdr->count, &amt)) \
3798 bfd_set_error (bfd_error_file_too_big); \
3800 goto return_something; \
3802 if (bfd_seek (input_bfd, symhdr->offset, SEEK_SET) != 0) \
3805 goto return_something; \
3807 debug->ptr = _bfd_malloc_and_read (input_bfd, amt + 1, amt); \
3808 if (debug->ptr == NULL) \
3811 goto return_something; \
3813 ((char *) debug->ptr)[amt] = 0; \
3816 /* If alloc_syments is true, then the data was already by read by
3817 _bfd_ecoff_slurp_symbolic_info. */
3818 if (!debug
->alloc_syments
)
3820 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char));
3821 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
);
3822 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
);
3823 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
);
3824 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
);
3825 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
3826 READ (ss
, cbSsOffset
, issMax
, sizeof (char));
3827 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
);
3828 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
);
3832 /* We do not read the external strings or the external symbols. */
3834 ret
= (bfd_ecoff_debug_accumulate
3835 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
3836 &ecoff_backend (output_bfd
)->debug_swap
,
3837 input_bfd
, debug
, swap
, info
));
3840 _bfd_ecoff_free_ecoff_debug_info (debug
);
3844 /* Relocate and write an ECOFF section into an ECOFF output file. */
3847 ecoff_indirect_link_order (bfd
*output_bfd
,
3848 struct bfd_link_info
*info
,
3849 asection
*output_section
,
3850 struct bfd_link_order
*link_order
)
3852 asection
*input_section
;
3854 bfd_byte
*contents
= NULL
;
3855 bfd_size_type external_reloc_size
;
3856 bfd_size_type external_relocs_size
;
3857 void * external_relocs
= NULL
;
3859 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
3861 input_section
= link_order
->u
.indirect
.section
;
3862 input_bfd
= input_section
->owner
;
3863 if (input_section
->size
== 0)
3866 BFD_ASSERT (input_section
->output_section
== output_section
);
3867 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
3868 BFD_ASSERT (input_section
->size
== link_order
->size
);
3870 /* Get the section contents. */
3871 if (!bfd_malloc_and_get_section (input_bfd
, input_section
, &contents
))
3874 /* Get the relocs. If we are relaxing MIPS code, they will already
3875 have been read in. Otherwise, we read them in now. */
3876 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
3877 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
3879 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0)
3881 external_relocs
= _bfd_malloc_and_read (input_bfd
, external_relocs_size
,
3882 external_relocs_size
);
3883 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
3886 /* Relocate the section contents. */
3887 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
3888 (output_bfd
, info
, input_bfd
, input_section
, contents
,
3892 /* Write out the relocated section. */
3893 if (! bfd_set_section_contents (output_bfd
,
3896 input_section
->output_offset
,
3897 input_section
->size
))
3900 /* If we are producing relocatable output, the relocs were
3901 modified, and we write them out now. We use the reloc_count
3902 field of output_section to keep track of the number of relocs we
3903 have output so far. */
3904 if (bfd_link_relocatable (info
))
3906 file_ptr pos
= (output_section
->rel_filepos
3907 + output_section
->reloc_count
* external_reloc_size
);
3908 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
3909 || (bfd_write (external_relocs
, external_relocs_size
, output_bfd
)
3910 != external_relocs_size
))
3912 output_section
->reloc_count
+= input_section
->reloc_count
;
3916 free (external_relocs
);
3921 free (external_relocs
);
3925 /* Generate a reloc when linking an ECOFF file. This is a reloc
3926 requested by the linker, and does come from any input file. This
3927 is used to build constructor and destructor tables when linking
3931 ecoff_reloc_link_order (bfd
*output_bfd
,
3932 struct bfd_link_info
*info
,
3933 asection
*output_section
,
3934 struct bfd_link_order
*link_order
)
3936 enum bfd_link_order_type type
;
3940 struct internal_reloc in
;
3941 bfd_size_type external_reloc_size
;
3946 type
= link_order
->type
;
3948 addend
= link_order
->u
.reloc
.p
->addend
;
3950 /* We set up an arelent to pass to the backend adjust_reloc_out
3952 rel
.address
= link_order
->offset
;
3954 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
3957 bfd_set_error (bfd_error_bad_value
);
3961 if (type
== bfd_section_reloc_link_order
)
3963 section
= link_order
->u
.reloc
.p
->u
.section
;
3964 rel
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
3968 struct bfd_link_hash_entry
*h
;
3970 /* Treat a reloc against a defined symbol as though it were
3971 actually against the section. */
3972 h
= bfd_wrapped_link_hash_lookup (output_bfd
, info
,
3973 link_order
->u
.reloc
.p
->u
.name
,
3974 false, false, false);
3976 && (h
->type
== bfd_link_hash_defined
3977 || h
->type
== bfd_link_hash_defweak
))
3979 type
= bfd_section_reloc_link_order
;
3980 section
= h
->u
.def
.section
->output_section
;
3981 /* It seems that we ought to add the symbol value to the
3982 addend here, but in practice it has already been added
3983 because it was passed to constructor_callback. */
3984 addend
+= section
->vma
+ h
->u
.def
.section
->output_offset
;
3988 /* We can't set up a reloc against a symbol correctly,
3989 because we have no asymbol structure. Currently no
3990 adjust_reloc_out routine cares. */
3991 rel
.sym_ptr_ptr
= NULL
;
3995 /* All ECOFF relocs are in-place. Put the addend into the object
3998 BFD_ASSERT (rel
.howto
->partial_inplace
);
4002 bfd_reloc_status_type rstat
;
4005 size
= bfd_get_reloc_size (rel
.howto
);
4006 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4007 if (buf
== NULL
&& size
!= 0)
4009 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4010 (bfd_vma
) addend
, buf
);
4016 case bfd_reloc_outofrange
:
4018 case bfd_reloc_overflow
:
4019 (*info
->callbacks
->reloc_overflow
)
4021 (link_order
->type
== bfd_section_reloc_link_order
4022 ? bfd_section_name (section
)
4023 : link_order
->u
.reloc
.p
->u
.name
),
4024 rel
.howto
->name
, addend
, NULL
, NULL
, (bfd_vma
) 0);
4027 ok
= bfd_set_section_contents (output_bfd
, output_section
, (void *) buf
,
4028 (file_ptr
) link_order
->offset
, size
);
4036 /* Move the information into an internal_reloc structure. */
4037 in
.r_vaddr
= rel
.address
+ bfd_section_vma (output_section
);
4038 in
.r_type
= rel
.howto
->type
;
4040 if (type
== bfd_symbol_reloc_link_order
)
4042 struct ecoff_link_hash_entry
*h
;
4044 h
= ((struct ecoff_link_hash_entry
*)
4045 bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4046 link_order
->u
.reloc
.p
->u
.name
,
4047 false, false, true));
4050 in
.r_symndx
= h
->indx
;
4053 (*info
->callbacks
->unattached_reloc
)
4054 (info
, link_order
->u
.reloc
.p
->u
.name
, NULL
, NULL
, (bfd_vma
) 0);
4070 { _TEXT
, RELOC_SECTION_TEXT
},
4071 { _RDATA
, RELOC_SECTION_RDATA
},
4072 { _DATA
, RELOC_SECTION_DATA
},
4073 { _SDATA
, RELOC_SECTION_SDATA
},
4074 { _SBSS
, RELOC_SECTION_SBSS
},
4075 { _BSS
, RELOC_SECTION_BSS
},
4076 { _INIT
, RELOC_SECTION_INIT
},
4077 { _LIT8
, RELOC_SECTION_LIT8
},
4078 { _LIT4
, RELOC_SECTION_LIT4
},
4079 { _XDATA
, RELOC_SECTION_XDATA
},
4080 { _PDATA
, RELOC_SECTION_PDATA
},
4081 { _FINI
, RELOC_SECTION_FINI
},
4082 { _LITA
, RELOC_SECTION_LITA
},
4083 { "*ABS*", RELOC_SECTION_ABS
},
4084 { _RCONST
, RELOC_SECTION_RCONST
}
4087 name
= bfd_section_name (section
);
4089 for (i
= 0; i
< ARRAY_SIZE (section_symndx
); i
++)
4090 if (streq (name
, section_symndx
[i
].name
))
4092 in
.r_symndx
= section_symndx
[i
].r_symndx
;
4096 if (i
== ARRAY_SIZE (section_symndx
))
4102 /* Let the BFD backend adjust the reloc. */
4103 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4105 /* Get some memory and swap out the reloc. */
4106 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4107 rbuf
= (bfd_byte
*) bfd_malloc (external_reloc_size
);
4111 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (void *) rbuf
);
4113 pos
= (output_section
->rel_filepos
4114 + output_section
->reloc_count
* external_reloc_size
);
4115 ok
= (bfd_seek (output_bfd
, pos
, SEEK_SET
) == 0
4116 && (bfd_write (rbuf
, external_reloc_size
, output_bfd
)
4117 == external_reloc_size
));
4120 ++output_section
->reloc_count
;
4127 /* Put out information for an external symbol. These come only from
4131 ecoff_link_write_external (struct bfd_hash_entry
*bh
, void * data
)
4133 struct ecoff_link_hash_entry
*h
= (struct ecoff_link_hash_entry
*) bh
;
4134 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4135 bfd
*output_bfd
= einfo
->abfd
;
4138 if (h
->root
.type
== bfd_link_hash_warning
)
4140 h
= (struct ecoff_link_hash_entry
*) h
->root
.u
.i
.link
;
4141 if (h
->root
.type
== bfd_link_hash_new
)
4145 /* We need to check if this symbol is being stripped. */
4146 if (h
->root
.type
== bfd_link_hash_undefined
4147 || h
->root
.type
== bfd_link_hash_undefweak
)
4149 else if (einfo
->info
->strip
== strip_all
4150 || (einfo
->info
->strip
== strip_some
4151 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4152 h
->root
.root
.string
,
4153 false, false) == NULL
))
4158 if (strip
|| h
->written
)
4161 if (h
->abfd
== NULL
)
4164 h
->esym
.cobol_main
= 0;
4165 h
->esym
.weakext
= 0;
4166 h
->esym
.reserved
= 0;
4167 h
->esym
.ifd
= ifdNil
;
4168 h
->esym
.asym
.value
= 0;
4169 h
->esym
.asym
.st
= stGlobal
;
4171 if (h
->root
.type
!= bfd_link_hash_defined
4172 && h
->root
.type
!= bfd_link_hash_defweak
)
4173 h
->esym
.asym
.sc
= scAbs
;
4176 asection
*output_section
;
4184 section_storage_classes
[] =
4188 { _SDATA
, scSData
},
4189 { _RDATA
, scRData
},
4194 { _PDATA
, scPData
},
4195 { _XDATA
, scXData
},
4196 { _RCONST
, scRConst
}
4199 output_section
= h
->root
.u
.def
.section
->output_section
;
4200 name
= bfd_section_name (output_section
);
4202 for (i
= 0; i
< ARRAY_SIZE (section_storage_classes
); i
++)
4203 if (streq (name
, section_storage_classes
[i
].name
))
4205 h
->esym
.asym
.sc
= section_storage_classes
[i
].sc
;
4209 if (i
== ARRAY_SIZE (section_storage_classes
))
4210 h
->esym
.asym
.sc
= scAbs
;
4213 h
->esym
.asym
.reserved
= 0;
4214 h
->esym
.asym
.index
= indexNil
;
4216 else if (h
->esym
.ifd
!= -1)
4218 struct ecoff_debug_info
*debug
;
4220 /* Adjust the FDR index for the symbol by that used for the
4222 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4223 BFD_ASSERT (h
->esym
.ifd
>= 0
4224 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4225 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4228 switch (h
->root
.type
)
4231 case bfd_link_hash_warning
:
4232 case bfd_link_hash_new
:
4234 case bfd_link_hash_undefined
:
4235 case bfd_link_hash_undefweak
:
4236 if (h
->esym
.asym
.sc
!= scUndefined
4237 && h
->esym
.asym
.sc
!= scSUndefined
)
4238 h
->esym
.asym
.sc
= scUndefined
;
4240 case bfd_link_hash_defined
:
4241 case bfd_link_hash_defweak
:
4242 if (h
->esym
.asym
.sc
== scUndefined
4243 || h
->esym
.asym
.sc
== scSUndefined
)
4244 h
->esym
.asym
.sc
= scAbs
;
4245 else if (h
->esym
.asym
.sc
== scCommon
)
4246 h
->esym
.asym
.sc
= scBss
;
4247 else if (h
->esym
.asym
.sc
== scSCommon
)
4248 h
->esym
.asym
.sc
= scSBss
;
4249 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4250 + h
->root
.u
.def
.section
->output_section
->vma
4251 + h
->root
.u
.def
.section
->output_offset
);
4253 case bfd_link_hash_common
:
4254 if (h
->esym
.asym
.sc
!= scCommon
4255 && h
->esym
.asym
.sc
!= scSCommon
)
4256 h
->esym
.asym
.sc
= scCommon
;
4257 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4259 case bfd_link_hash_indirect
:
4260 /* We ignore these symbols, since the indirected symbol is
4261 already in the hash table. */
4265 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4267 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4270 return (bfd_ecoff_debug_one_external
4271 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4272 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4276 /* ECOFF final link routine. This looks through all the input BFDs
4277 and gathers together all the debugging information, and then
4278 processes all the link order information. This may cause it to
4279 close and reopen some input BFDs; I'll see how bad this is. */
4282 _bfd_ecoff_bfd_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
4284 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4285 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4290 struct bfd_link_order
*p
;
4291 struct extsym_info einfo
;
4293 /* We accumulate the debugging information counts in the symbolic
4295 symhdr
= &debug
->symbolic_header
;
4297 symhdr
->ilineMax
= 0;
4301 symhdr
->isymMax
= 0;
4302 symhdr
->ioptMax
= 0;
4303 symhdr
->iauxMax
= 0;
4305 symhdr
->issExtMax
= 0;
4308 symhdr
->iextMax
= 0;
4310 /* We accumulate the debugging information itself in the debug_info
4313 debug
->external_dnr
= NULL
;
4314 debug
->external_pdr
= NULL
;
4315 debug
->external_sym
= NULL
;
4316 debug
->external_opt
= NULL
;
4317 debug
->external_aux
= NULL
;
4319 debug
->ssext
= debug
->ssext_end
= NULL
;
4320 debug
->external_fdr
= NULL
;
4321 debug
->external_rfd
= NULL
;
4322 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4324 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4328 /* Accumulate the debugging symbols from each input BFD. */
4329 for (input_bfd
= info
->input_bfds
;
4331 input_bfd
= input_bfd
->link
.next
)
4335 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4337 /* Arbitrarily set the symbolic header vstamp to the vstamp
4338 of the first object file in the link. */
4339 if (symhdr
->vstamp
== 0)
4341 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4342 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4346 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4347 debug
, &backend
->debug_swap
,
4352 /* Combine the register masks. */
4353 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4354 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4355 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4356 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4357 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4358 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4361 /* Write out the external symbols. */
4364 bfd_hash_traverse (&info
->hash
->table
, ecoff_link_write_external
, &einfo
);
4366 if (bfd_link_relocatable (info
))
4368 /* We need to make a pass over the link_orders to count up the
4369 number of relocations we will need to output, so that we know
4370 how much space they will take up. */
4371 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4374 for (p
= o
->map_head
.link_order
;
4377 if (p
->type
== bfd_indirect_link_order
)
4378 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4379 else if (p
->type
== bfd_section_reloc_link_order
4380 || p
->type
== bfd_symbol_reloc_link_order
)
4385 /* Compute the reloc and symbol file positions. */
4386 ecoff_compute_reloc_file_positions (abfd
);
4388 /* Write out the debugging information. */
4389 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4390 &backend
->debug_swap
, info
,
4391 ecoff_data (abfd
)->sym_filepos
))
4394 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4396 if (bfd_link_relocatable (info
))
4398 /* Now reset the reloc_count field of the sections in the output
4399 BFD to 0, so that we can use them to keep track of how many
4400 relocs we have output thus far. */
4401 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4405 /* Get a value for the GP register. */
4406 if (ecoff_data (abfd
)->gp
== 0)
4408 struct bfd_link_hash_entry
*h
;
4410 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4412 && h
->type
== bfd_link_hash_defined
)
4413 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4414 + h
->u
.def
.section
->output_section
->vma
4415 + h
->u
.def
.section
->output_offset
);
4416 else if (bfd_link_relocatable (info
))
4420 /* Make up a value. */
4422 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4425 && (streq (o
->name
, _SBSS
)
4426 || streq (o
->name
, _SDATA
)
4427 || streq (o
->name
, _LIT4
)
4428 || streq (o
->name
, _LIT8
)
4429 || streq (o
->name
, _LITA
)))
4432 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4436 /* If the relocate_section function needs to do a reloc
4437 involving the GP value, it should make a reloc_dangerous
4438 callback to warn that GP is not defined. */
4442 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4444 for (p
= o
->map_head
.link_order
;
4448 if (p
->type
== bfd_indirect_link_order
4449 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4450 == bfd_target_ecoff_flavour
))
4452 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4455 else if (p
->type
== bfd_section_reloc_link_order
4456 || p
->type
== bfd_symbol_reloc_link_order
)
4458 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4463 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4469 abfd
->symcount
= symhdr
->iextMax
+ symhdr
->isymMax
;
4471 ecoff_data (abfd
)->linker
= true;