1 /* Generic ECOFF (Extended-COFF) routines.
2 Copyright 1990, 1991, 1992, 1993 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 2 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "aout/ranlib.h"
29 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
30 some other stuff which we don't want and which conflicts with stuff
33 #include "aout/aout64.h"
36 #undef obj_sym_filepos
38 #include "coff/internal.h"
40 #include "coff/symconst.h"
41 #include "coff/ecoff.h"
45 /* Prototypes for static functions. */
47 static int ecoff_get_magic
PARAMS ((bfd
*abfd
));
48 static boolean ecoff_slurp_symbolic_header
PARAMS ((bfd
*abfd
));
49 static void ecoff_set_symbol_info
PARAMS ((bfd
*abfd
, SYMR
*ecoff_sym
,
50 asymbol
*asym
, int ext
,
51 asymbol
**indirect_ptr_ptr
));
52 static void ecoff_emit_aggregate
PARAMS ((bfd
*abfd
, char *string
,
53 RNDXR
*rndx
, long isym
,
55 static char *ecoff_type_to_string
PARAMS ((bfd
*abfd
, union aux_ext
*aux_ptr
,
56 unsigned int indx
, int bigendian
));
57 static boolean ecoff_slurp_reloc_table
PARAMS ((bfd
*abfd
, asection
*section
,
59 static void ecoff_compute_section_file_positions
PARAMS ((bfd
*abfd
));
60 static bfd_size_type ecoff_compute_reloc_file_positions
PARAMS ((bfd
*abfd
));
61 static boolean ecoff_get_extr
PARAMS ((asymbol
*, EXTR
*));
62 static void ecoff_set_index
PARAMS ((asymbol
*, bfd_size_type
));
63 static unsigned int ecoff_armap_hash
PARAMS ((CONST
char *s
,
68 /* This stuff is somewhat copied from coffcode.h. */
70 static asection bfd_debug_section
= { "*DEBUG*" };
72 /* Create an ECOFF object. */
78 abfd
->tdata
.ecoff_obj_data
= ((struct ecoff_tdata
*)
79 bfd_zalloc (abfd
, sizeof (ecoff_data_type
)));
80 if (abfd
->tdata
.ecoff_obj_data
== NULL
)
82 bfd_error
= no_memory
;
89 /* This is a hook called by coff_real_object_p to create any backend
90 specific information. */
93 ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
98 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
99 struct internal_aouthdr
*internal_a
= (struct internal_aouthdr
*) aouthdr
;
100 ecoff_data_type
*ecoff
;
103 if (ecoff_mkobject (abfd
) == false)
106 ecoff
= ecoff_data (abfd
);
108 ecoff
->sym_filepos
= internal_f
->f_symptr
;
110 /* Create the .reginfo section to give programs outside BFD a way to
111 see the information stored in the a.out header. See the comment
113 regsec
= bfd_make_section (abfd
, REGINFO
);
117 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
121 ecoff
->text_start
= internal_a
->text_start
;
122 ecoff
->text_end
= internal_a
->text_start
+ internal_a
->tsize
;
123 ecoff
->gp
= internal_a
->gp_value
;
124 ecoff
->gprmask
= internal_a
->gprmask
;
125 for (i
= 0; i
< 4; i
++)
126 ecoff
->cprmask
[i
] = internal_a
->cprmask
[i
];
127 ecoff
->fprmask
= internal_a
->fprmask
;
128 if (internal_a
->magic
== ECOFF_AOUT_ZMAGIC
)
129 abfd
->flags
|= D_PAGED
;
132 /* It turns out that no special action is required by the MIPS or
133 Alpha ECOFF backends. They have different information in the
134 a.out header, but we just copy it all (e.g., gprmask, cprmask and
135 fprmask) and let the swapping routines ensure that only relevant
136 information is written out. */
141 /* This is a hook needed by SCO COFF, but we have nothing to do. */
145 ecoff_make_section_hook (abfd
, name
)
149 return (asection
*) NULL
;
152 /* Initialize a new section. */
155 ecoff_new_section_hook (abfd
, section
)
159 section
->alignment_power
= abfd
->xvec
->align_power_min
;
161 if (strcmp (section
->name
, _TEXT
) == 0)
162 section
->flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
163 else if (strcmp (section
->name
, _DATA
) == 0
164 || strcmp (section
->name
, _SDATA
) == 0)
165 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
166 else if (strcmp (section
->name
, _RDATA
) == 0
167 || strcmp (section
->name
, _LIT8
) == 0
168 || strcmp (section
->name
, _LIT4
) == 0)
169 section
->flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
170 else if (strcmp (section
->name
, _BSS
) == 0
171 || strcmp (section
->name
, _SBSS
) == 0)
172 section
->flags
|= SEC_ALLOC
;
173 else if (strcmp (section
->name
, REGINFO
) == 0)
175 /* Setting SEC_SHARED_LIBRARY should make the linker leave the
176 section completely alone. */
177 section
->flags
|= (SEC_SHARED_LIBRARY
180 section
->_raw_size
= sizeof (struct ecoff_reginfo
);
183 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
184 uncertain about .init on some systems and I don't know how shared
190 /* Determine the machine architecture and type. This is called from
191 the generic COFF routines. It is the inverse of ecoff_get_magic,
192 below. This could be an ECOFF backend routine, with one version
193 for each target, but there aren't all that many ECOFF targets. */
196 ecoff_set_arch_mach_hook (abfd
, filehdr
)
200 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
201 enum bfd_architecture arch
;
204 switch (internal_f
->f_magic
)
207 case MIPS_MAGIC_LITTLE
:
209 arch
= bfd_arch_mips
;
213 case MIPS_MAGIC_LITTLE2
:
214 case MIPS_MAGIC_BIG2
:
215 /* MIPS ISA level 2: the r6000 */
216 arch
= bfd_arch_mips
;
220 case MIPS_MAGIC_LITTLE3
:
221 case MIPS_MAGIC_BIG3
:
222 /* MIPS ISA level 3: the r4000 */
223 arch
= bfd_arch_mips
;
228 arch
= bfd_arch_alpha
;
233 arch
= bfd_arch_obscure
;
238 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
241 /* Get the magic number to use based on the architecture and machine.
242 This is the inverse of ecoff_set_arch_mach_hook, above. */
245 ecoff_get_magic (abfd
)
250 switch (bfd_get_arch (abfd
))
253 switch (bfd_get_mach (abfd
))
258 big
= MIPS_MAGIC_BIG
;
259 little
= MIPS_MAGIC_LITTLE
;
263 big
= MIPS_MAGIC_BIG2
;
264 little
= MIPS_MAGIC_LITTLE2
;
268 big
= MIPS_MAGIC_BIG3
;
269 little
= MIPS_MAGIC_LITTLE3
;
273 return abfd
->xvec
->byteorder_big_p
? big
: little
;
284 /* Get the section s_flags to use for a section. */
287 ecoff_sec_to_styp_flags (name
, flags
)
295 if (strcmp (name
, _TEXT
) == 0)
297 else if (strcmp (name
, _DATA
) == 0)
299 else if (strcmp (name
, _SDATA
) == 0)
301 else if (strcmp (name
, _RDATA
) == 0)
303 else if (strcmp (name
, _LITA
) == 0)
305 else if (strcmp (name
, _LIT8
) == 0)
307 else if (strcmp (name
, _LIT4
) == 0)
309 else if (strcmp (name
, _BSS
) == 0)
311 else if (strcmp (name
, _SBSS
) == 0)
313 else if (strcmp (name
, _INIT
) == 0)
314 styp
= STYP_ECOFF_INIT
;
315 else if (strcmp (name
, _FINI
) == 0)
316 styp
= STYP_ECOFF_FINI
;
317 else if (strcmp (name
, _PDATA
) == 0)
319 else if (strcmp (name
, _XDATA
) == 0)
321 else if (flags
& SEC_CODE
)
323 else if (flags
& SEC_DATA
)
325 else if (flags
& SEC_READONLY
)
327 else if (flags
& SEC_LOAD
)
332 if (flags
& SEC_NEVER_LOAD
)
338 /* Get the BFD flags to use for a section. */
342 ecoff_styp_to_sec_flags (abfd
, hdr
)
346 struct internal_scnhdr
*internal_s
= (struct internal_scnhdr
*) hdr
;
347 long styp_flags
= internal_s
->s_flags
;
348 flagword sec_flags
=0;
350 if (styp_flags
& STYP_NOLOAD
)
351 sec_flags
|= SEC_NEVER_LOAD
;
353 /* For 386 COFF, at least, an unloadable text or data section is
354 actually a shared library section. */
355 if ((styp_flags
& STYP_TEXT
)
356 || (styp_flags
& STYP_ECOFF_INIT
)
357 || (styp_flags
& STYP_ECOFF_FINI
))
359 if (sec_flags
& SEC_NEVER_LOAD
)
360 sec_flags
|= SEC_CODE
| SEC_SHARED_LIBRARY
;
362 sec_flags
|= SEC_CODE
| SEC_LOAD
| SEC_ALLOC
;
364 else if ((styp_flags
& STYP_DATA
)
365 || (styp_flags
& STYP_RDATA
)
366 || (styp_flags
& STYP_SDATA
))
368 if (sec_flags
& SEC_NEVER_LOAD
)
369 sec_flags
|= SEC_DATA
| SEC_SHARED_LIBRARY
;
371 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
;
372 if (styp_flags
& STYP_RDATA
)
373 sec_flags
|= SEC_READONLY
;
375 else if ((styp_flags
& STYP_BSS
)
376 || (styp_flags
& STYP_SBSS
))
378 sec_flags
|= SEC_ALLOC
;
380 else if (styp_flags
& STYP_INFO
)
382 sec_flags
|= SEC_NEVER_LOAD
;
384 else if ((styp_flags
& STYP_LITA
)
385 || (styp_flags
& STYP_LIT8
)
386 || (styp_flags
& STYP_LIT4
))
388 sec_flags
|= SEC_DATA
| SEC_LOAD
| SEC_ALLOC
| SEC_READONLY
;
392 sec_flags
|= SEC_ALLOC
| SEC_LOAD
;
398 /* Routines to swap auxiliary information in and out. I am assuming
399 that the auxiliary information format is always going to be target
402 /* Swap in a type information record.
403 BIGEND says whether AUX symbols are big-endian or little-endian; this
404 info comes from the file header record (fh-fBigendian). */
407 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
409 struct tir_ext
*ext_copy
;
412 struct tir_ext ext
[1];
414 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
416 /* now the fun stuff... */
418 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
419 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
420 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
421 >> TIR_BITS1_BT_SH_BIG
;
422 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
423 >> TIR_BITS_TQ4_SH_BIG
;
424 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
425 >> TIR_BITS_TQ5_SH_BIG
;
426 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
427 >> TIR_BITS_TQ0_SH_BIG
;
428 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
429 >> TIR_BITS_TQ1_SH_BIG
;
430 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
431 >> TIR_BITS_TQ2_SH_BIG
;
432 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
433 >> TIR_BITS_TQ3_SH_BIG
;
435 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
436 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
437 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
438 >> TIR_BITS1_BT_SH_LITTLE
;
439 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
440 >> TIR_BITS_TQ4_SH_LITTLE
;
441 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
442 >> TIR_BITS_TQ5_SH_LITTLE
;
443 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
444 >> TIR_BITS_TQ0_SH_LITTLE
;
445 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
446 >> TIR_BITS_TQ1_SH_LITTLE
;
447 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
448 >> TIR_BITS_TQ2_SH_LITTLE
;
449 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
450 >> TIR_BITS_TQ3_SH_LITTLE
;
454 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
459 /* Swap out a type information record.
460 BIGEND says whether AUX symbols are big-endian or little-endian; this
461 info comes from the file header record (fh-fBigendian). */
464 ecoff_swap_tir_out (bigend
, intern_copy
, ext
)
471 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
473 /* now the fun stuff... */
475 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_BIG
: 0)
476 | (intern
->continued
? TIR_BITS1_CONTINUED_BIG
: 0)
477 | ((intern
->bt
<< TIR_BITS1_BT_SH_BIG
)
478 & TIR_BITS1_BT_BIG
));
479 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_BIG
)
481 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_BIG
)
482 & TIR_BITS_TQ5_BIG
));
483 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_BIG
)
485 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_BIG
)
486 & TIR_BITS_TQ1_BIG
));
487 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_BIG
)
489 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_BIG
)
490 & TIR_BITS_TQ3_BIG
));
492 ext
->t_bits1
[0] = ((intern
->fBitfield
? TIR_BITS1_FBITFIELD_LITTLE
: 0)
493 | (intern
->continued
? TIR_BITS1_CONTINUED_LITTLE
: 0)
494 | ((intern
->bt
<< TIR_BITS1_BT_SH_LITTLE
)
495 & TIR_BITS1_BT_LITTLE
));
496 ext
->t_tq45
[0] = (((intern
->tq4
<< TIR_BITS_TQ4_SH_LITTLE
)
497 & TIR_BITS_TQ4_LITTLE
)
498 | ((intern
->tq5
<< TIR_BITS_TQ5_SH_LITTLE
)
499 & TIR_BITS_TQ5_LITTLE
));
500 ext
->t_tq01
[0] = (((intern
->tq0
<< TIR_BITS_TQ0_SH_LITTLE
)
501 & TIR_BITS_TQ0_LITTLE
)
502 | ((intern
->tq1
<< TIR_BITS_TQ1_SH_LITTLE
)
503 & TIR_BITS_TQ1_LITTLE
));
504 ext
->t_tq23
[0] = (((intern
->tq2
<< TIR_BITS_TQ2_SH_LITTLE
)
505 & TIR_BITS_TQ2_LITTLE
)
506 | ((intern
->tq3
<< TIR_BITS_TQ3_SH_LITTLE
)
507 & TIR_BITS_TQ3_LITTLE
));
511 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
516 /* Swap in a relative symbol record. BIGEND says whether it is in
517 big-endian or little-endian format.*/
520 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
522 struct rndx_ext
*ext_copy
;
525 struct rndx_ext ext
[1];
527 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
529 /* now the fun stuff... */
531 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
532 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
533 >> RNDX_BITS1_RFD_SH_BIG
);
534 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
535 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
536 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
537 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
539 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
540 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
541 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
542 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
543 >> RNDX_BITS1_INDEX_SH_LITTLE
)
544 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
545 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
549 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
554 /* Swap out a relative symbol record. BIGEND says whether it is in
555 big-endian or little-endian format.*/
558 ecoff_swap_rndx_out (bigend
, intern_copy
, ext
)
561 struct rndx_ext
*ext
;
565 *intern
= *intern_copy
; /* Make it reasonable to do in-place. */
567 /* now the fun stuff... */
569 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_BIG
;
570 ext
->r_bits
[1] = (((intern
->rfd
<< RNDX_BITS1_RFD_SH_BIG
)
571 & RNDX_BITS1_RFD_BIG
)
572 | ((intern
->index
>> RNDX_BITS1_INDEX_SH_LEFT_BIG
)
573 & RNDX_BITS1_INDEX_BIG
));
574 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_BIG
;
575 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_BIG
;
577 ext
->r_bits
[0] = intern
->rfd
>> RNDX_BITS0_RFD_SH_LEFT_LITTLE
;
578 ext
->r_bits
[1] = (((intern
->rfd
>> RNDX_BITS1_RFD_SH_LEFT_LITTLE
)
579 & RNDX_BITS1_RFD_LITTLE
)
580 | ((intern
->index
<< RNDX_BITS1_INDEX_SH_LITTLE
)
581 & RNDX_BITS1_INDEX_LITTLE
));
582 ext
->r_bits
[2] = intern
->index
>> RNDX_BITS2_INDEX_SH_LEFT_LITTLE
;
583 ext
->r_bits
[3] = intern
->index
>> RNDX_BITS3_INDEX_SH_LEFT_LITTLE
;
587 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
592 /* Read in the symbolic header for an ECOFF object file. */
595 ecoff_slurp_symbolic_header (abfd
)
598 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
599 bfd_size_type external_hdr_size
;
601 HDRR
*internal_symhdr
;
603 /* See if we've already read it in. */
604 if (ecoff_data (abfd
)->debug_info
.symbolic_header
.magic
==
605 backend
->debug_swap
.sym_magic
)
608 /* See whether there is a symbolic header. */
609 if (ecoff_data (abfd
)->sym_filepos
== 0)
611 bfd_get_symcount (abfd
) = 0;
615 /* At this point bfd_get_symcount (abfd) holds the number of symbols
616 as read from the file header, but on ECOFF this is always the
617 size of the symbolic information header. It would be cleaner to
618 handle this when we first read the file in coffgen.c. */
619 external_hdr_size
= backend
->debug_swap
.external_hdr_size
;
620 if (bfd_get_symcount (abfd
) != external_hdr_size
)
622 bfd_error
= bad_value
;
626 /* Read the symbolic information header. */
627 raw
= (PTR
) alloca ((size_t) external_hdr_size
);
628 if (bfd_seek (abfd
, ecoff_data (abfd
)->sym_filepos
, SEEK_SET
) == -1
629 || (bfd_read (raw
, external_hdr_size
, 1, abfd
)
630 != external_hdr_size
))
632 bfd_error
= system_call_error
;
635 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
636 (*backend
->debug_swap
.swap_hdr_in
) (abfd
, raw
, internal_symhdr
);
638 if (internal_symhdr
->magic
!= backend
->debug_swap
.sym_magic
)
640 bfd_error
= bad_value
;
644 /* Now we can get the correct number of symbols. */
645 bfd_get_symcount (abfd
) = (internal_symhdr
->isymMax
646 + internal_symhdr
->iextMax
);
651 /* Read in and swap the important symbolic information for an ECOFF
652 object file. This is called by gdb. */
655 ecoff_slurp_symbolic_info (abfd
)
658 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
659 HDRR
*internal_symhdr
;
660 bfd_size_type raw_base
;
661 bfd_size_type raw_size
;
663 bfd_size_type external_fdr_size
;
667 bfd_size_type raw_end
;
668 bfd_size_type cb_end
;
670 /* Check whether we've already gotten it, and whether there's any to
672 if (ecoff_data (abfd
)->raw_syments
!= (PTR
) NULL
)
674 if (ecoff_data (abfd
)->sym_filepos
== 0)
676 bfd_get_symcount (abfd
) = 0;
680 if (! ecoff_slurp_symbolic_header (abfd
))
683 internal_symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
685 /* Read all the symbolic information at once. */
686 raw_base
= (ecoff_data (abfd
)->sym_filepos
687 + backend
->debug_swap
.external_hdr_size
);
689 /* Alpha ecoff makes the determination of raw_size difficult. It has
690 an undocumented debug data section between the symhdr and the first
691 documented section. And the ordering of the sections varies between
692 statically and dynamically linked executables.
693 If bfd supports SEEK_END someday, this code could be simplified. */
697 #define UPDATE_RAW_END(start, count, size) \
698 cb_end = internal_symhdr->start + internal_symhdr->count * (size); \
699 if (cb_end > raw_end) \
702 UPDATE_RAW_END (cbLineOffset
, cbLine
, sizeof (unsigned char));
703 UPDATE_RAW_END (cbDnOffset
, idnMax
, backend
->debug_swap
.external_dnr_size
);
704 UPDATE_RAW_END (cbPdOffset
, ipdMax
, backend
->debug_swap
.external_pdr_size
);
705 UPDATE_RAW_END (cbSymOffset
, isymMax
, backend
->debug_swap
.external_sym_size
);
706 UPDATE_RAW_END (cbOptOffset
, ioptMax
, backend
->debug_swap
.external_opt_size
);
707 UPDATE_RAW_END (cbAuxOffset
, iauxMax
, sizeof (union aux_ext
));
708 UPDATE_RAW_END (cbSsOffset
, issMax
, sizeof (char));
709 UPDATE_RAW_END (cbSsExtOffset
, issExtMax
, sizeof (char));
710 UPDATE_RAW_END (cbFdOffset
, ifdMax
, backend
->debug_swap
.external_fdr_size
);
711 UPDATE_RAW_END (cbRfdOffset
, crfd
, backend
->debug_swap
.external_rfd_size
);
712 UPDATE_RAW_END (cbExtOffset
, iextMax
, backend
->debug_swap
.external_ext_size
);
714 #undef UPDATE_RAW_END
716 raw_size
= raw_end
- raw_base
;
719 ecoff_data (abfd
)->sym_filepos
= 0;
722 raw
= (PTR
) bfd_alloc (abfd
, raw_size
);
725 bfd_error
= no_memory
;
729 (ecoff_data (abfd
)->sym_filepos
730 + backend
->debug_swap
.external_hdr_size
),
732 || bfd_read (raw
, raw_size
, 1, abfd
) != raw_size
)
734 bfd_error
= system_call_error
;
735 bfd_release (abfd
, raw
);
739 ecoff_data (abfd
)->raw_syments
= raw
;
741 /* Get pointers for the numeric offsets in the HDRR structure. */
742 #define FIX(off1, off2, type) \
743 if (internal_symhdr->off1 == 0) \
744 ecoff_data (abfd)->debug_info.off2 = (type) NULL; \
746 ecoff_data (abfd)->debug_info.off2 = (type) ((char *) raw \
747 + internal_symhdr->off1 \
749 FIX (cbLineOffset
, line
, unsigned char *);
750 FIX (cbDnOffset
, external_dnr
, PTR
);
751 FIX (cbPdOffset
, external_pdr
, PTR
);
752 FIX (cbSymOffset
, external_sym
, PTR
);
753 FIX (cbOptOffset
, external_opt
, PTR
);
754 FIX (cbAuxOffset
, external_aux
, union aux_ext
*);
755 FIX (cbSsOffset
, ss
, char *);
756 FIX (cbSsExtOffset
, ssext
, char *);
757 FIX (cbFdOffset
, external_fdr
, PTR
);
758 FIX (cbRfdOffset
, external_rfd
, PTR
);
759 FIX (cbExtOffset
, external_ext
, PTR
);
762 /* I don't want to always swap all the data, because it will just
763 waste time and most programs will never look at it. The only
764 time the linker needs most of the debugging information swapped
765 is when linking big-endian and little-endian MIPS object files
766 together, which is not a common occurrence.
768 We need to look at the fdr to deal with a lot of information in
769 the symbols, so we swap them here. */
770 ecoff_data (abfd
)->debug_info
.fdr
=
771 (struct fdr
*) bfd_alloc (abfd
,
772 (internal_symhdr
->ifdMax
*
773 sizeof (struct fdr
)));
774 if (ecoff_data (abfd
)->debug_info
.fdr
== NULL
)
776 bfd_error
= no_memory
;
779 external_fdr_size
= backend
->debug_swap
.external_fdr_size
;
780 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
781 fraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_fdr
;
782 fraw_end
= fraw_src
+ internal_symhdr
->ifdMax
* external_fdr_size
;
783 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
784 (*backend
->debug_swap
.swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
789 /* ECOFF symbol table routines. The ECOFF symbol table is described
790 in gcc/mips-tfile.c. */
792 /* ECOFF uses two common sections. One is the usual one, and the
793 other is for small objects. All the small objects are kept
794 together, and then referenced via the gp pointer, which yields
795 faster assembler code. This is what we use for the small common
797 static asection ecoff_scom_section
;
798 static asymbol ecoff_scom_symbol
;
799 static asymbol
*ecoff_scom_symbol_ptr
;
801 /* Create an empty symbol. */
804 ecoff_make_empty_symbol (abfd
)
807 ecoff_symbol_type
*new;
809 new = (ecoff_symbol_type
*) bfd_alloc (abfd
, sizeof (ecoff_symbol_type
));
810 if (new == (ecoff_symbol_type
*) NULL
)
812 bfd_error
= no_memory
;
813 return (asymbol
*) NULL
;
815 memset (new, 0, sizeof *new);
816 new->symbol
.section
= (asection
*) NULL
;
817 new->fdr
= (FDR
*) NULL
;
820 new->symbol
.the_bfd
= abfd
;
824 /* Set the BFD flags and section for an ECOFF symbol. */
827 ecoff_set_symbol_info (abfd
, ecoff_sym
, asym
, ext
, indirect_ptr_ptr
)
832 asymbol
**indirect_ptr_ptr
;
834 asym
->the_bfd
= abfd
;
835 asym
->value
= ecoff_sym
->value
;
836 asym
->section
= &bfd_debug_section
;
839 /* An indirect symbol requires two consecutive stabs symbols. */
840 if (*indirect_ptr_ptr
!= (asymbol
*) NULL
)
842 BFD_ASSERT (ECOFF_IS_STAB (ecoff_sym
));
844 /* @@ Stuffing pointers into integers is a no-no.
845 We can usually get away with it if the integer is
846 large enough though. */
847 if (sizeof (asym
) > sizeof (bfd_vma
))
849 (*indirect_ptr_ptr
)->value
= (bfd_vma
) asym
;
851 asym
->flags
= BSF_DEBUGGING
;
852 asym
->section
= &bfd_und_section
;
853 *indirect_ptr_ptr
= NULL
;
857 if (ECOFF_IS_STAB (ecoff_sym
)
858 && (ECOFF_UNMARK_STAB (ecoff_sym
->index
) | N_EXT
) == (N_INDR
| N_EXT
))
860 asym
->flags
= BSF_DEBUGGING
| BSF_INDIRECT
;
861 asym
->section
= &bfd_ind_section
;
862 /* Pass this symbol on to the next call to this function. */
863 *indirect_ptr_ptr
= asym
;
867 /* Most symbol types are just for debugging. */
868 switch (ecoff_sym
->st
)
877 if (ECOFF_IS_STAB (ecoff_sym
))
879 asym
->flags
= BSF_DEBUGGING
;
884 asym
->flags
= BSF_DEBUGGING
;
889 asym
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
891 asym
->flags
= BSF_LOCAL
;
892 switch (ecoff_sym
->sc
)
895 /* Used for compiler generated labels. Leave them in the
896 debugging section, and mark them as local. If BSF_DEBUGGING
897 is set, then nm does not display them for some reason. If no
898 flags are set then the linker whines about them. */
899 asym
->flags
= BSF_LOCAL
;
902 asym
->section
= bfd_make_section_old_way (abfd
, ".text");
903 asym
->value
-= asym
->section
->vma
;
906 asym
->section
= bfd_make_section_old_way (abfd
, ".data");
907 asym
->value
-= asym
->section
->vma
;
910 asym
->section
= bfd_make_section_old_way (abfd
, ".bss");
911 asym
->value
-= asym
->section
->vma
;
914 asym
->flags
= BSF_DEBUGGING
;
917 asym
->section
= &bfd_abs_section
;
920 asym
->section
= &bfd_und_section
;
930 asym
->flags
= BSF_DEBUGGING
;
933 asym
->section
= bfd_make_section_old_way (abfd
, ".sdata");
934 asym
->value
-= asym
->section
->vma
;
937 asym
->section
= bfd_make_section_old_way (abfd
, ".sbss");
938 asym
->value
-= asym
->section
->vma
;
941 asym
->section
= bfd_make_section_old_way (abfd
, ".rdata");
942 asym
->value
-= asym
->section
->vma
;
945 asym
->flags
= BSF_DEBUGGING
;
948 if (asym
->value
> ecoff_data (abfd
)->gp_size
)
950 asym
->section
= &bfd_com_section
;
956 if (ecoff_scom_section
.name
== NULL
)
958 /* Initialize the small common section. */
959 ecoff_scom_section
.name
= SCOMMON
;
960 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
961 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
962 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
963 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
964 ecoff_scom_symbol
.name
= SCOMMON
;
965 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
966 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
967 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
969 asym
->section
= &ecoff_scom_section
;
974 asym
->flags
= BSF_DEBUGGING
;
977 asym
->section
= &bfd_und_section
;
982 asym
->section
= bfd_make_section_old_way (abfd
, ".init");
983 asym
->value
-= asym
->section
->vma
;
988 asym
->flags
= BSF_DEBUGGING
;
991 asym
->section
= bfd_make_section_old_way (abfd
, ".fini");
992 asym
->value
-= asym
->section
->vma
;
998 /* Look for special constructors symbols and make relocation entries
999 in a special construction section. These are produced by the
1000 -fgnu-linker argument to g++. */
1001 if (ECOFF_IS_STAB (ecoff_sym
))
1003 switch (ECOFF_UNMARK_STAB (ecoff_sym
->index
))
1015 arelent_chain
*reloc_chain
;
1016 unsigned int bitsize
;
1018 /* Get a section with the same name as the symbol (usually
1019 __CTOR_LIST__ or __DTOR_LIST__). FIXME: gcc uses the
1020 name ___CTOR_LIST (three underscores). We need
1021 __CTOR_LIST (two underscores), since ECOFF doesn't use
1022 a leading underscore. This should be handled by gcc,
1023 but instead we do it here. Actually, this should all
1024 be done differently anyhow. */
1025 name
= bfd_asymbol_name (asym
);
1026 if (name
[0] == '_' && name
[1] == '_' && name
[2] == '_')
1031 section
= bfd_get_section_by_name (abfd
, name
);
1032 if (section
== (asection
*) NULL
)
1036 copy
= (char *) bfd_alloc (abfd
, strlen (name
) + 1);
1037 strcpy (copy
, name
);
1038 section
= bfd_make_section (abfd
, copy
);
1041 /* Build a reloc pointing to this constructor. */
1043 (arelent_chain
*) bfd_alloc (abfd
, sizeof (arelent_chain
));
1044 reloc_chain
->relent
.sym_ptr_ptr
=
1045 bfd_get_section (asym
)->symbol_ptr_ptr
;
1046 reloc_chain
->relent
.address
= section
->_raw_size
;
1047 reloc_chain
->relent
.addend
= asym
->value
;
1048 reloc_chain
->relent
.howto
=
1049 ecoff_backend (abfd
)->constructor_reloc
;
1051 /* Set up the constructor section to hold the reloc. */
1052 section
->flags
= SEC_CONSTRUCTOR
;
1053 ++section
->reloc_count
;
1055 /* Constructor sections must be rounded to a boundary
1056 based on the bitsize. These are not real sections--
1057 they are handled specially by the linker--so the ECOFF
1058 16 byte alignment restriction does not apply. */
1059 bitsize
= ecoff_backend (abfd
)->constructor_bitsize
;
1060 section
->alignment_power
= 1;
1061 while ((1 << section
->alignment_power
) < bitsize
/ 8)
1062 ++section
->alignment_power
;
1064 reloc_chain
->next
= section
->constructor_chain
;
1065 section
->constructor_chain
= reloc_chain
;
1066 section
->_raw_size
+= bitsize
/ 8;
1068 /* Mark the symbol as a constructor. */
1069 asym
->flags
|= BSF_CONSTRUCTOR
;
1076 /* Read an ECOFF symbol table. */
1079 ecoff_slurp_symbol_table (abfd
)
1082 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1083 const bfd_size_type external_ext_size
1084 = backend
->debug_swap
.external_ext_size
;
1085 const bfd_size_type external_sym_size
1086 = backend
->debug_swap
.external_sym_size
;
1087 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1088 = backend
->debug_swap
.swap_ext_in
;
1089 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1090 = backend
->debug_swap
.swap_sym_in
;
1091 bfd_size_type internal_size
;
1092 ecoff_symbol_type
*internal
;
1093 ecoff_symbol_type
*internal_ptr
;
1094 asymbol
*indirect_ptr
;
1100 /* If we've already read in the symbol table, do nothing. */
1101 if (ecoff_data (abfd
)->canonical_symbols
!= NULL
)
1104 /* Get the symbolic information. */
1105 if (ecoff_slurp_symbolic_info (abfd
) == false)
1107 if (bfd_get_symcount (abfd
) == 0)
1110 internal_size
= bfd_get_symcount (abfd
) * sizeof (ecoff_symbol_type
);
1111 internal
= (ecoff_symbol_type
*) bfd_alloc (abfd
, internal_size
);
1112 if (internal
== NULL
)
1114 bfd_error
= no_memory
;
1118 internal_ptr
= internal
;
1119 indirect_ptr
= NULL
;
1120 eraw_src
= (char *) ecoff_data (abfd
)->debug_info
.external_ext
;
1121 eraw_end
= (eraw_src
1122 + (ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
1123 * external_ext_size
));
1124 for (; eraw_src
< eraw_end
; eraw_src
+= external_ext_size
, internal_ptr
++)
1128 (*swap_ext_in
) (abfd
, (PTR
) eraw_src
, &internal_esym
);
1129 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ssext
1130 + internal_esym
.asym
.iss
);
1131 ecoff_set_symbol_info (abfd
, &internal_esym
.asym
,
1132 &internal_ptr
->symbol
, 1, &indirect_ptr
);
1133 /* The alpha uses a negative ifd field for section symbols. */
1134 if (internal_esym
.ifd
>= 0)
1135 internal_ptr
->fdr
= (ecoff_data (abfd
)->debug_info
.fdr
1136 + internal_esym
.ifd
);
1138 internal_ptr
->fdr
= NULL
;
1139 internal_ptr
->local
= false;
1140 internal_ptr
->native
= (PTR
) eraw_src
;
1142 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1144 /* The local symbols must be accessed via the fdr's, because the
1145 string and aux indices are relative to the fdr information. */
1146 fdr_ptr
= ecoff_data (abfd
)->debug_info
.fdr
;
1147 fdr_end
= fdr_ptr
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1148 for (; fdr_ptr
< fdr_end
; fdr_ptr
++)
1153 lraw_src
= ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1154 + fdr_ptr
->isymBase
* external_sym_size
);
1155 lraw_end
= lraw_src
+ fdr_ptr
->csym
* external_sym_size
;
1157 lraw_src
< lraw_end
;
1158 lraw_src
+= external_sym_size
, internal_ptr
++)
1162 (*swap_sym_in
) (abfd
, (PTR
) lraw_src
, &internal_sym
);
1163 internal_ptr
->symbol
.name
= (ecoff_data (abfd
)->debug_info
.ss
1165 + internal_sym
.iss
);
1166 ecoff_set_symbol_info (abfd
, &internal_sym
,
1167 &internal_ptr
->symbol
, 0, &indirect_ptr
);
1168 internal_ptr
->fdr
= fdr_ptr
;
1169 internal_ptr
->local
= true;
1170 internal_ptr
->native
= (PTR
) lraw_src
;
1173 BFD_ASSERT (indirect_ptr
== (asymbol
*) NULL
);
1175 ecoff_data (abfd
)->canonical_symbols
= internal
;
1180 /* Return the amount of space needed for the canonical symbols. */
1183 ecoff_get_symtab_upper_bound (abfd
)
1186 if (ecoff_slurp_symbolic_info (abfd
) == false
1187 || bfd_get_symcount (abfd
) == 0)
1190 return (bfd_get_symcount (abfd
) + 1) * (sizeof (ecoff_symbol_type
*));
1193 /* Get the canonical symbols. */
1196 ecoff_get_symtab (abfd
, alocation
)
1198 asymbol
**alocation
;
1200 unsigned int counter
= 0;
1201 ecoff_symbol_type
*symbase
;
1202 ecoff_symbol_type
**location
= (ecoff_symbol_type
**) alocation
;
1204 if (ecoff_slurp_symbol_table (abfd
) == false
1205 || bfd_get_symcount (abfd
) == 0)
1208 symbase
= ecoff_data (abfd
)->canonical_symbols
;
1209 while (counter
< bfd_get_symcount (abfd
))
1211 *(location
++) = symbase
++;
1214 *location
++ = (ecoff_symbol_type
*) NULL
;
1215 return bfd_get_symcount (abfd
);
1218 /* Turn ECOFF type information into a printable string.
1219 ecoff_emit_aggregate and ecoff_type_to_string are from
1220 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
1222 /* Write aggregate information to a string. */
1225 ecoff_emit_aggregate (abfd
, string
, rndx
, isym
, which
)
1232 int ifd
= rndx
->rfd
;
1233 int indx
= rndx
->index
;
1234 int sym_base
, ss_base
;
1240 sym_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].isymBase
;
1241 ss_base
= ecoff_data (abfd
)->debug_info
.fdr
[ifd
].issBase
;
1243 if (indx
== indexNil
)
1244 name
= "/* no name */";
1247 const struct ecoff_debug_swap
* const debug_swap
1248 = &ecoff_backend (abfd
)->debug_swap
;
1252 (*debug_swap
->swap_sym_in
)
1254 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
1255 + indx
* debug_swap
->external_sym_size
),
1257 name
= ecoff_data (abfd
)->debug_info
.ss
+ ss_base
+ sym
.iss
;
1261 "%s %s { ifd = %d, index = %ld }",
1264 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
));
1267 /* Convert the type information to string format. */
1270 ecoff_type_to_string (abfd
, aux_ptr
, indx
, bigendian
)
1272 union aux_ext
*aux_ptr
;
1284 unsigned int basic_type
;
1286 static char buffer1
[1024];
1287 static char buffer2
[1024];
1292 for (i
= 0; i
< 7; i
++)
1294 qualifiers
[i
].low_bound
= 0;
1295 qualifiers
[i
].high_bound
= 0;
1296 qualifiers
[i
].stride
= 0;
1299 if (AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
]) == -1)
1300 return "-1 (no type)";
1301 ecoff_swap_tir_in (bigendian
, &aux_ptr
[indx
++].a_ti
, &u
.ti
);
1303 basic_type
= u
.ti
.bt
;
1304 qualifiers
[0].type
= u
.ti
.tq0
;
1305 qualifiers
[1].type
= u
.ti
.tq1
;
1306 qualifiers
[2].type
= u
.ti
.tq2
;
1307 qualifiers
[3].type
= u
.ti
.tq3
;
1308 qualifiers
[4].type
= u
.ti
.tq4
;
1309 qualifiers
[5].type
= u
.ti
.tq5
;
1310 qualifiers
[6].type
= tqNil
;
1313 * Go get the basic type.
1317 case btNil
: /* undefined */
1321 case btAdr
: /* address - integer same size as pointer */
1322 strcpy (p1
, "address");
1325 case btChar
: /* character */
1326 strcpy (p1
, "char");
1329 case btUChar
: /* unsigned character */
1330 strcpy (p1
, "unsigned char");
1333 case btShort
: /* short */
1334 strcpy (p1
, "short");
1337 case btUShort
: /* unsigned short */
1338 strcpy (p1
, "unsigned short");
1341 case btInt
: /* int */
1345 case btUInt
: /* unsigned int */
1346 strcpy (p1
, "unsigned int");
1349 case btLong
: /* long */
1350 strcpy (p1
, "long");
1353 case btULong
: /* unsigned long */
1354 strcpy (p1
, "unsigned long");
1357 case btFloat
: /* float (real) */
1358 strcpy (p1
, "float");
1361 case btDouble
: /* Double (real) */
1362 strcpy (p1
, "double");
1365 /* Structures add 1-2 aux words:
1366 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1367 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1369 case btStruct
: /* Structure (Record) */
1370 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1371 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1372 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1374 indx
++; /* skip aux words */
1377 /* Unions add 1-2 aux words:
1378 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1379 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1381 case btUnion
: /* Union */
1382 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1383 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1384 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1386 indx
++; /* skip aux words */
1389 /* Enumerations add 1-2 aux words:
1390 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1391 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1393 case btEnum
: /* Enumeration */
1394 ecoff_swap_rndx_in (bigendian
, &aux_ptr
[indx
].a_rndx
, &rndx
);
1395 ecoff_emit_aggregate (abfd
, p1
, &rndx
,
1396 (long) AUX_GET_ISYM (bigendian
, &aux_ptr
[indx
+1]),
1398 indx
++; /* skip aux words */
1401 case btTypedef
: /* defined via a typedef, isymRef points */
1402 strcpy (p1
, "typedef");
1405 case btRange
: /* subrange of int */
1406 strcpy (p1
, "subrange");
1409 case btSet
: /* pascal sets */
1413 case btComplex
: /* fortran complex */
1414 strcpy (p1
, "complex");
1417 case btDComplex
: /* fortran double complex */
1418 strcpy (p1
, "double complex");
1421 case btIndirect
: /* forward or unnamed typedef */
1422 strcpy (p1
, "forward/unamed typedef");
1425 case btFixedDec
: /* Fixed Decimal */
1426 strcpy (p1
, "fixed decimal");
1429 case btFloatDec
: /* Float Decimal */
1430 strcpy (p1
, "float decimal");
1433 case btString
: /* Varying Length Character String */
1434 strcpy (p1
, "string");
1437 case btBit
: /* Aligned Bit String */
1441 case btPicture
: /* Picture */
1442 strcpy (p1
, "picture");
1445 case btVoid
: /* Void */
1446 strcpy (p1
, "void");
1450 sprintf (p1
, "Unknown basic type %d", (int) basic_type
);
1454 p1
+= strlen (buffer1
);
1457 * If this is a bitfield, get the bitsize.
1463 bitsize
= AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
++]);
1464 sprintf (p1
, " : %d", bitsize
);
1465 p1
+= strlen (buffer1
);
1470 * Deal with any qualifiers.
1472 if (qualifiers
[0].type
!= tqNil
)
1475 * Snarf up any array bounds in the correct order. Arrays
1476 * store 5 successive words in the aux. table:
1477 * word 0 RNDXR to type of the bounds (ie, int)
1478 * word 1 Current file descriptor index
1480 * word 3 high bound (or -1 if [])
1481 * word 4 stride size in bits
1483 for (i
= 0; i
< 7; i
++)
1485 if (qualifiers
[i
].type
== tqArray
)
1487 qualifiers
[i
].low_bound
=
1488 AUX_GET_DNLOW (bigendian
, &aux_ptr
[indx
+2]);
1489 qualifiers
[i
].high_bound
=
1490 AUX_GET_DNHIGH (bigendian
, &aux_ptr
[indx
+3]);
1491 qualifiers
[i
].stride
=
1492 AUX_GET_WIDTH (bigendian
, &aux_ptr
[indx
+4]);
1498 * Now print out the qualifiers.
1500 for (i
= 0; i
< 6; i
++)
1502 switch (qualifiers
[i
].type
)
1509 strcpy (p2
, "ptr to ");
1510 p2
+= sizeof ("ptr to ")-1;
1514 strcpy (p2
, "volatile ");
1515 p2
+= sizeof ("volatile ")-1;
1519 strcpy (p2
, "far ");
1520 p2
+= sizeof ("far ")-1;
1524 strcpy (p2
, "func. ret. ");
1525 p2
+= sizeof ("func. ret. ");
1530 int first_array
= i
;
1533 /* Print array bounds reversed (ie, in the order the C
1534 programmer writes them). C is such a fun language.... */
1536 while (i
< 5 && qualifiers
[i
+1].type
== tqArray
)
1539 for (j
= i
; j
>= first_array
; j
--)
1541 strcpy (p2
, "array [");
1542 p2
+= sizeof ("array [")-1;
1543 if (qualifiers
[j
].low_bound
!= 0)
1545 "%ld:%ld {%ld bits}",
1546 (long) qualifiers
[j
].low_bound
,
1547 (long) qualifiers
[j
].high_bound
,
1548 (long) qualifiers
[j
].stride
);
1550 else if (qualifiers
[j
].high_bound
!= -1)
1553 (long) (qualifiers
[j
].high_bound
+ 1),
1554 (long) (qualifiers
[j
].stride
));
1557 sprintf (p2
, " {%ld bits}", (long) (qualifiers
[j
].stride
));
1560 strcpy (p2
, "] of ");
1561 p2
+= sizeof ("] of ")-1;
1569 strcpy (p2
, buffer1
);
1573 /* Return information about ECOFF symbol SYMBOL in RET. */
1577 ecoff_get_symbol_info (abfd
, symbol
, ret
)
1578 bfd
*abfd
; /* Ignored. */
1582 bfd_symbol_info (symbol
, ret
);
1585 /* Print information about an ECOFF symbol. */
1588 ecoff_print_symbol (abfd
, filep
, symbol
, how
)
1592 bfd_print_symbol_type how
;
1594 const struct ecoff_debug_swap
* const debug_swap
1595 = &ecoff_backend (abfd
)->debug_swap
;
1596 FILE *file
= (FILE *)filep
;
1600 case bfd_print_symbol_name
:
1601 fprintf (file
, "%s", symbol
->name
);
1603 case bfd_print_symbol_more
:
1604 if (ecoffsymbol (symbol
)->local
)
1608 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1610 fprintf (file
, "ecoff local ");
1611 fprintf_vma (file
, (bfd_vma
) ecoff_sym
.value
);
1612 fprintf (file
, " %x %x", (unsigned) ecoff_sym
.st
,
1613 (unsigned) ecoff_sym
.sc
);
1619 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1621 fprintf (file
, "ecoff extern ");
1622 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1623 fprintf (file
, " %x %x", (unsigned) ecoff_ext
.asym
.st
,
1624 (unsigned) ecoff_ext
.asym
.sc
);
1627 case bfd_print_symbol_all
:
1628 /* Print out the symbols in a reasonable way */
1637 if (ecoffsymbol (symbol
)->local
)
1639 (*debug_swap
->swap_sym_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1642 pos
= ((((char *) ecoffsymbol (symbol
)->native
1643 - (char *) ecoff_data (abfd
)->debug_info
.external_sym
)
1644 / debug_swap
->external_sym_size
)
1645 + ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
);
1652 (*debug_swap
->swap_ext_in
) (abfd
, ecoffsymbol (symbol
)->native
,
1655 pos
= (((char *) ecoffsymbol (symbol
)->native
1656 - (char *) ecoff_data (abfd
)->debug_info
.external_ext
)
1657 / debug_swap
->external_ext_size
);
1658 jmptbl
= ecoff_ext
.jmptbl
? 'j' : ' ';
1659 cobol_main
= ecoff_ext
.cobol_main
? 'c' : ' ';
1660 weakext
= ecoff_ext
.weakext
? 'w' : ' ';
1663 fprintf (file
, "[%3d] %c ",
1665 fprintf_vma (file
, (bfd_vma
) ecoff_ext
.asym
.value
);
1666 fprintf (file
, " st %x sc %x indx %x %c%c%c %s",
1667 (unsigned) ecoff_ext
.asym
.st
,
1668 (unsigned) ecoff_ext
.asym
.sc
,
1669 (unsigned) ecoff_ext
.asym
.index
,
1670 jmptbl
, cobol_main
, weakext
,
1673 if (ecoffsymbol (symbol
)->fdr
!= NULL
1674 && ecoff_ext
.asym
.index
!= indexNil
)
1678 bfd_size_type sym_base
;
1679 union aux_ext
*aux_base
;
1681 indx
= ecoff_ext
.asym
.index
;
1683 /* sym_base is used to map the fdr relative indices which
1684 appear in the file to the position number which we are
1686 sym_base
= ecoffsymbol (symbol
)->fdr
->isymBase
;
1687 if (ecoffsymbol (symbol
)->local
)
1689 ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
1691 /* aux_base is the start of the aux entries for this file;
1692 asym.index is an offset from this. */
1693 aux_base
= (ecoff_data (abfd
)->debug_info
.external_aux
1694 + ecoffsymbol (symbol
)->fdr
->iauxBase
);
1696 /* The aux entries are stored in host byte order; the
1697 order is indicated by a bit in the fdr. */
1698 bigendian
= ecoffsymbol (symbol
)->fdr
->fBigendian
;
1700 /* This switch is basically from gcc/mips-tdump.c */
1701 switch (ecoff_ext
.asym
.st
)
1709 fprintf (file
, "\n End+1 symbol: %ld",
1710 (long) (indx
+ sym_base
));
1714 if (ecoff_ext
.asym
.sc
== scText
1715 || ecoff_ext
.asym
.sc
== scInfo
)
1716 fprintf (file
, "\n First symbol: %ld",
1717 (long) (indx
+ sym_base
));
1719 fprintf (file
, "\n First symbol: %ld",
1720 (long) (AUX_GET_ISYM (bigendian
,
1721 &aux_base
[ecoff_ext
.asym
.index
])
1727 if (ECOFF_IS_STAB (&ecoff_ext
.asym
))
1729 else if (ecoffsymbol (symbol
)->local
)
1730 fprintf (file
, "\n End+1 symbol: %-7ld Type: %s",
1731 (long) (AUX_GET_ISYM (bigendian
,
1732 &aux_base
[ecoff_ext
.asym
.index
])
1734 ecoff_type_to_string (abfd
, aux_base
, indx
+ 1,
1737 fprintf (file
, "\n Local symbol: %ld",
1740 + (ecoff_data (abfd
)
1741 ->debug_info
.symbolic_header
.iextMax
)));
1745 if (! ECOFF_IS_STAB (&ecoff_ext
.asym
))
1746 fprintf (file
, "\n Type: %s",
1747 ecoff_type_to_string (abfd
, aux_base
, indx
,
1757 /* Read in the relocs for a section. */
1760 ecoff_slurp_reloc_table (abfd
, section
, symbols
)
1765 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
1766 arelent
*internal_relocs
;
1767 bfd_size_type external_reloc_size
;
1768 bfd_size_type external_relocs_size
;
1769 char *external_relocs
;
1773 if (section
->relocation
!= (arelent
*) NULL
1774 || section
->reloc_count
== 0
1775 || (section
->flags
& SEC_CONSTRUCTOR
) != 0)
1778 if (ecoff_slurp_symbol_table (abfd
) == false)
1781 internal_relocs
= (arelent
*) bfd_alloc (abfd
,
1783 * section
->reloc_count
));
1784 external_reloc_size
= backend
->external_reloc_size
;
1785 external_relocs_size
= external_reloc_size
* section
->reloc_count
;
1786 external_relocs
= (char *) bfd_alloc (abfd
, external_relocs_size
);
1787 if (internal_relocs
== (arelent
*) NULL
1788 || external_relocs
== (char *) NULL
)
1790 bfd_error
= no_memory
;
1793 if (bfd_seek (abfd
, section
->rel_filepos
, SEEK_SET
) != 0)
1795 if (bfd_read (external_relocs
, 1, external_relocs_size
, abfd
)
1796 != external_relocs_size
)
1798 bfd_error
= system_call_error
;
1802 for (i
= 0, rptr
= internal_relocs
; i
< section
->reloc_count
; i
++, rptr
++)
1804 struct internal_reloc intern
;
1806 (*backend
->swap_reloc_in
) (abfd
,
1807 external_relocs
+ i
* external_reloc_size
,
1810 if (intern
.r_extern
)
1812 /* r_symndx is an index into the external symbols. */
1813 BFD_ASSERT (intern
.r_symndx
>= 0
1815 < (ecoff_data (abfd
)
1816 ->debug_info
.symbolic_header
.iextMax
)));
1817 rptr
->sym_ptr_ptr
= symbols
+ intern
.r_symndx
;
1820 else if (intern
.r_symndx
== RELOC_SECTION_NONE
1821 || intern
.r_symndx
== RELOC_SECTION_ABS
)
1823 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
1828 CONST
char *sec_name
;
1831 /* r_symndx is a section key. */
1832 switch (intern
.r_symndx
)
1834 case RELOC_SECTION_TEXT
: sec_name
= ".text"; break;
1835 case RELOC_SECTION_RDATA
: sec_name
= ".rdata"; break;
1836 case RELOC_SECTION_DATA
: sec_name
= ".data"; break;
1837 case RELOC_SECTION_SDATA
: sec_name
= ".sdata"; break;
1838 case RELOC_SECTION_SBSS
: sec_name
= ".sbss"; break;
1839 case RELOC_SECTION_BSS
: sec_name
= ".bss"; break;
1840 case RELOC_SECTION_INIT
: sec_name
= ".init"; break;
1841 case RELOC_SECTION_LIT8
: sec_name
= ".lit8"; break;
1842 case RELOC_SECTION_LIT4
: sec_name
= ".lit4"; break;
1843 case RELOC_SECTION_XDATA
: sec_name
= ".xdata"; break;
1844 case RELOC_SECTION_PDATA
: sec_name
= ".pdata"; break;
1845 case RELOC_SECTION_FINI
: sec_name
= ".fini"; break;
1846 case RELOC_SECTION_LITA
: sec_name
= ".lita"; break;
1850 sec
= bfd_get_section_by_name (abfd
, sec_name
);
1851 if (sec
== (asection
*) NULL
)
1853 rptr
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
1855 rptr
->addend
= - bfd_get_section_vma (abfd
, sec
);
1858 rptr
->address
= intern
.r_vaddr
- bfd_get_section_vma (abfd
, section
);
1860 /* Let the backend select the howto field and do any other
1861 required processing. */
1862 (*backend
->adjust_reloc_in
) (abfd
, &intern
, rptr
);
1865 bfd_release (abfd
, external_relocs
);
1867 section
->relocation
= internal_relocs
;
1872 /* Get a canonical list of relocs. */
1875 ecoff_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1883 if (section
->flags
& SEC_CONSTRUCTOR
)
1885 arelent_chain
*chain
;
1887 /* This section has relocs made up by us, not the file, so take
1888 them out of their chain and place them into the data area
1890 for (count
= 0, chain
= section
->constructor_chain
;
1891 count
< section
->reloc_count
;
1892 count
++, chain
= chain
->next
)
1893 *relptr
++ = &chain
->relent
;
1899 if (ecoff_slurp_reloc_table (abfd
, section
, symbols
) == false)
1902 tblptr
= section
->relocation
;
1903 if (tblptr
== (arelent
*) NULL
)
1906 for (count
= 0; count
< section
->reloc_count
; count
++)
1907 *relptr
++ = tblptr
++;
1910 *relptr
= (arelent
*) NULL
;
1912 return section
->reloc_count
;
1915 /* Provided a BFD, a section and an offset into the section, calculate
1916 and return the name of the source file and the line nearest to the
1921 ecoff_find_nearest_line (abfd
,
1930 asymbol
**ignore_symbols
;
1932 CONST
char **filename_ptr
;
1933 CONST
char **functionname_ptr
;
1934 unsigned int *retline_ptr
;
1936 const struct ecoff_debug_swap
* const debug_swap
1937 = &ecoff_backend (abfd
)->debug_swap
;
1942 bfd_size_type external_pdr_size
;
1946 unsigned char *line_ptr
;
1947 unsigned char *line_end
;
1950 /* If we're not in the .text section, we don't have any line
1952 if (strcmp (section
->name
, _TEXT
) != 0
1953 || offset
< ecoff_data (abfd
)->text_start
1954 || offset
>= ecoff_data (abfd
)->text_end
)
1957 /* Make sure we have the FDR's. */
1958 if (ecoff_slurp_symbolic_info (abfd
) == false
1959 || bfd_get_symcount (abfd
) == 0)
1962 /* Each file descriptor (FDR) has a memory address. Here we track
1963 down which FDR we want. The FDR's are stored in increasing
1964 memory order. If speed is ever important, this can become a
1965 binary search. We must ignore FDR's with no PDR entries; they
1966 will have the adr of the FDR before or after them. */
1967 fdr_start
= ecoff_data (abfd
)->debug_info
.fdr
;
1968 fdr_end
= fdr_start
+ ecoff_data (abfd
)->debug_info
.symbolic_header
.ifdMax
;
1969 fdr_hold
= (FDR
*) NULL
;
1970 for (fdr_ptr
= fdr_start
; fdr_ptr
< fdr_end
; fdr_ptr
++)
1972 if (fdr_ptr
->cpd
== 0)
1974 if (offset
< fdr_ptr
->adr
)
1978 if (fdr_hold
== (FDR
*) NULL
)
1982 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
1983 have an address, which is relative to the FDR address, and are
1984 also stored in increasing memory order. */
1985 offset
-= fdr_ptr
->adr
;
1986 external_pdr_size
= debug_swap
->external_pdr_size
;
1987 pdr_ptr
= ((char *) ecoff_data (abfd
)->debug_info
.external_pdr
1988 + fdr_ptr
->ipdFirst
* external_pdr_size
);
1989 pdr_end
= pdr_ptr
+ fdr_ptr
->cpd
* external_pdr_size
;
1990 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
1992 /* The address of the first PDR is an offset which applies to the
1993 addresses of all the PDR's. */
1996 for (pdr_ptr
+= external_pdr_size
;
1998 pdr_ptr
+= external_pdr_size
)
2000 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2001 if (offset
< pdr
.adr
)
2005 /* Now we can look for the actual line number. The line numbers are
2006 stored in a very funky format, which I won't try to describe.
2007 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2008 we want; we need this to compute line_end. */
2009 line_end
= ecoff_data (abfd
)->debug_info
.line
;
2010 if (pdr_ptr
== pdr_end
)
2011 line_end
+= fdr_ptr
->cbLineOffset
+ fdr_ptr
->cbLine
;
2013 line_end
+= fdr_ptr
->cbLineOffset
+ pdr
.cbLineOffset
;
2015 /* Now change pdr and pdr_ptr to the one we want. */
2016 pdr_ptr
-= external_pdr_size
;
2017 (*debug_swap
->swap_pdr_in
) (abfd
, (PTR
) pdr_ptr
, &pdr
);
2021 line_ptr
= (ecoff_data (abfd
)->debug_info
.line
2022 + fdr_ptr
->cbLineOffset
2023 + pdr
.cbLineOffset
);
2024 while (line_ptr
< line_end
)
2029 delta
= *line_ptr
>> 4;
2032 count
= (*line_ptr
& 0xf) + 1;
2036 delta
= (((line_ptr
[0]) & 0xff) << 8) + ((line_ptr
[1]) & 0xff);
2037 if (delta
>= 0x8000)
2042 if (offset
< count
* 4)
2044 offset
-= count
* 4;
2047 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2048 at least according to gdb/mipsread.c. */
2049 if (fdr_ptr
->rss
== -1)
2051 *filename_ptr
= NULL
;
2053 *functionname_ptr
= NULL
;
2058 (*debug_swap
->swap_ext_in
)
2060 ((char *) ecoff_data (abfd
)->debug_info
.external_ext
2061 + pdr
.isym
* debug_swap
->external_ext_size
),
2063 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ssext
2064 + proc_ext
.asym
.iss
);
2071 *filename_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2074 (*debug_swap
->swap_sym_in
)
2076 ((char *) ecoff_data (abfd
)->debug_info
.external_sym
2077 + (fdr_ptr
->isymBase
+ pdr
.isym
) * debug_swap
->external_sym_size
),
2079 *functionname_ptr
= (ecoff_data (abfd
)->debug_info
.ss
2083 if (lineno
== ilineNil
)
2085 *retline_ptr
= lineno
;
2089 /* Set the architecture. The supported architecture is stored in the
2090 backend pointer. We always set the architecture anyhow, since many
2091 callers ignore the return value. */
2094 ecoff_set_arch_mach (abfd
, arch
, machine
)
2096 enum bfd_architecture arch
;
2097 unsigned long machine
;
2099 bfd_default_set_arch_mach (abfd
, arch
, machine
);
2100 return arch
== ecoff_backend (abfd
)->arch
;
2103 /* Get the size of the section headers. We do not output the .reginfo
2108 ecoff_sizeof_headers (abfd
, reloc
)
2116 for (current
= abfd
->sections
;
2117 current
!= (asection
*)NULL
;
2118 current
= current
->next
)
2119 if (strcmp (current
->name
, REGINFO
) != 0)
2122 return (bfd_coff_filhsz (abfd
)
2123 + bfd_coff_aoutsz (abfd
)
2124 + c
* bfd_coff_scnhsz (abfd
));
2127 /* Get the contents of a section. This is where we handle reading the
2128 .reginfo section, which implicitly holds the contents of an
2129 ecoff_reginfo structure. */
2132 ecoff_get_section_contents (abfd
, section
, location
, offset
, count
)
2137 bfd_size_type count
;
2139 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2140 struct ecoff_reginfo s
;
2143 if (strcmp (section
->name
, REGINFO
) != 0)
2144 return bfd_generic_get_section_contents (abfd
, section
, location
,
2147 s
.gp_value
= tdata
->gp
;
2148 s
.gprmask
= tdata
->gprmask
;
2149 for (i
= 0; i
< 4; i
++)
2150 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2151 s
.fprmask
= tdata
->fprmask
;
2153 /* bfd_get_section_contents has already checked that the offset and
2154 size is reasonable. We don't have to worry about swapping or any
2155 such thing; the .reginfo section is defined such that the
2156 contents are an ecoff_reginfo structure as seen on the host. */
2157 memcpy (location
, ((char *) &s
) + offset
, (size_t) count
);
2161 /* Calculate the file position for each section, and set
2165 ecoff_compute_section_file_positions (abfd
)
2173 sofar
= ecoff_sizeof_headers (abfd
, false);
2176 for (current
= abfd
->sections
;
2177 current
!= (asection
*) NULL
;
2178 current
= current
->next
)
2180 /* Only deal with sections which have contents */
2181 if ((current
->flags
& (SEC_HAS_CONTENTS
| SEC_LOAD
)) == 0
2182 || strcmp (current
->name
, REGINFO
) == 0)
2185 /* On Ultrix, the data sections in an executable file must be
2186 aligned to a page boundary within the file. This does not
2187 affect the section size, though. FIXME: Does this work for
2188 other platforms? It requires some modification for the
2189 Alpha, because .rdata on the Alpha goes with the text, not
2191 if ((abfd
->flags
& EXEC_P
) != 0
2192 && (abfd
->flags
& D_PAGED
) != 0
2193 && first_data
!= false
2194 && (current
->flags
& SEC_CODE
) == 0
2195 && (! ecoff_backend (abfd
)->rdata_in_text
2196 || strcmp (current
->name
, _RDATA
) != 0)
2197 && strcmp (current
->name
, _PDATA
) != 0)
2199 const bfd_vma round
= ecoff_backend (abfd
)->round
;
2201 sofar
= (sofar
+ round
- 1) &~ (round
- 1);
2205 /* Align the sections in the file to the same boundary on
2206 which they are aligned in virtual memory. */
2208 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2210 current
->filepos
= sofar
;
2212 sofar
+= current
->_raw_size
;
2214 /* make sure that this section is of the right size too */
2216 sofar
= BFD_ALIGN (sofar
, 1 << current
->alignment_power
);
2217 current
->_raw_size
+= sofar
- old_sofar
;
2220 ecoff_data (abfd
)->reloc_filepos
= sofar
;
2223 /* Determine the location of the relocs for all the sections in the
2226 static bfd_size_type
2227 ecoff_compute_reloc_file_positions (abfd
)
2230 const bfd_size_type external_reloc_size
=
2231 ecoff_backend (abfd
)->external_reloc_size
;
2232 file_ptr reloc_base
;
2233 bfd_size_type reloc_size
;
2236 if (! abfd
->output_has_begun
)
2237 ecoff_compute_section_file_positions (abfd
);
2239 reloc_base
= ecoff_data (abfd
)->reloc_filepos
;
2242 for (current
= abfd
->sections
;
2243 current
!= (asection
*)NULL
;
2244 current
= current
->next
)
2246 if (strcmp (current
->name
, REGINFO
) == 0)
2248 if (current
->reloc_count
== 0)
2249 current
->rel_filepos
= 0;
2252 bfd_size_type relsize
;
2254 current
->rel_filepos
= reloc_base
;
2255 relsize
= current
->reloc_count
* external_reloc_size
;
2256 reloc_size
+= relsize
;
2257 reloc_base
+= relsize
;
2264 /* Set the contents of a section. This is where we handle setting the
2265 contents of the .reginfo section, which implicitly holds a
2266 ecoff_reginfo structure. */
2269 ecoff_set_section_contents (abfd
, section
, location
, offset
, count
)
2274 bfd_size_type count
;
2276 /* This must be done first, because bfd_set_section_contents is
2277 going to set output_has_begun to true. */
2278 if (abfd
->output_has_begun
== false)
2279 ecoff_compute_section_file_positions (abfd
);
2284 if (strcmp (section
->name
, REGINFO
) == 0)
2286 ecoff_data_type
*tdata
= ecoff_data (abfd
);
2287 struct ecoff_reginfo s
;
2290 /* If the caller is only changing part of the structure, we must
2291 retrieve the current information before the memcpy. */
2292 if (offset
!= 0 || count
!= sizeof (struct ecoff_reginfo
))
2294 s
.gp_value
= tdata
->gp
;
2295 s
.gprmask
= tdata
->gprmask
;
2296 for (i
= 0; i
< 4; i
++)
2297 s
.cprmask
[i
] = tdata
->cprmask
[i
];
2298 s
.fprmask
= tdata
->fprmask
;
2301 /* bfd_set_section_contents has already checked that the offset
2302 and size is reasonable. We don't have to worry about
2303 swapping or any such thing; the .reginfo section is defined
2304 such that the contents are an ecoff_reginfo structure as seen
2306 memcpy (((char *) &s
) + offset
, location
, (size_t) count
);
2308 tdata
->gp
= s
.gp_value
;
2309 tdata
->gprmask
= s
.gprmask
;
2310 for (i
= 0; i
< 4; i
++)
2311 tdata
->cprmask
[i
] = s
.cprmask
[i
];
2312 tdata
->fprmask
= s
.fprmask
;
2317 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) != 0
2318 || bfd_write (location
, 1, count
, abfd
) != count
)
2324 /* Get ECOFF EXTR information for an external symbol. This function
2325 is passed to bfd_ecoff_debug_externals. */
2328 ecoff_get_extr (sym
, esym
)
2332 ecoff_symbol_type
*ecoff_sym_ptr
;
2335 /* Don't include debugging, local or section symbols. */
2336 if ((sym
->flags
& BSF_DEBUGGING
) != 0
2337 || (sym
->flags
& BSF_LOCAL
) != 0
2338 || (sym
->flags
& BSF_SECTION_SYM
) != 0)
2341 if (bfd_asymbol_flavour (sym
) != bfd_target_ecoff_flavour
2342 || ecoffsymbol (sym
)->native
== NULL
)
2345 esym
->cobol_main
= 0;
2349 /* FIXME: we can do better than this for st and sc. */
2350 esym
->asym
.st
= stGlobal
;
2351 esym
->asym
.sc
= scAbs
;
2352 esym
->asym
.reserved
= 0;
2353 esym
->asym
.index
= indexNil
;
2357 ecoff_sym_ptr
= ecoffsymbol (sym
);
2359 if (ecoff_sym_ptr
->local
)
2362 input_bfd
= bfd_asymbol_bfd (sym
);
2363 (*(ecoff_backend (input_bfd
)->debug_swap
.swap_ext_in
))
2364 (input_bfd
, ecoff_sym_ptr
->native
, esym
);
2366 /* If the symbol was defined by the linker, then esym will be
2367 undefined but sym will not be. Get a better class for such a
2369 if ((esym
->asym
.sc
== scUndefined
2370 || esym
->asym
.sc
== scSUndefined
)
2371 && bfd_get_section (sym
) != &bfd_und_section
)
2372 esym
->asym
.sc
= scAbs
;
2374 /* Adjust the FDR index for the symbol by that used for the input
2376 esym
->ifd
+= ecoff_data (input_bfd
)->debug_info
.ifdbase
;
2381 /* Set the external symbol index. This routine is passed to
2382 bfd_ecoff_debug_externals. */
2385 ecoff_set_index (sym
, indx
)
2389 ecoff_set_sym_index (sym
, indx
);
2392 /* Write out an ECOFF file. */
2395 ecoff_write_object_contents (abfd
)
2398 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
2399 const bfd_vma round
= backend
->round
;
2400 const bfd_size_type filhsz
= bfd_coff_filhsz (abfd
);
2401 const bfd_size_type aoutsz
= bfd_coff_aoutsz (abfd
);
2402 const bfd_size_type scnhsz
= bfd_coff_scnhsz (abfd
);
2403 const bfd_size_type external_hdr_size
2404 = backend
->debug_swap
.external_hdr_size
;
2405 const bfd_size_type external_reloc_size
= backend
->external_reloc_size
;
2406 void (* const adjust_reloc_out
) PARAMS ((bfd
*,
2408 struct internal_reloc
*))
2409 = backend
->adjust_reloc_out
;
2410 void (* const swap_reloc_out
) PARAMS ((bfd
*,
2411 const struct internal_reloc
*,
2413 = backend
->swap_reloc_out
;
2414 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
2415 HDRR
* const symhdr
= &debug
->symbolic_header
;
2419 bfd_size_type reloc_size
;
2420 unsigned long text_size
;
2421 unsigned long text_start
;
2422 unsigned long data_size
;
2423 unsigned long data_start
;
2424 unsigned long bss_size
;
2426 struct internal_filehdr internal_f
;
2427 struct internal_aouthdr internal_a
;
2430 bfd_error
= system_call_error
;
2432 /* Determine where the sections and relocs will go in the output
2434 reloc_size
= ecoff_compute_reloc_file_positions (abfd
);
2437 for (current
= abfd
->sections
;
2438 current
!= (asection
*)NULL
;
2439 current
= current
->next
)
2441 if (strcmp (current
->name
, REGINFO
) == 0)
2443 current
->target_index
= count
;
2447 sym_base
= ecoff_data (abfd
)->reloc_filepos
+ reloc_size
;
2449 /* At least on Ultrix, the symbol table of an executable file must
2450 be aligned to a page boundary. FIXME: Is this true on other
2452 if ((abfd
->flags
& EXEC_P
) != 0
2453 && (abfd
->flags
& D_PAGED
) != 0)
2454 sym_base
= (sym_base
+ round
- 1) &~ (round
- 1);
2456 ecoff_data (abfd
)->sym_filepos
= sym_base
;
2458 if ((abfd
->flags
& D_PAGED
) != 0)
2459 text_size
= ecoff_sizeof_headers (abfd
, false);
2467 /* Write section headers to the file. */
2469 buff
= (PTR
) alloca (scnhsz
);
2470 internal_f
.f_nscns
= 0;
2471 if (bfd_seek (abfd
, (file_ptr
) (filhsz
+ aoutsz
), SEEK_SET
) != 0)
2473 for (current
= abfd
->sections
;
2474 current
!= (asection
*) NULL
;
2475 current
= current
->next
)
2477 struct internal_scnhdr section
;
2480 if (strcmp (current
->name
, REGINFO
) == 0)
2482 BFD_ASSERT (current
->reloc_count
== 0);
2486 ++internal_f
.f_nscns
;
2488 strncpy (section
.s_name
, current
->name
, sizeof section
.s_name
);
2490 /* FIXME: is this correct for shared libraries? I think it is
2491 but I have no platform to check. Ian Lance Taylor. */
2492 vma
= bfd_get_section_vma (abfd
, current
);
2493 if (strcmp (current
->name
, _LIB
) == 0)
2494 section
.s_vaddr
= 0;
2496 section
.s_vaddr
= vma
;
2498 section
.s_paddr
= vma
;
2499 section
.s_size
= bfd_get_section_size_before_reloc (current
);
2501 /* If this section is unloadable then the scnptr will be 0. */
2502 if ((current
->flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
)) == 0)
2503 section
.s_scnptr
= 0;
2505 section
.s_scnptr
= current
->filepos
;
2506 section
.s_relptr
= current
->rel_filepos
;
2508 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
2509 object file produced by the assembler is supposed to point to
2510 information about how much room is required by objects of
2511 various different sizes. I think this only matters if we
2512 want the linker to compute the best size to use, or
2513 something. I don't know what happens if the information is
2515 section
.s_lnnoptr
= 0;
2517 section
.s_nreloc
= current
->reloc_count
;
2518 section
.s_nlnno
= 0;
2519 section
.s_flags
= ecoff_sec_to_styp_flags (current
->name
,
2522 bfd_coff_swap_scnhdr_out (abfd
, (PTR
) §ion
, buff
);
2523 if (bfd_write (buff
, 1, scnhsz
, abfd
) != scnhsz
)
2526 if ((section
.s_flags
& STYP_TEXT
) != 0
2527 || ((section
.s_flags
& STYP_RDATA
) != 0
2528 && backend
->rdata_in_text
)
2529 || strcmp (current
->name
, _PDATA
) == 0)
2531 text_size
+= bfd_get_section_size_before_reloc (current
);
2532 if (text_start
== 0 || text_start
> vma
)
2535 else if ((section
.s_flags
& STYP_RDATA
) != 0
2536 || (section
.s_flags
& STYP_DATA
) != 0
2537 || (section
.s_flags
& STYP_LITA
) != 0
2538 || (section
.s_flags
& STYP_LIT8
) != 0
2539 || (section
.s_flags
& STYP_LIT4
) != 0
2540 || (section
.s_flags
& STYP_SDATA
) != 0
2541 || strcmp (current
->name
, _XDATA
) == 0)
2543 data_size
+= bfd_get_section_size_before_reloc (current
);
2544 if (data_start
== 0 || data_start
> vma
)
2547 else if ((section
.s_flags
& STYP_BSS
) != 0
2548 || (section
.s_flags
& STYP_SBSS
) != 0)
2549 bss_size
+= bfd_get_section_size_before_reloc (current
);
2554 /* Set up the file header. */
2556 internal_f
.f_magic
= ecoff_get_magic (abfd
);
2558 /* We will NOT put a fucking timestamp in the header here. Every
2559 time you put it back, I will come in and take it out again. I'm
2560 sorry. This field does not belong here. We fill it with a 0 so
2561 it compares the same but is not a reasonable time. --
2563 internal_f
.f_timdat
= 0;
2565 if (bfd_get_symcount (abfd
) != 0)
2567 /* The ECOFF f_nsyms field is not actually the number of
2568 symbols, it's the size of symbolic information header. */
2569 internal_f
.f_nsyms
= external_hdr_size
;
2570 internal_f
.f_symptr
= sym_base
;
2574 internal_f
.f_nsyms
= 0;
2575 internal_f
.f_symptr
= 0;
2578 internal_f
.f_opthdr
= aoutsz
;
2580 internal_f
.f_flags
= F_LNNO
;
2581 if (reloc_size
== 0)
2582 internal_f
.f_flags
|= F_RELFLG
;
2583 if (bfd_get_symcount (abfd
) == 0)
2584 internal_f
.f_flags
|= F_LSYMS
;
2585 if (abfd
->flags
& EXEC_P
)
2586 internal_f
.f_flags
|= F_EXEC
;
2588 if (! abfd
->xvec
->byteorder_big_p
)
2589 internal_f
.f_flags
|= F_AR32WR
;
2591 internal_f
.f_flags
|= F_AR32W
;
2593 /* Set up the ``optional'' header. */
2594 if ((abfd
->flags
& D_PAGED
) != 0)
2595 internal_a
.magic
= ECOFF_AOUT_ZMAGIC
;
2597 internal_a
.magic
= ECOFF_AOUT_OMAGIC
;
2599 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
2600 linker happy. But, is it right? */
2601 internal_a
.vstamp
= 0x20a;
2603 /* At least on Ultrix, these have to be rounded to page boundaries.
2604 FIXME: Is this true on other platforms? */
2605 if ((abfd
->flags
& D_PAGED
) != 0)
2607 internal_a
.tsize
= (text_size
+ round
- 1) &~ (round
- 1);
2608 internal_a
.text_start
= text_start
&~ (round
- 1);
2609 internal_a
.dsize
= (data_size
+ round
- 1) &~ (round
- 1);
2610 internal_a
.data_start
= data_start
&~ (round
- 1);
2614 internal_a
.tsize
= text_size
;
2615 internal_a
.text_start
= text_start
;
2616 internal_a
.dsize
= data_size
;
2617 internal_a
.data_start
= data_start
;
2620 /* On Ultrix, the initial portions of the .sbss and .bss segments
2621 are at the end of the data section. The bsize field in the
2622 optional header records how many bss bytes are required beyond
2623 those in the data section. The value is not rounded to a page
2625 if (bss_size
< internal_a
.dsize
- data_size
)
2628 bss_size
-= internal_a
.dsize
- data_size
;
2629 internal_a
.bsize
= bss_size
;
2630 internal_a
.bss_start
= internal_a
.data_start
+ internal_a
.dsize
;
2632 internal_a
.entry
= bfd_get_start_address (abfd
);
2634 internal_a
.gp_value
= ecoff_data (abfd
)->gp
;
2636 internal_a
.gprmask
= ecoff_data (abfd
)->gprmask
;
2637 internal_a
.fprmask
= ecoff_data (abfd
)->fprmask
;
2638 for (i
= 0; i
< 4; i
++)
2639 internal_a
.cprmask
[i
] = ecoff_data (abfd
)->cprmask
[i
];
2641 /* Write out the file header and the optional header. */
2643 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2646 buff
= (PTR
) alloca (filhsz
);
2647 bfd_coff_swap_filehdr_out (abfd
, (PTR
) &internal_f
, buff
);
2648 if (bfd_write (buff
, 1, filhsz
, abfd
) != filhsz
)
2651 buff
= (PTR
) alloca (aoutsz
);
2652 bfd_coff_swap_aouthdr_out (abfd
, (PTR
) &internal_a
, buff
);
2653 if (bfd_write (buff
, 1, aoutsz
, abfd
) != aoutsz
)
2656 /* Build the external symbol information. This must be done before
2657 writing out the relocs so that we know the symbol indices. The
2658 condition checks makes sure this object was not created by
2659 ecoff_bfd_final_link, since if it was we do not want to tamper
2660 with the external symbols. */
2661 if (bfd_get_outsymbols (abfd
) != (asymbol
**) NULL
2662 || bfd_get_symcount (abfd
) == 0)
2664 symhdr
->iextMax
= 0;
2665 symhdr
->issExtMax
= 0;
2666 debug
->external_ext
= debug
->external_ext_end
= NULL
;
2667 debug
->ssext
= debug
->ssext_end
= NULL
;
2668 if (bfd_ecoff_debug_externals (abfd
, debug
, &backend
->debug_swap
,
2669 (((abfd
->flags
& EXEC_P
) == 0)
2671 ecoff_get_extr
, ecoff_set_index
)
2675 /* Write out the relocs. */
2676 for (current
= abfd
->sections
;
2677 current
!= (asection
*) NULL
;
2678 current
= current
->next
)
2680 arelent
**reloc_ptr_ptr
;
2681 arelent
**reloc_end
;
2684 if (current
->reloc_count
== 0)
2687 buff
= bfd_alloc (abfd
, current
->reloc_count
* external_reloc_size
);
2690 bfd_error
= no_memory
;
2694 reloc_ptr_ptr
= current
->orelocation
;
2695 reloc_end
= reloc_ptr_ptr
+ current
->reloc_count
;
2696 out_ptr
= (char *) buff
;
2698 reloc_ptr_ptr
< reloc_end
;
2699 reloc_ptr_ptr
++, out_ptr
+= external_reloc_size
)
2703 struct internal_reloc in
;
2705 memset (&in
, 0, sizeof in
);
2707 reloc
= *reloc_ptr_ptr
;
2708 sym
= *reloc
->sym_ptr_ptr
;
2710 in
.r_vaddr
= (reloc
->address
2711 + bfd_get_section_vma (abfd
, current
));
2712 in
.r_type
= reloc
->howto
->type
;
2714 if ((sym
->flags
& BSF_SECTION_SYM
) == 0)
2716 in
.r_symndx
= ecoff_get_sym_index (*reloc
->sym_ptr_ptr
);
2723 name
= bfd_get_section_name (abfd
, bfd_get_section (sym
));
2724 if (strcmp (name
, ".text") == 0)
2725 in
.r_symndx
= RELOC_SECTION_TEXT
;
2726 else if (strcmp (name
, ".rdata") == 0)
2727 in
.r_symndx
= RELOC_SECTION_RDATA
;
2728 else if (strcmp (name
, ".data") == 0)
2729 in
.r_symndx
= RELOC_SECTION_DATA
;
2730 else if (strcmp (name
, ".sdata") == 0)
2731 in
.r_symndx
= RELOC_SECTION_SDATA
;
2732 else if (strcmp (name
, ".sbss") == 0)
2733 in
.r_symndx
= RELOC_SECTION_SBSS
;
2734 else if (strcmp (name
, ".bss") == 0)
2735 in
.r_symndx
= RELOC_SECTION_BSS
;
2736 else if (strcmp (name
, ".init") == 0)
2737 in
.r_symndx
= RELOC_SECTION_INIT
;
2738 else if (strcmp (name
, ".lit8") == 0)
2739 in
.r_symndx
= RELOC_SECTION_LIT8
;
2740 else if (strcmp (name
, ".lit4") == 0)
2741 in
.r_symndx
= RELOC_SECTION_LIT4
;
2742 else if (strcmp (name
, ".xdata") == 0)
2743 in
.r_symndx
= RELOC_SECTION_XDATA
;
2744 else if (strcmp (name
, ".pdata") == 0)
2745 in
.r_symndx
= RELOC_SECTION_PDATA
;
2746 else if (strcmp (name
, ".fini") == 0)
2747 in
.r_symndx
= RELOC_SECTION_FINI
;
2748 else if (strcmp (name
, ".lita") == 0)
2749 in
.r_symndx
= RELOC_SECTION_LITA
;
2750 else if (strcmp (name
, "*ABS*") == 0)
2751 in
.r_symndx
= RELOC_SECTION_ABS
;
2757 (*adjust_reloc_out
) (abfd
, reloc
, &in
);
2759 (*swap_reloc_out
) (abfd
, &in
, (PTR
) out_ptr
);
2762 if (bfd_seek (abfd
, current
->rel_filepos
, SEEK_SET
) != 0)
2764 if (bfd_write (buff
, external_reloc_size
, current
->reloc_count
, abfd
)
2765 != external_reloc_size
* current
->reloc_count
)
2767 bfd_release (abfd
, buff
);
2771 /* Write out the symbolic debugging information. */
2772 if (bfd_get_symcount (abfd
) > 0)
2774 /* Write out the debugging information. */
2775 if (bfd_ecoff_write_debug (abfd
, debug
, &backend
->debug_swap
,
2776 ecoff_data (abfd
)->sym_filepos
)
2780 else if ((abfd
->flags
& EXEC_P
) != 0
2781 && (abfd
->flags
& D_PAGED
) != 0)
2785 /* A demand paged executable must occupy an even number of
2787 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2790 if (bfd_read (&c
, 1, 1, abfd
) == 0)
2792 if (bfd_seek (abfd
, (file_ptr
) ecoff_data (abfd
)->sym_filepos
- 1,
2795 if (bfd_write (&c
, 1, 1, abfd
) != 1)
2802 /* Archive handling. ECOFF uses what appears to be a unique type of
2803 archive header (armap). The byte ordering of the armap and the
2804 contents are encoded in the name of the armap itself. At least for
2805 now, we only support archives with the same byte ordering in the
2806 armap and the contents.
2808 The first four bytes in the armap are the number of symbol
2809 definitions. This is always a power of two.
2811 This is followed by the symbol definitions. Each symbol definition
2812 occupies 8 bytes. The first four bytes are the offset from the
2813 start of the armap strings to the null-terminated string naming
2814 this symbol. The second four bytes are the file offset to the
2815 archive member which defines this symbol. If the second four bytes
2816 are 0, then this is not actually a symbol definition, and it should
2819 The symbols are hashed into the armap with a closed hashing scheme.
2820 See the functions below for the details of the algorithm.
2822 After the symbol definitions comes four bytes holding the size of
2823 the string table, followed by the string table itself. */
2825 /* The name of an archive headers looks like this:
2826 __________E[BL]E[BL]_ (with a trailing space).
2827 The trailing space is changed to an X if the archive is changed to
2828 indicate that the armap is out of date.
2830 The Alpha seems to use ________64E[BL]E[BL]_. */
2832 #define ARMAP_BIG_ENDIAN 'B'
2833 #define ARMAP_LITTLE_ENDIAN 'L'
2834 #define ARMAP_MARKER 'E'
2835 #define ARMAP_START_LENGTH 10
2836 #define ARMAP_HEADER_MARKER_INDEX 10
2837 #define ARMAP_HEADER_ENDIAN_INDEX 11
2838 #define ARMAP_OBJECT_MARKER_INDEX 12
2839 #define ARMAP_OBJECT_ENDIAN_INDEX 13
2840 #define ARMAP_END_INDEX 14
2841 #define ARMAP_END "_ "
2843 /* This is a magic number used in the hashing algorithm. */
2844 #define ARMAP_HASH_MAGIC 0x9dd68ab5
2846 /* This returns the hash value to use for a string. It also sets
2847 *REHASH to the rehash adjustment if the first slot is taken. SIZE
2848 is the number of entries in the hash table, and HLOG is the log
2852 ecoff_armap_hash (s
, rehash
, size
, hlog
)
2854 unsigned int *rehash
;
2862 hash
= ((hash
>> 27) | (hash
<< 5)) + *s
++;
2863 hash
*= ARMAP_HASH_MAGIC
;
2864 *rehash
= (hash
& (size
- 1)) | 1;
2865 return hash
>> (32 - hlog
);
2868 /* Read in the armap. */
2871 ecoff_slurp_armap (abfd
)
2876 struct areltdata
*mapdata
;
2877 bfd_size_type parsed_size
;
2879 struct artdata
*ardata
;
2882 struct symdef
*symdef_ptr
;
2885 /* Get the name of the first element. */
2886 i
= bfd_read ((PTR
) nextname
, 1, 16, abfd
);
2892 bfd_seek (abfd
, (file_ptr
) -16, SEEK_CUR
);
2894 /* Irix 4.0.5F apparently can use either an ECOFF armap or a
2895 standard COFF armap. We could move the ECOFF armap stuff into
2896 bfd_slurp_armap, but that seems inappropriate since no other
2897 target uses this format. Instead, we check directly for a COFF
2899 if (strncmp (nextname
, "/ ", 16) == 0)
2900 return bfd_slurp_armap (abfd
);
2902 /* See if the first element is an armap. */
2903 if (strncmp (nextname
, ecoff_backend (abfd
)->armap_start
,
2904 ARMAP_START_LENGTH
) != 0
2905 || nextname
[ARMAP_HEADER_MARKER_INDEX
] != ARMAP_MARKER
2906 || (nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2907 && nextname
[ARMAP_HEADER_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2908 || nextname
[ARMAP_OBJECT_MARKER_INDEX
] != ARMAP_MARKER
2909 || (nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_BIG_ENDIAN
2910 && nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] != ARMAP_LITTLE_ENDIAN
)
2911 || strncmp (nextname
+ ARMAP_END_INDEX
,
2912 ARMAP_END
, sizeof ARMAP_END
- 1) != 0)
2914 bfd_has_map (abfd
) = false;
2918 /* Make sure we have the right byte ordering. */
2919 if (((nextname
[ARMAP_HEADER_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2920 ^ (abfd
->xvec
->header_byteorder_big_p
!= false))
2921 || ((nextname
[ARMAP_OBJECT_ENDIAN_INDEX
] == ARMAP_BIG_ENDIAN
)
2922 ^ (abfd
->xvec
->byteorder_big_p
!= false)))
2924 bfd_error
= wrong_format
;
2928 /* Read in the armap. */
2929 ardata
= bfd_ardata (abfd
);
2930 mapdata
= _bfd_snarf_ar_hdr (abfd
);
2931 if (mapdata
== (struct areltdata
*) NULL
)
2933 parsed_size
= mapdata
->parsed_size
;
2934 bfd_release (abfd
, (PTR
) mapdata
);
2936 raw_armap
= (char *) bfd_alloc (abfd
, parsed_size
);
2937 if (raw_armap
== (char *) NULL
)
2939 bfd_error
= no_memory
;
2943 if (bfd_read ((PTR
) raw_armap
, 1, parsed_size
, abfd
) != parsed_size
)
2945 bfd_error
= malformed_archive
;
2946 bfd_release (abfd
, (PTR
) raw_armap
);
2950 ardata
->tdata
= (PTR
) raw_armap
;
2952 count
= bfd_h_get_32 (abfd
, (PTR
) raw_armap
);
2954 ardata
->symdef_count
= 0;
2955 ardata
->cache
= (struct ar_cache
*) NULL
;
2957 /* This code used to overlay the symdefs over the raw archive data,
2958 but that doesn't work on a 64 bit host. */
2960 stringbase
= raw_armap
+ count
* 8 + 8;
2962 #ifdef CHECK_ARMAP_HASH
2966 /* Double check that I have the hashing algorithm right by making
2967 sure that every symbol can be looked up successfully. */
2969 for (i
= 1; i
< count
; i
<<= 1)
2971 BFD_ASSERT (i
== count
);
2973 raw_ptr
= raw_armap
+ 4;
2974 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
2976 unsigned int name_offset
, file_offset
;
2977 unsigned int hash
, rehash
, srch
;
2979 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
2980 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
2981 if (file_offset
== 0)
2983 hash
= ecoff_armap_hash (stringbase
+ name_offset
, &rehash
, count
,
2988 /* See if we can rehash to this location. */
2989 for (srch
= (hash
+ rehash
) & (count
- 1);
2990 srch
!= hash
&& srch
!= i
;
2991 srch
= (srch
+ rehash
) & (count
- 1))
2992 BFD_ASSERT (bfd_h_get_32 (abfd
, (PTR
) (raw_armap
+ 8 + srch
* 8))
2994 BFD_ASSERT (srch
== i
);
2998 #endif /* CHECK_ARMAP_HASH */
3000 raw_ptr
= raw_armap
+ 4;
3001 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3002 if (bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4)) != 0)
3003 ++ardata
->symdef_count
;
3005 symdef_ptr
= ((struct symdef
*)
3007 ardata
->symdef_count
* sizeof (struct symdef
)));
3008 ardata
->symdefs
= (carsym
*) symdef_ptr
;
3010 raw_ptr
= raw_armap
+ 4;
3011 for (i
= 0; i
< count
; i
++, raw_ptr
+= 8)
3013 unsigned int name_offset
, file_offset
;
3015 file_offset
= bfd_h_get_32 (abfd
, (PTR
) (raw_ptr
+ 4));
3016 if (file_offset
== 0)
3018 name_offset
= bfd_h_get_32 (abfd
, (PTR
) raw_ptr
);
3019 symdef_ptr
->s
.name
= stringbase
+ name_offset
;
3020 symdef_ptr
->file_offset
= file_offset
;
3024 ardata
->first_file_filepos
= bfd_tell (abfd
);
3025 /* Pad to an even boundary. */
3026 ardata
->first_file_filepos
+= ardata
->first_file_filepos
% 2;
3028 bfd_has_map (abfd
) = true;
3033 /* Write out an armap. */
3036 ecoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
3038 unsigned int elength
;
3040 unsigned int orl_count
;
3043 unsigned int hashsize
, hashlog
;
3044 unsigned int symdefsize
;
3046 unsigned int stringsize
;
3047 unsigned int mapsize
;
3050 struct stat statbuf
;
3053 bfd_byte
*hashtable
;
3057 /* Ultrix appears to use as a hash table size the least power of two
3058 greater than twice the number of entries. */
3059 for (hashlog
= 0; (1 << hashlog
) <= 2 * orl_count
; hashlog
++)
3061 hashsize
= 1 << hashlog
;
3063 symdefsize
= hashsize
* 8;
3065 stringsize
= stridx
+ padit
;
3067 /* Include 8 bytes to store symdefsize and stringsize in output. */
3068 mapsize
= symdefsize
+ stringsize
+ 8;
3070 firstreal
= SARMAG
+ sizeof (struct ar_hdr
) + mapsize
+ elength
;
3072 memset ((PTR
) &hdr
, 0, sizeof hdr
);
3074 /* Work out the ECOFF armap name. */
3075 strcpy (hdr
.ar_name
, ecoff_backend (abfd
)->armap_start
);
3076 hdr
.ar_name
[ARMAP_HEADER_MARKER_INDEX
] = ARMAP_MARKER
;
3077 hdr
.ar_name
[ARMAP_HEADER_ENDIAN_INDEX
] =
3078 (abfd
->xvec
->header_byteorder_big_p
3080 : ARMAP_LITTLE_ENDIAN
);
3081 hdr
.ar_name
[ARMAP_OBJECT_MARKER_INDEX
] = ARMAP_MARKER
;
3082 hdr
.ar_name
[ARMAP_OBJECT_ENDIAN_INDEX
] =
3083 abfd
->xvec
->byteorder_big_p
? ARMAP_BIG_ENDIAN
: ARMAP_LITTLE_ENDIAN
;
3084 memcpy (hdr
.ar_name
+ ARMAP_END_INDEX
, ARMAP_END
, sizeof ARMAP_END
- 1);
3086 /* Write the timestamp of the archive header to be just a little bit
3087 later than the timestamp of the file, otherwise the linker will
3088 complain that the index is out of date. Actually, the Ultrix
3089 linker just checks the archive name; the GNU linker may check the
3091 stat (abfd
->filename
, &statbuf
);
3092 sprintf (hdr
.ar_date
, "%ld", (long) (statbuf
.st_mtime
+ 60));
3094 /* The DECstation uses zeroes for the uid, gid and mode of the
3096 hdr
.ar_uid
[0] = '0';
3097 hdr
.ar_gid
[0] = '0';
3098 hdr
.ar_mode
[0] = '0';
3100 sprintf (hdr
.ar_size
, "%-10d", (int) mapsize
);
3102 hdr
.ar_fmag
[0] = '`';
3103 hdr
.ar_fmag
[1] = '\n';
3105 /* Turn all null bytes in the header into spaces. */
3106 for (i
= 0; i
< sizeof (struct ar_hdr
); i
++)
3107 if (((char *)(&hdr
))[i
] == '\0')
3108 (((char *)(&hdr
))[i
]) = ' ';
3110 if (bfd_write ((PTR
) &hdr
, 1, sizeof (struct ar_hdr
), abfd
)
3111 != sizeof (struct ar_hdr
))
3114 bfd_h_put_32 (abfd
, (bfd_vma
) hashsize
, temp
);
3115 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3118 hashtable
= (bfd_byte
*) bfd_zalloc (abfd
, symdefsize
);
3120 current
= abfd
->archive_head
;
3122 for (i
= 0; i
< orl_count
; i
++)
3124 unsigned int hash
, rehash
;
3126 /* Advance firstreal to the file position of this archive
3128 if (((bfd
*) map
[i
].pos
) != last_elt
)
3132 firstreal
+= arelt_size (current
) + sizeof (struct ar_hdr
);
3133 firstreal
+= firstreal
% 2;
3134 current
= current
->next
;
3136 while (current
!= (bfd
*) map
[i
].pos
);
3141 hash
= ecoff_armap_hash (*map
[i
].name
, &rehash
, hashsize
, hashlog
);
3142 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (hash
* 8) + 4)) != 0)
3146 /* The desired slot is already taken. */
3147 for (srch
= (hash
+ rehash
) & (hashsize
- 1);
3149 srch
= (srch
+ rehash
) & (hashsize
- 1))
3150 if (bfd_h_get_32 (abfd
, (PTR
) (hashtable
+ (srch
* 8) + 4)) == 0)
3153 BFD_ASSERT (srch
!= hash
);
3158 bfd_h_put_32 (abfd
, (bfd_vma
) map
[i
].namidx
,
3159 (PTR
) (hashtable
+ hash
* 8));
3160 bfd_h_put_32 (abfd
, (bfd_vma
) firstreal
,
3161 (PTR
) (hashtable
+ hash
* 8 + 4));
3164 if (bfd_write ((PTR
) hashtable
, 1, symdefsize
, abfd
) != symdefsize
)
3167 bfd_release (abfd
, hashtable
);
3169 /* Now write the strings. */
3170 bfd_h_put_32 (abfd
, (bfd_vma
) stringsize
, temp
);
3171 if (bfd_write ((PTR
) temp
, 1, 4, abfd
) != 4)
3173 for (i
= 0; i
< orl_count
; i
++)
3177 len
= strlen (*map
[i
].name
) + 1;
3178 if (bfd_write ((PTR
) (*map
[i
].name
), 1, len
, abfd
) != len
)
3182 /* The spec sez this should be a newline. But in order to be
3183 bug-compatible for DECstation ar we use a null. */
3186 if (bfd_write ("", 1, 1, abfd
) != 1)
3193 /* See whether this BFD is an archive. If it is, read in the armap
3194 and the extended name table. */
3197 ecoff_archive_p (abfd
)
3200 char armag
[SARMAG
+ 1];
3202 if (bfd_read ((PTR
) armag
, 1, SARMAG
, abfd
) != SARMAG
3203 || strncmp (armag
, ARMAG
, SARMAG
) != 0)
3205 bfd_error
= wrong_format
;
3206 return (bfd_target
*) NULL
;
3209 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3210 involves a cast, we can't do it as the left operand of
3212 abfd
->tdata
.aout_ar_data
=
3213 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
3215 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
3217 bfd_error
= no_memory
;
3218 return (bfd_target
*) NULL
;
3221 bfd_ardata (abfd
)->first_file_filepos
= SARMAG
;
3222 bfd_ardata (abfd
)->cache
= NULL
;
3223 bfd_ardata (abfd
)->archive_head
= NULL
;
3224 bfd_ardata (abfd
)->symdefs
= NULL
;
3225 bfd_ardata (abfd
)->extended_names
= NULL
;
3226 bfd_ardata (abfd
)->tdata
= NULL
;
3228 if (ecoff_slurp_armap (abfd
) == false
3229 || ecoff_slurp_extended_name_table (abfd
) == false)
3231 bfd_release (abfd
, bfd_ardata (abfd
));
3232 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
3233 return (bfd_target
*) NULL
;
3239 /* ECOFF linker code. */
3241 static struct bfd_hash_entry
*ecoff_link_hash_newfunc
3242 PARAMS ((struct bfd_hash_entry
*entry
,
3243 struct bfd_hash_table
*table
,
3244 const char *string
));
3245 static boolean ecoff_link_add_archive_symbols
3246 PARAMS ((bfd
*, struct bfd_link_info
*));
3247 static boolean ecoff_link_check_archive_element
3248 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*pneeded
));
3249 static boolean ecoff_link_add_object_symbols
3250 PARAMS ((bfd
*, struct bfd_link_info
*));
3251 static boolean ecoff_link_add_externals
3252 PARAMS ((bfd
*, struct bfd_link_info
*, PTR
, char *));
3254 /* Routine to create an entry in an ECOFF link hash table. */
3256 static struct bfd_hash_entry
*
3257 ecoff_link_hash_newfunc (entry
, table
, string
)
3258 struct bfd_hash_entry
*entry
;
3259 struct bfd_hash_table
*table
;
3262 struct ecoff_link_hash_entry
*ret
= (struct ecoff_link_hash_entry
*) entry
;
3264 /* Allocate the structure if it has not already been allocated by a
3266 if (ret
== (struct ecoff_link_hash_entry
*) NULL
)
3267 ret
= ((struct ecoff_link_hash_entry
*)
3268 bfd_hash_allocate (table
, sizeof (struct ecoff_link_hash_entry
)));
3270 /* Call the allocation method of the superclass. */
3271 ret
= ((struct ecoff_link_hash_entry
*)
3272 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3275 /* Set local fields. */
3278 memset (&ret
->esym
, 0, sizeof ret
->esym
);
3280 return (struct bfd_hash_entry
*) ret
;
3283 /* Create an ECOFF link hash table. */
3285 struct bfd_link_hash_table
*
3286 ecoff_bfd_link_hash_table_create (abfd
)
3289 struct ecoff_link_hash_table
*ret
;
3291 ret
= ((struct ecoff_link_hash_table
*)
3292 bfd_xmalloc (sizeof (struct ecoff_link_hash_table
)));
3293 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
,
3294 ecoff_link_hash_newfunc
))
3297 return (struct bfd_link_hash_table
*) NULL
;
3302 /* Look up an entry in an ECOFF link hash table. */
3304 #define ecoff_link_hash_lookup(table, string, create, copy, follow) \
3305 ((struct ecoff_link_hash_entry *) \
3306 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
3308 /* Traverse an ECOFF link hash table. */
3310 #define ecoff_link_hash_traverse(table, func, info) \
3311 (bfd_link_hash_traverse \
3313 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
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 /* Given an ECOFF BFD, add symbols to the global hash table as
3325 ecoff_bfd_link_add_symbols (abfd
, info
)
3327 struct bfd_link_info
*info
;
3329 switch (bfd_get_format (abfd
))
3332 return ecoff_link_add_object_symbols (abfd
, info
);
3334 return ecoff_link_add_archive_symbols (abfd
, info
);
3336 bfd_error
= wrong_format
;
3341 /* Add the symbols from an archive file to the global hash table.
3342 This looks through the undefined symbols, looks each one up in the
3343 archive hash table, and adds any associated object file. We do not
3344 use _bfd_generic_link_add_archive_symbols because ECOFF archives
3345 already have a hash table, so there is no reason to construct
3349 ecoff_link_add_archive_symbols (abfd
, info
)
3351 struct bfd_link_info
*info
;
3353 const bfd_byte
*raw_armap
;
3354 struct bfd_link_hash_entry
**pundef
;
3355 unsigned int armap_count
;
3356 unsigned int armap_log
;
3358 const bfd_byte
*hashtable
;
3359 const char *stringbase
;
3361 if (! bfd_has_map (abfd
))
3363 bfd_error
= no_symbols
;
3367 /* If we don't have any raw data for this archive, as can happen on
3368 Irix 4.0.5F, we call the generic routine.
3369 FIXME: We should be more clever about this, since someday tdata
3370 may get to something for a generic archive. */
3371 raw_armap
= (const bfd_byte
*) bfd_ardata (abfd
)->tdata
;
3372 if (raw_armap
== (bfd_byte
*) NULL
)
3373 return (_bfd_generic_link_add_archive_symbols
3374 (abfd
, info
, ecoff_link_check_archive_element
));
3376 armap_count
= bfd_h_get_32 (abfd
, raw_armap
);
3379 for (i
= 1; i
< armap_count
; i
<<= 1)
3381 BFD_ASSERT (i
== armap_count
);
3383 hashtable
= raw_armap
+ 4;
3384 stringbase
= (const char *) raw_armap
+ armap_count
* 8 + 8;
3386 /* Look through the list of undefined symbols. */
3387 pundef
= &info
->hash
->undefs
;
3388 while (*pundef
!= (struct bfd_link_hash_entry
*) NULL
)
3390 struct bfd_link_hash_entry
*h
;
3391 unsigned int hash
, rehash
;
3392 unsigned int file_offset
;
3398 /* When a symbol is defined, it is not necessarily removed from
3400 if (h
->type
!= bfd_link_hash_undefined
3401 && h
->type
!= bfd_link_hash_common
)
3403 /* Remove this entry from the list, for general cleanliness
3404 and because we are going to look through the list again
3405 if we search any more libraries. We can't remove the
3406 entry if it is the tail, because that would lose any
3407 entries we add to the list later on. */
3408 if (*pundef
!= info
->hash
->undefs_tail
)
3409 *pundef
= (*pundef
)->next
;
3411 pundef
= &(*pundef
)->next
;
3415 /* Native ECOFF linkers do not pull in archive elements merely
3416 to satisfy common definitions, so neither do we. We leave
3417 them on the list, though, in case we are linking against some
3418 other object format. */
3419 if (h
->type
!= bfd_link_hash_undefined
)
3421 pundef
= &(*pundef
)->next
;
3425 /* Look for this symbol in the archive hash table. */
3426 hash
= ecoff_armap_hash (h
->root
.string
, &rehash
, armap_count
,
3429 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8) + 4);
3430 if (file_offset
== 0)
3432 /* Nothing in this slot. */
3433 pundef
= &(*pundef
)->next
;
3437 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (hash
* 8));
3438 if (name
[0] != h
->root
.string
[0]
3439 || strcmp (name
, h
->root
.string
) != 0)
3444 /* That was the wrong symbol. Try rehashing. */
3446 for (srch
= (hash
+ rehash
) & (armap_count
- 1);
3448 srch
= (srch
+ rehash
) & (armap_count
- 1))
3450 file_offset
= bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8) + 4);
3451 if (file_offset
== 0)
3453 name
= stringbase
+ bfd_h_get_32 (abfd
, hashtable
+ (srch
* 8));
3454 if (name
[0] == h
->root
.string
[0]
3455 && strcmp (name
, h
->root
.string
) == 0)
3464 pundef
= &(*pundef
)->next
;
3471 element
= _bfd_get_elt_at_filepos (abfd
, file_offset
);
3472 if (element
== (bfd
*) NULL
)
3475 if (! bfd_check_format (element
, bfd_object
))
3478 /* Unlike the generic linker, we know that this element provides
3479 a definition for an undefined symbol and we know that we want
3480 to include it. We don't need to check anything. */
3481 if (! (*info
->callbacks
->add_archive_element
) (info
, element
, name
))
3483 if (! ecoff_link_add_object_symbols (element
, info
))
3486 pundef
= &(*pundef
)->next
;
3492 /* This is called if we used _bfd_generic_link_add_archive_symbols
3493 because we were not dealing with an ECOFF archive. */
3496 ecoff_link_check_archive_element (abfd
, info
, pneeded
)
3498 struct bfd_link_info
*info
;
3501 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3502 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3503 = backend
->debug_swap
.swap_ext_in
;
3505 bfd_size_type external_ext_size
;
3514 if (! ecoff_slurp_symbolic_header (abfd
))
3517 /* If there are no symbols, we don't want it. */
3518 if (bfd_get_symcount (abfd
) == 0)
3521 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3523 /* Read in the external symbols and external strings. */
3524 external_ext_size
= backend
->debug_swap
.external_ext_size
;
3525 esize
= symhdr
->iextMax
* external_ext_size
;
3526 external_ext
= (PTR
) alloca (esize
);
3527 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3528 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3531 ssext
= (char *) alloca (symhdr
->issExtMax
);
3532 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3533 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3536 /* Look through the external symbols to see if they define some
3537 symbol that is currently undefined. */
3538 ext_ptr
= (char *) external_ext
;
3539 ext_end
= ext_ptr
+ esize
;
3540 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
)
3545 struct bfd_link_hash_entry
*h
;
3547 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3549 /* See if this symbol defines something. */
3550 if (esym
.asym
.st
!= stGlobal
3551 && esym
.asym
.st
!= stLabel
3552 && esym
.asym
.st
!= stProc
)
3555 switch (esym
.asym
.sc
)
3578 name
= ssext
+ esym
.asym
.iss
;
3579 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
3581 /* Unlike the generic linker, we do not pull in elements because
3582 of common symbols. */
3583 if (h
== (struct bfd_link_hash_entry
*) NULL
3584 || h
->type
!= bfd_link_hash_undefined
)
3587 /* Include this element. */
3588 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
3590 if (! ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
))
3600 /* Add symbols from an ECOFF object file to the global linker hash
3604 ecoff_link_add_object_symbols (abfd
, info
)
3606 struct bfd_link_info
*info
;
3609 bfd_size_type external_ext_size
;
3614 if (! ecoff_slurp_symbolic_header (abfd
))
3617 /* If there are no symbols, we don't want it. */
3618 if (bfd_get_symcount (abfd
) == 0)
3621 symhdr
= &ecoff_data (abfd
)->debug_info
.symbolic_header
;
3623 /* Read in the external symbols and external strings. */
3624 external_ext_size
= ecoff_backend (abfd
)->debug_swap
.external_ext_size
;
3625 esize
= symhdr
->iextMax
* external_ext_size
;
3626 external_ext
= (PTR
) alloca (esize
);
3627 if (bfd_seek (abfd
, symhdr
->cbExtOffset
, SEEK_SET
) != 0
3628 || bfd_read (external_ext
, 1, esize
, abfd
) != esize
)
3631 ssext
= (char *) alloca (symhdr
->issExtMax
);
3632 if (bfd_seek (abfd
, symhdr
->cbSsExtOffset
, SEEK_SET
) != 0
3633 || bfd_read (ssext
, 1, symhdr
->issExtMax
, abfd
) != symhdr
->issExtMax
)
3636 return ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
);
3639 /* Add the external symbols of an object file to the global linker
3640 hash table. The external symbols and strings we are passed are
3641 just allocated on the stack, and will be discarded. We must
3642 explicitly save any information we may need later on in the link.
3643 We do not want to read the external symbol information again. */
3646 ecoff_link_add_externals (abfd
, info
, external_ext
, ssext
)
3648 struct bfd_link_info
*info
;
3652 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3653 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
3654 = backend
->debug_swap
.swap_ext_in
;
3655 bfd_size_type external_ext_size
= backend
->debug_swap
.external_ext_size
;
3656 unsigned long ext_count
;
3657 struct ecoff_link_hash_entry
**sym_hash
;
3661 ext_count
= ecoff_data (abfd
)->debug_info
.symbolic_header
.iextMax
;
3663 sym_hash
= ((struct ecoff_link_hash_entry
**)
3665 ext_count
* sizeof (struct bfd_link_hash_entry
*)));
3666 ecoff_data (abfd
)->sym_hashes
= sym_hash
;
3668 ext_ptr
= (char *) external_ext
;
3669 ext_end
= ext_ptr
+ ext_count
* external_ext_size
;
3670 for (; ext_ptr
< ext_end
; ext_ptr
+= external_ext_size
, sym_hash
++)
3677 struct ecoff_link_hash_entry
*h
;
3681 (*swap_ext_in
) (abfd
, (PTR
) ext_ptr
, &esym
);
3683 /* Skip debugging symbols. */
3685 switch (esym
.asym
.st
)
3701 /* Get the information for this symbol. */
3702 value
= esym
.asym
.value
;
3703 switch (esym
.asym
.sc
)
3723 section
= bfd_make_section_old_way (abfd
, ".text");
3724 value
-= section
->vma
;
3727 section
= bfd_make_section_old_way (abfd
, ".data");
3728 value
-= section
->vma
;
3731 section
= bfd_make_section_old_way (abfd
, ".bss");
3732 value
-= section
->vma
;
3735 section
= &bfd_abs_section
;
3738 section
= &bfd_und_section
;
3741 section
= bfd_make_section_old_way (abfd
, ".sdata");
3742 value
-= section
->vma
;
3745 section
= bfd_make_section_old_way (abfd
, ".sbss");
3746 value
-= section
->vma
;
3749 section
= bfd_make_section_old_way (abfd
, ".rdata");
3750 value
-= section
->vma
;
3753 if (value
> ecoff_data (abfd
)->gp_size
)
3755 section
= &bfd_com_section
;
3760 if (ecoff_scom_section
.name
== NULL
)
3762 /* Initialize the small common section. */
3763 ecoff_scom_section
.name
= SCOMMON
;
3764 ecoff_scom_section
.flags
= SEC_IS_COMMON
;
3765 ecoff_scom_section
.output_section
= &ecoff_scom_section
;
3766 ecoff_scom_section
.symbol
= &ecoff_scom_symbol
;
3767 ecoff_scom_section
.symbol_ptr_ptr
= &ecoff_scom_symbol_ptr
;
3768 ecoff_scom_symbol
.name
= SCOMMON
;
3769 ecoff_scom_symbol
.flags
= BSF_SECTION_SYM
;
3770 ecoff_scom_symbol
.section
= &ecoff_scom_section
;
3771 ecoff_scom_symbol_ptr
= &ecoff_scom_symbol
;
3773 section
= &ecoff_scom_section
;
3776 section
= &bfd_und_section
;
3779 section
= bfd_make_section_old_way (abfd
, ".init");
3780 value
-= section
->vma
;
3783 section
= bfd_make_section_old_way (abfd
, ".fini");
3784 value
-= section
->vma
;
3788 if (section
== (asection
*) NULL
)
3791 name
= ssext
+ esym
.asym
.iss
;
3793 if (! (_bfd_generic_link_add_one_symbol
3794 (info
, abfd
, name
, BSF_GLOBAL
, section
, value
,
3795 (const char *) NULL
, true, true, backend
->constructor_bitsize
,
3796 (struct bfd_link_hash_entry
**) &h
)))
3801 /* If we are building an ECOFF hash table, save the external
3802 symbol information. */
3803 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
3805 if (h
->abfd
== (bfd
*) NULL
3806 || (section
!= &bfd_und_section
3807 && (! bfd_is_com_section (section
)
3808 || h
->root
.type
!= bfd_link_hash_defined
)))
3819 /* ECOFF final link routines. */
3821 static boolean ecoff_final_link_debug_accumulate
3822 PARAMS ((bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*));
3823 static boolean ecoff_link_write_external
3824 PARAMS ((struct ecoff_link_hash_entry
*, PTR
));
3825 static boolean ecoff_indirect_link_order
3826 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
3827 struct bfd_link_order
*));
3829 /* ECOFF final link routine. This looks through all the input BFDs
3830 and gathers together all the debugging information, and then
3831 processes all the link order information. This may cause it to
3832 close and reopen some input BFDs; I'll see how bad this is. */
3835 ecoff_bfd_final_link (abfd
, info
)
3837 struct bfd_link_info
*info
;
3839 const struct ecoff_backend_data
* const backend
= ecoff_backend (abfd
);
3840 struct ecoff_debug_info
* const debug
= &ecoff_data (abfd
)->debug_info
;
3842 register bfd
*input_bfd
;
3844 struct bfd_link_order
*p
;
3846 /* We accumulate the debugging information counts in the symbolic
3848 symhdr
= &debug
->symbolic_header
;
3849 symhdr
->magic
= backend
->debug_swap
.sym_magic
;
3850 /* FIXME: What should the version stamp be? */
3852 symhdr
->ilineMax
= 0;
3856 symhdr
->isymMax
= 0;
3857 symhdr
->ioptMax
= 0;
3858 symhdr
->iauxMax
= 0;
3860 symhdr
->issExtMax
= 0;
3863 symhdr
->iextMax
= 0;
3865 /* We accumulate the debugging information itself in the debug_info
3867 debug
->line
= debug
->line_end
= NULL
;
3868 debug
->external_dnr
= debug
->external_dnr_end
= NULL
;
3869 debug
->external_pdr
= debug
->external_pdr_end
= NULL
;
3870 debug
->external_sym
= debug
->external_sym_end
= NULL
;
3871 debug
->external_opt
= debug
->external_opt_end
= NULL
;
3872 debug
->external_aux
= debug
->external_aux_end
= NULL
;
3873 debug
->ss
= debug
->ss_end
= NULL
;
3874 debug
->ssext
= debug
->ssext_end
= NULL
;
3875 debug
->external_fdr
= debug
->external_fdr_end
= NULL
;
3876 debug
->external_rfd
= debug
->external_rfd_end
= NULL
;
3877 debug
->external_ext
= debug
->external_ext_end
= NULL
;
3879 /* Accumulate the debugging symbols from each input BFD. */
3880 for (input_bfd
= info
->input_bfds
;
3881 input_bfd
!= (bfd
*) NULL
;
3882 input_bfd
= input_bfd
->link_next
)
3886 /* If we might be using the C based alloca function, dump memory
3887 allocated by ecoff_final_link_debug_accumulate. */
3894 if (bfd_get_flavour (input_bfd
) == bfd_target_ecoff_flavour
)
3895 ret
= ecoff_final_link_debug_accumulate (abfd
, input_bfd
, info
);
3897 ret
= bfd_ecoff_debug_link_other (abfd
,
3899 &backend
->debug_swap
,
3904 /* Combine the register masks. */
3905 ecoff_data (abfd
)->gprmask
|= ecoff_data (input_bfd
)->gprmask
;
3906 ecoff_data (abfd
)->fprmask
|= ecoff_data (input_bfd
)->fprmask
;
3907 ecoff_data (abfd
)->cprmask
[0] |= ecoff_data (input_bfd
)->cprmask
[0];
3908 ecoff_data (abfd
)->cprmask
[1] |= ecoff_data (input_bfd
)->cprmask
[1];
3909 ecoff_data (abfd
)->cprmask
[2] |= ecoff_data (input_bfd
)->cprmask
[2];
3910 ecoff_data (abfd
)->cprmask
[3] |= ecoff_data (input_bfd
)->cprmask
[3];
3913 /* Write out the external symbols. */
3914 ecoff_link_hash_traverse (ecoff_hash_table (info
),
3915 ecoff_link_write_external
,
3918 if (info
->relocateable
)
3920 /* We need to make a pass over the link_orders to count up the
3921 number of relocations we will need to output, so that we know
3922 how much space they will take up. */
3923 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3926 for (p
= o
->link_order_head
;
3927 p
!= (struct bfd_link_order
*) NULL
;
3929 if (p
->type
== bfd_indirect_link_order
)
3930 o
->reloc_count
+= p
->u
.indirect
.section
->reloc_count
;
3933 ecoff_compute_reloc_file_positions (abfd
);
3935 /* Now reset the reloc_count field of the sections in the output
3936 BFD to 0, so that we can use them to keep track of how many
3937 relocs we have output thus far. */
3938 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3942 /* Get a value for the GP register. */
3943 if (ecoff_data (abfd
)->gp
== 0)
3945 struct bfd_link_hash_entry
*h
;
3947 h
= bfd_link_hash_lookup (info
->hash
, "_gp", false, false, true);
3948 if (h
!= (struct bfd_link_hash_entry
*) NULL
3949 && h
->type
== bfd_link_hash_defined
)
3950 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
3951 + h
->u
.def
.section
->output_section
->vma
3952 + h
->u
.def
.section
->output_offset
);
3953 else if (info
->relocateable
)
3957 /* Make up a value. */
3959 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3962 && (strcmp (o
->name
, _SBSS
) == 0
3963 || strcmp (o
->name
, _SDATA
) == 0
3964 || strcmp (o
->name
, _LIT4
) == 0
3965 || strcmp (o
->name
, _LIT8
) == 0
3966 || strcmp (o
->name
, _LITA
) == 0))
3969 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
3973 /* If the relocate_section function needs to do a reloc
3974 involving the GP value, it should make a reloc_dangerous
3975 callback to warn that GP is not defined. */
3979 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3981 /* Ignore any link_orders for the .reginfo section, which does
3982 not really exist. */
3983 if (strcmp (o
->name
, REGINFO
) == 0)
3986 for (p
= o
->link_order_head
;
3987 p
!= (struct bfd_link_order
*) NULL
;
3990 /* If we might be using the C based alloca function, we need
3991 to dump the memory allocated by the function
3992 ecoff_indirect_link_order. */
3998 if (p
->type
== bfd_indirect_link_order
3999 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4000 == bfd_target_ecoff_flavour
))
4002 if (! ecoff_indirect_link_order (abfd
, info
, o
, p
))
4007 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4013 bfd_get_symcount (abfd
) = symhdr
->iextMax
+ symhdr
->isymMax
;
4018 /* Accumulate the debugging information for an input BFD into the
4019 output BFD. This must read in the symbolic information of the
4023 ecoff_final_link_debug_accumulate (output_bfd
, input_bfd
, info
)
4026 struct bfd_link_info
*info
;
4028 struct ecoff_debug_info
* const debug
= &ecoff_data (input_bfd
)->debug_info
;
4029 const struct ecoff_debug_swap
* const swap
=
4030 &ecoff_backend (input_bfd
)->debug_swap
;
4031 HDRR
*symhdr
= &debug
->symbolic_header
;
4034 #define READ(ptr, offset, count, size, type) \
4035 if (symhdr->count == 0) \
4036 debug->ptr = NULL; \
4039 debug->ptr = (type) alloca (size * symhdr->count); \
4040 if ((bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) \
4042 || (bfd_read (debug->ptr, size, symhdr->count, \
4043 input_bfd) != size * symhdr->count)) \
4047 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
4048 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
4049 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
4050 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
4051 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
4052 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
4054 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
4055 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
4056 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
4059 /* We do not read the external strings or the external symbols. */
4061 ret
= (bfd_ecoff_debug_accumulate
4062 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4063 &ecoff_backend (output_bfd
)->debug_swap
,
4064 input_bfd
, debug
, swap
, info
->relocateable
));
4066 /* Make sure we don't accidentally follow one of these pointers on
4069 debug
->external_dnr
= NULL
;
4070 debug
->external_pdr
= NULL
;
4071 debug
->external_sym
= NULL
;
4072 debug
->external_opt
= NULL
;
4073 debug
->external_aux
= NULL
;
4075 debug
->external_fdr
= NULL
;
4076 debug
->external_rfd
= NULL
;
4081 /* Put out information for an external symbol. These come only from
4085 ecoff_link_write_external (h
, data
)
4086 struct ecoff_link_hash_entry
*h
;
4089 bfd
*output_bfd
= (bfd
*) data
;
4091 /* FIXME: We should check if this symbol is being stripped. */
4093 if (h
->root
.written
)
4096 if (h
->abfd
== (bfd
*) NULL
)
4099 h
->esym
.cobol_main
= 0;
4100 h
->esym
.weakext
= 0;
4101 h
->esym
.reserved
= 0;
4102 h
->esym
.ifd
= ifdNil
;
4103 h
->esym
.asym
.value
= 0;
4104 /* FIXME: we can do better than this for st and sc. */
4105 h
->esym
.asym
.st
= stGlobal
;
4106 h
->esym
.asym
.sc
= scAbs
;
4107 h
->esym
.asym
.reserved
= 0;
4108 h
->esym
.asym
.index
= indexNil
;
4112 /* Adjust the FDR index for the symbol by that used for the
4114 h
->esym
.ifd
+= ecoff_data (h
->abfd
)->debug_info
.ifdbase
;
4117 switch (h
->root
.type
)
4120 case bfd_link_hash_new
:
4122 case bfd_link_hash_undefined
:
4123 case bfd_link_hash_weak
:
4124 if (h
->esym
.asym
.st
!= scUndefined
4125 && h
->esym
.asym
.st
!= scSUndefined
)
4126 h
->esym
.asym
.st
= scUndefined
;
4128 case bfd_link_hash_defined
:
4129 if (h
->esym
.asym
.sc
== scUndefined
4130 || h
->esym
.asym
.sc
== scSUndefined
)
4131 h
->esym
.asym
.sc
= scAbs
;
4132 else if (h
->esym
.asym
.sc
== scCommon
)
4133 h
->esym
.asym
.sc
= scBss
;
4134 else if (h
->esym
.asym
.sc
== scSCommon
)
4135 h
->esym
.asym
.sc
= scSBss
;
4136 h
->esym
.asym
.value
= (h
->root
.u
.def
.value
4137 + h
->root
.u
.def
.section
->output_section
->vma
4138 + h
->root
.u
.def
.section
->output_offset
);
4140 case bfd_link_hash_common
:
4141 if (h
->esym
.asym
.sc
!= scCommon
4142 && h
->esym
.asym
.sc
!= scSCommon
)
4143 h
->esym
.asym
.sc
= scCommon
;
4144 h
->esym
.asym
.value
= h
->root
.u
.c
.size
;
4146 case bfd_link_hash_indirect
:
4147 case bfd_link_hash_warning
:
4148 /* FIXME: Ignore these for now. The circumstances under which
4149 they should be written out are not clear to me. */
4153 /* bfd_ecoff_debug_one_external uses iextMax to keep track of the
4155 h
->indx
= ecoff_data (output_bfd
)->debug_info
.symbolic_header
.iextMax
;
4156 h
->root
.written
= true;
4158 return (bfd_ecoff_debug_one_external
4159 (output_bfd
, &ecoff_data (output_bfd
)->debug_info
,
4160 &ecoff_backend (output_bfd
)->debug_swap
, h
->root
.root
.string
,
4164 /* Relocate and write an ECOFF section into an ECOFF output file. */
4167 ecoff_indirect_link_order (output_bfd
, info
, output_section
, link_order
)
4169 struct bfd_link_info
*info
;
4170 asection
*output_section
;
4171 struct bfd_link_order
*link_order
;
4173 asection
*input_section
;
4175 bfd_size_type input_size
;
4177 bfd_size_type external_reloc_size
;
4178 bfd_size_type external_relocs_size
;
4179 PTR external_relocs
;
4181 BFD_ASSERT ((output_section
->flags
& SEC_HAS_CONTENTS
) != 0);
4183 if (link_order
->size
== 0)
4186 input_section
= link_order
->u
.indirect
.section
;
4187 input_bfd
= input_section
->owner
;
4189 BFD_ASSERT (input_section
->output_section
== output_section
);
4190 BFD_ASSERT (input_section
->output_offset
== link_order
->offset
);
4191 BFD_ASSERT (bfd_section_size (input_bfd
, input_section
) == link_order
->size
);
4193 /* Get the section contents. */
4194 input_size
= bfd_section_size (input_bfd
, input_section
);
4195 contents
= (bfd_byte
*) alloca (input_size
);
4196 if (! bfd_get_section_contents (input_bfd
, input_section
, (PTR
) contents
,
4197 (file_ptr
) 0, input_size
))
4200 /* Get the relocs. */
4201 external_reloc_size
= ecoff_backend (input_bfd
)->external_reloc_size
;
4202 external_relocs_size
= external_reloc_size
* input_section
->reloc_count
;
4203 external_relocs
= (PTR
) alloca (external_relocs_size
);
4204 if (bfd_seek (input_bfd
, input_section
->rel_filepos
, SEEK_SET
) != 0
4205 || (bfd_read (external_relocs
, 1, external_relocs_size
, input_bfd
)
4206 != external_relocs_size
))
4209 /* Relocate the section contents. */
4210 if (! ((*ecoff_backend (input_bfd
)->relocate_section
)
4211 (output_bfd
, info
, input_bfd
, input_section
, contents
,
4215 /* Write out the relocated section. */
4216 if (! bfd_set_section_contents (output_bfd
,
4219 input_section
->output_offset
,
4223 /* If we are producing relocateable output, the relocs were
4224 modified, and we write them out now. We use the reloc_count
4225 field of output_section to keep track of the number of relocs we
4226 have output so far. */
4227 if (info
->relocateable
)
4229 if (bfd_seek (output_bfd
,
4230 (output_section
->rel_filepos
+
4231 output_section
->reloc_count
* external_reloc_size
),
4233 || (bfd_write (external_relocs
, 1, external_relocs_size
, output_bfd
)
4234 != external_relocs_size
))
4236 output_section
->reloc_count
+= input_section
->reloc_count
;