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
;
1455 const char *symname
= (symbol
->name
!= bfd_symbol_error_name
1456 ? symbol
->name
: _("<corrupt>"));
1460 case bfd_print_symbol_name
:
1461 fprintf (file
, "%s", symname
);
1463 case bfd_print_symbol_more
:
1464 if (ecoffsymbol (symbol
)->local
)
1468 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1470 fprintf (file
, "ecoff local ");
1471 bfd_fprintf_vma (abfd
, file
, ecoff_sym
.value
);
1472 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1473 (unsigned) ecoff_sym
.sc
);
1479 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1481 fprintf (file
, "ecoff extern ");
1482 bfd_fprintf_vma (abfd
, file
, ecoff_ext
.asym
.value
);
1483 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1484 (unsigned) ecoff_ext
.asym
.sc
);
1487 case bfd_print_symbol_all
:
1488 /* Print out the symbols in a reasonable way. */
1497 if (ecoffsymbol (symbol
)->local
)
1499 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1502 pos
= ((((char *) ecoffsymbol (symbol
)->native
1503 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1504 / debug_swap
->external_sym_size
)
1505 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1512 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1515 pos
= (((char *) ecoffsymbol (symbol
)->native
1516 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1517 / debug_swap
->external_ext_size
);
1518 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1519 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1520 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1523 fprintf (file
, "[%3d] %c ",
1525 bfd_fprintf_vma (abfd
, file
, ecoff_ext
.asym
.value
);
1526 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1527 (unsigned) ecoff_ext
.asym
.st
,
1528 (unsigned) ecoff_ext
.asym
.sc
,
1529 (unsigned) ecoff_ext
.asym
.index
,
1530 jmptbl
, cobol_main
, weakext
,
1533 if (ecoffsymbol (symbol
)->fdr
!= NULL
1534 && ecoff_ext
.asym
.index
!= indexNil
)
1539 bfd_size_type sym_base
;
1540 union aux_ext
*aux_base
;
1542 fdr
= ecoffsymbol (symbol
)->fdr
;
1543 indx
= ecoff_ext
.asym
.index
;
1545 /* sym_base is used to map the fdr relative indices which
1546 appear in the file to the position number which we are
1548 sym_base
= fdr
->isymBase
;
1549 if (ecoffsymbol (symbol
)->local
)
1551 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1553 /* aux_base is the start of the aux entries for this file;
1554 asym.index is an offset from this. */
1555 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1558 /* The aux entries are stored in host byte order; the
1559 order is indicated by a bit in the fdr. */
1560 bigendian
= fdr
->fBigendian
;
1562 /* This switch is basically from gcc/mips-tdump.c. */
1563 switch (ecoff_ext
.asym
.st
)
1571 fprintf (file
, _("\n End+1 symbol: %ld"),
1572 (long) (indx
+ sym_base
));
1576 if (ecoff_ext
.asym
.sc
== scText
1577 || ecoff_ext
.asym
.sc
== scInfo
)
1578 fprintf (file
, _("\n First symbol: %ld"),
1579 (long) (indx
+ sym_base
));
1581 fprintf (file
, _("\n First symbol: %ld"),
1583 (AUX_GET_ISYM (bigendian
,
1584 &aux_base
[ecoff_ext
.asym
.index
])
1590 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1592 else if (ecoffsymbol (symbol
)->local
)
1595 /* xgettext:c-format */
1596 fprintf (file
, _("\n End+1 symbol: %-7ld Type: %s"),
1598 (AUX_GET_ISYM (bigendian
,
1599 &aux_base
[ecoff_ext
.asym
.index
])
1601 ecoff_type_to_string (abfd
, fdr
, indx
+ 1, buff
));
1604 fprintf (file
, _("\n Local symbol: %ld"),
1607 + (ecoff_data (abfd
)
1608 ->debug_info
.symbolic_header
.iextMax
)));
1612 fprintf (file
, _("\n struct; End+1 symbol: %ld"),
1613 (long) (indx
+ sym_base
));
1617 fprintf (file
, _("\n union; End+1 symbol: %ld"),
1618 (long) (indx
+ sym_base
));
1622 fprintf (file
, _("\n enum; End+1 symbol: %ld"),
1623 (long) (indx
+ sym_base
));
1627 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1630 fprintf (file
, _("\n Type: %s"),
1631 ecoff_type_to_string (abfd
, fdr
, indx
, buff
));
1641 /* Read in the relocs for a section. */
1644 ecoff_slurp_reloc_table (bfd
*abfd
,
1648 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1649 arelent
*internal_relocs
;
1650 bfd_size_type external_reloc_size
;
1652 bfd_byte
*external_relocs
;
1656 if (section
->relocation
!= NULL
1657 || section
->reloc_count
== 0
1658 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1661 if (! _bfd_ecoff_slurp_symbol_table (abfd
))
1664 external_reloc_size
= backend
->external_reloc_size
;
1665 amt
= external_reloc_size
* section
->reloc_count
;
1666 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1668 external_relocs
= _bfd_malloc_and_read (abfd
, amt
, amt
);
1669 if (external_relocs
== NULL
)
1672 amt
= section
->reloc_count
;
1673 amt
*= sizeof (arelent
);
1674 internal_relocs
= (arelent
*) bfd_alloc (abfd
, amt
);
1675 if (internal_relocs
== NULL
)
1677 free (external_relocs
);
1681 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1683 struct internal_reloc intern
;
1685 (*backend
->swap_reloc_in
) (abfd
,
1686 external_relocs
+ i
* external_reloc_size
,
1688 rptr
->sym_ptr_ptr
= &bfd_abs_section_ptr
->symbol
;
1691 if (intern
.r_extern
)
1693 /* r_symndx is an index into the external symbols. */
1695 && intern
.r_symndx
>= 0
1697 < (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
)))
1698 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1702 const char *sec_name
;
1705 /* r_symndx is a section key. */
1706 switch (intern
.r_symndx
)
1708 case RELOC_SECTION_TEXT
: sec_name
= _TEXT
; break;
1709 case RELOC_SECTION_RDATA
: sec_name
= _RDATA
; break;
1710 case RELOC_SECTION_DATA
: sec_name
= _DATA
; break;
1711 case RELOC_SECTION_SDATA
: sec_name
= _SDATA
; break;
1712 case RELOC_SECTION_SBSS
: sec_name
= _SBSS
; break;
1713 case RELOC_SECTION_BSS
: sec_name
= _BSS
; break;
1714 case RELOC_SECTION_INIT
: sec_name
= _INIT
; break;
1715 case RELOC_SECTION_LIT8
: sec_name
= _LIT8
; break;
1716 case RELOC_SECTION_LIT4
: sec_name
= _LIT4
; break;
1717 case RELOC_SECTION_XDATA
: sec_name
= _XDATA
; break;
1718 case RELOC_SECTION_PDATA
: sec_name
= _PDATA
; break;
1719 case RELOC_SECTION_FINI
: sec_name
= _FINI
; break;
1720 case RELOC_SECTION_LITA
: sec_name
= _LITA
; break;
1721 case RELOC_SECTION_RCONST
: sec_name
= _RCONST
; break;
1727 if (sec_name
!= NULL
)
1729 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1732 rptr
->sym_ptr_ptr
= &sec
->symbol
;
1733 rptr
->addend
= - bfd_section_vma (sec
);
1738 rptr
->address
= intern
.r_vaddr
- bfd_section_vma (section
);
1740 /* Let the backend select the howto field and do any other
1741 required processing. */
1742 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1745 free (external_relocs
);
1747 section
->relocation
= internal_relocs
;
1752 /* Get a canonical list of relocs. */
1755 _bfd_ecoff_canonicalize_reloc (bfd
*abfd
,
1762 if (section
->flags
& SEC_CONSTRUCTOR
)
1764 arelent_chain
*chain
;
1766 /* This section has relocs made up by us, not the file, so take
1767 them out of their chain and place them into the data area
1769 for (count
= 0, chain
= section
->constructor_chain
;
1770 count
< section
->reloc_count
;
1771 count
++, chain
= chain
->next
)
1772 *relptr
++ = &chain
->relent
;
1778 if (! ecoff_slurp_reloc_table (abfd
, section
, symbols
))
1781 tblptr
= section
->relocation
;
1783 for (count
= 0; count
< section
->reloc_count
; count
++)
1784 *relptr
++ = tblptr
++;
1789 return section
->reloc_count
;
1792 /* Provided a BFD, a section and an offset into the section, calculate
1793 and return the name of the source file and the line nearest to the
1797 _bfd_ecoff_find_nearest_line (bfd
*abfd
,
1798 asymbol
**symbols ATTRIBUTE_UNUSED
,
1801 const char **filename_ptr
,
1802 const char **functionname_ptr
,
1803 unsigned int *retline_ptr
,
1804 unsigned int *discriminator_ptr
)
1806 const struct ecoff_debug_swap
* const debug_swap
1807 = &ecoff_backend (abfd
)->debug_swap
;
1808 struct ecoff_debug_info
* const debug_info
= &ecoff_data (abfd
)->debug_info
;
1809 struct ecoff_find_line
*line_info
;
1811 /* Make sure we have the FDR's. */
1812 if (! _bfd_ecoff_slurp_symbolic_info (abfd
, NULL
, debug_info
)
1813 || bfd_get_symcount (abfd
) == 0)
1816 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1818 size_t amt
= sizeof (struct ecoff_find_line
);
1820 ecoff_data (abfd
)->find_line_info
=
1821 (struct ecoff_find_line
*) bfd_zalloc (abfd
, amt
);
1822 if (ecoff_data (abfd
)->find_line_info
== NULL
)
1826 if (discriminator_ptr
)
1827 *discriminator_ptr
= 0;
1828 line_info
= ecoff_data (abfd
)->find_line_info
;
1829 return _bfd_ecoff_locate_line (abfd
, section
, offset
, debug_info
,
1830 debug_swap
, line_info
, filename_ptr
,
1831 functionname_ptr
, retline_ptr
);
1834 /* Copy private BFD data. This is called by objcopy and strip. We
1835 use it to copy the ECOFF debugging information from one BFD to the
1836 other. It would be theoretically possible to represent the ECOFF
1837 debugging information in the symbol table. However, it would be a
1838 lot of work, and there would be little gain (gas, gdb, and ld
1839 already access the ECOFF debugging information via the
1840 ecoff_debug_info structure, and that structure would have to be
1841 retained in order to support ECOFF debugging in MIPS ELF).
1843 The debugging information for the ECOFF external symbols comes from
1844 the symbol table, so this function only handles the other debugging
1848 _bfd_ecoff_bfd_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
1850 struct ecoff_debug_info
*iinfo
= &ecoff_data (ibfd
)->debug_info
;
1851 struct ecoff_debug_info
*oinfo
= &ecoff_data (obfd
)->debug_info
;
1853 asymbol
**sym_ptr_ptr
;
1857 /* We only want to copy information over if both BFD's use ECOFF
1859 if (bfd_get_flavour (ibfd
) != bfd_target_ecoff_flavour
1860 || bfd_get_flavour (obfd
) != bfd_target_ecoff_flavour
)
1863 /* Copy the GP value and the register masks. */
1864 ecoff_data (obfd
)->gp
= ecoff_data (ibfd
)->gp
;
1865 ecoff_data (obfd
)->gprmask
= ecoff_data (ibfd
)->gprmask
;
1866 ecoff_data (obfd
)->fprmask
= ecoff_data (ibfd
)->fprmask
;
1867 for (i
= 0; i
< 3; i
++)
1868 ecoff_data (obfd
)->cprmask
[i
] = ecoff_data (ibfd
)->cprmask
[i
];
1870 /* Copy the version stamp. */
1871 oinfo
->symbolic_header
.vstamp
= iinfo
->symbolic_header
.vstamp
;
1873 /* If there are no symbols, don't copy any debugging information. */
1874 c
= bfd_get_symcount (obfd
);
1875 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1876 if (c
== 0 || sym_ptr_ptr
== NULL
)
1879 /* See if there are any local symbols. */
1881 for (; c
> 0; c
--, sym_ptr_ptr
++)
1883 if (ecoffsymbol (*sym_ptr_ptr
)->local
)
1892 /* There are some local symbols. We just bring over all the
1893 debugging information. FIXME: This is not quite the right
1894 thing to do. If the user has asked us to discard all
1895 debugging information, then we are probably going to wind up
1896 keeping it because there will probably be some local symbol
1897 which objcopy did not discard. We should actually break
1898 apart the debugging information and only keep that which
1899 applies to the symbols we want to keep. */
1900 oinfo
->symbolic_header
.ilineMax
= iinfo
->symbolic_header
.ilineMax
;
1901 oinfo
->symbolic_header
.cbLine
= iinfo
->symbolic_header
.cbLine
;
1902 oinfo
->line
= iinfo
->line
;
1904 oinfo
->symbolic_header
.idnMax
= iinfo
->symbolic_header
.idnMax
;
1905 oinfo
->external_dnr
= iinfo
->external_dnr
;
1907 oinfo
->symbolic_header
.ipdMax
= iinfo
->symbolic_header
.ipdMax
;
1908 oinfo
->external_pdr
= iinfo
->external_pdr
;
1910 oinfo
->symbolic_header
.isymMax
= iinfo
->symbolic_header
.isymMax
;
1911 oinfo
->external_sym
= iinfo
->external_sym
;
1913 oinfo
->symbolic_header
.ioptMax
= iinfo
->symbolic_header
.ioptMax
;
1914 oinfo
->external_opt
= iinfo
->external_opt
;
1916 oinfo
->symbolic_header
.iauxMax
= iinfo
->symbolic_header
.iauxMax
;
1917 oinfo
->external_aux
= iinfo
->external_aux
;
1919 oinfo
->symbolic_header
.issMax
= iinfo
->symbolic_header
.issMax
;
1920 oinfo
->ss
= iinfo
->ss
;
1922 oinfo
->symbolic_header
.ifdMax
= iinfo
->symbolic_header
.ifdMax
;
1923 oinfo
->external_fdr
= iinfo
->external_fdr
;
1925 oinfo
->symbolic_header
.crfd
= iinfo
->symbolic_header
.crfd
;
1926 oinfo
->external_rfd
= iinfo
->external_rfd
;
1928 /* Flag that oinfo entries should not be freed. */
1929 oinfo
->alloc_syments
= true;
1933 /* We are discarding all the local symbol information. Look
1934 through the external symbols and remove all references to FDR
1935 or aux information. */
1936 c
= bfd_get_symcount (obfd
);
1937 sym_ptr_ptr
= bfd_get_outsymbols (obfd
);
1938 for (; c
> 0; c
--, sym_ptr_ptr
++)
1942 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_in
))
1943 (obfd
, ecoffsymbol (*sym_ptr_ptr
)->native
, &esym
);
1945 esym
.asym
.index
= indexNil
;
1946 (*(ecoff_backend (obfd
)->debug_swap
.swap_ext_out
))
1947 (obfd
, &esym
, ecoffsymbol (*sym_ptr_ptr
)->native
);
1954 /* Set the architecture. The supported architecture is stored in the
1955 backend pointer. We always set the architecture anyhow, since many
1956 callers ignore the return value. */
1959 _bfd_ecoff_set_arch_mach (bfd
*abfd
,
1960 enum bfd_architecture arch
,
1961 unsigned long machine
)
1963 bfd_default_set_arch_mach (abfd
, arch
, machine
);
1964 return arch
== ecoff_backend (abfd
)->arch
;
1967 /* Get the size of the section headers. */
1970 _bfd_ecoff_sizeof_headers (bfd
*abfd
,
1971 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
1978 for (current
= abfd
->sections
;
1980 current
= current
->next
)
1983 ret
= (bfd_coff_filhsz (abfd
)
1984 + bfd_coff_aoutsz (abfd
)
1985 + c
* bfd_coff_scnhsz (abfd
));
1986 return (int) BFD_ALIGN (ret
, 16);
1989 /* Get the contents of a section. */
1992 _bfd_ecoff_get_section_contents (bfd
*abfd
,
1996 bfd_size_type count
)
1998 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2002 /* Sort sections by VMA, but put SEC_ALLOC sections first. This is
2003 called via qsort. */
2006 ecoff_sort_hdrs (const void * arg1
, const void * arg2
)
2008 const asection
*hdr1
= *(const asection
**) arg1
;
2009 const asection
*hdr2
= *(const asection
**) arg2
;
2011 if ((hdr1
->flags
& SEC_ALLOC
) != 0)
2013 if ((hdr2
->flags
& SEC_ALLOC
) == 0)
2018 if ((hdr2
->flags
& SEC_ALLOC
) != 0)
2021 if (hdr1
->vma
< hdr2
->vma
)
2023 else if (hdr1
->vma
> hdr2
->vma
)
2029 /* Calculate the file position for each section, and set
2033 ecoff_compute_section_file_positions (bfd
*abfd
)
2035 file_ptr sofar
, file_sofar
;
2036 asection
**sorted_hdrs
;
2041 bool first_data
, first_nonalloc
;
2042 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2045 sofar
= _bfd_ecoff_sizeof_headers (abfd
, NULL
);
2048 /* Sort the sections by VMA. */
2049 amt
= abfd
->section_count
;
2050 amt
*= sizeof (asection
*);
2051 sorted_hdrs
= (asection
**) bfd_malloc (amt
);
2052 if (sorted_hdrs
== NULL
)
2054 for (current
= abfd
->sections
, i
= 0;
2056 current
= current
->next
, i
++)
2057 sorted_hdrs
[i
] = current
;
2058 BFD_ASSERT (i
== abfd
->section_count
);
2060 qsort (sorted_hdrs
, abfd
->section_count
, sizeof (asection
*),
2063 /* Some versions of the OSF linker put the .rdata section in the
2064 text segment, and some do not. */
2065 rdata_in_text
= ecoff_backend (abfd
)->rdata_in_text
;
2068 for (i
= 0; i
< abfd
->section_count
; i
++)
2070 current
= sorted_hdrs
[i
];
2071 if (streq (current
->name
, _RDATA
))
2073 if ((current
->flags
& SEC_CODE
) == 0
2074 && ! streq (current
->name
, _PDATA
)
2075 && ! streq (current
->name
, _RCONST
))
2077 rdata_in_text
= false;
2082 ecoff_data (abfd
)->rdata_in_text
= rdata_in_text
;
2085 first_nonalloc
= true;
2086 for (i
= 0; i
< abfd
->section_count
; i
++)
2088 unsigned int alignment_power
;
2090 current
= sorted_hdrs
[i
];
2092 /* For the Alpha ECOFF .pdata section the lnnoptr field is
2093 supposed to indicate the number of .pdata entries that are
2094 really in the section. Each entry is 8 bytes. We store this
2095 away in line_filepos before increasing the section size. */
2096 if (streq (current
->name
, _PDATA
))
2097 current
->line_filepos
= current
->size
/ 8;
2099 alignment_power
= current
->alignment_power
;
2101 /* On Ultrix, the data sections in an executable file must be
2102 aligned to a page boundary within the file. This does not
2103 affect the section size, though. FIXME: Does this work for
2104 other platforms? It requires some modification for the
2105 Alpha, because .rdata on the Alpha goes with the text, not
2107 if ((abfd
->flags
& EXEC_P
) != 0
2108 && (abfd
->flags
& D_PAGED
) != 0
2110 && (current
->flags
& SEC_CODE
) == 0
2112 || ! streq (current
->name
, _RDATA
))
2113 && ! streq (current
->name
, _PDATA
)
2114 && ! streq (current
->name
, _RCONST
))
2116 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2117 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2120 else if (streq (current
->name
, _LIB
))
2122 /* On Irix 4, the location of contents of the .lib section
2123 from a shared library section is also rounded up to a
2126 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2127 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2129 else if (first_nonalloc
2130 && (current
->flags
& SEC_ALLOC
) == 0
2131 && (abfd
->flags
& D_PAGED
) != 0)
2133 /* Skip up to the next page for an unallocated section, such
2134 as the .comment section on the Alpha. This leaves room
2135 for the .bss section. */
2136 first_nonalloc
= false;
2137 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2138 file_sofar
= (file_sofar
+ round
- 1) &~ (round
- 1);
2141 /* Align the sections in the file to the same boundary on
2142 which they are aligned in virtual memory. */
2143 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2144 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2145 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2147 if ((abfd
->flags
& D_PAGED
) != 0
2148 && (current
->flags
& SEC_ALLOC
) != 0)
2150 sofar
+= (current
->vma
- sofar
) % round
;
2151 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2152 file_sofar
+= (current
->vma
- file_sofar
) % round
;
2155 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) != 0)
2156 current
->filepos
= file_sofar
;
2158 sofar
+= current
->size
;
2159 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2160 file_sofar
+= current
->size
;
2162 /* Make sure that this section is of the right size too. */
2164 sofar
= BFD_ALIGN (sofar
, 1 << alignment_power
);
2165 if ((current
->flags
& SEC_HAS_CONTENTS
) != 0)
2166 file_sofar
= BFD_ALIGN (file_sofar
, 1 << alignment_power
);
2167 current
->size
+= sofar
- old_sofar
;
2173 ecoff_data (abfd
)->reloc_filepos
= file_sofar
;
2178 /* Determine the location of the relocs for all the sections in the
2179 output file, as well as the location of the symbolic debugging
2182 static bfd_size_type
2183 ecoff_compute_reloc_file_positions (bfd
*abfd
)
2185 const bfd_size_type external_reloc_size
=
2186 ecoff_backend (abfd
)->external_reloc_size
;
2187 file_ptr reloc_base
;
2188 bfd_size_type reloc_size
;
2192 if (! abfd
->output_has_begun
)
2194 if (! ecoff_compute_section_file_positions (abfd
))
2196 abfd
->output_has_begun
= true;
2199 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2202 for (current
= abfd
->sections
;
2204 current
= current
->next
)
2206 if (current
->reloc_count
== 0)
2207 current
->rel_filepos
= 0;
2210 bfd_size_type relsize
;
2212 current
->rel_filepos
= reloc_base
;
2213 relsize
= current
->reloc_count
* external_reloc_size
;
2214 reloc_size
+= relsize
;
2215 reloc_base
+= relsize
;
2219 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2221 /* At least on Ultrix, the symbol table of an executable file must
2222 be aligned to a page boundary. FIXME: Is this true on other
2224 if ((abfd
->flags
& EXEC_P
) != 0
2225 && (abfd
->flags
& D_PAGED
) != 0)
2226 sym_base
= ((sym_base
+ ecoff_backend (abfd
)->round
- 1)
2227 &~ (ecoff_backend (abfd
)->round
- 1));
2229 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2234 /* Set the contents of a section. */
2237 _bfd_ecoff_set_section_contents (bfd
*abfd
,
2239 const void * location
,
2241 bfd_size_type count
)
2245 /* This must be done first, because bfd_set_section_contents is
2246 going to set output_has_begun to TRUE. */
2247 if (! abfd
->output_has_begun
2248 && ! ecoff_compute_section_file_positions (abfd
))
2251 /* Handle the .lib section specially so that Irix 4 shared libraries
2252 work out. See coff_set_section_contents in coffcode.h. */
2253 if (streq (section
->name
, _LIB
))
2255 bfd_byte
*rec
, *recend
;
2257 rec
= (bfd_byte
*) location
;
2258 recend
= rec
+ count
;
2259 while (rec
< recend
)
2262 rec
+= bfd_get_32 (abfd
, rec
) * 4;
2265 BFD_ASSERT (rec
== recend
);
2271 pos
= section
->filepos
+ offset
;
2272 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
2273 || bfd_write (location
, count
, abfd
) != count
)
2279 /* Set the GP value for an ECOFF file. This is a hook used by the
2283 bfd_ecoff_set_gp_value (bfd
*abfd
, bfd_vma gp_value
)
2285 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2286 || bfd_get_format (abfd
) != bfd_object
)
2288 bfd_set_error (bfd_error_invalid_operation
);
2292 ecoff_data (abfd
)->gp
= gp_value
;
2297 /* Set the register masks for an ECOFF file. This is a hook used by
2301 bfd_ecoff_set_regmasks (bfd
*abfd
,
2302 unsigned long gprmask
,
2303 unsigned long fprmask
,
2304 unsigned long *cprmask
)
2306 ecoff_data_type
*tdata
;
2308 if (bfd_get_flavour (abfd
) != bfd_target_ecoff_flavour
2309 || bfd_get_format (abfd
) != bfd_object
)
2311 bfd_set_error (bfd_error_invalid_operation
);
2315 tdata
= ecoff_data (abfd
);
2316 tdata
->gprmask
= gprmask
;
2317 tdata
->fprmask
= fprmask
;
2318 if (cprmask
!= NULL
)
2322 for (i
= 0; i
< 3; i
++)
2323 tdata
->cprmask
[i
] = cprmask
[i
];
2329 /* Get ECOFF EXTR information for an external symbol. This function
2330 is passed to bfd_ecoff_debug_externals. */
2333 ecoff_get_extr (asymbol
*sym
, EXTR
*esym
)
2335 ecoff_symbol_type
*ecoff_sym_ptr
;
2338 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2339 || ecoffsymbol (sym
)->native
== NULL
)
2341 /* Don't include debugging, local, or section symbols. */
2342 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2343 || (sym
->flags
& BSF_LOCAL
) != 0
2344 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2348 esym
->cobol_main
= 0;
2349 esym
->weakext
= (sym
->flags
& BSF_WEAK
) != 0;
2352 /* FIXME: we can do better than this for st and sc. */
2353 esym
->asym
.st
= stGlobal
;
2354 esym
->asym
.sc
= scAbs
;
2355 esym
->asym
.reserved
= 0;
2356 esym
->asym
.index
= indexNil
;
2360 ecoff_sym_ptr
= ecoffsymbol (sym
);
2362 if (ecoff_sym_ptr
->local
)
2365 input_bfd
= bfd_asymbol_bfd (sym
);
2366 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2367 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2369 /* If the symbol was defined by the linker, then esym will be
2370 undefined but sym will not be. Get a better class for such a
2372 if ((esym
->asym
.sc
== scUndefined
2373 || esym
->asym
.sc
== scSUndefined
)
2374 && ! bfd_is_und_section (bfd_asymbol_section (sym
)))
2375 esym
->asym
.sc
= scAbs
;
2377 /* Adjust the FDR index for the symbol by that used for the input
2379 if (esym
->ifd
!= -1)
2381 struct ecoff_debug_info
*input_debug
;
2383 input_debug
= &ecoff_data (input_bfd
)->debug_info
;
2384 BFD_ASSERT (esym
->ifd
< input_debug
->symbolic_header
.ifdMax
);
2385 if (input_debug
->ifdmap
!= NULL
)
2386 esym
->ifd
= input_debug
->ifdmap
[esym
->ifd
];
2392 /* Set the external symbol index. This routine is passed to
2393 bfd_ecoff_debug_externals. */
2396 ecoff_set_index (asymbol
*sym
, bfd_size_type indx
)
2398 ecoff_set_sym_index (sym
, indx
);
2401 /* Write out an ECOFF file. */
2404 _bfd_ecoff_write_object_contents (bfd
*abfd
)
2406 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2407 const bfd_vma round
= backend
->round
;
2408 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2409 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2410 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2411 const bfd_size_type external_hdr_size
2412 = backend
->debug_swap
.external_hdr_size
;
2413 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2414 void (* const adjust_reloc_out
) (bfd
*, const arelent
*, struct internal_reloc
*)
2415 = backend
->adjust_reloc_out
;
2416 void (* const swap_reloc_out
) (bfd
*, const struct internal_reloc
*, void *)
2417 = backend
->swap_reloc_out
;
2418 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2419 HDRR
* const symhdr
= &debug
->symbolic_header
;
2422 bfd_size_type reloc_size
;
2423 bfd_size_type text_size
;
2425 bool set_text_start
;
2426 bfd_size_type data_size
;
2428 bool set_data_start
;
2429 bfd_size_type bss_size
;
2431 void * reloc_buff
= NULL
;
2432 struct internal_filehdr internal_f
;
2433 struct internal_aouthdr internal_a
;
2436 /* Determine where the sections and relocs will go in the output
2438 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2441 for (current
= abfd
->sections
;
2443 current
= current
->next
)
2445 current
->target_index
= count
;
2449 if ((abfd
->flags
& D_PAGED
) != 0)
2450 text_size
= _bfd_ecoff_sizeof_headers (abfd
, NULL
);
2454 set_text_start
= false;
2457 set_data_start
= false;
2460 /* Write section headers to the file. */
2462 /* Allocate buff big enough to hold a section header,
2463 file header, or a.out header. */
2472 buff
= bfd_malloc (siz
);
2477 internal_f
.f_nscns
= 0;
2478 if (bfd_seek (abfd
, filhsz
+ aoutsz
, SEEK_SET
) != 0)
2481 for (current
= abfd
->sections
;
2483 current
= current
->next
)
2485 struct internal_scnhdr section
;
2488 ++internal_f
.f_nscns
;
2490 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2492 /* This seems to be correct for Irix 4 shared libraries. */
2493 vma
= bfd_section_vma (current
);
2494 if (streq (current
->name
, _LIB
))
2495 section
.s_vaddr
= 0;
2497 section
.s_vaddr
= vma
;
2499 section
.s_paddr
= current
->lma
;
2500 section
.s_size
= current
->size
;
2502 /* If this section is unloadable then the scnptr will be 0. */
2503 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2504 section
.s_scnptr
= 0;
2506 section
.s_scnptr
= current
->filepos
;
2507 section
.s_relptr
= current
->rel_filepos
;
2509 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2510 object file produced by the assembler is supposed to point to
2511 information about how much room is required by objects of
2512 various different sizes. I think this only matters if we
2513 want the linker to compute the best size to use, or
2514 something. I don't know what happens if the information is
2516 if (! streq (current
->name
, _PDATA
))
2517 section
.s_lnnoptr
= 0;
2520 /* The Alpha ECOFF .pdata section uses the lnnoptr field to
2521 hold the number of entries in the section (each entry is
2522 8 bytes). We stored this in the line_filepos field in
2523 ecoff_compute_section_file_positions. */
2524 section
.s_lnnoptr
= current
->line_filepos
;
2527 section
.s_nreloc
= current
->reloc_count
;
2528 section
.s_nlnno
= 0;
2529 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2532 if (bfd_coff_swap_scnhdr_out (abfd
, (void *) §ion
, buff
) == 0
2533 || bfd_write (buff
, scnhsz
, abfd
) != scnhsz
)
2536 if ((section
.s_flags
& STYP_TEXT
) != 0
2537 || ((section
.s_flags
& STYP_RDATA
) != 0
2538 && ecoff_data (abfd
)->rdata_in_text
)
2539 || section
.s_flags
== STYP_PDATA
2540 || (section
.s_flags
& STYP_DYNAMIC
) != 0
2541 || (section
.s_flags
& STYP_LIBLIST
) != 0
2542 || (section
.s_flags
& STYP_RELDYN
) != 0
2543 || section
.s_flags
== STYP_CONFLIC
2544 || (section
.s_flags
& STYP_DYNSTR
) != 0
2545 || (section
.s_flags
& STYP_DYNSYM
) != 0
2546 || (section
.s_flags
& STYP_HASH
) != 0
2547 || (section
.s_flags
& STYP_ECOFF_INIT
) != 0
2548 || (section
.s_flags
& STYP_ECOFF_FINI
) != 0
2549 || section
.s_flags
== STYP_RCONST
)
2551 text_size
+= current
->size
;
2552 if (! set_text_start
|| text_start
> vma
)
2555 set_text_start
= true;
2558 else if ((section
.s_flags
& STYP_RDATA
) != 0
2559 || (section
.s_flags
& STYP_DATA
) != 0
2560 || (section
.s_flags
& STYP_LITA
) != 0
2561 || (section
.s_flags
& STYP_LIT8
) != 0
2562 || (section
.s_flags
& STYP_LIT4
) != 0
2563 || (section
.s_flags
& STYP_SDATA
) != 0
2564 || section
.s_flags
== STYP_XDATA
2565 || (section
.s_flags
& STYP_GOT
) != 0)
2567 data_size
+= current
->size
;
2568 if (! set_data_start
|| data_start
> vma
)
2571 set_data_start
= true;
2574 else if ((section
.s_flags
& STYP_BSS
) != 0
2575 || (section
.s_flags
& STYP_SBSS
) != 0)
2576 bss_size
+= current
->size
;
2577 else if (section
.s_flags
== 0
2578 || (section
.s_flags
& STYP_ECOFF_LIB
) != 0
2579 || section
.s_flags
== STYP_COMMENT
)
2585 /* Set up the file header. */
2586 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2588 /* We will NOT put a fucking timestamp in the header here. Every
2589 time you put it back, I will come in and take it out again. I'm
2590 sorry. This field does not belong here. We fill it with a 0 so
2591 it compares the same but is not a reasonable time. --
2593 internal_f
.f_timdat
= 0;
2595 if (bfd_get_symcount (abfd
) != 0)
2597 /* The ECOFF f_nsyms field is not actually the number of
2598 symbols, it's the size of symbolic information header. */
2599 internal_f
.f_nsyms
= external_hdr_size
;
2600 internal_f
.f_symptr
= ecoff_data (abfd
)->sym_filepos
;
2604 internal_f
.f_nsyms
= 0;
2605 internal_f
.f_symptr
= 0;
2608 internal_f
.f_opthdr
= aoutsz
;
2610 internal_f
.f_flags
= F_LNNO
;
2611 if (reloc_size
== 0)
2612 internal_f
.f_flags
|= F_RELFLG
;
2613 if (bfd_get_symcount (abfd
) == 0)
2614 internal_f
.f_flags
|= F_LSYMS
;
2615 if (abfd
->flags
& EXEC_P
)
2616 internal_f
.f_flags
|= F_EXEC
;
2618 if (bfd_little_endian (abfd
))
2619 internal_f
.f_flags
|= F_AR32WR
;
2621 internal_f
.f_flags
|= F_AR32W
;
2623 /* Set up the ``optional'' header. */
2624 if ((abfd
->flags
& D_PAGED
) != 0)
2625 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2627 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2629 /* FIXME: Is this really correct? */
2630 internal_a
.vstamp
= symhdr
->vstamp
;
2632 /* At least on Ultrix, these have to be rounded to page boundaries.
2633 FIXME: Is this true on other platforms? */
2634 if ((abfd
->flags
& D_PAGED
) != 0)
2636 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2637 internal_a
.text_start
= text_start
&~ (round
- 1);
2638 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2639 internal_a
.data_start
= data_start
&~ (round
- 1);
2643 internal_a
.tsize
= text_size
;
2644 internal_a
.text_start
= text_start
;
2645 internal_a
.dsize
= data_size
;
2646 internal_a
.data_start
= data_start
;
2649 /* On Ultrix, the initial portions of the .sbss and .bss segments
2650 are at the end of the data section. The bsize field in the
2651 optional header records how many bss bytes are required beyond
2652 those in the data section. The value is not rounded to a page
2654 if (bss_size
< internal_a
.dsize
- data_size
)
2657 bss_size
-= internal_a
.dsize
- data_size
;
2658 internal_a
.bsize
= bss_size
;
2659 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2661 internal_a
.entry
= bfd_get_start_address (abfd
);
2663 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2665 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2666 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2667 for (i
= 0; i
< 4; i
++)
2668 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2670 /* Let the backend adjust the headers if necessary. */
2671 if (backend
->adjust_headers
)
2673 if (! (*backend
->adjust_headers
) (abfd
, &internal_f
, &internal_a
))
2677 /* Write out the file header and the optional header. */
2678 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0)
2681 bfd_coff_swap_filehdr_out (abfd
, (void *) &internal_f
, buff
);
2682 if (bfd_write (buff
, filhsz
, abfd
) != filhsz
)
2685 bfd_coff_swap_aouthdr_out (abfd
, (void *) &internal_a
, buff
);
2686 if (bfd_write (buff
, aoutsz
, abfd
) != aoutsz
)
2689 /* Build the external symbol information. This must be done before
2690 writing out the relocs so that we know the symbol indices. We
2691 don't do this if this BFD was created by the backend linker,
2692 since it will have already handled the symbols and relocs. */
2693 if (! ecoff_data (abfd
)->linker
)
2695 symhdr
->iextMax
= 0;
2696 symhdr
->issExtMax
= 0;
2697 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2698 debug
->ssext
= debug
->ssext_end
= NULL
;
2699 if (! bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2700 (abfd
->flags
& EXEC_P
) == 0,
2701 ecoff_get_extr
, ecoff_set_index
))
2704 /* Write out the relocs. */
2705 for (current
= abfd
->sections
;
2707 current
= current
->next
)
2709 arelent
**reloc_ptr_ptr
;
2710 arelent
**reloc_end
;
2714 if (current
->reloc_count
== 0)
2717 amt
= current
->reloc_count
* external_reloc_size
;
2718 reloc_buff
= bfd_zalloc (abfd
, amt
);
2719 if (reloc_buff
== NULL
)
2722 reloc_ptr_ptr
= current
->orelocation
;
2723 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2724 out_ptr
= (char *) reloc_buff
;
2727 reloc_ptr_ptr
< reloc_end
;
2728 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2732 struct internal_reloc in
;
2734 memset ((void *) &in
, 0, sizeof in
);
2736 reloc
= *reloc_ptr_ptr
;
2737 sym
= *reloc
->sym_ptr_ptr
;
2739 /* If the howto field has not been initialised then skip this reloc.
2740 This assumes that an error message has been issued elsewhere. */
2741 if (reloc
->howto
== NULL
)
2744 in
.r_vaddr
= reloc
->address
+ bfd_section_vma (current
);
2745 in
.r_type
= reloc
->howto
->type
;
2747 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2749 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2763 { _TEXT
, RELOC_SECTION_TEXT
},
2764 { _RDATA
, RELOC_SECTION_RDATA
},
2765 { _DATA
, RELOC_SECTION_DATA
},
2766 { _SDATA
, RELOC_SECTION_SDATA
},
2767 { _SBSS
, RELOC_SECTION_SBSS
},
2768 { _BSS
, RELOC_SECTION_BSS
},
2769 { _INIT
, RELOC_SECTION_INIT
},
2770 { _LIT8
, RELOC_SECTION_LIT8
},
2771 { _LIT4
, RELOC_SECTION_LIT4
},
2772 { _XDATA
, RELOC_SECTION_XDATA
},
2773 { _PDATA
, RELOC_SECTION_PDATA
},
2774 { _FINI
, RELOC_SECTION_FINI
},
2775 { _LITA
, RELOC_SECTION_LITA
},
2776 { "*ABS*", RELOC_SECTION_ABS
},
2777 { _RCONST
, RELOC_SECTION_RCONST
}
2780 name
= bfd_section_name (bfd_asymbol_section (sym
));
2782 for (j
= 0; j
< ARRAY_SIZE (section_symndx
); j
++)
2783 if (streq (name
, section_symndx
[j
].name
))
2785 in
.r_symndx
= section_symndx
[j
].r_symndx
;
2789 if (j
== ARRAY_SIZE (section_symndx
))
2794 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2796 (*swap_reloc_out
) (abfd
, &in
, (void *) out_ptr
);
2799 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2801 amt
= current
->reloc_count
* external_reloc_size
;
2802 if (bfd_write (reloc_buff
, amt
, abfd
) != amt
)
2804 bfd_release (abfd
, reloc_buff
);
2808 /* Write out the symbolic debugging information. */
2809 if (bfd_get_symcount (abfd
) > 0)
2811 /* Write out the debugging information. */
2812 if (! bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2813 ecoff_data (abfd
)->sym_filepos
))
2818 /* The .bss section of a demand paged executable must receive an
2819 entire page. If there are symbols, the symbols will start on the
2820 next page. If there are no symbols, we must fill out the page by
2822 if (bfd_get_symcount (abfd
) == 0
2823 && (abfd
->flags
& EXEC_P
) != 0
2824 && (abfd
->flags
& D_PAGED
) != 0)
2828 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
- 1, SEEK_SET
) != 0)
2830 if (bfd_read (&c
, 1, abfd
) == 0)
2832 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
- 1, SEEK_SET
) != 0)
2834 if (bfd_write (&c
, 1, abfd
) != 1)
2838 if (reloc_buff
!= NULL
)
2839 bfd_release (abfd
, reloc_buff
);
2843 if (reloc_buff
!= NULL
)
2844 bfd_release (abfd
, reloc_buff
);
2849 /* Archive handling. ECOFF uses what appears to be a unique type of
2850 archive header (armap). The byte ordering of the armap and the
2851 contents are encoded in the name of the armap itself. At least for
2852 now, we only support archives with the same byte ordering in the
2853 armap and the contents.
2855 The first four bytes in the armap are the number of symbol
2856 definitions. This is always a power of two.
2858 This is followed by the symbol definitions. Each symbol definition
2859 occupies 8 bytes. The first four bytes are the offset from the
2860 start of the armap strings to the null-terminated string naming
2861 this symbol. The second four bytes are the file offset to the
2862 archive member which defines this symbol. If the second four bytes
2863 are 0, then this is not actually a symbol definition, and it should
2866 The symbols are hashed into the armap with a closed hashing scheme.
2867 See the functions below for the details of the algorithm.
2869 After the symbol definitions comes four bytes holding the size of
2870 the string table, followed by the string table itself. */
2872 /* The name of an archive headers looks like this:
2873 __________E[BL]E[BL]_ (with a trailing space).
2874 The trailing space is changed to an X if the archive is changed to
2875 indicate that the armap is out of date.
2877 The Alpha seems to use ________64E[BL]E[BL]_. */
2879 #define ARMAP_BIG_ENDIAN 'B'
2880 #define ARMAP_LITTLE_ENDIAN 'L'
2881 #define ARMAP_MARKER 'E'
2882 #define ARMAP_START_LENGTH 10
2883 #define ARMAP_HEADER_MARKER_INDEX 10
2884 #define ARMAP_HEADER_ENDIAN_INDEX 11
2885 #define ARMAP_OBJECT_MARKER_INDEX 12
2886 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2887 #define ARMAP_END_INDEX 14
2888 #define ARMAP_END "_ "
2890 /* This is a magic number used in the hashing algorithm. */
2891 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2893 /* This returns the hash value to use for a string. It also sets
2894 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2895 is the number of entries in the hash table, and HLOG is the log
2899 ecoff_armap_hash (const char *s
,
2900 unsigned int *rehash
,
2910 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2911 hash
*= ARMAP_HASH_MAGIC
;
2912 *rehash
= (hash
& (size
- 1)) | 1;
2913 return hash
>> (32 - hlog
);
2916 /* Read in the armap. */
2919 _bfd_ecoff_slurp_armap (bfd
*abfd
)
2923 struct areltdata
*mapdata
;
2924 bfd_size_type parsed_size
, stringsize
;
2926 struct artdata
*ardata
;
2933 /* Get the name of the first element. */
2934 i
= bfd_read (nextname
, 16, abfd
);
2940 if (bfd_seek (abfd
, -16, SEEK_CUR
) != 0)
2943 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2944 standard COFF armap. We could move the ECOFF armap stuff into
2945 bfd_slurp_armap, but that seems inappropriate since no other
2946 target uses this format. Instead, we check directly for a COFF
2948 if (startswith (nextname
, "/ "))
2949 return bfd_slurp_armap (abfd
);
2951 /* See if the first element is an armap. */
2952 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
, ARMAP_START_LENGTH
) != 0
2953 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2954 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2955 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2956 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
2957 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2958 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2959 || strncmp (nextname
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
2961 abfd
->has_armap
= false;
2965 /* Make sure we have the right byte ordering. */
2966 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2967 ^ (bfd_header_big_endian (abfd
)))
2968 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2969 ^ (bfd_big_endian (abfd
))))
2971 bfd_set_error (bfd_error_wrong_format
);
2975 /* Read in the armap. */
2976 ardata
= bfd_ardata (abfd
);
2977 mapdata
= (struct areltdata
*) _bfd_read_ar_hdr (abfd
);
2978 if (mapdata
== NULL
)
2980 parsed_size
= mapdata
->parsed_size
;
2983 if (parsed_size
+ 1 < 9)
2985 bfd_set_error (bfd_error_malformed_archive
);
2989 raw_armap
= (char *) _bfd_alloc_and_read (abfd
, parsed_size
+ 1, parsed_size
);
2990 if (raw_armap
== NULL
)
2992 raw_armap
[parsed_size
] = 0;
2994 ardata
->tdata
= (void *) raw_armap
;
2996 count
= H_GET_32 (abfd
, raw_armap
);
2997 if ((parsed_size
- 8) / 8 < count
)
2998 goto error_malformed
;
3000 ardata
->symdef_count
= 0;
3001 ardata
->cache
= NULL
;
3003 /* This code used to overlay the symdefs over the raw archive data,
3004 but that doesn't work on a 64 bit host. */
3005 stringbase
= raw_armap
+ count
* 8 + 8;
3006 stringsize
= parsed_size
- (count
* 8 + 8);
3008 #ifdef CHECK_ARMAP_HASH
3012 /* Double check that I have the hashing algorithm right by making
3013 sure that every symbol can be looked up successfully. */
3015 for (i
= 1; i
< count
; i
<<= 1)
3017 BFD_ASSERT (i
== count
);
3019 raw_ptr
= raw_armap
+ 4;
3020 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3022 unsigned int name_offset
, file_offset
;
3023 unsigned int hash
, rehash
, srch
;
3025 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3026 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3027 if (file_offset
== 0)
3029 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
3034 /* See if we can rehash to this location. */
3035 for (srch
= (hash
+ rehash
) & (count
- 1);
3036 srch
!= hash
&& srch
!= i
;
3037 srch
= (srch
+ rehash
) & (count
- 1))
3038 BFD_ASSERT (H_GET_32 (abfd
, (raw_armap
+ 8 + srch
* 8)) != 0);
3039 BFD_ASSERT (srch
== i
);
3043 #endif /* CHECK_ARMAP_HASH */
3045 raw_ptr
= raw_armap
+ 4;
3046 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3047 if (H_GET_32 (abfd
, (raw_ptr
+ 4)) != 0)
3048 ++ardata
->symdef_count
;
3050 amt
= ardata
->symdef_count
;
3051 amt
*= sizeof (carsym
);
3052 symdef_ptr
= (carsym
*) bfd_alloc (abfd
, amt
);
3056 ardata
->symdefs
= symdef_ptr
;
3058 raw_ptr
= raw_armap
+ 4;
3059 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3061 unsigned int name_offset
, file_offset
;
3063 file_offset
= H_GET_32 (abfd
, (raw_ptr
+ 4));
3064 if (file_offset
== 0)
3066 name_offset
= H_GET_32 (abfd
, raw_ptr
);
3067 if (name_offset
> stringsize
)
3068 goto error_malformed
;
3069 symdef_ptr
->name
= stringbase
+ name_offset
;
3070 symdef_ptr
->file_offset
= file_offset
;
3074 ardata
->first_file_filepos
= bfd_tell (abfd
);
3075 /* Pad to an even boundary. */
3076 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3077 abfd
->has_armap
= true;
3081 bfd_set_error (bfd_error_malformed_archive
);
3083 ardata
->symdef_count
= 0;
3084 ardata
->symdefs
= NULL
;
3085 ardata
->tdata
= NULL
;
3086 bfd_release (abfd
, raw_armap
);
3090 /* Write out an armap. */
3093 _bfd_ecoff_write_armap (bfd
*abfd
,
3094 unsigned int elength
,
3096 unsigned int orl_count
,
3099 unsigned int hashsize
, hashlog
;
3100 bfd_size_type symdefsize
;
3102 unsigned int stringsize
;
3103 unsigned int mapsize
;
3106 struct stat statbuf
;
3109 bfd_byte
*hashtable
;
3113 /* Ultrix appears to use as a hash table size the least power of two
3114 greater than twice the number of entries. */
3115 for (hashlog
= 0; ((unsigned int) 1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3117 hashsize
= 1 << hashlog
;
3119 symdefsize
= hashsize
* 8;
3121 stringsize
= stridx
+ padit
;
3123 /* Include 8 bytes to store symdefsize and stringsize in output. */
3124 mapsize
= symdefsize
+ stringsize
+ 8;
3126 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3128 memset ((void *) &hdr
, 0, sizeof hdr
);
3130 /* Work out the ECOFF armap name. */
3131 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3132 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3133 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3134 (bfd_header_big_endian (abfd
)
3136 : ARMAP_LITTLE_ENDIAN
);
3137 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3138 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3139 bfd_big_endian (abfd
) ? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3140 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3142 /* Write the timestamp of the archive header to be just a little bit
3143 later than the timestamp of the file, otherwise the linker will
3144 complain that the index is out of date. Actually, the Ultrix
3145 linker just checks the archive name; the GNU linker may check the
3147 stat (bfd_get_filename (abfd
), &statbuf
);
3148 _bfd_ar_spacepad (hdr
.ar_date
, sizeof (hdr
.ar_date
), "%ld",
3149 (long) (statbuf
.st_mtime
+ 60));
3151 /* The DECstation uses zeroes for the uid, gid and mode of the
3153 hdr
.ar_uid
[0] = '0';
3154 hdr
.ar_gid
[0] = '0';
3155 /* Building gcc ends up extracting the armap as a file - twice. */
3156 hdr
.ar_mode
[0] = '6';
3157 hdr
.ar_mode
[1] = '4';
3158 hdr
.ar_mode
[2] = '4';
3160 _bfd_ar_spacepad (hdr
.ar_size
, sizeof (hdr
.ar_size
), "%-10ld", mapsize
);
3162 hdr
.ar_fmag
[0] = '`';
3163 hdr
.ar_fmag
[1] = '\012';
3165 /* Turn all null bytes in the header into spaces. */
3166 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3167 if (((char *) (&hdr
))[i
] == '\0')
3168 (((char *) (&hdr
))[i
]) = ' ';
3170 if (bfd_write (&hdr
, sizeof (struct ar_hdr
), abfd
) != sizeof (struct ar_hdr
))
3173 H_PUT_32 (abfd
, hashsize
, temp
);
3174 if (bfd_write (temp
, 4, abfd
) != 4)
3177 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3181 current
= abfd
->archive_head
;
3183 for (i
= 0; i
< orl_count
; i
++)
3185 unsigned int hash
, rehash
= 0;
3187 /* Advance firstreal to the file position of this archive
3189 if (map
[i
].u
.abfd
!= last_elt
)
3193 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3194 firstreal
+= firstreal
% 2;
3195 current
= current
->archive_next
;
3197 while (current
!= map
[i
].u
.abfd
);
3202 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3203 if (H_GET_32 (abfd
, (hashtable
+ (hash
* 8) + 4)) != 0)
3207 /* The desired slot is already taken. */
3208 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3210 srch
= (srch
+ rehash
) & (hashsize
- 1))
3211 if (H_GET_32 (abfd
, (hashtable
+ (srch
* 8) + 4)) == 0)
3214 BFD_ASSERT (srch
!= hash
);
3219 H_PUT_32 (abfd
, map
[i
].namidx
, (hashtable
+ hash
* 8));
3220 H_PUT_32 (abfd
, firstreal
, (hashtable
+ hash
* 8 + 4));
3223 if (bfd_write (hashtable
, symdefsize
, abfd
) != symdefsize
)
3226 bfd_release (abfd
, hashtable
);
3228 /* Now write the strings. */
3229 H_PUT_32 (abfd
, stringsize
, temp
);
3230 if (bfd_write (temp
, 4, abfd
) != 4)
3232 for (i
= 0; i
< orl_count
; i
++)
3236 len
= strlen (*map
[i
].name
) + 1;
3237 if (bfd_write (*map
[i
].name
, len
, abfd
) != len
)
3241 /* The spec sez this should be a newline. But in order to be
3242 bug-compatible for DECstation ar we use a null. */
3245 if (bfd_write ("", 1, abfd
) != 1)
3252 /* ECOFF linker code. */
3254 /* Routine to create an entry in an ECOFF link hash table. */
3256 static struct bfd_hash_entry
*
3257 ecoff_link_hash_newfunc (struct bfd_hash_entry
*entry
,
3258 struct bfd_hash_table
*table
,
3261 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3263 /* Allocate the structure if it has not already been allocated by a
3266 ret
= ((struct ecoff_link_hash_entry
*)
3267 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3271 /* Call the allocation method of the superclass. */
3272 ret
= ((struct ecoff_link_hash_entry
*)
3273 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3278 /* Set local fields. */
3283 memset ((void *) &ret
->esym
, 0, sizeof ret
->esym
);
3286 return (struct bfd_hash_entry
*) ret
;
3289 /* Create an ECOFF link hash table. */
3291 struct bfd_link_hash_table
*
3292 _bfd_ecoff_bfd_link_hash_table_create (bfd
*abfd
)
3294 struct ecoff_link_hash_table
*ret
;
3295 size_t amt
= sizeof (struct ecoff_link_hash_table
);
3297 ret
= (struct ecoff_link_hash_table
*) bfd_malloc (amt
);
3300 if (!_bfd_link_hash_table_init (&ret
->root
, abfd
,
3301 ecoff_link_hash_newfunc
,
3302 sizeof (struct ecoff_link_hash_entry
)))
3310 /* Look up an entry in an ECOFF link hash table. */
3312 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3313 ((struct ecoff_link_hash_entry *) \
3314 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3316 /* Get the ECOFF link hash table from the info structure. This is
3319 #define ecoff_hash_table(p) ((struct ecoff_link_hash_table *) ((p)->hash))
3321 /* Add the external symbols of an object file to the global linker
3322 hash table. The external symbols and strings we are passed are
3323 just allocated on the stack, and will be discarded. We must
3324 explicitly save any information we may need later on in the link.
3325 We do not want to read the external symbol information again. */
3328 ecoff_link_add_externals (bfd
*abfd
,
3329 struct bfd_link_info
*info
,
3330 void * external_ext
,
3333 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3334 void (* const swap_ext_in
) (bfd
*, void *, EXTR
*)
3335 = backend
->debug_swap
.swap_ext_in
;
3336 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3337 unsigned long ext_count
;
3338 struct bfd_link_hash_entry
**sym_hash
;
3343 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3346 amt
*= sizeof (struct bfd_link_hash_entry
*);
3347 sym_hash
= (struct bfd_link_hash_entry
**) bfd_alloc (abfd
, amt
);
3350 ecoff_data (abfd
)->sym_hashes
= (struct ecoff_link_hash_entry
**) sym_hash
;
3352 ext_ptr
= (char *) external_ext
;
3353 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3354 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3361 struct ecoff_link_hash_entry
*h
;
3365 (*swap_ext_in
) (abfd
, (void *) ext_ptr
, &esym
);
3367 /* Skip debugging symbols. */
3369 switch (esym
.asym
.st
)
3385 /* Get the information for this symbol. */
3386 value
= esym
.asym
.value
;
3387 switch (esym
.asym
.sc
)
3407 section
= bfd_make_section_old_way (abfd
, _TEXT
);
3408 value
-= section
->vma
;
3411 section
= bfd_make_section_old_way (abfd
, _DATA
);
3412 value
-= section
->vma
;
3415 section
= bfd_make_section_old_way (abfd
, _BSS
);
3416 value
-= section
->vma
;
3419 section
= bfd_abs_section_ptr
;
3422 section
= bfd_und_section_ptr
;
3425 section
= bfd_make_section_old_way (abfd
, _SDATA
);
3426 value
-= section
->vma
;
3429 section
= bfd_make_section_old_way (abfd
, _SBSS
);
3430 value
-= section
->vma
;
3433 section
= bfd_make_section_old_way (abfd
, _RDATA
);
3434 value
-= section
->vma
;
3437 if (value
> ecoff_data (abfd
)->gp_size
)
3439 section
= bfd_com_section_ptr
;
3444 section
= &ecoff_scom_section
;
3447 section
= bfd_und_section_ptr
;
3450 section
= bfd_make_section_old_way (abfd
, _INIT
);
3451 value
-= section
->vma
;
3454 section
= bfd_make_section_old_way (abfd
, _FINI
);
3455 value
-= section
->vma
;
3458 section
= bfd_make_section_old_way (abfd
, _RCONST
);
3459 value
-= section
->vma
;
3463 if (section
== NULL
)
3466 name
= ssext
+ esym
.asym
.iss
;
3468 if (! (_bfd_generic_link_add_one_symbol
3470 (flagword
) (esym
.weakext
? BSF_WEAK
: BSF_GLOBAL
),
3471 section
, value
, NULL
, true, true, sym_hash
)))
3474 h
= (struct ecoff_link_hash_entry
*) *sym_hash
;
3476 /* If we are building an ECOFF hash table, save the external
3477 symbol information. */
3478 if (bfd_get_flavour (info
->output_bfd
) == bfd_get_flavour (abfd
))
3481 || (! bfd_is_und_section (section
)
3482 && (! bfd_is_com_section (section
)
3483 || (h
->root
.type
!= bfd_link_hash_defined
3484 && h
->root
.type
!= bfd_link_hash_defweak
))))
3490 /* Remember whether this symbol was small undefined. */
3491 if (esym
.asym
.sc
== scSUndefined
)
3494 /* If this symbol was ever small undefined, it needs to wind
3495 up in a GP relative section. We can't control the
3496 section of a defined symbol, but we can control the
3497 section of a common symbol. This case is actually needed
3498 on Ultrix 4.2 to handle the symbol cred in -lckrb. */
3500 && h
->root
.type
== bfd_link_hash_common
3501 && streq (h
->root
.u
.c
.p
->section
->name
, SCOMMON
))
3503 h
->root
.u
.c
.p
->section
= bfd_make_section_old_way (abfd
,
3505 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
3506 if (h
->esym
.asym
.sc
== scCommon
)
3507 h
->esym
.asym
.sc
= scSCommon
;
3515 /* Add symbols from an ECOFF object file to the global linker hash
3519 ecoff_link_add_object_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3522 bfd_size_type external_ext_size
;
3523 void * external_ext
= NULL
;
3524 bfd_size_type esize
;
3528 if (! ecoff_slurp_symbolic_header (abfd
))
3531 /* If there are no symbols, we don't want it. */
3532 if (bfd_get_symcount (abfd
) == 0)
3535 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3537 /* Read in the external symbols and external strings. */
3538 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0)
3540 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3541 esize
= symhdr
->iextMax
* external_ext_size
;
3542 external_ext
= _bfd_malloc_and_read (abfd
, esize
, esize
);
3543 if (external_ext
== NULL
&& esize
!= 0)
3546 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0)
3548 ssext
= (char *) _bfd_malloc_and_read (abfd
, symhdr
->issExtMax
,
3550 if (ssext
== NULL
&& symhdr
->issExtMax
!= 0)
3553 result
= ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3556 free (external_ext
);
3561 free (external_ext
);
3565 /* This is called if we used _bfd_generic_link_add_archive_symbols
3566 because we were not dealing with an ECOFF archive. */
3569 ecoff_link_check_archive_element (bfd
*abfd
,
3570 struct bfd_link_info
*info
,
3571 struct bfd_link_hash_entry
*h
,
3577 /* Unlike the generic linker, we do not pull in elements because
3578 of common symbols. */
3579 if (h
->type
!= bfd_link_hash_undefined
)
3582 /* Include this element? */
3583 if (!(*info
->callbacks
->add_archive_element
) (info
, abfd
, name
, &abfd
))
3587 return ecoff_link_add_object_symbols (abfd
, info
);
3590 /* Add the symbols from an archive file to the global hash table.
3591 This looks through the undefined symbols, looks each one up in the
3592 archive hash table, and adds any associated object file. We do not
3593 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3594 already have a hash table, so there is no reason to construct
3598 ecoff_link_add_archive_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3600 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3601 const bfd_byte
*raw_armap
;
3602 struct bfd_link_hash_entry
**pundef
;
3603 unsigned int armap_count
;
3604 unsigned int armap_log
;
3606 const bfd_byte
*hashtable
;
3607 const char *stringbase
;
3609 if (! bfd_has_map (abfd
))
3611 /* An empty archive is a special case. */
3612 if (bfd_openr_next_archived_file (abfd
, NULL
) == NULL
)
3614 bfd_set_error (bfd_error_no_armap
);
3618 /* If we don't have any raw data for this archive, as can happen on
3619 Irix 4.0.5F, we call the generic routine.
3620 FIXME: We should be more clever about this, since someday tdata
3621 may get to something for a generic archive. */
3622 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3623 if (raw_armap
== NULL
)
3624 return (_bfd_generic_link_add_archive_symbols
3625 (abfd
, info
, ecoff_link_check_archive_element
));
3627 armap_count
= H_GET_32 (abfd
, raw_armap
);
3630 for (i
= 1; i
< armap_count
; i
<<= 1)
3632 BFD_ASSERT (i
== armap_count
);
3634 hashtable
= raw_armap
+ 4;
3635 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3637 /* Look through the list of undefined symbols. */
3638 pundef
= &info
->hash
->undefs
;
3639 while (*pundef
!= NULL
)
3641 struct bfd_link_hash_entry
*h
;
3642 unsigned int hash
, rehash
= 0;
3643 unsigned int file_offset
;
3649 /* When a symbol is defined, it is not necessarily removed from
3651 if (h
->type
!= bfd_link_hash_undefined
3652 && h
->type
!= bfd_link_hash_common
)
3654 /* Remove this entry from the list, for general cleanliness
3655 and because we are going to look through the list again
3656 if we search any more libraries. We can't remove the
3657 entry if it is the tail, because that would lose any
3658 entries we add to the list later on. */
3659 if (*pundef
!= info
->hash
->undefs_tail
)
3660 *pundef
= (*pundef
)->u
.undef
.next
;
3662 pundef
= &(*pundef
)->u
.undef
.next
;
3666 /* Native ECOFF linkers do not pull in archive elements merely
3667 to satisfy common definitions, so neither do we. We leave
3668 them on the list, though, in case we are linking against some
3669 other object format. */
3670 if (h
->type
!= bfd_link_hash_undefined
)
3672 pundef
= &(*pundef
)->u
.undef
.next
;
3676 /* Look for this symbol in the archive hash table. */
3677 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3680 file_offset
= H_GET_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3681 if (file_offset
== 0)
3683 /* Nothing in this slot. */
3684 pundef
= &(*pundef
)->u
.undef
.next
;
3688 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (hash
* 8));
3689 if (name
[0] != h
->root
.string
[0]
3690 || ! streq (name
, h
->root
.string
))
3695 /* That was the wrong symbol. Try rehashing. */
3697 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3699 srch
= (srch
+ rehash
) & (armap_count
- 1))
3701 file_offset
= H_GET_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3702 if (file_offset
== 0)
3704 name
= stringbase
+ H_GET_32 (abfd
, hashtable
+ (srch
* 8));
3705 if (name
[0] == h
->root
.string
[0]
3706 && streq (name
, h
->root
.string
))
3715 pundef
= &(*pundef
)->u
.undef
.next
;
3722 element
= (*backend
->get_elt_at_filepos
) (abfd
,
3723 (file_ptr
) file_offset
,
3725 if (element
== NULL
)
3728 if (! bfd_check_format (element
, bfd_object
))
3731 /* Unlike the generic linker, we know that this element provides
3732 a definition for an undefined symbol and we know that we want
3733 to include it. We don't need to check anything. */
3734 if (!(*info
->callbacks
3735 ->add_archive_element
) (info
, element
, name
, &element
))
3737 if (! ecoff_link_add_object_symbols (element
, info
))
3740 pundef
= &(*pundef
)->u
.undef
.next
;
3746 /* Given an ECOFF BFD, add symbols to the global hash table as
3750 _bfd_ecoff_bfd_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3752 switch (bfd_get_format (abfd
))
3755 return ecoff_link_add_object_symbols (abfd
, info
);
3757 return ecoff_link_add_archive_symbols (abfd
, info
);
3759 bfd_set_error (bfd_error_wrong_format
);
3765 /* ECOFF final link routines. */
3767 /* Structure used to pass information to ecoff_link_write_external. */
3772 struct bfd_link_info
*info
;
3775 /* Accumulate the debugging information for an input BFD into the
3776 output BFD. This must read in the symbolic information of the
3780 ecoff_final_link_debug_accumulate (bfd
*output_bfd
,
3782 struct bfd_link_info
*info
,
3785 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
3786 const struct ecoff_debug_swap
* const swap
=
3787 &ecoff_backend (input_bfd
)->debug_swap
;
3788 HDRR
*symhdr
= &debug
->symbolic_header
;
3791 #define READ(ptr, offset, count, size) \
3795 debug->ptr = NULL; \
3796 if (symhdr->count == 0) \
3798 if (_bfd_mul_overflow (size, symhdr->count, &amt)) \
3800 bfd_set_error (bfd_error_file_too_big); \
3802 goto return_something; \
3804 if (bfd_seek (input_bfd, symhdr->offset, SEEK_SET) != 0) \
3807 goto return_something; \
3809 debug->ptr = _bfd_malloc_and_read (input_bfd, amt + 1, amt); \
3810 if (debug->ptr == NULL) \
3813 goto return_something; \
3815 ((char *) debug->ptr)[amt] = 0; \
3818 /* If alloc_syments is true, then the data was already by read by
3819 _bfd_ecoff_slurp_symbolic_info. */
3820 if (!debug
->alloc_syments
)
3822 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char));
3823 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
);
3824 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
);
3825 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
);
3826 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
);
3827 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
3828 READ (ss
, cbSsOffset
, issMax
, sizeof (char));
3829 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
);
3830 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
);
3834 /* We do not read the external strings or the external symbols. */
3836 ret
= (bfd_ecoff_debug_accumulate
3837 (handle
, output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
3838 &ecoff_backend (output_bfd
)->debug_swap
,
3839 input_bfd
, debug
, swap
, info
));
3842 _bfd_ecoff_free_ecoff_debug_info (debug
);
3846 /* Relocate and write an ECOFF section into an ECOFF output file. */
3849 ecoff_indirect_link_order (bfd
*output_bfd
,
3850 struct bfd_link_info
*info
,
3851 asection
*output_section
,
3852 struct bfd_link_order
*link_order
)
3854 asection
*input_section
;
3856 bfd_byte
*contents
= NULL
;
3857 bfd_size_type external_reloc_size
;
3858 bfd_size_type external_relocs_size
;
3859 void * external_relocs
= NULL
;
3861 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
3863 input_section
= link_order
->u
.indirect
.section
;
3864 input_bfd
= input_section
->owner
;
3865 if (input_section
->size
== 0)
3868 BFD_ASSERT (input_section
->output_section
== output_section
);
3869 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
3870 BFD_ASSERT (input_section
->size
== link_order
->size
);
3872 /* Get the section contents. */
3873 if (!bfd_malloc_and_get_section (input_bfd
, input_section
, &contents
))
3876 /* Get the relocs. If we are relaxing MIPS code, they will already
3877 have been read in. Otherwise, we read them in now. */
3878 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
3879 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
3881 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0)
3883 external_relocs
= _bfd_malloc_and_read (input_bfd
, external_relocs_size
,
3884 external_relocs_size
);
3885 if (external_relocs
== NULL
&& external_relocs_size
!= 0)
3888 /* Relocate the section contents. */
3889 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
3890 (output_bfd
, info
, input_bfd
, input_section
, contents
,
3894 /* Write out the relocated section. */
3895 if (! bfd_set_section_contents (output_bfd
,
3898 input_section
->output_offset
,
3899 input_section
->size
))
3902 /* If we are producing relocatable output, the relocs were
3903 modified, and we write them out now. We use the reloc_count
3904 field of output_section to keep track of the number of relocs we
3905 have output so far. */
3906 if (bfd_link_relocatable (info
))
3908 file_ptr pos
= (output_section
->rel_filepos
3909 + output_section
->reloc_count
* external_reloc_size
);
3910 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
3911 || (bfd_write (external_relocs
, external_relocs_size
, output_bfd
)
3912 != external_relocs_size
))
3914 output_section
->reloc_count
+= input_section
->reloc_count
;
3918 free (external_relocs
);
3923 free (external_relocs
);
3927 /* Generate a reloc when linking an ECOFF file. This is a reloc
3928 requested by the linker, and does come from any input file. This
3929 is used to build constructor and destructor tables when linking
3933 ecoff_reloc_link_order (bfd
*output_bfd
,
3934 struct bfd_link_info
*info
,
3935 asection
*output_section
,
3936 struct bfd_link_order
*link_order
)
3938 enum bfd_link_order_type type
;
3942 struct internal_reloc in
;
3943 bfd_size_type external_reloc_size
;
3948 type
= link_order
->type
;
3950 addend
= link_order
->u
.reloc
.p
->addend
;
3952 /* We set up an arelent to pass to the backend adjust_reloc_out
3954 rel
.address
= link_order
->offset
;
3956 rel
.howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
3959 bfd_set_error (bfd_error_bad_value
);
3963 if (type
== bfd_section_reloc_link_order
)
3965 section
= link_order
->u
.reloc
.p
->u
.section
;
3966 rel
.sym_ptr_ptr
= §ion
->symbol
;
3970 struct bfd_link_hash_entry
*h
;
3972 /* Treat a reloc against a defined symbol as though it were
3973 actually against the section. */
3974 h
= bfd_wrapped_link_hash_lookup (output_bfd
, info
,
3975 link_order
->u
.reloc
.p
->u
.name
,
3976 false, false, false);
3978 && (h
->type
== bfd_link_hash_defined
3979 || h
->type
== bfd_link_hash_defweak
))
3981 type
= bfd_section_reloc_link_order
;
3982 section
= h
->u
.def
.section
->output_section
;
3983 /* It seems that we ought to add the symbol value to the
3984 addend here, but in practice it has already been added
3985 because it was passed to constructor_callback. */
3986 addend
+= section
->vma
+ h
->u
.def
.section
->output_offset
;
3990 /* We can't set up a reloc against a symbol correctly,
3991 because we have no asymbol structure. Currently no
3992 adjust_reloc_out routine cares. */
3993 rel
.sym_ptr_ptr
= NULL
;
3997 /* All ECOFF relocs are in-place. Put the addend into the object
4000 BFD_ASSERT (rel
.howto
->partial_inplace
);
4004 bfd_reloc_status_type rstat
;
4007 size
= bfd_get_reloc_size (rel
.howto
);
4008 buf
= (bfd_byte
*) bfd_zmalloc (size
);
4009 if (buf
== NULL
&& size
!= 0)
4011 rstat
= _bfd_relocate_contents (rel
.howto
, output_bfd
,
4012 (bfd_vma
) addend
, buf
);
4018 case bfd_reloc_outofrange
:
4020 case bfd_reloc_overflow
:
4021 (*info
->callbacks
->reloc_overflow
)
4023 (link_order
->type
== bfd_section_reloc_link_order
4024 ? bfd_section_name (section
)
4025 : link_order
->u
.reloc
.p
->u
.name
),
4026 rel
.howto
->name
, addend
, NULL
, NULL
, (bfd_vma
) 0);
4029 ok
= bfd_set_section_contents (output_bfd
, output_section
, (void *) buf
,
4030 (file_ptr
) link_order
->offset
, size
);
4038 /* Move the information into an internal_reloc structure. */
4039 in
.r_vaddr
= rel
.address
+ bfd_section_vma (output_section
);
4040 in
.r_type
= rel
.howto
->type
;
4042 if (type
== bfd_symbol_reloc_link_order
)
4044 struct ecoff_link_hash_entry
*h
;
4046 h
= ((struct ecoff_link_hash_entry
*)
4047 bfd_wrapped_link_hash_lookup (output_bfd
, info
,
4048 link_order
->u
.reloc
.p
->u
.name
,
4049 false, false, true));
4052 in
.r_symndx
= h
->indx
;
4055 (*info
->callbacks
->unattached_reloc
)
4056 (info
, link_order
->u
.reloc
.p
->u
.name
, NULL
, NULL
, (bfd_vma
) 0);
4072 { _TEXT
, RELOC_SECTION_TEXT
},
4073 { _RDATA
, RELOC_SECTION_RDATA
},
4074 { _DATA
, RELOC_SECTION_DATA
},
4075 { _SDATA
, RELOC_SECTION_SDATA
},
4076 { _SBSS
, RELOC_SECTION_SBSS
},
4077 { _BSS
, RELOC_SECTION_BSS
},
4078 { _INIT
, RELOC_SECTION_INIT
},
4079 { _LIT8
, RELOC_SECTION_LIT8
},
4080 { _LIT4
, RELOC_SECTION_LIT4
},
4081 { _XDATA
, RELOC_SECTION_XDATA
},
4082 { _PDATA
, RELOC_SECTION_PDATA
},
4083 { _FINI
, RELOC_SECTION_FINI
},
4084 { _LITA
, RELOC_SECTION_LITA
},
4085 { "*ABS*", RELOC_SECTION_ABS
},
4086 { _RCONST
, RELOC_SECTION_RCONST
}
4089 name
= bfd_section_name (section
);
4091 for (i
= 0; i
< ARRAY_SIZE (section_symndx
); i
++)
4092 if (streq (name
, section_symndx
[i
].name
))
4094 in
.r_symndx
= section_symndx
[i
].r_symndx
;
4098 if (i
== ARRAY_SIZE (section_symndx
))
4104 /* Let the BFD backend adjust the reloc. */
4105 (*ecoff_backend (output_bfd
)->adjust_reloc_out
) (output_bfd
, &rel
, &in
);
4107 /* Get some memory and swap out the reloc. */
4108 external_reloc_size
= ecoff_backend (output_bfd
)->external_reloc_size
;
4109 rbuf
= (bfd_byte
*) bfd_malloc (external_reloc_size
);
4113 (*ecoff_backend (output_bfd
)->swap_reloc_out
) (output_bfd
, &in
, (void *) rbuf
);
4115 pos
= (output_section
->rel_filepos
4116 + output_section
->reloc_count
* external_reloc_size
);
4117 ok
= (bfd_seek (output_bfd
, pos
, SEEK_SET
) == 0
4118 && (bfd_write (rbuf
, external_reloc_size
, output_bfd
)
4119 == external_reloc_size
));
4122 ++output_section
->reloc_count
;
4129 /* Put out information for an external symbol. These come only from
4133 ecoff_link_write_external (struct bfd_hash_entry
*bh
, void * data
)
4135 struct ecoff_link_hash_entry
*h
= (struct ecoff_link_hash_entry
*) bh
;
4136 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
4137 bfd
*output_bfd
= einfo
->abfd
;
4140 if (h
->root
.type
== bfd_link_hash_warning
)
4142 h
= (struct ecoff_link_hash_entry
*) h
->root
.u
.i
.link
;
4143 if (h
->root
.type
== bfd_link_hash_new
)
4147 /* We need to check if this symbol is being stripped. */
4148 if (h
->root
.type
== bfd_link_hash_undefined
4149 || h
->root
.type
== bfd_link_hash_undefweak
)
4151 else if (einfo
->info
->strip
== strip_all
4152 || (einfo
->info
->strip
== strip_some
4153 && bfd_hash_lookup (einfo
->info
->keep_hash
,
4154 h
->root
.root
.string
,
4155 false, false) == NULL
))
4160 if (strip
|| h
->written
)
4163 if (h
->abfd
== NULL
)
4166 h
->esym
.cobol_main
= 0;
4167 h
->esym
.weakext
= 0;
4168 h
->esym
.reserved
= 0;
4169 h
->esym
.ifd
= ifdNil
;
4170 h
->esym
.asym
.value
= 0;
4171 h
->esym
.asym
.st
= stGlobal
;
4173 if (h
->root
.type
!= bfd_link_hash_defined
4174 && h
->root
.type
!= bfd_link_hash_defweak
)
4175 h
->esym
.asym
.sc
= scAbs
;
4178 asection
*output_section
;
4186 section_storage_classes
[] =
4190 { _SDATA
, scSData
},
4191 { _RDATA
, scRData
},
4196 { _PDATA
, scPData
},
4197 { _XDATA
, scXData
},
4198 { _RCONST
, scRConst
}
4201 output_section
= h
->root
.u
.def
.section
->output_section
;
4202 name
= bfd_section_name (output_section
);
4204 for (i
= 0; i
< ARRAY_SIZE (section_storage_classes
); i
++)
4205 if (streq (name
, section_storage_classes
[i
].name
))
4207 h
->esym
.asym
.sc
= section_storage_classes
[i
].sc
;
4211 if (i
== ARRAY_SIZE (section_storage_classes
))
4212 h
->esym
.asym
.sc
= scAbs
;
4215 h
->esym
.asym
.reserved
= 0;
4216 h
->esym
.asym
.index
= indexNil
;
4218 else if (h
->esym
.ifd
!= -1)
4220 struct ecoff_debug_info
*debug
;
4222 /* Adjust the FDR index for the symbol by that used for the
4224 debug
= &ecoff_data (h
->abfd
)->debug_info
;
4225 BFD_ASSERT (h
->esym
.ifd
>= 0
4226 && h
->esym
.ifd
< debug
->symbolic_header
.ifdMax
);
4227 h
->esym
.ifd
= debug
->ifdmap
[h
->esym
.ifd
];
4230 switch (h
->root
.type
)
4233 case bfd_link_hash_warning
:
4234 case bfd_link_hash_new
:
4236 case bfd_link_hash_undefined
:
4237 case bfd_link_hash_undefweak
:
4238 if (h
->esym
.asym
.sc
!= scUndefined
4239 && h
->esym
.asym
.sc
!= scSUndefined
)
4240 h
->esym
.asym
.sc
= scUndefined
;
4242 case bfd_link_hash_defined
:
4243 case bfd_link_hash_defweak
:
4244 if (h
->esym
.asym
.sc
== scUndefined
4245 || h
->esym
.asym
.sc
== scSUndefined
)
4246 h
->esym
.asym
.sc
= scAbs
;
4247 else if (h
->esym
.asym
.sc
== scCommon
)
4248 h
->esym
.asym
.sc
= scBss
;
4249 else if (h
->esym
.asym
.sc
== scSCommon
)
4250 h
->esym
.asym
.sc
= scSBss
;
4251 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4252 + h
->root
.u
.def
.section
->output_section
->vma
4253 + h
->root
.u
.def
.section
->output_offset
);
4255 case bfd_link_hash_common
:
4256 if (h
->esym
.asym
.sc
!= scCommon
4257 && h
->esym
.asym
.sc
!= scSCommon
)
4258 h
->esym
.asym
.sc
= scCommon
;
4259 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4261 case bfd_link_hash_indirect
:
4262 /* We ignore these symbols, since the indirected symbol is
4263 already in the hash table. */
4267 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4269 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4272 return (bfd_ecoff_debug_one_external
4273 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4274 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4278 /* ECOFF final link routine. This looks through all the input BFDs
4279 and gathers together all the debugging information, and then
4280 processes all the link order information. This may cause it to
4281 close and reopen some input BFDs; I'll see how bad this is. */
4284 _bfd_ecoff_bfd_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
4286 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
4287 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
4292 struct bfd_link_order
*p
;
4293 struct extsym_info einfo
;
4295 /* We accumulate the debugging information counts in the symbolic
4297 symhdr
= &debug
->symbolic_header
;
4299 symhdr
->ilineMax
= 0;
4303 symhdr
->isymMax
= 0;
4304 symhdr
->ioptMax
= 0;
4305 symhdr
->iauxMax
= 0;
4307 symhdr
->issExtMax
= 0;
4310 symhdr
->iextMax
= 0;
4312 /* We accumulate the debugging information itself in the debug_info
4315 debug
->external_dnr
= NULL
;
4316 debug
->external_pdr
= NULL
;
4317 debug
->external_sym
= NULL
;
4318 debug
->external_opt
= NULL
;
4319 debug
->external_aux
= NULL
;
4321 debug
->ssext
= debug
->ssext_end
= NULL
;
4322 debug
->external_fdr
= NULL
;
4323 debug
->external_rfd
= NULL
;
4324 debug
->external_ext
= debug
->external_ext_end
= NULL
;
4326 handle
= bfd_ecoff_debug_init (abfd
, debug
, &backend
->debug_swap
, info
);
4330 /* Accumulate the debugging symbols from each input BFD. */
4331 for (input_bfd
= info
->input_bfds
;
4333 input_bfd
= input_bfd
->link
.next
)
4337 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
4339 /* Arbitrarily set the symbolic header vstamp to the vstamp
4340 of the first object file in the link. */
4341 if (symhdr
->vstamp
== 0)
4343 = ecoff_data (input_bfd
)->debug_info
.symbolic_header
.vstamp
;
4344 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
,
4348 ret
= bfd_ecoff_debug_accumulate_other (handle
, abfd
,
4349 debug
, &backend
->debug_swap
,
4354 /* Combine the register masks. */
4355 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
4356 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
4357 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
4358 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
4359 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
4360 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
4363 /* Write out the external symbols. */
4366 bfd_hash_traverse (&info
->hash
->table
, ecoff_link_write_external
, &einfo
);
4368 if (bfd_link_relocatable (info
))
4370 /* We need to make a pass over the link_orders to count up the
4371 number of relocations we will need to output, so that we know
4372 how much space they will take up. */
4373 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4376 for (p
= o
->map_head
.link_order
;
4379 if (p
->type
== bfd_indirect_link_order
)
4380 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
4381 else if (p
->type
== bfd_section_reloc_link_order
4382 || p
->type
== bfd_symbol_reloc_link_order
)
4387 /* Compute the reloc and symbol file positions. */
4388 ecoff_compute_reloc_file_positions (abfd
);
4390 /* Write out the debugging information. */
4391 if (! bfd_ecoff_write_accumulated_debug (handle
, abfd
, debug
,
4392 &backend
->debug_swap
, info
,
4393 ecoff_data (abfd
)->sym_filepos
))
4396 bfd_ecoff_debug_free (handle
, abfd
, debug
, &backend
->debug_swap
, info
);
4398 if (bfd_link_relocatable (info
))
4400 /* Now reset the reloc_count field of the sections in the output
4401 BFD to 0, so that we can use them to keep track of how many
4402 relocs we have output thus far. */
4403 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4407 /* Get a value for the GP register. */
4408 if (ecoff_data (abfd
)->gp
== 0)
4410 struct bfd_link_hash_entry
*h
;
4412 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
4414 && h
->type
== bfd_link_hash_defined
)
4415 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
4416 + h
->u
.def
.section
->output_section
->vma
4417 + h
->u
.def
.section
->output_offset
);
4418 else if (bfd_link_relocatable (info
))
4422 /* Make up a value. */
4424 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4427 && (streq (o
->name
, _SBSS
)
4428 || streq (o
->name
, _SDATA
)
4429 || streq (o
->name
, _LIT4
)
4430 || streq (o
->name
, _LIT8
)
4431 || streq (o
->name
, _LITA
)))
4434 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
4438 /* If the relocate_section function needs to do a reloc
4439 involving the GP value, it should make a reloc_dangerous
4440 callback to warn that GP is not defined. */
4444 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4446 for (p
= o
->map_head
.link_order
;
4450 if (p
->type
== bfd_indirect_link_order
4451 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4452 == bfd_target_ecoff_flavour
))
4454 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4457 else if (p
->type
== bfd_section_reloc_link_order
4458 || p
->type
== bfd_symbol_reloc_link_order
)
4460 if (! ecoff_reloc_link_order (abfd
, info
, o
, p
))
4465 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4471 abfd
->symcount
= symhdr
->iextMax
+ symhdr
->isymMax
;
4473 ecoff_data (abfd
)->linker
= true;